Skip to content

Commit 8cc1b2a

Browse files
committed
also exclude DL2 telescope merging when tel-wise merge is selected
use data format defs in merge tool tests
1 parent 2a3f0b8 commit 8cc1b2a

3 files changed

Lines changed: 40 additions & 18 deletions

File tree

src/ctapipe/io/hdf5dataformat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"DL2_TEL_GEOMETRY_GROUP",
4444
"DL2_TEL_ENERGY_GROUP",
4545
"DL2_TEL_PARTICLETYPE_GROUP",
46+
"DL2_TEL_IMPACT_GROUP",
4647
"DL0_TEL_POINTING_GROUP",
4748
"DL1_SUBARRAY_POINTING_GROUP",
4849
"DL1_TEL_POINTING_GROUP",
@@ -104,6 +105,7 @@
104105
DL2_TEL_GEOMETRY_GROUP = "/dl2/event/telescope/geometry"
105106
DL2_TEL_ENERGY_GROUP = "/dl2/event/telescope/energy"
106107
DL2_TEL_PARTICLETYPE_GROUP = "/dl2/event/telescope/particle_type"
108+
DL2_TEL_IMPACT_GROUP = "/dl2/event/telescope/impact"
107109

108110
DL2_GROUP = "/dl2"
109111
DL2_SUBARRAY_GROUP = "/dl2/event/subarray"

src/ctapipe/io/hdf5merger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ def __init__(self, output_path=None, **kwargs):
223223
)
224224
self.combine_telescope_data = self.merge_strategy == "combine-telescope-data"
225225
if self.combine_telescope_data and (
226-
not self.telescope_events or self.dl2_subarray
226+
not self.telescope_events or self.dl2_telescope or self.dl2_subarray
227227
):
228228
raise traits.TraitError(
229229
"Merge strategy 'combine-telescope-data' requires telescope_events=True "
230-
"and dl2_subarray=False"
230+
"and dl2_telescope=False and dl2_subarray=False"
231231
)
232232

233233
output_exists = self.output_path.exists()

src/ctapipe/tools/tests/test_merge.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
from ctapipe.core import ToolConfigurationError, run_tool
1515
from ctapipe.io import DataWriter, EventSource, TableLoader
1616
from ctapipe.io.astropy_helpers import read_table
17+
from ctapipe.io.hdf5dataformat import (
18+
DL1_TEL_MUON_GROUP,
19+
DL2_EVENT_STATISTICS_GROUP,
20+
DL2_SUBARRAY_GEOMETRY_GROUP,
21+
OBSERVATION_BLOCK_TABLE,
22+
SCHEDULING_BLOCK_TABLE,
23+
SIMULATION_IMAGES_GROUP,
24+
)
1725
from ctapipe.io.tests.test_astropy_helpers import assert_table_equal
1826
from ctapipe.tools.process import ProcessorTool
1927

@@ -108,7 +116,7 @@ def test_skip_images(tmp_path, dl1_file, dl1_proton_file):
108116
assert "images" in f.root.simulation.event.telescope
109117
assert "parameters" in f.root.dl1.event.telescope
110118

111-
t = read_table(output, "/simulation/event/telescope/images/tel_001")
119+
t = read_table(output, f"{SIMULATION_IMAGES_GROUP}/tel_001")
112120
assert "true_image" not in t.colnames
113121
assert "true_image_sum" in t.colnames
114122

@@ -128,13 +136,13 @@ def test_dl2(tmp_path, dl2_shower_geometry_file, dl2_proton_geometry_file):
128136
)
129137

130138
table1 = read_table(
131-
dl2_shower_geometry_file, "/dl2/event/subarray/geometry/HillasReconstructor"
139+
dl2_shower_geometry_file, f"{DL2_SUBARRAY_GEOMETRY_GROUP}/HillasReconstructor"
132140
)
133141
table2 = read_table(
134-
dl2_proton_geometry_file, "/dl2/event/subarray/geometry/HillasReconstructor"
142+
dl2_proton_geometry_file, f"{DL2_SUBARRAY_GEOMETRY_GROUP}/HillasReconstructor"
135143
)
136144
table_merged = read_table(
137-
output, "/dl2/event/subarray/geometry/HillasReconstructor"
145+
output, f"{DL2_SUBARRAY_GEOMETRY_GROUP}/HillasReconstructor"
138146
)
139147

