datasets - Reduced datasets


The gammapy.datasets sub-package contains classes to handle reduced gamma-ray data for modeling and fitting.

The Dataset class bundles reduced data, IRFs and model to perform likelihood fitting and joint-likelihood fitting. All datasets contain a Models container with one or more SkyModel objects that represent additive emission components.

To model and fit data in Gammapy, you have to create a Datasets container object with one or multiple Dataset objects. Gammapy has built-in support to create and analyse the following datasets: MapDataset, MapDatasetOnOff, SpectrumDataset, SpectrumDatasetOnOff and FluxPointsDataset.

The map datasets represent 3D cubes (WcsNDMap objects) with two spatial and one energy axis. For 2D images the same map objects and map datasets are used, an energy axis is present but only has one energy bin. The MapDataset contains a counzts map, background is modeled with a BackgroundModel, and the fit statistic used is cash. The MapDatasetOnOff contains on and off count maps, background is implicitly modeled via the off counts map, and the wstat fit statistic.

The spectrum datasets represent 1D spectra (RegionNDMap objects) with an energy axis. There are no spatial axes or information, the 1D spectra are obtained for a given on region. The SpectrumDataset contains a counts spectrum, background is modeled with a RegionNDMap, and the fit statistic used is cash. The SpectrumDatasetOnOff contains on on and off count spectra, background is implicitly modeled via the off counts spectrum, and the wstat fit statistic. The FluxPointsDataset contains estimatorsFluxPoints and a spectral model, the fit statistic used is chi2.

Note that in Gammapy, 2D image analyses are done with 3D cubes with a single energy bin, e.g. for modeling and fitting, see the 2D map analysis tutorial.

Getting started


gammapy.datasets Package



Dataset abstract base class.


Dataset collection.

MapDatasetOnOff([models, counts, …])

Map dataset for on-off likelihood fitting.

SpectrumDataset([models, counts, exposure, …])


Sample events from a map dataset

MapDataset([models, counts, exposure, …])

Perform sky model likelihood fit on maps.

SpectrumDatasetOnOff([models, counts, …])

FluxPointsDataset([models, data, mask_fit, …])

Fit a set of flux points with a parametric model.



Registry of dataset classes in Gammapy.