Skip to content

Commit

Permalink
Resort stereo predictions to order in input file
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Nov 20, 2022
1 parent 838d7c8 commit 799925c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ctapipe/tools/apply_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 799925c

Please sign in to comment.