SpectrumDataset¶
-
class
gammapy.datasets.SpectrumDataset(models=None, counts=None, livetime=None, aeff=None, edisp=None, background=None, mask_safe=None, mask_fit=None, name=None, gti=None)[source]¶ Bases:
gammapy.datasets.DatasetSpectrum dataset for likelihood fitting.
The spectrum dataset bundles reduced counts data, with a spectral model, background model and instrument response function to compute the fit-statistic given the current model and data.
- Parameters
- models
Models Fit model
- counts
RegionNDMap Counts spectrum
- livetime
Quantity Livetime
- aeff
EffectiveAreaTable Effective area
- edisp
EDispKernel Energy dispersion
- background
RegionNDMap Background to use for the fit.
- mask_safe
RegionNDMap Mask defining the safe data range.
- mask_fit
RegionNDMap Mask to apply to the likelihood for fitting.
- namestr
Dataset name.
- gti
GTI GTI of the observation or union of GTI if it is a stacked observation
- models
See also
SpectrumDatasetOnOff,FluxPointsDataset,gammapy.cube.MapDataset
Attributes Summary
Shape of the counts data
Energy range defined by the safe mask
Model evaluators
Excess (counts - alpha * counts_off)
Excess (aeff * livetime)
Combined fit and safe mask
Models (
gammapy.modeling.models.Models).Methods Summary
copy(self[, name])A deep copy.
create(e_reco[, e_true, region, …])Creates empty spectrum dataset.
fake(self[, random_state])Simulate fake counts for the current model and reduced irfs.
info_dict(self[, in_safe_energy_range])Info dict with summary statistics, summed over energy
npred(self)Return npred map (model + background)
npred_sig(self)Predicted counts from source model (
RegionNDMap).peek(self[, figsize])Quick-look summary plots.
plot_counts(self[, ax])Plot predicted and detected counts.
plot_fit(self)Plot counts and residuals in two panels.
plot_residuals(self[, method, ax])Plot residuals.
residuals(self[, method])Compute the spectral residuals.
stack(self, other)Stack this dataset with another one.
stat_array(self)Likelihood per bin given the current model parameters
stat_sum(self)Total statistic given the current model parameters.
Attributes Documentation
-
data_shape¶ Shape of the counts data
-
energy_range¶ Energy range defined by the safe mask
-
evaluators¶ Model evaluators
-
excess¶ Excess (counts - alpha * counts_off)
-
exposure¶ Excess (aeff * livetime)
-
mask¶ Combined fit and safe mask
-
mask_safe¶
-
models¶ Models (
gammapy.modeling.models.Models).
-
name¶
-
stat_type= 'cash'¶
-
tag= 'SpectrumDataset'¶
Methods Documentation
-
copy(self, name=None)¶ A deep copy.
-
classmethod
create(e_reco, e_true=None, region=None, reference_time='2000-01-01', name=None)[source]¶ Creates empty spectrum dataset.
Empty containers are created with the correct geometry. counts, background and aeff are zero and edisp is diagonal.
The safe_mask is set to False in every bin.
-
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.
- random_state{int, ‘random-seed’, ‘global-rng’,
-
info_dict(self, in_safe_energy_range=True)[source]¶ Info dict with summary statistics, summed over energy
- Parameters
- in_safe_energy_rangebool
Whether to sum only in the safe energy range
- Returns
- info_dictdict
Dictionary with summary info.
-
plot_counts(self, ax=None)[source]¶ Plot predicted and detected counts.
- Parameters
- ax
Axes Axes object.
- ax
- Returns
- ax
Axes Axes object.
- ax
-
plot_fit(self)[source]¶ Plot counts and residuals in two panels.
Calls
plot_countsandplot_residuals.
-
plot_residuals(self, method='diff', ax=None, **kwargs)[source]¶ Plot residuals.
- Parameters
- ax
Axes Axes object.
- method{“diff”, “diff/model”, “diff/sqrt(model)”}
Normalization used to compute the residuals, see
SpectrumDataset.residuals()- **kwargsdict
Keywords passed to
RegionNDMap.plot()
- ax
- Returns
- ax
Axes Axes object.
- ax
-
residuals(self, method='diff')[source]¶ Compute the spectral residuals.
- Parameters
- method{“diff”, “diff/model”, “diff/sqrt(model)”}
- Method used to compute the residuals. Available options are:
diff(default): data - modeldiff/model: (data - model) / modeldiff/sqrt(model): (data - model) / sqrt(model)
- Returns
- residuals
RegionNDMap Residual spectrum
- residuals
-
stack(self, other)[source]¶ Stack this dataset with another one.
Safe mask is applied to compute the stacked counts vector. Counts outside each dataset safe mask are lost.
Stacking is performed in-place.
The stacking of 2 datasets is implemented as follows. Here, \(k\) denotes a bin in reconstructed energy and \(j = {1,2}\) is the dataset number
The
mask_safeof each dataset is defined as:\[\begin{split}\epsilon_{jk} =\left\{\begin{array}{cl} 1, & \mbox{if bin k is inside the energy thresholds}\\ 0, & \mbox{otherwise} \end{array}\right.\end{split}\]Then the total
countsand model backgroundbkgare computed according to:\[ \begin{align}\begin{aligned}\overline{\mathrm{n_{on}}}_k = \mathrm{n_{on}}_{1k} \cdot \epsilon_{1k} + \mathrm{n_{on}}_{2k} \cdot \epsilon_{2k}\\\overline{bkg}_k = bkg_{1k} \cdot \epsilon_{1k} + bkg_{2k} \cdot \epsilon_{2k}\end{aligned}\end{align} \]The stacked
safe_maskis then:\[\overline{\epsilon_k} = \epsilon_{1k} OR \epsilon_{2k}\]Please refer to the
IRFStackerfor the description of how the IRFs are stacked.- Parameters
- other
SpectrumDataset the dataset to stack to the current one
- other
-
stat_sum(self)¶ Total statistic given the current model parameters.