save_resid

sherpa.astro.ui.save_resid(id, filename=None, bkg_id: IdType | None = None, ascii=False, clobber=False) None

Save the residuals (data-model) to a file.

Parameters:
idint 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.

filenamestr

The name of the file to write the array to. The format is determined by the ascii argument.

bkg_idint, str, or None, optional

Set if the background residuals should be written out rather than the source.

asciibool, optional

If False then the data is written as a FITS format binary table. The default is False. The exact format of the output file depends on the I/O library in use (Crates or AstroPy).

clobberbool, optional

If outfile is not None, then this flag controls whether an existing file can be overwritten (True) or if it raises an exception (False, the default setting).

Raises:
sherpa.utils.err.IdentifierErr

If no model has been set for this data set.

sherpa.utils.err.IOErr

If filename already exists and clobber is False.

See also

save_data

Save the data to a file.

save_delchi

Save the ratio of residuals (data-model) to error to a file.

Notes

The function does not follow the normal Python standards for parameter use, since it is designed for easy interactive use. When called with a single un-named argument, it is taken to be the filename parameter. If given two un-named arguments, then they are interpreted as the id and filename parameters, respectively. The remaining parameters are expected to be given as named arguments.

The output file contains the columns X and RESID. The residuals array respects any filter or (for PHA files), grouping settings.

Examples

Write the residuals to the file “resid.fits”:

>>> save_resid('resid.fits')

Write the residuals from the data set ‘jet’ to the ASCII file “resid.dat”:

>>> save_resid('jet', "resid.dat", ascii=True)