Use MEDiCINe's own recommended default for num_depth_bins#4686
Use MEDiCINe's own recommended default for num_depth_bins#4686nwatters01 wants to merge 4 commits into
Conversation
The medicine preset derived num_depth_bins from the generic win_scale_um windowing parameter (tuned for other methods like dredge/decentralized), which for a typical probe produces far more depth bins than MEDiCINe is designed for. MEDiCINe's own default and documented recommendation is 2 non-rigid depth bins, so use that directly (1 when rigid) unless the user explicitly passes num_depth_bins. All other MedicineRegistration defaults already matched medicine.run_medicine()'s defaults exactly.
|
Some context: I have received emails from users complaining about the fact that spikeinterface's default parameters for Medicine are not appropriate. This PR changes this to make the default parameters ones that Medicine works well for. This change is completely backwards compatible, and no other motion estimation methods are affected. |
|
This makes sense to me thanks for this. Would it be possible to add a test which runs the SI wrapper and the original MEDiCINe package to ensure the outputs / settings match? |
zm711
left a comment
There was a problem hiding this comment.
This makes sense to me. Just one question about positioning of the args.
| ## medicine specific kwargs propagated to the lib | ||
| output_dir=None, | ||
| plot_figures=False, | ||
| num_depth_bins=None, |
There was a problem hiding this comment.
curious about the positioning of this arg? I'm just thinking for backwards compatibility. If we put this at the bottom it won't break positional arguments for people but has the same effect.
There was a problem hiding this comment.
Thanks, I've now moved it to the bottom!
…nal package Verifies that: - num_depth_bins resolves to MEDiCINe's own default (2 non-rigid / 1 rigid), independent of the generic win_scale_um window parameter used by other motion estimation methods. - Given the same peaks and RNG state, spikeinterface's `medicine` estimate_motion method produces output identical to calling medicine.run_medicine() directly.
|
Thank you for your suggestions. I've moved the num_depth_bins argument to the bottom to ensure backwards compatibility, and added a test file to test that this wrapper gives the results as the medicine package with default parameters. I ran the test locally to make sure it passes. |
|
Thanks for this! The new tests aren't currently running on the ci: if you look at https://github.com/SpikeInterface/spikeinterface/actions/runs/29302001612/job/86987545183?pr=4686#step:30:378 and search "medicine" you'll see You should be able to add it to the sorting-components test suite by adding medicine to the pyproject.toml here: Line 309 in c33abf5 |
Needed so the new test_medicine.py test actually runs in CI instead of being skipped, and documents medicine-neuro as an optional heavy dep (like torch) for the "medicine" motion estimation method.
|
Thanks for the comments, and Alessio for approval! I've now fixed the test dependencies, so the tests run. I'll wait for the rest of the day to hear if there's anything else, and otherwise will merge first thing tomorrow. |
Summary
medicinemotion estimation preset (MedicineRegistration.runinsrc/spikeinterface/sortingcomponents/motion/medicine.py) computednum_depth_binsby dividing the probe's depth span bywin_scale_um, a generic windowing parameter tuned for other methods (dredge,decentralized, etc.), defaulting to 300 µm. For a typical probe this yields far more depth bins than MEDiCINe is designed for.medicine.run.run_medicine) defaults and documentsnum_depth_bins=2as sufficient for all of its authors' recording sessions, independent of any window-scale concept.MedicineRegistration.run(motion_bound,time_kernel_width,activity_network_hidden_features,amplitude_threshold_quantile,batch_size,training_steps,initial_motion_noise,motion_noise_steps,learning_rate,epsilon) already matchmedicine's own defaults exactly —num_depth_binswas the one outlier.num_depth_bins=Noneparameter toMedicineRegistration.run. When unset, it now defaults to1 if rigid else 2(MEDiCINe's own recommendation) instead of being derived fromwin_scale_um/win_margin_um. Users who want a different value can still passnum_depth_binsexplicitly throughestimate_motion_kwargs.params_docdocstring for this method, and removed a leftover debugprint().estimate_motion()signature/defaults were touched, so this is backwards compatible for all other motion estimation methods.Dependencies
medicine-neurowas not previously referenced anywhere inpyproject.toml. Added it to thetest-sortingcomponentsdependency group (alongsidetorch, following the same pattern) so the new test below actually runs in CI rather than being skipped, and added an explanatory comment next to the existingtorchcomment in[project.optional-dependencies].sortingcomponentsnoting it's an optional heavy dep (itself pulling intorch) needed only for themedicinemethod — not bundled into that extra by default, same treatment astorch.Test plan
src/spikeinterface/sortingcomponents/motion/tests/test_medicine.py(skipped if the optionalmedicine/torchpackages aren't installed):num_depth_binsresolves to MEDiCINe's own default (2 non-rigid / 1 rigid), independent ofwin_scale_um.torch.manual_seed/np.random.seed), the spikeinterfacemedicineestimate_motionwrapper produces output numerically identical to callingmedicine.run_medicine()directly, confirming the wrapper's resolved settings and outputs match the original package.python -m pytest src/spikeinterface/sortingcomponents/motion/tests/(full directory, 12 passed, no regressions)python -m py_compile src/spikeinterface/sortingcomponents/motion/medicine.py