Skip to the navigation links
Last modified: 11 December 2023

URL: https://cxc.cfa.harvard.edu/sherpa/bugs/fit.html

Caveats: fit


Caveats

Fitting source data with multiple backgrounds fails unless all background IDs are assigned models.

When a Chandra grating PHA data set is loaded into Sherpa, and the associated background data is available, it is assigned two separate background IDs, one for each of the 'up' and 'down' background data sets.

sherpa In [1]: load_pha("3c120_heg_-1.pha.gz")
WARNING: systematic errors were not found in file '3c120_heg_-1.pha.gz'
statistical errors were found in file '3c120_heg_-1.pha.gz' 
but not used; to use them, re-read with use_errors=True
read ARF file 3c120_heg_-1.arf
read RMF file 3c120_heg_-1.rmf
read background_up into a dataset from file 3c120_heg_-1.pha.gz
read background_down into a dataset from file 3c120_heg_-1.pha.gz

Currently, if the source data ID and only one of its two background data IDs have been assigned a model, an attempt to fit the source and single background will fail with an error; Sherpa expects to include both backgrounds in the fit. While this safeguards the user against potentially misleading results in the analysis of their data, the fit should continue on in this case and simply issue a warning that only one of the two associated background data sets will be included in the fit.

sherpa In [2]: set_model(xspowerlaw.p1)

sherpa In [3]: set_bkg_model(const1d.c1)

sherpa In [4]: fit()
ModelErr: background model 2 for data set 1 has not been set

Workaround:

In order to fit only one of multiple background data sets assigned to a single source data set, the get_data() command may be used to remove the unneeded background, as shown below:


sherpa In [5]: print(get_data(1).background_ids)
[1, 2]

sherpa In [6]: get_data(1).background_ids = [1]  # set background 1 as the only
                                                 # background to fit.
sherpa In [7]: print(get_data(1).background_ids)
[1]