Skip to content

Commit 050e5f9

Browse files
committed
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into add_distance_function
2 parents e9bbbb5 + d9ad31f commit 050e5f9

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/spikeinterface/sortingcomponents/matching/method_list.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@
1212
"circus-omp-svd": CircusOMPSVDPeeler,
1313
"wobble": WobbleMatch,
1414
}
15+
16+
try:
17+
# Kilosort licence (GPL 3) is forcing us to make and use an external package
18+
from spikeinterface_kilosort_components import KiloSortMatching
19+
20+
matching_methods["kilosort-matching"] = KiloSortMatching
21+
except ImportError:
22+
pass

src/spikeinterface/sortingcomponents/tests/test_template_matching.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,39 @@ def test_find_spikes_from_templates(method, sorting_analyzer):
4545
"templates": templates,
4646
}
4747
method_kwargs = {}
48-
if method in ("naive", "tdc-peeler", "circus", "tdc-peeler2"):
48+
if method in (
49+
"naive",
50+
"tdc-peeler",
51+
"circus",
52+
):
4953
method_kwargs["noise_levels"] = noise_levels
5054

55+
if method == "kilosort-matching":
56+
from spikeinterface.sortingcomponents.peak_selection import select_peaks
57+
from spikeinterface.sortingcomponents.tools import extract_waveform_at_max_channel
58+
from spikeinterface.sortingcomponents.peak_detection import detect_peaks
59+
60+
peaks = detect_peaks(sorting_analyzer.recording, method="locally_exclusive", skip_after_n_peaks=5000)
61+
few_wfs = extract_waveform_at_max_channel(sorting_analyzer.recording, peaks, ms_before=1, ms_after=2)
62+
63+
wfs = few_wfs[:, :, 0]
64+
import numpy as np
65+
66+
n_components = 5
67+
from sklearn.cluster import KMeans
68+
69+
wfs /= np.linalg.norm(wfs, axis=1)[:, None]
70+
model = KMeans(n_clusters=n_components, n_init=10).fit(wfs)
71+
temporal_components = model.cluster_centers_
72+
temporal_components = temporal_components / np.linalg.norm(temporal_components[:, None])
73+
temporal_components = temporal_components.astype(np.float32)
74+
from sklearn.decomposition import TruncatedSVD
75+
76+
model = TruncatedSVD(n_components=n_components).fit(wfs)
77+
spatial_components = model.components_.astype(np.float32)
78+
method_kwargs["spatial_components"] = spatial_components
79+
method_kwargs["temporal_components"] = temporal_components
80+
5181
# method_kwargs["wobble"] = {
5282
# "templates": waveform_extractor.get_all_templates(),
5383
# "nbefore": waveform_extractor.nbefore,
@@ -91,5 +121,7 @@ def test_find_spikes_from_templates(method, sorting_analyzer):
91121
# method = "tdc-peeler"
92122
# method = "circus"
93123
# method = "circus-omp-svd"
94-
method = "wobble"
124+
# method = "wobble"
125+
method = "kilosort-matching"
126+
95127
test_find_spikes_from_templates(method, sorting_analyzer)

0 commit comments

Comments
 (0)