Skip to content

Commit 2a3f0b8

Browse files
committed
exclude DL2 subarray when merging telescope data
1 parent 488695a commit 2a3f0b8

2 files changed

Lines changed: 46 additions & 8 deletions

File tree

src/ctapipe/io/hdf5merger.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,12 @@ def __init__(self, output_path=None, **kwargs):
222222
"Merge strategy 'monitoring-only' requires monitoring=True"
223223
)
224224
self.combine_telescope_data = self.merge_strategy == "combine-telescope-data"
225-
if self.combine_telescope_data and not self.telescope_events:
225+
if self.combine_telescope_data and (
226+
not self.telescope_events or self.dl2_subarray
227+
):
226228
raise traits.TraitError(
227-
"Merge strategy 'combine-telescope-data' requires telescope_events=True"
229+
"Merge strategy 'combine-telescope-data' requires telescope_events=True "
230+
"and dl2_subarray=False"
228231
)
229232

230233
output_exists = self.output_path.exists()
@@ -551,7 +554,7 @@ def _append_monitoring_dl2_groups(self, other):
551554
DL2_SUBARRAY_CROSS_CALIBRATION_GROUP,
552555
]
553556
for key in monitoring_dl2_subarray_groups:
554-
if key in other.root:
557+
if self.dl2_subarray and key in other.root:
555558
self._append_table(other, other.root[key], once=self.single_ob)
556559

557560
def _append_pixel_statistics(self, other):

src/ctapipe/tools/tests/test_merge.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
301301
as processing all telescopes together.
302302
"""
303303

304+
from ctapipe.core import traits
304305
from ctapipe.io.hdf5merger import CannotMerge
305306
from ctapipe.tools.merge import MergeTool
306307
from ctapipe.tools.process import ProcessorTool
@@ -322,7 +323,7 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
322323
"sub2_dl1b": tmp_path / "gamma_sub2_noimages.dl1b.h5",
323324
"merged": tmp_path / "gamma_merged.dl1.h5",
324325
"merged_appendmode": tmp_path / "gamma_merged_appendmode.dl1.h5",
325-
"tel_ids_invalid": tmp_path / "duplicated_tel_ids_invalid.dl1.h5",
326+
"invalid": tmp_path / "invalid.dl1.h5",
326327
"required_node_invalid": tmp_path / "required_node_invalid.dl1.h5",
327328
}
328329
# Select a few telescopes that cover different telescope types
@@ -364,6 +365,7 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
364365
str(outputs["sub2"]),
365366
f"--output={outputs[merged_mode_name]}",
366367
"--telescope-events",
368+
"--no-dl2-subarray",
367369
"--combine-telescope-data",
368370
],
369371
cwd=tmp_path,
@@ -394,17 +396,49 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
394396

395397
# Check that merging files with overlapping telescope IDs raises an error
396398
# When combining telescope data, telescope IDs must be unique.
399+
argv_options = [
400+
str(outputs["sub1"]),
401+
str(outputs[merged_mode_name]),
402+
f"--output={outputs['invalid']}",
403+
"--combine-telescope-data",
404+
]
397405
with pytest.raises(
398406
ValueError, match="Duplicate telescope IDs found when merging file"
399407
):
400408
run_tool(
401409
MergeTool(),
402410
argv=[
403-
str(outputs["sub1"]),
404-
str(outputs[merged_mode_name]),
411+
*argv_options,
405412
"--telescope-events",
406-
"--combine-telescope-data",
407-
f"--output={outputs['tel_ids_invalid']}",
413+
"--no-dl2-subarray",
414+
],
415+
cwd=tmp_path,
416+
raises=True,
417+
)
418+
419+
# Check that merging files with incompatible options raises a TraitError
420+
with pytest.raises(
421+
traits.TraitError, match="Merge strategy 'combine-telescope-data' requires"
422+
):
423+
run_tool(
424+
MergeTool(),
425+
argv=[
426+
*argv_options,
427+
"--no-telescope-events",
428+
"--no-dl2-subarray",
429+
],
430+
cwd=tmp_path,
431+
raises=True,
432+
)
433+
with pytest.raises(
434+
traits.TraitError, match="Merge strategy 'combine-telescope-data' requires"
435+
):
436+
run_tool(
437+
MergeTool(),
438+
argv=[
439+
*argv_options,
440+
"--telescope-events",
441+
"--dl2-subarray",
408442
],
409443
cwd=tmp_path,
410444
raises=True,
@@ -430,6 +464,7 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
430464
str(outputs["sub2_dl1b"]),
431465
"--telescope-events",
432466
"--combine-telescope-data",
467+
"--no-dl2-subarray",
433468
f"--output={outputs['required_node_invalid']}",
434469
],
435470
cwd=tmp_path,

0 commit comments

Comments
 (0)