Last modified: January 2016

URL: https://cxc.cfa.harvard.edu/sherpa/ahelp/save_chart_spectrum.html
AHELP for CIAO 4.16 Sherpa

save_chart_spectrum

Context: contrib

Synopsis

Write out the model spectrum in the form required by ChaRT2

Syntax

save_chart_spectrum(outfile, format="text", clobber=True, verbose=True,
id=None, elow=None, ehigh=None, ewidth=None, norm=None)

Description

The save_chart_spectrum() command writes out the current model values in the form expected by ChaRT2 (the Chandra Ray Tracer). Please see the ChaRT preparation thread for further information on how to use this routine.

Loading the routine

The routine can be loaded into Sherpa by saying:

from sherpa_contrib.chart import *

Arguments

Name Default value Description
outfile The name of the file to create. It is no longer valid to use a value of None for this argument.
format "text" The output format of the file: "text" for ASCII format, "fits" for a FITS binary table.
clobber True Determines the behavior if the output file already exists: a value of True (the default) means that the file will be overwritten, otherwise an error will be raised.
verbose True If verbose is True then a message will be printed to the standard output when the file has been created.
id None Which dataset to use: if None then the value returned by get_default_id() will be used.
elow None The minimum energy at which to evaluate the model; this parameter controls the lower edge of the lowest-energy bin, and is in keV. A value of None means to use the lowest energy bin from the ARF grid. This value should not be smaller than 0.2 keV.
ehigh None The maximum energy at which to evaluate the model; this parameter controls the upper edge of the highest-energy bin, and is in keV. A value of None means to use the highest energy bin from the ARF grid. This valus should not be larger than 10 keV.
ewidth None The bin width to use, in keV. A value of None means to use the bin width from the ARF grid.
norm None A scaling factor to allow you to easily change the overall flux of the model. A value of None is equivalent to a factor of 1; a value of 10 would create a ChaRT spectral model ten times brighter than the input model.

Examples

Example 1

sherpa> load_pha("3c273.pi")
sherpa> subtract()
sherpa> notice(0.1, 6)
sherpa> set_source(xsphabs.abs1 * powlaw1d.p1)
sherpa> abs1.nh = 0.07
sherpa> freeze(abs1)
sherpa> guess(p1)
sherpa> fit()
...
sherpa> save_chart_spectrum("chart.dat")

Here we load in a source spectrum from the file 3c273.pi, along with the associated files (e.g. ARF, RMF, and background) that are indicated in its header. The background is subtracted, the analysis restricted to the 0.1 to 6 keV range, a model is created - consisting of an absorbed power law - and then parameter values are set before the fit is made.

After the fit has been made the save_chart_spectrum() routine is used to write out the best-fit model - in a format usable by ChaRT2 - to the text file "chart.dat".

Example 2

sherpa> save_chart_spectrum("chart.dat", elow=1, ehigh=8)

In this example the output is restricted to the range 1 to 8 keV, using the default binning given by the ARF grid. Note that this energy range need not overlap the range used to fit the data (or even the energy ranges of the ARF and RMF files). It should however remain within the range 0.2 to 10 keV.

Example 3

sherpa> save_chart_spectrum("chart.fits", format="fits")

The data is written to a FITS binary table called 'chart.fits'.


Changes in the scripts 4.8.2 (January 2016) release

The routine has been updated to work with version 2 of ChART: the output now contains three columns rather than two; it can be in FITS or ASCII format; a clobber parameter has been added; and the outfile parameter can no-longer be set to None.


Bugs

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

See Also

contrib
get_chart_spectrum, plot_chart_spectrum, save_marx_spectrum, sherpa_chart
modeling
save_model, save_source
saving
restore, save, save_all, save_arrays, save_data, save_delchi, save_error, save_filter, save_grouping, save_image, save_pha, save_quality, save_resid, save_staterror, save_syserror, save_table, script