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

Add gain selection to calibration chain #1095

Merged
merged 11 commits into from
Jun 28, 2019
6 changes: 3 additions & 3 deletions ctapipe/calib/camera/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _get_correction(self, event, telid):
ndarray
"""
try:
gain_selection = event.mon.tel[telid].gain_selection
gain_selection = event.r1.tel[telid].gain_selection
shift = self.image_extractor.window_shift
width = self.image_extractor.window_width
shape = event.mc.tel[telid].reference_pulse_shape
Expand Down Expand Up @@ -185,12 +185,12 @@ def _calibrate_dl0(self, event, telid):
# waveform dimensions.
waveforms_gs, pixel_channel = self.gain_selector(waveforms)
if pixel_channel is not None:
event.mon.tel[telid].gain_selection = pixel_channel
event.r1.tel[telid].gain_selection = pixel_channel
else:
# If pixel_channel is None, then waveforms has already been
# pre-gainselected, and presumably the gain_selection container is
# filled by the EventSource
if event.mon.tel[telid].gain_selection is None:
if event.r1.tel[telid].gain_selection is None:
raise ValueError(
"EventSource is loading pre-gainselected waveforms "
"without filling the gain_selection container"
Expand Down
2 changes: 1 addition & 1 deletion ctapipe/calib/camera/tests/test_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_select_gain():

event = DataContainer()
event.r1.tel[telid].waveform = np.ones((n_pixels, n_samples))
event.mon.tel[telid].gain_selection = np.zeros(n_pixels)
event.r1.tel[telid].gain_selection = np.zeros(n_pixels)
calibrator._calibrate_dl0(event, telid)
assert event.dl0.tel[telid].waveform.shape == (n_pixels, n_samples)

Expand Down
16 changes: 2 additions & 14 deletions ctapipe/calib/camera/tests/test_flatfield.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import numpy as np
from ctapipe.calib.camera.flatfield import *
from ctapipe.io.containers import DataContainer
from ctapipe.io.containers import EventAndMonDataContainer
from traitlets.config.loader import Config


# class FixedWindowSum2Chan(FixedWindowSum):
#
# def __call__(self, waveforms):
# start = self.window_start
# end = self.window_start + self.window_width
# charge = waveforms[..., start:end].sum(2)
# pulse_time = extract_pulse_time_around_peak(
# waveforms, self.window_start, self.window_width, 0
# )
# return charge, pulse_time


def test_flasherflatfieldcalculator():
"""test of flasherFlatFieldCalculator"""
tel_id = 0
Expand All @@ -34,7 +22,7 @@ def test_flasherflatfieldcalculator():
sample_size=n_events,
tel_id=tel_id, config=config)
# create one event
data = DataContainer()
data = EventAndMonDataContainer()
data.meta['origin'] = 'test'

# initialize mon and r1 data
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
@@ -1,6 +1,6 @@
import numpy as np
from ctapipe.calib.camera.pedestals import *
from ctapipe.io.containers import DataContainer
from ctapipe.io.containers import EventAndMonDataContainer


def test_pedestal_calculator():
Expand All @@ -16,7 +16,7 @@ def test_pedestal_calculator():
sample_size=n_events,
tel_id=tel_id)
# create one event
data = DataContainer()
data = EventAndMonDataContainer()
data.meta['origin'] = 'test'

# fill the values necessary for the pedestal calculation
Expand Down
57 changes: 31 additions & 26 deletions ctapipe/io/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'WaveformCalibrationContainer',
'MonitoringCameraContainer',
'MonitoringContainer',
'EventAndMonDataContainer'
]


Expand Down Expand Up @@ -153,7 +154,10 @@ class R1CameraContainer(Container):
"numpy array containing a set of images, one per ADC sample"
"Shape: (n_channels, n_pixels, n_samples)"
))

gain_selection = Field(None, (
kosack marked this conversation as resolved.
Show resolved Hide resolved
"Numpy array containing the gain channel chosen for each pixel. "
"Shape: (n_pixels)"
))

class R1Container(Container):
"""
Expand Down Expand Up @@ -408,6 +412,28 @@ class TelescopePointingContainer(Container):
altitude = Field(nan * u.rad, 'Altitude', unit=u.rad)


class DataContainer(Container):
""" Top-level container for all event information """

event_type = Field('data', "Event type")
r0 = Field(R0Container(), "Raw Data")
r1 = Field(R1Container(), "R1 Calibrated Data")
dl0 = Field(DL0Container(), "DL0 Data Volume Reduced Data")
dl1 = Field(DL1Container(), "DL1 Calibrated image")
dl2 = Field(ReconstructedContainer(), "Reconstructed Shower Information")
mc = Field(MCEventContainer(), "Monte-Carlo data")
mcheader = Field(MCHeaderContainer(), "Monte-Carlo run header data")
trig = Field(CentralTriggerContainer(), "central trigger information")
count = Field(0, "number of events processed")
inst = Field(InstrumentContainer(), "instrumental information (deprecated")
pointing = Field(Map(TelescopePointingContainer),
'Telescope pointing positions')


class SST1MDataContainer(DataContainer):
sst1m = Field(SST1MContainer(), "optional SST1M Specific Information")


class MuonRingParameter(Container):
"""
Storage of muon ring fit output
Expand Down Expand Up @@ -749,16 +775,11 @@ class WaveformCalibrationContainer(Container):
"Boolean np array of final calibration data analysis, True = failing pixels (n_chan, n_pix)"
)


class MonitoringCameraContainer(Container):
"""
Container for camera monitoring data
"""

gain_selection = Field(None, (
"Numpy array containing the gain channel chosen for each pixel. "
"Shape: (n_pixels)"
))
flatfield = Field(FlatFieldContainer(), "Data from flat-field event distributions")
pedestal = Field(PedestalContainer(), "Data from pedestal event distributions")
pixel_status = Field(PixelStatusContainer(), "Container for masks with pixel status")
Expand All @@ -778,24 +799,8 @@ class MonitoringContainer(Container):
"map of tel_id to MonitoringCameraContainer")


class DataContainer(Container):
""" Top-level container for all event information """

event_type = Field('data', "Event type")
r0 = Field(R0Container(), "Raw Data")
r1 = Field(R1Container(), "R1 Calibrated Data")
dl0 = Field(DL0Container(), "DL0 Data Volume Reduced Data")
dl1 = Field(DL1Container(), "DL1 Calibrated image")
dl2 = Field(ReconstructedContainer(), "Reconstructed Shower Information")
mc = Field(MCEventContainer(), "Monte-Carlo data")
mcheader = Field(MCHeaderContainer(), "Monte-Carlo run header data")
trig = Field(CentralTriggerContainer(), "central trigger information")
count = Field(0, "number of events processed")
inst = Field(InstrumentContainer(), "instrumental information (deprecated")
pointing = Field(Map(TelescopePointingContainer),
'Telescope pointing positions')
class EventAndMonDataContainer(DataContainer):
"""
Data container including monitoring information
"""
mon = Field(MonitoringContainer(), "container for monitoring data (MON)")


class SST1MDataContainer(DataContainer):
sst1m = Field(SST1MContainer(), "optional SST1M Specific Information")