Adapt ASmoothEstimator
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Implementation of adaptive smoothing algorithms."""
import numpy as np
-from astropy import units as u
from astropy.convolution import Gaussian2DKernel, Tophat2DKernel
from astropy.coordinates import Angle
-from gammapy.datasets import Datasets, MapDatasetOnOff
-from gammapy.maps import Map, WcsNDMap
+from gammapy.datasets import MapDatasetOnOff
+from gammapy.maps import Map, WcsNDMap, MapAxis
from gammapy.modeling.models import PowerLawSpectralModel
from gammapy.stats import CashCountsStatistic
from gammapy.utils.array import scale_cube
@@ -143,6 +142,7 @@ class ASmoothMapEstimator(Estimator):
----------
dataset : `~gammapy.datasets.MapDataset` or `~gammapy.datasets.MapDatasetOnOff`
the input dataset (with one bin in energy at most)
+
Returns
-------
images : dict of `~gammapy.maps.WcsNDMap`
@@ -155,20 +155,22 @@ class ASmoothMapEstimator(Estimator):
"""
if self.energy_edges is None:
energy_axis = dataset.counts.geom.axes["energy"]
- energy_edges = u.Quantity([energy_axis.edges[0], energy_axis.edges[-1]])
else:
- energy_edges = self.energy_edges
+ energy_axis = MapAxis.from_energy_edges(self.energy_edges)
results = []
for energy_min, energy_max in progress_bar(
- zip(energy_edges[:-1], energy_edges[1:]),
+ energy_axis.iter_by_edges,
desc="Energy bins"
):
- dataset_sliced = dataset.slice_by_energy(energy_min, energy_max, name=dataset.name)
+ dataset_sliced = dataset.slice_by_energy(
+ energy_min=energy_min, energy_max=energy_max, name=dataset.name
+ )
dataset_sliced.models = dataset.models
result = self.estimate_maps(dataset_sliced)
results.append(result)
+
result_all = {}
for name in results[0].keys():
