Skip to content

WIP: Allow Dredge AP to use online motion resolution method - #4746

Open
chrishalcrow wants to merge 7 commits into
SpikeInterface:mainfrom
chrishalcrow:dredge-ap-online
Open

WIP: Allow Dredge AP to use online motion resolution method#4746
chrishalcrow wants to merge 7 commits into
SpikeInterface:mainfrom
chrishalcrow:dredge-ap-online

Conversation

@chrishalcrow

@chrishalcrow chrishalcrow commented Aug 31, 2026

Copy link
Copy Markdown
Member

The motion correction algorithms in SpikeInterface have two steps. You first compute many histograms-in-depth (using e.g. peak detection or LFP) over time. Second, you compare the histograms at different times to extract a time vector.

In the current implementation, if you use peak detection the comparison part of the algorithm compares ALL histograms against all others. This is fine if you have a standard recording, but fills up RAM quickly if you get towards one day long recordings. If you use LFP there is an "online" method to compare the histograms. This only compares histograms which are nearby in time, meaning that you don't need to load them all into memory. Hence, this can be used for very long recordings.

This PR refactors the "all at once" and "online" methods to extract motion vectors from histograms, allowing either method to be used regardless of histogram-construction method. Most of the pain is in how parameters are dealt with - they were packaged a bit differently for the two algorithms. We attempt to unify the arguments in the two methods as much as possible, and abstract some language.

Docs, tests, etc incoming.

I spent a while understanding the parameters and all the kwarg dicts. Here's a summary:

Parameters

User can give dredge_ap and dredge_online_lpf the following dicts:

thomas_kw: passed to thomas_solve
xcorr_kw: passed to xcorr_windows

Inside the functions, we set the following kwarg dicts:

full_xcorr_kw

  • rigid
  • bin_um
  • max_disp_um
  • progress_bar
  • device

weights_kw (passed to weight_correlation_matrixin AP, just used to get mincorr in LFP)

  • mincorr
  • time_horizon_s
  • do_window_weights
  • weights_threshold_low
  • weights_threshold_high

threshold_kw (passed to threshold_correlation_matrix). We set:

  • mincorr_percentile_nneighbs
  • in_place
  • soft
  • time_horizon_s
  • bin_s

@cwindolf

cwindolf commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

This is amazing! I'll take a look at the code.

@cwindolf cwindolf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can't see any issues here, this is great!

**xcorr_kw,
)

if resolution_mode == "simultaneous":

@cwindolf cwindolf Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd call this "batch" or "offline"? (Just because those are more standard terms in optimization literature for this kind of thing)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you think "resolution_mode" is the right terminology. I struggled with this language.

bin_s=1 / lfp_recording.sampling_frequency, # only relevant for time_horizon_s
)

P_online = compute_displacement_online(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

if isinstance(lfp_recording, BaseRecording):
traces0 = lfp_recording.get_traces(start_frame=t0, end_frame=t1)
else:
traces0 = lfp_recording[:, t0:t1].T

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

@chrishalcrow chrishalcrow added this to the 0.105.0 milestone Sep 3, 2026
Comment thread src/spikeinterface/sortingcomponents/motion/dredge.py Outdated
@alejoe91 alejoe91 added the motion correction Questions related to motion correction label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

motion correction Questions related to motion correction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants