Skip to content

Commit

Permalink
Merge pull request #2082 from samuelgarcia/tdc_2
Browse files Browse the repository at this point in the history
Update on tridesclous2
  • Loading branch information
yger authored Oct 7, 2023
2 parents 1dc77f3 + 375dbdd commit 490d74c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/spikeinterface/sorters/internal/tridesclous2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +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": 8000.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": {},
"svd": {"n_components": 6},
"clustering": {
"split_radius_um": 40.0,
Expand Down Expand Up @@ -154,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_before=0.5,
ms_after=1.5,
radius_um=100.0,
ms_before=ms_before,
ms_after=ms_after,
radius_um=radius_um,
)

model_folder_path = sorter_output_folder / "tsvd_model"
Expand Down Expand Up @@ -193,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,
Expand All @@ -205,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,
),
Expand Down Expand Up @@ -237,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,
)
Expand Down
7 changes: 5 additions & 2 deletions src/spikeinterface/sortingcomponents/clustering/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/spikeinterface/sortingcomponents/clustering/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 490d74c

Please sign in to comment.