Skip to content

Commit 4265274

Browse files
authored
Merge pull request #29 from cta-observatory/no_tel_ids_with_data
Fix source for older test campaign data without tel_ids_with_data
2 parents 29dfaeb + 93fa9b9 commit 4265274

2 files changed

Lines changed: 40 additions & 15 deletions

File tree

src/ctapipe_io_zfits/conftest.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,42 @@ def get_module_and_pixel_id_map(n_modules, n_pixels_module, missing_modules=None
7171
return module_id_map, pixel_id_map
7272

7373

74-
# we parametrize the dummy dl0 for a couple of different scenarios.
75-
# Tests using this fixture will be run under all scenarios automatically
76-
@pytest.fixture(
77-
scope="session",
78-
params=[
74+
test_configurations = [
75+
pytest.param(
76+
{
77+
"obs_start": Time("2025-02-04T20:45:31"),
78+
"sb_creator_id": 2,
79+
"sb_id": 124,
80+
"obs_id": 789,
81+
},
82+
id="standard",
83+
),
84+
pytest.param(
7985
{
80-
"missing_modules": True,
86+
"missing_modules": [50, 200],
8187
"obs_start": Time("2023-08-02T02:15:31"),
8288
"sb_creator_id": 2,
8389
"sb_id": 123,
8490
"obs_id": 456,
8591
},
92+
id="missing-modules",
93+
),
94+
pytest.param(
8695
{
87-
"missing_modules": False,
96+
"tel_ids_with_data": False,
8897
"obs_start": Time("2025-02-04T20:45:31"),
8998
"sb_creator_id": 2,
90-
"sb_id": 124,
91-
"obs_id": 789,
99+
"sb_id": 125,
100+
"obs_id": 126,
92101
},
93-
],
94-
)
102+
id="no_tel_ids_with_data",
103+
),
104+
]
105+
106+
107+
# we parametrize the dummy dl0 for a couple of different scenarios.
108+
# Tests using this fixture will be run under all scenarios automatically
109+
@pytest.fixture(scope="session", params=test_configurations)
95110
def dummy_dl0(dl0_base, request):
96111
rng = np.random.default_rng(0)
97112

@@ -136,7 +151,7 @@ def dummy_dl0(dl0_base, request):
136151
sb_creator_id=sb_creator_id,
137152
)
138153

139-
missing_modules = [50, 200] if config["missing_modules"] else None
154+
missing_modules = config.get("missing_modules")
140155
module_id_map, pixel_id_map = get_module_and_pixel_id_map(
141156
n_modules=265, n_pixels_module=7, missing_modules=missing_modules
142157
)
@@ -207,6 +222,11 @@ def convert_waveform(waveform):
207222
event_id = i + 1
208223
time_s, time_qns = time_to_cta_high_res(time)
209224

225+
# simulate old data without tel_ids_with_data if asked
226+
kwargs = {}
227+
if config.get("tel_ids_with_data", True):
228+
kwargs["tel_ids_with_data"] = numpy_to_any_array(np.array([1]))
229+
210230
trigger_file.write_message(
211231
DL0_Subarray.Event(
212232
event_id=event_id,
@@ -217,7 +237,7 @@ def convert_waveform(waveform):
217237
event_time_qns=int(time_qns),
218238
trigger_ids=numpy_to_any_array(np.array([event_id])),
219239
tel_ids_with_trigger=numpy_to_any_array(np.array([1])),
220-
tel_ids_with_data=numpy_to_any_array(np.array([1])),
240+
**kwargs,
221241
)
222242
)
223243

src/ctapipe_io_zfits/dl0.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ def _generator(self):
313313
),
314314
)
315315

316-
for tel_id in subarray_trigger.tel_ids_with_data:
316+
tel_ids = subarray_trigger.tel_ids_with_data
317+
# older ACADA test campaign data does not have tel_ids_with_data, which was introduced in 2025
318+
if tel_ids is None:
319+
tel_ids = subarray_trigger.tel_ids_with_trigger
320+
321+
for tel_id in tel_ids:
317322
tel_file = self._telescope_files[tel_id]
318323
camera = self.subarray.tel[tel_id].camera
319324

@@ -435,7 +440,7 @@ def _fill_event(self, count, zfits_event) -> ArrayEventContainer:
435440
time = cta_high_res_to_time(
436441
zfits_event.event_time_s, zfits_event.event_time_qns
437442
)
438-
event_type=EventType(int(zfits_event.event_type))
443+
event_type = EventType(int(zfits_event.event_type))
439444
array_event = ArrayEventContainer(
440445
count=count,
441446
index=EventIndexContainer(

0 commit comments

Comments
 (0)