Improve test_map_maker
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest
+from numpy.testing import assert_allclose
import astropy.units as u
from astropy.coordinates import SkyCoord
-from ...utils.testing import assert_quantity_allclose, requires_data
+from ...utils.testing import requires_data
from ...data import DataStore
from ...maps import WcsGeom, MapAxis
from ..make import MapMaker
@@ -12,8 +13,10 @@ pytest.importorskip('scipy')
@pytest.fixture(scope='session')
-def data_store():
- return DataStore.from_dir("$GAMMAPY_EXTRA/datasets/cta-1dc/index/gps/")
+def obs_list():
+ data_store = DataStore.from_dir("$GAMMAPY_EXTRA/datasets/cta-1dc/index/gps/")
+ obs_id = [110380, 111140]
+ return data_store.obs_list(obs_id)
@pytest.fixture(scope='session')
@@ -25,20 +28,32 @@ def geom():
@requires_data('gammapy-extra')
-@pytest.mark.parametrize("mode, expected", [("trim", 107214.0), ("strict", 53486.0)])
-def test_map_maker(mode, expected, data_store, geom):
- mmaker = MapMaker(geom, '6 deg', cutout_mode=mode)
- obs = [110380, 111140]
-
- for obsid in obs:
- mmaker.process_obs(data_store.obs(obsid))
-
- assert mmaker.exposure_map.unit == "m2 s"
- assert_quantity_allclose(mmaker.counts_map.data.sum(), expected)
-
- maker = MapMaker(geom, '6 deg', cutout_mode=mode)
- obslist = data_store.obs_list(obs)
- maps = maker.run(obslist)
-
- assert maps['exposure_map'].unit == "m2 s"
- assert_quantity_allclose(maps['counts_map'].data.sum(), expected)
+@pytest.mark.parametrize("pars", [
+ {
+ 'mode': 'trim',
+ 'counts': 107214,
+ 'exposure': 9.582158e+13,
+ 'background': 107214.016,
+ },
+ {
+ 'mode': 'strict',
+ 'counts': 53486,
+ 'exposure': 4.794064e+13,
+ 'background': 53486,
+ },
+])
+def test_map_maker(pars, obs_list, geom):
+ maker = MapMaker(geom, '6 deg', cutout_mode=pars['mode'])
+ maps = maker.run(obs_list)
+
+ counts = maps['counts_map']
+ assert counts.unit == ""
+ assert_allclose(counts.data.sum(), pars['counts'], rtol=1e-5)
+
+ exposure = maps['exposure_map']
+ assert exposure.unit == "m2 s"
+ assert_allclose(exposure.data.sum(), pars['exposure'], rtol=1e-5)
+
+ background = maps['background_map']
+ assert background.unit == ""
+ assert_allclose(background.data.sum(), pars['background'], rtol=1e-5)
