|
SynopsisS-Lang function to read a spectrum in PHA format (both type I and II) SyntaxStruct_Type readpha( filename ) Error Return Value: NULL Argument: filename is a String_Type variable DescriptionThe readpha() function provides a high-level interface to reading in a spectrum stored using the PHA format - both type I and type II - described in the OGIP standard. It can be called either directly or indirectly (i.e. when using the readfile() function). The ahelp page for readfile describes the features of this routine that are common to all the "read" functions provided by the Varmm module. This page describes those features that are unique to the readpha() command. The filename argument should be a string that contains the name of the file to be read in. Although it can include Data Model filters it is best not to use them when reading in a PHA file, since any filter may well remove needed information from the file. As an example of how the function is used: chips> spec = readpha( "src.pha" ) What does the function return?The function returns a structure whose fields contain the data read in from the file. If an error occurred - such as the file not being found, or it is not in PHA format - then NULL is returned instead. The returned structure follows the format of the other "read" functions: metadata - i.e. information about the file - is stored in fields beginning with an underscore character followed by fields containing the image data and coordinate-transformation information. The initial fields are discussed in "ahelp readfile"; here we concentrate on those fields specific to PHA files. Fields for PHA-I files:
For example, here is the structure returned when a PHA-I file - with no grouping data - is read in: chips> pha = readpha("source.pha") chips> print( pha ) _filename = source.pha _path = /data/analysis/ _filter = NULL _filetype = 7 _header = String_Type[304] _exptime = 50703.3 _ncols = 11 _nrows = 1024 channels = Float_Type[1024] counts = Float_Type[1024] grouping = Integer_Type[1024] areascal = 1 backscal = 7.72066e-07 errors = Float_Type[1024] background = none arf = /data/analysis/source.arf response = /data/analysis/source.rmf numgroups = 1024 numchans = 0 The format for type-II PHA files is similar; the main changes are extra information related to the gratings and the fact that the structure now contains data for multiple spectra. Fields for PHA-II files:
For example, the following is a PHA-II file from a HETG observation. chips> pha2 = readpha("acisf00459N002_pha2.fits") chips> print( pha2 ) _filename = acisf00459N002_pha2.fits _path = /data/analysis/ _filter = NULL _filetype = 8 _header = String_Type[190] _exptime = 38564.6 _ncols = 19 _nrows = 12 channels = Float_Type[98304] counts = Float_Type[98304] grouping = Integer_Type[12,8192] binhi = Float_Type[98304] binlo = Float_Type[98304] backup = Float_Type[98304] backdown = Float_Type[98304] areascal = 1 backscal = 1 backscup = 0.222222 backscdn = 0.222222 errors = Float_Type[98304] background = String_Type[12] arf = String_Type[12] response = String_Type[12] numgroups = Integer_Type[12] numchans = Integer_Type[12] order = Integer_Type[12] tgpart = Integer_Type[12] Example 1Reading in a PHA-I file using readpha()chips> pha = readpha( "src.pi.grp" ) chips> print( pha ) _filename = src.pi.grp _path = /data/analysis/ _filter = NULL _filetype = 7 _header = String_Type[352] _exptime = 50703.3 _ncols = 12 _nrows = 1024 channels = Float_Type[127] counts = Float_Type[127] grouping = Integer_Type[1024] qualityflags = Integer_Type[127] phachans = Integer_Type[127] areascal = 1 backscal = 0.000664699 background = /data/analysis/bgnd.pi arf = /data/analysis/src.arf response = /data/analysis/src.rmf numgroups = 127 numchans = 1024 Here we read in a PHA-I file that had been grouped - i.e. it was the output of dmgroup - which is why the length of the counts array (127) does not match the number of rows in the file (1024). Example 2Reading in a PHA-I file using readfile()Since readfile() calls readpha() when given a PHA file, the following command produces the same structure as the previous example. chips> pha = readfile( "src.pi.grp" ) Example 3Reading in a PHA-II file using readarf()Here we use readpha() to read in a PHA-II file from a LETG observation using the HRC-I. chips> pha2 = readpha( "hrcf01801N003_pha2.fits" ) Warning: could not find SYS_ERR column chips> print( pha2 ) _filename = hrcf01801N003_pha2.fits _path = /data/analysis/ _filter = NULL _filetype = 8 _header = String_Type[190] _exptime = 13726.5 _ncols = 19 _nrows = 2 channels = Float_Type[32768] counts = Float_Type[32768] grouping = Integer_Type[2,16384] binhi = Float_Type[32768] binlo = Float_Type[32768] backup = Float_Type[32768] backdown = Float_Type[32768] areascal = 1 backscal = 1 backscup = 4.5 backscdn = 4.5 errors = Float_Type[32768] background = String_Type[2] arf = String_Type[2] response = String_Type[2] numgroups = Integer_Type[2] numchans = Integer_Type[2] order = Integer_Type[2] tgpart = Integer_Type[2] CHANGES IN CIAO 3.1Reading a file in a directory containing the string '::'The routines no longer crash when reading a file within a directory whose name contains the string "::". Enhanced documentationThe readpha function is now documented separately from readfile. CHANGES IN CIAO 3.0.2Stack Underflow errorsIt is now possible to use readfile() - or any of the other read functions described here - in an if statement. Prior to CIAO 3.0.2 you could not write something like if ( NULL == readfile("evt2.fits") ) error("Failed to read file."); since it would result in a "Stack Underflow" error message. This means that many routines that use readfile() - such as Sherpa's load_dataset() and related functions - can also now be used in an if statement such as: if ( 1 != load_image(imgname) ) verror( "Unable to load %s as an image.", imgname ); CHANGES IN CIAO 3.0New field "_filetype"A new field called "_filetype" has been added to the data structure which describes the type of the file read in. The contents of the field are described in the "Format of data structure" section in "ahelp readfile". BugsSee the bugs page for the Varmm library on the CIAO website for an up-to-date listing of known bugs. See Also
|
The Chandra X-Ray
Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA. Email: cxcweb@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2004. All rights reserved. |