flx2xsp - Creates spectra and response files from an input text file of fluxes and errors.


flx2xsp infile phafil rspfil xunit yunit clobber


This tool reads a text file (infile) containing one or more spectra and errors and writes out a standard PHA file (phafil) and RSP file (rspfil) which can be used in XSPEC. The response file created is a unit diagonal matrix of the appropriate size. The input text file should have one line for each bin of the spectrum. Each line should have at least four numbers. The first two should be the start and end energy (or wavelength) of the bin and the second two the flux and one sigma error. If multiple spectra are to be read then the flux and error for the second spectrum will be the fifth and sixth numbers and so forth. The bins must be contiguous i.e. the end energy (or wavelength) of one bin must be the same as the start energy (or wavelength) as the next. The nspec parameter is used to specify the number of spectra to read so the text file should have nspec*2+2 numbers per line.

The units for the energies (or wavelengths) and fluxes in the input text file can be specified using the xunit and yunit parameters. The allowed units are given below in the parameter specifications.


infile [filename]
The name of the input text file with the spectrum or spectra and errors.

phafil [filename]
The name of the output PHA file.

rspfil [filename]
The name of the output RSP file. This will be a diagonal response.

nspec [int]
The number of spectra in the input text file.

xunit [string]
The units for energy or wavelength used in the input text file. The allowed options are keV (the default), MeV, GeV, Hz, angstrom, cm, micron, or nm.

yunit [string]
The units for flux used in the input text file. The allowed options are ph/cm^2/s (the default), ph/cm^2/s/MeV, ph/cm^2/s/GeV, ph/cm^2/s/Hz, ph/cm^2/s/A, ph/cm^2/s/cm, ph/cm^2/s/um, ph/cm^2/s/nm, ergs/cm^2/s, ergs/cm^2/s/Hz, ergs/cm^2/s/A, ergs/cm^2/s/cm, ergs/cm^2/s/um, ergs/cm^2/s/nm, or Jy.

clobber [bool]
If clobber = yes then overwrite the output files if a file of the appropriate name already exists.


1. Suppose we have a single spectrum with errors which we wish to fit in XSPEC. We create an text input file, myinput.txt :
0.1 0.2  1.3 0.1
0.2 0.3  1.4 0.1
0.3 0.4  1.8 0.1
0.4 0.5  0.9 0.1
0.5 0.6  0.8 0.1
0.6 0.7  1.0 0.1
0.7 0.8  0.5 0.1
0.8 0.9  0.3 0.1
0.9 1.0  0.1 0.1
and make the files by :

flx2xsp myinput.txt myspectrum.pha myresponse.rsp



Oct 2012