Skip to content

Commit

Permalink
fix traits for outlier detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
TjarkMiener committed Aug 5, 2024
1 parent 3a300a9 commit e8d6504
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/ctapipe/monitoring/outlier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import numpy as np

from ctapipe.core import TelescopeComponent
from ctapipe.core import TelescopeComponent, traits
from ctapipe.core.traits import List


Expand Down Expand Up @@ -55,11 +55,14 @@ class RangeOutlierDetector(OutlierDetector):
"""

validity_range = List(
[1.0, 2.0],
trait=traits.Float(),
default_value=[1.0, 2.0],
help=(
"Range of valid statistic values (in units of the image value)."
"Values outside the range are identified as outliers."
),
minlen=2,
maxlen=2,
).tag(config=True)

def __call__(self, column):
Expand All @@ -80,12 +83,15 @@ class MedianOutlierDetector(OutlierDetector):
"""

median_range_factors = List(
[-1.0, 1.0],
trait=traits.Float(),
default_value=[-1.0, 1.0],
help=(
"Multiplicative factors (unitless) applied to the camera median"
"of the provided statistic values to define a valid range based on the"
"deviation of the values to its camera median."
),
minlen=2,
maxlen=2,
).tag(config=True)

def __call__(self, column):
Expand All @@ -109,12 +115,15 @@ class StdOutlierDetector(OutlierDetector):
"""

std_range_factors = List(
[-1.0, 1.0],
trait=traits.Float(),
default_value=[-1.0, 1.0],
help=(
"Multiplicative factors (unitless) applied to the camera standard deviation"
"of the provided statistic values to define a valid range based on the"
"deviation of the values to its camera median."
),
minlen=2,
maxlen=2,
).tag(config=True)

def __call__(self, column):
Expand Down
8 changes: 5 additions & 3 deletions src/ctapipe/monitoring/tests/test_outlier.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def test_range_detection(example_subarray):
# Initialize the outlier detector based on the range of valid values
# In this test, the interval [15, 25] corresponds to the range (in waveform samples)
# of accepted mean (or median) values of peak times of flat-field events
detector = RangeOutlierDetector(subarray=example_subarray, validity_range=[15, 25])
detector = RangeOutlierDetector(
subarray=example_subarray, validity_range=[15.0, 25.0]
)
# Detect outliers
outliers = detector(table["mean"])
# Construct the expected outliers
Expand All @@ -54,7 +56,7 @@ def test_median_detection(example_subarray):
# In this test, the interval [-0.9, 8] corresponds to multiplication factors
# typical used for the median values of charge images of flat-field events
detector = MedianOutlierDetector(
subarray=example_subarray, median_range_factors=[-0.9, 8]
subarray=example_subarray, median_range_factors=[-0.9, 8.0]
)
# Detect outliers
outliers = detector(table["median"])
Expand Down Expand Up @@ -87,7 +89,7 @@ def test_std_detection(example_subarray):
# typical used for the std values of charge images of flat-field events
# and median (and std) values of charge images of pedestal events
detector = StdOutlierDetector(
subarray=example_subarray, std_range_factors=[-15, 15]
subarray=example_subarray, std_range_factors=[-15.0, 15.0]
)
ff_outliers = detector(ff_table["std"])
ped_outliers = detector(ped_table["median"])
Expand Down

0 comments on commit e8d6504

Please sign in to comment.