Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions neo/rawio/examplerawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 21 additions & 0 deletions neo/test/rawiotest/rawio_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down