@@ -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