Chandra X-Ray Observatory
Skip to the navigation links
Last modified: 8 February 2018

How do I change an XSPEC xset variable?

A number of XSPEC models use "environment variables" to modify their behavior via the xset command. The set_xsxset and get_xsxset routines let you set and inspect these values from Sherpa.

The normalisation of the xspowerlaw model defaults to defining the amplitude at 1 keV, but this can be changed by setting the POW_EMIN and POW_EMAX variables, as described at the XSPEC model description. Here we show how to make these changes from within Sherpa:

% sherpa
Welcome to Sherpa: CXC's Modeling and Fitting Package
CIAO 4.8 Sherpa version 1 Thursday, December 3, 2015

sherpa-1> pl =
sherpa-2> pl.norm
           <Parameter 'norm' of model 'pl'>
sherpa-3> pl.norm.val
sherpa-4> get_xsxset("POW_EMIN")
sherpa-5> get_xsxset("POW_EMAX")
sherpa-6> ebins = np.arange(0.1,10,0.01)
sherpa-7> y1 = pl(ebins)
sherpa-9> set_xsxset("POW_EMIN", "0.5")
sherpa-10> set_xsxset("POW_EMAX", "5")
sherpa-11> y2 = pl(ebins)
sherpa-12> set_xsxset("POW_EMIN", "2")
sherpa-13> set_xsxset("POW_EMAX", "2")
sherpa-14> y3 = pl(ebins)
sherpa-15> set_xsxset("POW_EMIN", "")
sherpa-16> set_xsxset("POW_EMAX", "")

In the above, we have evaluated the pl model over the energy range 0.1 to 10 keV (with a bin width of 0.01 keV), three times:

  1. y1 uses the default settings, so it should have a flux of 1 photon/cm2/s at 1 keV;
  2. y2 has POW_EMIN set to 0.5 and POW_EMAX set to 5, so the model norm value now refers to the integrated flux over the range 0.5 to 5 keV (in units of 10-12 ergs/cm2/s);
  3. and y3 has POW_EMIN and POW_EMAX both set to 2, so the normalisation now refers to the value at 2 keV.

After evaluating the models we set the values back to their default settings. These curves can be plotted to show the change in amplitudes (note that we divide by the bin width before plotting):

sherpa-17> add_window(8,6,"inches")
sherpa-18> set_preference("", "none")
sherpa-19> add_curve(ebins, y1/0.01)
sherpa-20> add_curve(ebins, y2/0.01, ["line.color", "green"])
sherpa-21> add_curve(ebins, y3/0.01, ["line.color", "red"])
sherpa-22> log_scale()
sherpa-23> set_plot_ylabel("photon cm^{-2} s^{-1} keV^{-1}")
sherpa-24> set_yaxis(["tickformat", "%0.0z"])
sherpa-25> set_plot_xlabel("Energy (keV)")
sherpa-26> set_plot_title(r"Varying: \tt POW\_EMIN POW\_EMAX")
sherpa-27> set_axis(["label.size", 20, "ticklabel.size", 20])
sherpa-28> set_plot(["title.size", 20])
sherpa-29> set_yaxis(["offset.perpendicular", 50])

which creates the following plot:

[Three powerlaws with the same slope but different normalisations]

Last modified: 8 February 2018
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.