def test_extract_pulse_time_within_range(): x = np.arange(100) # Generic waveform that goes from positive to negative in window # Can cause extreme values with incorrect handling of weighted average y = -1.2 * x + 20 _, pulse_time = extract_around_peak(y[np.newaxis, :], 12, 10, 0) assert (pulse_time >= 0).all() & (pulse_time < x.size).all()
def extract(self, waveforms, peak_index): cc = correlate1d(waveforms, self.cc_ref_y, mode='constant', origin=self.origin) charge, _, = extract_around_peak(cc, peak_index, 1, 0, 1) return charge
def test_extract_around_peak(toymodel): waveforms, _, _, _, _, _ = toymodel n_pixels, n_samples = waveforms.shape rand = np.random.RandomState(1) peak_index = rand.uniform(0, n_samples, n_pixels).astype(np.int) charge, pulse_time = extract_around_peak(waveforms, peak_index, 7, 3, 1) assert (charge >= 0).all() assert (pulse_time >= 0).all() and (pulse_time <= n_samples).all() x = np.arange(100) y = norm.pdf(x, 41.2, 6) charge, pulse_time = extract_around_peak(y[np.newaxis, :], 0, x.size, 0, 1) assert_allclose(charge[0], 1.0, rtol=1e-3) assert_allclose(pulse_time[0], 41.2, rtol=1e-3) # Test negative amplitude y_offset = y - y.max() / 2 charge, _ = extract_around_peak(y_offset[np.newaxis, :], 0, x.size, 0, 1) assert_allclose(charge, y_offset.sum(), rtol=1e-3)
def test_extract_around_peak(camera_waveforms): waveforms, _ = camera_waveforms n_pixels, n_samples = waveforms.shape rand = np.random.RandomState(1) peak_index = rand.uniform(0, n_samples, n_pixels).astype(np.int) charge, pulse_time = extract_around_peak(waveforms, peak_index, 7, 3) assert_allclose(charge[0], 146.022991, rtol=1e-3) assert_allclose(pulse_time[0], 40.659884, rtol=1e-3) x = np.arange(100) y = norm.pdf(x, 41.2, 6) charge, pulse_time = extract_around_peak(y[np.newaxis, :], 0, x.size, 0) assert_allclose(charge[0], 1.0, rtol=1e-3) assert_allclose(pulse_time[0], 41.2, rtol=1e-3) # Test negative amplitude y_offset = y - y.max() / 2 charge, pulse_time = extract_around_peak(y_offset[np.newaxis, :], 0, x.size, 0) assert_allclose(charge, y_offset.sum(), rtol=1e-3)
def test_extract_around_peak_charge_expected(toymodel): waveforms = np.ones((2048, 96)) n_samples = waveforms.shape[-1] sampling_rate_ghz = 1 peak_index = 0 width = 10 shift = 0 charge, _ = extract_around_peak( waveforms, peak_index, width, shift, sampling_rate_ghz ) assert_equal(charge, 10) peak_index = 0 width = 10 shift = 10 charge, _ = extract_around_peak( waveforms, peak_index, width, shift, sampling_rate_ghz ) assert_equal(charge, 0) peak_index = 0 width = 20 shift = 10 charge, _ = extract_around_peak( waveforms, peak_index, width, shift, sampling_rate_ghz ) assert_equal(charge, 10) peak_index = n_samples width = 10 shift = 0 charge, _ = extract_around_peak( waveforms, peak_index, width, shift, sampling_rate_ghz ) assert_equal(charge, 0) peak_index = n_samples width = 20 shift = 10 charge, _ = extract_around_peak( waveforms, peak_index, width, shift, sampling_rate_ghz ) assert_equal(charge, 10) peak_index = 0 width = n_samples * 3 shift = n_samples charge, _ = extract_around_peak( waveforms, peak_index, width, shift, sampling_rate_ghz ) assert_equal(charge, n_samples)
def test_extract_around_peak_charge_expected(camera_waveforms): waveforms, _ = camera_waveforms waveforms = np.ones(waveforms.shape) n_samples = waveforms.shape[-1] peak_index = 0 width = 10 shift = 0 charge, _ = extract_around_peak(waveforms, peak_index, width, shift) assert_equal(charge, 10) peak_index = 0 width = 10 shift = 10 charge, _ = extract_around_peak(waveforms, peak_index, width, shift) assert_equal(charge, 0) peak_index = 0 width = 20 shift = 10 charge, _ = extract_around_peak(waveforms, peak_index, width, shift) assert_equal(charge, 10) peak_index = n_samples width = 10 shift = 0 charge, _ = extract_around_peak(waveforms, peak_index, width, shift) assert_equal(charge, 0) peak_index = n_samples width = 20 shift = 10 charge, _ = extract_around_peak(waveforms, peak_index, width, shift) assert_equal(charge, 10) peak_index = 0 width = n_samples * 3 shift = n_samples charge, _ = extract_around_peak(waveforms, peak_index, width, shift) assert_equal(charge, n_samples)