Skip to content

Commit

Permalink
Add test, limit to first 8 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Feb 28, 2024
1 parent 2b1464a commit c82b0b7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ctapipe_io_lst/evb_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def get_processings_for_trigger_bits(camera_configuration):
tdp_action = camera_configuration.debug.ttype_pattern

# first bit (no shift) is default handling
default = EVBPreprocessingFlag(int(tdp_action[0]))
# only look at the first byte for now (maximum 6 bits defied above)
default = EVBPreprocessingFlag(int(tdp_action[0]) & 0xff)
actions = defaultdict(lambda: default)

# the following bits refer to the entries in tdp_type
Expand All @@ -61,6 +62,7 @@ def get_processings_for_trigger_bits(camera_configuration):
if trigger_bits == 0:
continue

actions[TriggerBits(int(trigger_bits))] = EVBPreprocessingFlag(int(tdp_action[i]))
# only look at the first byte for now (maximum 6 bits defied above)
actions[TriggerBits(int(trigger_bits))] = EVBPreprocessingFlag(int(tdp_action[i]) & 0xff)

return actions
56 changes: 56 additions & 0 deletions src/ctapipe_io_lst/tests/test_evb_preprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
from pathlib import Path
from protozfits import File
from ctapipe_io_lst import TriggerBits
from ctapipe_io_lst.evb_preprocessing import EVBPreprocessingFlag

import pytest


test_data = Path(os.getenv('LSTCHAIN_TEST_DATA', 'test_data')).absolute()

test_files = [
"20231214/LST-1.1.Run16102.0000_first50.fits.fz", # has only baseline enabled
"20231218/LST-1.1.Run16231.0000_first50.fits.fz", # baseline + gain selection for physics
"20231219/LST-1.1.Run16255.0000_first50.fits.fz", # all corrections + gain selection for physics
]

all_corrections = EVBPreprocessingFlag.BASELINE_SUBTRACTION | EVBPreprocessingFlag.DELTA_T_CORRECTION | EVBPreprocessingFlag.PE_CALIBRATION | EVBPreprocessingFlag.PEDESTAL_SUBTRACTION

expected = [
{
TriggerBits.MONO: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.STEREO: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.MONO|TriggerBits.PEDESTAL: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.MONO|TriggerBits.CALIBRATION: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.PEDESTAL: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.CALIBRATION: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
},
{
TriggerBits.MONO: EVBPreprocessingFlag.BASELINE_SUBTRACTION | EVBPreprocessingFlag.GAIN_SELECTION,
TriggerBits.STEREO: EVBPreprocessingFlag.BASELINE_SUBTRACTION | EVBPreprocessingFlag.GAIN_SELECTION,
TriggerBits.MONO|TriggerBits.PEDESTAL: EVBPreprocessingFlag.BASELINE_SUBTRACTION | EVBPreprocessingFlag.GAIN_SELECTION,
TriggerBits.MONO|TriggerBits.CALIBRATION: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.PEDESTAL: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
TriggerBits.CALIBRATION: EVBPreprocessingFlag.BASELINE_SUBTRACTION,
},
{
TriggerBits.MONO: all_corrections | EVBPreprocessingFlag.GAIN_SELECTION,
TriggerBits.STEREO: all_corrections| EVBPreprocessingFlag.GAIN_SELECTION,
TriggerBits.MONO|TriggerBits.PEDESTAL: all_corrections | EVBPreprocessingFlag.GAIN_SELECTION,
TriggerBits.MONO|TriggerBits.CALIBRATION: all_corrections,
TriggerBits.PEDESTAL: all_corrections,
TriggerBits.CALIBRATION: all_corrections,
},
]
@pytest.mark.parametrize(("test_file", "expected"), zip(test_files, expected))
def test_get_processings_for_trigger_bits(test_file, expected):
from ctapipe_io_lst.evb_preprocessing import get_processings_for_trigger_bits

path = test_data / "real/R0/" / test_file

with File(str(path)) as f:
camera_config = f.CameraConfiguration[0]

result = get_processings_for_trigger_bits(camera_config)
assert result == expected

0 comments on commit c82b0b7

Please sign in to comment.