SpikeInterface / SpikeInterface/spikeinterface

Bug in extract_waveforms_to_buffers()

Open
#3,826 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
847
Forks
280
Avg merge
3d 9h
Merged PRs (30d)
29

Description

Using extract_waveforms_to_buffers() I noticed there is a mismatch between the number of expected waveforms and the actual number returned per unit, when the unit_ids not exactly like range(num_units).

It seems my issue is related to this piece of code in allocate_waveforms_buffers():

for unit_ind, unit_id in enumerate(unit_ids):
        n_spikes = np.sum(spikes["unit_index"] == unit_ind)

https://github.com/SpikeInterface/spikeinterface/blob/2b6e7a2ed43f946274209b0fa7d63e96e0be2f55/src/spikeinterface/core/waveform_tools.py#L183

Obviously, if unit_ids=[0,1,2,3,4] there is no issue, but if unit_ids=[0,1,13,91,101], for example, then there is an issue, because:

>>> unit_ids=[0,1,13,91,101]
>>> list(enumerate(unit_ids))
[(0, 0), (1, 1), (2, 13), (3, 91), (4, 101)]

I could be missing something about how extract_waveforms_to_buffers() is intended to be used, but to me this looks like it was a mistake.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/spikeinterface/core/waveform_tools.py at allocate_waveforms_buffers(), especially the loop around line 183, and trace how unit_ids are used by extract_waveforms_to_buffers(). Reproduce the mismatch with non-contiguous IDs such as [0, 1, 13, 91, 101], then verify that the returned waveform count for each unit matches its actual spikes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.