SpikeInterface / spikeinterface

A Python-based module for creating flexible and robust spike sorting pipelines.
https://spikeinterface.readthedocs.io
MIT License
527 stars 187 forks source link

Spike amplitude data for multi-segments is incorrect #2975

Closed chrishalcrow closed 4 months ago

chrishalcrow commented 5 months ago

When you get_data by unit for amplitudes, the sampling is incorrect for multi-segment recordings.

Consider the following code:

import spikeinterface.full as si

recording, sorting = si.generate_ground_truth_recording(durations=[10,10], seed=1205)

analyzer = si.create_sorting_analyzer(recording=recording, sorting=sorting)
analyzer.compute(['random_spikes', 'templates', 'spike_amplitudes'])

si.plot_amplitudes(analyzer, segment_index=0)
si.plot_amplitudes(analyzer, segment_index=1)

The output for the first plot is

Screenshot 2024-06-05 at 10 29 02

This looks good: each unit has amplitudes based around a common mean.

The second plot looks like this

Screenshot 2024-06-05 at 10 29 07

This doesn't look good. The amplitudes for each unit are scattered randomly.

Issue is in _get_data function for ComputeSpikeAmplitudes. I'm working on a fix.

samuelgarcia commented 5 months ago

oups. Muts be me during the refactoring.