SpectrumDatasetOnOff#

class gammapy.datasets.SpectrumDatasetOnOff[source]#

Bases: PlotMixin, MapDatasetOnOff

Spectrum dataset for 1D on-off likelihood fitting.

It bundles together the binned on and off counts, the binned IRFs as well as the on and off acceptances.

A fit mask can be added to exclude bins during the analysis.

It uses the Wstat statistic (see wstat).

For more information see Datasets (DL4).

Attributes Summary

tag

Methods Summary

cutout(*args, **kwargs)

Not supported for SpectrumDatasetOnOff.

from_dict(data, **kwargs)

Create spectrum dataset from dictionary.

from_spectrum_dataset(**kwargs)

Create a SpectrumDatasetOnOff from a SpectrumDataset dataset.

plot_residuals_spatial(*args, **kwargs)

Not supported for SpectrumDatasetOnOff.

read(filename[, format, checksum, name])

Read from file.

to_dict()

Convert to dict for YAML serialization.

to_spectrum_dataset([name])

Convert a SpectrumDatasetOnOff to a SpectrumDataset.

write(filename[, overwrite, format, checksum])

Write spectrum dataset on off to file.

Attributes Documentation

tag = 'SpectrumDatasetOnOff'#

Methods Documentation

cutout(*args, **kwargs)[source]#

Not supported for SpectrumDatasetOnOff.

classmethod from_dict(data, **kwargs)[source]#

Create spectrum dataset from dictionary.

Reads file from the disk as specified in the dict.

Parameters:
datadict

Dictionary containing data to create dataset from.

Returns:
datasetSpectrumDatasetOnOff

Spectrum dataset on off.

classmethod from_spectrum_dataset(**kwargs)[source]#

Create a SpectrumDatasetOnOff from a SpectrumDataset dataset.

Parameters:
datasetSpectrumDataset

Spectrum dataset defining counts, edisp, exposure etc.

acceptancearray or float

Relative background efficiency in the on region.

acceptance_offarray or float

Relative background efficiency in the off region.

counts_offRegionNDMap

Off counts spectrum. If the dataset provides a background model, and no off counts are defined. The off counts are deferred from counts_off / alpha.

Returns:
datasetSpectrumDatasetOnOff

Spectrum dataset on off.

plot_residuals_spatial(*args, **kwargs)[source]#

Not supported for SpectrumDatasetOnOff.

classmethod read(filename, format='ogip', checksum=False, name=None, **kwargs)[source]#

Read from file.

For OGIP formats, filename is the name of a PHA file. The BKG, ARF, and RMF file names must be set in the PHA header and the files must be present in the same folder. For details, see OGIPDatasetReader.read.

For the GADF format, a MapDataset serialisation is used.

Parameters:
filenamePath or str

OGIP PHA file to read.

format{“ogip”, “ogip-sherpa”, “gadf”}

Format to use. Default is “ogip”.

checksumbool, optional

If True checks both DATASUM and CHECKSUM cards in the file headers. Default is False.

name: str, optional

Name of the dataset. If None, dataset name will be set to the written one. Default is None.

kwargsdict, optional

Keyword arguments passed to MapDataset.read.

to_dict()[source]#

Convert to dict for YAML serialization.

to_spectrum_dataset(name=None)[source]#

Convert a SpectrumDatasetOnOff to a SpectrumDataset.

The background model template is taken as alpha*counts_off.

Parameters:
namestr, optional

Name of the new dataset. Default is None.

Returns:
datasetSpectrumDataset

SpectrumDataset with Cash statistic.

write(filename, overwrite=False, format='ogip', checksum=False)[source]#

Write spectrum dataset on off to file.

Can be serialised either as a MapDataset with a RegionGeom following the GADF specifications, or as per the OGIP format. For OGIP formats specs, see OGIPDatasetWriter.

Parameters:
filenamePath or str

Filename to write to.

overwritebool, optional

Overwrite existing file. Default is False.

format{“ogip”, “ogip-sherpa”, “gadf”}

Format to use. Default is “ogip”.

checksumbool

When True adds both DATASUM and CHECKSUM cards to the headers written to the file. Default is False.

__init__(models=None, counts=None, counts_off=None, acceptance=None, acceptance_off=None, exposure=None, mask_fit=None, psf=None, edisp=None, name=None, mask_safe=None, gti=None, meta_table=None, meta=None, stat_type='wstat')#
classmethod __new__(*args, **kwargs)#