Skip to content

Commit

Permalink
Merge pull request #208 from cta-observatory/time_offset
Browse files Browse the repository at this point in the history
Add option to correct event times by a fixed shift
  • Loading branch information
maxnoe authored Jan 16, 2024
2 parents 8cca1cb + 5536e2d commit 37baa46
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ctapipe_io_lst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
OpticsDescription,
SizeType,
)
from astropy.time import Time
from astropy.time import Time, TimeDelta

from ctapipe.io import EventSource, read_table
from ctapipe.io.datalevels import DataLevel
Expand Down Expand Up @@ -267,6 +267,12 @@ class LSTEventSource(EventSource):
)
).tag(config=True)

event_time_correction_s = Float(
default_value=None,
allow_none=True,
help='If given, this number of seconds is *added* to the original event time. This is intendend to be used to correct wrong event timestamps due to wrong time on the White Rabbit switch.'
).tag(config=True)


classes = [PointingSource, EventTimeCalculator, LSTR0Corrections]

Expand Down Expand Up @@ -378,12 +384,14 @@ def __init__(self, input_url=None, **kwargs):

self.read_pedestal_ids()



if self.use_flatfield_heuristic is None:
self.use_flatfield_heuristic = self.run_start < NO_FF_HEURISTIC_DATE
self.log.info(f"Changed `use_flatfield_heuristic` to {self.use_flatfield_heuristic}")

self._event_time_correction = None
if self.event_time_correction_s is not None:
self._event_time_correction = TimeDelta(self.event_time_correction_s * u.s)

@property
def subarray(self):
return self._subarray
Expand Down Expand Up @@ -634,6 +642,12 @@ def _generator(self):

self.fill_mon_container(array_event, zfits_event)

# apply correction before the rest, so corrected time is used e.g. for pointing
if self._event_time_correction is not None:
array_event.trigger.time += self._event_time_correction
for tel_trigger in array_event.trigger.tel.values():
tel_trigger.time += self._event_time_correction

if self.pointing_information:
self.fill_pointing_info(array_event)

Expand Down
25 changes: 25 additions & 0 deletions src/ctapipe_io_lst/tests/test_lsteventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,28 @@ def test_reference_position():
assert u.isclose(position.lat, LST1_LOCATION.lat)
assert u.isclose(position.lon, LST1_LOCATION.lon)
assert u.isclose(position.height, LST1_LOCATION.height)




@pytest.mark.parametrize("timeshift", (-5, 70))
def test_time_correction(timeshift):
from ctapipe_io_lst import LSTEventSource
config = {
'LSTEventSource': {
'input_url': test_r0_path_all_streams,
'apply_drs4_corrections': False,
'pointing_information': False,
'max_events': 5,
},
}

original = LSTEventSource(config=Config(config))
shifted = LSTEventSource(config=Config(config), event_time_correction_s=timeshift)

with original, shifted:
for event, event_shifted in zip(original, shifted):
dt = event_shifted.trigger.time - event.trigger.time
dt_tel = event_shifted.trigger.tel[1].time - event.trigger.tel[1].time
assert u.isclose(dt.to_value(u.s), timeshift)
assert u.isclose(dt_tel.to_value(u.s), timeshift)

0 comments on commit 37baa46

Please sign in to comment.