Skip to content

Commit

Permalink
Add test for bounds behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Dec 12, 2023
1 parent 7d14fe1 commit 875ae2a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ctapipe/io/tests/test_pointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 875ae2a

Please sign in to comment.