From 875ae2a12199247adb15f07147e2fc14ff608941 Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Tue, 12 Dec 2023 11:29:16 +0100 Subject: [PATCH] Add test for bounds behavior --- ctapipe/io/tests/test_pointing.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ctapipe/io/tests/test_pointing.py b/ctapipe/io/tests/test_pointing.py index 6817083944f..10913053c18 100644 --- a/ctapipe/io/tests/test_pointing.py +++ b/ctapipe/io/tests/test_pointing.py @@ -111,3 +111,44 @@ def test_hdf5(tmp_path): alt, az = interpolator(tel_id=1, time=t0 + 1 * u.s) assert u.isclose(alt, 69 * u.deg) assert u.isclose(az, 1 * u.deg) + + +def test_bounds(): + """Test invalid pointing tables raise nice errors""" + from ctapipe.io.pointing import PointingInterpolator + + t0 = Time("2022-01-01T00:00:00") + + table = Table( + { + "time": t0 + np.arange(0.0, 10.1, 2.0) * u.s, + "azimuth": np.linspace(0.0, 10.0, 6) * u.deg, + "altitude": np.linspace(70.0, 60.0, 6) * u.deg, + }, + ) + + interpolator = PointingInterpolator() + interpolator.add_table(1, table) + + with pytest.raises(ValueError, match="below the interpolation range"): + interpolator(tel_id=1, time=t0 - 0.1 * u.s) + + with pytest.raises(ValueError, match="above the interpolation range"): + interpolator(tel_id=1, time=t0 + 10.2 * u.s) + + interpolator = PointingInterpolator(bounds_error=False) + interpolator.add_table(1, table) + for dt in (-0.1, 10.1) * u.s: + alt, az = interpolator(tel_id=1, time=t0 + dt) + assert np.isnan(alt.value) + assert np.isnan(az.value) + + interpolator = PointingInterpolator(bounds_error=False, extrapolate=True) + interpolator.add_table(1, table) + alt, az = interpolator(tel_id=1, time=t0 - 1 * u.s) + assert u.isclose(alt, 71 * u.deg) + assert u.isclose(az, -1 * u.deg) + + alt, az = interpolator(tel_id=1, time=t0 + 11 * u.s) + assert u.isclose(alt, 59 * u.deg) + assert u.isclose(az, 11 * u.deg)