From 74ef4eba21ec8bb7d413f5221d899d3f35c8287f Mon Sep 17 00:00:00 2001 From: Charlie Windolf Date: Fri, 1 Nov 2024 17:51:15 -0400 Subject: [PATCH 1/2] Remove remaining array.ptp()s --- .../postprocessing/localization_tools.py | 10 ++++++---- .../sortingcomponents/motion/dredge.py | 18 ++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/spikeinterface/postprocessing/localization_tools.py b/src/spikeinterface/postprocessing/localization_tools.py index 837b983059..685dcad1f0 100644 --- a/src/spikeinterface/postprocessing/localization_tools.py +++ b/src/spikeinterface/postprocessing/localization_tools.py @@ -3,6 +3,10 @@ import warnings import numpy as np +from spikeinterface.core import SortingAnalyzer, Templates, compute_sparsity +from spikeinterface.core.template_tools import (_get_nbefore, + get_dense_templates_array, + get_template_extremum_channel) try: import numba @@ -12,8 +16,6 @@ HAVE_NUMBA = False -from spikeinterface.core import compute_sparsity, SortingAnalyzer, Templates -from spikeinterface.core.template_tools import get_template_extremum_channel, _get_nbefore, get_dense_templates_array def compute_monopolar_triangulation( @@ -110,7 +112,7 @@ def compute_monopolar_triangulation( # wf is (nsample, nchan) - chann is only nieghboor wf = templates[i, :, :][:, chan_inds] if feature == "ptp": - wf_data = wf.ptp(axis=0) + wf_data = np.ptp(wf, axis=0) elif feature == "energy": wf_data = np.linalg.norm(wf, axis=0) elif feature == "peak_voltage": @@ -188,7 +190,7 @@ def compute_center_of_mass( wf = templates[i, :, :] if feature == "ptp": - wf_data = (wf[:, chan_inds]).ptp(axis=0) + wf_data = np.ptp(wf[:, chan_inds], axis=0) elif feature == "mean": wf_data = (wf[:, chan_inds]).mean(axis=0) elif feature == "energy": diff --git a/src/spikeinterface/sortingcomponents/motion/dredge.py b/src/spikeinterface/sortingcomponents/motion/dredge.py index e2b6b1a2bc..4db6bb1cb2 100644 --- a/src/spikeinterface/sortingcomponents/motion/dredge.py +++ b/src/spikeinterface/sortingcomponents/motion/dredge.py @@ -22,21 +22,15 @@ """ +import gc import warnings -from tqdm.auto import trange import numpy as np +from tqdm.auto import trange -import gc - -from .motion_utils import ( - Motion, - get_spatial_windows, - get_window_domains, - scipy_conv1d, - make_2d_motion_histogram, - get_spatial_bin_edges, -) +from .motion_utils import (Motion, get_spatial_bin_edges, get_spatial_windows, + get_window_domains, make_2d_motion_histogram, + scipy_conv1d) # simple class wrapper to be compliant with estimate_motion @@ -979,7 +973,7 @@ def xcorr_windows( if max_disp_um is None: if rigid: - max_disp_um = int(spatial_bin_edges_um.ptp() // 4) + max_disp_um = int(np.ptp(spatial_bin_edges_um) // 4) else: max_disp_um = int(win_scale_um // 4) From 43b085fefe1574de8bc65764ecd0b246408ebed0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 21:53:15 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../postprocessing/localization_tools.py | 6 +----- src/spikeinterface/sortingcomponents/motion/dredge.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/spikeinterface/postprocessing/localization_tools.py b/src/spikeinterface/postprocessing/localization_tools.py index 685dcad1f0..59c12a9923 100644 --- a/src/spikeinterface/postprocessing/localization_tools.py +++ b/src/spikeinterface/postprocessing/localization_tools.py @@ -4,9 +4,7 @@ import numpy as np from spikeinterface.core import SortingAnalyzer, Templates, compute_sparsity -from spikeinterface.core.template_tools import (_get_nbefore, - get_dense_templates_array, - get_template_extremum_channel) +from spikeinterface.core.template_tools import _get_nbefore, get_dense_templates_array, get_template_extremum_channel try: import numba @@ -16,8 +14,6 @@ HAVE_NUMBA = False - - def compute_monopolar_triangulation( sorting_analyzer_or_templates: SortingAnalyzer | Templates, unit_ids=None, diff --git a/src/spikeinterface/sortingcomponents/motion/dredge.py b/src/spikeinterface/sortingcomponents/motion/dredge.py index 4db6bb1cb2..bfedd4e1ee 100644 --- a/src/spikeinterface/sortingcomponents/motion/dredge.py +++ b/src/spikeinterface/sortingcomponents/motion/dredge.py @@ -28,9 +28,14 @@ import numpy as np from tqdm.auto import trange -from .motion_utils import (Motion, get_spatial_bin_edges, get_spatial_windows, - get_window_domains, make_2d_motion_histogram, - scipy_conv1d) +from .motion_utils import ( + Motion, + get_spatial_bin_edges, + get_spatial_windows, + get_window_domains, + make_2d_motion_histogram, + scipy_conv1d, +) # simple class wrapper to be compliant with estimate_motion