Refactor corresponding tests
@@ -4,38 +4,32 @@ import numpy as np
from numpy.testing import assert_allclose
import astropy.units as u
from gammapy.irf import EffectiveAreaTable, EDispKernel
-from gammapy.spectrum import CountsSpectrum, SensitivityEstimator
-from gammapy.utils.testing import requires_data
+from gammapy.spectrum import CountsSpectrum, SensitivityEstimator, SpectrumDataset
@pytest.fixture()
-def sens():
+def spectrum_dataset():
etrue = np.logspace(0, 1, 21) * u.TeV
- elo = etrue[:-1]
- ehi = etrue[1:]
- area = np.zeros(20) + 1e6 * u.m ** 2
-
- arf = EffectiveAreaTable(energy_lo=elo, energy_hi=ehi, data=area)
-
ereco = np.logspace(0, 1, 5) * u.TeV
- rmf = EDispKernel.from_diagonal_response(etrue, ereco)
+ aeff = EffectiveAreaTable.from_constant(value=1e6 * u.m ** 2, energy=etrue)
+ edisp = EDispKernel.from_diagonal_response(etrue, ereco)
- bkg_array = np.ones(4)
- bkg_array[-1] = 1e-3
- bkg = CountsSpectrum(
- energy_lo=ereco[:-1], energy_hi=ereco[1:], data=bkg_array, unit="s-1"
+ data = np.ones(4)
+ data[-1] = 1e-3
+ background = CountsSpectrum(
+ energy_lo=ereco[:-1], energy_hi=ereco[1:], data=data, unit="s-1"
)
-
- sens = SensitivityEstimator(
- arf=arf, rmf=rmf, bkg=bkg, livetime=1 * u.h, index=2, gamma_min=20, alpha=0.2
+ return SpectrumDataset(
+ aeff=aeff,
+ livetime="5h",
+ edisp=edisp,
+ background=background
)
- sens.run()
- return sens
-@requires_data()
-def test_cta_sensitivity_estimator(sens):
- table = sens.results_table
+def test_cta_sensitivity_estimator(spectrum_dataset):
+ sens = SensitivityEstimator()
+ table = sens.run(spectrum_dataset)
assert len(table) == 4
assert table.colnames == ["energy", "e2dnde", "excess", "background", "criterion"]
