Skip to content

Commit

Permalink
Merge pull request #146 from cta-observatory/auto_flatfield_heuristic
Browse files Browse the repository at this point in the history
Determine default for use_flatfield_heuristic by date
  • Loading branch information
maxnoe authored Mar 30, 2022
2 parents 6e76c2d + e1e695b commit 4fadbd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 18 additions & 5 deletions ctapipe_io_lst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
OpticsDescription,
)
from enum import IntFlag, auto
from astropy.time import Time

from ctapipe.io import EventSource, read_table
from ctapipe.io.datalevels import DataLevel
Expand All @@ -43,9 +44,14 @@
HIGH_GAIN, N_GAINS, N_PIXELS, N_SAMPLES
)


__all__ = ['LSTEventSource', '__version__']


# Date from which the flatfield heuristic will be switch off by default
NO_FF_HEURISTIC_DATE = Time("2022-01-01T00:00:00")


class TriggerBits(IntFlag):
'''
See TIB User manual
Expand Down Expand Up @@ -197,12 +203,14 @@ class LSTEventSource(EventSource):
).tag(config=True)

use_flatfield_heuristic = Bool(
default_value=False,
default_value=None,
allow_none=True,
help=(
'If true, try to identify flat field events independent of the'
' trigger type in the event. This should only be needed for data'
' from before 2022, when a TIB firmware update fixed the issue with'
' unreliable UCTS information in the event data'
'Whether or not to try to identify flat field events independent of'
' the trigger type in the event. If None (the default) the decision'
' will be made based on the date of the run, as this should only be'
' needed for data from before 2022, when a TIB firmware update fixed'
' the issue with unreliable UCTS information in the event data'
),
).tag(config=True)

Expand Down Expand Up @@ -308,6 +316,11 @@ def __init__(self, input_url=None, **kwargs):

self.read_pedestal_ids()

if self.use_flatfield_heuristic is None:
date_of_run = Time(self.camera_config.date, format='unix')
self.use_flatfield_heuristic = date_of_run < NO_FF_HEURISTIC_DATE
self.log.info(f"Changed `use_flatfield_heuristic` to {self.use_flatfield_heuristic}")

@property
def subarray(self):
return self._subarray
Expand Down
4 changes: 3 additions & 1 deletion ctapipe_io_lst/tests/test_stage1.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_stage1(tmp_path):

config = {
'LSTEventSource': {
'use_flatfield_heuristic': True,
'LSTR0Corrections': {
'drs4_pedestal_path': str(test_drs4_pedestal_path),
'drs4_time_calibration_path': str(test_time_calib_path),
Expand Down Expand Up @@ -71,6 +70,9 @@ def test_stage1(tmp_path):
# test our custom default works
assert tool.event_source.r0_r1_calibrator.gain_selector.threshold == 3500

# test it used the ff heuristic because run is from before 2022
assert tool.event_source.use_flatfield_heuristic

parameters = read_table(output, '/dl1/event/telescope/parameters/tel_001')
assert len(parameters) == 200

Expand Down

0 comments on commit 4fadbd6

Please sign in to comment.