Allow Dredge AP to use online motion resolution method - #4746
chrishalcrow wants to merge 15 commits into
Conversation
|
This is amazing! I'll take a look at the code. |
cwindolf
left a comment
There was a problem hiding this comment.
Can't see any issues here, this is great!
|
I think this is working. I still want to add tests and docs, but if anyone wants to try it out on some real data, have a go! @alejoe91 @cwindolf Here's an hour chronic recording estimated motion: this PR, full: this PR, online: |
| What torch device to run on? E.g., "cpu" or "cuda" or "cuda:1". | ||
| batching_mode : Literal["full", "online"], default: "full" | ||
| Which batching_mode to run when computing displacement vector. | ||
| chunk_len_s=None, |
There was a problem hiding this comment.
| chunk_len_s=None, | |
| chunk_len_s: float | None, default: None, |
There was a problem hiding this comment.
I think that a better behavior would be to fail if mode is online and chunk_len_s is None. You want online? Give me chunk size!
| batching_mode : Literal["full", "online"], default: "full" | ||
| Which batching_mode to run when computing displacement vector. | ||
| chunk_len_s=None, | ||
| If `batching_mode` is "online", how long should each batch be, in seconds. |
There was a problem hiding this comment.
Add comment about longer chunks is better.
|
You are a hero. |
|
Does the raster fit in memory for long recording ? @cwindolf @chrishalcrow what do you think ? |
|
I think it's okay to keep the raster in memory. Chris is a hero!! Next up is multi-segment :) |
|
Maybe this can be merged with the raster in memory for now. I think it's more natural to do the rasters separately in a multi-segment setting, so maybe when we implement multi-segment we can improve this? |



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_apanddredge_online_lpfthe following dicts:thomas_kw: passed to
thomas_solvexcorr_kw: passed to
xcorr_windowsInside the functions, we set the following kwarg dicts:
full_xcorr_kw
weights_kw (passed to
weight_correlation_matrixin AP, just used to getmincorrin LFP)threshold_kw (passed to
threshold_correlation_matrix). We set: