subtract

sherpa.astro.ui.subtract(id=None)

Subtract the background estimate from a data set.

The subtract function performs a channel-by-channel subtraction of the background estimate from the data. After this command, anything that uses the data set - such as a plot, fit, or error analysis - will use the subtracted data. Models should be re-fit if subtract is called.

Parameters:

id (int or str, optional) – The identifier for the data set to use. If not given then the default identifier is used, as returned by get_default_id.

Raises:

See also

fit()
Fit one or more data sets.
unsubtract()
Undo any background subtraction for the data set.

Notes

Unlike X-Spec [1], Sherpa does not automatically subtract the background estimate from the data.

Background subtraction can only be performed when data and background are of the same length. If the data and background are ungrouped, both must have same number of channels. If they are grouped, data and background can start with different numbers of channels, but must have the same number of groups after grouping.

The equation for the subtraction is:

src_counts - bg_counts * (src_exposure * src_backscal)
                         -----------------------------
                          (bg_exposure * bg_backscal)

where src_exposure and bg_exposure are the source and background exposure times, and src_backscal and bg_backscal are the source and background backscales. The backscale, read from the BACKSCAL header keyword of the PHA file [2], is the ratio of data extraction area to total detector area.

The subtracted field of a dataset is set to True when the background is subtracted.

References

[1]https://heasarc.gsfc.nasa.gov/xanadu/xspec/manual/XspecSpectralFitting.html
[2]https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/spectra/ogip_92_007/node5.html

Examples

Background subtract the default data set.

>>> subtract()
>>> get_data().subtracted
True

Remove the background from the data set labelled ‘src’:

>>> subtract('src')
>>> get_data('src').subtracted
True

Overplot the background-subtracted data on the original data for the default data set:

>>> plot_data()
>>> subtract()
>>> plot_data(overplot=True)