Examining Grating Spectra and Regions: PHA2 files
CIAO 4.12 Science Threads
An overview of displaying grating data Type II PHA files and the source and background extraction regions.
- Analysis Guide for Chandra High Resolution Spectroscopy: an in-depth discussion of grating analysis.
Last Update: 2 Apr 2019 - Show how to plot spectrum using matplotlib
- What is a PHA2 File?
- Examining the Files with Prism
- Displaying the Spectrum
- Displaying ACIS and HRC Extraction Regions
- Figure 1: ACIS-S/HETG dataset in prism
- Figure 2: ACIS-S/LETG dataset in prism
- Figure 3: HRC-S/LETG dataset in prism
- Figure 4: HRC-I/LETG dataset in prism
- Figure 5: Plot of +1 order spectrum with matplotlib
- Figure 6: +/-1 order plot in Sherpa: count rate per keV
- Figure 7: +/-1 order plot in Sherpa: counts
- Figure 8: ACIS/HETG data with source and background regions overlaid
- Figure 9: HRC-S/LETG data with bow-tie extraction region
What is a PHA2 File?
A Type II PHA file is a standard FITS format in which each row contains several columns. The PHA file is a product of standard data processing and is identified by the pha2.fits extension; note that the "2" in the filename refers to the fact that it is a level=2 data product, not that it is a Type II file. In the case that the user has to manually reprocess an event file (e.g. when applying an updated order sorting table), the PHA2 spectrum file is obtained from the level 2 event file by tgextract; see the HETG/ACIS-S Grating Spectra for an example of this.
The SPECTRUM block of a PHA2 file has 13 columns of data:
ColNo Name Description 1 SPEC_NUM Spectrum Number 2 TG_M Diffraction order (m) 3 TG_PART Spectral component (HEG, MEG, LEG, HESF parts) 4 TG_SRCID Source ID, output by tgdetect 5 X X sky coord of source 6 Y Y sky coord of source 7 CHANNEL Vector of spectral bin numbers. 8 COUNTS Counts array (a spectrum) 9 STAT_ERR Statistical uncertainty (error) on counts colum 10 BACKGROUND_UP Upper Background count vector. 11 BACKGROUND_DOWN Lower Background count vector. 12 BIN_LO Bin boundary, left edge 13 BIN_HI Bin boundary, right edge
There are two columns that are especially relevant when doing analysis:
- TG_M indicates the order of the spectrum (+/- 1, +/-2, +/- 3)
- TG_PART indicates the spectral component / grating arm (1 = HEG, 2 = MEG, 3 = LEG)
Examining the Files with Prism
Download the sample data: 459 (HETG/ACIS-S 3C 273); 460 (LETG/HRC-S, 3C 273); 1198 (LETG/ACIS-S, 3C 273); 1800 (LETG/HRC-I, PKS2155-304)
unix% download_chandra_obsid 459,460,1198,1800 evt2,pha2
ACIS-S HETG/LETG Observations
We can use prism to examine the PHA2 file for ObsID 459:
unix% prism acisf00459N004_pha2.fits &
as shown in Figure 1. In this example, there are twelve rows - all the +/- orders for both HEG and MEG - for the observation. The columns CHANNEL, COUNTS, BIN_LO, etc. are all so-called "vector columns"; each contains a vector of elements which, in this example, is 8192 elements long.
Figure 1: ACIS-S/HETG dataset in prism
An ACIS-S/LETG observation (ObsID 1198) looks similar in prism (Figure 2) but only contains 6 rows (+/- orders for the LEG).
Figure 2: ACIS-S/LETG dataset in prism
HRC-S/HRC-I LETG Observations
Examining an HRC-S/LETG observation (ObsID 460) is done in the same way as an ACIS grating observation:
unix% prism hrcf00460N005_pha2.fits &
but there is an important difference in the results. As seen in the prism display (Figure 3), there are only two rows for the LEG observation. HRC-S cannot resolve orders and the COUNTS in the +/- 1 order are in fact the total counts of all orders combined. Also, the BIN_LO and BIN_HI columns should be considered for reference only; they actually represent the boundary wavelength of the +/- 1 order alone, while photons from all orders are included in the spectra.
Figure 3: HRC-S/LETG dataset in prism
The same holds true for HRC-I/LETG observations, as seen Figure 4 in the example of ObsID 1800.
Figure 4: HRC-I/LETG dataset in prism
Displaying the Spectrum
To make it easier to display the spectrum with matplotlib we need to split out the desired row(s) with dmtype2split. The +1 order (tg_m=1) HEG (tg_part=1) spectrum for the observation, chosen by the "[tg_part=1,tg_m=1]" filter:
unix% dmtype2split "acisf00459N004_pha2.fits[tg_part=1,tg_m=1]" heg_p1.fits unix% python >>> import matplotlib.pyplot as plt >>> from pycrates import read_file >>> tab = read_file("heg_p1.fits") >>> x = tab.get_column("bin_lo").values >>> y = tab.get_column("counts").values >>> plt.plot(x,y, marker='None') >>> plt.xlabel("BIN_LO [angstrom]") >>> plt.ylabel("COUNTS [count]") >>> plt.title("ACIS+HEG order=+1") >>> plt.savefig("plt_01.png")
These commands produce the plot shown in Figure 5.
Figure 5: Plot of +1 order spectrum with matplotlib
Sherpa can also be used to plot a PHA2 spectrum. Sherpa reads all the rows and allows you to specify individual ones for plotting or fitting purposes:
unix% sherpa sherpa In : load_pha("acisf00459N004_pha2.fits") statistical errors were found in file 'acisf00459N004_pha2.fits' but not used; to use them, re-read with use_errors=True read background_up into a dataset from file acisf00459N004_pha2.fits read background_down into a dataset from file acisf00459N004_pha2.fits Multiple data sets have been input: 1-12 sherpa In : import matplotlib.pylab as plt sherpa In : set_analysis("energy") sherpa In : plot("data",4,"data",3) sherpa In : plt.savefig("rate.png")
Figure 6 shows the plot of the HEG -1 order (row 3, upper drawing area) and +1 order (row 4, lower drawing area) that is created.
To plot the data in CHANNEL vs. COUNTS:
sherpa In : set_analysis("channel") sherpa In : plot("data",4,"data",3) sherpa In : plt.savefig("counts.png")
These commands create Figure 7.
Displaying ACIS and HRC Extraction Regions
Each pha2 file has a second block, named REGION, which stores the regions used by tgextract to extract the source and background spectra.
There are three regions associated with each order: source, upper background, and lower background. For an ACIS/HETG observation, this gives 36 regions: 12 spectral components (+/- 3, +/- 2, and +/- 1 for HEG and MEG) times 3 regions apiece (source and two backgrounds).
To look at the columns of a REGION block:
unix% dmlist "acisf00459N004_pha2.fits[REGION]" cols -------------------------------------------------------------------------------- Columns for Table Block REGION -------------------------------------------------------------------------------- ColNo Name Unit Type Range 1 SPEC_NUM Int2 1:32767 Spectrum number 2 ROWID String Source or a background 3 SHAPE String Shape of region 4 TG_LAM angstrom Real4 0: 400.0 Dispersion coordinate 5 TG_D degrees Real4 -2.0: 2.0 Cross-dispersion coordinate 6 R (angstrom , degrees) Real4(2) -Inf:+Inf Raduis vector for SHAPE 7 ROTANG degrees Real4 -360.0: 360.0 Rotation angle for SHAPE 8 TG_PART Int2 0:9 Grating part index (HEG=1, MEG=2, LEG=3) 9 TG_SRCID Int2 1:32767 Source identification number 10 TG_M Int2 -62:62 Diffraction order 11 COMPONENT Int2 - Component number
ds9 cannot display these regions as they are written in the pha2 file. In order to view them, we need to rename the (TG_LAM,TG_D) columns to (X,Y) so that ds9 knows how to interpret them. We will also need to create images in (TG_LAM,TG_D) coordinates, on which we can display the regions.
The following dmcopy commands create image and region files for the 1st and 3rd orders of the MEG arm:
unix% dmcopy \ "acisf00459N004_evt2.fits[bin tg_lam=0:30:0.08,tg_d=-0.01:0.01:0.00008][tg_m=-1,1,tg_part=2]" \ 459_order1.fits opt=all unix% dmcopy \ "acisf00459N004_evt2.fits[bin tg_lam=0:15:0.08,tg_d=-0.01:0.01:0.00008][tg_m=-3,3,tg_part=2]" \ 459_order3.fits opt=all unix% dmcopy \ "acisf00459N004_pha2.fits[region][tg_m=1,tg_part=2][cols x=tg_lam,y=tg_d,*]" \ region_order1.fits opt=all unix% dmcopy \ "acisf00459N004_pha2.fits[region][tg_m=3,tg_part=2][cols x=tg_lam,y=tg_d,*]" \ region_order3.fits opt=all
In creating the images, the filter includes + and - orders to obtain more events in the image. Since the regions are the same for +/- orders, it is only necessary to copy one (the + orders were used here). The image limits are typical for ACIS/HETG observations, but will need to be adjusted for other configurations.
To display the event files with the regions overlaid:
unix% ds9 -tile 459_order1.fits -region region_order1.fits -cmap a -scale log \ 459_order3.fits -region region_order3.fits -cmap a -scale log
which produces Figure 8. We can see that all events are contained within at least one extraction region.
Figure 8: ACIS/HETG data with source and background regions overlaid
For HRC/LETG data, a bow-tie extraction region is used. Using similar dmcopy commands as for the ACIS data:
unix% dmcopy \ "hrcf00460N005_evt2.fits[bin tg_lam=0:210:0.25,tg_d=-2:2:0.0008][tg_m=-1,1,tg_part=3]" \ hrc_order1_img.fits opt=all unix% dmcopy \ "hrcf00460N005_pha2.fits[REGION][tg_m=1,tg_part=3][cols x=tg_lam,y=tg_d,*]" \ hrc_region_order1.fits opt=all
To display the file and regions:
unix% ds9 hrc_order1_img.fits -region hrc_region_order1.fits -cmap b -scale log
which produces Figure 9.
Figure 9: HRC-S/LETG data with bow-tie extraction region
|01 Jun 2004||reviewed for CIAO 3.2: no changes|
|06 Dec 2005||updated for CIAO 3.3: version numbers|
|01 Dec 2006||updated for CIAO 3.4: ChIPS and Sherpa versions|
|24 Jan 2008||updated for CIAO 4.0: updated ChIPS and Sherpa syntax|
|06 Jun 2008||added "opt=all" to dmcopy commands so all blocks are kept in the grating files|
|06 Feb 2009||updated for CIAO 4.1: prism was rewritten in GTK, so some cosmetic changes (updated all thread images); images are inline; Python and S-Lang syntax included for ChIPS and Sherpa plotting|
|14 Jan 2009||updated for CIAO 4.2: ObsID 459 file versions|
|19 Jul 2010||the S-Lang syntax has been removed from this thread as it is not supported in CIAO 4.2 Sherpa v2.|
|12 Jan 2011||reviewed for CIAO 4.3: no changes|
|01 Mar 2012||reviewed for CIAO 4.4: use dmtype2split to split a type II spectrum file before displaying it with ChIPS|
|03 Dec 2012||Review for CIAO 4.5; updated dmtype2split syntax, need to review crates changes.|
|14 Jan 2013||Completed CIAO 4.5 review, minor edits only.|
|26 Nov 2013||Reviewed for CIAO 4.6; no changes.|
|17 Dec 2014||Review for CIAO 4.7. Minor edits only.|
|02 Apr 2019||Show how to plot spectrum using matplotlib|