From a1f57b81b093fd41d6fbe83caaace1f5368cc812 Mon Sep 17 00:00:00 2001 From: Jason Watson Date: Fri, 21 Jun 2019 15:49:56 +0200 Subject: [PATCH 1/2] Restore returning selected channels in gain selection (#1094) * Return pixel_channel from GainSelector * Restore gain selection --- ctapipe/calib/camera/gainselection.py | 12 ++++-- .../calib/camera/tests/test_gainselection.py | 43 ++++++++++++++----- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ctapipe/calib/camera/gainselection.py b/ctapipe/calib/camera/gainselection.py index 1b140f77434..0a414cf6481 100644 --- a/ctapipe/calib/camera/gainselection.py +++ b/ctapipe/calib/camera/gainselection.py @@ -45,14 +45,17 @@ def __call__(self, waveforms): Shape: (n_pix, n_samples) """ if waveforms.ndim == 2: # Return if already gain selected - return waveforms + pixel_channel = None # Provided by EventSource + return waveforms, pixel_channel elif waveforms.ndim == 3: n_channels, n_pixels, _ = waveforms.shape if n_channels == 1: # Reduce if already single channel - return waveforms[0] + pixel_channel = np.zeros(n_pixels, dtype=int) + return waveforms[0], pixel_channel else: pixel_channel = self.select_channel(waveforms) - return waveforms[pixel_channel, np.arange(n_pixels)] + gain_selected = waveforms[pixel_channel, np.arange(n_pixels)] + return gain_selected, pixel_channel else: raise ValueError( f"Cannot handle waveform array of shape: {waveforms.ndim}" @@ -92,7 +95,8 @@ class ManualGainSelector(GainSelector): ).tag(config=True) def select_channel(self, waveforms): - return GainChannel[self.channel] + n_pixels = waveforms.shape[1] + return np.full(n_pixels, GainChannel[self.channel]) class ThresholdGainSelector(GainSelector): diff --git a/ctapipe/calib/camera/tests/test_gainselection.py b/ctapipe/calib/camera/tests/test_gainselection.py index 2ee34a2042d..9983a3bac00 100644 --- a/ctapipe/calib/camera/tests/test_gainselection.py +++ b/ctapipe/calib/camera/tests/test_gainselection.py @@ -14,12 +14,29 @@ def test_gain_selector(): waveforms[1] *= 2 gain_selector = TestGainSelector() - waveforms_gs = gain_selector(waveforms) + waveforms_gs, pixel_channel = gain_selector(waveforms) np.testing.assert_equal(waveforms[GainChannel.HIGH], waveforms_gs) - waveforms_gs = gain_selector(waveforms[0]) - np.testing.assert_equal(waveforms_gs, waveforms[0]) - waveforms_gs = gain_selector(waveforms[[0]]) - np.testing.assert_equal(waveforms_gs, waveforms[0]) + np.testing.assert_equal(pixel_channel, 0) + + +def test_pre_selected(): + shape = (2048, 128) + waveforms = np.zeros(shape) + + gain_selector = TestGainSelector() + waveforms_gs, pixel_channel = gain_selector(waveforms) + assert waveforms.shape == waveforms_gs.shape + assert pixel_channel is None + + +def test_single_channel(): + shape = (1, 2048, 128) + waveforms = np.zeros(shape) + + gain_selector = TestGainSelector() + waveforms_gs, pixel_channel = gain_selector(waveforms) + assert waveforms_gs.shape == (2048, 128) + assert (pixel_channel == 0).all() def test_manual_gain_selector(): @@ -28,12 +45,14 @@ def test_manual_gain_selector(): waveforms[1] *= 2 gs_high = ManualGainSelector(channel="HIGH") - waveforms_gs_high = gs_high(waveforms) - np.testing.assert_equal(waveforms[GainChannel.HIGH], waveforms_gs_high) + waveforms_gs, pixel_channel = gs_high(waveforms) + np.testing.assert_equal(waveforms[GainChannel.HIGH], waveforms_gs) + np.testing.assert_equal(pixel_channel, 0) - gs_high = ManualGainSelector(channel="LOW") - waveforms_gs_low = gs_high(waveforms) - np.testing.assert_equal(waveforms[GainChannel.LOW], waveforms_gs_low) + gs_low = ManualGainSelector(channel="LOW") + waveforms_gs, pixel_channel = gs_low(waveforms) + np.testing.assert_equal(waveforms[GainChannel.LOW], waveforms_gs) + np.testing.assert_equal(pixel_channel, 1) def test_threshold_gain_selector(): @@ -43,6 +62,8 @@ def test_threshold_gain_selector(): waveforms[0, 0] = 100 gain_selector = ThresholdGainSelector(threshold=50) - waveforms_gs = gain_selector(waveforms) + waveforms_gs, pixel_channel = gain_selector(waveforms) assert (waveforms_gs[0] == 1).all() assert (waveforms_gs[np.arange(1, 2048)] == 0).all() + assert pixel_channel[0] == 1 + assert (pixel_channel[np.arange(1, 2048)] == 0).all() From a3d030667c468128b7dd147693a68f7ff8604446 Mon Sep 17 00:00:00 2001 From: Michele Peresano Date: Wed, 26 Jun 2019 10:53:07 +0200 Subject: [PATCH 2/2] Added my emails to mailmap (#1098) --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index 83184416d46..d5e71f5e9c2 100644 --- a/.mailmap +++ b/.mailmap @@ -28,6 +28,8 @@ Lukas Nickel LukasNickel Maximilian Noethe +Michele Peresano Michele Peresano + Raquel de los Reyes rdelosreyes Samuel Timothy Spencer Samuel Timothy Spencer <31512502+STSpencer@users.noreply.github.com>