Add tests for extract.py
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import pytest
+import logging
import numpy as np
from numpy.testing import assert_allclose
import astropy.units as u
@@ -12,6 +13,7 @@ from ...background import ReflectedRegionsBackgroundEstimator
from ...maps import WcsGeom, WcsNDMap
from ...data import DataStore
+log = logging.getLogger(__name__)
@pytest.fixture(scope="session")
def exclusion_mask():
@@ -165,3 +167,30 @@ class TestSpectrumExtraction:
extraction.compute_energy_threshold(method_lo="area_max", area_percent_lo=10)
actual = extraction.spectrum_observations[0].energy_range[0]
assert_quantity_allclose(actual, 0.8799225 * u.TeV, rtol=1e-3)
+
+
+def test_extract_cta_1dc_data(caplog):
+ datastore = DataStore.from_dir("$GAMMAPY_DATA/cta-1dc/index/gps/")
+ obs_ids = [110380, 111140]
+ observations = datastore.get_observations(obs_ids)
+
+ pos = SkyCoord(0.0, 0.0, unit="deg", frame="galactic")
+ radius = Angle(0.11, "deg")
+ on_region = CircleSkyRegion(pos, radius)
+
+ est = ReflectedRegionsBackgroundEstimator(
+ observations=observations,
+ on_region=on_region,
+ min_distance_input="0.2 deg",
+ )
+ est.run()
+ # This will test non PSF3D input as well as absence of default thresholds
+ extract = SpectrumExtraction(bkg_estimate=est.result, observations=observations,
+ containment_correction=True)
+ extract.run()
+ assert 'No thresholds defined for obs Info for OBS_ID = 110380' in caplog.text
+
+ extract.compute_energy_threshold(method_lo="area_max", area_percent_lo=10)
+ actual = extract.spectrum_observations[0].energy_range[0]
+ assert_quantity_allclose(actual, 0.774263 * u.TeV, rtol=1e-3)
+
