forked from xmm/arches
good night
This commit is contained in:
@@ -51,83 +51,24 @@ for obsid in files:
|
||||
# Create QPB
|
||||
# https://www.cosmos.esa.int/web/xmm-newton/sas-thread-background
|
||||
#
|
||||
|
||||
attfiles = glob.glob(events_dir+f'/{obsid}/*{obsid}_AttHk.ds')
|
||||
if(attfiles):
|
||||
print(f"*** {attfiles} ***")
|
||||
else:
|
||||
print("AttHk?")
|
||||
sys.exit()
|
||||
|
||||
attfile = attfiles[0]
|
||||
if not os.path.isfile(attfile):
|
||||
print ("File "+attfile+" does not exist, please check. \n")
|
||||
sys.exit()
|
||||
attfile = get_first_file(events_dir+f'/{obsid}/*{obsid}_AttHk.ds')
|
||||
|
||||
spec=[]
|
||||
bkg=[]
|
||||
resp=[]
|
||||
arf=[]
|
||||
#for imos in [1,2]:
|
||||
for key in ['MOS1','MOS2','PN']:
|
||||
evtfile = get_first_file(events_dir+f'/{obsid}/*{obsid}_E{key}*_ImagingEvts.ds')
|
||||
|
||||
# Run the SAS task evqpb over each one of these event files.
|
||||
evqpb_outset=work_dir+f'/EPIC_{key}_QPB.fits' # Name of the output file
|
||||
inargs = [f'table={evtfile}', f'attfile={attfile}',
|
||||
f'outset={evqpb_outset}',
|
||||
f'exposurefactor=2.0',]
|
||||
w("evqpb", inargs).run()
|
||||
|
||||
gti=f'EPIC_{key}_gti.fit'
|
||||
expression=f'gti({gti},TIME)'
|
||||
# filter the EPIC event files to create cleaned and filtered for
|
||||
# flaring particle background event files for your observation
|
||||
sci_clean=work_dir+f'/EPIC_{key}_filtered.fits' # Name of the output file
|
||||
inargs = [f'table={evtfile}', 'withfilteredset=yes',
|
||||
f'filteredset={sci_clean}',
|
||||
'destruct=yes','keepfilteroutput=true',
|
||||
f'expression={expression}']
|
||||
w("evselect", inargs).run()
|
||||
|
||||
# Use the same expression to filter the FWC event files:
|
||||
qpb_clean=work_dir+f'/EPIC_{key}_QPB_clean.fits' # Name of the output file
|
||||
inargs = [f'table={evqpb_outset}', 'withfilteredset=yes',
|
||||
f'filteredset={qpb_clean}',
|
||||
'destruct=yes','keepfilteroutput=true',
|
||||
f'expression={expression}']
|
||||
w("evselect", inargs).run()
|
||||
# first element contains all energies
|
||||
label=['',]
|
||||
pimin=[200,]
|
||||
pimax=[12000,]
|
||||
for idx,e1 in enumerate(emin):
|
||||
label.append(f"_{idx}")
|
||||
pimin.append(emin[idx])
|
||||
pimax.append(emax[idx])
|
||||
|
||||
run_evqpb(key, work_dir=work_dir, evtfile=evtfile, attfile=attfile, label=label, pimin=pimin, pimax=pimax)
|
||||
|
||||
if(key=='PN'):
|
||||
expression='(#XMMEA_EP)&&(PATTERN<=4)&&(PI>=200)&&(PI<=12000)'
|
||||
else:
|
||||
expression='(#XMMEA_EM)&&(PATTERN<=12)&&(PI>=200)&&(PI<=12000)'
|
||||
|
||||
sci_image=work_dir+f'/EPIC_{key}_sci_image.fits' # Name of the output file
|
||||
# Extract an image for the science exposure
|
||||
inargs = [f'table={sci_clean}', f'expression={expression}',
|
||||
'imagebinning=binSize', f'imageset={sci_image}',
|
||||
'withimageset=yes','xcolumn=X', 'ycolumn=Y',
|
||||
'ximagebinsize=80', 'yimagebinsize=80',
|
||||
]
|
||||
w("evselect", inargs).run()
|
||||
|
||||
qpb_image=work_dir+f'/EPIC_{key}_qpb_image.fits' # Name of the output file
|
||||
# Extract an image for the FWC exposure
|
||||
inargs = [f'table={qpb_clean}', f'expression={expression}',
|
||||
'imagebinning=binSize', f'imageset={qpb_image}',
|
||||
'withimageset=yes','xcolumn=X', 'ycolumn=Y',
|
||||
'ximagebinsize=80', 'yimagebinsize=80','zcolumn=EWEIGHT',
|
||||
]
|
||||
w("evselect", inargs).run()
|
||||
|
||||
# Subtract background
|
||||
cor_image=work_dir+f'/EPIC_{key}_cor_image.fits' # Name of the output file
|
||||
cmd = ['farith', f'{sci_image}', f'{qpb_image}', f'{cor_image}', 'SUB',
|
||||
'copyprime=yes',
|
||||
'clobber=yes']
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||
|
||||
continue
|
||||
|
||||
#
|
||||
|
||||
77
scripts/07_sas_eimageget.py
Executable file
77
scripts/07_sas_eimageget.py
Executable file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from pysas.wrapper import Wrapper as w
|
||||
import os, sys
|
||||
from os.path import dirname
|
||||
import inspect
|
||||
import glob
|
||||
|
||||
import os.path
|
||||
from os import path
|
||||
import subprocess
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from astropy.io import fits
|
||||
from astropy.table import Table
|
||||
from matplotlib.colors import LogNorm
|
||||
|
||||
import re
|
||||
import pyds9
|
||||
|
||||
import arches
|
||||
from arches.utils import *
|
||||
from arches.config import *
|
||||
|
||||
root_path=dirname(dirname(dirname(inspect.getfile(arches))))
|
||||
print("Arches root path: {}".format(root_path))
|
||||
|
||||
fwc_dir=root_path+'/data/FWC'
|
||||
archive_dir=root_path+'/data/archive'
|
||||
events_dir=root_path+'/data/processed'
|
||||
events_dir_oot=root_path+'/data/processed-oot'
|
||||
products_dir=root_path+'/products/sas'
|
||||
ds9reg_dir=root_path+'/data/ds9reg'
|
||||
|
||||
|
||||
create_folder(products_dir)
|
||||
|
||||
inargs = ['--version']
|
||||
t = w('sasver', inargs)
|
||||
t.run()
|
||||
|
||||
files = glob.glob(archive_dir+'/*')
|
||||
|
||||
for obsid in files:
|
||||
obsid = os.path.basename(obsid)
|
||||
if(obsid in skip):
|
||||
continue
|
||||
|
||||
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||
os.chdir(work_dir)
|
||||
|
||||
#
|
||||
# https://www.cosmos.esa.int/web/xmm-newton/sas-thread-images
|
||||
#
|
||||
|
||||
attfile = get_first_file(events_dir+f'/{obsid}/*{obsid}_AttHk.ds')
|
||||
|
||||
for key in ['MOS1','MOS2','PN']:
|
||||
evtfile = get_first_file(events_dir+f'/{obsid}/*{obsid}_E{key}*_ImagingEvts.ds')
|
||||
fwcfile = get_first_file(fwc_dir+f'/{key}_closed_FF_2025_v1.fits')
|
||||
pimin=" ".join(emin)
|
||||
pimax=" ".join(emax)
|
||||
gti=f'EPIC_{key}_gti.fit'
|
||||
sci_clean=work_dir+f'/EPIC_{key}_filtered.fits' # Name of the output file
|
||||
inargs = [f'evtfile={evtfile}','withemtaglenoise=no',
|
||||
f'fwcfile={fwcfile}','withfwcimages=yes',
|
||||
f'gtifile={gti}',
|
||||
f'attfile={attfile}',
|
||||
f'pimin={pimin}',
|
||||
f'pimax={pimax}',
|
||||
]
|
||||
if(key=='PN'):
|
||||
evtfile_oot = get_first_file(events_dir_oot+f'/{obsid}/*{obsid}_E{key}*_ImagingEvts.ds')
|
||||
inargs.append(f'ootfile={evtfile_oot}')
|
||||
w("eimageget", inargs).run()
|
||||
|
||||
#sys.exit()
|
||||
149
scripts/08_sas_mosaic.py
Executable file
149
scripts/08_sas_mosaic.py
Executable file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from pysas.wrapper import Wrapper as w
|
||||
import os, sys
|
||||
from os.path import dirname
|
||||
import inspect
|
||||
import glob
|
||||
|
||||
import os.path
|
||||
from os import path
|
||||
import subprocess
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from astropy.io import fits
|
||||
from astropy.table import Table
|
||||
from matplotlib.colors import LogNorm
|
||||
|
||||
import re
|
||||
import pyds9
|
||||
|
||||
import arches
|
||||
from arches.utils import *
|
||||
from arches.config import *
|
||||
|
||||
root_path=dirname(dirname(dirname(inspect.getfile(arches))))
|
||||
print("Arches root path: {}".format(root_path))
|
||||
|
||||
archive_dir=root_path+'/data/archive'
|
||||
events_dir=root_path+'/data/processed'
|
||||
products_dir=root_path+'/products/sas'
|
||||
create_folder(products_dir)
|
||||
mosaic_dir=root_path+'/products/mosaic'
|
||||
create_folder(mosaic_dir)
|
||||
|
||||
ds9reg_dir=root_path+'/data/ds9reg'
|
||||
|
||||
|
||||
inargs = ['--version']
|
||||
t = w('sasver', inargs)
|
||||
t.run()
|
||||
|
||||
files = glob.glob(archive_dir+'/*')
|
||||
|
||||
|
||||
# run over energies
|
||||
for idx,e in enumerate(emin):
|
||||
label=f"_{idx}"
|
||||
e1=emin[idx]
|
||||
e2=emax[idx]
|
||||
|
||||
# all MOS1
|
||||
m1_ima=[]
|
||||
m1_qpb=[]
|
||||
m1_exp=[]
|
||||
|
||||
# all MOS2
|
||||
m2_ima=[]
|
||||
m2_qpb=[]
|
||||
m2_exp=[]
|
||||
|
||||
# all MOS
|
||||
mos_ima=[]
|
||||
mos_qpb=[]
|
||||
mos_exp=[]
|
||||
|
||||
# all PNs
|
||||
pn_ima=[]
|
||||
pn_qpb=[]
|
||||
pn_exp=[]
|
||||
|
||||
# all MOS1,2,PN
|
||||
ima=[]
|
||||
qpb=[]
|
||||
exp=[]
|
||||
|
||||
for obsid in files:
|
||||
obsid = os.path.basename(obsid)
|
||||
if(obsid in skip):
|
||||
continue
|
||||
|
||||
work_dir = f'{products_dir}/{obsid}'
|
||||
|
||||
for ikey,key in enumerate(['MOS1','MOS2','PN']):
|
||||
shortkey = key.replace("OS","")
|
||||
expkey=f'S00{ikey+1}'
|
||||
# sci and qpb image are produced by 06_sas_QPB.py
|
||||
sci_image=work_dir+f'/EPIC_{key}_sci_image{label}.fits'
|
||||
test_file(sci_image)
|
||||
qpb_image=work_dir+f'/EPIC_{key}_qpb_image{label}.fits'
|
||||
test_file(qpb_image)
|
||||
# exposure image is produced by eimageget (07_sas_eimageget.py)
|
||||
# example: P0862470801PNS003_ima_4exp.fits
|
||||
exp_image=work_dir+f'/P{obsid}{shortkey}{expkey}_ima{label}exp.fits'
|
||||
test_file(exp_image)
|
||||
|
||||
ima.append(sci_image)
|
||||
qpb.append(qpb_image)
|
||||
exp.append(exp_image)
|
||||
|
||||
if(key=='PN'):
|
||||
pn_ima.append(sci_image)
|
||||
pn_qpb.append(qpb_image)
|
||||
pn_exp.append(exp_image)
|
||||
if(key=='MOS1'):
|
||||
m1_ima.append(sci_image)
|
||||
m1_qpb.append(qpb_image)
|
||||
m1_exp.append(exp_image)
|
||||
if(key=='MOS2'):
|
||||
m2_ima.append(sci_image)
|
||||
m2_qpb.append(qpb_image)
|
||||
m2_exp.append(exp_image)
|
||||
if(key=='MOS1' or key=='MOS2'):
|
||||
mos_ima.append(sci_image)
|
||||
mos_qpb.append(qpb_image)
|
||||
mos_exp.append(exp_image)
|
||||
|
||||
|
||||
run_mosaic(outfile_cts=mosaic_dir+f'/m1_cts{label}.fits',
|
||||
outfile_exp=mosaic_dir+f'/m1_exp{label}.fits',
|
||||
outfile_qpb=mosaic_dir+f'/m1_qpb{label}.fits',
|
||||
outfile_sub=mosaic_dir+f'/m1_sub{label}.fits',
|
||||
outfile_flx=mosaic_dir+f'/m1_flx{label}.fits',
|
||||
outfile_pix=mosaic_dir+f'/m1_pix{label}.fits',
|
||||
cts=m1_ima,qpb=m1_qpb,exp=m1_exp)
|
||||
run_mosaic(outfile_cts=mosaic_dir+f'/m2_cts{label}.fits',
|
||||
outfile_exp=mosaic_dir+f'/m2_exp{label}.fits',
|
||||
outfile_qpb=mosaic_dir+f'/m2_qpb{label}.fits',
|
||||
outfile_sub=mosaic_dir+f'/m2_sub{label}.fits',
|
||||
outfile_flx=mosaic_dir+f'/m2_flx{label}.fits',
|
||||
cts=m2_ima,qpb=m2_qpb,exp=m2_exp)
|
||||
run_mosaic(outfile_cts=mosaic_dir+f'/mos_cts{label}.fits',
|
||||
outfile_exp=mosaic_dir+f'/mos_exp{label}.fits',
|
||||
outfile_qpb=mosaic_dir+f'/mos_qpb{label}.fits',
|
||||
outfile_sub=mosaic_dir+f'/mos_sub{label}.fits',
|
||||
outfile_flx=mosaic_dir+f'/mos_flx{label}.fits',
|
||||
cts=mos_ima,qpb=mos_qpb,exp=mos_exp)
|
||||
run_mosaic(outfile_cts=mosaic_dir+f'/pn_cts{label}.fits',
|
||||
outfile_exp=mosaic_dir+f'/pn_exp{label}.fits',
|
||||
outfile_qpb=mosaic_dir+f'/pn_qpb{label}.fits',
|
||||
outfile_sub=mosaic_dir+f'/pn_sub{label}.fits',
|
||||
outfile_flx=mosaic_dir+f'/pn_flx{label}.fits',
|
||||
cts=pn_ima,qpb=pn_qpb,exp=pn_exp)
|
||||
run_mosaic(outfile_cts=mosaic_dir+f'/cts{label}.fits',
|
||||
outfile_exp=mosaic_dir+f'/exp{label}.fits',
|
||||
outfile_qpb=mosaic_dir+f'/qpb{label}.fits',
|
||||
outfile_sub=mosaic_dir+f'/sub{label}.fits',
|
||||
outfile_flx=mosaic_dir+f'/flx{label}.fits',
|
||||
cts=ima,qpb=qpb,exp=exp)
|
||||
|
||||
Reference in New Issue
Block a user