1414from ctapipe .core import ToolConfigurationError , run_tool
1515from ctapipe .io import DataWriter , EventSource , TableLoader
1616from 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+ )
1725from ctapipe .io .tests .test_astropy_helpers import assert_table_equal
1826from 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