-
Notifications
You must be signed in to change notification settings - Fork 222
/
parameters.py
380 lines (340 loc) · 13.2 KB
/
parameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import numpy as np
# Format for parameter specification:
# parameter: {
# 'gui_name': text displayed next to edit box in GUI
# 'type': callable datatype for this parameter, like int or float.
# 'min': minimum value allowed (inclusive).
# 'max': maximum value allowed (inclusive).
# 'exclude': list of individual values to exclude from allowed range.
# 'default': default value used by gui and API
# 'step': which step of the pipeline the parameter is used in, from:
# ['data', 'preprocessing', 'spike detection',
# 'clustering', 'postprocessing']
# 'description': Explanation of parameter's use. Populates parameter help
# in GUI.
# }
MAIN_PARAMETERS = {
# NOTE: n_chan_bin must be specified by user when running through API
'n_chan_bin': {
'gui_name': 'number of channels', 'type': int, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 385, 'step': 'data',
'description':
"""
Total number of channels in the binary file, which may be different
from the number of channels containing ephys data. The value of this
parameter *must* be specified by the user, or `run_kilosort` will
raise a ValueError.
"""
},
'fs': {
'gui_name': 'sampling frequency', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 30000, 'step': 'data',
'description':
"""
Sampling frequency of probe.
"""
},
'batch_size': {
'gui_name': 'batch size', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 60000, 'step': 'data',
'description':
"""
Number of samples included in each batch of data.
"""
},
'nblocks': {
'gui_name': 'nblocks', 'type': int, 'min': 0, 'max': np.inf,
'exclude': [], 'default': 1, 'step': 'preprocessing',
'description':
"""
Number of non-overlapping blocks for drift correction
(additional nblocks-1 blocks are created in the overlaps).
"""
},
'Th_universal': {
'gui_name': 'Th (universal)', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 9, 'step': 'spike detection',
'description':
"""
Spike detection threshold for universal templates.
Th(1) in previous versions of Kilosort.
"""
},
'Th_learned': {
'gui_name': 'Th (learned)', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 8, 'step': 'spike detection',
'description':
"""
Spike detection threshold for learned templates.
Th(2) in previous versions of Kilosort.
"""
},
'tmin': {
'gui_name': 'tmin', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [], 'default': 0, 'step': 'data',
'description':
"""
Time in seconds when data used for sorting should begin. By default,
begins at 0 seconds.
"""
},
'tmax': {
'gui_name': 'tmax', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': np.inf, 'step': 'data',
'description':
"""
Time in seconds when data used for sorting should end. By default,
ends at the end of the recording.
"""
},
}
EXTRA_PARAMETERS = {
### DATA
'nt': {
'gui_name': 'nt', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 61, 'step': 'data',
'description':
"""
Number of samples per waveform. Also size of symmetric padding
for filtering.
"""
},
### PREPROCESSING
'artifact_threshold': {
'gui_name': 'artifact threshold', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [], 'default': np.inf, 'step': 'preprocessing',
'description':
"""
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).
"""
},
'nskip': {
'gui_name': 'nskip', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 25, 'step': 'preprocessing',
'description':
"""
Batch stride for computing whitening matrix.
"""
},
'whitening_range': {
'gui_name': 'whitening range', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 32, 'step': 'preprocessing',
'description':
"""
Number of nearby channels used to estimate the whitening matrix.
"""
},
'binning_depth': {
'gui_name': 'binning_depth', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 5, 'step': 'preprocessing',
'description':
"""
For drift correction, vertical bin size in microns used for
2D histogram.
"""
},
'sig_interp': {
'gui_name': 'sig_interp', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 20, 'step': 'preprocessing',
'description':
"""
Approximate spatial smoothness scale in units of microns.
"""
},
'drift_smoothing': {
'gui_name': 'drift smoothing', 'type': list, 'min': None, 'max': None,
'exclude': [], 'default': [0.5, 0.5, 0.5], 'step': 'preprocessing',
'description':
"""
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`.
"""
},
### SPIKE DETECTION
# NOTE: if left as None, will be set to `int(20 * settings['nt']/61)`
'nt0min': {
'gui_name': 'nt0min', 'type': int, 'min': 0, 'max': np.inf,
'exclude': [], 'default': None, 'step': 'spike detection',
'description':
"""
Sample index for aligning waveforms, so that their minimum
or maximum value happens here. Defaults to
`int(20 * settings['nt']/61)`.
"""
},
'dmin': {
'gui_name': 'dmin', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': None, 'step': 'spike detection',
'description':
"""
Vertical spacing of template centers used for spike detection,
in microns. Determined automatically by default.
"""
},
'dminx': {
'gui_name': 'dminx', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 32, 'step': 'spike detection',
'description':
"""
Horizontal spacing of template centers used for spike detection,
in microns. The default 32um should work well for Neuropixels 1 and
Neuropixels 2 probes. For other probe geometries, try setting this
to the median lateral distance between contacts to start.
"""
},
'min_template_size': {
'gui_name': 'min template size', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 10, 'step': 'spike detection',
'description':
"""
Standard deviation of the smallest, spatial envelope Gaussian used
for universal templates.
"""
},
'template_sizes': {
'gui_name': 'template sizes', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 5, 'step': 'spike detection',
'description':
"""
Number of sizes for universal spike templates (multiples of the
min_template_size).
"""
},
'nearest_chans': {
'gui_name': 'nearest chans', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 10, 'step': 'spike detection',
'description':
"""
Number of nearest channels to consider when finding local maxima
during spike detection.
"""
},
'nearest_templates': {
'gui_name': 'nearest templates', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 100, 'step': 'spike detection',
'description':
"""
Number of nearest spike template locations to consider when finding
local maxima during spike detection.
"""
},
'max_channel_distance': {
'gui_name': 'max channel distance', 'type': float, 'min': 1,
'max': np.inf, 'exclude': [], 'default': None, 'step': 'spike detection',
'description':
"""
Templates farther away than this from their nearest channel will
not be used. Also limits distance between compared channels during
clustering.
"""
},
'templates_from_data': {
'gui_name': 'templates from data', 'type': bool, 'min': None, 'max': None,
'exclude': [], 'default': True, 'step': 'spike detection',
'description':
"""
Indicates whether spike shapes used in universal templates should be
estimated from the data or loaded from the predefined templates.
"""
},
'n_templates': {
'gui_name': 'n templates', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 6, 'step': 'spike detection',
'description':
"""
Number of single-channel templates to use for the universal
templates (only used if templates_from_data is True).
"""
},
'n_pcs': {
'gui_name': 'n pcs', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 6, 'step': 'spike detection',
'description':
"""
Number of single-channel PCs to use for extracting spike features
(only used if templates_from_data is True).
"""
},
'Th_single_ch': {
'gui_name': 'Th (single channel)', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 6, 'step': 'spike detection',
'description':
"""
For single channel threshold crossings to compute universal-
templates. In units of whitened data standard deviations.
"""
},
### CLUSTERING
'acg_threshold': {
'gui_name': 'acg threshold', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 0.2, 'step': 'clustering',
'description':
"""
Fraction of refractory period violations that are allowed in the ACG
compared to baseline; used to assign "good" units.
"""
},
'ccg_threshold': {
'gui_name': 'ccg threshold', 'type': float, 'min': 0, 'max': np.inf,
'exclude': [0], 'default': 0.25, 'step': 'clustering',
'description':
"""
Fraction of refractory period violations that are allowed in the CCG
compared to baseline; used to perform splits and merges.
"""
},
'cluster_downsampling': {
'gui_name': 'cluster downsampling', 'type': int, 'min': 1, 'max': np.inf,
'exclude': [], 'default': 20, 'step': 'clustering',
'description':
"""
Inverse fraction of nodes used as landmarks during clustering
(can be 1, but that slows down the optimization).
"""
},
'x_centers': {
'gui_name': 'x centers', 'type': int, 'min': 1,
'max': np.inf, 'exclude': [], 'default': None, 'step': 'clustering',
'description':
"""
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.
"""
},
### POSTPROCESSING
'duplicate_spike_bins': {
'gui_name': 'duplicate spike bins', 'type': int, 'min': 0, 'max': np.inf,
'exclude': [], 'default': 7, 'step': 'postprocessing',
'description':
"""
Number of bins for which subsequent spikes from the same cluster are
assumed to be artifacts. A value of 0 disables this step.
"""
},
}
# Add default values to descriptions
for k, v in MAIN_PARAMETERS.items():
s = f"""
Default value: {str(v["default"])}
Min, max: ({str(v['min'])}, {str(v['max'])})
Type: {v['type'].__name__}
"""
v['description'] += s
for k, v in EXTRA_PARAMETERS.items():
s = f"""
Default value: {str(v["default"])}
Min, max: ({str(v['min'])}, {str(v['max'])})
Type: {v['type'].__name__}
"""
v['description'] += s
main_defaults = {k: v['default'] for k, v in MAIN_PARAMETERS.items()}
extra_defaults = {k: v['default'] for k, v in EXTRA_PARAMETERS.items()}
# In the format expected by `run_kilosort`
DEFAULT_SETTINGS = {**main_defaults, **extra_defaults}