Skip to content

Add option to export spike waveforms subset to phy (mimic phy extract-waveforms) - #4699

Merged
chrishalcrow merged 7 commits into
SpikeInterface:mainfrom
alejoe91:phy-extract-waveforms
Sep 10, 2026
Merged

Add option to export spike waveforms subset to phy (mimic phy extract-waveforms)#4699
chrishalcrow merged 7 commits into
SpikeInterface:mainfrom
alejoe91:phy-extract-waveforms

Conversation

@alejoe91

@alejoe91 alejoe91 commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds an add_waveforms option to export_to_phy that writes phy's _phy_spikes_subset.{spikes,channels,waveforms}.npy files, mimicking the phy extract-waveforms CLI command.
  • Reuses the SortingAnalyzer's waveforms/random_spikes extensions when already computed, and computes them on demand otherwise (skipping with a warning if there's no recording available).
  • Handles both sparse and dense SortingAnalyzer/sparsity combinations, matching the sparsity already used for templates.npy/pc_feature_ind.npy.

Test plan

  • Verified with phylib.io.model.TemplateModel (phy's own loader) that the exported files load correctly and return proper per-cluster waveforms, for both sparse and dense analyzers.
  • Verified stored waveform values exactly match manually-extracted raw-trace snippets (accounting for nbefore/uV scaling).
  • Add a unit test to src/spikeinterface/exporters/tests/ covering add_waveforms=True.

🤖 Generated with Claude Code

alejoe91 and others added 2 commits July 20, 2026 10:49
Writes _phy_spikes_subset.{spikes,channels,waveforms}.npy from the
SortingAnalyzer's "waveforms"/"random_spikes" extensions, so phy/phy-lib
can display individual spike waveforms without re-reading the raw
recording.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@alejoe91 alejoe91 added this to the 0.105.0 milestone Jul 20, 2026
@alejoe91 alejoe91 added the extractors Related to extractors module label Jul 20, 2026
Comment thread src/spikeinterface/exporters/to_phy.py Outdated
Comment thread src/spikeinterface/exporters/to_phy.py Outdated
@chrishalcrow

chrishalcrow commented Sep 9, 2026

Copy link
Copy Markdown
Member

I think the new release of phy no longer supports _phy_spikes_subset.* - I can't find any mention of this type of file in the code of the codebase. I propose to delay this for now.

@alejoe91

Copy link
Copy Markdown
Member Author

I think the new release of phy no longer supports _phy_spikes_subset.* - I can't find any mention of this type of file in the code of the codebase. I propose to delay this for now.

This is handled in phylib and I tested with the most recent phy version:
https://github.com/cortex-lab/phylib/blob/master/phylib/io/model.py#L684-L702

Example with add_waveforms=True, exported after resetting recoriding (so waveforms must be coming from new files), phy==2.1.0
image

I don't think we should delay this ;)

@chrishalcrow chrishalcrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there was a bug(?) in phy and no templates or waveforms were showing until I toggled and bunch of options. Ok, working for me now!

Just one request to make one of the docstrings less overly verbose.

@chrishalcrow
chrishalcrow merged commit 5494c1f into SpikeInterface:main Sep 10, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extractors Related to extractors module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants