-
Notifications
You must be signed in to change notification settings - Fork 241
Description
I am still working out exactly what's wrong here. I have been testing different motion correction settings and benchmarking against one another.
I'm starting with the new motion syntax (as opposed to the old syntax which returned motion, temporal_bins, and spatial_bins)
# NEW FORMAT
from spikeinterface.sortingcomponents.motion import estimate_motion
motion, motion_info = estimate_motion(recording=rec,
peaks=peaks, peak_locations=peak_locations, extra_outputs=True, **estimate_motion_kwargs)
However this "extra outputs" variable appears to be empty as of right now, so I fill it in myself.
I want to use the built in
# THE FUNCTION WE CALL, BOTH OLD AND NEW
si.plot_motion_info(motion_info, rec, color_amplitude=True,figure=fig,
amplitude_cmap="inferno",
scatter_decimate=10,)
Like is shown on the motion tutorials on the docs. However this function is still written for the old format of motion_info, which was structured as:
# OLD FORMAT
motion_info = dict(
parameters=parameters,
peaks=peaks,
peak_locations=peak_locations,
temporal_bins=temporal_bins,
spatial_bins=spatial_bins,
motion=motion,
)
I am attempting to preserve that structure, so in my code I add the following:
# MY NEW FORMAT
motion_info.update(
parameters=parameters,
peaks=peaks,
peak_locations=peak_locations,
motion=motion,
)
to add it all into one place.
It appears that si.plot_motion_info does not extract temporal_bins or spatial_bins from the motion_info struct but rather from the motion object directly.
Here are my results when I use dredge:
This result is pretty bad, from a motion correction standpoint, but it demonstrates a few things going on in the code.
- First, it's important to know that I'm using 10 minutes (600 seconds) of NPX data which start at 25 minutes into the file. That is, the
recrecording object is only 600 seconds long. To be honest, I'm not sure how therecobject knows that the .bin file it loaded from doesn't start at t=0 (presumably reading the associated .meta file) - The top left plot is the original, uncorrected peaks. The time span is 0 to 600 seconds. This data has been time shifted.
- The top right plot is the corrected peaks. The time span is 0 to 600 seconds. This data has been time shifted
- The bottom plots show the motion vectors. The time span is 1500 to 2100 seconds. This data has not been time shifted. However it shows that the
si.plot_motion_infois aware of both the motion vector and the original timeline.
This is true for dredge, nonrigid accurate, and kilosort-like. However things break with Medicine.
There are two mistakes here:
- The motion vector is not applied. The top right graph is exactly the same as the top left, and there is no way for the user to determine if the Medicine motion vector is better / worse than the other methods.
- Unlike the other methods, the motion plots on the bottom both reference the timescale 0 to 600. This is not an error per se, but it does indicate a difference in behavior, and may explain the underlying error of #1 above.
I am still digging into things, but I anticipate that there is something different about the formatting of the motion object between medicine and the other motion correction methods. This may be a unique error for data pulled out of a snippet of the recording, or may exist more broadly.
I'd appreciate any insights into how these motion vectors are aligned to the different time vectors, either 0-600 or 1500-2100
UPDATE:
I can confirm that within motion, temporal_bins_s and temporal_bins_edges_s begin at 1500 for dredge and 0 for Medicine