Skip to content

Commit 1d9539b

Browse files
frnbrunjlenain
andauthored
Choose LightNectarCAMEventSource or not in BaseNectarCAMCalibrationTool (#299)
* add boolean to choose the NectarCAMEventSource (instead of the Light one) in the BaseNectarCAMCalibrationTool * More modifications to allow the choice * Clarification in method description * Clarification in method description * Fix bug in case is provided --------- Co-authored-by: Jean-Philippe Lenain <jlenain@in2p3.fr>
1 parent 6c58dfe commit 1d9539b

1 file changed

Lines changed: 46 additions & 13 deletions

File tree

src/nectarchain/makers/core.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from ctapipe.io import HDF5TableWriter
2222
from ctapipe.io.datawriter import DATA_MODEL_VERSION
23-
from ctapipe_io_nectarcam import LightNectarCAMEventSource
23+
from ctapipe_io_nectarcam import LightNectarCAMEventSource, NectarCAMEventSource
2424
from ctapipe_io_nectarcam.containers import NectarCAMDataContainer
2525
from tables.exceptions import HDF5ExtError
2626
from tqdm.auto import tqdm
@@ -77,7 +77,8 @@ def load_run(
7777
max_events: int = None,
7878
run_file: str = None,
7979
camera: int = [camera for camera in ALLOWED_CAMERAS if "QM" in camera][0],
80-
) -> LightNectarCAMEventSource:
80+
use_lightevtsource: bool = True,
81+
) -> LightNectarCAMEventSource | NectarCAMEventSource:
8182
"""Static method to load from $NECTARCAMDATA directory data for specified run
8283
with max_events.
8384
@@ -91,24 +92,38 @@ def load_run(
9192
if provided, will load this run file
9293
camera : str
9394
camera for which data are processed. (Default: NectarCAMQM)
95+
use_lightevtsource : bool, optional
96+
if False the NectarCAMEventSource will be used (Default :
97+
LightNectarCAMEventSource), allowing to load the FEB data
9498
9599
Returns
96100
-------
97-
List[ctapipe_io_nectarcam.LightNectarCAMEventSource]
101+
List[ctapipe_io_nectarcam.(Light)NectarCAMEventSource]
98102
List of EventSource for each run files.
99103
"""
100104
# Load the data from the run file.
101105
if run_file is None:
102106
generic_filename, _ = DataManagement.findrun(run_number, camera=camera)
103107
log.info(f"{str(generic_filename)} will be loaded")
104-
eventsource = LightNectarCAMEventSource(
105-
input_url=generic_filename, max_events=max_events
106-
)
108+
if use_lightevtsource:
109+
eventsource = LightNectarCAMEventSource(
110+
input_url=generic_filename, max_events=max_events
111+
)
112+
else:
113+
eventsource = NectarCAMEventSource(
114+
input_url=generic_filename, max_events=max_events
115+
)
107116
else:
108117
log.info(f"{run_file} will be loaded")
109-
eventsource = LightNectarCAMEventSource(
110-
input_url=run_file, max_events=max_events
111-
)
118+
if use_lightevtsource:
119+
eventsource = LightNectarCAMEventSource(
120+
input_url=run_file, max_events=max_events
121+
)
122+
else:
123+
eventsource = NectarCAMEventSource(
124+
input_url=run_file, max_events=max_events
125+
)
126+
112127
return eventsource
113128

114129

@@ -122,6 +137,8 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
122137
max_events (int, optional): The maximum number of events to be loaded.
123138
Defaults to None.
124139
run_file (optional): The specific run file to be loaded.
140+
use_lightevtsource (bool, optional): Whether or not use the
141+
LightNectarCAMEventSource. Defaults to True.
125142
126143
Example Usage:
127144
maker = EventsLoopMaker(run_number=1234, max_events=1000)
@@ -144,6 +161,7 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
144161
("m", "max-events"): "EventsLoopNectarCAMCalibrationTool.max_events",
145162
("o", "output"): "EventsLoopNectarCAMCalibrationTool.output_path",
146163
"events-per-slice": "EventsLoopNectarCAMCalibrationTool.events_per_slice",
164+
"use_lightevtsource": "EventsLoopNectarCAMCalibrationTool.use_lightevtsource",
147165
}
148166

149167
flags = {
@@ -164,6 +182,7 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
164182
HDF5TableWriter,
165183
]
166184
+ classes_with_traits(LightNectarCAMEventSource)
185+
+ classes_with_traits(NectarCAMEventSource)
167186
+ classes_with_traits(NectarCAMComponent)
168187
)
169188

@@ -209,6 +228,13 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
209228
allow_none=True,
210229
).tag(config=True)
211230

231+
use_lightevtsource = Bool(
232+
help="Indicate to use the LightNectarCAMEventSource or not."
233+
"If True, no FEB info is loaded (faster).",
234+
default_value=True,
235+
allow_none=True,
236+
).tag(config=True)
237+
212238
def __new__(cls, *args, **kwargs):
213239
"""This method is used to pass to the current instance of Tool the traits
214240
defined in the components provided in the componentsList trait.
@@ -255,6 +281,7 @@ def _load_eventsource(self, *args, **kwargs):
255281
self.max_events,
256282
run_file=self.run_file,
257283
camera=self.camera,
284+
use_lightevtsource=self.use_lightevtsource,
258285
)
259286
)
260287

@@ -546,15 +573,21 @@ def event_source(self):
546573
@event_source.setter
547574
def event_source(self, value):
548575
"""
549-
Setter method to set a new LightNectarCAMEventSource to the _reader attribute.
576+
Setter method to set a new LightNectarCAMEventSource or NectarCAMEventSource
577+
to the _reader attribute.
550578
551579
Args:
552-
value: a LightNectarCAMEventSource instance.
580+
value: a LightNectarCAMEventSource or NectarCAMEventSource instance.
553581
"""
554-
if isinstance(value, LightNectarCAMEventSource):
582+
if isinstance(value, LightNectarCAMEventSource) or isinstance(
583+
value, NectarCAMEventSource
584+
):
555585
self._event_source = value
556586
else:
557-
raise TypeError("The reader must be a LightNectarCAMEventSource")
587+
raise TypeError(
588+
"The reader must be a LightNectarCAMEventSource"
589+
"or a NectarCAMEventSource."
590+
)
558591

559592
@property
560593
def _npixels(self):

0 commit comments

Comments
 (0)