Skip to content

Set amplitude scalings equal zero for zero template units#4455

Merged
alejoe91 merged 2 commits intoSpikeInterface:mainfrom
chrishalcrow:fix-scalings-if-template-zero
Mar 18, 2026
Merged

Set amplitude scalings equal zero for zero template units#4455
alejoe91 merged 2 commits intoSpikeInterface:mainfrom
chrishalcrow:fix-scalings-if-template-zero

Conversation

@chrishalcrow
Copy link
Member

In some edge cases*, templates can be arrays of zeros. When this is the case, the amplitude scalings compute throws an error as you can't linregress a constant y-vector.

This PR fixes this: if the template of a given unit is equal to an array of zeros, the amplitude scalings computation is skipped (with scalings set to zero)

*This is my edge case: take two recordings, concatenate them and sort. Then make an analyzer for each recording by splitting the sorting in two. The concatenation has caused a artifact at the boundary of the two recordings which leads to a unit with a single spike near the boundary. Spikes within nbefore of the boundary get given a waveform equal to an array of zeros (this is because we can't accurately compute a waveform, but want to keep the number of spikes in random_spikes, waveforms etc the same). Spikes within nbefore usually aren't selected by select_random_spikes but because it's the only spike in the unit, it is selected. This is then the only waveform which contributes to the unit template, meaning the template is an array of zeros.

@chrishalcrow chrishalcrow added bug Something isn't working postprocessing Related to postprocessing module labels Mar 17, 2026
@chrishalcrow chrishalcrow added this to the 0.104.0 milestone Mar 17, 2026
@alejoe91
Copy link
Member

Oups, @chrishalcrow can you check tests?

@alejoe91 alejoe91 merged commit 1f0339f into SpikeInterface:main Mar 18, 2026
15 checks passed
@chrishalcrow chrishalcrow deleted the fix-scalings-if-template-zero branch March 18, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working postprocessing Related to postprocessing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants