Xtend NXB Image Generation Recipe
This page is to show an example to generate a COR-weighted image (DET and SKY) for Xtend. xtdnxbgen produces a CORTIME-weighted spectrum, and we show a procedure that is semi-equivalent.
Prerequisite and Caveats
We assume that you have installed HEASOFT 6.34, and you have installed Python and the astropy library, both of which are prerequisites of HEASOFT.
Please follow the instructions that describe how to use a single NTE event file to generate an NXB spectrum for your source. Specifically, we suppose you have produced the following files:
- Source event file (flickering pixel removed): xa123456789xtd_p0300000a0_cl2.evt
- Source event file (ehk-based and event-based selection applied): xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt
- stacked NTE event file (ehk-based selection applied): merged_rev2_nte_xtend_fullwin_gtifix_ehkSel.evt
Example of Commands
If you have not done so yet, run xtdnxbgen with event selection and All_det.reg
- xtdnxbgen infile=xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt ehkfile=xa123456789.ehk.gz regmode=DET regfile=All_det.reg innxbfile=merged_rev2_nte_xtend_fullwin_gtifix_ehkSel.evt innxbehk=merged_reduced_fix.ehk apply_xtdtools=no database=LOCAL db_location=./ timefirst=-150 timelast=+150 SORTCOL=CORTIME sortbin="6,8,10,12,99" expr="(abs(rawy-0)>=3 && abs(rawy-80)>=3 && abs(rawy-160)>=3 && abs(rawy-240)>=3 && abs(rawy-320)>=3 && abs(rawy-400)>=3 && abs(rawy-480)>=3 && abs(rawy-560)>=3) && (abs(rawy-0)>=3 && abs(rawy-35)>=3 && abs(rawy-115)>=3 && abs(rawy-195)>=3 && abs(rawy-275)>=3 && abs(rawy-355)>=3 && abs(rawy-435)>=3 && abs(rawy-515)>=3 && abs(rawy-595)>=3) && (grade==0 || grade==2 || grade==3 || grade==4 || grade==6) && status[1]==b0 && status[2]==b0 && DETY>360 && DETY<1440" outpifile=xtdnxb.pi outnxbfile=xtdnxb.evt outnxbehk=xtdnxb.ehk
Prepare COR-sorted NXB event file
- maketime 'infile=xtdnxb.ehk' 'outfile=gti.tmp' 'expr=CORTIME>=6&&CORTIME<8' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xtdnxb.evt' 'eventsout=xtdnxb_COR6-8.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- maketime 'infile=xtdnxb.ehk' 'outfile=gti.tmp' 'expr=CORTIME>=8&&CORTIME<10' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xtdnxb.evt' 'eventsout=xtdnxb_COR8-10.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- maketime 'infile=xtdnxb.ehk' 'outfile=gti.tmp' 'expr=CORTIME>=10&&CORTIME<12' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xtdnxb.evt' 'eventsout=xtdnxb_COR10-12.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- maketime 'infile=xtdnxb.ehk' 'outfile=gti.tmp' 'expr=CORTIME>=12' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xtdnxb.evt' 'eventsout=xtdnxb_COR12-.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
Check exposures of NXB event files - your numbers will differ from this example
- fkeyprint xtdnxb_COR6-8.evt EXPOSURE # 36.53 ks
- fkeyprint xtdnxb_COR8-10.evt EXPOSURE # 63.22 ks
- fkeyprint xtdnxb_COR10-12.evt EXPOSURE # 86.62 ks
- fkeyprint xtdnxb_COR12-.evt EXPOSURE # 154.89 ks
Likewise, prepare COR-sorted source event files
- maketime 'infile=xa123456789.ehk.gz' 'outfile=gti.tmp' 'expr=CORTIME>=6&&CORTIME<8' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt' 'eventsout=xtd_COR6-8.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- maketime 'infile=xa123456789.ehk.gz' 'outfile=gti.tmp' 'expr=CORTIME>=8&&CORTIME<10' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt' 'eventsout=xtd_COR8-10.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- maketime 'infile=xa123456789.ehk.gz' 'outfile=gti.tmp' 'expr=CORTIME>=10&&CORTIME<12' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt' 'eventsout=xtd_COR10-12.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- maketime 'infile=xa123456789.ehk.gz' 'outfile=gti.tmp' 'expr=CORTIME>=12' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt' 'eventsout=xtd_COR12-.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
- hk.gz' 'outfile=gti.tmp' 'expr=CORTIME>=6' 'name=-' 'value=-' 'time=TIME' 'start=START' 'stop=STOP' 'compact=no' 'prefr=0' 'postfr=1' 'clobber=yes'
- extractor 'filename=xa123456789xtd_p0300000a0_cl2_ehkSel_evSel.evt' 'eventsout=xtd_COR6-.evt' 'imgfile=NONE' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=gti.tmp' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'ecol=PI' 'xcolh=DETX' 'ycolh=DETY'
Check exposures of source event files - your numbers will differ from this example
- fkeyprint xtd_COR6-8.evt EXPOSURE # 12.86 ks
- fkeyprint xtd_COR8-10.evt EXPOSURE # 15.46 ks
- fkeyprint xtd_COR10-12.evt EXPOSURE # 16.89 ks
- fkeyprint xtd_COR12-.evt EXPOSURE # 31.35 ks
Here is the summary of exposures for this example:
CORTIME |
Data (ks) |
NXB (ks) |
6 to 8 |
12.86 |
36.53 |
8 to 10 |
15.46 |
63.22 |
10 to 12 |
16.89 |
86.62 |
>=12 |
31.35 |
154.89 |
Prepare "subsets" of NXB events so that relative exposures for each COR bin are the same between the source and NXB. Use your derived exposure values here.
- ftselect xtdnxb_COR12-.evt xtdnxb_COR12-_sel.evt '#row%100<(100*36.53/12.86*31.35/154.89)'
- ftselect xtdnxb_COR10-12.evt xtdnxb_COR10-12_sel.evt '#row%100<(100*36.53/12.86*16.89/86.62)'
- ftselect xtdnxb_COR8-10.evt xtdnxb_COR8-10_sel.evt '#row%100<(100*36.53/12.86*15.46/63.22)'
Prepare a single, COR-weighted NXB event file
- ftmerge 'xtdnxb_COR6-8.evt[EVENTS],xtdnxb_COR8-10_sel.evt[EVENTS],xtdnxb_COR10-12_sel.evt[EVENTS],xtdnxb_COR12-_sel.evt[EVENTS]' tmp.fits
- ftmerge 'tmp.fits[STDGTI],xtdnxb_COR8-10_sel.evt[STDGTI],xtdnxb_COR10-12_sel.evt[STDGTI],xtdnxb_COR12-_sel.evt[STDGTI]' xtdnxb_COR-W_COR6-.evt
Total exposure for this example should be 36.53*(31.35+16.89+15.46+12.86)/12.86=217.47 ks. Since the GTI does not report the exposure, we must update header keywords. (We also have provided a simple script; see below.) Use your total exposure time in SECONDS, not ks.
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[0]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[1]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[2]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[0]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[1]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[2]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[0]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[1]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-.evt[2]" LIVETIME
We also must modify the X and Y columns of the COR-weighted NXB event file to create a sky image, since the NXB data were taken at many combinations of RA and DEC pointings. Here we copy the source pointing information into the NXB image header.
First, check the header keywords of the source event file. (We also have provided a simple script; see below.) Your values will differ.
- fkeyprint xtd_COR6-.evt RA_OBJ # 81.258 # ext1
- fkeyprint xtd_COR6-.evt DEC_OBJ # -69.641 # ext 1
- fkeyprint xtd_COR6-.evt RA_PNT # 81.235 # ext 0 & 1
- fkeyprint xtd_COR6-.evt DEC_PNT # -69.628 # ext 0 & 1
- fkeyprint xtd_COR6-.evt RA_NOM # 81.258 # ext 0 & 1
- fkeyprint xtd_COR6-.evt DEC_NOM # -69.641 # ext 0 & 1
- fkeyprint xtd_COR6-.evt PA_NOM # 171.054 # ext 0 & 1
- fkeyprint xtd_COR6-.evt TCTYP31 # 'RA---TAN'
- fkeyprint xtd_COR6-.evt TCRPX31 # 1215.5
- fkeyprint xtd_COR6-.evt TCRVL31 # 81.258
- fkeyprint xtd_COR6-.evt TCDLT31 # -4.911e-4
- fkeyprint xtd_COR6-.evt TCTYP32 # 'DEC--TAN'
- fkeyprint xtd_COR6-.evt TCRPX32 # 1215.5
- fkeyprint xtd_COR6-.evt TCRVL32 # -69.641
- fkeyprint xtd_COR6-.evt TCDLT32 # 4.911e-4
- fkeyprint xtd_COR6-.evt OPTDETX # 722.17 # ext 0 & 1
- fkeyprint xtd_COR6-.evt OPTDETY # 703.58 # ext 0 & 1
- fkeyprint xtd_COR6-.evt OPTSKYX # 1231.54 # ext 0 & 1
- fkeyprint xtd_COR6-.evt OPTSKYY # 1240.58 # ext 0 & 1
Then update header keywords of the COR-weighted NXB event file. (We also have provided a simple script; see below.) Your values will differ.
- fparkey 81.258 "xtdnxb_COR-W_COR6-.evt[1]" RA_OBJ add=yes
- fparkey -69.641 "xtdnxb_COR-W_COR6-.evt[1]" DEC_OBJ add=yes
- fparkey 81.235 "xtdnxb_COR-W_COR6-.evt[0]" RA_PNT add=yes
- fparkey 81.235 "xtdnxb_COR-W_COR6-.evt[1]" RA_PNT add=yes
- fparkey -69.628 "xtdnxb_COR-W_COR6-.evt[0]" DEC_PNT add=yes
- fparkey -69.628 "xtdnxb_COR-W_COR6-.evt[1]" DEC_PNT add=yes
- fparkey 81.258 "xtdnxb_COR-W_COR6-.evt[0]" RA_NOM add=yes
- fparkey 81.258 "xtdnxb_COR-W_COR6-.evt[1]" RA_NOM add=yes
- fparkey -69.641 "xtdnxb_COR-W_COR6-.evt[0]" DEC_NOM add=yes
- fparkey -69.641 "xtdnxb_COR-W_COR6-.evt[1]" DEC_NOM add=yes
- fparkey 171.054 "xtdnxb_COR-W_COR6-.evt[0]" PA_NOM add=yes
- fparkey 171.054 "xtdnxb_COR-W_COR6-.evt[1]" PA_NOM add=yes
- ## somehow column names do not match btw. source and NXB event files (each NTE data in trend archive has different column name)
- fparkey 'RA---TAN' "xtdnxb_COR-W_COR6-.evt[1]" TCTYP8 add=yes
- fparkey 1215.5 "xtdnxb_COR-W_COR6-.evt[1]" TCRPX8 add=yes
- fparkey 81.258 "xtdnxb_COR-W_COR6-.evt[1]" TCRVL8 add=yes
- fparkey -4.911e-4 "xtdnxb_COR-W_COR6-.evt[1]" TCDLT8 add=yes
- fparkey 'DEC--TAN' "xtdnxb_COR-W_COR6-.evt[1]" TCTYP9 add=yes
- fparkey 1215.5 "xtdnxb_COR-W_COR6-.evt[1]" TCRPX9 add=yes
- fparkey -69.641 "xtdnxb_COR-W_COR6-.evt[1]" TCRVL9 add=yes
- fparkey 4.911e-4 "xtdnxb_COR-W_COR6-.evt[1]" TCDLT9 add=yes
For your convenience, we provide a simple script to modify the header (link). Here is an example to run this script.
Then update the X and Y columns of the COR-weighted NXB event file. The following Python commands use astropy, and you must change the numerical values to match your own observations.
- #----- python
- python
- import sys, string, math
- from astropy.io import fits
- infile = "xtdnxb_COR-W_COR6-.evt"
- outfile = "xtdnxb_COR-W_COR6-_mod.evt"
- hdu1 = fits.open(infile)
- data1 = hdu1[1].data
- detx = data1['DETX']
- dety = data1['DETY']
- ref_detx = 722.17
- ref_dety = 703.58
- rot = 171.054
- rot = rot/180.0*math.pi
- ref_x = 1231.54
- ref_y = 1240.58
- numEvent = len(detx)
- for i in range(numEvent):
- if (i%1000==0):
- print (i)
- hdu1[1].data['X'][i] = (detx[i]-ref_detx)*math.cos(rot)-(dety[i]-ref_dety)*math.sin(rot) + ref_x
- hdu1[1].data['Y'][i] = (detx[i]-ref_detx)*math.sin(rot)+(dety[i]-ref_dety)*math.cos(rot) + ref_y
- hdu1.writeto(outfile)
- sys.exit()
- #-----
Prepare COR-weighted NXB images (DET and SKY)
- extractor 'filename=xtdnxb_COR-W_COR6-.evt' 'eventsout=NONE' 'imgfile=xtdnxb_COR-W_COR6-_det.img' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=NONE' 'xcolf=DETX' 'ycolf=DETY' 'tcol=TIME'
- extractor 'filename=xtdnxb_COR-W_COR6-.evt' 'eventsout=NONE' 'imgfile=xtdnxb_COR-W_COR6-_det_bin8.img' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=NONE' 'xcolf=DETX' 'ycolf=DETY' 'tcol=TIME' 'binf=8'
- extractor 'filename=xtdnxb_COR-W_COR6-_mod.evt' 'eventsout=NONE' 'imgfile=xtdnxb_COR-W_COR6-_mod_sky_bin8.img' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=NONE' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'binf=8'
Values of ONTIME/EXPOSURE/LIVETIME are not valid. We must update header keywords of the images (COR-weighted NXB). Your values will differ.
- fparkey 217470 "xtdnxb_COR-W_COR6-_det.img[0]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det.img[1]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det.img[0]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-_det.img[1]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-_det.img[0]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det.img[1]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det_bin8.img[0]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det_bin8.img[1]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det_bin8.img[0]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-_det_bin8.img[1]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-_det_bin8.img[0]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_det_bin8.img[1]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_mod_sky_bin8.img[0]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_mod_sky_bin8.img[1]" ONTIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_mod_sky_bin8.img[0]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-_mod_sky_bin8.img[1]" EXPOSURE
- fparkey 217470 "xtdnxb_COR-W_COR6-_mod_sky_bin8.img[0]" LIVETIME
- fparkey 217470 "xtdnxb_COR-W_COR6-_mod_sky_bin8.img[1]" LIVETIME
Prepare source images. (DET and SKY)
- extractor 'filename=xtd_COR6-.evt' 'eventsout=NONE' 'imgfile=xtd_COR6-_det.img' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=NONE' 'xcolf=DETX' 'ycolf=DETY' 'tcol=TIME'
- extractor 'filename=xtd_COR6-.evt' 'eventsout=NONE' 'imgfile=xtd_COR6-_det_bin8.img' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=NONE' 'xcolf=DETX' 'ycolf=DETY' 'tcol=TIME' 'binf=8'
- extractor 'filename=xtd_COR6-.evt' 'eventsout=NONE' 'imgfile=xtd_COR6-_sky_bin8.img' 'phafile=NONE' 'fitsbinlc=NONE' 'regionfile=NONE' 'timefile=NONE' 'xcolf=X' 'ycolf=Y' 'tcol=TIME' 'binf=8'
COR-weighted Image
Here are generated DET images of an observation of N132D (left) and the derived NXB model (right). Z-axis ranges are roughly proportional to the exposure ratio.
Here are generated SKY images of the data (left) and NXB model (right). The coordinates of the NXB image look OK.