Skip to content

Commit 409a6c4

Browse files
author
guillaume.grolleron
committed
update charges extractor with ctapipe update : the images shape changed from (n_pix, n_sample) to (n_chan, n_pix, n_chan)
1 parent 92301e0 commit 409a6c4

File tree

2 files changed

+39
-43
lines changed

2 files changed

+39
-43
lines changed

src/nectarchain/makers/component/charges_component.py

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,17 @@ def __call__(
176176

177177
__image = CtapipeExtractor.get_image_peak_time(
178178
imageExtractor(
179-
wfs_hg_tmp, self.TEL_ID, constants.HIGH_GAIN, broken_pixels_hg
179+
np.array([wfs_hg_tmp, wfs_lg_tmp]),
180+
self.TEL_ID,
181+
None,
182+
np.array([broken_pixels_hg, broken_pixels_lg]),
180183
)
181184
)
182-
self.__charges_hg[f"{name}"].append(__image[0])
183-
self.__peak_hg[f"{name}"].append(__image[1])
185+
self.__charges_hg[f"{name}"].append(__image[0][0])
186+
self.__peak_hg[f"{name}"].append(__image[1][0])
184187

185-
__image = CtapipeExtractor.get_image_peak_time(
186-
imageExtractor(
187-
wfs_lg_tmp, self.TEL_ID, constants.LOW_GAIN, broken_pixels_lg
188-
)
189-
)
190-
self.__charges_lg[f"{name}"].append(__image[0])
191-
self.__peak_lg[f"{name}"].append(__image[1])
188+
self.__charges_lg[f"{name}"].append(__image[0][1])
189+
self.__peak_lg[f"{name}"].append(__image[1][1])
192190

193191
@staticmethod
194192
def _get_extractor_kwargs_from_method_and_kwargs(method: str, kwargs: dict):
@@ -568,44 +566,42 @@ def compute_charges(
568566
imageExtractor = __class__._get_imageExtractor(
569567
method=method, subarray=subarray, **kwargs
570568
)
571-
if channel == constants.HIGH_GAIN:
572-
out = np.array(
573-
[
574-
CtapipeExtractor.get_image_peak_time(
575-
imageExtractor(
576-
waveformsContainer.wfs_hg[i],
577-
tel_id,
578-
channel,
579-
waveformsContainer.broken_pixels_hg[i],
580-
)
569+
out = np.array(
570+
[
571+
CtapipeExtractor.get_image_peak_time(
572+
imageExtractor(
573+
waveforms=np.array(
574+
[waveformsContainer.wfs_hg[i], waveformsContainer.wfs_lg[i]]
575+
),
576+
tel_id=tel_id,
577+
selected_gain_channel=None,
578+
broken_pixels=np.array(
579+
[
580+
waveformsContainer.broken_pixels_hg[i],
581+
waveformsContainer.broken_pixels_lg[i],
582+
]
583+
),
581584
)
582-
for i in range(len(waveformsContainer.wfs_hg))
583-
]
584-
).transpose(1, 0, 2)
585-
return ChargesContainer.fields["charges_hg"].dtype.type(
586-
out[0]
587-
), ChargesContainer.fields["peak_hg"].dtype.type(out[1])
585+
)
586+
for i in range(len(waveformsContainer.wfs_hg))
587+
]
588+
)
589+
# by setting selected_gain_channel to None, we can now pass to ctapipe extractor
590+
# waveforms in (n_ch, n_pix, n_samples)
591+
# then out hase shape (n_events, 2, n_ch, n_pi)
592+
if channel == constants.HIGH_GAIN:
593+
index = 0
594+
gain_label = "hg"
588595
elif channel == constants.LOW_GAIN:
589-
out = np.array(
590-
[
591-
CtapipeExtractor.get_image_peak_time(
592-
imageExtractor(
593-
waveformsContainer.wfs_lg[i],
594-
tel_id,
595-
channel,
596-
waveformsContainer.broken_pixels_lg[i],
597-
)
598-
)
599-
for i in range(len(waveformsContainer.wfs_lg))
600-
]
601-
).transpose(1, 0, 2)
602-
return ChargesContainer.fields["charges_lg"].dtype.type(
603-
out[0]
604-
), ChargesContainer.fields["peak_lg"].dtype.type(out[1])
596+
index = 1
597+
gain_label = "lg"
605598
else:
606599
raise ArgumentError(
607600
None, f"channel must be {constants.LOW_GAIN} or {constants.HIGH_GAIN}"
608601
)
602+
return ChargesContainer.fields[f"charges_{gain_label}"].dtype.type(
603+
out[:, 0, index, :]
604+
), ChargesContainer.fields[f"peak_{gain_label}"].dtype.type(out[:, 1, index, :])
609605

610606
@staticmethod
611607
def histo_hg(

src/nectarchain/makers/tests/test_core_makers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def test_finish_components(self, mock_finish_components, tool_instance_run_file)
385385

386386
_ = tool_instance_run_file._finish_components()
387387

388-
assert mock_finish_components.called_with([MockComponent().finish()], 0)
388+
mock_finish_components.assert_called()
389389

390390
@patch("nectarchain.makers.core.HDF5TableWriter")
391391
def test_write_container_with_nectarcam_container(

0 commit comments

Comments
 (0)