This commit is contained in:
2023-02-16 19:36:16 +03:00
parent d8e7eb9408
commit 182ede9d0a
3 changed files with 54 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ from astropy.io.fits import update
from astropy.io.fits import getdata
import glob
from fitsio import FITS
from pathlib import Path
from astropy.table import QTable, Table, Column
from astropy import units as u
@@ -53,6 +54,7 @@ def do_evtool_esass(events=None,outfile=None,evlist=None,gti=None):
]
print((" ").join(cmd))
test_exe('evtool')
os.system((" ").join(cmd))
def set_bit(value, bit):
@@ -118,7 +120,7 @@ def do_badpix_tm6(filename):
def init_events(key=None, eband_selected=[0], eband_index=None,
ra_cen=None, de_cen=None,
emin_kev=None, emax_kev=None, subdir=None,
emin_kev=None, emax_kev=None, infile_dir=None, outfile_dir=None,
do_obsmode=False,do_center=False,do_evtool=False,do_expmap=False):
expmaps=[]
expmap_all=[]
@@ -132,23 +134,22 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
outfile_post='.fits'
if not (subdir):
print("subdir=?")
if not (infile_dir):
print("infile_dir=?")
return
if not (outfile_dir):
print("outfile_dir=?")
return
if not (os.path.exists(subdir)):
os.makedirs(subdir)
print("init events -- reading key {}".format(key))
infile="{}.fits".format(key)
infile="{}/{}.fits".format(infile_dir,key)
if(do_obsmode==True):
""" correct OBS_MODE in files """
lockfile="{}.obsmode.lock".format(key)
lockfile="{}/{}.obsmode.lock".format(infile_dir,key)
if not os.path.isfile(lockfile):
with fits.open(infile) as hdu:
for h in hdu:
@@ -173,9 +174,10 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
"{}".format(ra_cen),
"{}".format(de_cen)]
lockfile="{}.radec2xy.lock".format(key)
lockfile="{}/{}.radec2xy.lock".format(infile_dir,key)
if not os.path.isfile(lockfile):
print((" ").join(cmd))
test_exe('radec2xy')
os.system((" ").join(cmd))
Path(lockfile).touch()
else:
@@ -183,7 +185,7 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
pass
outfile_evtool="{}/{}_EventList_en{}{}".format(subdir, key, eband_index, outfile_post)
outfile_evtool="{}/{}_EventList_en{}{}".format(outfile_dir, key, eband_index, outfile_post)
cmd=["evtool",
"eventfiles=%s" %(infile),
@@ -199,6 +201,7 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
if(do_evtool==True):
#log = subprocess.check_call(cmd)
print((" ").join(cmd))
test_exe('evtool')
os.system((" ").join(cmd))
""" correct OBS_MODE """
with fits.open(outfile_evtool) as hdu:
@@ -211,7 +214,7 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
hdu.writeto(outfile_evtool,overwrite=True)
outfile_expmap="{}_ExposureMap_en{}{}".format(os.path.join(subdir,key), eband_index, outfile_post)
outfile_expmap="{}_ExposureMap_en{}{}".format(os.path.join(outfile_dir,key), eband_index, outfile_post)
if(do_expmap==True):
cmd=["expmap",
"inputdatasets=%s" %(outfile_evtool),
@@ -224,6 +227,27 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
"withmergedmaps=no",
]
print((" ").join(cmd))
test_exe('expmap')
os.system((" ").join(cmd))
return outfile_evtool
def test_exe(program):
""" Tests if executable exists in PATH """
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
print("\n*** Command {} not found ***\n".format(program))
sys.exit()