calc_data_sum

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

Sum up the data values over a pass band.

Parameters:
  • lo (number, optional) – The minimum limit of the band. Use None, the default, to use the low value of the data set.
  • hi (number, optional) – The maximum limit of the band, which must be larger than lo. Use None, the default, to use the upper value of the data set.
  • 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.
Returns:

dsum – The sum of the data values that lie within the given limits. If hi is None but lo is set then the data value of the bin containing the lo value are returned. If a background estimate has been subtracted from the data set then the calculation will use the background-subtracted values.

Return type:

number

See also

calc_data_sum2d()
Sum up the data values of a 2D data set.
calc_model_sum()
Sum up the fitted model over a pass band.
calc_energy_flux()
Integrate the source model over a pass band.
calc_photon_flux()
Integrate the source model over a pass band.
calc_source_sum()
Sum up the source model over a pass band.
set_model()
Set the source model expression for a data set.

Notes

The units of lo and hi are determined by the analysis setting for the data set (e.g. get_analysis).

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

If a grouping scheme has been applied to the data set that it will be used. This can change the results, since the first and last bins of the selected range may extend outside the requested range.

Examples

Calculate the number of counts over the ranges 0.5 to 2 and 0.5 to 7 keV for the default data set, first using the observed signal and then, for the 0.5 to 2 keV band - the background-subtraced estimate:

>>> set_analysis('energy')
>>> calc_data_sum(0.5, 2)
745.0
>>> calc_data_sum(0.5, 7)
60.0
>>> subtract()
>>> calc_data_sum(0.5, 2)
730.9179738207356

Calculate the data value in the bin containing 0.5 keV for the source “core”:

>>> calc_data_sum(0.5, id="core")
0.0