Skip to content

Add automatic post-sorting unit merge (Phase 3b) via SpikeInterface curation#149

Draft
mandarmp with Copilot wants to merge 2 commits into
mainfrom
copilot/add-automatic-merging-units
Draft

Add automatic post-sorting unit merge (Phase 3b) via SpikeInterface curation#149
mandarmp with Copilot wants to merge 2 commits into
mainfrom
copilot/add-automatic-merging-units

Conversation

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Kilosort4 frequently oversplits single neurons into multiple clusters. This adds a dedicated auto-merge phase between the analyzer and report generation that detects and corrects those splits using SpikeInterface's auto_merge_units.

Pipeline change

New Phase 3b inserted between run_analyzer() and generate_reports():

pipeline.run_sorting()
pipeline.run_analyzer()
pipeline.run_auto_merge(no_auto_merge=resolved["no_auto_merge"])  # new
pipeline.generate_reports(...)

run_auto_merge() calls sic.auto_merge_units() with the "similarity_correlograms" preset, which gates merges through six sequential criteria:

  1. Minimum spike count (preset default: 100)
  2. Refractory-period contamination filter
  3. Location proximity (≤150 µm)
  4. Template shape similarity
  5. Cross-correlogram similarity
  6. Net quality-score improvement (firing rate vs. contamination balance)

Merged units are saved to analyzer_merged/ and loaded on resume. If no merge candidates are found, or if the step throws, the original analyzer is used unchanged.

New controls

Flag Config key Effect
--no-auto-merge curation.no_auto_merge Skip the merge step entirely

Available on both mea_analysis_routine.py and run_pipeline_driver.py; propagated through build_extra_args.

Docs

README.md updated with: pipeline stages table, key features list, output directory layout (analyzer_merged/), config section reference, CLI reference table, workflow example, and a new Automatic Unit Merging section covering the algorithm and disable instructions.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: mandarmp <33731455+mandarmp@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic merging of units after spike sorting Add automatic post-sorting unit merge (Phase 3b) via SpikeInterface curation Mar 12, 2026
Copilot AI requested a review from mandarmp March 12, 2026 19:55
@mandarmp mandarmp requested a review from adamwea March 12, 2026 22:29
@mandarmp

Copy link
Copy Markdown
Collaborator

@mandarmp @adamwea I had started this experimentation with the automerge feature. Is it similar to yours?

@adamwea

adamwea commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

@mandarmp @adamwea I had started this experimentation with the automerge feature. Is it similar to yours?

Yea I have automerge implemented on my branch as an alternative to unit match. Just the same way it's implemented in si docs.

@mandarmp

Copy link
Copy Markdown
Collaborator

@adamwea can we have your PR then we can add that functionality here to the MAIN BRANCH

@mandarmp mandarmp force-pushed the copilot/add-automatic-merging-units branch from 4185207 to 574a594 Compare April 28, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants