@@ -45,8 +45,35 @@ 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 ("naive" , "tdc-peeler" , "circus" ,):
4949 method_kwargs ["noise_levels" ] = noise_levels
50+
51+ if method == "kilosort-matching" :
52+ from spikeinterface .sortingcomponents .peak_selection import select_peaks
53+ from spikeinterface .sortingcomponents .tools import extract_waveform_at_max_channel
54+ from spikeinterface .sortingcomponents .peak_detection import detect_peaks
55+
56+ peaks = detect_peaks (sorting_analyzer .recording , method = "locally_exclusive" , skip_after_n_peaks = 5000 )
57+ few_wfs = extract_waveform_at_max_channel (sorting_analyzer .recording , peaks , ms_before = 1 , ms_after = 2 )
58+
59+ wfs = few_wfs [:, :, 0 ]
60+ import numpy as np
61+
62+ n_components = 5
63+ from sklearn .cluster import KMeans
64+
65+ wfs /= np .linalg .norm (wfs , axis = 1 )[:, None ]
66+ model = KMeans (n_clusters = n_components , n_init = 10 ).fit (wfs )
67+ temporal_components = model .cluster_centers_
68+ temporal_components = temporal_components / np .linalg .norm (temporal_components [:, None ])
69+ temporal_components = temporal_components .astype (np .float32 )
70+ from sklearn .decomposition import TruncatedSVD
71+
72+ model = TruncatedSVD (n_components = n_components ).fit (wfs )
73+ spatial_components = model .components_ .astype (np .float32 )
74+ method_kwargs ["spatial_components" ] = spatial_components
75+ method_kwargs ["temporal_components" ] = temporal_components
76+
5077
5178 # method_kwargs["wobble"] = {
5279 # "templates": waveform_extractor.get_all_templates(),
@@ -91,5 +118,7 @@ def test_find_spikes_from_templates(method, sorting_analyzer):
91118 # method = "tdc-peeler"
92119 # method = "circus"
93120 # method = "circus-omp-svd"
94- method = "wobble"
121+ # method = "wobble"
122+ method = "kilosort-matching"
123+
95124 test_find_spikes_from_templates (method , sorting_analyzer )
0 commit comments