MapDatasetOnOff#
- class gammapy.datasets.MapDatasetOnOff[source]#
Bases:
MapDataset
Map dataset for 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 safe mask and a fit mask can be added to exclude bins during the analysis.
It uses the Wstat statistic (see
wstat
), therefore no background model is needed.For more information see Datasets (DL4).
- Parameters:
- models
Models
Source sky models.
- counts
WcsNDMap
Counts cube.
- counts_off
WcsNDMap
Ring-convolved counts cube.
- acceptance
WcsNDMap
Acceptance from the IRFs.
- acceptance_off
WcsNDMap
Acceptance off.
- exposure
WcsNDMap
Exposure cube.
- mask_fit
WcsNDMap
Mask to apply to the likelihood for fitting.
- psf
PSFKernel
PSF kernel.
- edisp
EDispKernel
Energy dispersion.
- mask_safe
WcsNDMap
Mask defining the safe data range.
- gti
GTI
GTI of the observation or union of GTI if it is a stacked observation.
- meta_table
Table
Table listing information on observations used to create the dataset. One line per observation for stacked datasets.
- namestr
Name of the dataset.
- meta
MapDatasetMetaData
Associated meta data container
- models
See also
MapDataset
,SpectrumDataset
,FluxPointsDataset.
Attributes Summary
Exposure ratio between signal and background regions.
Computed as alpha * n_off.
Methods Summary
cutout
(position, width[, mode, name])Cutout map dataset.
downsample
(factor[, axis_name, name])Downsample map dataset.
fake
(npred_background[, random_state])Simulate fake counts (on and off) for the current model and reduced IRFs.
from_geoms
(geom[, geom_exposure, geom_psf, ...])Create an empty
MapDatasetOnOff
object according to the specified geometries.from_hdulist
(hdulist[, name, format])Create map dataset from list of HDUs.
from_map_dataset
(dataset, acceptance, ...[, ...])Create on off dataset from a map dataset.
info_dict
([in_safe_data_range])Basic info dict with summary statistics.
Predicted background counts estimated from the marginalized likelihood estimate.
Predicted counts in the off region; mu_bkg/alpha.
pad
()Not implemented for MapDatasetOnOff.
resample_energy_axis
(energy_axis[, name])Resample MapDatasetOnOff over reconstructed energy edges.
slice_by_idx
(slices[, name])Slice sub dataset.
stack
(other[, nan_to_num])Stack another dataset in place.
Convert map dataset to list of HDUs.
to_map_dataset
([name])Convert a MapDatasetOnOff to a MapDataset.
to_spectrum_dataset
(on_region[, ...])Return a ~gammapy.datasets.SpectrumDatasetOnOff from on_region.
Attributes Documentation
- alpha#
Exposure ratio between signal and background regions.
See WStat : Poisson data with background measurement.
- Returns:
- alpha
Map
Alpha map.
- alpha
- background#
Computed as alpha * n_off.
See WStat : Poisson data with background measurement.
- Returns:
- background
Map
Background map.
- background
- tag = 'MapDatasetOnOff'#
Methods Documentation
- cutout(position, width, mode='trim', name=None)[source]#
Cutout map dataset.
- Parameters:
- position
SkyCoord
Center position of the cutout region.
- widthtuple of
Angle
Angular sizes of the region in (lon, lat) in that specific order. If only one value is passed, a square region is extracted.
- mode{‘trim’, ‘partial’, ‘strict’}
Mode option for Cutout2D, for details see
Cutout2D
. Default is “trim”.- namestr, optional
Name of the new dataset. Default is None.
- position
- Returns:
- cutout
MapDatasetOnOff
Cutout map dataset.
- cutout
- downsample(factor, axis_name=None, name=None)[source]#
Downsample map dataset.
The PSFMap and EDispKernelMap are not downsampled, except if a corresponding axis is given.
- Parameters:
- factorint
Downsampling factor.
- axis_namestr, optional
Which non-spatial axis to downsample. By default, only spatial axes are downsampled. Default is None.
- namestr, optional
Name of the downsampled dataset. Default is None.
- Returns:
- dataset
MapDatasetOnOff
Downsampled map dataset.
- dataset
- fake(npred_background, random_state='random-seed')[source]#
Simulate fake counts (on and off) for the current model and reduced IRFs.
This method overwrites the counts defined on the dataset object.
- Parameters:
- npred_background
Map
Expected number of background counts in the on region.
- random_state{int, ‘random-seed’, ‘global-rng’,
RandomState
} Defines random number generator initialisation. Passed to
get_random_state
. Default is “random-seed”.
- npred_background
- classmethod from_geoms(geom, geom_exposure=None, geom_psf=None, geom_edisp=None, reference_time='2000-01-01', name=None, **kwargs)[source]#
Create an empty
MapDatasetOnOff
object according to the specified geometries.- Parameters:
- geom
gammapy.maps.WcsGeom
Geometry for the counts, counts_off, acceptance and acceptance_off maps.
- geom_exposure
gammapy.maps.WcsGeom
, optional Geometry for the exposure map. Default is None.
- geom_psf
gammapy.maps.WcsGeom
, optional Geometry for the PSF map. Default is None.
- geom_edisp
gammapy.maps.WcsGeom
, optional Geometry for the energy dispersion kernel map. If geom_edisp has a migra axis, this will create an EDispMap instead. Default is None.
- reference_time
Time
The reference time to use in GTI definition. Default is “2000-01-01”.
- namestr, optional
Name of the returned dataset. Default is None.
- **kwargsdict, optional
Keyword arguments to be passed.
- geom
- Returns:
- empty_maps
MapDatasetOnOff
A MapDatasetOnOff containing zero filled maps.
- empty_maps
- classmethod from_hdulist(hdulist, name=None, format='gadf')[source]#
Create map dataset from list of HDUs.
- Parameters:
- hdulist
HDUList
List of HDUs.
- namestr, optional
Name of the new dataset. Default is None.
- format{“gadf”}
Format the hdulist is given in. Default is “gadf”.
- hdulist
- Returns:
- dataset
MapDatasetOnOff
Map dataset.
- dataset
- classmethod from_map_dataset(dataset, acceptance, acceptance_off, counts_off=None, name=None)[source]#
Create on off dataset from a map dataset.
- Parameters:
- dataset
MapDataset
Spectrum dataset defining counts, edisp, aeff, livetime etc.
- acceptance
Map
Relative background efficiency in the on region.
- acceptance_off
Map
Relative background efficiency in the off region.
- counts_off
Map
, optional Off counts map . If the dataset provides a background model, and no off counts are defined. The off counts are deferred from counts_off / alpha. Default is None.
- namestr, optional
Name of the returned dataset. Default is None.
- dataset
- Returns:
- dataset
MapDatasetOnOff
Map dataset on off.
- dataset
- info_dict(in_safe_data_range=True)[source]#
Basic info dict with summary statistics.
If a region is passed, then a spectrum dataset is extracted, and the corresponding info returned.
- Parameters:
- in_safe_data_rangebool
Whether to sum only in the safe energy range. Default is True.
- Returns:
- info_dictdict
Dictionary with summary info.
- npred_background()[source]#
Predicted background counts estimated from the marginalized likelihood estimate.
See WStat : Poisson data with background measurement.
- Returns:
- npred_background
Map
Predicted background counts.
- npred_background
- npred_off()[source]#
Predicted counts in the off region; mu_bkg/alpha.
See WStat : Poisson data with background measurement.
- Returns:
- npred_off
Map
Predicted off counts.
- npred_off
- resample_energy_axis(energy_axis, name=None)[source]#
Resample MapDatasetOnOff over reconstructed energy edges.
Counts are summed taking into account safe mask.
- Parameters:
- energy_axis
MapAxis
New reco energy axis.
- namestr, optional
Name of the new dataset. Default is None.
- energy_axis
- Returns:
- dataset
SpectrumDataset
Resampled spectrum dataset.
- dataset
- slice_by_idx(slices, name=None)[source]#
Slice sub dataset.
The slicing only applies to the maps that define the corresponding axes.
- Parameters:
- slicesdict
Dictionary of axes names and integers or
slice
object pairs. Contains one element for each non-spatial dimension. For integer indexing the corresponding axes is dropped from the map. Axes not specified in the dict are kept unchanged.- namestr, optional
Name of the sliced dataset. Default is None.
- Returns:
- map_out
Map
Sliced map object.
- map_out
- stack(other, nan_to_num=True)[source]#
Stack another dataset in place.
Safe mask is applied to the other dataset to compute the stacked counts data, counts outside the safe mask are lost (as for
stack
).The
acceptance
of the stacked dataset is obtained by stacking the acceptance weighted by the other mask_safe onto the current unweighted acceptance.Note that the masking is not applied to the current dataset. If masking needs to be applied to it, use
to_masked()
first.The stacked
acceptance_off
is scaled so that:\[\alpha_\text{stacked} = \frac{1}{a_\text{off}} = \frac{\alpha_1\text{OFF}_1 + \alpha_2\text{OFF}_2}{\text{OFF}_1 + OFF_2}.\]For details, see Stacking Multiple Datasets.
- Parameters:
- other
MapDatasetOnOff
Other dataset.
- nan_to_numbool
Non-finite values are replaced by zero if True. Default is True.
- other
- to_hdulist()[source]#
Convert map dataset to list of HDUs.
- Returns:
- hdulist
HDUList
Map dataset list of HDUs.
- hdulist
- to_map_dataset(name=None)[source]#
Convert a MapDatasetOnOff to a MapDataset.
The background model template is taken as alpha * counts_off.
- Parameters:
- namestr, optional
Name of the new dataset. Default is None.
- Returns:
- dataset
MapDataset
Map dataset with cash statistics.
- dataset
- to_spectrum_dataset(on_region, containment_correction=False, name=None)[source]#
Return a ~gammapy.datasets.SpectrumDatasetOnOff from on_region.
Counts and OFF counts are summed in the on_region.
Acceptance is the average of all acceptances while acceptance OFF is taken such that number of excess is preserved in the on_region.
Effective area is taken from the average exposure.
The energy dispersion kernel is obtained at the on_region center. Only regions with centers are supported.
The models are not exported to the ~gammapy.dataset.SpectrumDatasetOnOff. It must be set after the dataset extraction.
- Parameters:
- on_region
SkyRegion
The input ON region on which to extract the spectrum.
- containment_correctionbool
Apply containment correction for point sources and circular on regions. Default is False.
- namestr, optional
Name of the new dataset. Default is None.
- on_region
- Returns:
- dataset
SpectrumDatasetOnOff
The resulting reduced dataset.
- dataset
- __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')[source]#
- classmethod __new__(*args, **kwargs)#