Skip to content

Commit

Permalink
changing the name of GainInterpolator to FlatFieldInterpolator
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Toennis committed Aug 5, 2024
1 parent db1c983 commit 86849d1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/ctapipe/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .interpolation import (
Interpolator,
PointingInterpolator,
GainInterpolator,
FlatFieldInterpolator,
PedestalInterpolator,
)

Expand All @@ -45,5 +45,5 @@
"Interpolator",
"PointingInterpolator",
"PedestalInterpolator",
"GainInterpolator",
"FlatFieldInterpolator",
]
22 changes: 11 additions & 11 deletions src/ctapipe/io/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class PointingInterpolator(Interpolator):
"""

telescope_data_group = "/dl0/monitoring/telescope/pointing"
required_columns = {"time", "azimuth", "altitude"}
required_columns = frozenset(["time", "azimuth", "altitude"])
expected_units = {"azimuth": u.rad, "altitude": u.rad}

def __call__(self, tel_id, time):
Expand Down Expand Up @@ -230,16 +230,16 @@ def add_table(self, tel_id, input_table):
self._interpolators[tel_id]["alt"] = interp1d(mjd, alt, **self.interp_options)


class GainInterpolator(Interpolator):
class FlatFieldInterpolator(Interpolator):
"""
Interpolator for relative gain data
Interpolator for flatfield data
"""

telescope_data_group = "dl1/calibration/gain" # TBD

def __call__(self, tel_id, time):
"""
Interpolate pedestal or gain for a given time and tel_id.
Interpolate flatfield data for a given time and tel_id.
Parameters
----------
Expand All @@ -250,14 +250,14 @@ def __call__(self, tel_id, time):
Returns
-------
gain : array [float]
interpolated relative gain
ffield : array [float]
interpolated flatfield data
"""

self._check_interpolators(tel_id)

gain = self._interpolators[tel_id]["gain"](time)
return gain
ffield = self._interpolators[tel_id]["gain"](time)
return ffield

def add_table(self, tel_id, input_table):
"""
Expand All @@ -270,10 +270,10 @@ def add_table(self, tel_id, input_table):
input_table : astropy.table.Table
Table of pointing values, expected columns
are ``time`` as ``Time`` column and "gain"
for the relative gain data
for the flatfield data
"""

self.required_columns = {"time", "gain"}
self.required_columns = frozenset(["time", "gain"]) # TBD

self._check_tables(input_table)

Expand Down Expand Up @@ -329,7 +329,7 @@ def add_table(self, tel_id, input_table):
for the pedestal data
"""

self.required_columns = {"time", "pedestal"}
self.required_columns = frozenset(["time", "pedestal"]) # TBD

self._check_tables(input_table)

Expand Down
22 changes: 11 additions & 11 deletions src/ctapipe/io/tests/test_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from astropy.time import Time

from ctapipe.io.interpolation import (
GainInterpolator,
FlatFieldInterpolator,
PedestalInterpolator,
PointingInterpolator,
)
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_bounds():
},
)

table_gain = Table(
table_flatfield = Table(
{
"time": np.arange(0.0, 10.1, 2.0),
"gain": np.reshape(np.random.normal(1.0, 1.0, 1850 * 6), (6, 1850)),
Expand All @@ -117,10 +117,10 @@ def test_bounds():

interpolator_pointing = PointingInterpolator()
interpolator_pedestal = PedestalInterpolator()
interpolator_gain = GainInterpolator()
interpolator_flatfield = FlatFieldInterpolator()
interpolator_pointing.add_table(1, table_pointing)
interpolator_pedestal.add_table(1, table_pedestal)
interpolator_gain.add_table(1, table_gain)
interpolator_flatfield.add_table(1, table_flatfield)

error_message = "below the interpolation range"

Expand All @@ -131,7 +131,7 @@ def test_bounds():
interpolator_pedestal(tel_id=1, time=-0.1)

with pytest.raises(ValueError, match=error_message):
interpolator_gain(tel_id=1, time=-0.1)
interpolator_flatfield(tel_id=1, time=-0.1)

with pytest.raises(ValueError, match="above the interpolation range"):
interpolator_pointing(tel_id=1, time=t0 + 10.2 * u.s)
Expand All @@ -142,29 +142,29 @@ def test_bounds():

pedestal = interpolator_pedestal(tel_id=1, time=1.0)
assert all(pedestal == table_pedestal["pedestal"][0])
gain = interpolator_gain(tel_id=1, time=1.0)
assert all(gain == table_gain["gain"][0])
flatfield = interpolator_flatfield(tel_id=1, time=1.0)
assert all(flatfield == table_flatfield["gain"][0])
with pytest.raises(KeyError):
interpolator_pointing(tel_id=2, time=t0 + 1 * u.s)
with pytest.raises(KeyError):
interpolator_pedestal(tel_id=2, time=1.0)
with pytest.raises(KeyError):
interpolator_gain(tel_id=2, time=1.0)
interpolator_flatfield(tel_id=2, time=1.0)

interpolator_pointing = PointingInterpolator(bounds_error=False)
interpolator_pedestal = PedestalInterpolator(bounds_error=False)
interpolator_gain = GainInterpolator(bounds_error=False)
interpolator_flatfield = FlatFieldInterpolator(bounds_error=False)
interpolator_pointing.add_table(1, table_pointing)
interpolator_pedestal.add_table(1, table_pedestal)
interpolator_gain.add_table(1, table_gain)
interpolator_flatfield.add_table(1, table_flatfield)

for dt in (-0.1, 10.1) * u.s:
alt, az = interpolator_pointing(tel_id=1, time=t0 + dt)
assert np.isnan(alt.value)
assert np.isnan(az.value)

assert all(np.isnan(interpolator_pedestal(tel_id=1, time=-0.1)))
assert all(np.isnan(interpolator_gain(tel_id=1, time=-0.1)))
assert all(np.isnan(interpolator_flatfield(tel_id=1, time=-0.1)))

interpolator_pointing = PointingInterpolator(bounds_error=False, extrapolate=True)
interpolator_pointing.add_table(1, table_pointing)
Expand Down

0 comments on commit 86849d1

Please sign in to comment.