forked from erosita/uds
Minor
This commit is contained in:
parent
d8e7eb9408
commit
182ede9d0a
@ -23,8 +23,9 @@ outkey="mosa_tm0"
|
||||
root_path=dirname(dirname(dirname(inspect.getfile(uds))))
|
||||
print("UDS root path: {}".format(root_path))
|
||||
|
||||
outfile_subdir=root_path+'/products/'
|
||||
create_folder(outfile_subdir)
|
||||
infile_dir=root_path+'/data/processed'
|
||||
outfile_dir=root_path+'/products'
|
||||
create_folder(outfile_dir)
|
||||
|
||||
index=4
|
||||
|
||||
@ -33,17 +34,19 @@ for tmkey in keylist_tm.keys():
|
||||
print("TM{} in work... init events".format(tmkey))
|
||||
for datakey in keylist_tm[tmkey]:
|
||||
print("--> {}".format(datakey))
|
||||
|
||||
""" Подготавливаем списки событий индивидуальных наблюдений """
|
||||
events.append(init_events(key=datakey, eband_index=eband[index],
|
||||
subdir=outfile_subdir,
|
||||
infile_dir=infile_dir,
|
||||
outfile_dir=outfile_dir,
|
||||
do_obsmode=True,
|
||||
do_center=True,
|
||||
do_evtool=False,
|
||||
do_evtool=True,
|
||||
do_expmap=False,
|
||||
ra_cen=ra_cen, de_cen=de_cen,
|
||||
emin_kev=emin_kev[index],
|
||||
emax_kev=emax_kev[index]))
|
||||
sys.exit()
|
||||
outfile_evtool="{}_EventList_en{}.fits".format(os.path.join(outfile_subdir,outkey), eband[index])
|
||||
do_evtool_esass(events=events, outfile=outfile_evtool)
|
||||
|
||||
""" Собираем общий список событий """
|
||||
outfile_evtool="{}_EventList_en{}.fits".format(os.path.join(outfile_dir,outkey), eband[index])
|
||||
do_evtool_esass(events=events, outfile=outfile_evtool)
|
||||
|
||||
|
@ -3,4 +3,10 @@
|
||||
Создает начальные списки событий и помещает их в ```uds/data/processed```
|
||||
Оригинальные файлы со списками событий задаются в файлах ```uds/data/evtlists/*.txt```
|
||||
|
||||
### 02_merge_events.py
|
||||
|
||||
Создает объедененный список событий и помещает его в ```uds/products```. Этот список событий нужен, в основном для извлечения спектров с помощью ```srctool```.
|
||||
|
||||
Попутно этот скрипт унифицирует оригинальные списки событий для последующей обработки. А именно, корректируются слова OBS_MODE=POINING/SURVEY в зависимости от типа наблюдения и производится центрирование на одни и те же координаты.
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user