Skip to content

Commit b10cfbb

Browse files
committed
Keep channel dimension on waevforms, even if event is gain-selected
1 parent f5d6739 commit b10cfbb

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

src/ctapipe_io_nectarcam/__init__.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,17 @@ def fill_r0r1_camera_container(self, zfits_event):
11581158
)
11591159
expected_pixels = self.nectarcam_service.pixel_ids
11601160

1161+
has_low_gain = (zfits_event.pixel_status & PixelStatus.LOW_GAIN_STORED).astype(
1162+
bool
1163+
)
1164+
has_high_gain = (
1165+
zfits_event.pixel_status & PixelStatus.HIGH_GAIN_STORED
1166+
).astype(bool)
1167+
not_broken = (has_low_gain | has_high_gain).astype(bool)
1168+
11611169
# broken pixels have both false, so gain selected means checking
11621170
# if there are any pixels where exactly one of high or low gain is stored
1163-
# gain_selected = np.any(has_low_gain != has_high_gain)
1171+
gain_selected = np.any(has_low_gain != has_high_gain)
11641172

11651173
# fill value for broken pixels
11661174

@@ -1177,15 +1185,41 @@ def fill_r0r1_camera_container(self, zfits_event):
11771185
# we assume that either all pixels are gain selected or none
11781186
# only broken pixels are allowed to be missing completely
11791187

1180-
reshaped_waveform = zfits_event.waveform.reshape(N_GAINS, n_pixels, n_samples)
1181-
# re-order the waveform following the expected_pixels_id values
1182-
# could also just do waveform = reshaped_waveform[np.argsort(expected_ids)]
1183-
reordered_waveform = np.full(
1184-
(N_GAINS, N_PIXELS, N_SAMPLES), fill, dtype=dtype
1185-
) # VIM : use empty ?
1186-
reordered_waveform[:, expected_pixels, :] = reshaped_waveform
1187-
r0 = R0CameraContainer(waveform=reordered_waveform)
1188-
r1 = R1CameraContainer()
1188+
if gain_selected:
1189+
# print("GAIN SELECTED")
1190+
selected_gain = np.where(has_high_gain, 0, 1)
1191+
waveform = np.full(
1192+
(N_GAINS, n_pixels, n_samples), fill, dtype=dtype
1193+
) # VIM : Replace full by empty ?
1194+
waveform[not_broken] = zfits_event.waveform.reshape((-1, n_samples))[
1195+
not_broken
1196+
]
1197+
1198+
reordered_waveform = np.full(
1199+
(N_GAINS, N_PIXELS, N_SAMPLES), fill, dtype=dtype
1200+
) # VIM : Replace full by empty ?
1201+
reordered_waveform[expected_pixels] = waveform
1202+
1203+
reordered_selected_gain = np.full(N_PIXELS, -1, dtype=np.int8)
1204+
reordered_selected_gain[expected_pixels] = selected_gain
1205+
1206+
r0 = R0CameraContainer()
1207+
r1 = R1CameraContainer(
1208+
waveform=reordered_waveform,
1209+
selected_gain_channel=reordered_selected_gain,
1210+
)
1211+
else:
1212+
reshaped_waveform = zfits_event.waveform.reshape(
1213+
N_GAINS, n_pixels, n_samples
1214+
)
1215+
# re-order the waveform following the expected_pixels_id values
1216+
# could also just do waveform = reshaped_waveform[np.argsort(expected_ids)]
1217+
reordered_waveform = np.full(
1218+
(N_GAINS, N_PIXELS, N_SAMPLES), fill, dtype=dtype
1219+
) # VIM : use empty ?
1220+
reordered_waveform[:, expected_pixels, :] = reshaped_waveform
1221+
r0 = R0CameraContainer(waveform=reordered_waveform)
1222+
r1 = R1CameraContainer()
11891223

11901224
if not self.pre_v6_data:
11911225
if r0.waveform is not None:

0 commit comments

Comments
 (0)