feat: DREDge motion correction (CatGT→DREDge→KS4) + uv/py3.14 env#5
Open
tabedzki wants to merge 3 commits into
Open
feat: DREDge motion correction (CatGT→DREDge→KS4) + uv/py3.14 env#5tabedzki wants to merge 3 commits into
tabedzki wants to merge 3 commits into
Conversation
…CatGT Adds DREDge (SpikeInterface correct_motion(preset="dredge_ap")) as an opt-in preprocessing tool alongside CatGT, per BrainCogsEphysSorters#4 (Option A). - config: register 'dredge' in preproc_tools + preproc_tools_delete_post - preprocess_wrappers: dredge branch in preprocess_main; dredge.run_dredge reads the SpikeGLX run, runs correct_motion, and writes a SpikeGLX-style *.ap.bin + copied *.ap.meta into dredge_output/ (drop-in for CatGT output, so the Kilosort callers are unchanged). SpikeInterface import is deferred. Adds preprocess_has_tool() helper. - sorter_wrappers: when DREDge ran, disable each Kilosort's internal drift correction to avoid double-correcting (KS4 nblocks=0+do_correction=False, KS3 nblocks=0, KS2 reorder=0). - kilosortbatch.m: honor ops.nblocks==0 (was always calling datashift2(rez,1)) - deps: add spikeinterface[full] Assisted-by: ClaudeCode:claude-opus-4.8
3 tasks
Contributor
Author
|
🤖 AI text below 🤖 Companion tracking issue (orchestration side): BrainCOGS/U19-pipeline-python#94 — describes the DataJoint param inserts ( |
correct_motion() has never accepted "dredge_ap" as a preset key. The valid key is "dredge" (SpikeInterface's "Official Dredge preset"), which sets estimate_motion_kwargs.method="dredge_ap" internally. Passing "dredge_ap" would raise on every released version, including the 0.104.8 the lockfile resolves to. Pin a >=0.101 floor: that release introduced the Motion class and the dredge preset. write_binary_recording's signature is unchanged across 0.101-0.104 for the kwargs we pass. Assisted-by: ClaudeCode:claude-opus-4.8
…nize env Reconcile the DREDge preprocessing step with the CatGT->DREDge->KS4 flow and modernize the Python environment to uv on Python 3.14. DREDge (u19_sorting/preprocess_wrappers.py): - run_dredge reads whatever the previous step produced (the flattened CatGT output dir, or raw SpikeGLX if DREDge runs alone) by globbing *ap.meta, so it chains after CatGT without assuming the original run-folder layout. - Pass the motion-estimation device explicitly (cuda when available, cpu fallback) since DREDge does not auto-detect a GPU the way KS4 does; free CUDA memory before handing off to the sorter. - Persist motion_info + drift plots for verification; lazy-skip on requeue. - Materialize a SpikeGLX-style *.ap.bin via write_binary_recording (+ copied *.ap.meta) so the existing Kilosort callers read it unchanged. Environment: - requires-python >= 3.14; spikeinterface>=0.104.8 (floor, no upper bound); floor ibllib/ONE-api at 4.0.1/3.4.1 to stop the resolver regressing to a stale pre-2024 snapshot; re-lock so matplotlib/pyarrow pick cp314 wheels. - Replace invalid empty license field with license-files; point Pyright at .venv. - config.py: register dredge in preproc_tools + preproc_tools_delete_post. Verified end-to-end on a synthetic drifting recording: produces one ap.bin+ap.meta, non-trivial motion displacement, KS4 find_binary locates it, and the second run lazy-skips. Closes #4
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Summary
Implements Option A from #4: adds DREDge motion correction (SpikeInterface
correct_motion(preset="dredge")) as an opt-in preprocessing step in theCatGT → DREDge → Kilosort4flow. DREDge is one more selectablepreproc_tool, mirroringcatgt; Kilosort keeps its directkilosort.run_kilosortcall. Also modernizes the environment to uv on Python 3.14.How it works
run_dredgereads whatever the previous step produced (globs*ap.meta): the flattened CatGT output dir when chained, or raw SpikeGLX if DREDge runs alone. It writes a SpikeGLX-style*.ap.bin+ copied*.ap.metaintodredge_output/, which becomesnew_raw_data_directory, so the existing Kilosort callers read it unchanged.nblocks=0in the process paramset, so motion is corrected once (by DREDge).do_correctionis not a KS4 parameter (verified: zero hits in thekilosortpkg) and is kept only as an inert, KS2/KS3-friendly key.run_dredgepassesestimate_motion_kwargs={"device": ...}explicitly (cuda when available, cpu fallback) and frees CUDA memory before the sorter stage.Changes
u19_sorting/config.py— registerdredgeinpreproc_tools+preproc_tools_delete_post.u19_sorting/preprocess_wrappers.py—dredgebranch inpreprocess_main;dredge.run_dredge(read →correct_motion→write_binary_recording+ copy meta → persistmotion/→ lazy-skip) anddredge_check_output.pyproject.toml—requires-python >= 3.14;spikeinterface>=0.104.8(floor, no upper bound); flooribllib/ONE-apiat 4.0.1/3.4.1 to stop the resolver regressing to a stale pre-2024 snapshot; replace the invalid emptylicensewithlicense-files; point Pyright at.venv. Re-locked so matplotlib/pyarrow resolve cp314 wheels. Retirerequirements.txt/setup.py.Verification
End-to-end on a synthetic drifting recording: exactly one
ap.bin+ap.meta, non-trivial motion displacement (≈±30 µm, not the all-zero silent-failure mode),kilosort.io.find_binarylocates the output, and a second run lazy-skips.Linkage (merge together)
🤖 Generated with Claude Code