    Subtract the background estimate from a data set.

subtract(id=None)
id - int or str, optional

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.

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)

PARAMETERS

The parameter for this function is:

Parameter
Definition
id
The identifier for the data set to use. If not given then the default identifier is used, as returned by

`get_default_id` .

Notes

Unlike X-Spec, 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, 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.

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

December 2023