22Algorithms for the data volume reduction.
33"""
44
5- from abc import abstractmethod
5+ from abc import ABCMeta , abstractmethod
66
77import numpy as np
88
1818from ctapipe .image .cleaning import dilate
1919from ctapipe .image .extractor import ImageExtractor
2020
21- __all__ = ["DataVolumeReducer" , "NullDataVolumeReducer" , "TailCutsDataVolumeReducer" ]
21+ __all__ = [
22+ "DataVolumeReducer" ,
23+ "NullDataVolumeReducer" ,
24+ "TailCutsDataVolumeReducer" ,
25+ ]
2226
2327
24- class DataVolumeReducer (TelescopeComponent ):
28+ class DataVolumeReducer (TelescopeComponent , metaclass = ABCMeta ):
2529 """
2630 Base component for data volume reducers.
2731 """
@@ -41,39 +45,12 @@ def __init__(self, subarray, config=None, parent=None, **kwargs):
4145 self .subarray = subarray
4246 super ().__init__ (config = config , parent = parent , subarray = subarray , ** kwargs )
4347
44- def __call__ (self , waveforms , tel_id = None , selected_gain_channel = None ):
45- """
46- Call the relevant functions to perform data volume reduction on the
47- waveforms.
48-
49- Parameters
50- ----------
51- waveforms: ndarray
52- Waveforms stored in a numpy array of shape
53- (n_pix, n_samples).
54- tel_id: int
55- The telescope id. Required for the 'image_extractor' and
56- 'camera.geometry' in 'TailCutsDataVolumeReducer'.
57- selected_gain_channel: ndarray
58- The channel selected in the gain selection, per pixel. Required for
59- the 'image_extractor' in 'TailCutsDataVolumeReducer'.
60- extraction.
61-
62- Returns
63- -------
64- mask: array
65- Mask of selected pixels.
66- """
67- mask = self .select_pixels (
68- waveforms , tel_id = tel_id , selected_gain_channel = selected_gain_channel
69- )
70- return mask
71-
7248 @abstractmethod
73- def select_pixels (self , waveforms , tel_id = None , selected_gain_channel = None ):
49+ def __call__ (
50+ self , waveforms , tel_id : int , selected_gain_channel = None
51+ ) -> np .ndarray [bool ]:
7452 """
75- Abstract method to be defined by a DataVolumeReducer subclass.
76- Call the relevant functions for the required pixel selection.
53+ Select pixels of which to keep the waveform data.
7754
7855 Parameters
7956 ----------
@@ -99,7 +76,7 @@ class NullDataVolumeReducer(DataVolumeReducer):
9976 Perform no data volume reduction
10077 """
10178
102- def select_pixels (self , waveforms , tel_id = None , selected_gain_channel = None ):
79+ def __call__ (self , waveforms , tel_id : int , selected_gain_channel = None ):
10380 n_pixels = waveforms .shape [- 2 ]
10481 return np .ones (n_pixels , dtype = bool )
10582
@@ -122,6 +99,16 @@ class TailCutsDataVolumeReducer(DataVolumeReducer):
12299 do_boundary_dilation: BoolTelescopeParameter
123100 If set to 'False', the iteration steps in 2) are skipped and
124101 normal TailcutCleaning is used.
102+
103+ Parameters
104+ ----------
105+ subarray: ctapipe.instrument.SubarrayDescription
106+ Description of the subarray
107+ config: traitlets.loader.Config
108+ Configuration specified by config file or cmdline arguments.
109+ Used to set traitlet values.
110+ Set to None if no configuration to pass.
111+ kwargs
125112 """
126113
127114 image_extractor_type = TelescopeParameter (
@@ -149,17 +136,6 @@ def __init__(
149136 image_extractor = None ,
150137 ** kwargs ,
151138 ):
152- """
153- Parameters
154- ----------
155- subarray: ctapipe.instrument.SubarrayDescription
156- Description of the subarray
157- config: traitlets.loader.Config
158- Configuration specified by config file or cmdline arguments.
159- Used to set traitlet values.
160- Set to None if no configuration to pass.
161- kwargs
162- """
163139 super ().__init__ (config = config , parent = parent , subarray = subarray , ** kwargs )
164140
165141 if cleaner is None :
@@ -178,7 +154,7 @@ def __init__(
178154 self .image_extractor_type = [("type" , "*" , name )]
179155 self .image_extractors [name ] = image_extractor
180156
181- def select_pixels (self , waveforms , tel_id = None , selected_gain_channel = None ):
157+ def __call__ (self , waveforms , tel_id , selected_gain_channel = None ):
182158 camera_geom = self .subarray .tel [tel_id ].camera .geometry
183159 # Pulse-integrate waveforms
184160 extractor = self .image_extractors [self .image_extractor_type .tel [tel_id ]]
0 commit comments