Skip to content

Commit

Permalink
Merge pull request #187 from cta-observatory/fix_tib_data_type
Browse files Browse the repository at this point in the history
Correct dtype of TIB data
  • Loading branch information
maxnoe authored Jun 1, 2023
2 parents fbf9fc9 + a2d8986 commit a1e3db7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ctapipe_io_lst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
SWAT_DTYPE,
DRAGON_COUNTERS_DTYPE,
TIB_DTYPE,
parse_tib_10MHz_counter,
)
from .constants import (
HIGH_GAIN, LST_LOCATIONS, N_GAINS, N_PIXELS, N_SAMPLES, LST1_LOCATION, REFERENCE_LOCATION,
Expand Down Expand Up @@ -556,7 +557,7 @@ def fill_lst_event_container(self, array_event, zfits_event):
tib = zfits_event.lstcam.tib_data.view(TIB_DTYPE)[0]
lst_evt.tib_event_counter = tib['event_counter']
lst_evt.tib_pps_counter = tib['pps_counter']
lst_evt.tib_tenMHz_counter = tib['tenMHz_counter']
lst_evt.tib_tenMHz_counter = parse_tib_10MHz_counter(tib['tenMHz_counter'])
lst_evt.tib_stereo_pattern = tib['stereo_pattern']
lst_evt.tib_masked_trigger = tib['masked_trigger']

Expand Down
20 changes: 18 additions & 2 deletions src/ctapipe_io_lst/anyarray_dtypes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
'''
Numpy dtypes for the structured arrays send as anyarray of
opaque bytes by EVB in LST R1 and CTA R1v1 debug events.
These data structures are defined in the EVB ICD:
https://edms.cern.ch/ui/file/2411710/2.6/LSTMST-ICD-20191206.pdf
'''
import numpy as np


Expand All @@ -13,8 +20,8 @@
TIB_DTYPE = np.dtype([
('event_counter', np.uint32),
('pps_counter', np.uint16),
('tenMHz_counter', np.uint32),
('stereo_pattern', np.uint8),
('tenMHz_counter', (np.uint8, 3)),
('stereo_pattern', np.uint16),
('masked_trigger', np.uint8),
]).newbyteorder('<')

Expand Down Expand Up @@ -53,3 +60,12 @@
('array_flag', np.uint8),
('event_num', np.uint32),
]).newbyteorder('<')


def parse_tib_10MHz_counter(counter):
"""
Convert the tib 10MHz counter to uint32
The counter is stored using 3 uint8 values forming a 24-bit unsigned integer
"""
return counter[0] + (counter[1] << 8) + (counter[2] << 16)
12 changes: 12 additions & 0 deletions src/ctapipe_io_lst/tests/test_anyarray_dtypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
import numpy as np
from ctapipe_io_lst.anyarray_dtypes import parse_tib_10MHz_counter

COUNTER_VALUES = np.array([1, 1234, 2**16 - 1, 2**24 - 1], dtype=np.uint32)


@pytest.mark.parametrize("value", COUNTER_VALUES)
def test_parse_tib_10MHz_counter(value):
counter_24bit = np.frombuffer(value.tobytes()[:3], np.uint8)
result = parse_tib_10MHz_counter(counter_24bit)
assert result == value

0 comments on commit a1e3db7

Please sign in to comment.