Skip to content

Commit

Permalink
Fix error in ctapipe-process in case telescope event is missing true …
Browse files Browse the repository at this point in the history
…image
  • Loading branch information
maxnoe committed Nov 27, 2024
1 parent 055b62b commit 488848a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/changes/2659.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Fix error in ``ctapipe-process`` when in the middle of a simtel file
that has true images available, a telescope event is missing the true image.
This can happen rarely in case a telescope triggered on pure NSB or
is oversaturated to the point where the true pe didn't fit into memory constraints.

The error was due to the ``DataWriter`` trying to write a ``None`` into an
already setup table for the true images.

The ``SimTelEventSource`` will no create an invalid true image filled with ``-1``
for such events.
13 changes: 13 additions & 0 deletions src/ctapipe/io/simteleventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def __init__(self, input_url=Undefined, config=None, parent=None, **kwargs):
self.file_, kind=self.atmosphere_profile_choice
)

self._has_true_image = None
self.log.debug(f"Using gain selector {self.gain_selector}")

def __exit__(self, exc_type, exc_val, exc_tb):
Expand Down Expand Up @@ -872,6 +873,18 @@ def _generate_events(self):
.get("photoelectrons", None)
)

if self._has_true_image is None:
self._has_true_image = true_image is not None

if self._has_true_image and true_image is None:
self.log.warning(
"Encountered telescope event with missing true_image in"
"file that has true images: event_id = %d, tel_id = %d",
event_id,
tel_id,
)
true_image = np.full(n_pixels, -1, dtype=np.int32)

if data.simulation is not None:
if data.simulation.shower is not None:
impact_container = TelescopeImpactParameterContainer(
Expand Down

0 comments on commit 488848a

Please sign in to comment.