Clean up gammapy/irf/tests/test_psf_analytical.py a bit
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import absolute_import, division, print_function, unicode_literals
+import pytest
import numpy as np
from numpy.testing.utils import assert_allclose
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits
-from astropy.units import Quantity
-import pytest
-from astropy.coordinates import Angle
+from astropy import units as u
from ...utils.testing import requires_dependency, requires_data
from ...irf import EnergyDependentMultiGaussPSF
-from ...datasets import gammapy_extra
-
-ENERGIES = Quantity([1, 10, 25], 'TeV')
@requires_dependency('scipy')
@requires_data('gammapy-extra')
-def test_EnergyDependentMultiGaussPSF():
+class TestEnergyDependentMultiGaussPSF:
+
+ @pytest.fixture(scope='session')
+ def psf(self):
+ filename = '$GAMMAPY_EXTRA/test_datasets/unbundled/irfs/psf.fits'
+ return EnergyDependentMultiGaussPSF.read(filename, hdu='POINT SPREAD FUNCTION')
+
+ def test_info(self, psf):
filename = get_pkg_data_filename('data/psf_info.txt')
info_str = open(filename, 'r').read()
- filename = gammapy_extra.filename('test_datasets/unbundled/irfs/psf.fits')
- psf = EnergyDependentMultiGaussPSF.read(filename, hdu='POINT SPREAD FUNCTION')
assert psf.info() == info_str
-
-@requires_data('gammapy-extra')
-def test_EnergyDependentMultiGaussPSF_write(tmpdir):
- filename = gammapy_extra.filename('test_datasets/unbundled/irfs/psf.fits')
- psf = EnergyDependentMultiGaussPSF.read(filename, hdu='POINT SPREAD FUNCTION')
-
+ def test_write(self, tmpdir, psf):
# Write it back to disk
filename = str(tmpdir / 'multigauss_psf_test.fits')
psf.write(filename)
@@ -43,15 +39,9 @@ def test_EnergyDependentMultiGaussPSF_write(tmpdir):
# assert hdu_list[1].verify_checksum() == 1
assert len(hdu_list) == 2
-
-@requires_dependency('scipy')
-@requires_data('gammapy-extra')
-@pytest.mark.parametrize(('energy'), ENERGIES)
-def test_to_table_psf(energy):
- filename = gammapy_extra.filename('datasets/hess-crab4-hd-hap-prod2/run023400-023599/'
- 'run023523/hess_psf_3gauss_023523.fits.gz')
- psf = EnergyDependentMultiGaussPSF.read(filename, hdu='PSF_2D_GAUSS')
- theta = Angle(0, 'deg')
+ def test_to_table_psf(self, psf):
+ energy = 1 * u.TeV
+ theta = 0 * u.deg
table_psf = psf.to_energy_dependent_table_psf(theta)
interpol_param = dict(method='nearest', bounds_error=False)
