Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ImageCleaner API #2511

Merged
merged 10 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changes/2511.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Adding monitoring: MonitoringCameraContainer as keyword argument to
the ``ImageCleaner`` API so cleaning algorithms can now access
relevant information for methods that e.g. require monitoring information.
1 change: 1 addition & 0 deletions src/ctapipe/calib/camera/tests/test_calibrator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for CameraCalibrator and related functions
"""

from copy import deepcopy

import astropy.units as u
Expand Down
6 changes: 3 additions & 3 deletions src/ctapipe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def camera_geometry(request):
def _global_example_event():
"""
helper to get a single event from a MC file. Don't use this fixture
directly, rather use `test_event`
directly, rather use `example_event`
"""
filename = get_dataset_path("gamma_test_large.simtel.gz")

Expand Down Expand Up @@ -93,8 +93,8 @@ def example_event(_global_example_event):
example:

.. code-block::
def test_my_thing(test_event):
assert len(test_event.r0.tel) > 0
def test_my_thing(example_event):
assert len(example_event.r0.tel) > 0

"""
return deepcopy(_global_example_event)
Expand Down
41 changes: 36 additions & 5 deletions src/ctapipe/image/cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import numpy as np

from ctapipe.containers import MonitoringCameraContainer

from ..core import TelescopeComponent
from ..core.traits import (
BoolTelescopeParameter,
Expand Down Expand Up @@ -466,7 +468,12 @@ class ImageCleaner(TelescopeComponent):

@abstractmethod
Hckjs marked this conversation as resolved.
Show resolved Hide resolved
def __call__(
self, tel_id: int, image: np.ndarray, arrival_times: np.ndarray = None
self,
tel_id: int,
image: np.ndarray,
arrival_times: np.ndarray = None,
*,
monitoring: MonitoringCameraContainer = None,
) -> np.ndarray:
"""
Identify pixels with signal, and reject those with pure noise.
Expand All @@ -480,6 +487,9 @@ def __call__(
image pixel data corresponding to the camera geometry
arrival_times: np.ndarray
image of arrival time (not used in this method)
monitoring: `ctapipe.containers.MonitoringCameraContainer`
MonitoringCameraContainer to make use of additional parameters
from monitoring data e.g. pedestal std.

Returns
-------
Expand Down Expand Up @@ -514,7 +524,12 @@ class TailcutsImageCleaner(ImageCleaner):
).tag(config=True)

def __call__(
self, tel_id: int, image: np.ndarray, arrival_times=None
self,
tel_id: int,
image: np.ndarray,
arrival_times: np.ndarray = None,
*,
monitoring: MonitoringCameraContainer = None,
) -> np.ndarray:
"""
Apply standard picture-boundary cleaning. See `ImageCleaner.__call__()`
Expand All @@ -536,7 +551,12 @@ class MARSImageCleaner(TailcutsImageCleaner):
"""

def __call__(
self, tel_id: int, image: np.ndarray, arrival_times=None
self,
tel_id: int,
image: np.ndarray,
arrival_times: np.ndarray = None,
*,
monitoring: MonitoringCameraContainer = None,
) -> np.ndarray:
"""
Apply MARS-style image cleaning. See `ImageCleaner.__call__()`
Expand All @@ -563,9 +583,15 @@ class FACTImageCleaner(TailcutsImageCleaner):
).tag(config=True)

def __call__(
self, tel_id: int, image: np.ndarray, arrival_times=None
self,
tel_id: int,
image: np.ndarray,
arrival_times: np.ndarray = None,
*,
monitoring: MonitoringCameraContainer = None,
) -> np.ndarray:
"""Apply FACT-style image cleaning. see ImageCleaner.__call__()"""

return fact_image_cleaning(
geom=self.subarray.tel[tel_id].camera.geometry,
image=image,
Expand All @@ -592,7 +618,12 @@ class TimeConstrainedImageCleaner(TailcutsImageCleaner):
).tag(config=True)

def __call__(
self, tel_id: int, image: np.ndarray, arrival_times=None
self,
tel_id: int,
image: np.ndarray,
arrival_times: np.ndarray = None,
*,
monitoring: MonitoringCameraContainer = None,
) -> np.ndarray:
"""
Apply MAGIC-like image cleaning with timing information. See `ImageCleaner.__call__()`
Expand Down
2 changes: 2 additions & 0 deletions src/ctapipe/image/image_processor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
High level image processing (ImageProcessor Component)
"""

from copy import deepcopy

import numpy as np
Expand Down Expand Up @@ -221,6 +222,7 @@ def _process_telescope_event(self, event):
tel_id=tel_id,
image=dl1_camera.image,
arrival_times=dl1_camera.peak_time,
monitoring=event.mon.tel[tel_id],
)

dl1_camera.parameters = self._parameterize_image(
Expand Down
1 change: 1 addition & 0 deletions src/ctapipe/image/reducer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Algorithms for the data volume reduction.
"""

from abc import abstractmethod

import numpy as np
Expand Down