Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove python warnings #2421

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions ctapipe/calib/camera/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
calibration and image extraction, as well as supporting algorithms.
"""

import warnings

import astropy.units as u
import numpy as np
from numba import float32, float64, guvectorize, int64
Expand Down Expand Up @@ -129,7 +127,7 @@ def __init__(
self.image_extractors = {}

if image_extractor is None:
for (_, _, name) in self.image_extractor_type:
for _, _, name in self.image_extractor_type:
self.image_extractors[name] = ImageExtractor.from_name(
name, subarray=self.subarray, parent=self
)
Expand All @@ -156,7 +154,7 @@ def __init__(
def _check_r1_empty(self, waveforms):
if waveforms is None:
if not self._r1_empty_warn:
warnings.warn(
self.log.debug(
"Encountered an event with no R1 data. "
"DL0 is unchanged in this circumstance."
)
Expand All @@ -168,7 +166,7 @@ def _check_r1_empty(self, waveforms):
def _check_dl0_empty(self, waveforms):
if waveforms is None:
if not self._dl0_empty_warn:
warnings.warn(
self.log.warning(
"Encountered an event with no DL0 data. "
"DL1 is unchanged in this circumstance."
)
Expand Down Expand Up @@ -245,7 +243,6 @@ def _calibrate_dl1(self, event, tel_id):
is_valid=True,
)
else:

# shift waveforms if time_shift calibration is available
if time_shift is not None:
if self.apply_waveform_time_shift.tel[tel_id]:
Expand Down
18 changes: 2 additions & 16 deletions ctapipe/calib/camera/tests/test_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import astropy.units as u
import numpy as np
import pytest
from scipy.stats import norm
from traitlets.config import Config

Expand Down Expand Up @@ -101,11 +100,6 @@ def test_check_r1_empty(example_event, example_subarray):
calibrator = CameraCalibrator(subarray=example_subarray)
tel_id = list(example_event.r0.tel)[0]
waveform = example_event.r1.tel[tel_id].waveform.copy()
with pytest.warns(UserWarning):
example_event.r1.tel[tel_id].waveform = None
calibrator._calibrate_dl0(example_event, tel_id)
assert example_event.dl0.tel[tel_id].waveform is None

assert calibrator._check_r1_empty(None) is True
assert calibrator._check_r1_empty(waveform) is False

Expand All @@ -115,8 +109,7 @@ def test_check_r1_empty(example_event, example_subarray):
)
event = ArrayEventContainer()
event.dl0.tel[tel_id].waveform = np.full((2048, 128), 2)
with pytest.warns(UserWarning):
calibrator(event)
calibrator(event)
assert (event.dl0.tel[tel_id].waveform == 2).all()
assert (event.dl1.tel[tel_id].image == 2 * 128).all()

Expand All @@ -126,19 +119,13 @@ def test_check_dl0_empty(example_event, example_subarray):
tel_id = list(example_event.r0.tel)[0]
calibrator._calibrate_dl0(example_event, tel_id)
waveform = example_event.dl0.tel[tel_id].waveform.copy()
with pytest.warns(UserWarning):
example_event.dl0.tel[tel_id].waveform = None
calibrator._calibrate_dl1(example_event, tel_id)
assert example_event.dl1.tel[tel_id].image is None

assert calibrator._check_dl0_empty(None) is True
assert calibrator._check_dl0_empty(waveform) is False

calibrator = CameraCalibrator(subarray=example_subarray)
event = ArrayEventContainer()
event.dl1.tel[tel_id].image = np.full(2048, 2)
with pytest.warns(UserWarning):
calibrator(event)
calibrator(event)
assert (event.dl1.tel[tel_id].image == 2).all()


Expand Down Expand Up @@ -267,7 +254,6 @@ def test_shift_waveforms():


def test_invalid_pixels(example_event, example_subarray):

# switching off the corrections makes it easier to test for
# the exact value of 1.0
config = Config(
Expand Down
5 changes: 5 additions & 0 deletions docs/changes/2421.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Remove warnings about missing R1 or DL0 data when using the CameraCalibrator.
These were previously emitted directly as python warnings and did not use the
component logging system, which they now do.
As we do not actually expect R1 to be present it was also moved down to
debug level.