From d373c05673b04354749e9d4ed9fc207f00824de3 Mon Sep 17 00:00:00 2001 From: Samuel Garcia Date: Fri, 6 Oct 2023 12:49:21 +0200 Subject: [PATCH 1/4] wip --- .../sorters/internal/tridesclous2.py | 16 +++++++++++----- .../sortingcomponents/clustering/split.py | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/sorters/internal/tridesclous2.py b/src/spikeinterface/sorters/internal/tridesclous2.py index e2f4812222..5a2664a45e 100644 --- a/src/spikeinterface/sorters/internal/tridesclous2.py +++ b/src/spikeinterface/sorters/internal/tridesclous2.py @@ -20,9 +20,11 @@ class Tridesclous2Sorter(ComponentsBasedSorter): _default_params = { "apply_preprocessing": True, "waveforms" : {"ms_before": 0.5, "ms_after": 1.5, }, - "filtering": {"freq_min": 300., "freq_max": 8000.0}, - "detection": {"peak_sign": "neg", "detect_threshold": 5, "exclude_sweep_ms": 1.5, "radius_um": 150.}, + "filtering": {"freq_min": 300., "freq_max": 12000.0}, + "detection": {"peak_sign": "neg", "detect_threshold": 5, + "exclude_sweep_ms": 1.5, "radius_um": 150.}, "selection": {"n_peaks_per_channel": 5000, "min_n_peaks": 20000}, + "features": {"radius_um": 120}, "svd": {"n_components": 6}, "clustering": { "split_radius_um": 40., @@ -35,7 +37,10 @@ class Tridesclous2Sorter(ComponentsBasedSorter): }, "matching": { "peak_shift_ms": 0.2, - "radius_um": 100. + # "radius_um": 100. + "num_peeler_loop": 3, + "num_template_try": 3, + }, "job_kwargs": {"n_jobs":-1}, "save_array": True, @@ -143,9 +148,10 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): # upsampling_um=5.0, # ) + radius = params["features"]["radius_um"] node3 = ExtractSparseWaveforms(recording, parents=[node0], return_output=True, - ms_before=0.5, - ms_after=1.5, + ms_before=ms_before, + ms_after=ms_after, radius_um=100.0, ) diff --git a/src/spikeinterface/sortingcomponents/clustering/split.py b/src/spikeinterface/sortingcomponents/clustering/split.py index 9836e9110f..b433a2d16d 100644 --- a/src/spikeinterface/sortingcomponents/clustering/split.py +++ b/src/spikeinterface/sortingcomponents/clustering/split.py @@ -192,6 +192,7 @@ def split( # target channel subset is done intersect local channels + neighbours local_chans = np.unique(peaks["channel_index"][peak_indices]) + target_channels = np.flatnonzero(np.all(neighbours_mask[local_chans, :], axis=0)) # TODO fix this a better way, this when cluster have too few overlapping channels @@ -204,6 +205,7 @@ def split( local_labels[dont_have_channels] = -2 kept = np.flatnonzero(~dont_have_channels) + if kept.size < min_size_split: return False, None From f5a42e7c51d5983738191d10896cf9fb500847c7 Mon Sep 17 00:00:00 2001 From: Samuel Garcia Date: Fri, 6 Oct 2023 13:41:13 +0200 Subject: [PATCH 2/4] wip --- src/spikeinterface/sorters/internal/tridesclous2.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/sorters/internal/tridesclous2.py b/src/spikeinterface/sorters/internal/tridesclous2.py index bfc01b897f..909a2d1cb3 100644 --- a/src/spikeinterface/sorters/internal/tridesclous2.py +++ b/src/spikeinterface/sorters/internal/tridesclous2.py @@ -29,11 +29,12 @@ class Tridesclous2Sorter(ComponentsBasedSorter): "waveforms": { "ms_before": 0.5, "ms_after": 1.5, + "radius_um": 120.0, }, "filtering": {"freq_min": 300.0, "freq_max": 12000.0}, "detection": {"peak_sign": "neg", "detect_threshold": 5, "exclude_sweep_ms": 1.5, "radius_um": 150.0}, "selection": {"n_peaks_per_channel": 5000, "min_n_peaks": 20000}, - "features": {"radius_um": 120}, + "features": {}, "svd": {"n_components": 6}, "clustering": { "split_radius_um": 40.0, @@ -155,13 +156,14 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): # upsampling_um=5.0, # ) + radius_um = params["waveforms"]["radius_um"] node3 = ExtractSparseWaveforms( recording, parents=[node0], return_output=True, - ms_beforems_before, + ms_before=ms_before, ms_after=ms_after, - radius_um=radius, + radius_um=radius_um, ) model_folder_path = sorter_output_folder / "tsvd_model" From f465e815c7de66958c659880b21085edd38f4216 Mon Sep 17 00:00:00 2001 From: Samuel Garcia Date: Fri, 6 Oct 2023 21:22:31 +0200 Subject: [PATCH 3/4] wip --- src/spikeinterface/sorters/internal/tridesclous2.py | 11 +++++++---- .../sortingcomponents/clustering/merge.py | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/sorters/internal/tridesclous2.py b/src/spikeinterface/sorters/internal/tridesclous2.py index 909a2d1cb3..ca1dfa1854 100644 --- a/src/spikeinterface/sorters/internal/tridesclous2.py +++ b/src/spikeinterface/sorters/internal/tridesclous2.py @@ -196,6 +196,8 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): original_labels = peaks["channel_index"] + min_cluster_size = 50 + post_split_label, split_count = split_clusters( original_labels, recording, @@ -208,8 +210,8 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): # feature_name="sparse_wfs", neighbours_mask=neighbours_mask, waveforms_sparse_mask=sparse_mask, - min_size_split=50, - min_cluster_size=50, + min_size_split=min_cluster_size, + min_cluster_size=min_cluster_size, min_samples=50, n_pca_features=3, ), @@ -240,9 +242,10 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): # criteria="percentile", # threshold_percentile=80., criteria="distrib_overlap", - threshold_overlap=0.4, + threshold_overlap=0.3, + min_cluster_size=min_cluster_size+1, # num_shift=0 - num_shift=2, + num_shift=5, ), **job_kwargs, ) diff --git a/src/spikeinterface/sortingcomponents/clustering/merge.py b/src/spikeinterface/sortingcomponents/clustering/merge.py index d892d0723a..45090452dc 100644 --- a/src/spikeinterface/sortingcomponents/clustering/merge.py +++ b/src/spikeinterface/sortingcomponents/clustering/merge.py @@ -398,6 +398,7 @@ def merge( threshold_diptest=0.5, threshold_percentile=80.0, threshold_overlap=0.4, + min_cluster_size=50, num_shift=2, ): if num_shift > 0: @@ -414,7 +415,7 @@ def merge( chans1 = np.unique(peaks["channel_index"][inds1]) target_chans1 = np.flatnonzero(np.all(waveforms_sparse_mask[chans1, :], axis=0)) - if inds0.size < 40 or inds1.size < 40: + if inds0.size < min_cluster_size or inds1.size < min_cluster_size: is_merge = False merge_value = 0 final_shift = 0 @@ -525,7 +526,9 @@ def merge( # DEBUG = True DEBUG = False - if DEBUG and is_merge: + # if DEBUG and is_merge: + # if DEBUG and (overlap > 0.1 and overlap <0.3): + if DEBUG: # if DEBUG and not is_merge: # if DEBUG and (overlap > 0.05 and overlap <0.25): # if label0 == 49 and label1== 65: From 1bbfe1622baf3250b362dae28c11b03c5dc712cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:24:58 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/sorters/internal/tridesclous2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/sorters/internal/tridesclous2.py b/src/spikeinterface/sorters/internal/tridesclous2.py index ca1dfa1854..054596e9b3 100644 --- a/src/spikeinterface/sorters/internal/tridesclous2.py +++ b/src/spikeinterface/sorters/internal/tridesclous2.py @@ -243,7 +243,7 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): # threshold_percentile=80., criteria="distrib_overlap", threshold_overlap=0.3, - min_cluster_size=min_cluster_size+1, + min_cluster_size=min_cluster_size + 1, # num_shift=0 num_shift=5, ),