From 799925c2a2167b2bdaba9092b2603bc7295708d3 Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Sun, 20 Nov 2022 19:04:12 +0100 Subject: [PATCH] Resort stereo predictions to order in input file --- ctapipe/tools/apply_models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ctapipe/tools/apply_models.py b/ctapipe/tools/apply_models.py index 49aa949b7fc..73be64a8c62 100644 --- a/ctapipe/tools/apply_models.py +++ b/ctapipe/tools/apply_models.py @@ -11,7 +11,9 @@ from ctapipe.core.tool import Tool from ctapipe.core.traits import Bool, Path, flag from ctapipe.io import TableLoader, write_table +from ctapipe.io.astropy_helpers import read_table from ctapipe.io.tableio import TelListToMaskTransform +from ctapipe.io.tableloader import _join_subarray_events from ctapipe.reco import EnergyRegressor, ParticleClassifier, StereoCombiner __all__ = [ @@ -203,6 +205,15 @@ def _combine(self, combiner, mono_predictions): stereo_predictions[c.name] = np.array([trafo(r) for r in c]) stereo_predictions[c.name].description = c.description + # to ensure events are stored in the correct order, + # we resort to trigger table order + trigger = read_table(self.h5file, "/dl1/event/subarray/trigger")[ + ["obs_id", "event_id"] + ] + trigger["__sort_index__"] = np.arange(len(trigger)) + stereo_predictions = _join_subarray_events(trigger, stereo_predictions) + stereo_predictions.sort("__sort_index__") + write_table( stereo_predictions, self.output_path,