From bbe1081e00a59b6cf4cbc865501ad8d37aaa6172 Mon Sep 17 00:00:00 2001 From: Astro-Kirsty Date: Mon, 14 Oct 2024 10:54:24 +0200 Subject: [PATCH 1/5] Change to use specltra_model instead of spectrum Signed-off-by: Astro-Kirsty --- gammapy/estimators/map/asmooth.py | 14 ++++++++------ gammapy/estimators/points/profile.py | 14 ++++++++------ gammapy/estimators/points/sensitivity.py | 19 +++++++++++-------- .../points/tests/test_sensitivity.py | 2 +- gammapy/irf/psf/kernel.py | 12 +++++++----- gammapy/irf/psf/map.py | 12 +++++++----- 6 files changed, 42 insertions(+), 31 deletions(-) diff --git a/gammapy/estimators/map/asmooth.py b/gammapy/estimators/map/asmooth.py index 5c062bf241..f1fb74d5c9 100644 --- a/gammapy/estimators/map/asmooth.py +++ b/gammapy/estimators/map/asmooth.py @@ -12,6 +12,7 @@ from gammapy.utils.pbar import progress_bar from ..core import Estimator from ..utils import estimate_exposure_reco_energy +from gammapy.utils.deprecation import deprecated_renamed_argument __all__ = ["ASmoothMapEstimator"] @@ -21,6 +22,7 @@ def _sqrt_ts_asmooth(counts, background): return (counts - background) / np.sqrt(counts + background) +@deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") class ASmoothMapEstimator(Estimator): """Adaptively smooth counts image. @@ -37,7 +39,7 @@ class ASmoothMapEstimator(Estimator): Smoothing scales. kernel : `astropy.convolution.Kernel` Smoothing kernel. - spectrum : `~gammapy.modeling.models.SpectralModel` + spectral_model : `~gammapy.modeling.models.SpectralModel` Spectral model assumption. method : {'lima', 'asmooth'} Significance estimation method. Default is 'lima'. @@ -67,15 +69,15 @@ def __init__( self, scales=None, kernel=Gaussian2DKernel, - spectrum=None, + spectral_model=None, method="lima", threshold=5, energy_edges=None, ): - if spectrum is None: - spectrum = PowerLawSpectralModel() + if spectral_model is None: + spectral_model = PowerLawSpectralModel() - self.spectrum = spectrum + self.spectral_model = spectral_model if scales is None: scales = self.get_scales(n_scales=9, kernel=kernel) @@ -231,7 +233,7 @@ def estimate_maps(self, dataset): background = dataset_image.background.data[0] if dataset_image.exposure is not None: - exposure = estimate_exposure_reco_energy(dataset_image, self.spectrum) + exposure = estimate_exposure_reco_energy(dataset_image, self.spectral_model) else: exposure = None diff --git a/gammapy/estimators/points/profile.py b/gammapy/estimators/points/profile.py index 8b7700b0fe..0a11117a52 100644 --- a/gammapy/estimators/points/profile.py +++ b/gammapy/estimators/points/profile.py @@ -11,10 +11,12 @@ from gammapy.modeling.models import PowerLawSpectralModel, SkyModel from .core import FluxPoints from .sed import FluxPointsEstimator +from gammapy.utils.deprecation import deprecated_renamed_argument __all__ = ["FluxProfileEstimator"] +@deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") class FluxProfileEstimator(FluxPointsEstimator): """Estimate flux profiles. @@ -22,7 +24,7 @@ class FluxProfileEstimator(FluxPointsEstimator): ---------- regions : list of `~regions.SkyRegion` Regions to use. - spectrum : `~gammapy.modeling.models.SpectralModel`, optional + spectral_model : `~gammapy.modeling.models.SpectralModel`, optional Spectral model to compute the fluxes or brightness. Default is power-law with spectral index of 2. n_jobs : int, optional @@ -89,7 +91,7 @@ class FluxProfileEstimator(FluxPointsEstimator): tag = "FluxProfileEstimator" - def __init__(self, regions, spectrum=None, **kwargs): + def __init__(self, regions, spectral_model=None, **kwargs): if len(regions) <= 1: raise ValueError( "Please provide at least two regions for flux profile estimation." @@ -97,10 +99,10 @@ def __init__(self, regions, spectrum=None, **kwargs): self.regions = regions - if spectrum is None: - spectrum = PowerLawSpectralModel() + if spectral_model is None: + spectral_model = PowerLawSpectralModel() - self.spectrum = spectrum + self.spectral_model = spectral_model super().__init__(**kwargs) @property @@ -170,7 +172,7 @@ def _run_region(self, datasets, region): .to_region_nd_map(region, func=np.sum, weights=dataset_map.mask_safe) .data ) - datasets_to_fit.models = SkyModel(self.spectrum, name="test-source") + datasets_to_fit.models = SkyModel(self.spectral_model, name="test-source") estimator = self.copy() estimator.n_jobs = self._n_child_jobs return estimator._run_flux_points(datasets_to_fit) diff --git a/gammapy/estimators/points/sensitivity.py b/gammapy/estimators/points/sensitivity.py index 3c2730f592..35345997ab 100644 --- a/gammapy/estimators/points/sensitivity.py +++ b/gammapy/estimators/points/sensitivity.py @@ -5,10 +5,12 @@ from gammapy.modeling.models import PowerLawSpectralModel, SkyModel from gammapy.stats import WStatCountsStatistic from ..core import Estimator +from gammapy.utils.deprecation import deprecated_renamed_argument __all__ = ["SensitivityEstimator"] +@deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") class SensitivityEstimator(Estimator): """Estimate sensitivity. @@ -20,7 +22,7 @@ class SensitivityEstimator(Estimator): Parameters ---------- - spectrum : `SpectralModel` + spectral_model : `SpectralModel` Spectral model assumption. Default is Power Law with index 2. n_sigma : float, optional Minimum significance. Default is 5. @@ -39,16 +41,17 @@ class SensitivityEstimator(Estimator): def __init__( self, - spectrum=None, + spectral_model=None, n_sigma=5.0, gamma_min=10, bkg_syst_fraction=0.05, ): + if spectral_model is None: + spectral_model = PowerLawSpectralModel( + index=2, amplitude="1 cm-2 s-1 TeV-1" + ) - if spectrum is None: - spectrum = PowerLawSpectralModel(index=2, amplitude="1 cm-2 s-1 TeV-1") - - self.spectrum = spectrum + self.spectral_model = spectral_model self.n_sigma = n_sigma self.gamma_min = gamma_min self.bkg_syst_fraction = bkg_syst_fraction @@ -100,12 +103,12 @@ def estimate_min_e2dnde(self, excess, dataset): """ energy = dataset._geom.axes["energy"].center - dataset.models = SkyModel(spectral_model=self.spectrum) + dataset.models = SkyModel(spectral_model=self.spectral_model) npred = dataset.npred_signal() phi_0 = excess / npred - dnde_model = self.spectrum(energy=energy) + dnde_model = self.spectral_model(energy=energy) dnde = phi_0.data[:, 0, 0] * dnde_model * energy**2 return dnde.to("erg / (cm2 s)") diff --git a/gammapy/estimators/points/tests/test_sensitivity.py b/gammapy/estimators/points/tests/test_sensitivity.py index 926b2bf18b..938ec5d794 100644 --- a/gammapy/estimators/points/tests/test_sensitivity.py +++ b/gammapy/estimators/points/tests/test_sensitivity.py @@ -89,7 +89,7 @@ def test_integral_estimation(spectrum_dataset, caplog): sens = SensitivityEstimator(gamma_min=25, bkg_syst_fraction=0.075) table = sens.run(dataset_on_off) flux_points = FluxPoints.from_table( - table, sed_type="e2dnde", reference_model=sens.spectrum + table, sed_type="e2dnde", reference_model=sens.spectral_model ) assert_allclose(table["excess"].data.squeeze(), 270540, rtol=1e-3) diff --git a/gammapy/irf/psf/kernel.py b/gammapy/irf/psf/kernel.py index d13a8e3a49..b7d102d3e1 100644 --- a/gammapy/irf/psf/kernel.py +++ b/gammapy/irf/psf/kernel.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt from gammapy.maps import Map from gammapy.modeling.models import PowerLawSpectralModel +from gammapy.utils.deprecation import deprecated_renamed_argument __all__ = ["PSFKernel"] @@ -161,12 +162,13 @@ def write(self, *args, **kwargs): """Write the Map object which contains the PSF kernel to file.""" self.psf_kernel_map.write(*args, **kwargs) - def to_image(self, spectrum=None, exposure=None, keepdims=True): + @deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") + def to_image(self, spectral_model=None, exposure=None, keepdims=True): """Transform 3D PSFKernel into a 2D PSFKernel. Parameters ---------- - spectrum : `~gammapy.modeling.models.SpectralModel`, optional + spectral_model : `~gammapy.modeling.models.SpectralModel`, optional Spectral model to compute the weights. Default is power-law with spectral index of 2. exposure : `~astropy.units.Quantity` or `~numpy.ndarray`, optional @@ -184,8 +186,8 @@ def to_image(self, spectrum=None, exposure=None, keepdims=True): """ map = self.psf_kernel_map - if spectrum is None: - spectrum = PowerLawSpectralModel(index=2.0) + if spectral_model is None: + spectral_model = PowerLawSpectralModel(index=2.0) if exposure is None: exposure = np.ones(map.geom.axes[0].center.shape) @@ -200,7 +202,7 @@ def to_image(self, spectrum=None, exposure=None, keepdims=True): if "energy" in name: energy_name = name energy_edges = map.geom.axes[energy_name].edges - weights = spectrum.integral( + weights = spectral_model.integral( energy_min=energy_edges[:-1], energy_max=energy_edges[1:], intervals=True ) weights *= exposure diff --git a/gammapy/irf/psf/map.py b/gammapy/irf/psf/map.py index 348bd190eb..7aaa9c3496 100644 --- a/gammapy/irf/psf/map.py +++ b/gammapy/irf/psf/map.py @@ -12,6 +12,7 @@ from ..core import IRFMap from .core import PSF from .kernel import PSFKernel +from gammapy.utils.deprecation import deprecated_renamed_argument __all__ = ["PSFMap", "RecoPSFMap"] @@ -447,12 +448,13 @@ def from_gauss(cls, energy_axis_true, rad_axis=None, sigma=0.1 * u.deg, geom=Non ) return cls(psf_map=psf_map, exposure_map=exposure_map) - def to_image(self, spectrum=None, keepdims=True): + @deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") + def to_image(self, spectral_model=None, keepdims=True): """Reduce to a 2D map after weighing with the associated exposure and a spectrum. Parameters ---------- - spectrum : `~gammapy.modeling.models.SpectralModel`, optional + spectral_model : `~gammapy.modeling.models.SpectralModel`, optional Spectral model to compute the weights. Default is power-law with spectral index of 2. keepdims : bool, optional @@ -466,10 +468,10 @@ def to_image(self, spectrum=None, keepdims=True): """ from gammapy.makers.utils import _map_spectrum_weight - if spectrum is None: - spectrum = PowerLawSpectralModel(index=2.0) + if spectral_model is None: + spectral_model = PowerLawSpectralModel(index=2.0) - exp_weighed = _map_spectrum_weight(self.exposure_map, spectrum) + exp_weighed = _map_spectrum_weight(self.exposure_map, spectral_model) exposure = exp_weighed.sum_over_axes( axes_names=[self.energy_name], keepdims=keepdims ) From 80f47f185a820dc759c2a4a1963270a16b36337e Mon Sep 17 00:00:00 2001 From: Astro-Kirsty Date: Mon, 14 Oct 2024 14:53:17 +0200 Subject: [PATCH 2/5] Addextra details Signed-off-by: Astro-Kirsty --- examples/tutorials/analysis-1d/cta_sensitivity.py | 7 ++++--- gammapy/estimators/map/asmooth.py | 8 +++++--- gammapy/estimators/points/sensitivity.py | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/tutorials/analysis-1d/cta_sensitivity.py b/examples/tutorials/analysis-1d/cta_sensitivity.py index 78509d4912..1317c8c431 100644 --- a/examples/tutorials/analysis-1d/cta_sensitivity.py +++ b/examples/tutorials/analysis-1d/cta_sensitivity.py @@ -21,6 +21,7 @@ - `~gammapy.estimators.SensitivityEstimator` """ + from cycler import cycler import numpy as np import astropy.units as u @@ -182,13 +183,11 @@ # - fig, ax = plt.subplots() ax.set_prop_cycle(cycler("marker", "s*v") + cycler("color", "rgb")) for criterion in ("significance", "gamma", "bkg"): - mask = sensitivity_table["criterion"] == criterion t = sensitivity_table[mask] @@ -264,7 +263,9 @@ # flux_points = FluxPoints.from_table( - sensitivity_table, sed_type="e2dnde", reference_model=sensitivity_estimator.spectrum + sensitivity_table, + sed_type="e2dnde", + reference_model=sensitivity_estimator.spectral_model, ) print( f"Integral sensitivity in {livetime:.2f} above {energy_axis.edges[0]:.2e} " diff --git a/gammapy/estimators/map/asmooth.py b/gammapy/estimators/map/asmooth.py index f1fb74d5c9..4318c0fd62 100644 --- a/gammapy/estimators/map/asmooth.py +++ b/gammapy/estimators/map/asmooth.py @@ -39,8 +39,8 @@ class ASmoothMapEstimator(Estimator): Smoothing scales. kernel : `astropy.convolution.Kernel` Smoothing kernel. - spectral_model : `~gammapy.modeling.models.SpectralModel` - Spectral model assumption. + spectral_model : `~gammapy.modeling.models.SpectralModel`, optional + Spectral model assumption. Default is power-law with spectral index of 2. method : {'lima', 'asmooth'} Significance estimation method. Default is 'lima'. threshold : float @@ -75,7 +75,9 @@ def __init__( energy_edges=None, ): if spectral_model is None: - spectral_model = PowerLawSpectralModel() + spectral_model = PowerLawSpectralModel( + index=2, amplitude="1 cm-2 s-1 TeV-1" + ) self.spectral_model = spectral_model diff --git a/gammapy/estimators/points/sensitivity.py b/gammapy/estimators/points/sensitivity.py index 35345997ab..2b099e7ab3 100644 --- a/gammapy/estimators/points/sensitivity.py +++ b/gammapy/estimators/points/sensitivity.py @@ -22,8 +22,8 @@ class SensitivityEstimator(Estimator): Parameters ---------- - spectral_model : `SpectralModel` - Spectral model assumption. Default is Power Law with index 2. + spectral_model : `~gammapy.modeling.models.SpectralModel`, optional + Spectral model assumption. Default is power-law with spectral index of 2. n_sigma : float, optional Minimum significance. Default is 5. gamma_min : float, optional From 874222ee81ea4726cd9cbedaa2d1c0eb6ead05e3 Mon Sep 17 00:00:00 2001 From: Astro-Kirsty Date: Mon, 14 Oct 2024 15:34:43 +0200 Subject: [PATCH 3/5] Fix typo Signed-off-by: Astro-Kirsty --- gammapy/estimators/map/asmooth.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gammapy/estimators/map/asmooth.py b/gammapy/estimators/map/asmooth.py index 4318c0fd62..67a3b51fbf 100644 --- a/gammapy/estimators/map/asmooth.py +++ b/gammapy/estimators/map/asmooth.py @@ -75,9 +75,7 @@ def __init__( energy_edges=None, ): if spectral_model is None: - spectral_model = PowerLawSpectralModel( - index=2, amplitude="1 cm-2 s-1 TeV-1" - ) + spectral_model = PowerLawSpectralModel(index=2) self.spectral_model = spectral_model From 8574c830ba21df88371fc963fcaa14ec5b2a9853 Mon Sep 17 00:00:00 2001 From: Astro-Kirsty Date: Mon, 14 Oct 2024 17:33:00 +0200 Subject: [PATCH 4/5] Fix location of deprecation Signed-off-by: Astro-Kirsty --- gammapy/estimators/map/asmooth.py | 2 +- gammapy/estimators/points/profile.py | 2 +- gammapy/estimators/points/sensitivity.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gammapy/estimators/map/asmooth.py b/gammapy/estimators/map/asmooth.py index 67a3b51fbf..9555e2df3f 100644 --- a/gammapy/estimators/map/asmooth.py +++ b/gammapy/estimators/map/asmooth.py @@ -22,7 +22,6 @@ def _sqrt_ts_asmooth(counts, background): return (counts - background) / np.sqrt(counts + background) -@deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") class ASmoothMapEstimator(Estimator): """Adaptively smooth counts image. @@ -65,6 +64,7 @@ class ASmoothMapEstimator(Estimator): tag = "ASmoothMapEstimator" + @deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") def __init__( self, scales=None, diff --git a/gammapy/estimators/points/profile.py b/gammapy/estimators/points/profile.py index 0a11117a52..77a04870c6 100644 --- a/gammapy/estimators/points/profile.py +++ b/gammapy/estimators/points/profile.py @@ -16,7 +16,6 @@ __all__ = ["FluxProfileEstimator"] -@deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") class FluxProfileEstimator(FluxPointsEstimator): """Estimate flux profiles. @@ -91,6 +90,7 @@ class FluxProfileEstimator(FluxPointsEstimator): tag = "FluxProfileEstimator" + @deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") def __init__(self, regions, spectral_model=None, **kwargs): if len(regions) <= 1: raise ValueError( diff --git a/gammapy/estimators/points/sensitivity.py b/gammapy/estimators/points/sensitivity.py index 2b099e7ab3..3aa5be991d 100644 --- a/gammapy/estimators/points/sensitivity.py +++ b/gammapy/estimators/points/sensitivity.py @@ -10,7 +10,6 @@ __all__ = ["SensitivityEstimator"] -@deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") class SensitivityEstimator(Estimator): """Estimate sensitivity. @@ -39,6 +38,7 @@ class SensitivityEstimator(Estimator): tag = "SensitivityEstimator" + @deprecated_renamed_argument("spectrum", "spectral_model", "v1.3") def __init__( self, spectral_model=None, From 9661f4b9a89364af66273022d1c0d61d91b4a7f4 Mon Sep 17 00:00:00 2001 From: Astro-Kirsty Date: Wed, 16 Oct 2024 11:31:21 +0200 Subject: [PATCH 5/5] Add tests for deprecation Signed-off-by: Astro-Kirsty --- gammapy/estimators/map/tests/test_asmooth.py | 5 +++++ gammapy/estimators/points/tests/test_profile.py | 9 +++++++++ gammapy/estimators/points/tests/test_sensitivity.py | 6 ++++++ gammapy/irf/psf/tests/test_kernel.py | 6 +++++- gammapy/irf/psf/tests/test_map.py | 5 +++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gammapy/estimators/map/tests/test_asmooth.py b/gammapy/estimators/map/tests/test_asmooth.py index 7613f19105..90920215f3 100644 --- a/gammapy/estimators/map/tests/test_asmooth.py +++ b/gammapy/estimators/map/tests/test_asmooth.py @@ -7,6 +7,8 @@ from gammapy.estimators import ASmoothMapEstimator from gammapy.maps import Map, MapAxis, WcsNDMap from gammapy.utils.testing import requires_data +from gammapy.modeling.models import PowerLawSpectralModel +from gammapy.utils.deprecation import GammapyDeprecationWarning @pytest.fixture(scope="session") @@ -39,6 +41,9 @@ def test_asmooth(input_dataset_simple): kernel = Tophat2DKernel scales = ASmoothMapEstimator.get_scales(3, factor=2, kernel=kernel) * 0.1 * u.deg + with pytest.warns(GammapyDeprecationWarning): + ASmoothMapEstimator(scales=scales, spectrum=PowerLawSpectralModel()) + asmooth = ASmoothMapEstimator( scales=scales, kernel=kernel, method="lima", threshold=2.5 ) diff --git a/gammapy/estimators/points/tests/test_profile.py b/gammapy/estimators/points/tests/test_profile.py index 8b9eaae10d..405805e48a 100644 --- a/gammapy/estimators/points/tests/test_profile.py +++ b/gammapy/estimators/points/tests/test_profile.py @@ -17,6 +17,7 @@ make_orthogonal_rectangle_sky_regions, ) from gammapy.utils.testing import requires_data, requires_dependency +from gammapy.utils.deprecation import GammapyDeprecationWarning def get_simple_dataset_on_off(): @@ -54,6 +55,13 @@ def test_profile_content(): wcs = mapdataset_onoff.counts.geom.wcs boxes = make_horizontal_boxes(wcs) + with pytest.warns(GammapyDeprecationWarning): + FluxProfileEstimator( + regions=boxes, + energy_edges=[0.1, 1, 10] * u.TeV, + spectrum=PowerLawSpectralModel(), + ) + prof_maker = FluxProfileEstimator( regions=boxes, energy_edges=[0.1, 1, 10] * u.TeV, @@ -61,6 +69,7 @@ def test_profile_content(): n_sigma=1, n_sigma_ul=3, ) + result = prof_maker.run(mapdataset_onoff) imp_prof = result.to_table(sed_type="flux") diff --git a/gammapy/estimators/points/tests/test_sensitivity.py b/gammapy/estimators/points/tests/test_sensitivity.py index 938ec5d794..bc3fecb993 100644 --- a/gammapy/estimators/points/tests/test_sensitivity.py +++ b/gammapy/estimators/points/tests/test_sensitivity.py @@ -5,6 +5,8 @@ from gammapy.estimators import FluxPoints, SensitivityEstimator from gammapy.irf import EDispKernelMap from gammapy.maps import MapAxis, RegionNDMap +from gammapy.modeling.models import PowerLawSpectralModel +from gammapy.utils.deprecation import GammapyDeprecationWarning @pytest.fixture() @@ -37,6 +39,10 @@ def test_cta_sensitivity_estimator(spectrum_dataset, caplog): acceptance=RegionNDMap.from_geom(geom=geom, data=1), acceptance_off=RegionNDMap.from_geom(geom=geom, data=5), ) + with pytest.warns(GammapyDeprecationWarning): + SensitivityEstimator( + gamma_min=25, bkg_syst_fraction=0.075, spectrum=PowerLawSpectralModel() + ) sens = SensitivityEstimator(gamma_min=25, bkg_syst_fraction=0.075) table = sens.run(dataset_on_off) diff --git a/gammapy/irf/psf/tests/test_kernel.py b/gammapy/irf/psf/tests/test_kernel.py index dcf452e11c..67f27effe4 100644 --- a/gammapy/irf/psf/tests/test_kernel.py +++ b/gammapy/irf/psf/tests/test_kernel.py @@ -5,8 +5,9 @@ import astropy.units as u from gammapy.irf import PSFKernel from gammapy.maps import MapAxis, WcsGeom -from gammapy.modeling.models import DiskSpatialModel +from gammapy.modeling.models import DiskSpatialModel, PowerLawSpectralModel from gammapy.utils.testing import mpl_plot_check +from gammapy.utils.deprecation import GammapyDeprecationWarning @pytest.fixture @@ -51,6 +52,9 @@ def test_psf_kernel_to_image(): kernel1 = PSFKernel.from_spatial_model(disk_1, geom, max_radius=rad_max, factor=4) kernel2 = PSFKernel.from_spatial_model(disk_2, geom, max_radius=rad_max, factor=4) + with pytest.warns(GammapyDeprecationWarning): + kernel1.to_image(spectrum=PowerLawSpectralModel()) + kernel1.psf_kernel_map.data[1, :, :] = kernel2.psf_kernel_map.data[1, :, :] kernel_image_1 = kernel1.to_image() diff --git a/gammapy/irf/psf/tests/test_map.py b/gammapy/irf/psf/tests/test_map.py index d2ef82787f..5b2f30c987 100644 --- a/gammapy/irf/psf/tests/test_map.py +++ b/gammapy/irf/psf/tests/test_map.py @@ -10,6 +10,8 @@ from gammapy.makers.utils import make_map_exposure_true_energy, make_psf_map from gammapy.maps import Map, MapAxis, MapCoord, RegionGeom, WcsGeom from gammapy.utils.testing import mpl_plot_check, requires_data +from gammapy.modeling.models import PowerLawSpectralModel +from gammapy.utils.deprecation import GammapyDeprecationWarning @pytest.fixture(scope="session") @@ -423,6 +425,9 @@ def test_psf_map_write_gtpsf(tmpdir): def test_to_image(): psfmap = make_test_psfmap(0.15 * u.deg) + with pytest.warns(GammapyDeprecationWarning): + psfmap.to_image(spectrum=PowerLawSpectralModel()) + psf2D = psfmap.to_image() assert_allclose(psf2D.psf_map.geom.data_shape, (1, 100, 25, 25)) assert_allclose(psf2D.exposure_map.geom.data_shape, (1, 1, 25, 25))