Changes
This commit is contained in:
parent
e27d4a5e62
commit
d8e7eb9408
@ -52,3 +52,5 @@ ecf=[1.0, 1.0, 1.0, 1.0, 1.0]
|
||||
|
||||
""" Это просто индекс диапазона для выходных файлов. """
|
||||
eband=["0", "1", "2", "3", "4"]
|
||||
|
||||
outfile_post='.fits'
|
||||
|
119
uds/uds/utils.py
119
uds/uds/utils.py
@ -62,7 +62,12 @@ def clear_bit(value, bit):
|
||||
return value & ~(1<<bit)
|
||||
|
||||
def do_badpix_tm6(filename):
|
||||
""" special corrrection for TM6 camera, needed for two CalPV-UDS observations, which shows high background at RAWX>250 """
|
||||
"""
|
||||
special corrrection for TM6 camera, needed for two CalPV-UDS observations,
|
||||
which shows high background at RAWX>250
|
||||
|
||||
creates new file with added _badpix.fits
|
||||
"""
|
||||
|
||||
nraw=384
|
||||
skip_after=250
|
||||
@ -110,3 +115,115 @@ def do_badpix_tm6(filename):
|
||||
|
||||
f[4].append(data4)
|
||||
f.close()
|
||||
|
||||
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,
|
||||
do_obsmode=False,do_center=False,do_evtool=False,do_expmap=False):
|
||||
expmaps=[]
|
||||
expmap_all=[]
|
||||
infile_expmap=[]
|
||||
emin=[]
|
||||
emax=[]
|
||||
emin_ev_str=[]
|
||||
emax_ev_str=[]
|
||||
outfile_evtool=[]
|
||||
outfile_expmap=[]
|
||||
|
||||
outfile_post='.fits'
|
||||
|
||||
if not (subdir):
|
||||
print("subdir=?")
|
||||
return
|
||||
|
||||
if not (os.path.exists(subdir)):
|
||||
os.makedirs(subdir)
|
||||
|
||||
print("init events -- reading key {}".format(key))
|
||||
|
||||
|
||||
|
||||
infile="{}.fits".format(key)
|
||||
|
||||
if(do_obsmode==True):
|
||||
""" correct OBS_MODE in files """
|
||||
|
||||
lockfile="{}.obsmode.lock".format(key)
|
||||
if not os.path.isfile(lockfile):
|
||||
with fits.open(infile) as hdu:
|
||||
for h in hdu:
|
||||
extname = h.header['EXTNAME'] if "EXTNAME" in h.header else "None"
|
||||
changeto = 'SURVEY' if ('scan' in infile) else 'POINTING'
|
||||
if not (h.header['OBS_MODE'] == changeto):
|
||||
print("*** {} {} --> {}".format(extname,h.header['OBS_MODE'],changeto))
|
||||
h.header['OBS_MODE'] = changeto
|
||||
hdu.writeto(infile,overwrite=True)
|
||||
Path(lockfile).touch()
|
||||
else:
|
||||
print("Lock file {} is found, skipping OBS_MODE correction.".format(lockfile))
|
||||
pass
|
||||
|
||||
if(do_center==True):
|
||||
""" re-center original events files """
|
||||
if not (ra_cen and de_cen):
|
||||
print("Please provide center coordinates")
|
||||
sys.exit()
|
||||
cmd=["radec2xy",
|
||||
"{}".format(infile),
|
||||
"{}".format(ra_cen),
|
||||
"{}".format(de_cen)]
|
||||
|
||||
lockfile="{}.radec2xy.lock".format(key)
|
||||
if not os.path.isfile(lockfile):
|
||||
print((" ").join(cmd))
|
||||
os.system((" ").join(cmd))
|
||||
Path(lockfile).touch()
|
||||
else:
|
||||
print("Lock file {} is found, skipping radec2xy.".format(lockfile))
|
||||
pass
|
||||
|
||||
|
||||
outfile_evtool="{}/{}_EventList_en{}{}".format(subdir, key, eband_index, outfile_post)
|
||||
|
||||
cmd=["evtool",
|
||||
"eventfiles=%s" %(infile),
|
||||
"outfile=%s" %(outfile_evtool),
|
||||
"emin=%f" %(emin_kev),
|
||||
"emax=%f" %(emax_kev),
|
||||
#"region=%s" %(region),
|
||||
"image=yes",
|
||||
"flag=0x2000",
|
||||
"pattern=15"
|
||||
]
|
||||
# run the command
|
||||
if(do_evtool==True):
|
||||
#log = subprocess.check_call(cmd)
|
||||
print((" ").join(cmd))
|
||||
os.system((" ").join(cmd))
|
||||
""" correct OBS_MODE """
|
||||
with fits.open(outfile_evtool) as hdu:
|
||||
for h in hdu:
|
||||
extname = h.header['EXTNAME'] if "EXTNAME" in h.header else "None"
|
||||
changeto = 'SURVEY' if ('scan' in infile) else 'POINTING'
|
||||
if not (h.header['OBS_MODE'] == changeto):
|
||||
print("*** {} {} --> {}".format(extname,h.header['OBS_MODE'],changeto))
|
||||
h.header['OBS_MODE'] = changeto
|
||||
hdu.writeto(outfile_evtool,overwrite=True)
|
||||
|
||||
|
||||
outfile_expmap="{}_ExposureMap_en{}{}".format(os.path.join(subdir,key), eband_index, outfile_post)
|
||||
if(do_expmap==True):
|
||||
cmd=["expmap",
|
||||
"inputdatasets=%s" %(outfile_evtool),
|
||||
"emin=%s" %(emin_kev),
|
||||
"emax=%s" %(emax_kev),
|
||||
"templateimage=%s" %(outfile_evtool),
|
||||
"singlemaps=%s" %(outfile_expmap),
|
||||
"withvignetting=yes",
|
||||
"withsinglemaps=yes","withfilebadpix=yes",
|
||||
"withmergedmaps=no",
|
||||
]
|
||||
print((" ").join(cmd))
|
||||
os.system((" ").join(cmd))
|
||||
|
||||
return outfile_evtool
|
||||
|
Loading…
x
Reference in New Issue
Block a user