generated from erosita/uds
242 lines
7.4 KiB
Python
Executable File
242 lines
7.4 KiB
Python
Executable File
#!/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 subprocess
|
|
|
|
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'
|
|
events_oot_dir=root_path+'/data/processed-oot'
|
|
products_dir=root_path+'/products'
|
|
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)
|
|
print(f"\n*** jump to {work_dir} ***\n")
|
|
os.chdir(work_dir)
|
|
|
|
|
|
""" energy limits for all cameras """
|
|
pi_min=1000
|
|
pi_max=10000
|
|
|
|
""" EPN """
|
|
search_str = f'{events_dir}/{obsid}/????_{obsid}_EPN_S???_ImagingEvts.ds'
|
|
epfiles = glob.glob(search_str)
|
|
if not (epfiles):
|
|
print("*** run 01_init_events.py ***")
|
|
sys.exit()
|
|
eventfile, = epfiles
|
|
unfilt_image = eventfile.replace("ImagingEvts.ds","diag-det-unfilt.fits")
|
|
expression = f'#XMMEA_EP&&(PATTERN<=4)&&(PI in [{pi_min}:{pi_max}])' # event filter expression
|
|
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()
|
|
|
|
d = pyds9.DS9()
|
|
d.set("file "+unfilt_image)
|
|
d.set('cmap bb')
|
|
d.set('scale log')
|
|
print(f"\nEPN, ObsID: {obsid}")
|
|
#user_input = input()
|
|
|
|
|
|
"""
|
|
try:
|
|
print(f"\n### espfilt EPN {obsid} ###\n")
|
|
|
|
w('espfilt', [f'eventfile={eventfile}','elow=2500','ehigh=3500','withsmoothing=yes', 'smooth=51',
|
|
'rangescale=25', 'allowsigma=2.0', 'method=histogram', 'keepinterfiles=true',
|
|
'withoot=no',]).run()
|
|
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
pass
|
|
"""
|
|
#sys.exit()
|
|
|
|
""" EPN OOT """
|
|
search_str = f'{events_oot_dir}/{obsid}/????_{obsid}_EPN_S???_ImagingEvts.ds'
|
|
epfiles = glob.glob(search_str)
|
|
if not (epfiles):
|
|
print("*** run 01_init_events.py ***")
|
|
sys.exit()
|
|
eventfile, = epfiles
|
|
unfilt_image = eventfile.replace("ImagingEvts.ds","diag-det-unfilt.fits")
|
|
expression = f'#XMMEA_EP&&(PATTERN<=4)&&(PI in [{pi_min}:{pi_max}])' # event filter expression
|
|
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()
|
|
|
|
d = pyds9.DS9()
|
|
d.set("file "+unfilt_image)
|
|
d.set('cmap bb')
|
|
d.set('scale log')
|
|
print(f"\nEPN-OOT, ObsID: {obsid}")
|
|
#user_input = input()
|
|
|
|
try:
|
|
print(f"\n### espfilt EPN-OOT {obsid} ###\n")
|
|
|
|
w('espfilt', [f'eventfile={eventfile}','elow=2500','ehigh=3500','withsmoothing=yes', 'smooth=51',
|
|
'rangescale=25', 'allowsigma=2.0', 'method=histogram', 'keepinterfiles=true',
|
|
'withoot=yes',]).run()
|
|
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
pass
|
|
|
|
sys.exit()
|
|
|
|
""" MOS1 """
|
|
imos=1
|
|
search_str=f'{events_dir}/{obsid}/????_{obsid}_EMOS{imos}_S???_ImagingEvts.ds'
|
|
emfiles = glob.glob(search_str)
|
|
print(emfiles)
|
|
if not (emfiles):
|
|
print("*** run 01_init_events.py ***")
|
|
sys.exit()
|
|
eventfile, = emfiles
|
|
unfilt_image = eventfile.replace("ImagingEvts.ds","diag-det-unfilt.fits")
|
|
expression = f'(PATTERN<=12)&&(PI in [{pi_min}:{pi_max}])&&((FLAG & 0x766aa000)==0)'
|
|
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()
|
|
|
|
try:
|
|
w('emanom', [f'eventfile={eventfile}','keepcorner=no',]).run()
|
|
except:
|
|
pass
|
|
|
|
d = pyds9.DS9()
|
|
d.set("file "+unfilt_image)
|
|
d.set('cmap bb')
|
|
d.set('scale log')
|
|
print(f"\nMOS{imos}, ObsID: {obsid}")
|
|
#user_input = input()
|
|
|
|
|
|
try:
|
|
print(f"\n### espfilt MOS{imos} {obsid} ###\n")
|
|
w('espfilt', [f'eventfile={eventfile}','elow=2500','ehigh=8500','withsmoothing=yes', 'smooth=51',
|
|
'rangescale=6.0', 'allowsigma=3.0', 'method=histogram', 'keepinterfiles=false']).run()
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
pass
|
|
|
|
|
|
|
|
""" MOS2 """
|
|
imos=2
|
|
search_str=f'{events_dir}/{obsid}/????_{obsid}_EMOS{imos}_S???_ImagingEvts.ds'
|
|
emfiles = glob.glob(search_str)
|
|
print(emfiles)
|
|
if not (emfiles):
|
|
print("*** run 01_init_events.py ***")
|
|
sys.exit()
|
|
eventfile, = emfiles
|
|
unfilt_image = eventfile.replace("ImagingEvts.ds","diag-det-unfilt.fits")
|
|
expression = f'(PATTERN<=12)&&(PI in [{pi_min}:{pi_max}])&&((FLAG & 0x766aa000)==0)'
|
|
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()
|
|
|
|
try:
|
|
w('emanom', [f'eventfile={eventfile}','keepcorner=no',]).run()
|
|
except:
|
|
pass
|
|
|
|
d = pyds9.DS9()
|
|
d.set("file "+unfilt_image)
|
|
d.set('cmap bb')
|
|
d.set('scale log')
|
|
print(f"\nMOS{imos}, ObsID: {obsid}")
|
|
#user_input = input()
|
|
|
|
try:
|
|
print(f"\n### espfilt MOS{imos} {obsid} ###\n")
|
|
w('espfilt', [f'eventfile={eventfile}','elow=2500','ehigh=8500','withsmoothing=yes', 'smooth=51',
|
|
'rangescale=6.0', 'allowsigma=3.0', 'method=histogram','keepinterfiles=false']).run()
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
pass
|
|
|
|
masks = [
|
|
"*-fovlc.fits",
|
|
"*-corev.fits",
|
|
"*-allimc.fits",
|
|
"*-allim.fits",
|
|
"*-anom.log",
|
|
"*-corlc.fits",
|
|
"*-corim.fits",
|
|
"*-corimc.fits",
|
|
"*-corevc.fits",
|
|
]
|
|
rmfiles = [file for mask in masks for file in glob.glob(mask)]
|
|
|
|
for fn in rmfiles:
|
|
print("rm ",fn)
|
|
try:
|
|
os.remove(fn)
|
|
except:
|
|
pass
|
|
#sys.exit()
|
|
|
|
|
|
|
|
|
|
|