Skip to content

Commit

Permalink
Start adapting code-base to new container structure
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jul 7, 2023
1 parent e686a2e commit c522715
Show file tree
Hide file tree
Showing 36 changed files with 611 additions and 604 deletions.
4 changes: 2 additions & 2 deletions ctapipe/calib/camera/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
from numba import float32, float64, guvectorize, int64

from ctapipe.containers import TelescopeDL1Container, TelescopeEventContainer
from ctapipe.containers import DL1TelescopeContainer, TelescopeEventContainer
from ctapipe.core import TelescopeComponent
from ctapipe.core.traits import (
BoolTelescopeParameter,
Expand Down Expand Up @@ -229,7 +229,7 @@ def dl0_to_dl1(self, tel_event: TelescopeEventContainer):
# - Read into dl1 container directly?
# - Don't do anything if dl1 container already filled
# - Update on SST review decision
dl1 = TelescopeDL1Container(
dl1 = DL1TelescopeContainer(
image=waveforms[..., 0].astype(np.float32),
peak_time=np.zeros(n_pixels, dtype=np.float32),
is_valid=True,
Expand Down
8 changes: 4 additions & 4 deletions ctapipe/calib/camera/flatfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from astropy import units as u

from ctapipe.containers import TelescopeDL1Container
from ctapipe.containers import DL1TelescopeContainer
from ctapipe.core import Component
from ctapipe.core.traits import Int, List, Unicode
from ctapipe.image.extractor import ImageExtractor
Expand Down Expand Up @@ -169,7 +169,7 @@ def __init__(self, **kwargs):
self.arrival_times = None # arrival time per event in sample
self.sample_masked_pixels = None # masked pixels per event in sample

def _extract_charge(self, event) -> TelescopeDL1Container:
def _extract_charge(self, event) -> DL1TelescopeContainer:
"""
Extract the charge and the time from a calibration event
Expand All @@ -195,7 +195,7 @@ def _extract_charge(self, event) -> TelescopeDL1Container:
waveforms, self.tel_id, selected_gain_channel, broken_pixels
)
else:
return TelescopeDL1Container(image=0, peak_pos=0, is_valid=False)
return DL1TelescopeContainer(image=0, peak_pos=0, is_valid=False)

def calculate_relative_gain(self, event):
"""
Expand Down Expand Up @@ -237,7 +237,7 @@ def calculate_relative_gain(self, event):

# extract the charge of the event and
# the peak position (assumed as time for the moment)
dl1: TelescopeDL1Container = self._extract_charge(event)
dl1: DL1TelescopeContainer = self._extract_charge(event)

if not dl1.is_valid:
return False
Expand Down
8 changes: 4 additions & 4 deletions ctapipe/calib/camera/pedestals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from astropy import units as u

from ctapipe.containers import TelescopeDL1Container
from ctapipe.containers import DL1TelescopeContainer
from ctapipe.core import Component
from ctapipe.core.traits import Int, List, Unicode
from ctapipe.image.extractor import ImageExtractor
Expand Down Expand Up @@ -197,7 +197,7 @@ def __init__(self, **kwargs):
self.charges = None # charge per event in sample
self.sample_masked_pixels = None # pixels tp be masked per event in sample

def _extract_charge(self, event) -> TelescopeDL1Container:
def _extract_charge(self, event) -> DL1TelescopeContainer:
"""
Extract the charge and the time from a pedestal event
Expand All @@ -224,7 +224,7 @@ def _extract_charge(self, event) -> TelescopeDL1Container:
waveforms, self.tel_id, selected_gain_channel, broken_pixels
)
else:
return TelescopeDL1Container(image=0, peak_pos=0, is_valid=False)
return DL1TelescopeContainer(image=0, peak_pos=0, is_valid=False)

def calculate_pedestals(self, event):
"""
Expand Down Expand Up @@ -258,7 +258,7 @@ def calculate_pedestals(self, event):

# extract the charge of the event and
# the peak position (assumed as time for the moment)
dl1: TelescopeDL1Container = self._extract_charge(event)
dl1: DL1TelescopeContainer = self._extract_charge(event)

if not dl1.is_valid:
return False
Expand Down
28 changes: 14 additions & 14 deletions ctapipe/calib/camera/tests/test_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

from ctapipe.calib.camera.calibrator import CameraCalibrator
from ctapipe.containers import (
ArrayEventContainer,
TelescopeDL0Container,
TelescopeDL1Container,
DL0TelescopeContainer,
DL1TelescopeContainer,
R1TelescopeContainer,
SubarrayEventContainer,
TelescopeEventContainer,
TelescopeEventIndexContainer,
TelescopeR1Container,
)
from ctapipe.image.extractor import (
FullWaveformSum,
Expand Down Expand Up @@ -114,17 +114,17 @@ def test_check_r1_empty(example_event, example_subarray):
assert tel_event.dl0.waveform is None

assert calibrator._check_r1_empty(None) is True
assert calibrator._check_r1_empty(TelescopeR1Container(waveform=None)) is True
assert calibrator._check_r1_empty(TelescopeR1Container(waveform=waveform)) is False
assert calibrator._check_r1_empty(R1TelescopeContainer(waveform=None)) is True
assert calibrator._check_r1_empty(R1TelescopeContainer(waveform=waveform)) is False

calibrator = CameraCalibrator(
subarray=example_subarray,
image_extractor=FullWaveformSum(subarray=example_subarray),
)
event = ArrayEventContainer()
event = SubarrayEventContainer()
event.tel[tel_id] = TelescopeEventContainer(
index=TelescopeEventIndexContainer(obs_id=1, event_id=1, tel_id=tel_id),
dl0=TelescopeDL0Container(waveform=np.full((2048, 128), 2)),
dl0=DL0TelescopeContainer(waveform=np.full((2048, 128), 2)),
)
with pytest.warns(UserWarning):
calibrator(event)
Expand All @@ -145,16 +145,16 @@ def test_check_dl0_empty(example_event, example_subarray):
assert tel_event.dl1.image is None

assert calibrator._check_dl0_empty(None) is True
assert calibrator._check_dl0_empty(TelescopeDL0Container(waveform=None)) is True
assert calibrator._check_dl0_empty(DL0TelescopeContainer(waveform=None)) is True
assert (
calibrator._check_dl0_empty(TelescopeDL0Container(waveform=waveform)) is False
calibrator._check_dl0_empty(DL0TelescopeContainer(waveform=waveform)) is False
)

calibrator = CameraCalibrator(subarray=example_subarray)
event = ArrayEventContainer()
event = SubarrayEventContainer()
tel_event = TelescopeEventContainer(
index=TelescopeEventIndexContainer(obs_id=1, event_id=1, tel_id=tel_id),
dl1=TelescopeDL1Container(image=np.full(2048, 2)),
dl1=DL1TelescopeContainer(image=np.full(2048, 2)),
)
event.tel[tel_id] = tel_event
with pytest.warns(UserWarning):
Expand Down Expand Up @@ -198,10 +198,10 @@ def test_dl1_charge_calib(example_subarray):
pedestal = rng.uniform(-4, 4, n_pixels)
y += pedestal[:, np.newaxis]

event = ArrayEventContainer()
event = SubarrayEventContainer()
event.tel[tel_id] = TelescopeEventContainer(
index=TelescopeEventIndexContainer(obs_id=1, event_id=1, tel_id=tel_id),
dl0=TelescopeDL0Container(
dl0=DL0TelescopeContainer(
waveform=y,
selected_gain_channel=np.zeros(len(y), dtype=int),
),
Expand Down
4 changes: 2 additions & 2 deletions ctapipe/calib/camera/tests/test_flatfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from traitlets.config import Config

from ctapipe.calib.camera.flatfield import FlasherFlatFieldCalculator
from ctapipe.containers import ArrayEventContainer
from ctapipe.containers import SubarrayEventContainer
from ctapipe.instrument import SubarrayDescription


Expand Down Expand Up @@ -37,7 +37,7 @@ def test_flasherflatfieldcalculator(prod5_sst):
config=config,
)
# create one event
data = ArrayEventContainer()
data = SubarrayEventContainer()
data.meta["origin"] = "test"
data.trigger.time = Time.now()

Expand Down
4 changes: 2 additions & 2 deletions ctapipe/calib/camera/tests/test_pedestals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
PedestalIntegrator,
calc_pedestals_from_traces,
)
from ctapipe.containers import ArrayEventContainer
from ctapipe.containers import SubarrayEventContainer
from ctapipe.instrument import SubarrayDescription


Expand Down Expand Up @@ -39,7 +39,7 @@ def test_pedestal_integrator(prod5_sst):
tel_id=tel_id,
)
# create one event
data = ArrayEventContainer()
data = SubarrayEventContainer()
data.meta["origin"] = "test"
data.trigger.time = Time.now()

Expand Down
Loading

0 comments on commit c522715

Please sign in to comment.