From ef0d66e6cfeea0b1f3392c5a0a8758194a9c884d Mon Sep 17 00:00:00 2001 From: Pierre Yger Date: Tue, 19 Sep 2023 09:27:18 +0200 Subject: [PATCH] Bringing back right searches --- src/spikeinterface/core/generate.py | 8 +++----- src/spikeinterface/curation/remove_duplicated_spikes.py | 3 ++- src/spikeinterface/postprocessing/spike_locations.py | 3 ++- .../sortingcomponents/motion_interpolation.py | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 6f85e76f1f..33f3dea923 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1209,11 +1209,9 @@ def get_traces( else: traces = np.zeros([end_frame - start_frame, n_channels], dtype=self.dtype) - start, end = np.searchsorted( - self.spike_vector["sample_index"], - [start_frame - self.templates.shape[1], end_frame + self.templates.shape[1] + 1], - side="left", - ) + start = np.searchsorted(self.spike_vector["sample_index"], start_frame - self.templates.shape[1], side="left") + end = np.searchsorted(self.spike_vector["sample_index"], end_frame + self.templates.shape[1], side="right") + for i in range(start, end): spike = self.spike_vector[i] diff --git a/src/spikeinterface/curation/remove_duplicated_spikes.py b/src/spikeinterface/curation/remove_duplicated_spikes.py index d01ca1f6a1..04af69b37a 100644 --- a/src/spikeinterface/curation/remove_duplicated_spikes.py +++ b/src/spikeinterface/curation/remove_duplicated_spikes.py @@ -82,7 +82,8 @@ def get_unit_spike_train( if end_frame == None: end_frame = spike_train[-1] if len(spike_train) > 0 else 0 - start, end = np.searchsorted(spike_train, [start_frame, end_frame + 1], side="left") + start = np.searchsorted(spike_train, start_frame, side="left") + end = np.searchsorted(spike_train, end_frame, side="right") return spike_train[start:end] diff --git a/src/spikeinterface/postprocessing/spike_locations.py b/src/spikeinterface/postprocessing/spike_locations.py index 5f23e25b32..c6f498f7e8 100644 --- a/src/spikeinterface/postprocessing/spike_locations.py +++ b/src/spikeinterface/postprocessing/spike_locations.py @@ -77,7 +77,8 @@ def get_data(self, outputs="concatenated"): elif outputs == "by_unit": locations_by_unit = [] for segment_index in range(self.waveform_extractor.get_num_segments()): - i0, i1 = np.searchsorted(self.spikes["segment_index"], [segment_index, segment_index + 1], side="left") + i0 = np.searchsorted(self.spikes["segment_index"], segment_index, side="left") + i1 = np.searchsorted(self.spikes["segment_index"], segment_index, side="right") spikes = self.spikes[i0:i1] locations = self._extension_data["spike_locations"][i0:i1] diff --git a/src/spikeinterface/sortingcomponents/motion_interpolation.py b/src/spikeinterface/sortingcomponents/motion_interpolation.py index 18bb4f5a99..9a4cd688c5 100644 --- a/src/spikeinterface/sortingcomponents/motion_interpolation.py +++ b/src/spikeinterface/sortingcomponents/motion_interpolation.py @@ -155,8 +155,9 @@ def interpolate_motion_on_traces( **spatial_interpolation_kwargs, ) - i0, i1 = np.searchsorted(bin_inds, [bin_ind, bin_ind + 1], side="left") - + i0 = np.searchsorted(bin_inds, bin_ind, side="left") + i1 = np.searchsorted(bin_inds, bin_ind, side="right") + # here we use a simple np.matmul even if dirft_kernel can be super sparse. # because the speed for a sparse matmul is not so good when we disable multi threaad (due multi processing # in ChunkRecordingExecutor)