From 8c282299ec1e227bf531aef91d7d14ab97ee7170 Mon Sep 17 00:00:00 2001 From: Andrew Laing Date: Wed, 25 Nov 2020 14:04:33 +0100 Subject: [PATCH] Add tests with pandas and numpy and comparison --- .../detsim/buffer_functions_test.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/invisible_cities/detsim/buffer_functions_test.py b/invisible_cities/detsim/buffer_functions_test.py index c3eb78265c..c6643ab420 100644 --- a/invisible_cities/detsim/buffer_functions_test.py +++ b/invisible_cities/detsim/buffer_functions_test.py @@ -125,3 +125,38 @@ def test_buffer_calculator(mc_waveforms, binned_waveforms, assert evt_pmt .shape[1] == int(buffer_length / pmt_binwid) assert evt_sipm.shape[1] == int(buffer_length / sipm_binwid) assert np.sum(evt_pmt, axis=0)[pre_trg_samp] == pmt_sum[pulses[i]] + + +def test_buffer_calculator_pandas_numpy(mc_waveforms, binned_waveforms): + + _, pmt_binwid, sipm_binwid, _ = mc_waveforms + + pmt_bins, pmt_wfs, sipm_bins, sipm_wfs = binned_waveforms + + buffer_length = 800 * units.mus + bin_width = np.diff(pmt_bins)[0] + stand_off = int(buffer_length / bin_width) + pre_trigger = 100 * units.mus + signal_thresh = 2 + + pulses_pd = find_signal_start(pmt_wfs, signal_thresh, stand_off) + pmt_nparr = np.asarray(pmt_wfs.tolist()) + pulses_np = find_signal_start(pmt_nparr, signal_thresh, stand_off) + + calculate_buffers = buffer_calculator(buffer_length, + pre_trigger , + pmt_binwid , + sipm_binwid ) + + buffers_pd = calculate_buffers(pulses_pd, *binned_waveforms) + buffers_np = calculate_buffers(pulses_np , + pmt_bins , + pmt_nparr , + sipm_bins , + np.asarray(sipm_wfs.tolist())) + + assert len(buffers_pd) == len(buffers_np) == 1 + evtpd_buffers = buffers_pd[0] + evtnp_buffers = buffers_np[0] + assert np.all([np.all(evtpd_buffers[0] == evtnp_buffers[0]), + np.all(evtpd_buffers[1] == evtnp_buffers[1])])