SpikeInterface / spikeinterface

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

Waveform processing by unit very slow in version 0.101.0 #2589

Open taningh86 opened 8 months ago

taningh86 commented 8 months ago

Hi, Once the waveform figure is plotted its taking a lot of time (~2 mins) to process from waveform of one unit to another. This also happened with 0.100.0 but templates_percentile_shading=None got rid of the issue. With version 0.101.0 templates_percentile_shading=None don't seem to improve. Below is the code I used to compute amplitudes and get the plot

sparsity = si.compute_sparsity(sorting_analyzer, method = "radius", radius_um = 30) w = sw.plot_unit_templates(sorting_analyzer,templates_percentile_shading=None,backend = "ipywidgets")

Is there another alternative with version 0.101.0? or is the issue soething other than the version?

Thanks Jimmy

samuelgarcia commented 8 months ago

Hi. Maybe your sorting is dense and you want to have sparse one. compute_sparsity, like uou do here, do means that you turn sorting_analyzer into a sparse one.

zm711 commented 8 months ago

Hey Sam here is the correctly rendered code from the original issue:

from spikeinterface import create_sorting_analyzer, load_sorting_analyzer
sorting_analyzer = si.create_sorting_analyzer( sorting=sorting_wout_excess_spikes,  recording=recording_saved,  format='binary_folder',  folder= 'sorting_analyzer' )
job_kwargs = dict(n_jobs=8, chunk_duration="1s", progress_bar=True)
sorting_analyzer.compute( "random_spikes", method="uniform", max_spikes_per_unit=500, ) 
sorting_analyzer.compute("waveforms", ms_before=1.0, ms_after=2.0, return_scaled=True, **job_kwargs) 
sorting_analyzer.compute("templates", operators=["average", "median", "std"])
print(sorting_analyzer)
sparsity = si.compute_sparsity(sorting_analyzer, method = "radius", radius_um = 30) 
w = sw.plot_unit_templates(sorting_analyzer,templates_percentile_shading=None,backend = "ipywidgets")

The analyzer is already sparse at creation, so it shouldn't be a dense issue. But yeah calculating the sparsity again doesn't do anything, but it also shouldn't hurt anything....

taningh86 commented 8 months ago

Sorry, its about 13 seconds of lag to toggle between units not 2 mins. I overshot it by a lot. However, its not instantaneous like how it used to be. Are there any other arguments I can change to make the process faster?

alejoe91 commented 8 months ago

@samuelgarcia I think we should pre-load the templates within the widget, especially when using ipywidgets backend!

samuelgarcia commented 8 months ago

SAlut, Normally when the templates extension is loaded then the array living in memory and so it is loaded for always until the analyzer is desoyed. So the access should be fast. I will try to reproduce the lag when interactive plot template locally.

alejoe91 commented 8 months ago

@taningh86 can you check if this slowdown is only happening the first time you plot it? Because in that case, we know how and where to fix it :)

taningh86 commented 8 months ago

hi @alejoe91 . The slowdown is persistent on my end. I restarted the kernel and ran the whole notebook again to check and it is still slow to toggle between units. Is that what you wanted me to check?

alejoe91 commented 8 months ago

Almost. Not restarting the kernel, but just re-rilunning the cell

taningh86 commented 8 months ago

@alejoe91 Yeah, i did that too but don't improve processing speed. Is it better on your end?

taningh86 commented 8 months ago

Please let me know if there are any updates on this issue. Thanks!