MapDataset

class gammapy.cube.MapDataset(model=None, counts=None, exposure=None, mask_fit=None, psf=None, edisp=None, background_model=None, likelihood='cash', evaluation_mode='local', mask_safe=None, gti=None)[source]

Bases: gammapy.utils.fitting.Dataset

Perform sky model likelihood fit on maps.

Parameters:
model : SkyModel or SkyModels

Source sky models.

counts : WcsNDMap

Counts cube

exposure : WcsNDMap

Exposure cube

mask_fit : ndarray

Mask to apply to the likelihood for fitting.

psf : PSFKernel

PSF kernel

edisp : EnergyDispersion

Energy dispersion

background_model : BackgroundModel or BackgroundModels

Background models to use for the fit.

likelihood : {“cash”, “cstat”}

Likelihood function to use for the fit.

evaluation_mode : {“local”, “global”}

Model evaluation mode.

The “local” mode evaluates the model components on smaller grids to save computation time. This mode is recommended for local optimization algorithms. The “global” evaluation mode evaluates the model components on the full map. This mode is recommended for global optimization algorithms.

mask_safe : ndarray

Mask defining the safe data range.

gti : ‘~gammapy.data.gti.GTI’

GTI of the observation or union of GTI if it is a stacked observation

Attributes Summary

data_shape Shape of the counts data (tuple)
mask Combined fit and safe mask
model Sky model to fit (SkyModel or SkyModels)
parameters List of parameters (Parameters)

Methods Summary

copy(self) A deep copy.
fake(self[, random_state]) Simulate fake counts for the current model and reduced irfs.
from_hdulist(hdulist) Create map dataset from list of HDUs.
likelihood(self) Total likelihood given the current model parameters.
likelihood_per_bin(self) Likelihood per bin given the current model parameters
npred(self) Predicted source and background counts (Map).
plot_residuals(self[, method, …]) Plot spatial and spectral residuals.
read(filename) Read map dataset from file.
residuals(self[, method]) Compute residuals map.
to_hdulist(self) Convert map dataset to list of HDUs.
write(self, filename[, overwrite]) Write map dataset to file.

Attributes Documentation

data_shape

Shape of the counts data (tuple)

mask

Combined fit and safe mask

model

Sky model to fit (SkyModel or SkyModels)

parameters

List of parameters (Parameters)

Methods Documentation

copy(self)

A deep copy.

fake(self, random_state='random-seed')[source]

Simulate fake counts for the current model and reduced irfs.

This method overwrites the counts defined on the dataset object.

Parameters:
random_state : {int, ‘random-seed’, ‘global-rng’, RandomState}

Defines random number generator initialisation. Passed to get_random_state.

classmethod from_hdulist(hdulist)[source]

Create map dataset from list of HDUs.

Parameters:
hdulist : HDUList

List of HDUs.

Returns:
dataset : MapDataset

Map dataset.

likelihood(self)[source]

Total likelihood given the current model parameters.

likelihood_per_bin(self)[source]

Likelihood per bin given the current model parameters

npred(self)[source]

Predicted source and background counts (Map).

plot_residuals(self, method='diff', smooth_kernel='gauss', smooth_radius='0.1 deg', region=None, figsize=(12, 4), **kwargs)[source]

Plot spatial and spectral residuals.

The spectral residuals are extracted from the provided region, and the normalization used for the residuals computation can be controlled using the norm parameter. If no region is passed, only the spatial residuals are shown.

Parameters:
method : {“diff”, “diff/model”, “diff/sqrt(model)”}

Method used to compute the residuals, see MapDataset.residuals()

smooth_kernel : {‘gauss’, ‘box’}

Kernel shape.

smooth_radius: `~astropy.units.Quantity`, str or float

Smoothing width given as quantity or float. If a float is given it is interpreted as smoothing width in pixels.

region: `~regions.Region`

Region (pixel or sky regions accepted)

figsize : tuple

Figure size used for the plotting.

**kwargs : dict

Keyword arguments passed to imshow.

Returns:
ax_image, ax_spec : Axes,

Image and spectrum axes.

classmethod read(filename)[source]

Read map dataset from file.

Parameters:
filename : str

Filename to read from.

Returns:
dataset : MapDataset

Map dataset.

residuals(self, method='diff')[source]

Compute residuals map.

Parameters:
method: {“diff”, “diff/model”, “diff/sqrt(model)”}
Method used to compute the residuals. Available options are:
  • diff (default): data - model
  • diff/model: (data - model) / model
  • diff/sqrt(model): (data - model) / sqrt(model)
Returns:
residuals : gammapy.maps.WcsNDMap

Residual map.

to_hdulist(self)[source]

Convert map dataset to list of HDUs.

Returns:
hdulist : HDUList

Map dataset list of HDUs.

write(self, filename, overwrite=False)[source]

Write map dataset to file.

Parameters:
filename : str

Filename to write to.

overwrite : bool

Overwrite file if it exists.