calc_source

sherpa.astro.ui.calc_source(id: IdType | None = None, bkg_id: IdType | None = None) tuple[tuple[np.ndarray, ...], np.ndarray]

Calculate the per-bin source values.

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

Added in version 4.17.0.

Parameters:
  • 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.

Returns:

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.

Return type:

tuple of ndarray, ndarray

Examples

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]

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))

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()

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])