1
0
forked from erosita/uds
This commit is contained in:
Roman Krivonos 2023-02-16 19:36:16 +03:00
parent d8e7eb9408
commit 182ede9d0a
3 changed files with 54 additions and 21 deletions

View File

@ -23,8 +23,9 @@ outkey="mosa_tm0"
root_path=dirname(dirname(dirname(inspect.getfile(uds)))) root_path=dirname(dirname(dirname(inspect.getfile(uds))))
print("UDS root path: {}".format(root_path)) print("UDS root path: {}".format(root_path))
outfile_subdir=root_path+'/products/' infile_dir=root_path+'/data/processed'
create_folder(outfile_subdir) outfile_dir=root_path+'/products'
create_folder(outfile_dir)
index=4 index=4
@ -33,17 +34,19 @@ for tmkey in keylist_tm.keys():
print("TM{} in work... init events".format(tmkey)) print("TM{} in work... init events".format(tmkey))
for datakey in keylist_tm[tmkey]: for datakey in keylist_tm[tmkey]:
print("--> {}".format(datakey)) print("--> {}".format(datakey))
""" Подготавливаем списки событий индивидуальных наблюдений """
events.append(init_events(key=datakey, eband_index=eband[index], 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_obsmode=True,
do_center=True, do_center=True,
do_evtool=False, do_evtool=True,
do_expmap=False, do_expmap=False,
ra_cen=ra_cen, de_cen=de_cen, ra_cen=ra_cen, de_cen=de_cen,
emin_kev=emin_kev[index], emin_kev=emin_kev[index],
emax_kev=emax_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)

View File

@ -3,4 +3,10 @@
Создает начальные списки событий и помещает их в ```uds/data/processed``` Создает начальные списки событий и помещает их в ```uds/data/processed```
Оригинальные файлы со списками событий задаются в файлах ```uds/data/evtlists/*.txt``` Оригинальные файлы со списками событий задаются в файлах ```uds/data/evtlists/*.txt```
### 02_merge_events.py
Создает объедененный список событий и помещает его в ```uds/products```. Этот список событий нужен, в основном для извлечения спектров с помощью ```srctool```.
Попутно этот скрипт унифицирует оригинальные списки событий для последующей обработки. А именно, корректируются слова OBS_MODE=POINING/SURVEY в зависимости от типа наблюдения и производится центрирование на одни и те же координаты.

View File

@ -8,6 +8,7 @@ from astropy.io.fits import update
from astropy.io.fits import getdata from astropy.io.fits import getdata
import glob import glob
from fitsio import FITS from fitsio import FITS
from pathlib import Path
from astropy.table import QTable, Table, Column from astropy.table import QTable, Table, Column
from astropy import units as u 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)) print((" ").join(cmd))
test_exe('evtool')
os.system((" ").join(cmd)) os.system((" ").join(cmd))
def set_bit(value, bit): 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, def init_events(key=None, eband_selected=[0], eband_index=None,
ra_cen=None, de_cen=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): do_obsmode=False,do_center=False,do_evtool=False,do_expmap=False):
expmaps=[] expmaps=[]
expmap_all=[] expmap_all=[]
@ -132,23 +134,22 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
outfile_post='.fits' outfile_post='.fits'
if not (subdir): if not (infile_dir):
print("subdir=?") print("infile_dir=?")
return return
if not (os.path.exists(subdir)): if not (outfile_dir):
os.makedirs(subdir) print("outfile_dir=?")
return
print("init events -- reading key {}".format(key)) print("init events -- reading key {}".format(key))
infile="{}/{}.fits".format(infile_dir,key)
infile="{}.fits".format(key)
if(do_obsmode==True): if(do_obsmode==True):
""" correct OBS_MODE in files """ """ correct OBS_MODE in files """
lockfile="{}.obsmode.lock".format(key) lockfile="{}/{}.obsmode.lock".format(infile_dir,key)
if not os.path.isfile(lockfile): if not os.path.isfile(lockfile):
with fits.open(infile) as hdu: with fits.open(infile) as hdu:
for h in hdu: for h in hdu:
@ -173,9 +174,10 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
"{}".format(ra_cen), "{}".format(ra_cen),
"{}".format(de_cen)] "{}".format(de_cen)]
lockfile="{}.radec2xy.lock".format(key) lockfile="{}/{}.radec2xy.lock".format(infile_dir,key)
if not os.path.isfile(lockfile): if not os.path.isfile(lockfile):
print((" ").join(cmd)) print((" ").join(cmd))
test_exe('radec2xy')
os.system((" ").join(cmd)) os.system((" ").join(cmd))
Path(lockfile).touch() Path(lockfile).touch()
else: else:
@ -183,7 +185,7 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
pass 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", cmd=["evtool",
"eventfiles=%s" %(infile), "eventfiles=%s" %(infile),
@ -199,6 +201,7 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
if(do_evtool==True): if(do_evtool==True):
#log = subprocess.check_call(cmd) #log = subprocess.check_call(cmd)
print((" ").join(cmd)) print((" ").join(cmd))
test_exe('evtool')
os.system((" ").join(cmd)) os.system((" ").join(cmd))
""" correct OBS_MODE """ """ correct OBS_MODE """
with fits.open(outfile_evtool) as hdu: 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) 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): if(do_expmap==True):
cmd=["expmap", cmd=["expmap",
"inputdatasets=%s" %(outfile_evtool), "inputdatasets=%s" %(outfile_evtool),
@ -224,6 +227,27 @@ def init_events(key=None, eband_selected=[0], eband_index=None,
"withmergedmaps=no", "withmergedmaps=no",
] ]
print((" ").join(cmd)) print((" ").join(cmd))
test_exe('expmap')
os.system((" ").join(cmd)) os.system((" ").join(cmd))
return outfile_evtool 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()