-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import astropy.units as u | ||
import numpy as np | ||
import pytest | ||
import tables | ||
from astropy.table import Table | ||
from astropy.time import Time | ||
|
||
|
||
def test_simple(): | ||
"""Test pointing interpolation""" | ||
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) | ||
|
||
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) | ||
|
||
with pytest.raises(KeyError): | ||
interpolator(tel_id=2, time=t0 + 1 * u.s) | ||
|
||
|
||
def test_azimuth_switchover(): | ||
"""Test pointing interpolation""" | ||
from ctapipe.io.pointing import PointingInterpolator | ||
|
||
t0 = Time("2022-01-01T00:00:00") | ||
|
||
table = Table( | ||
{ | ||
"time": t0 + [0, 1, 2] * u.s, | ||
"azimuth": [359, 1, 3] * u.deg, | ||
"altitude": [60, 61, 62] * u.deg, | ||
}, | ||
) | ||
|
||
interpolator = PointingInterpolator() | ||
interpolator.add_table(1, table) | ||
|
||
alt, az = interpolator(tel_id=1, time=t0 + 0.5 * u.s) | ||
assert u.isclose(az, 360 * u.deg) | ||
assert u.isclose(alt, 60.5 * u.deg) | ||
|
||
|
||
def test_invalid_input(): | ||
"""Test invalid pointing tables raise nice errors""" | ||
from ctapipe.io.pointing import PointingInterpolator | ||
|
||
wrong_time = Table( | ||
{ | ||
"time": [1, 2, 3] * u.s, | ||
"azimuth": [1, 2, 3] * u.deg, | ||
"altitude": [1, 2, 3] * u.deg, | ||
} | ||
) | ||
|
||
interpolator = PointingInterpolator() | ||
with pytest.raises(TypeError, match="astropy.time.Time"): | ||
interpolator.add_table(1, wrong_time) | ||
|
||
wrong_unit = Table( | ||
{ | ||
"time": Time(1.7e9 + np.arange(3), format="unix"), | ||
"azimuth": [1, 2, 3] * u.m, | ||
"altitude": [1, 2, 3] * u.deg, | ||
} | ||
) | ||
with pytest.raises(ValueError, match="compatible with 'rad'"): | ||
interpolator.add_table(1, wrong_unit) | ||
|
||
wrong_unit = Table( | ||
{ | ||
"time": Time(1.7e9 + np.arange(3), format="unix"), | ||
"azimuth": [1, 2, 3] * u.deg, | ||
"altitude": [1, 2, 3], | ||
} | ||
) | ||
with pytest.raises(ValueError, match="compatible with 'rad'"): | ||
interpolator.add_table(1, wrong_unit) | ||
|
||
|
||
def test_hdf5(tmp_path): | ||
from ctapipe.io import write_table | ||
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, | ||
}, | ||
) | ||
|
||
path = tmp_path / "pointing.h5" | ||
write_table(table, path, "/dl0/monitoring/telescope/pointing/tel_001") | ||
with tables.open_file(path) as h5file: | ||
interpolator = PointingInterpolator(h5file) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Add support for interpolating a monitoring pointing table | ||
in ``TableLoader``. The corresponding table is not yet written by ``ctapipe``, | ||
but can be written by external tools. | ||
This is to enable analysis of real obsversations, where the pointing changes over time in | ||
This is to enable analysis of real observations, where the pointing changes over time in | ||
alt/az. |