SpikeInterface / spikeinterface

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

Calculate mean wavrforms #3282

Closed nadine-saluti closed 3 months ago

nadine-saluti commented 3 months ago

Not an issue, more of a question. I have data that I preprocessed and sorted with Kilosort 2.0 using the spike interface pipeline. I then curated the data with phy, and now I want to extract the waveforms in the new units after the curation. However, I only want the templates_avergade.npy file—and preferably only for the units I labeled as "good." Extracting all the waveforms again using the extract_waveforms function seems too time-consuming. How can I do it?

zm711 commented 3 months ago

Great question!

you can use the read_phy function. (docstring here ) which has a keep_good_only=True option you can set that will only load the units you labeled as "good". Unfortunately after that you would still have to run the extract_waveforms (it seems like you are using spikeinterface < 0.101.0 since we've had an api change (and some nice speed-ups too). But in this case you would only extract on the good units and not waste time on all the "non-good" units :)

nadine-saluti commented 3 months ago

Thank you! Is there a way to use extract_waveforms without re-loading the recording (this is pretty time-consuming as well, in my case)?

zm711 commented 3 months ago

Unfortunately not :(

The only way you can get waveforms is with the raw data (and it is recommended to preprocess your recording as well to get accurate waveforms) . Our new version 0.101.0 let's you calculate the templates (waveform averages) on the fly so that you don't have to save a bunch of waveforms that you don't want, but it still requires the raw data. Although it takes some time this method will be more accurate in the end.

Our new version has greater compatibility for merging inside of spikeinterface, which will automatically just pull out the waveforms and let you get new averages etc without having to re-extract. So if your workflow is really this time-consuming it might be beneficial to update and test out either sortingview (a web version of general phy functionality) or spikeinterface-gui ( a local gui with phy-like functionality). The api changes will have a little bit of a learning curve, but might fit better with your workflow and save you time in the long-run. I would suggest reading our docs on the update and seeing if it might be better for you long-term docs here

But for your current issue you have to re-extract!

nadine-saluti commented 3 months ago

Alright, thanks a lot!

I will re-extract for now, but when I'm done with my current analysis, I will check out the updates. Maybe for future experiments, I will also use your GUI for the curation.

zm711 commented 3 months ago

Cool, I'll close this then, but feel free to open new issues if needed :)