changed tests to assert_allclose
Fixed random seed and assert_allclose to fixed pixel values
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import numpy as np
+from numpy.testing import assert_allclose
from astropy.coordinates import SkyCoord
import astropy.units as u
from ...irf import load_cta_irfs
@@ -8,7 +9,7 @@ from ...spectrum.models import PowerLaw
from ...image.models import SkyGaussian
from ...cube.models import SkyModel
from ...cube import MapDataset
-from ..simulate import simulate_3d
+from ..simulate import simulate_dataset
def test_simulate():
@@ -28,25 +29,26 @@ def test_simulate():
# Define map geometry
axis = MapAxis.from_edges(
- np.logspace(-1, 1.0, 10), unit="TeV", name="energy", interp="log"
+ np.logspace(-1, 1.0, 20), unit="TeV", name="energy", interp="log"
)
geom = WcsGeom.create(
- skydir=(0, 0), binsz=0.05, width=(1, 1), coordsys="GAL", axes=[axis]
+ skydir=(0, 0), binsz=0.025, width=(1, 1), coordsys="GAL", axes=[axis]
)
# Define some observation parameters
pointing = SkyCoord(0 * u.deg, 0 * u.deg, frame="galactic")
- dataset = simulate_3d(
- sky_model_simu, geom, pointing, irfs, livetime=1 * u.h, edisp=True
+ dataset = simulate_dataset(
+ sky_model_simu, geom, pointing, irfs, livetime=10 * u.h, random_state=42
)
assert isinstance(dataset, MapDataset)
assert isinstance(dataset.model, SkyModel)
assert dataset.counts.data.dtype is np.dtype("int")
- assert np.sum(dataset.counts.data) > 0
- assert np.sum(dataset.exposure.data) > 0
- assert np.sum(dataset.edisp.data.data) > 0
- assert np.sum(dataset.psf.data) > 0
- assert np.sum(dataset.background_model.map.data) > 0
+ assert_allclose(dataset.counts.data[5, 20, 20],5)
+ assert_allclose(dataset.exposure.data[5, 20, 20],16122681639.856329)
+ assert_allclose(dataset.background_model.map.data[5, 20, 20],0.9765544250896915)
+ assert_allclose(dataset.psf.data[5, 32, 32],0.044402823)
+ assert_allclose(dataset.edisp.data.data[10,10],0.6623215756621856)
+