140148
diff = StringIO()
@@ -143,7 +151,7 @@ def test_dl2(tmp_path, dl2_shower_geometry_file, dl2_proton_geometry_file):
143151
f"Merged table not equal to individual tables. Diff:\n {diff.getvalue()}"
144152
)
145153

146-
stats_key = "/dl2/service/tel_event_statistics/HillasReconstructor"
154+
stats_key = f"{DL2_EVENT_STATISTICS_GROUP}/HillasReconstructor"
147155
merged_stats = read_table(output, stats_key)
148156
stats1 = read_table(dl2_shower_geometry_file, stats_key)
149157
stats2 = read_table(dl2_proton_geometry_file, stats_key)
@@ -152,8 +160,8 @@ def test_dl2(tmp_path, dl2_shower_geometry_file, dl2_proton_geometry_file):
152160
assert np.all(merged_stats[col] == (stats1[col] + stats2[col]))
153161

154162
# test reading configurations as well:
155-
obs = read_table(output, "/configuration/observation/observation_block")
156-
sbs = read_table(output, "/configuration/observation/scheduling_block")
163+
obs = read_table(output, OBSERVATION_BLOCK_TABLE)
164+
sbs = read_table(output, SCHEDULING_BLOCK_TABLE)
157165

158166
assert len(obs) == 2, "should have two OB entries"
159167
assert len(sbs) == 2, "should have two SB entries"
@@ -182,8 +190,8 @@ def test_muon(tmp_path, dl1_muon_output_file):
182190
raises=True,
183191
)
184192

185-
table = read_table(output, "/dl1/event/telescope/muon/tel_001")
186-
input_table = read_table(dl1_muon_output_file, "/dl1/event/telescope/muon/tel_001")
193+
table = read_table(output, f"{DL1_TEL_MUON_GROUP}/tel_001")
194+
input_table = read_table(dl1_muon_output_file, f"{DL1_TEL_MUON_GROUP}/tel_001")
187195

188196
n_input = len(input_table)
189197
assert len(table) == n_input
@@ -365,6 +373,7 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
365373
str(outputs["sub2"]),
366374
f"--output={outputs[merged_mode_name]}",
367375
"--telescope-events",
376+
"--no-dl2-telescope",
368377
"--no-dl2-subarray",
369378
"--combine-telescope-data",
370379
],
@@ -410,16 +419,16 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
410419
argv=[
411420
*argv_options,
412421
"--telescope-events",
422+
"--no-dl2-telescope",
413423
"--no-dl2-subarray",
414424
],
415425
cwd=tmp_path,
416426
raises=True,
417427
)
418428

419429
# 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-
):
430+
traits_error_msg = "Merge strategy 'combine-telescope-data' requires"
431+
with pytest.raises(traits.TraitError, match=traits_error_msg):
423432
run_tool(
424433
MergeTool(),
425434
argv=[
@@ -430,20 +439,30 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
430439
cwd=tmp_path,
431440
raises=True,
432441
)
433-
with pytest.raises(
434-
traits.TraitError, match="Merge strategy 'combine-telescope-data' requires"
435-
):
442+
with pytest.raises(traits.TraitError, match=traits_error_msg):
436443
run_tool(
437444
MergeTool(),
438445
argv=[
439446
*argv_options,
440447
"--telescope-events",
448+
"--no-dl2-telescope",
441449
"--dl2-subarray",
442450
],
443451
cwd=tmp_path,
444452
raises=True,
445453
)
446-
454+
with pytest.raises(traits.TraitError, match=traits_error_msg):
455+
run_tool(
456+
MergeTool(),
457+
argv=[
458+
*argv_options,
459+
"--telescope-events",
460+
"--dl2-telescope",
461+
"--no-dl2-subarray",
462+
],
463+
cwd=tmp_path,
464+
raises=True,
465+
)
447466
# Check that merging files. with different data levels raises an error
448467
# When combining telescope data, data levels must match.
449468
run_tool(
@@ -465,6 +484,7 @@ def test_merge_telescope_data(tmp_path, prod6_gamma_simtel_path):
465484
"--telescope-events",
466485
"--combine-telescope-data",
467486
"--no-dl2-subarray",
487+
"--no-dl2-telescope",
468488
f"--output={outputs['required_node_invalid']}",
469489
],
470490
cwd=tmp_path,

0 commit comments

Comments
 (0)