Skip to content

Commit

Permalink
Merge pull request #2708 from samuelgarcia/fix_motion_interpolate
Browse files Browse the repository at this point in the history
Change "idw" to "kriging" in spatial_interpolation_kernel parameters
  • Loading branch information
samuelgarcia committed Apr 29, 2024
2 parents 256757c + 55425df commit 932b1fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
21 changes: 4 additions & 17 deletions src/spikeinterface/preprocessing/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@
weight_with_amplitude=False,
),
"interpolate_motion_kwargs": dict(
direction=1,
border_mode="remove_channels",
spatial_interpolation_method="idw",
num_closest=3,
direction=1, border_mode="remove_channels", spatial_interpolation_method="kriging", sigma_um=20.0, p=2
),
},
"nonrigid_fast_and_accurate": {
Expand Down Expand Up @@ -131,10 +128,7 @@
weight_with_amplitude=False,
),
"interpolate_motion_kwargs": dict(
direction=1,
border_mode="remove_channels",
spatial_interpolation_method="idw",
num_closest=3,
direction=1, border_mode="remove_channels", spatial_interpolation_method="kriging", sigma_um=20.0, p=2
),
},
# This preset is a super fast rigid estimation with center of mass
Expand All @@ -159,10 +153,7 @@
rigid=True,
),
"interpolate_motion_kwargs": dict(
direction=1,
border_mode="remove_channels",
spatial_interpolation_method="idw",
num_closest=3,
direction=1, border_mode="remove_channels", spatial_interpolation_method="kriging", sigma_um=20.0, p=2
),
},
# This preset try to mimic kilosort2.5 motion estimator
Expand Down Expand Up @@ -196,11 +187,7 @@
win_shape="rect",
),
"interpolate_motion_kwargs": dict(
direction=1,
border_mode="force_extrapolate",
spatial_interpolation_method="kriging",
sigma_um=[20.0, 30],
p=1,
direction=1, border_mode="force_extrapolate", spatial_interpolation_method="kriging", sigma_um=20.0, p=2
),
},
# empty preset
Expand Down
4 changes: 2 additions & 2 deletions src/spikeinterface/preprocessing/preprocessing_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_spatial_interpolation_kernel(
method="kriging",
sigma_um=20.0,
p=1,
num_closest=3,
num_closest=4,
sparse_thresh=None,
dtype="float32",
force_extrapolate=False,
Expand Down Expand Up @@ -40,7 +40,7 @@ def get_spatial_interpolation_kernel(
Used in the "kriging" formula
sparse_thresh: None or float, default: None
If not None for "kriging" force small value to be zeros to get a sparse matrix.
num_closest: int, default: 3
num_closest: int, default: 4
Used for "idw"
force_extrapolate: bool, default: False
How to handle when target location are outside source location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_get_spatial_interpolation_kernel():
target_location[:, 1] = np.linspace(0, 130, 4)

for method in ("kriging", "idw", "nearest"):

kernel = get_spatial_interpolation_kernel(
source_location, target_location, method=method, force_extrapolate=False
)
Expand All @@ -23,6 +24,13 @@ def test_get_spatial_interpolation_kernel():
# check sum sum close 1
assert np.allclose(np.sum(kernel[:, 1:], axis=0), 1.0)

# import matplotlib.pyplot as plt
# fig, ax = plt.subplots()
# im = ax.imshow(kernel)
# ax.set_title(method)
# fig.colorbar(im)
# plt.show()


if __name__ == "__main__":
test_get_spatial_interpolation_kernel()

0 comments on commit 932b1fa

Please sign in to comment.