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

Replace WaveformCleaner and ChargeExtractor with WaveformExtractor #1033

Merged
merged 30 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d643c9e
Creation of WaveformReducer class
watsonjj Mar 25, 2019
d07a800
Replace WaveformReducer with WaveformExtractor
watsonjj Mar 25, 2019
199e0f8
Created tests for waveform_extractor.py
watsonjj Mar 25, 2019
f5ec3b2
Removed waveform_cleaning.py
watsonjj Mar 25, 2019
e835769
Updated containers
watsonjj Mar 25, 2019
c6c2d2b
Updated __init__.py
watsonjj Mar 25, 2019
7f59bef
Updated calibration to use new WaveformExtractors
watsonjj Mar 25, 2019
3a6d3d6
Merge branch 'charge_extractor' into waveform_reducer
watsonjj Mar 25, 2019
87dfab1
Merge branch 'charge_extractor' into waveform_reducer
watsonjj Mar 26, 2019
91a10c8
Fix name mixup after merge
watsonjj Mar 26, 2019
55324f0
Limit range for pulse_time calculation
watsonjj Mar 26, 2019
431f23f
Update bokeh event plotter to handle new WaveformExtractor
watsonjj Mar 26, 2019
1981a30
Update tools
watsonjj Mar 26, 2019
54a9f8a
Correct references to ChargeExtractor
watsonjj Mar 26, 2019
a3419b3
Remove further references
watsonjj Mar 26, 2019
d70c0dc
Correct tools
watsonjj Mar 26, 2019
23bc110
Improved names of WaveformExtractors
watsonjj Mar 26, 2019
563749f
Merge branch 'numba_neighbors' into waveform_reducer
watsonjj Mar 26, 2019
1d4f55a
Merge branch 'master' into waveform_reducer
watsonjj Mar 29, 2019
cabe80e
Deleted empty file
watsonjj Mar 29, 2019
79b9276
Rename WaveformExtractor to ImageExtractor
watsonjj Mar 29, 2019
000dbc7
Update doc
watsonjj Mar 29, 2019
875307d
Update docs
watsonjj Mar 29, 2019
a27269b
Update docs
watsonjj Mar 29, 2019
71f4766
Update docs
watsonjj Mar 29, 2019
2861d0f
Update notebooks
watsonjj Mar 29, 2019
80be3dc
Merge branch 'master' into waveform_reducer
watsonjj Apr 3, 2019
e510fd9
Rename UserWindowSum to FixedWindowSum
watsonjj Apr 4, 2019
ca6c2a3
Set to nan if out of range
watsonjj Apr 4, 2019
0678346
Set out-of-bounds pulse time to -1
watsonjj Apr 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 6 additions & 37 deletions ctapipe/calib/camera/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CameraDL0Reducer,
CameraDL1Calibrator,
)
from ctapipe.image import ChargeExtractor, WaveformCleaner
from ctapipe.image import ImageExtractor


__all__ = ['CameraCalibrator']
Expand All @@ -23,33 +23,10 @@ class CameraCalibrator(Component):
This calibrator will apply the calibrations found in r1.py, dl0.py and
dl1.py.

The following traitlet alias configuration is suggestion for configuring
the calibration inside a `ctapipe.core.Tool`:

.. code-block:: python

aliases = Dict(dict(
ped='CameraR1CalibratorFactory.pedestal_path',
tf='CameraR1CalibratorFactory.tf_path',
pe='CameraR1CalibratorFactory.adc2pe_path',
extractor='ChargeExtractorFactory.extractor',
extractor_t0='ChargeExtractorFactory.t0',
window_width='ChargeExtractorFactory.window_width',
window_shift='ChargeExtractorFactory.window_shift',
sig_amp_cut_HG='ChargeExtractorFactory.sig_amp_cut_HG',
sig_amp_cut_LG='ChargeExtractorFactory.sig_amp_cut_LG',
lwt='ChargeExtractorFactory.lwt',
clip_amplitude='CameraDL1Calibrator.clip_amplitude',
radius='CameraDL1Calibrator.radius',
cleaner='WaveformCleanerFactory.cleaner',
cleaner_t0='WaveformCleanerFactory.t0',
))

