resample_energy_edges#

gammapy.estimators.utils.resample_energy_edges(dataset, conditions={})[source]#

Return energy edges that satisfy given condition on the per bin statistics.

Parameters:
datasetSpectrumDataset or SpectrumDatasetOnOff

The input dataset.

conditionsdict

Keyword arguments containing the per-bin conditions used to resample the axis. Available options are: ‘counts_min’, ‘background_min’, ‘excess_min’, ‘sqrt_ts_min’, ‘npred_min’, ‘npred_background_min’, ‘npred_signal_min’. Default is {}.

Returns:
energy_edgeslist of Quantity

Energy edges for the resampled energy axis.

Examples

>>> from gammapy.datasets import Datasets, SpectrumDatasetOnOff
>>> from gammapy.estimators.utils import resample_energy_edges
>>>
>>> datasets = Datasets()
>>>
>>> for obs_id in [23523, 23526]:
...     dataset = SpectrumDatasetOnOff.read(
...         f"$GAMMAPY_DATA/joint-crab/spectra/hess/pha_obs{obs_id}.fits"
...     )
...     datasets.append(dataset)
>>>
>>> spectrum_dataset = Datasets(datasets).stack_reduce()
>>> # Resample the energy edges so the minimum sqrt_ts is 2
>>> resampled_energy_edges = resample_energy_edges(
...     spectrum_dataset,
...     conditions={"sqrt_ts_min": 2}
... )