add npred_background tests
@@ -895,7 +895,7 @@ def test_stack(sky_model):
@requires_data()
-def test_npred_sig(sky_model, geom, geom_etrue):
+def test_npred(sky_model, geom, geom_etrue):
dataset = get_map_dataset(geom, geom_etrue)
pwl = PowerLawSpectralModel()
@@ -910,9 +910,18 @@ def test_npred_sig(sky_model, geom, geom_etrue):
assert_allclose(
dataset.npred_signal(model_name=model1.name).data.sum(), 150.7487, rtol=1e-3
)
+ assert dataset._background_cached is None
+ assert_allclose(dataset.npred_background().data.sum(), 4000., rtol=1e-3)
+ assert_allclose(dataset._background_cached.data.sum(), 4000., rtol=1e-3)
+
assert_allclose(dataset.npred().data.sum(), 9676.047906, rtol=1e-3)
assert_allclose(dataset.npred_signal().data.sum(), 5676.04790, rtol=1e-3)
+ bkg.spectral_model.norm.value = 1.1
+ assert_allclose(dataset.npred_background().data.sum(), 4400., rtol=1e-3)
+ assert_allclose(dataset._background_cached.data.sum(), 4400., rtol=1e-3)
+
+
with pytest.raises(
KeyError,
match="m2",
@@ -920,6 +929,7 @@ def test_npred_sig(sky_model, geom, geom_etrue):
dataset.npred_signal(model_name="m2")
+
def test_stack_npred():
pwl = PowerLawSpectralModel()
gauss = GaussianSpatialModel(sigma="0.2 deg")
