Skip to content

Commit

Permalink
Move error for empty image_parameters trait into FeatureAggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBeiske committed Feb 23, 2024
1 parent e859537 commit 9557b20
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/ctapipe/image/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 1 addition & 5 deletions src/ctapipe/tools/aggregate_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
8 changes: 1 addition & 7 deletions src/ctapipe/tools/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,7 +172,6 @@ class ProcessorTool(Tool):
)

def setup(self):

# setup components:
self.event_source = self.enter_context(EventSource(parent=self))

Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions src/ctapipe/tools/tests/test_aggregate_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from ctapipe.core import ToolConfigurationError, run_tool
from ctapipe.core.traits import TraitError
from ctapipe.io import TableLoader


Expand All @@ -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(),
Expand Down Expand Up @@ -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

0 comments on commit 9557b20

Please sign in to comment.