Last modified: December 2024

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

calc_source

Context: utilities

Synopsis

Calculate the per-bin source values.

Syntax

calc_source(id=None, bkg_id=None)

Description

Unlike calc_model, the values are not filtered and grouped, but the independent axis will use the analysis setting for PHA data.


Examples

Example 1

For a PHA dataset the independent axis is a pair of values, giving the low and high energies. The xlo and xhi values are in keV, and represent the low and high edges of each bin, and the yvals array will generally be in photon/cm^2/s.

>>> load_pha("3c273.pi")
>>> set_analysis("energy")
>>> notice(0.5, 6)
>>> set_source(xsphabs.gal * powlaw1d.pl)
>>> gal.nh = 0.1
>>> pl.gamma = 1.7
>>> pl.ampl = 2e-4
>>> xvals, yvals = calc_source()
>>> xlo = xvals[0]
>>> xhi = xvals[1]

Example 2

The results can be compared to the output of plot_source to show agreement:

>>> set_analysis("energy", type="rate", factor=0)
>>> plot_source()
>>> xvals, yvals = calc_source()
>>> elo, ehi = xvals
>>> plt.plot((elo + ehi) / 2, yvals / (ehi - elo))

Example 3

Changing the analysis setting changes the x values, as xvals2 is in Angstrom rather than keV (the model values are the same, although there may be small numerical differences that mean the values do not exactly match):

>>> set_analysis("wave")
>>> xvals2, yvals2 = calc_source()

Example 4

For 1D datasets the x axis is a single-element tuple:

>>> load_arrays(2, [1, 4, 7], [3, 12, 2])
>>> set_source(2, gauss1.gline)
>>> gline.pos = 4.2
>>> gline.fwhm = 3
>>> gline.ampl = 12
>>> xvals, yvals = calc_source(2)
>>> x = xvals[0]
>>> x
array([1, 4, 7])
>>> yvals
array([ 0.51187072, 11.85303595,  1.07215839])

PARAMETERS

The parameters for this function are:

Parameter Type information Definition
id int, str, or None, optional Use the source expression associated with this data set. If not given then the default identifier is used, as returned by `get_default_id` .
bkg_id int, str, or None, optional If set, use the model associated with the given background component rather than the source model.

Return value

The return value from this function is:

xvals, yvals -- The independent axis, which uses a tuple as the number of elements depends on the dimensionality and type of data. The units depends on the data type: for PHA data the X axis will be in the analysis units and Y axis will generally be photon/cm^2/s.

Changes in CIAO

Added in CIAO 4.17


Bugs

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

See Also

utilities
calc_model, calc_source_sum