From c89060314e233b89e4e9112e74c7643545806d22 Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Thu, 21 Nov 2024 16:09:45 -0500 Subject: [PATCH] Fix variable typo; add docstring --- .../motion/motion_interpolation.py | 5 +++-- .../sortingcomponents/motion/motion_utils.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/sortingcomponents/motion/motion_interpolation.py b/src/spikeinterface/sortingcomponents/motion/motion_interpolation.py index 14471f77fc..e87f83751c 100644 --- a/src/spikeinterface/sortingcomponents/motion/motion_interpolation.py +++ b/src/spikeinterface/sortingcomponents/motion/motion_interpolation.py @@ -3,7 +3,8 @@ import numpy as np from spikeinterface.core.core_tools import define_function_from_class from spikeinterface.preprocessing import get_spatial_interpolation_kernel -from spikeinterface.preprocessing.basepreprocessor import BasePreprocessor, BasePreprocessorSegment +from spikeinterface.preprocessing.basepreprocessor import ( + BasePreprocessor, BasePreprocessorSegment) from spikeinterface.preprocessing.filter import fix_dtype from .motion_utils import ensure_time_bin_edges, ensure_time_bins @@ -155,7 +156,7 @@ def interpolate_motion_on_traces( interp_times = np.empty(total_num_chans) current_start_index = 0 for interp_bin_ind in interpolation_bins_here: - bin_time = bin_centers_s[interp_bin_ind] + bin_time = interpolation_time_bin_centers_s[interp_bin_ind] interp_times.fill(bin_time) channel_motions = motion.get_displacement_at_time_and_depth( interp_times, diff --git a/src/spikeinterface/sortingcomponents/motion/motion_utils.py b/src/spikeinterface/sortingcomponents/motion/motion_utils.py index ec0a55a8f8..680d75f221 100644 --- a/src/spikeinterface/sortingcomponents/motion/motion_utils.py +++ b/src/spikeinterface/sortingcomponents/motion/motion_utils.py @@ -580,6 +580,22 @@ def make_3d_motion_histograms( def ensure_time_bins(time_bin_centers_s=None, time_bin_edges_s=None): + """Ensure that both bin edges and bin centers are present + + If either of the inputs are None but not both, the missing is reconstructed + from the present. Going from edges to centers is done by taking midpoints. + Going from centers to edges is done by taking midpoints and padding with the + left and rightmost centers. + + Parameters + ---------- + time_bin_centers_s : None or np.array + time_bin_edges_s : None or np.array + + Returns + ------- + time_bin_centers_s, time_bin_edges_s + """ if time_bin_centers_s is None and time_bin_edges_s is None: raise ValueError("Need at least one of time_bin_centers_s or time_bin_edges_s.")