diff --git a/src/ctapipe/image/statistics.py b/src/ctapipe/image/statistics.py index 83d1d878d15..6af55999dd8 100644 --- a/src/ctapipe/image/statistics.py +++ b/src/ctapipe/image/statistics.py @@ -10,7 +10,7 @@ StatisticsContainer, ) from ..core import Component, FeatureGenerator, QualityQuery -from ..core.traits import List, Tuple, Unicode +from ..core.traits import List, TraitError, Tuple, Unicode from ..vectorization import ( collect_features, get_subarray_index, @@ -156,6 +156,9 @@ def aggregate_table(self, mono_parameters: Table) -> Table: Construct table containing aggregated image parameters from table of telescope events. """ + if len(self.image_parameters) == 0: + raise TraitError("No DL1 image parameters to aggregate are specified.") + mono_parameters = self.feature_generator(mono_parameters) passes_cuts = self.quality_query.get_table_mask(mono_parameters) diff --git a/src/ctapipe/tools/aggregate_features.py b/src/ctapipe/tools/aggregate_features.py index 5bc81e8a941..4a2f9d43b7b 100644 --- a/src/ctapipe/tools/aggregate_features.py +++ b/src/ctapipe/tools/aggregate_features.py @@ -4,7 +4,7 @@ import tables from tqdm.auto import tqdm -from ..core import Tool, ToolConfigurationError +from ..core import Tool from ..core.traits import Bool, Integer, Path, flag from ..image import FeatureAggregator from ..io import HDF5Merger, TableLoader, write_table @@ -118,10 +118,6 @@ def setup(self): ) ) self.aggregator = FeatureAggregator(parent=self) - if len(self.aggregator.image_parameters) == 0: - raise ToolConfigurationError( - "No image parameters to aggregate are specified." - ) def start(self): """Aggregate DL1 image parameters for input tables.""" diff --git a/src/ctapipe/tools/process.py b/src/ctapipe/tools/process.py index 6dbdc3ddbdb..3b1fee50c2b 100644 --- a/src/ctapipe/tools/process.py +++ b/src/ctapipe/tools/process.py @@ -7,7 +7,7 @@ from tqdm.auto import tqdm from ..calib import CameraCalibrator, GainSelector -from ..core import QualityQuery, Tool, ToolConfigurationError +from ..core import QualityQuery, Tool from ..core.traits import Bool, classes_with_traits, flag from ..image import FeatureAggregator, ImageCleaner, ImageModifier, ImageProcessor from ..image.extractor import ImageExtractor @@ -172,7 +172,6 @@ class ProcessorTool(Tool): ) def setup(self): - # setup components: self.event_source = self.enter_context(EventSource(parent=self)) @@ -305,7 +304,6 @@ def start(self): unit="ev", disable=not self.progress_bar, ): - self.log.debug("Processessing event_id=%s", event.index.event_id) if not self.event_type_filter(event): @@ -330,10 +328,6 @@ def start(self): self.process_shower(event) if self.write.write_dl1_aggregates: - if len(self.aggregate.image_parameters) == 0: - raise ToolConfigurationError( - "No DL1 image parameters to aggregate are specified." - ) self.aggregate(event) self.write(event) diff --git a/src/ctapipe/tools/tests/test_aggregate_features.py b/src/ctapipe/tools/tests/test_aggregate_features.py index ebc25b89f57..b82452dca98 100644 --- a/src/ctapipe/tools/tests/test_aggregate_features.py +++ b/src/ctapipe/tools/tests/test_aggregate_features.py @@ -3,6 +3,7 @@ import pytest from ctapipe.core import ToolConfigurationError, run_tool +from ctapipe.core.traits import TraitError from ctapipe.io import TableLoader @@ -14,8 +15,7 @@ def test_aggregate_features(dl2_shower_geometry_file_lapalma, tmp_path): config_path = tmp_path / "config.json" with pytest.raises( - ToolConfigurationError, - match="No image parameters to aggregate are specified.", + TraitError, match="No DL1 image parameters to aggregate are specified." ): run_tool( AggregateFeatures(), @@ -72,10 +72,11 @@ def test_aggregate_features(dl2_shower_geometry_file_lapalma, tmp_path): dl2=False, simulated=False, ) - assert "hillas_length_max" in events.colnames - assert "hillas_length_min" in events.colnames - assert "hillas_length_mean" in events.colnames - assert "hillas_length_std" in events.colnames - assert "timing_slope_mean" in events.colnames - assert "HillasReconstructor_tel_impact_distance_mean" in events.colnames - assert "hillas_abs_skewness_mean" in events.colnames + for col in [ + "hillas_length", + "timing_slope", + "HillasReconstructor_tel_impact_distance", + "hillas_abs_skewness", + ]: + for suffix in ["max", "min", "mean", "std"]: + assert f"{col}_{suffix}" in events.colnames