You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/spikeinterface/sorters/external/kilosort4.py
+42-77Lines changed: 42 additions & 77 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
frompathlibimportPath
4
4
fromtypingimportUnion
5
+
importwarnings
5
6
frompackagingimportversion
6
7
7
8
@@ -22,95 +23,29 @@ class Kilosort4Sorter(BaseSorter):
22
23
gpu_capability="nvidia-optional"
23
24
requires_binary_data=False
24
25
25
-
_default_params= {
26
-
"batch_size": 60000,
27
-
"nblocks": 1,
28
-
"Th_universal": 9,
29
-
"Th_learned": 8,
26
+
_si_default_params= {
30
27
"do_CAR": True,
31
28
"invert_sign": False,
32
-
"nt": 61,
33
-
"shift": None,
34
-
"scale": None,
35
-
"artifact_threshold": None,
36
-
"nskip": 25,
37
-
"whitening_range": 32,
38
-
"highpass_cutoff": 300,
39
-
"binning_depth": 5,
40
-
"sig_interp": 20,
41
-
"drift_smoothing": [0.5, 0.5, 0.5],
42
-
"nt0min": None,
43
-
"dmin": None,
44
-
"dminx": 32,
45
-
"min_template_size": 10,
46
-
"template_sizes": 5,
47
-
"nearest_chans": 10,
48
-
"nearest_templates": 100,
49
-
"max_channel_distance": None,
50
-
"templates_from_data": True,
51
-
"n_templates": 6,
52
-
"n_pcs": 6,
53
-
"Th_single_ch": 6,
54
-
"acg_threshold": 0.2,
55
-
"ccg_threshold": 0.25,
56
-
"cluster_downsampling": 20,
57
-
"cluster_pcs": 64,
58
-
"x_centers": None,
59
-
"duplicate_spike_ms": 0.25,
60
-
"scaleproc": None,
29
+
"save_extra_vars": False,
61
30
"save_preprocessed_copy": False,
62
31
"torch_device": "auto",
63
32
"bad_channels": None,
64
33
"clear_cache": False,
65
-
"save_extra_vars": False,
66
34
"do_correction": True,
67
-
"keep_good_only": False,
68
35
"skip_kilosort_preprocessing": False,
36
+
"keep_good_only": False,
69
37
"use_binary_file": True,
70
38
"delete_recording_dat": True,
71
39
}
72
40
73
-
_params_description= {
74
-
"batch_size": "Number of samples included in each batch of data.",
75
-
"nblocks": "Number of non-overlapping blocks for drift correction (additional nblocks-1 blocks are created in the overlaps). Default value: 1.",
76
-
"Th_universal": "Spike detection threshold for universal templates. Th(1) in previous versions of Kilosort. Default value: 9.",
77
-
"Th_learned": "Spike detection threshold for learned templates. Th(2) in previous versions of Kilosort. Default value: 8.",
78
-
"do_CAR": "Whether to perform common average reference. Default value: True.",
79
-
"invert_sign": "Invert the sign of the data. Default value: False.",
80
-
"nt": "Number of samples per waveform. Also size of symmetric padding for filtering. Default value: 61.",
81
-
"shift": "Scalar shift to apply to data before all other operations. Default None.",
82
-
"scale": "Scaling factor to apply to data before all other operations. Default None.",
83
-
"artifact_threshold": "If a batch contains absolute values above this number, it will be zeroed out under the assumption that a recording artifact is present. By default, the threshold is infinite (so that no zeroing occurs). Default value: None.",
84
-
"nskip": "Batch stride for computing whitening matrix. Default value: 25.",
85
-
"whitening_range": "Number of nearby channels used to estimate the whitening matrix. Default value: 32.",
86
-
"highpass_cutoff": "High-pass filter cutoff frequency in Hz. Default value: 300.",
87
-
"binning_depth": "For drift correction, vertical bin size in microns used for 2D histogram. Default value: 5.",
88
-
"sig_interp": "For drift correction, sigma for interpolation (spatial standard deviation). Approximate smoothness scale in units of microns. Default value: 20.",
89
-
"drift_smoothing": "Amount of gaussian smoothing to apply to the spatiotemporal drift estimation, for x,y,time axes in units of registration blocks (for x,y axes) and batch size (for time axis). The x,y smoothing has no effect for `nblocks = 1`.",
90
-
"nt0min": "Sample index for aligning waveforms, so that their minimum or maximum value happens here. Default of 20. Default value: None.",
91
-
"dmin": "Vertical spacing of template centers used for spike detection, in microns. Determined automatically by default. Default value: None.",
92
-
"dminx": "Horizontal spacing of template centers used for spike detection, in microns. Default value: 32.",
93
-
"min_template_size": "Standard deviation of the smallest, spatial envelope Gaussian used for universal templates. Default value: 10.",
94
-
"template_sizes": "Number of sizes for universal spike templates (multiples of the min_template_size). Default value: 5.",
95
-
"nearest_chans": "Number of nearest channels to consider when finding local maxima during spike detection. Default value: 10.",
96
-
"nearest_templates": "Number of nearest spike template locations to consider when finding local maxima during spike detection. Default value: 100.",
97
-
"max_channel_distance": "Templates farther away than this from their nearest channel will not be used. Also limits distance between compared channels during clustering. Default value: None.",
98
-
"templates_from_data": "Indicates whether spike shapes used in universal templates should be estimated from the data or loaded from the predefined templates. Default value: True.",
99
-
"n_templates": "Number of single-channel templates to use for the universal templates (only used if templates_from_data is True). Default value: 6.",
100
-
"n_pcs": "Number of single-channel PCs to use for extracting spike features (only used if templates_from_data is True). Default value: 6.",
101
-
"Th_single_ch": "For single channel threshold crossings to compute universal- templates. In units of whitened data standard deviations. Default value: 6.",
102
-
"acg_threshold": 'Fraction of refractory period violations that are allowed in the ACG compared to baseline; used to assign "good" units. Default value: 0.2.',
103
-
"ccg_threshold": "Fraction of refractory period violations that are allowed in the CCG compared to baseline; used to perform splits and merges. Default value: 0.25.",
104
-
"cluster_downsampling": "Inverse fraction of nodes used as landmarks during clustering (can be 1, but that slows down the optimization). Default value: 20.",
105
-
"cluster_pcs": "Maximum number of spatiotemporal PC features used for clustering. Default value: 64.",
106
-
"x_centers": "Number of x-positions to use when determining center points for template groupings. If None, this will be determined automatically by finding peaks in channel density. For 2D array type probes, we recommend specifying this so that centers are placed every few hundred microns.",
107
-
"duplicate_spike_bins": "Number of bins for which subsequent spikes from the same cluster are assumed to be artifacts. A value of 0 disables this step. Default value: 7.",
108
-
"save_extra_vars": "If True, additional kwargs are saved to the output",
109
-
"scaleproc": "int16 scaling of whitened data, if None set to 200.",
110
-
"save_preprocessed_copy": "Save a pre-processed copy of the data (including drift correction) to temp_wh.dat in the results directory and format Phy output to use that copy of the data",
111
-
"torch_device": "Select the torch device auto/cuda/cpu",
112
-
"bad_channels": "A list of channel indices (rows in the binary file) that should not be included in sorting. Listing channels here is equivalent to excluding them from the probe dictionary.",
113
-
"clear_cache": "If True, force pytorch to free up memory reserved for its cache in between memory-intensive operations. Note that setting `clear_cache=True` is NOT recommended unless you encounter GPU out-of-memory errors, since this can result in slower sorting.",
41
+
_si_params_description= {
42
+
"do_CAR": "If True, common average reference is performed. Default is True. (run_kilosrt parameter)",
43
+
"invert_sign": "Invert the sign of the data. Default value: False. (run_kilosort parameter)",
44
+
"save_extra_vars": "If True, additional kwargs are saved to the output. Default is False. (run_kilosort parameter)",
45
+
"save_preprocessed_copy": "Save a pre-processed copy of the data (including drift correction) to temp_wh.dat in the results directory and format Phy output to use that copy of the data. (run_kilosort parameter)",
46
+
"torch_device": "Select the torch device auto/cuda/cpu. Default is 'auto'. (run_kilosort parameter)",
47
+
"bad_channels": "A list of channel indices (rows in the binary file) that should not be included in sorting. Listing channels here is equivalent to excluding them from the probe dictionary. (run_kilosort parameter)",
48
+
"clear_cache": "If True, force pytorch to free up memory reserved for its cache in between memory-intensive operations. Note that setting `clear_cache=True` is NOT recommended unless you encounter GPU out-of-memory errors, since this can result in slower sorting. (run_kilosort parameter)",
114
49
"do_correction": "If True, drift correction is performed. Default is True. (spikeinterface parameter)",
115
50
"skip_kilosort_preprocessing": "Can optionally skip the internal kilosort preprocessing. (spikeinterface parameter)",
116
51
"keep_good_only": "If True, only the units labeled as 'good' by Kilosort are returned in the output. (spikeinterface parameter)",
@@ -151,6 +86,36 @@ def get_sorter_version(cls):
151
86
"""kilosort.__version__ <4.0.10 is always '4'"""
152
87
returnimportlib_version("kilosort")
153
88
89
+
@classmethod
90
+
def_dynamic_params(cls):
91
+
ifcls.is_installed():
92
+
importkilosortasks
93
+
94
+
# we skip some parameters that are not relevant for the user
95
+
# n_chan_bin/sampling_frequency: retrieved from the recording
96
+
# tmin/tmax: same ase time/frame_slice in SpikeInterface
0 commit comments