sherpa.astro.ui.calc_source_sum(lo=None, hi=None, id=None, bkg_id=None)

Sum up the source model over a pass band.

Sum up S(E) over a range of bins, where S(E) is the per-bin model value before it has been convolved with any instrumental response (e.g. RMF and ARF or PSF). This is intended for one-dimensional data sets: use calc_source_sum2d for two-dimensional data sets. The calc_model_sum function is used to calculate the sum of the model after any instrumental response is applied.

  • hi (lo,) – If both are None or both are set then sum up over the given band. If only one is set then use the model value in the selected bin. The units for lo and hi are given by the current analysis setting.
  • id (int or str, 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 or str, optional) – If set, use the model associated with the given background component rather than the source model.

signal – The model value (sum or individual bin).

Return type:


See also

Sum up the observed counts over a pass band.
Sum up the fitted model over a pass band.
Integrate the unconvolved source model over a pass band.
Integrate the unconvolved source model over a pass band.
Set the source model expression for a data set.


The units of lo and hi are determined by the analysis setting for the data set (e.g. get_analysis). The summation occurs over those points in the data set that lie within this range, not the range itself.

Any existing filter on the data set - e.g. as created by ignore or notice - is ignored by this function.

The units of the answer depend on the model components used in the source expression and the axis or axes of the data set.


Calculate the model evaluated over the full data set (all points or pixels of the independent axis) for the default data set, and compare it to the sum for th first background component:

>>> tsrc = calc_source_sum()
>>> tbkg = calc_source_sum(bkg_id=1)

Sum up the model over the data range 0.5 to 2 for the default data set:

>>> calc_source_sum(0.5, 2)

Compare the output of the calc_source_sum and calc_photon_flux routines. A 1099-bin data space is created, with a model which has a value of 1 for each bin. As the bin width is constant, at 0.01, the integrated value, calculated by calc_photon_flux, is one hundredth the value returned by calc_data_sum:

>>> dataspace1d(0.01, 11, 0.01, id="test")
>>> set_source("test", const1d.bflat)
>>> bflat.c0 = 1
>>> calc_source_sum(id="test")
>>> calc_photon_flux(id="test")

In the following example, a small data set is created, covering the axis range of -5 to 5, and an off-center gaussian model created (centered at 1). The model is evaluated over the full data grid and then a subset of pixels. As the summation is done over those points in the data set that lie within the requested range, the sum for lo=-2 to hi=1 is the same as that for lo=-1.5 to hi=1.5:

>>> load_arrays('test', [-5, -2.5, 0, 2.5, 5], [2, 5, 12, 7, 3])
>>> set_source('test', gauss1d.gmdl)
>>> gmdl.pos = 1
>>> gmdl.fwhm = 2.4
>>> gmdl.ampl = 10
>>> calc_source_sum(id='test')
>>> calc_source_sum(-2, 1, id='test')
>>> calc_source_sum(-1.5, 1.5, id='test')