Observation object fails to read source_position when not using event_cl
Closed this issue · 0 comments
While following the Straylight Wrappers Example Notebook, with data that I processed with nupipeline while specifying 'outdir=./out' rather than 'outdir=./event_cl', I found that the Observation object was unable to read the source_position parameters from the filtered event file header.
After creating a Det1 image and source regions in ds9, I ran the following python script (from within a configured straycats conda environemnt):
from nustar_gen import wrappers, info, utils
import os
from astropy import units as u
here = os.getcwd()+'/'
obs = info.Observation(seqid='30361002002', path=here, evdir=here+'/30361002002/out', out_path='./30361002002/SL_products/')
#Take the region generated in ds9 and filter the event file to extract stray light event file:
#Below spawns another XSELECT run behind the scenes to apply the region filtering in DET1 coordinates
infileA=os.path.join(obs.evdir, 'nu30361002002A01_cl.evt')
reg_fileA = os.path.join(obs.evdir, 'srcA_withex.reg')
filt_fileA = wrappers.extract_det1_events(infileA, regfile=reg_fileA, outpath=obs.out_path)
print(filt_fileA)
#filt_file is now the full path to the extracted event file. This is located in obs.evdir by default.
#Create a nuproducts script to produce a light curve. Note this is a 3-10 keV light curve by default
time_bin = 100*u.s
lc_script = wrappers.make_det1_lightcurve(filt_fileA, mod='A', elow=3, ehigh=10, time_bin=time_bin, obs=obs)
#lc_script is now the path to the nuproducts script to produce a lightcurve, which is stored in obs.out_path.
#Creates scripts that extract the spectrum and RMF from Det1 that can be run from the command line
det1spec_fileA = wrappers.make_det1_spectra(filt_fileA, mod='A', obs=obs)
print('--> go run the light curve filtering script and spectrum filtering script, in the shell')
The extract_det1_events and make_det1_lightcurve routines run without error, but the script breaks on the make_det1_spectra routine with the following error:
File "sc_getlcandpha.py", line 39, in
det1spec_fileA = wrappers.make_det1_spectra(filt_fileA, mod='A', obs=obs)
File "/Users/mbrumback/soft/nst_gen_utils/nustar_gen/wrappers.py", line 1067, in make_det1_spectra
ra =obs.source_position.ra.deg
File "/Users/mbrumback/soft/nst_gen_utils/nustar_gen/info.py", line 306, in source_position
return self._source_position
AttributeError: 'Observation' object has no attribute '_source_position'
I checked the FITS header of the filtered event file and found it did contain RA_OBS and DEC_OBS keywords. Attempting to print obs.source_position resulted in the same Attribute Error as above.
I believe this error is related to the specification of evdir as ./out instead of ./event_cl. I reran the NuSTAR pipeline with 'outdir=./event_cl' and modified the above script to reflect this change:
from nustar_gen import wrappers, info, utils
import os
from astropy import units as u
here = os.getcwd()+'/'
obs = info.Observation(seqid='30361002002', path=here, out_path='./30361002002/tstevcl_SL_products/')
#Take the region generated in ds9 and filter the event file to extract stray light event file:
#Below spawns another XSELECT run behind the scenes to apply the region filtering in DET1 coordinates
#Now passing files in event_cl
reg_fileA = obs.path+'/'+obs.seqid+'/event_cl/srcA_withex.reg'
filt_fileA = wrappers.extract_det1_events(obs.evtfiles['A'][0], regfile=reg_fileA)
print(filt_fileA)
#filt_file is now the full path to the extracted event file. This is located in obs.evdir by default.
#Create a nuproducts script to produce a light curve. Note this is a 3-10 keV light curve by default
time_bin = 100*u.s
lc_script = wrappers.make_det1_lightcurve(filt_fileA, mod='A', elow=3, ehigh=10, time_bin=time_bin, obs=obs)
#lc_script is now the path to the nuproducts script to produce a lightcurve, which is stored in obs.out_path.
#Creates scripts that extract the spectrum and RMF from Det1 that can be run from the command line
det1spec_fileA = wrappers.make_det1_spectra(filt_fileA, mod='A', obs=obs)
print('--> go run the light curve filtering script and spectrum filtering script, in the shell')
This script ran without errors.