"""
def __init__(self, config=None, parent=None,
r1_product=None,
extractor_product='NeighbourPeakIntegrator',
cleaner_product='NullWaveformCleaner',
extractor_name='NeighborPeakWindowSum',
eventsource=None,
**kwargs):
"""
Expand All @@ -65,10 +42,8 @@ def __init__(self, config=None, parent=None,
Set to None if no Tool to pass.
r1_product : str
The R1 calibrator to use. Manually overrides the Factory.
extractor_product : str
The ChargeExtractor to use. Manually overrides the Factory.
cleaner_product : str
The WaveformCleaner to use. Manually overrides the Factory.
extractor_name : str
The name of the ImageExtractor to use.
eventsource : ctapipe.io.eventsource.EventSource
EventSource that is being used to read the events. The EventSource
contains information (such as metadata or inst) which indicates
Expand All @@ -77,13 +52,8 @@ def __init__(self, config=None, parent=None,
"""
super().__init__(config=config, parent=parent, **kwargs)

extractor = ChargeExtractor.from_name(
extractor_product,
parent=self,
)

cleaner = WaveformCleaner.from_name(
cleaner_product,
extractor = ImageExtractor.from_name(
extractor_name,
parent=self,
)

Expand All @@ -103,7 +73,6 @@ def __init__(self, config=None, parent=None,
self.dl1 = CameraDL1Calibrator(
parent=self,
extractor=extractor,
cleaner=cleaner,
)

def calibrate(self, event):
Expand Down
47 changes: 15 additions & 32 deletions ctapipe/calib/camera/dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
Calibrator for the DL0 -> DL1 data level transition.

This module handles the calibration from the DL0 data level to DL1. This
transition involves the waveform cleaning (such as filtering, smoothing,
or basline subtraction) performed by a cleaner from
`ctapipe.image.waveform_cleaning`, and the charge extraction technique
from `ctapipe.image.charge_extractors`.
transition involves the extraction of parameters from the waveform using a
`ctapipe.image.extractor.ImageExtractor`.
"""
import numpy as np

from ...core import Component
from ...core.traits import Float
from ...image import NeighbourPeakIntegrator, NullWaveformCleaner
from ...image import NeighborPeakWindowSum

__all__ = ['CameraDL1Calibrator']

Expand Down Expand Up @@ -91,13 +89,11 @@ class CameraDL1Calibrator(Component):
Tool executable that is calling this component.
Passes the correct logger to the component.
Set to None if no Tool to pass.
extractor : ctapipe.calib.camera.charge_extractors.ChargeExtractor
The extractor to use to extract the charge from the waveforms.
By default the NeighbourPeakIntegrator with default configuration
extractor : ctapipe.calib.camera.waveform_reducer.ImageExtractor
The reducer to use to extract the charge and pulse time from
the waveforms.
By default the NeighborPeakWindowSum with default configuration
is used.
cleaner : ctapipe.calib.camera.waveform_cleaners.Cleaner
The waveform cleaner to use. By default no cleaning is
applied to the waveforms.
kwargs
"""
radius = Float(None, allow_none=True,
Expand All @@ -109,15 +105,11 @@ class CameraDL1Calibrator(Component):
'clipped. Set to None for no '
'clipping.').tag(config=True)

def __init__(self, config=None, parent=None, extractor=None, cleaner=None,
**kwargs):
def __init__(self, config=None, parent=None, extractor=None, **kwargs):
super().__init__(config=config, parent=parent, **kwargs)
self.extractor = extractor
if self.extractor is None:
self.extractor = NeighbourPeakIntegrator(config, parent)
self.cleaner = cleaner
if self.cleaner is None:
self.cleaner = NullWaveformCleaner(config, parent)
self.extractor = NeighborPeakWindowSum(config, parent)
self._dl0_empty_warn = False

def check_dl0_exists(self, event, telid):
Expand Down Expand Up @@ -199,20 +191,13 @@ def calibrate(self, event):
if n_samples == 1:
# To handle ASTRI and dst
corrected = waveforms[..., 0]
window = np.ones(waveforms.shape)
peakpos = np.zeros(waveforms.shape[0:2])
cleaned = waveforms
pulse_time = np.zeros(waveforms.shape[0:2])
else:
# Clean waveforms
cleaned = self.cleaner.apply(waveforms)

# Extract charge
if self.extractor.requires_neighbours():
e = self.extractor
# Extract charge and pulse time
if self.extractor.requires_neighbors():
g = event.inst.subarray.tel[telid].camera
e.neighbours = g.neighbor_matrix_where
extract = self.extractor.extract_charge
charge, peakpos, window = extract(cleaned)
self.extractor.neighbors = g.neighbor_matrix_where
charge, pulse_time = self.extractor(waveforms)

# Apply integration correction
correction = self.get_correction(event, telid)[:, None]
Expand All @@ -225,6 +210,4 @@ def calibrate(self, event):

# Store into event container
event.dl1.tel[telid].image = corrected
event.dl1.tel[telid].extracted_samples = window
event.dl1.tel[telid].peakpos = peakpos
event.dl1.tel[telid].cleaned = cleaned
event.dl1.tel[telid].pulse_time = pulse_time
6 changes: 3 additions & 3 deletions ctapipe/calib/camera/tests/test_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
HESSIOR1Calibrator,
NullR1Calibrator
)
from ctapipe.image.charge_extractors import LocalPeakIntegrator
from ctapipe.image.extractor import LocalPeakWindowSum
from ctapipe.io import SimTelEventSource
from ctapipe.utils import get_dataset_path

Expand All @@ -26,8 +26,8 @@ def test_manual_r1():


def test_manual_extractor():
calibrator = CameraCalibrator(extractor_product="LocalPeakIntegrator")
assert isinstance(calibrator.dl1.extractor, LocalPeakIntegrator)
calibrator = CameraCalibrator(extractor_name="LocalPeakWindowSum")
assert isinstance(calibrator.dl1.extractor, LocalPeakWindowSum)


def test_eventsource_r1():
Expand Down
3 changes: 1 addition & 2 deletions ctapipe/image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .hillas import *
from .cleaning import *
from .pixel_likelihood import *
from .charge_extractors import *
from .waveform_cleaning import *
from .extractor import *
from .reducers import *
from .muon import *
from .geometry_converter import *
Expand Down
Loading