Skip to content

Commit fb721f4

Browse files
authored
Merge pull request #4086 from samuelgarcia/motion_bins
Make `get_spatial_windows()` easier (and not fail) for short probes
2 parents a8e4321 + b90a5ff commit fb721f4

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/spikeinterface/preprocessing/tests/test_motion.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_compute_motion_fails(create_cache_folder):
5858
is `None`.
5959
"""
6060
# this recording has too few channels for the motion correction to work
61-
rec = generate_recording(durations=[5])
61+
rec = generate_recording(durations=[5], num_channels=1)
6262
motion, motion_info = compute_motion(rec, raise_error=False, output_motion_info=True)
6363

6464
assert motion is None
@@ -80,5 +80,8 @@ def test_compute_motion_fails(create_cache_folder):
8080
if __name__ == "__main__":
8181
# print(correct_motion.__doc__)
8282
# test_estimate_and_correct_motion()
83-
test_get_motion_parameters_preset()
84-
test_compute_motion_fails()
83+
# test_get_motion_parameters_preset()
84+
from pathlib import Path
85+
86+
cache_folder = Path(__file__).resolve().parents[4] / "cache_folder" / "preprocessing"
87+
test_compute_motion_fails(cache_folder)

src/spikeinterface/sortingcomponents/motion/motion_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ def get_spatial_windows(
7878
num_windows = int((max_ - min_) // win_step_um)
7979

8080
if num_windows < 1:
81-
raise Exception(
81+
num_windows = 1
82+
warnings.warn(
83+
f"You are trying to estimate motion with `non-rigid` on a probe that is too short!"
8284
f"get_spatial_windows(): {win_step_um=}/{win_scale_um=}/{win_margin_um=} are too large for the "
83-
f"probe size (depth range={np.ptp(contact_depths)}). You can try to reduce them or use rigid motion."
85+
f"probe size (depth range={np.ptp(contact_depths)}). Switching to rigid motion."
8486
)
87+
8588
border = ((max_ - min_) % win_step_um) / 2
8689
window_centers = np.arange(num_windows + 1) * win_step_um + min_ + border
8790
windows = []

0 commit comments

Comments
 (0)