diff --git a/neo/rawio/examplerawio.py b/neo/rawio/examplerawio.py index a31c6634a..b818db0cf 100644 --- a/neo/rawio/examplerawio.py +++ b/neo/rawio/examplerawio.py @@ -381,13 +381,16 @@ def _get_spike_raw_waveforms( # it is not always the case # we get 20 spikes with a sweep of 50 (5ms) - # trick to get how many spike in the slice + # generate the waveforms of all spikes, then keep only the ones in the slice, + # so a spike always gets the same waveform whatever t_start/t_stop + all_ts = self._get_spike_timestamps(block_index, seg_index, spike_channel_index, None, None) ts = self._get_spike_timestamps(block_index, seg_index, spike_channel_index, t_start, t_stop) - nb_spike = ts.size + nb_spike = all_ts.size np.random.seed(2205) # a magic number (my birthday) waveforms = np.random.randint(low=-(2**4), high=2**4, size=nb_spike * 50, dtype="int16") waveforms = waveforms.reshape(nb_spike, 1, 50) + waveforms = waveforms[np.isin(all_ts, ts)] return waveforms def _event_count(self, block_index: int, seg_index: int, event_channel_index: int): diff --git a/neo/test/rawiotest/rawio_compliance.py b/neo/test/rawiotest/rawio_compliance.py index 611b0fd48..82b0f2697 100644 --- a/neo/test/rawiotest/rawio_compliance.py +++ b/neo/test/rawiotest/rawio_compliance.py @@ -444,6 +444,27 @@ def read_spike_waveforms(reader): assert raw_waveforms.shape[0] == nb_spike assert raw_waveforms.ndim == 3 + if nb_spike > 3: + # load only one spike's waveform by forcing limits, as in read_spike_times + spike_timestamp = reader.get_spike_timestamps( + block_index=block_index, + seg_index=seg_index, + spike_channel_index=spike_channel_index, + t_start=None, + t_stop=None, + ) + spike_times = reader.rescale_spike_timestamp(spike_timestamp, "float64") + raw_waveforms2 = reader.get_spike_raw_waveforms( + block_index=block_index, + seg_index=seg_index, + spike_channel_index=spike_channel_index, + t_start=spike_times[1] - 0.001, + t_stop=spike_times[1] + 0.001, + ) + assert raw_waveforms2.shape[0] == 1 + assert raw_waveforms2.shape[1:] == raw_waveforms.shape[1:] + np.testing.assert_array_equal(raw_waveforms2[0], raw_waveforms[1]) + for dt in ("float32", "float64"): float_waveforms = reader.rescale_waveforms_to_float( raw_waveforms, dtype=dt, spike_channel_index=spike_channel_index