Skip to content

Commit

Permalink
Fill R0 data in case EVB has not applied pe calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Oct 25, 2023
1 parent 24e6138 commit e868560
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/ctapipe_io_lst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ def fill_from_cta_r1(self, array_event, zfits_event):
n_samples = zfits_event.num_samples

readout_shape = (n_channels, n_pixels, n_samples)
waveform = zfits_event.waveform.reshape(readout_shape)
waveform = waveform.astype(np.float32) / scale - offset
raw_waveform = zfits_event.waveform.reshape(readout_shape)
waveform = raw_waveform.astype(np.float32) / scale - offset

reordered_waveform = np.full((n_channels, N_PIXELS, n_samples), 0.0, dtype=np.float32)
reordered_waveform[:, pixel_id_map] = waveform
Expand Down Expand Up @@ -519,6 +519,13 @@ def fill_from_cta_r1(self, array_event, zfits_event):

array_event.r1.tel[self.tel_id] = r1

if DataLevel.R0 in self.datalevels:
reordered_raw_waveform = np.full((n_channels, N_PIXELS, n_samples), 0, dtype=np.uint16)
reordered_raw_waveform[:, pixel_id_map] = raw_waveform
array_event.r0.tel[self.tel_id] = R0CameraContainer(
waveform=reordered_raw_waveform,
)

def fill_lst_from_ctar1(self, zfits_event):
evt = LSTEventContainer(
pixel_status=zfits_event.pixel_status.copy(),
Expand Down
16 changes: 15 additions & 1 deletion src/ctapipe_io_lst/tests/test_cta_r1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ctapipe_io_lst.anyarray_dtypes import CDTS_AFTER_37201_DTYPE, TIB_DTYPE
from ctapipe_io_lst.constants import CLOCK_FREQUENCY_KHZ
from ctapipe.image.toymodel import WaveformModel, Gaussian
from ctapipe.containers import EventType
import socket

from ctapipe_io_lst.event_time import time_to_cta_high
Expand Down Expand Up @@ -285,8 +286,21 @@ def test_drs4_calibration(dummy_cta_r1):
})

with EventSource(dummy_cta_r1, config=config) as source:

n_events = 0
for e in source:
if e.trigger.event_type is EventType.SUBARRAY:
n_channels = 1
else:
n_channels = 2

assert e.r0.tel[1].waveform.dtype == np.uint16
assert e.r0.tel[1].waveform.shape == (n_channels, 1855, 40)

assert e.r1.tel[1].waveform.dtype == np.float32
if e.trigger.event_type is EventType.SUBARRAY:
assert e.r1.tel[1].waveform.shape == (1855, 36)
else:
assert e.r1.tel[1].waveform.shape == (2, 1855, 36)

n_events += 1
assert n_events == 100

0 comments on commit e868560

Please sign in to comment.