forked from xmm/arches
SAS
This commit is contained in:
@@ -60,6 +60,19 @@ def remove_file(filename):
|
|||||||
if(os.path.isfile(filename)==True):
|
if(os.path.isfile(filename)==True):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
|
def move_files(pattern, destination):
|
||||||
|
for file in glob.glob(pattern):
|
||||||
|
shutil.move(file, os.path.join(destination,file))
|
||||||
|
|
||||||
|
def get_first_file(pattern):
|
||||||
|
files = glob.glob(pattern)
|
||||||
|
if not (files):
|
||||||
|
print(f"Files not found from pattern {pattern}")
|
||||||
|
sys.exit()
|
||||||
|
filename = files[0]
|
||||||
|
return filename
|
||||||
|
|
||||||
|
|
||||||
# Function to plot Lightcurve
|
# Function to plot Lightcurve
|
||||||
def plotLC(plt,threshold,fileName):
|
def plotLC(plt,threshold,fileName):
|
||||||
if fileName != "NOT FOUND":
|
if fileName != "NOT FOUND":
|
||||||
@@ -119,6 +132,9 @@ def init_work_dir(obsid,products_dir=None):
|
|||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
|
if (products_dir==None):
|
||||||
|
print('products_dir is not defined')
|
||||||
|
sys.exit()
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
|
|
||||||
#inargs = ['--version']
|
#inargs = ['--version']
|
||||||
@@ -153,6 +169,10 @@ def init_work_dir(obsid,products_dir=None):
|
|||||||
|
|
||||||
""" See also convregion task, for conversion of regions """
|
""" See also convregion task, for conversion of regions """
|
||||||
def get_det_coords(ra,dec,image,key):
|
def get_det_coords(ra,dec,image,key):
|
||||||
|
if(os.path.isfile(image)==False):
|
||||||
|
print(f"{image} is not found")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
logfile=f'{key}-ecoordconv.log'
|
logfile=f'{key}-ecoordconv.log'
|
||||||
remove_file(logfile)
|
remove_file(logfile)
|
||||||
""" Convert sky coordinates to correct DETX/Y """
|
""" Convert sky coordinates to correct DETX/Y """
|
||||||
@@ -174,11 +194,38 @@ def get_det_coords(ra,dec,image,key):
|
|||||||
dety=float(dy)
|
dety=float(dy)
|
||||||
return detx,dety
|
return detx,dety
|
||||||
|
|
||||||
def run_mosspectra(key,ccds,check=True,elow="350",ehigh="1100"):
|
def run_mosspectra(key,ccds,check=False,elow="350",ehigh="1100"):
|
||||||
|
|
||||||
eventfile = f'{key}-allevc.fits'
|
eventfile = f'{key}-allevc.fits'
|
||||||
|
if(os.path.isfile(eventfile)==False):
|
||||||
|
print(f"{eventfile} is not found, run 01_init_events*.py and above")
|
||||||
|
cwd = os.getcwd()
|
||||||
|
print(f"Current directory: {cwd}")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
(detx,dety)=get_det_coords(arches_ra,arches_dec,f'{key}-fovimt.fits',key)
|
unfilt_image = eventfile.replace("allevc","ffov")
|
||||||
|
inargs = [f'table={eventfile}',
|
||||||
|
'withimageset=yes', f'imageset={unfilt_image}',
|
||||||
|
#'filtertype=expression', f'expression={expression}',
|
||||||
|
'ignorelegallimits=yes', 'imagebinning=imageSize',
|
||||||
|
'xcolumn=DETX','ycolumn=DETY','ximagesize=780','yimagesize=780',
|
||||||
|
'ximagemax=19500','yimagemax=19500', 'ximagemin=-19499', 'yimagemin=-19499',]
|
||||||
|
w('evselect', inargs).run()
|
||||||
|
if(os.path.isfile(unfilt_image)==False):
|
||||||
|
print(f"{unfilt_image} is not found")
|
||||||
|
cwd = os.getcwd()
|
||||||
|
print(f"Current directory: {cwd}")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if(check):
|
||||||
|
d = pyds9.DS9()
|
||||||
|
d.set("file "+unfilt_image)
|
||||||
|
d.set('cmap bb')
|
||||||
|
d.set('scale log')
|
||||||
|
#return
|
||||||
|
|
||||||
|
#(detx,dety)=get_det_coords(arches_ra,arches_dec,f'{key}-fovimt.fits',key)
|
||||||
|
(detx,dety)=get_det_coords(arches_ra,arches_dec,unfilt_image,key)
|
||||||
|
|
||||||
arches_Rmax_pix=int(np.round(arches_Rmax_as/det_pix_as))
|
arches_Rmax_pix=int(np.round(arches_Rmax_as/det_pix_as))
|
||||||
region_fn=f'{key}.txt'
|
region_fn=f'{key}.txt'
|
||||||
@@ -188,8 +235,6 @@ def run_mosspectra(key,ccds,check=True,elow="350",ehigh="1100"):
|
|||||||
freg.write(f'&&{expression}\n')
|
freg.write(f'&&{expression}\n')
|
||||||
freg.close()
|
freg.close()
|
||||||
|
|
||||||
# check selected region
|
|
||||||
if(check):
|
|
||||||
unfilt_image = eventfile.replace("allevc","region")
|
unfilt_image = eventfile.replace("allevc","region")
|
||||||
inargs = [f'table={eventfile}',
|
inargs = [f'table={eventfile}',
|
||||||
'withimageset=yes', f'imageset={unfilt_image}',
|
'withimageset=yes', f'imageset={unfilt_image}',
|
||||||
@@ -199,13 +244,6 @@ def run_mosspectra(key,ccds,check=True,elow="350",ehigh="1100"):
|
|||||||
'ximagemax=19500','yimagemax=19500', 'ximagemin=-19499', 'yimagemin=-19499',]
|
'ximagemax=19500','yimagemax=19500', 'ximagemin=-19499', 'yimagemin=-19499',]
|
||||||
w('evselect', inargs).run()
|
w('evselect', inargs).run()
|
||||||
|
|
||||||
#d = pyds9.DS9()
|
|
||||||
#d.set("file "+unfilt_image)
|
|
||||||
#d.set('cmap bb')
|
|
||||||
#d.set('scale log')
|
|
||||||
#return
|
|
||||||
|
|
||||||
|
|
||||||
inargs = [f'eventfile={eventfile}',
|
inargs = [f'eventfile={eventfile}',
|
||||||
'withsrcrem=yes',
|
'withsrcrem=yes',
|
||||||
f'cornerfile={key}-corevc.fits',
|
f'cornerfile={key}-corevc.fits',
|
||||||
@@ -222,6 +260,11 @@ def run_mosspectra(key,ccds,check=True,elow="350",ehigh="1100"):
|
|||||||
|
|
||||||
w('mosspectra', inargs).run()
|
w('mosspectra', inargs).run()
|
||||||
|
|
||||||
|
# check coordinate conversion
|
||||||
|
#(detx,dety)=get_det_coords(arches_ra,arches_dec,f'{key}-fovimt.fits',key) # image input in X,Y
|
||||||
|
#(detx,dety)=get_det_coords(arches_ra,arches_dec,unfilt_image,key) # image input in DETX,DETY
|
||||||
|
#sys.exit()
|
||||||
|
|
||||||
|
|
||||||
def run_bkgimsky(key,elow="350",ehigh="1100"):
|
def run_bkgimsky(key,elow="350",ehigh="1100"):
|
||||||
# convert background image in det coordinates (e.g. mos1S001-bkgimdet-350-1100.fits) to sky coordinates
|
# convert background image in det coordinates (e.g. mos1S001-bkgimdet-350-1100.fits) to sky coordinates
|
||||||
@@ -233,10 +276,32 @@ def run_bkgimsky(key,elow="350",ehigh="1100"):
|
|||||||
'withdetxy=false', 'withskyxy=false',]
|
'withdetxy=false', 'withskyxy=false',]
|
||||||
w('rotdet2sky', inargs).run()
|
w('rotdet2sky', inargs).run()
|
||||||
|
|
||||||
def run_pnspectra(key,quads,check=True,elow="350",ehigh="1100"):
|
def run_pnspectra(key,quads,check=True,elow="350",ehigh="1100",pattern=0):
|
||||||
eventfile = f'{key}-allevc.fits'
|
eventfile = f'{key}-allevc.fits'
|
||||||
|
if(os.path.isfile(eventfile)==False):
|
||||||
|
print(f"{eventfile} is not found, run 01_init_events*.py and above")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# write image file with full fov
|
||||||
|
unfilt_image = eventfile.replace("allevc","ffov")
|
||||||
|
inargs = [f'table={eventfile}',
|
||||||
|
'withimageset=yes', f'imageset={unfilt_image}',
|
||||||
|
#'filtertype=expression', f'expression={expression}',
|
||||||
|
'ignorelegallimits=yes', 'imagebinning=imageSize',
|
||||||
|
'xcolumn=DETX','ycolumn=DETY','ximagesize=780','yimagesize=780',
|
||||||
|
'ximagemax=19500','yimagemax=19500', 'ximagemin=-19499', 'yimagemin=-19499',]
|
||||||
|
w('evselect', inargs).run()
|
||||||
|
|
||||||
|
if(check):
|
||||||
|
d = pyds9.DS9()
|
||||||
|
d.set("file "+unfilt_image)
|
||||||
|
d.set('cmap bb')
|
||||||
|
d.set('scale log')
|
||||||
|
#return
|
||||||
|
|
||||||
|
#(detx,dety)=get_det_coords(arches_ra,arches_dec,f'{key}-fovimt.fits',key)
|
||||||
|
(detx,dety)=get_det_coords(arches_ra,arches_dec,unfilt_image,key)
|
||||||
|
|
||||||
(detx,dety)=get_det_coords(arches_ra,arches_dec,f'{key}-fovimt.fits',key)
|
|
||||||
|
|
||||||
arches_Rmax_pix=int(np.round(arches_Rmax_as/det_pix_as))
|
arches_Rmax_pix=int(np.round(arches_Rmax_as/det_pix_as))
|
||||||
region_fn=f'{key}.txt'
|
region_fn=f'{key}.txt'
|
||||||
@@ -246,8 +311,6 @@ def run_pnspectra(key,quads,check=True,elow="350",ehigh="1100"):
|
|||||||
freg.write(f'&&{expression}\n')
|
freg.write(f'&&{expression}\n')
|
||||||
freg.close()
|
freg.close()
|
||||||
|
|
||||||
# check selected region
|
|
||||||
if(check):
|
|
||||||
unfilt_image = eventfile.replace("allevc","region")
|
unfilt_image = eventfile.replace("allevc","region")
|
||||||
inargs = [f'table={eventfile}',
|
inargs = [f'table={eventfile}',
|
||||||
'withimageset=yes', f'imageset={unfilt_image}',
|
'withimageset=yes', f'imageset={unfilt_image}',
|
||||||
@@ -257,12 +320,6 @@ def run_pnspectra(key,quads,check=True,elow="350",ehigh="1100"):
|
|||||||
'ximagemax=19500','yimagemax=19500', 'ximagemin=-19499', 'yimagemin=-19499',]
|
'ximagemax=19500','yimagemax=19500', 'ximagemin=-19499', 'yimagemin=-19499',]
|
||||||
w('evselect', inargs).run()
|
w('evselect', inargs).run()
|
||||||
|
|
||||||
#d = pyds9.DS9()
|
|
||||||
#d.set("file "+unfilt_image)
|
|
||||||
#d.set('cmap bb')
|
|
||||||
#d.set('scale log')
|
|
||||||
#return
|
|
||||||
|
|
||||||
inargs = [f'eventfile={key}-allevc.fits',
|
inargs = [f'eventfile={key}-allevc.fits',
|
||||||
'withsrcrem=yes',
|
'withsrcrem=yes',
|
||||||
f'ootevtfile={key}-allevcoot.fits',
|
f'ootevtfile={key}-allevcoot.fits',
|
||||||
@@ -274,7 +331,7 @@ def run_pnspectra(key,quads,check=True,elow="350",ehigh="1100"):
|
|||||||
'withregion=yes',
|
'withregion=yes',
|
||||||
f'regionfile={region_fn}',
|
f'regionfile={region_fn}',
|
||||||
'keepinterfiles=yes',
|
'keepinterfiles=yes',
|
||||||
'pattern=0',
|
f'pattern={pattern}',
|
||||||
f'elow={elow}',
|
f'elow={elow}',
|
||||||
f'ehigh={ehigh}',
|
f'ehigh={ehigh}',
|
||||||
f'quads="{quads}"',]
|
f'quads="{quads}"',]
|
||||||
@@ -299,11 +356,51 @@ def run_pnback(key,quads):
|
|||||||
|
|
||||||
w('pnback', inargs).run()
|
w('pnback', inargs).run()
|
||||||
|
|
||||||
def group_spectrum(key=None, group_min=25, oot=False):
|
|
||||||
|
|
||||||
|
def run_mossave(key,elow="350",ehigh="1100"):
|
||||||
|
dd=f'ffov_{key}'
|
||||||
|
create_folder(dd)
|
||||||
|
move_files(f'{key}*-{elow}-{ehigh}*',dd)
|
||||||
|
move_files(f'{key}*-{elow}-{ehigh}*',dd)
|
||||||
|
move_files(f'{key}*.pi',dd)
|
||||||
|
move_files(f'{key}*.qdp',dd)
|
||||||
|
move_files(f'{key}*.ps',dd)
|
||||||
|
move_files(f'{key}*imt*',dd)
|
||||||
|
move_files(f'{key}*.arf',dd)
|
||||||
|
move_files(f'{key}*.rmf',dd)
|
||||||
|
move_files(f'{key}*imspdet*',dd)
|
||||||
|
move_files(f'{key}*bkgimsky*',dd)
|
||||||
|
|
||||||
|
|
||||||
|
def run_pnsave(key,elow="350",ehigh="1100",pattern=0):
|
||||||
|
dd=f'ffov_{key}_{pattern}'
|
||||||
|
create_folder(dd)
|
||||||
|
move_files(f'pn*-{elow}-{ehigh}*',dd)
|
||||||
|
move_files(f'pn*-{elow}-{ehigh}*',dd)
|
||||||
|
move_files(f'pn*.pi',dd)
|
||||||
|
move_files(f'pn*.qdp',dd)
|
||||||
|
move_files(f'pn*.ps',dd)
|
||||||
|
move_files(f'pn*imt*',dd)
|
||||||
|
move_files(f'pn*.arf',dd)
|
||||||
|
move_files(f'pn*.rmf',dd)
|
||||||
|
move_files(f'pn*imspdet*',dd)
|
||||||
|
move_files(f'pn*bkgimsky*',dd)
|
||||||
|
|
||||||
|
|
||||||
|
def group_spectrum(key=None, group_min=25, oot=False, chdir=None, cpdir=None, pattern=None):
|
||||||
if not (key):
|
if not (key):
|
||||||
print("Provide key= parameter, e.g. mos1S001")
|
print("Provide key= parameter, e.g. mos1S001")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
prefix=''
|
||||||
|
try:
|
||||||
|
if(chdir):
|
||||||
|
prefix='../'
|
||||||
|
os.chdir(chdir)
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
test_exe('grppha')
|
test_exe('grppha')
|
||||||
specfile=f'{key}-fovt.pi' if not (oot) else f'{key}-fovtootsub.pi'
|
specfile=f'{key}-fovt.pi' if not (oot) else f'{key}-fovtootsub.pi'
|
||||||
backfile=f'{key}-bkg.pi'
|
backfile=f'{key}-bkg.pi'
|
||||||
@@ -311,6 +408,25 @@ def group_spectrum(key=None, group_min=25, oot=False):
|
|||||||
ancrfile=f'{key}.arf'
|
ancrfile=f'{key}.arf'
|
||||||
fout=f'{specfile}.grp'
|
fout=f'{specfile}.grp'
|
||||||
|
|
||||||
|
if(pattern!=None):
|
||||||
|
specfile0=specfile
|
||||||
|
backfile0=backfile
|
||||||
|
respfile0=respfile
|
||||||
|
ancrfile0=ancrfile
|
||||||
|
fout0=fout
|
||||||
|
|
||||||
|
specfile=f'{key}_{pattern}-fovt.pi' if not (oot) else f'{key}_{pattern}-fovtootsub.pi'
|
||||||
|
backfile=f'{key}_{pattern}-bkg.pi'
|
||||||
|
respfile=f'{key}_{pattern}.rmf'
|
||||||
|
ancrfile=f'{key}_{pattern}.arf'
|
||||||
|
fout=f'{specfile}.grp'
|
||||||
|
|
||||||
|
shutil.copyfile(specfile0, specfile)
|
||||||
|
shutil.copyfile(backfile0, backfile)
|
||||||
|
shutil.copyfile(respfile0, respfile)
|
||||||
|
shutil.copyfile(ancrfile0, ancrfile)
|
||||||
|
shutil.copyfile(fout0, fout)
|
||||||
|
|
||||||
cmd=["grppha",
|
cmd=["grppha",
|
||||||
"infile={}".format(specfile),
|
"infile={}".format(specfile),
|
||||||
"outfile={}".format(fout),
|
"outfile={}".format(fout),
|
||||||
@@ -322,13 +438,106 @@ def group_spectrum(key=None, group_min=25, oot=False):
|
|||||||
print((" ").join(cmd))
|
print((" ").join(cmd))
|
||||||
os.system((" ").join(cmd))
|
os.system((" ").join(cmd))
|
||||||
|
|
||||||
fxcm = open(fout.replace("grp","xcm"), "w")
|
with fits.open(specfile) as hdul:
|
||||||
|
header = hdul['SPECTRUM'].header
|
||||||
|
backscal = header['BACKSCAL']
|
||||||
|
area_arcmin2 = float(backscal)*(det_pix_as/60)**2
|
||||||
|
print(f"Value of BACKSCAL: {backscal} area: {area_arcmin2:.4f} arcmin2")
|
||||||
|
|
||||||
|
fout_xcm=fout.replace("grp","xcm")
|
||||||
|
fxcm = open(fout_xcm, "w")
|
||||||
|
fxcm.write(f'# backscal {backscal} pix2\n')
|
||||||
|
fxcm.write(f'# area {area_arcmin2:.8f} arcmin2\n')
|
||||||
fxcm.write(f'data {fout}\n')
|
fxcm.write(f'data {fout}\n')
|
||||||
fxcm.write('ign **-2.\n')
|
fxcm.write('ign **-2.\n')
|
||||||
fxcm.write('ign 11.-**\n')
|
fxcm.write('ign 11.-**\n')
|
||||||
fxcm.write('ign bad\n')
|
fxcm.write('ign bad\n')
|
||||||
fxcm.write('cpd /xs\n')
|
fxcm.write('cpd /xs\n')
|
||||||
fxcm.write('setpl en\n')
|
fxcm.write('setpl en\n')
|
||||||
fxcm.write('@../../../data/xspec/wabs_apec_cflux.xcm\n')
|
fxcm.write(f'@{prefix}../../../data/xspec/wabs_apec_cflux.xcm\n')
|
||||||
fxcm.write('pl lda delchi\n')
|
fxcm.write('pl lda delchi\n')
|
||||||
fxcm.close()
|
fxcm.close()
|
||||||
|
|
||||||
|
if(cpdir):
|
||||||
|
shutil.copyfile(specfile, os.path.join('../',cpdir,specfile))
|
||||||
|
shutil.copyfile(backfile, os.path.join('../',cpdir,backfile))
|
||||||
|
shutil.copyfile(respfile, os.path.join('../',cpdir,respfile))
|
||||||
|
shutil.copyfile(ancrfile, os.path.join('../',cpdir,ancrfile))
|
||||||
|
shutil.copyfile(fout, os.path.join('../',cpdir,fout))
|
||||||
|
shutil.copyfile(fout_xcm, os.path.join('../',cpdir,fout_xcm))
|
||||||
|
|
||||||
|
if(chdir):
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_ds9_regions(image, src_fn, bkg_fn):
|
||||||
|
# Visualize the image with ds9
|
||||||
|
d = pyds9.DS9()
|
||||||
|
d.set("file "+image)
|
||||||
|
d.set('cmap bb')
|
||||||
|
d.set('scale log')
|
||||||
|
#d.set(f"region {ds9reg_dir}/arches.reg")
|
||||||
|
|
||||||
|
if(os.path.isfile(src_fn)==True):
|
||||||
|
d.set(f"region {src_fn}")
|
||||||
|
else:
|
||||||
|
print(f'src_fn: {src_fn} is not found')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if(os.path.isfile(bkg_fn)==True):
|
||||||
|
d.set(f"region {bkg_fn}")
|
||||||
|
else:
|
||||||
|
print(f'bkg_fn: {bkg_fn} is not found')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
#reply = input(f"{obsid}: Proceed to make spectrum/lightcurve? [y/[n]] ")
|
||||||
|
#if reply!='y':
|
||||||
|
# continue
|
||||||
|
|
||||||
|
print(d.get("regions"))
|
||||||
|
|
||||||
|
# Extract the relevant information from the ds9 regions.
|
||||||
|
|
||||||
|
region1=(re.split("circle|annulus",d.get("regions").partition("physical")[2]))[1].replace('(','').replace(')','').replace('#',',')
|
||||||
|
region2=(re.split("circle|annulus",d.get("regions").partition("physical")[2]))[2].replace('(','').replace(')','').replace('#',',')
|
||||||
|
print("Identified first region: ", region1)
|
||||||
|
print("Identified second region: ", region2)
|
||||||
|
|
||||||
|
#print("region1 "+region1.partition("color")[2].replace('=','').replace('\n',''))
|
||||||
|
#print("region2 "+region2.partition("color")[2].replace('=','').replace('\n',''))
|
||||||
|
|
||||||
|
# Identify source and background regions using the 'white' color.
|
||||||
|
c1=region1.partition("color")[2].replace('=','').replace('\n','')
|
||||||
|
print("Region1 color: "+c1)
|
||||||
|
if(c1=='white'):
|
||||||
|
regionsrc = region1
|
||||||
|
regionbkg = region2
|
||||||
|
else:
|
||||||
|
regionsrc = region2
|
||||||
|
regionbkg = region1
|
||||||
|
|
||||||
|
# Save and print selected region coordinates.
|
||||||
|
x_source = regionsrc.split(",")[0].replace('\n','')
|
||||||
|
|
||||||
|
y_source = regionsrc.split(",")[1].replace('\n','')
|
||||||
|
r_source = regionsrc.split(",")[2].replace('\n','')
|
||||||
|
print("The coordinates of the selected source region are: \n")
|
||||||
|
print(" x_source = ", x_source, "(physical)")
|
||||||
|
print(" y_source = ", y_source, "(physical)")
|
||||||
|
print(" r_source = ", r_source, "(physical) \n")
|
||||||
|
|
||||||
|
x_bkg = regionbkg.split(",")[0].replace('\n','')
|
||||||
|
y_bkg = regionbkg.split(",")[1].replace('\n','')
|
||||||
|
r_bkg = regionbkg.split(",")[2].replace('\n','')
|
||||||
|
print("The coordinates of the selected background region are: \n")
|
||||||
|
print(" x_bkg = ", x_bkg, "(physical)")
|
||||||
|
print(" y_bkg = ", y_bkg, "(physical)")
|
||||||
|
print(" r_bkg = ", r_bkg, "(physical) \n")
|
||||||
|
|
||||||
|
# If the background is an annulus, save and print R2.
|
||||||
|
r2_bkg=None
|
||||||
|
if "annulus" in str(d.get("regions")):
|
||||||
|
r2_bkg = regionbkg.split(",")[3].replace('\n','')
|
||||||
|
print(" r2_bkg = ", r2_bkg, "(physical, annulus)")
|
||||||
|
return x_source,y_source,r_source,x_bkg,y_bkg,r_bkg,r2_bkg
|
||||||
|
|||||||
BIN
data/xspec/mos1-diag.rsp.gz
Normal file
BIN
data/xspec/mos1-diag.rsp.gz
Normal file
Binary file not shown.
BIN
data/xspec/mos2-diag.rsp.gz
Normal file
BIN
data/xspec/mos2-diag.rsp.gz
Normal file
Binary file not shown.
BIN
data/xspec/pn-diag.rsp.gz
Normal file
BIN
data/xspec/pn-diag.rsp.gz
Normal file
Binary file not shown.
1187
data/xspec/pspcc.rsp
Normal file
1187
data/xspec/pspcc.rsp
Normal file
File diff suppressed because one or more lines are too long
18
data/xspec/rass.pi
Normal file
18
data/xspec/rass.pi
Normal file
File diff suppressed because one or more lines are too long
248
data/xspec/savexspec-full.xcm
Normal file
248
data/xspec/savexspec-full.xcm
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
# to be run from ffov_spectrum
|
||||||
|
|
||||||
|
data 1:1 mos1S001-fovt.pi.grp
|
||||||
|
data 2:2 mos2S002-fovt.pi.grp
|
||||||
|
data 3:3 pnS003_4-fovt.pi.grp
|
||||||
|
data 4:4 ../../../../data/xspec/rass.pi
|
||||||
|
resp 4 ../../../../data/xspec/pspcc.rsp
|
||||||
|
|
||||||
|
ignore 1:0.0-0.3,11.0-**
|
||||||
|
ignore 2:0.0-0.3,11.0-**
|
||||||
|
ignore 3:0.0-0.4,11.0-**
|
||||||
|
ig bad
|
||||||
|
|
||||||
|
response 2:1 ../../../../data/xspec/mos1-diag.rsp.gz
|
||||||
|
response 3:2 ../../../../data/xspec/mos2-diag.rsp.gz
|
||||||
|
response 4:3 ../../../../data/xspec/pn-diag.rsp.gz
|
||||||
|
|
||||||
|
statistic chi
|
||||||
|
method leven 100 0.01
|
||||||
|
abund angr
|
||||||
|
xsect bcmc
|
||||||
|
cosmo 70 0 0.73
|
||||||
|
xset delta -1
|
||||||
|
systematic 0
|
||||||
|
model gaussian + gaussian + gaussian + gaussian + gaussian + gaussian + gaussian + constant*constant(gaussian + gaussian + gaussian + apec + (apec + apec + powerlaw)wabs + apec*wabs)
|
||||||
|
1.4914 -0.05 0 0 1e+06 1e+06
|
||||||
|
0.0075373 -0.05 0 0 10 20
|
||||||
|
0.000279721 0.01 0 0 1e+24 1e+24
|
||||||
|
1.74008 -0.05 0 0 1e+06 1e+06
|
||||||
|
4.81313e-07 -0.05 0 0 10 20
|
||||||
|
0.000105 0.01 0 0 1e+24 1e+24
|
||||||
|
7.1 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
8.2 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
8.5 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
7.9 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
7.5 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
1.11638 0.01 0 0 1e+10 1e+10
|
||||||
|
503.173 -0.01 0 0 1e+10 1e+10
|
||||||
|
0.56 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
3.6986e-07 0.01 0 0 1e+24 1e+24
|
||||||
|
0.65 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
2.21088e-07 0.01 0 0 1e+24 1e+24
|
||||||
|
5.33663 0.05 0 0 1e+06 1e+06
|
||||||
|
1.82133 0.05 0 0 10 20
|
||||||
|
1.61981e-06 0.01 0 0 1e+24 1e+24
|
||||||
|
0.100163 0.01 0.008 0.008 64 64
|
||||||
|
1 -0.001 0 0 5 5
|
||||||
|
0 -0.001 0 0 2 2
|
||||||
|
3.00942e-06 0.01 0 0 1e+24 1e+24
|
||||||
|
0.1 -0.01 0.008 0.008 64 64
|
||||||
|
1 -0.001 0 0 5 5
|
||||||
|
0 -0.001 0 0 2 2
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
0.328221 0.01 0.008 0.008 64 64
|
||||||
|
1 -0.001 0 0 5 5
|
||||||
|
0 -0.001 0 0 2 2
|
||||||
|
4.54837e-07 0.01 0 0 1e+24 1e+24
|
||||||
|
1.46 -0.01 -3 -2 9 10
|
||||||
|
8.3844e-07 0.01 0 0 1e+24 1e+24
|
||||||
|
0.012 -0.001 0 0 100000 1e+06
|
||||||
|
4.22556 0.01 0.008 0.008 64 64
|
||||||
|
0.347165 0.001 0 0 5 5
|
||||||
|
0.0616234 0.001 0 0 2 2
|
||||||
|
0.000142354 0.01 0 0 1e+24 1e+24
|
||||||
|
= 47
|
||||||
|
= 1
|
||||||
|
= 2
|
||||||
|
0.000292855 0.01 0 0 1e+24 1e+24
|
||||||
|
= 4
|
||||||
|
= 5
|
||||||
|
0.000101956 0.01 0 0 1e+24 1e+24
|
||||||
|
= 7
|
||||||
|
= 8
|
||||||
|
= 9
|
||||||
|
= 10
|
||||||
|
= 11
|
||||||
|
= 12
|
||||||
|
= 13
|
||||||
|
= 14
|
||||||
|
= 15
|
||||||
|
= 16
|
||||||
|
= 17
|
||||||
|
= 18
|
||||||
|
= 19
|
||||||
|
= 20
|
||||||
|
= 21
|
||||||
|
1 -0.01 0 0 1e+10 1e+10
|
||||||
|
577.659 -0.01 0 0 1e+10 1e+10
|
||||||
|
= 24
|
||||||
|
= 25
|
||||||
|
= 26
|
||||||
|
= 27
|
||||||
|
= 28
|
||||||
|
= 29
|
||||||
|
= 30
|
||||||
|
= 31
|
||||||
|
= 32
|
||||||
|
= 33
|
||||||
|
= 34
|
||||||
|
= 35
|
||||||
|
= 36
|
||||||
|
= 37
|
||||||
|
= 38
|
||||||
|
= 39
|
||||||
|
= 40
|
||||||
|
= 41
|
||||||
|
= 42
|
||||||
|
= 43
|
||||||
|
= 44
|
||||||
|
= 45
|
||||||
|
= 46
|
||||||
|
= 47
|
||||||
|
= 48
|
||||||
|
= 49
|
||||||
|
= 50
|
||||||
|
= 51
|
||||||
|
= 52
|
||||||
|
1.48448 -0.05 0 0 1e+06 1e+06
|
||||||
|
0.0151104 -0.05 0 0 10 20
|
||||||
|
5.85154e-05 0.01 0 0 1e+24 1e+24
|
||||||
|
= 4
|
||||||
|
= 5
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
7.11089 -0.05 0 0 1e+06 1e+06
|
||||||
|
0 -0.05 0 0 10 20
|
||||||
|
8.91145e-06 0.01 0 0 1e+24 1e+24
|
||||||
|
8.90831 -0.05 0 0 1e+06 1e+06
|
||||||
|
0.0671747 -0.05 0 0 10 20
|
||||||
|
0.000169762 0.01 0 0 1e+24 1e+24
|
||||||
|
8.60897 -0.05 0 0 1e+06 1e+06
|
||||||
|
0.0507249 -0.05 0 0 10 20
|
||||||
|
0.000152181 0.01 0 0 1e+24 1e+24
|
||||||
|
8.0435 -0.05 0 0 1e+06 1e+06
|
||||||
|
0.0285638 -0.05 0 0 10 20
|
||||||
|
0.000841628 0.01 0 0 1e+24 1e+24
|
||||||
|
7.48298 -0.05 0 0 1e+06 1e+06
|
||||||
|
0.0470736 -0.05 0 0 10 20
|
||||||
|
0.000112861 0.01 0 0 1e+24 1e+24
|
||||||
|
0.933568 0.01 0 0 1e+10 1e+10
|
||||||
|
571.375 -0.01 0 0 1e+10 1e+10
|
||||||
|
= 24
|
||||||
|
= 25
|
||||||
|
= 26
|
||||||
|
= 27
|
||||||
|
= 28
|
||||||
|
= 29
|
||||||
|
= 30
|
||||||
|
= 31
|
||||||
|
= 32
|
||||||
|
= 33
|
||||||
|
= 34
|
||||||
|
= 35
|
||||||
|
= 36
|
||||||
|
= 37
|
||||||
|
= 38
|
||||||
|
= 39
|
||||||
|
= 40
|
||||||
|
= 41
|
||||||
|
= 42
|
||||||
|
= 43
|
||||||
|
= 44
|
||||||
|
= 45
|
||||||
|
= 46
|
||||||
|
= 47
|
||||||
|
= 48
|
||||||
|
= 49
|
||||||
|
= 50
|
||||||
|
= 51
|
||||||
|
= 52
|
||||||
|
= 1
|
||||||
|
= 2
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 4
|
||||||
|
= 5
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 7
|
||||||
|
= 8
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 10
|
||||||
|
= 11
|
||||||
|
= 12
|
||||||
|
= 13
|
||||||
|
= 14
|
||||||
|
= 15
|
||||||
|
= 16
|
||||||
|
= 17
|
||||||
|
= 18
|
||||||
|
= 19
|
||||||
|
= 20
|
||||||
|
= 21
|
||||||
|
1 -0.01 0 0 1e+10 1e+10
|
||||||
|
1 -0.01 0 0 1e+10 1e+10
|
||||||
|
= 24
|
||||||
|
= 25
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 27
|
||||||
|
= 28
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 30
|
||||||
|
= 31
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 33
|
||||||
|
= 34
|
||||||
|
= 35
|
||||||
|
= 36
|
||||||
|
= 37
|
||||||
|
= 38
|
||||||
|
= 39
|
||||||
|
= 40
|
||||||
|
= 41
|
||||||
|
= 42
|
||||||
|
= 43
|
||||||
|
= 44
|
||||||
|
= 45
|
||||||
|
= 46
|
||||||
|
= 47
|
||||||
|
= 48
|
||||||
|
= 49
|
||||||
|
= 50
|
||||||
|
0 -0.01 0 0 1e+24 1e+24
|
||||||
|
= 52
|
||||||
|
model 2:myback1 bknpower
|
||||||
|
0.96893 0.01 -3 -2 9 10
|
||||||
|
3 -0.01 -3 -2 9 10
|
||||||
|
= myback1:1
|
||||||
|
0.126493 0.01 0 0 1e+24 1e+24
|
||||||
|
model 3:myback2 bknpower
|
||||||
|
= myback1:1
|
||||||
|
= myback1:2
|
||||||
|
= myback1:3
|
||||||
|
0.123669 0.01 0 0 1e+24 1e+24
|
||||||
|
model 4:myback3 bknpower
|
||||||
|
1.51807 0.01 -3 -2 9 10
|
||||||
|
3 -0.01 -3 -2 9 10
|
||||||
|
= myback3:1
|
||||||
|
0.364031 0.01 0 0 1e+24 1e+24
|
||||||
@@ -15,7 +15,7 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed-oot'
|
events_dir=root_path+'/data/processed-oot'
|
||||||
products_dir=root_path+'/products'
|
#products_dir=root_path+'/products'
|
||||||
|
|
||||||
create_folder(events_dir)
|
create_folder(events_dir)
|
||||||
|
|
||||||
@@ -62,11 +62,14 @@ for obsid in files:
|
|||||||
|
|
||||||
w('sasver', []).run() # print info
|
w('sasver', []).run() # print info
|
||||||
|
|
||||||
search_str=f'{work_dir}/????_{obsid}_EPN_S???_ImagingEvts_OOT.ds'
|
search_str=f'{work_dir}/????_{obsid}_EPN_S???_ImagingEvts.ds'
|
||||||
epfiles = glob.glob(search_str)
|
epfiles = glob.glob(search_str)
|
||||||
if not (epfiles):
|
if not (epfiles):
|
||||||
print('Running epproc')
|
print('*** Running epproc')
|
||||||
w('epproc', ['withoutoftime=true',]).run()
|
w('epproc', ['withoutoftime=true',]).run()
|
||||||
|
else:
|
||||||
|
print('*** Skipping epproc')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
#products_dir=root_path+'/products'
|
||||||
|
|
||||||
create_folder(events_dir)
|
create_folder(events_dir)
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
products_dir=root_path+'/products/sas'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
imos=2
|
imos=1
|
||||||
|
|
||||||
|
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
@@ -42,8 +42,10 @@ files = glob.glob(archive_dir+'/*')
|
|||||||
|
|
||||||
for obsid in files:
|
for obsid in files:
|
||||||
obsid = os.path.basename(obsid)
|
obsid = os.path.basename(obsid)
|
||||||
|
if(obsid in skip):
|
||||||
|
continue
|
||||||
|
|
||||||
work_dir = init_work_dir(obsid)
|
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||||
|
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
products_dir=root_path+'/products/sas'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
@@ -39,8 +39,10 @@ files = glob.glob(archive_dir+'/0862*')
|
|||||||
|
|
||||||
for obsid in files:
|
for obsid in files:
|
||||||
obsid = os.path.basename(obsid)
|
obsid = os.path.basename(obsid)
|
||||||
|
if(obsid in skip):
|
||||||
|
continue
|
||||||
|
|
||||||
work_dir = init_work_dir(obsid)
|
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||||
|
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
|
|
||||||
@@ -147,7 +149,7 @@ for obsid in files:
|
|||||||
pn_pi_max = 12000. # High energy range eV
|
pn_pi_max = 12000. # High energy range eV
|
||||||
pn_threshold = 0.75 # cts/sec (only used here for display purposes)
|
pn_threshold = 0.75 # cts/sec (only used here for display purposes)
|
||||||
|
|
||||||
out_LCFile = work_dir+'/EPIC_pn_FlareBKGRate.fit' # Name of the output BKG lightcurve
|
out_LCFile = work_dir+'/EPIC_PN_FlareBKGRate.fit' # Name of the output BKG lightcurve
|
||||||
|
|
||||||
# SAS Command
|
# SAS Command
|
||||||
cmd = "evselect" # SAS task to be executed
|
cmd = "evselect" # SAS task to be executed
|
||||||
@@ -241,9 +243,9 @@ for obsid in files:
|
|||||||
|
|
||||||
# Define the input and output file names
|
# Define the input and output file names
|
||||||
|
|
||||||
in_LCFile = work_dir+'/EPIC_pn_FlareBKGRate.fit' # Name of the input BKG lightcurve
|
in_LCFile = work_dir+'/EPIC_PN_FlareBKGRate.fit' # Name of the input BKG lightcurve
|
||||||
out_gti_set = work_dir+'/EPIC_pn_gti.fit' # Name of the output file containing GTI intervals
|
out_gti_set = work_dir+'/EPIC_PN_gti.fit' # Name of the output file containing GTI intervals
|
||||||
out_clean_evtFile = work_dir+'/EPIC_pn_gtiFilteredEvts.ds' # Name of the output Event file filtered by GTI
|
out_clean_evtFile = work_dir+'/EPIC_PN_gtiFilteredEvts.ds' # Name of the output Event file filtered by GTI
|
||||||
|
|
||||||
# SAS Command
|
# SAS Command
|
||||||
cmd = "tabgtigen"
|
cmd = "tabgtigen"
|
||||||
@@ -26,10 +26,10 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
products_dir=root_path+'/products/sas'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
imos=1
|
imos=2
|
||||||
|
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
|
|
||||||
@@ -41,8 +41,11 @@ files = glob.glob(archive_dir+'/*')
|
|||||||
|
|
||||||
for obsid in files:
|
for obsid in files:
|
||||||
obsid = os.path.basename(obsid)
|
obsid = os.path.basename(obsid)
|
||||||
|
if(obsid in skip):
|
||||||
|
continue
|
||||||
|
|
||||||
|
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||||
|
|
||||||
work_dir = init_work_dir(obsid)
|
|
||||||
|
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
# EPIC_pn_gtiFilteredEvts.ds EPIC_MOS2_Image_0862470501.fit
|
# EPIC_pn_gtiFilteredEvts.ds EPIC_MOS2_Image_0862470501.fit
|
||||||
@@ -50,7 +53,7 @@ for obsid in files:
|
|||||||
print(search_str)
|
print(search_str)
|
||||||
epfiles = glob.glob(search_str)
|
epfiles = glob.glob(search_str)
|
||||||
if not (epfiles):
|
if not (epfiles):
|
||||||
print("*** run 02_filter_flares_pn.py ***")
|
print("*** run 02_sas_flares_pn.py ***")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
out_IMFile = epfiles[0]
|
out_IMFile = epfiles[0]
|
||||||
@@ -26,7 +26,7 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
products_dir=root_path+'/products/sas'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
@@ -39,8 +39,10 @@ files = glob.glob(archive_dir+'/*')
|
|||||||
|
|
||||||
for obsid in files:
|
for obsid in files:
|
||||||
obsid = os.path.basename(obsid)
|
obsid = os.path.basename(obsid)
|
||||||
|
if(obsid in skip):
|
||||||
|
continue
|
||||||
|
|
||||||
work_dir = init_work_dir(obsid)
|
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||||
|
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
# EPIC_pn_gtiFilteredEvts.ds
|
# EPIC_pn_gtiFilteredEvts.ds
|
||||||
@@ -48,7 +50,7 @@ for obsid in files:
|
|||||||
print(search_str)
|
print(search_str)
|
||||||
epfiles = glob.glob(search_str)
|
epfiles = glob.glob(search_str)
|
||||||
if not (epfiles):
|
if not (epfiles):
|
||||||
print("*** run 02_filter_flares_pn.py ***")
|
print("*** run 02_sas_flares_pn.py ***")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
out_IMFile = epfiles[0]
|
out_IMFile = epfiles[0]
|
||||||
@@ -56,16 +56,27 @@ for obsid in files:
|
|||||||
run_mosspectra(key,'T T F T T F T',elow=elow,ehigh=ehigh)
|
run_mosspectra(key,'T T F T T F T',elow=elow,ehigh=ehigh)
|
||||||
run_mosback (key,'T T F T T F T')
|
run_mosback (key,'T T F T T F T')
|
||||||
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
||||||
|
run_mossave (key,elow=elow,ehigh=ehigh)
|
||||||
|
|
||||||
key='mos2S002'
|
key='mos2S002'
|
||||||
run_mosspectra(key,'T T T T T T T',elow=elow,ehigh=ehigh)
|
run_mosspectra(key,'T T T T T T T',elow=elow,ehigh=ehigh)
|
||||||
run_mosback (key,'T T T T T T T')
|
run_mosback (key,'T T T T T T T')
|
||||||
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
||||||
|
run_mossave (key,elow=elow,ehigh=ehigh)
|
||||||
|
|
||||||
key='pnS003'
|
key='pnS003'
|
||||||
run_pnspectra(key,'T T T T',elow=elow,ehigh=ehigh)
|
|
||||||
|
pattern=0
|
||||||
|
run_pnspectra(key,'T T T T',elow=elow,ehigh=ehigh,pattern=pattern)
|
||||||
run_pnback (key,'T T T T')
|
run_pnback (key,'T T T T')
|
||||||
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
||||||
|
run_pnsave (key,elow=elow,ehigh=ehigh,pattern=pattern)
|
||||||
|
|
||||||
|
pattern=4
|
||||||
|
run_pnspectra(key,'T T T T',elow=elow,ehigh=ehigh,pattern=pattern)
|
||||||
|
run_pnback (key,'T T T T')
|
||||||
|
run_bkgimsky (key,elow=elow,ehigh=ehigh)
|
||||||
|
run_pnsave (key,elow=elow,ehigh=ehigh,pattern=pattern)
|
||||||
|
|
||||||
#sys.exit()
|
#sys.exit()
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,15 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
products_dir=root_path+'/products/sas'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
imos=2
|
if len(sys.argv) > 1:
|
||||||
|
print(f"The first command-line argument is: {sys.argv[1]}")
|
||||||
|
imos=sys.argv[1]
|
||||||
|
else:
|
||||||
|
print("No command-line arguments provided. Use MOS1.")
|
||||||
|
imos=1
|
||||||
|
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
|
|
||||||
@@ -42,91 +47,32 @@ files = glob.glob(archive_dir+'/*')
|
|||||||
|
|
||||||
for obsid in files:
|
for obsid in files:
|
||||||
obsid = os.path.basename(obsid)
|
obsid = os.path.basename(obsid)
|
||||||
|
if(obsid in skip):
|
||||||
|
continue
|
||||||
|
|
||||||
work_dir = init_work_dir(obsid)
|
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||||
|
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
|
|
||||||
eventfile=f'{products_dir}/{obsid}/EPIC_MOS{imos}_gtiFilteredEvts.ds'
|
eventfile=f'{products_dir}/{obsid}/EPIC_MOS{imos}_gtiFilteredEvts.ds'
|
||||||
if(os.path.isfile(eventfile)==False):
|
if(os.path.isfile(eventfile)==False):
|
||||||
print("*** run 02_filter_flares_mos.py ***")
|
print("*** run 02_sas_flares_mos.py ***")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
# EPIC_pn_gtiFilteredEvts.ds
|
# EPIC_pn_gtiFilteredEvts.ds
|
||||||
search_str = f'{products_dir}/{obsid}/EPIC_MOS{imos}_Image_{obsid}.fit'
|
search_str = f'{products_dir}/{obsid}/EPIC_MOS{imos}_Image_{obsid}.fit'
|
||||||
print(search_str)
|
print(search_str)
|
||||||
emfiles = glob.glob(search_str)
|
emfiles = glob.glob(search_str)
|
||||||
if not (emfiles):
|
if not (emfiles):
|
||||||
print("*** run 02_filter_flares_mos.py ***")
|
print("*** run 02_sas_flares_mos.py ***")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
out_IMFile = emfiles[0]
|
out_IMFile = emfiles[0]
|
||||||
|
|
||||||
# Visualize the image with ds9
|
# Visualize the image with ds9
|
||||||
|
|
||||||
d = pyds9.DS9()
|
|
||||||
d.set("file "+out_IMFile)
|
|
||||||
d.set('cmap bb')
|
|
||||||
d.set('scale log')
|
|
||||||
#d.set(f"region {ds9reg_dir}/arches.reg")
|
|
||||||
src_fn=f'{ds9reg_dir}/{obsid}/src.reg'
|
src_fn=f'{ds9reg_dir}/{obsid}/src.reg'
|
||||||
if(os.path.isfile(src_fn)==True):
|
|
||||||
d.set(f"region {src_fn}")
|
|
||||||
bkg_fn=f'{ds9reg_dir}/{obsid}/bkg.reg'
|
bkg_fn=f'{ds9reg_dir}/{obsid}/bkg.reg'
|
||||||
if(os.path.isfile(bkg_fn)==True):
|
x_source,y_source,r_source,x_bkg,y_bkg,r_bkg,r2_bkg = get_ds9_regions(out_IMFile, src_fn, bkg_fn)
|
||||||
d.set(f"region {bkg_fn}")
|
|
||||||
|
|
||||||
reply = input(f"{obsid}: Proceed to make spectrum/lightcurve? [y/[n]] ")
|
|
||||||
|
|
||||||
if reply!='y':
|
|
||||||
continue
|
|
||||||
|
|
||||||
print(d.get("regions"))
|
|
||||||
|
|
||||||
# Extract the relevant information from the ds9 regions.
|
|
||||||
|
|
||||||
region1=(re.split("circle|annulus",d.get("regions").partition("physical")[2]))[1].replace('(','').replace(')','').replace('#',',')
|
|
||||||
region2=(re.split("circle|annulus",d.get("regions").partition("physical")[2]))[2].replace('(','').replace(')','').replace('#',',')
|
|
||||||
print("Identified first region: ", region1)
|
|
||||||
print("Identified second region: ", region2)
|
|
||||||
|
|
||||||
#print("region1 "+region1.partition("color")[2].replace('=','').replace('\n',''))
|
|
||||||
#print("region2 "+region2.partition("color")[2].replace('=','').replace('\n',''))
|
|
||||||
|
|
||||||
# Identify source and background regions using the 'white' color.
|
|
||||||
c1=region1.partition("color")[2].replace('=','').replace('\n','')
|
|
||||||
print("Region1 color: "+c1)
|
|
||||||
if(c1=='white'):
|
|
||||||
regionsrc = region1
|
|
||||||
regionbkg = region2
|
|
||||||
else:
|
|
||||||
regionsrc = region2
|
|
||||||
regionbkg = region1
|
|
||||||
|
|
||||||
# Save and print selected region coordinates.
|
|
||||||
x_source = regionsrc.split(",")[0].replace('\n','')
|
|
||||||
|
|
||||||
y_source = regionsrc.split(",")[1].replace('\n','')
|
|
||||||
r_source = regionsrc.split(",")[2].replace('\n','')
|
|
||||||
print("The coordinates of the selected source region are: \n")
|
|
||||||
print(" x_source = ", x_source, "(physical)")
|
|
||||||
print(" y_source = ", y_source, "(physical)")
|
|
||||||
print(" r_source = ", r_source, "(physical) \n")
|
|
||||||
|
|
||||||
x_bkg = regionbkg.split(",")[0].replace('\n','')
|
|
||||||
y_bkg = regionbkg.split(",")[1].replace('\n','')
|
|
||||||
r_bkg = regionbkg.split(",")[2].replace('\n','')
|
|
||||||
print("The coordinates of the selected background region are: \n")
|
|
||||||
print(" x_bkg = ", x_bkg, "(physical)")
|
|
||||||
print(" y_bkg = ", y_bkg, "(physical)")
|
|
||||||
print(" r_bkg = ", r_bkg, "(physical) \n")
|
|
||||||
|
|
||||||
# If the background is an annulus, save and print R2.
|
|
||||||
|
|
||||||
if "annulus" in str(d.get("regions")):
|
|
||||||
r2_bkg = regionbkg.split(",")[3].replace('\n','')
|
|
||||||
print(" r2_bkg = ", r2_bkg, "(physical)")
|
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
# Extract the source region light curve #
|
# Extract the source region light curve #
|
||||||
@@ -143,28 +89,20 @@ for obsid in files:
|
|||||||
# Define the output ligthcurve file name
|
# Define the output ligthcurve file name
|
||||||
in_LCSRCFile = work_dir+f'/EPIC_MOS{imos}_source_lightcurve.lc' # Name of the output source light curve
|
in_LCSRCFile = work_dir+f'/EPIC_MOS{imos}_source_lightcurve.lc' # Name of the output source light curve
|
||||||
|
|
||||||
# SAS Command
|
|
||||||
cmd = "evselect" # SAS task to be executed
|
|
||||||
|
|
||||||
# Arguments of SAS Command
|
# Arguments of SAS Command
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))&&(PI in [{mos_pi_min}:{mos_pi_max}])'
|
||||||
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))&&(PI in [{mos_pi_min}:{mos_pi_max}])' # event filter expression
|
|
||||||
inargs = [f'table={eventfile}','energycolumn=PI','withrateset=yes',f'rateset={in_LCSRCFile}',
|
inargs = [f'table={eventfile}','energycolumn=PI','withrateset=yes',f'rateset={in_LCSRCFile}',
|
||||||
f'timebinsize={lc_bin}','maketimecolumn=yes','makeratecolumn=yes',f'expression={expression}']
|
f'timebinsize={lc_bin}','maketimecolumn=yes','makeratecolumn=yes',f'expression={expression}']
|
||||||
|
|
||||||
print(" Filter expression to use: "+expression+" \n")
|
print(" Filter expression to use: "+expression+" \n")
|
||||||
print(" SAS command to be executed: "+cmd+", with arguments; \n")
|
|
||||||
# Execute the SAS task with the parameters to produce the source region light curve
|
# Execute the SAS task with the parameters to produce the source region light curve
|
||||||
w(cmd, inargs).run()
|
w("evselect", inargs).run()
|
||||||
|
|
||||||
# Inspect light curve
|
# Inspect light curve
|
||||||
|
#plt.figure(figsize=(20,8)) # Size of figure
|
||||||
plt.figure(figsize=(20,8)) # Size of figure
|
#plotLC(plt,mos_threshold[imos-1],in_LCSRCFile) # Plot source region light curve
|
||||||
|
#plt.legend()
|
||||||
plotLC(plt,mos_threshold[imos-1],in_LCSRCFile) # Plot source region light curve
|
#plt.show()
|
||||||
|
|
||||||
plt.legend()
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
# Extract the source region spectrum #
|
# Extract the source region spectrum #
|
||||||
@@ -177,49 +115,45 @@ for obsid in files:
|
|||||||
# Define the output ligthcurve file name
|
# Define the output ligthcurve file name
|
||||||
in_SPSRCFile = work_dir+f'/EPIC_MOS{imos}_source_spectrum.fits' # Name of the output source spectrum
|
in_SPSRCFile = work_dir+f'/EPIC_MOS{imos}_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
|
||||||
# SAS Command
|
|
||||||
cmd = "evselect" # SAS task to be executed
|
|
||||||
|
|
||||||
# Arguments of SAS Command
|
# Arguments of SAS Command
|
||||||
|
|
||||||
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))' # event filter expression
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))' # event filter expression
|
||||||
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPSRCFile}',
|
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPSRCFile}',
|
||||||
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
'specchannelmax=11999',f'expression={expression}']
|
'specchannelmax=11999',f'expression={expression}']
|
||||||
|
|
||||||
print(" Filter expression to use: "+expression+" \n")
|
print(" Filter expression to use: "+expression+" \n")
|
||||||
print(" SAS command to be executed: "+cmd+", with arguments; \n")
|
w("evselect", inargs).run()
|
||||||
|
|
||||||
w(cmd, inargs).run()
|
|
||||||
|
|
||||||
# Extract the background region spectrum with the same criteria
|
# Extract the background region spectrum with the same criteria
|
||||||
|
|
||||||
# Define the output ligthcurve file name
|
# Define the output ligthcurve file name
|
||||||
in_SPBKGFile = work_dir+f'/EPIC_MOS{imos}_background_spectrum.fits' # Name of the output background spectrum
|
in_SPBKGFile = work_dir+f'/EPIC_MOS{imos}_background_spectrum.fits' # Name of the output background spectrum
|
||||||
|
|
||||||
# SAS Command
|
|
||||||
cmd = "evselect" # SAS task to be executed
|
|
||||||
|
|
||||||
# Arguments of SAS Command
|
# Arguments of SAS Command
|
||||||
|
if(r2_bkg==None):
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_bkg},{y_bkg},{r_bkg}))'
|
||||||
|
else:
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN annulus({x_bkg},{y_bkg},{r_bkg},{r2_bkg}))'
|
||||||
|
|
||||||
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_bkg},{y_bkg},{r_bkg}))' # event filter expression
|
|
||||||
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPBKGFile}',
|
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPBKGFile}',
|
||||||
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
'specchannelmax=11999',f'expression={expression}']
|
'specchannelmax=11999',f'expression={expression}']
|
||||||
|
|
||||||
print(" Filter expression to use: "+expression+" \n")
|
print(" Filter expression to use: "+expression+" \n")
|
||||||
print(" SAS command to be executed: "+cmd+", with arguments; \n")
|
w("evselect", inargs).run()
|
||||||
|
|
||||||
w(cmd, inargs).run()
|
|
||||||
|
|
||||||
w("backscale", [f'spectrumset={in_SPSRCFile}',f'badpixlocation={eventfile}']).run()
|
w("backscale", [f'spectrumset={in_SPSRCFile}',f'badpixlocation={eventfile}']).run()
|
||||||
w("backscale", [f'spectrumset={in_SPBKGFile}',f'badpixlocation={eventfile}']).run()
|
w("backscale", [f'spectrumset={in_SPBKGFile}',f'badpixlocation={eventfile}']).run()
|
||||||
|
|
||||||
|
# https://www.cosmos.esa.int/web/xmm-newton/sas-thread-epic-merging
|
||||||
|
MAXENERGY=12
|
||||||
|
NBINS=1190
|
||||||
in_RESPFile = work_dir+f'/EPIC_MOS{imos}.rmf' # Name of the output redistribution
|
in_RESPFile = work_dir+f'/EPIC_MOS{imos}.rmf' # Name of the output redistribution
|
||||||
w("rmfgen", [f'spectrumset={in_SPSRCFile}',f'rmfset={in_RESPFile}']).run()
|
w("rmfgen", [f'spectrumset={in_SPSRCFile}',f'rmfset={in_RESPFile}',
|
||||||
|
'withenergybins=yes', 'energymin=0.1',
|
||||||
|
f'energymax={MAXENERGY}', f'nenergybins={NBINS}',]).run()
|
||||||
|
|
||||||
in_ARFFile = work_dir+f'/EPIC_MOS{imos}.arf' # Name of the output ancillary
|
in_ARFFile = work_dir+f'/EPIC_MOS{imos}.arf' # Name of the output ancillary
|
||||||
cmd = "arfgen" # SAS task to be executed
|
|
||||||
|
|
||||||
print(" Checking for Response File ..... \n")
|
print(" Checking for Response File ..... \n")
|
||||||
# Check if RESP file is available.
|
# Check if RESP file is available.
|
||||||
@@ -232,7 +166,7 @@ for obsid in files:
|
|||||||
# Arguments of SAS Command
|
# Arguments of SAS Command
|
||||||
inargs = [f'spectrumset={in_SPSRCFile}',f'arfset={in_ARFFile}',
|
inargs = [f'spectrumset={in_SPSRCFile}',f'arfset={in_ARFFile}',
|
||||||
'withrmfset=yes',f'rmfset={in_RESPFile}',f'badpixlocation={eventfile}','detmaptype=psf']
|
'withrmfset=yes',f'rmfset={in_RESPFile}',f'badpixlocation={eventfile}','detmaptype=psf']
|
||||||
w(cmd, inargs).run()
|
w("arfgen", inargs).run()
|
||||||
|
|
||||||
# rebin the spectra and link associated files
|
# rebin the spectra and link associated files
|
||||||
in_GRPFile = work_dir+f'/EPIC_MOS{imos}_spectrum_grp.fits' # Name of the output specgruop
|
in_GRPFile = work_dir+f'/EPIC_MOS{imos}_spectrum_grp.fits' # Name of the output specgruop
|
||||||
@@ -27,7 +27,7 @@ print("Arches root path: {}".format(root_path))
|
|||||||
|
|
||||||
archive_dir=root_path+'/data/archive'
|
archive_dir=root_path+'/data/archive'
|
||||||
events_dir=root_path+'/data/processed'
|
events_dir=root_path+'/data/processed'
|
||||||
products_dir=root_path+'/products'
|
products_dir=root_path+'/products/sas'
|
||||||
ds9reg_dir=root_path+'/data/ds9reg'
|
ds9reg_dir=root_path+'/data/ds9reg'
|
||||||
|
|
||||||
create_folder(products_dir)
|
create_folder(products_dir)
|
||||||
@@ -40,8 +40,10 @@ files = glob.glob(archive_dir+'/*')
|
|||||||
|
|
||||||
for obsid in files:
|
for obsid in files:
|
||||||
obsid = os.path.basename(obsid)
|
obsid = os.path.basename(obsid)
|
||||||
|
if(obsid in skip):
|
||||||
|
continue
|
||||||
|
|
||||||
work_dir = init_work_dir(obsid)
|
work_dir = init_work_dir(obsid, products_dir=products_dir)
|
||||||
|
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
|
|
||||||
@@ -50,7 +52,6 @@ for obsid in files:
|
|||||||
print("*** run 02_filter_flares_pn.py ***")
|
print("*** run 02_filter_flares_pn.py ***")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
# EPIC_pn_gtiFilteredEvts.ds
|
# EPIC_pn_gtiFilteredEvts.ds
|
||||||
search_str = f'{products_dir}/{obsid}/EPIC_PN_Image_{obsid}.fit'
|
search_str = f'{products_dir}/{obsid}/EPIC_PN_Image_{obsid}.fit'
|
||||||
print(search_str)
|
print(search_str)
|
||||||
@@ -62,69 +63,9 @@ for obsid in files:
|
|||||||
out_IMFile = epfiles[0]
|
out_IMFile = epfiles[0]
|
||||||
|
|
||||||
# Visualize the image with ds9
|
# Visualize the image with ds9
|
||||||
|
|
||||||
d = pyds9.DS9()
|
|
||||||
d.set("file "+out_IMFile)
|
|
||||||
d.set('cmap bb')
|
|
||||||
d.set('scale log')
|
|
||||||
#d.set(f"region {ds9reg_dir}/arches.reg")
|
|
||||||
src_fn=f'{ds9reg_dir}/{obsid}/src.reg'
|
src_fn=f'{ds9reg_dir}/{obsid}/src.reg'
|
||||||
if(os.path.isfile(src_fn)==True):
|
|
||||||
d.set(f"region {src_fn}")
|
|
||||||
bkg_fn=f'{ds9reg_dir}/{obsid}/bkg.reg'
|
bkg_fn=f'{ds9reg_dir}/{obsid}/bkg.reg'
|
||||||
if(os.path.isfile(bkg_fn)==True):
|
x_source,y_source,r_source,x_bkg,y_bkg,r_bkg,r2_bkg = get_ds9_regions(out_IMFile, src_fn, bkg_fn)
|
||||||
d.set(f"region {bkg_fn}")
|
|
||||||
|
|
||||||
reply = input(f"{obsid}: Proceed to make spectrum/lightcurve? [y/[n]] ")
|
|
||||||
|
|
||||||
if reply!='y':
|
|
||||||
continue
|
|
||||||
|
|
||||||
print(d.get("regions"))
|
|
||||||
|
|
||||||
# Extract the relevant information from the ds9 regions.
|
|
||||||
|
|
||||||
region1=(re.split("circle|annulus",d.get("regions").partition("physical")[2]))[1].replace('(','').replace(')','').replace('#',',')
|
|
||||||
region2=(re.split("circle|annulus",d.get("regions").partition("physical")[2]))[2].replace('(','').replace(')','').replace('#',',')
|
|
||||||
print("Identified first region: ", region1)
|
|
||||||
print("Identified second region: ", region2)
|
|
||||||
|
|
||||||
#print("region1 "+region1.partition("color")[2].replace('=','').replace('\n',''))
|
|
||||||
#print("region2 "+region2.partition("color")[2].replace('=','').replace('\n',''))
|
|
||||||
|
|
||||||
# Identify source and background regions using the 'white' color.
|
|
||||||
c1=region1.partition("color")[2].replace('=','').replace('\n','')
|
|
||||||
print("Region1 color: "+c1)
|
|
||||||
if(c1=='white'):
|
|
||||||
regionsrc = region1
|
|
||||||
regionbkg = region2
|
|
||||||
else:
|
|
||||||
regionsrc = region2
|
|
||||||
regionbkg = region1
|
|
||||||
|
|
||||||
# Save and print selected region coordinates.
|
|
||||||
x_source = regionsrc.split(",")[0].replace('\n','')
|
|
||||||
|
|
||||||
y_source = regionsrc.split(",")[1].replace('\n','')
|
|
||||||
r_source = regionsrc.split(",")[2].replace('\n','')
|
|
||||||
print("The coordinates of the selected source region are: \n")
|
|
||||||
print(" x_source = ", x_source, "(physical)")
|
|
||||||
print(" y_source = ", y_source, "(physical)")
|
|
||||||
print(" r_source = ", r_source, "(physical) \n")
|
|
||||||
|
|
||||||
x_bkg = regionbkg.split(",")[0].replace('\n','')
|
|
||||||
y_bkg = regionbkg.split(",")[1].replace('\n','')
|
|
||||||
r_bkg = regionbkg.split(",")[2].replace('\n','')
|
|
||||||
print("The coordinates of the selected background region are: \n")
|
|
||||||
print(" x_bkg = ", x_bkg, "(physical)")
|
|
||||||
print(" y_bkg = ", y_bkg, "(physical)")
|
|
||||||
print(" r_bkg = ", r_bkg, "(physical) \n")
|
|
||||||
|
|
||||||
# If the background is an annulus, save and print R2.
|
|
||||||
|
|
||||||
if "annulus" in str(d.get("regions")):
|
|
||||||
r2_bkg = regionbkg.split(",")[3].replace('\n','')
|
|
||||||
print(" r2_bkg = ", r2_bkg, "(physical)")
|
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
# Extract the source region light curve #
|
# Extract the source region light curve #
|
||||||
@@ -156,13 +97,10 @@ for obsid in files:
|
|||||||
w(cmd, inargs).run()
|
w(cmd, inargs).run()
|
||||||
|
|
||||||
# Inspect light curve
|
# Inspect light curve
|
||||||
|
#plt.figure(figsize=(20,8)) # Size of figure
|
||||||
plt.figure(figsize=(20,8)) # Size of figure
|
#plotLC(plt,pn_threshold,in_LCSRCFile) # Plot source region light curve
|
||||||
|
#plt.legend()
|
||||||
plotLC(plt,pn_threshold,in_LCSRCFile) # Plot source region light curve
|
#plt.show()
|
||||||
|
|
||||||
plt.legend()
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
# Extract the source region spectrum #
|
# Extract the source region spectrum #
|
||||||
@@ -179,8 +117,7 @@ for obsid in files:
|
|||||||
cmd = "evselect" # SAS task to be executed
|
cmd = "evselect" # SAS task to be executed
|
||||||
|
|
||||||
# Arguments of SAS Command
|
# Arguments of SAS Command
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))'
|
||||||
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))' # event filter expression
|
|
||||||
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPSRCFile}',
|
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPSRCFile}',
|
||||||
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
'specchannelmax=20479',f'expression={expression}']
|
'specchannelmax=20479',f'expression={expression}']
|
||||||
@@ -199,10 +136,13 @@ for obsid in files:
|
|||||||
cmd = "evselect" # SAS task to be executed
|
cmd = "evselect" # SAS task to be executed
|
||||||
|
|
||||||
# Arguments of SAS Command
|
# Arguments of SAS Command
|
||||||
|
if(r2_bkg==None):
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_bkg},{y_bkg},{r_bkg}))'
|
||||||
|
else:
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN annulus({x_bkg},{y_bkg},{r_bkg},{r2_bkg}))'
|
||||||
|
|
||||||
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_bkg},{y_bkg},{r_bkg}))' # event filter expression
|
|
||||||
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPBKGFile}',
|
inargs = [f'table={eventfile}','withspectrumset=yes',f'spectrumset={in_SPBKGFile}',
|
||||||
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
'energycolumn=PI','spectralbinsize=5','specchannelmin=0',#'withspecranges=yes',
|
||||||
'specchannelmax=20479',f'expression={expression}']
|
'specchannelmax=20479',f'expression={expression}']
|
||||||
|
|
||||||
print(" Filter expression to use: "+expression+" \n")
|
print(" Filter expression to use: "+expression+" \n")
|
||||||
@@ -213,8 +153,13 @@ for obsid in files:
|
|||||||
w("backscale", [f'spectrumset={in_SPSRCFile}',f'badpixlocation={eventfile}']).run()
|
w("backscale", [f'spectrumset={in_SPSRCFile}',f'badpixlocation={eventfile}']).run()
|
||||||
w("backscale", [f'spectrumset={in_SPBKGFile}',f'badpixlocation={eventfile}']).run()
|
w("backscale", [f'spectrumset={in_SPBKGFile}',f'badpixlocation={eventfile}']).run()
|
||||||
|
|
||||||
|
# https://www.cosmos.esa.int/web/xmm-newton/sas-thread-epic-merging
|
||||||
|
MAXENERGY=15
|
||||||
|
NBINS=1490
|
||||||
in_RESPFile = work_dir+'/EPIC_PN.rmf' # Name of the output redistribution
|
in_RESPFile = work_dir+'/EPIC_PN.rmf' # Name of the output redistribution
|
||||||
w("rmfgen", [f'spectrumset={in_SPSRCFile}',f'rmfset={in_RESPFile}']).run()
|
w("rmfgen", [f'spectrumset={in_SPSRCFile}',f'rmfset={in_RESPFile}',
|
||||||
|
'withenergybins=yes', 'energymin=0.1',
|
||||||
|
f'energymax={MAXENERGY}', f'nenergybins={NBINS}',]).run()
|
||||||
|
|
||||||
in_ARFFile = work_dir+'/EPIC_PN.arf' # Name of the output ancillary
|
in_ARFFile = work_dir+'/EPIC_PN.arf' # Name of the output ancillary
|
||||||
cmd = "arfgen" # SAS task to be executed
|
cmd = "arfgen" # SAS task to be executed
|
||||||
@@ -48,10 +48,19 @@ for obsid in files:
|
|||||||
print(f"\n*** jump to {work_dir} ***\n")
|
print(f"\n*** jump to {work_dir} ***\n")
|
||||||
os.chdir(work_dir)
|
os.chdir(work_dir)
|
||||||
|
|
||||||
group_spectrum(key='mos1S001')
|
dd='ffov_spectrum'
|
||||||
group_spectrum(key='mos2S002')
|
create_folder(dd)
|
||||||
group_spectrum(key='pnS003')
|
|
||||||
group_spectrum(key='pnS003',oot=True)
|
group_spectrum(key='mos1S001',chdir='ffov_mos1S001',cpdir=dd)
|
||||||
|
group_spectrum(key='mos2S002',chdir='ffov_mos2S002',cpdir=dd)
|
||||||
|
|
||||||
|
pattern=0
|
||||||
|
group_spectrum(key='pnS003',oot=True,chdir=f'ffov_pnS003_{pattern}',cpdir=dd,pattern=pattern)
|
||||||
|
group_spectrum(key='pnS003',oot=False,chdir=f'ffov_pnS003_{pattern}',cpdir=dd,pattern=pattern)
|
||||||
|
|
||||||
|
pattern=4
|
||||||
|
group_spectrum(key='pnS003',oot=True,chdir=f'ffov_pnS003_{pattern}',cpdir=dd,pattern=pattern)
|
||||||
|
group_spectrum(key='pnS003',oot=False,chdir=f'ffov_pnS003_{pattern}',cpdir=dd,pattern=pattern)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
132
scripts/05_sas_spectrum_merge.py
Executable file
132
scripts/05_sas_spectrum_merge.py
Executable file
@@ -0,0 +1,132 @@
|
|||||||
|
#!/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'
|
||||||
|
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)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Combine MOS1+2
|
||||||
|
#
|
||||||
|
|
||||||
|
spec=[]
|
||||||
|
bkg=[]
|
||||||
|
resp=[]
|
||||||
|
arf=[]
|
||||||
|
for imos in [1,2]:
|
||||||
|
in_SPSRCFile = work_dir+f'/EPIC_MOS{imos}_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
in_SPBKGFile = work_dir+f'/EPIC_MOS{imos}_background_spectrum.fits' # Name of the output background spectrum
|
||||||
|
in_RESPFile = work_dir+f'/EPIC_MOS{imos}.rmf' # Name of the output redistribution
|
||||||
|
in_ARFFile = work_dir+f'/EPIC_MOS{imos}.arf' # Name of the output ancillary
|
||||||
|
spec.append(in_SPSRCFile)
|
||||||
|
bkg.append(in_SPBKGFile)
|
||||||
|
resp.append(in_RESPFile)
|
||||||
|
arf.append(in_ARFFile)
|
||||||
|
|
||||||
|
in_spec=" ".join(spec)
|
||||||
|
in_bkg=" ".join(bkg)
|
||||||
|
in_resp=" ".join(resp)
|
||||||
|
in_arf=" ".join(arf)
|
||||||
|
|
||||||
|
out_SPSRCFile = work_dir+f'/EPIC_MOS_merged_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
out_SPBKGFile = work_dir+f'/EPIC_MOS_merged_background_spectrum.fits' # Name of the output background spectrum
|
||||||
|
out_RESPFile = work_dir+f'/EPIC_MOS_merged.rmf' # Name of the output redistribution
|
||||||
|
out_ARFFile = work_dir+f'/EPIC_MOS_merged.arf' # Name of the output ancillary
|
||||||
|
|
||||||
|
inargs = [f'pha=\"{in_spec}\"',f'bkg={in_bkg}',
|
||||||
|
f'rmf=\"{in_resp}\"',f'arf=\"{in_arf}\"',
|
||||||
|
f'allowHEdiff=yes',
|
||||||
|
f'filepha={out_SPSRCFile}',
|
||||||
|
f'filebkg={out_SPBKGFile}',
|
||||||
|
f'filersp={out_RESPFile}']
|
||||||
|
|
||||||
|
w("epicspeccombine", inargs).run()
|
||||||
|
|
||||||
|
# rebin the spectra and link associated files
|
||||||
|
in_GRPFile = work_dir+f'/EPIC_MOS_merged_spectrum_grp.fits' # Name of the output specgruop
|
||||||
|
inargs = [f'spectrumset={out_SPSRCFile}','mincounts=30','oversample=3',
|
||||||
|
f'rmfset={out_RESPFile}',
|
||||||
|
f'backgndset={out_SPBKGFile}',f'groupedset={in_GRPFile}']
|
||||||
|
w("specgroup", inargs).run()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Combine MOS1,2+PN
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
in_SPSRCFile = work_dir+f'/EPIC_PN_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
in_SPBKGFile = work_dir+f'/EPIC_PN_background_spectrum.fits' # Name of the output background spectrum
|
||||||
|
in_RESPFile = work_dir+f'/EPIC_PN.rmf' # Name of the output redistribution
|
||||||
|
in_ARFFile = work_dir+f'/EPIC_PN.arf' # Name of the output ancillary
|
||||||
|
|
||||||
|
spec.append(work_dir+f'/EPIC_PN_source_spectrum.fits')
|
||||||
|
bkg.append(work_dir+f'/EPIC_PN_background_spectrum.fits')
|
||||||
|
resp.append(work_dir+f'/EPIC_PN.rmf')
|
||||||
|
arf.append(work_dir+f'/EPIC_PN.arf')
|
||||||
|
|
||||||
|
in_spec=" ".join(spec)
|
||||||
|
in_bkg=" ".join(bkg)
|
||||||
|
in_resp=" ".join(resp)
|
||||||
|
in_arf=" ".join(arf)
|
||||||
|
|
||||||
|
out_SPSRCFile = work_dir+f'/EPIC_merged_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
out_SPBKGFile = work_dir+f'/EPIC_merged_background_spectrum.fits' # Name of the output background spectrum
|
||||||
|
out_RESPFile = work_dir+f'/EPIC_merged.rmf' # Name of the output redistribution
|
||||||
|
out_ARFFile = work_dir+f'/EPIC_merged.arf' # Name of the output ancillary
|
||||||
|
|
||||||
|
inargs = [f'pha=\"{in_spec}\"',f'bkg={in_bkg}',
|
||||||
|
f'rmf=\"{in_resp}\"',f'arf=\"{in_arf}\"',
|
||||||
|
f'allowHEdiff=yes',
|
||||||
|
f'filepha={out_SPSRCFile}',
|
||||||
|
f'filebkg={out_SPBKGFile}',
|
||||||
|
f'filersp={out_RESPFile}']
|
||||||
|
w("epicspeccombine", inargs).run()
|
||||||
|
|
||||||
|
# rebin the spectra and link associated files
|
||||||
|
in_GRPFile = work_dir+f'/EPIC_merged_spectrum_grp.fits' # Name of the output specgruop
|
||||||
|
inargs = [f'spectrumset={out_SPSRCFile}','mincounts=30','oversample=3',
|
||||||
|
f'rmfset={out_RESPFile}',
|
||||||
|
f'backgndset={out_SPBKGFile}',f'groupedset={in_GRPFile}']
|
||||||
|
w("specgroup", inargs).run()
|
||||||
88
scripts/06_esas_protonscale.py
Executable file
88
scripts/06_esas_protonscale.py
Executable file
@@ -0,0 +1,88 @@
|
|||||||
|
#!/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 pyds9
|
||||||
|
|
||||||
|
import arches
|
||||||
|
from arches.utils import *
|
||||||
|
from arches.config import *
|
||||||
|
|
||||||
|
root_path=dirname(dirname(dirname(inspect.getfile(arches))))
|
||||||
|
print("Root path: {}".format(root_path))
|
||||||
|
|
||||||
|
archive_dir=root_path+'/data/archive'
|
||||||
|
events_dir=root_path+'/data/processed'
|
||||||
|
events_oot_dir=root_path+'/data/processed-oot'
|
||||||
|
products_dir=root_path+'/products/esas'
|
||||||
|
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)
|
||||||
|
print(f"\n*** jump to {work_dir} ***\n")
|
||||||
|
os.chdir(work_dir)
|
||||||
|
|
||||||
|
|
||||||
|
key="mos1S001"
|
||||||
|
os.chdir(f'ffov_{key}')
|
||||||
|
inargs = [f'maskfile={key}-fovimspdet.fits',
|
||||||
|
f'specfile={key}-fovt.pi',
|
||||||
|
'mode=1',]
|
||||||
|
w('protonscale', inargs).run()
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
key="mos2S002"
|
||||||
|
os.chdir(f'ffov_{key}')
|
||||||
|
inargs = [f'maskfile={key}-fovimspdet.fits',
|
||||||
|
f'specfile={key}-fovt.pi',
|
||||||
|
'mode=1',]
|
||||||
|
w('protonscale', inargs).run()
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
key="pnS003"
|
||||||
|
os.chdir(f'ffov_{key}_0')
|
||||||
|
inargs = [f'maskfile={key}-fovimspdet.fits',
|
||||||
|
f'specfile={key}-fovt.pi',
|
||||||
|
'mode=1',]
|
||||||
|
w('protonscale', inargs).run()
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
key="pnS003"
|
||||||
|
os.chdir(f'ffov_{key}_4')
|
||||||
|
inargs = [f'maskfile={key}-fovimspdet.fits',
|
||||||
|
f'specfile={key}-fovt.pi',
|
||||||
|
'mode=1',]
|
||||||
|
w('protonscale', inargs).run()
|
||||||
|
os.chdir('../')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
191
scripts/06_sas_QPB.py
Executable file
191
scripts/06_sas_QPB.py
Executable file
@@ -0,0 +1,191 @@
|
|||||||
|
#!/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'
|
||||||
|
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)
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
#
|
||||||
|
# How to use the FWC event files for spectra generation
|
||||||
|
#
|
||||||
|
src_fn=f'{ds9reg_dir}/{obsid}/src.reg'
|
||||||
|
bkg_fn=f'{ds9reg_dir}/{obsid}/bkg.reg'
|
||||||
|
x_source,y_source,r_source,x_bkg,y_bkg,r_bkg,r2_bkg = get_ds9_regions(sci_image, src_fn, bkg_fn)
|
||||||
|
|
||||||
|
######################################
|
||||||
|
# Extract the source region spectrum #
|
||||||
|
######################################
|
||||||
|
|
||||||
|
# Define some parameters for filtering the event file
|
||||||
|
q_flag = "#XMMEA_EP" if (key=='PN') else "#XMMEA_EM" # Quality flag for EPIC pn
|
||||||
|
n_pattern = 4 if (key=='PN') else 12 # Pattern selection
|
||||||
|
|
||||||
|
# for the source region of the science exposure
|
||||||
|
sci_spec_file = work_dir+f'/EPIC_{key}_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))'
|
||||||
|
inargs = [f'table={sci_clean}','withspectrumset=yes',f'spectrumset={sci_spec_file}',
|
||||||
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
|
'specchannelmax=11999',f'expression={expression}']
|
||||||
|
w("evselect", inargs).run()
|
||||||
|
|
||||||
|
# for the background region of the science exposure
|
||||||
|
sci_bkg_file = work_dir+f'/EPIC_{key}_background_spectrum.fits'
|
||||||
|
if(r2_bkg==None):
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_bkg},{y_bkg},{r_bkg}))'
|
||||||
|
else:
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN annulus({x_bkg},{y_bkg},{r_bkg},{r2_bkg}))'
|
||||||
|
inargs = [f'table={sci_clean}','withspectrumset=yes',f'spectrumset={sci_bkg_file}',
|
||||||
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
|
'specchannelmax=11999',f'expression={expression}']
|
||||||
|
w("evselect", inargs).run()
|
||||||
|
|
||||||
|
# for the source region of the science exposure
|
||||||
|
qpb_spec_file = work_dir+f'/EPIC_{key}_qpb_source_spectrum.fits' # Name of the output source spectrum
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_source},{y_source},{r_source}))'
|
||||||
|
inargs = [f'table={qpb_clean}','withspectrumset=yes',f'spectrumset={qpb_spec_file}',
|
||||||
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
|
'specchannelmax=11999',f'expression={expression}', 'zcolumn=EWEIGHT',]
|
||||||
|
w("evselect", inargs).run()
|
||||||
|
|
||||||
|
# for the source region of the science exposure
|
||||||
|
qpb_bkg_file = work_dir+f'/EPIC_{key}_qpb_background_spectrum.fits' # Name of the output source spectrum
|
||||||
|
if(r2_bkg==None):
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN circle({x_bkg},{y_bkg},{r_bkg}))'
|
||||||
|
else:
|
||||||
|
expression = f'{q_flag}&&(PATTERN<={n_pattern})&&((X,Y) IN annulus({x_bkg},{y_bkg},{r_bkg},{r2_bkg}))'
|
||||||
|
inargs = [f'table={qpb_clean}','withspectrumset=yes',f'spectrumset={qpb_bkg_file}',
|
||||||
|
'energycolumn=PI','spectralbinsize=5','withspecranges=yes','specchannelmin=0',
|
||||||
|
'specchannelmax=11999',f'expression={expression}', 'zcolumn=EWEIGHT',]
|
||||||
|
w("evselect", inargs).run()
|
||||||
|
"""
|
||||||
|
By using the zcolumn parameter in the generation of the spectra for the FWC exposure,
|
||||||
|
we ensure that the produced FWC spectra are correctly scaled for the ratio of exposure times
|
||||||
|
between science and FWC exposures. By doing so, the FWC spectra are ready to be
|
||||||
|
subtracted from the science spectra.
|
||||||
|
"""
|
||||||
|
#sys.exit()
|
||||||
Reference in New Issue
Block a user