Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save waveforms from spikeinterface to NWB? #3615

Open
khl02007 opened this issue Jan 13, 2025 · 8 comments
Open

How to save waveforms from spikeinterface to NWB? #3615

khl02007 opened this issue Jan 13, 2025 · 8 comments
Labels
question General question regarding SI

Comments

@khl02007
Copy link
Contributor

Is there a function to save waveforms in spikeinterface (SortingAnalyzer extension or older WaveformExtractor) to NWB format?

@alejoe91 alejoe91 added the question General question regarding SI label Jan 14, 2025
@alejoe91
Copy link
Member

Hi @khl02007!

You can use the write_sorting_analyzer from the neuroconv package!

from neuroconv.tools.spikeinterface.spikeinterface import write_sorting_analyzer

write_sorting_analyzer(sorting_analyzer, nwbfile_path="path-to-nwb-file")

You can also write to an open nwbfile using the nwbfile argument or simply add the sorting analyzer info (units table + waveform means/stds + quality/template metrics column) to an open nwbfile without writing it with the add_sorting_analyzer_to_nwbfile function.

@h-mayorquin
Copy link
Collaborator

Clarification for people that were confused like me: Note that this adds the means and the stds of the waveforms for each units as @alejoe91 mentions above. It does not add all the waveforms which is probably a good idea since that will make the NWB explode in size and anyway you can quickly extract each of the individual waveforms on the fly as you have the timings on the units table.

@borrepp
Copy link

borrepp commented Jan 21, 2025

Hi Heberto (@h-mayorquin )

One question, which might be more related to NWB than spikeinterface.

Once that the UNITS table is created (without the waveforms column). How can we retrieve the individual waveforms? The NWB.electricalseries are likely stored in the acquisition (i.e. raw recording) or ephys.FilteredEphys (i.e. spikeinterface preprocessed recording) containers. I searched for some example code/function but didn't find any.

Thanks
Pepe

@alejoe91
Copy link
Member

Hi @borrepp

Individual waveforms are not saved. Only the mean and std of the waveforms are added as columns.

@borrepp
Copy link

borrepp commented Jan 21, 2025

Hi @alejoe91
Thanks, I understood that part.
My question is more on the NWB side.
Once that I exported the sorting_analyzer (recording & units) to an NWB file. How can I read the waveforms? Or, for example, is there a function to create a sorting_analyzer from an NWB containing recording & units that will allow access to the waveforms?
Should I post this question on the NWB or neuroconv site?
Thanks in advance for any help.
Best
Pepe

@khl02007
Copy link
Contributor Author

@alejoe91 @h-mayorquin Thanks so much!

I think it's worth having an option to save all the waveforms and not just the mean. For example, many quality metrics require all the waveforms (e.g. to project onto PC space). It would be too time-consuming to re-extract waveforms every time you want to compute a different metric. The sorting analyzer saves waveforms to disk anyway; maybe there could be an option to save it in NWB format?

@alejoe91
Copy link
Member

alejoe91 commented Jan 22, 2025

Probably worth porting this issue over to neuroconv: https://github.com/catalystneuro/neuroconv

The "problem" is that by default the waveforms are only extracted on a subset of spikes, and I think that NWB would require waveforms for all spikes.

@h-mayorquin
Copy link
Collaborator

Once that I exported the sorting_analyzer (recording & units) to an NWB file. How can I read the waveforms? Or, for example, is there a function to create a sorting_analyzer from an NWB containing recording & units that will allow access to the waveforms?

Load the NWBRecording and the NWBSorting and create a sorting analyzer then you can use the extract waveforms functionality of the analyzer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question regarding SI
Projects
None yet
Development

No branches or pull requests

4 participants