UnitMatchPy 3.3.0__py3-none-any.whl → 3.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- UnitMatchPy/GUI.py +1 -1
- UnitMatchPy/default_params.py +6 -1
- UnitMatchPy/metric_functions.py +185 -10
- UnitMatchPy/overlord.py +4 -8
- UnitMatchPy/param_functions.py +8 -0
- UnitMatchPy/utils.py +171 -102
- {unitmatchpy-3.3.0.dist-info → unitmatchpy-3.4.0.dist-info}/METADATA +34 -21
- {unitmatchpy-3.3.0.dist-info → unitmatchpy-3.4.0.dist-info}/RECORD +11 -11
- {unitmatchpy-3.3.0.dist-info → unitmatchpy-3.4.0.dist-info}/WHEEL +1 -1
- {unitmatchpy-3.3.0.dist-info → unitmatchpy-3.4.0.dist-info}/licenses/LICENSE +0 -0
- {unitmatchpy-3.3.0.dist-info → unitmatchpy-3.4.0.dist-info}/top_level.txt +0 -0
UnitMatchPy/GUI.py
CHANGED
|
@@ -1792,7 +1792,7 @@ def plot_raw_waveforms(unit_a, unit_b, CV):
|
|
|
1792
1792
|
good_channels = nearest_channels(max_site, max_site_mean, channel_pos, clus_info, unit_a, CV[0])
|
|
1793
1793
|
|
|
1794
1794
|
min_x, min_y = channel_pos[session_no_a][good_channels[-2],[1,2]].squeeze()
|
|
1795
|
-
max_x,
|
|
1795
|
+
max_x, maxy = channel_pos[session_no_a][good_channels[1],[1,2]].squeeze()
|
|
1796
1796
|
delta_x = (max_x - min_x) / 2
|
|
1797
1797
|
delta_y = (maxy - min_y) / 18
|
|
1798
1798
|
#may want to change so it find this for both units and selects the most extreme arguments
|
UnitMatchPy/default_params.py
CHANGED
|
@@ -17,7 +17,6 @@ def get_default_param(param = None):
|
|
|
17
17
|
tmp = {'spike_width' : 82, # will automatically update after loading in the waveform
|
|
18
18
|
'waveidx' : np.arange(33,56), # what idxs cover the spike
|
|
19
19
|
'channel_radius' : 150, # the max distance channels which a unit will consider
|
|
20
|
-
'peak_loc' : 40, # were the spike peak will be aligned to
|
|
21
20
|
'max_dist' : 100, # max distance for possible matches
|
|
22
21
|
'neighbour_dist' : 50,
|
|
23
22
|
'stepsz' : 0.01, # size of of a step in probability distributions
|
|
@@ -27,6 +26,7 @@ def get_default_param(param = None):
|
|
|
27
26
|
'units_per_shank_thrs' : 15, # threshold for doing per shank drift correction
|
|
28
27
|
'match_threshold' : 0.5, # probability threshold to consider as a match
|
|
29
28
|
'curve_fit_maxfev' : 10000, # max evaluations for decay curve fitting
|
|
29
|
+
'chunk_size' : 500, # row-chunk size for pairwise metric computation
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
tmp['score_vector'] = np.arange(tmp['stepsz']/2 ,1 ,tmp['stepsz'])
|
|
@@ -38,4 +38,9 @@ def get_default_param(param = None):
|
|
|
38
38
|
else:
|
|
39
39
|
#Add default parameters to param dictionary, does not overwrite pre existing param values
|
|
40
40
|
out = tmp | param
|
|
41
|
+
|
|
42
|
+
# peak_loc always follows floor(spike_width / 2) unless the caller set it explicitly
|
|
43
|
+
if param is None or 'peak_loc' not in param:
|
|
44
|
+
out['peak_loc'] = int(np.floor(out['spike_width'] / 2))
|
|
45
|
+
|
|
41
46
|
return out
|
UnitMatchPy/metric_functions.py
CHANGED
|
@@ -252,6 +252,155 @@ def centroid_metrics(euclid_dist, param):
|
|
|
252
252
|
|
|
253
253
|
return centroid_dist, centroid_var
|
|
254
254
|
|
|
255
|
+
def get_euclidean_metrics_chunked(avg_waveform_per_tp_flip, param):
|
|
256
|
+
"""
|
|
257
|
+
Memory-efficient computation of Euclidean centroid metrics.
|
|
258
|
+
|
|
259
|
+
Fuses get_Euclidean_dist + centroid_metrics + peak-slice reduction into a single
|
|
260
|
+
pass that processes units in row-chunks, avoiding the full (N, waveidx, flips, N)
|
|
261
|
+
intermediate array. Produces identical results to the original three-step pipeline.
|
|
262
|
+
|
|
263
|
+
Parameters
|
|
264
|
+
----------
|
|
265
|
+
avg_waveform_per_tp_flip : ndarray (3, n_units, spike_width, 2, n_flips)
|
|
266
|
+
The average waveform per time point with the x axis flipped and not flipped
|
|
267
|
+
param : dict
|
|
268
|
+
The param dictionary. Uses 'chunk_size' (default 500) to control the
|
|
269
|
+
number of rows processed per iteration.
|
|
270
|
+
|
|
271
|
+
Returns
|
|
272
|
+
-------
|
|
273
|
+
centroid_dist : ndarray (n_units, n_units)
|
|
274
|
+
Rescaled centroid distance score at peak timepoint
|
|
275
|
+
centroid_var : ndarray (n_units, n_units)
|
|
276
|
+
Rescaled centroid variance score across timepoints
|
|
277
|
+
euclid_dist : ndarray (n_units, n_units)
|
|
278
|
+
Raw (unscaled) Euclidean distance at peak timepoint, minimized over flips.
|
|
279
|
+
Used downstream for distance-based pair filtering.
|
|
280
|
+
"""
|
|
281
|
+
waveidx = param['waveidx']
|
|
282
|
+
n_units = param['n_units']
|
|
283
|
+
max_dist = param['max_dist']
|
|
284
|
+
chunk_size = max(1, param.get('chunk_size', 500))
|
|
285
|
+
|
|
286
|
+
waveidx_arr = np.asarray(waveidx)
|
|
287
|
+
peak_loc = int(param['peak_loc'])
|
|
288
|
+
peak_matches = np.flatnonzero(waveidx_arr == peak_loc)
|
|
289
|
+
if peak_matches.size == 0:
|
|
290
|
+
raise ValueError("param['peak_loc'] must be present in param['waveidx'].")
|
|
291
|
+
peak_idx = int(peak_matches[0])
|
|
292
|
+
|
|
293
|
+
n_waveidx = len(waveidx)
|
|
294
|
+
ddof = 1 if n_waveidx > 1 else 0
|
|
295
|
+
|
|
296
|
+
# Extract relevant slices: (3, N, len_waveidx, n_flips)
|
|
297
|
+
data_cv0 = avg_waveform_per_tp_flip[:, :, waveidx, 0, :]
|
|
298
|
+
data_cv1 = avg_waveform_per_tp_flip[:, :, waveidx, 1, :]
|
|
299
|
+
|
|
300
|
+
# Preallocate (N, N) outputs
|
|
301
|
+
raw_centroid_dist = np.full((n_units, n_units), np.nan)
|
|
302
|
+
raw_centroid_var = np.full((n_units, n_units), np.nan)
|
|
303
|
+
|
|
304
|
+
for i_start in range(0, n_units, chunk_size):
|
|
305
|
+
i_end = min(i_start + chunk_size, n_units)
|
|
306
|
+
# (3, chunk, 1, waveidx, flips) - (3, 1, N, waveidx, flips) = (3, chunk, N, waveidx, flips)
|
|
307
|
+
diff = (data_cv0[:, i_start:i_end, np.newaxis, :, :]
|
|
308
|
+
- data_cv1[:, np.newaxis, :, :, :])
|
|
309
|
+
# Euclidean norm over spatial dims -> (chunk, N, waveidx, flips)
|
|
310
|
+
ed = np.linalg.norm(diff, axis=0)
|
|
311
|
+
del diff
|
|
312
|
+
|
|
313
|
+
# centroid_dist: distance at peak, min over flips
|
|
314
|
+
raw_centroid_dist[i_start:i_end, :] = np.nanmin(ed[:, :, peak_idx, :], axis=-1)
|
|
315
|
+
|
|
316
|
+
# centroid_var: variance over waveidx, min over flips
|
|
317
|
+
raw_centroid_var[i_start:i_end, :] = np.nanmin(
|
|
318
|
+
np.nanvar(ed, axis=2, ddof=ddof), axis=-1)
|
|
319
|
+
del ed
|
|
320
|
+
|
|
321
|
+
# euclid_dist is the raw centroid distance (before rescaling)
|
|
322
|
+
euclid_dist = raw_centroid_dist.copy()
|
|
323
|
+
|
|
324
|
+
# Rescale centroid_dist using max_dist (same as centroid_metrics)
|
|
325
|
+
min_cd = np.nanmin(raw_centroid_dist)
|
|
326
|
+
denom = max_dist - min_cd
|
|
327
|
+
if not np.isfinite(denom) or denom <= 0:
|
|
328
|
+
centroid_dist = np.zeros_like(raw_centroid_dist)
|
|
329
|
+
else:
|
|
330
|
+
centroid_dist = 1 - ((raw_centroid_dist - min_cd) / denom)
|
|
331
|
+
centroid_dist = np.clip(centroid_dist, 0, 1)
|
|
332
|
+
centroid_dist[np.isnan(centroid_dist)] = 0
|
|
333
|
+
|
|
334
|
+
# Rescale centroid_var (same as centroid_metrics)
|
|
335
|
+
centroid_var = np.sqrt(raw_centroid_var)
|
|
336
|
+
centroid_var = re_scale(centroid_var)
|
|
337
|
+
centroid_var[np.isnan(centroid_var)] = 0
|
|
338
|
+
|
|
339
|
+
return centroid_dist, centroid_var, euclid_dist
|
|
340
|
+
|
|
341
|
+
def get_recentered_metrics_chunked(avg_waveform_per_tp_flip, avg_centroid, param):
|
|
342
|
+
"""
|
|
343
|
+
Memory-efficient computation of recentered centroid distance metric.
|
|
344
|
+
|
|
345
|
+
Fuses get_recentered_euclidean_dist + recentered_metrics into a single pass.
|
|
346
|
+
First subtracts each unit's average centroid position from its per-timepoint
|
|
347
|
+
waveform trajectory, then computes pairwise Euclidean distances in row-chunks
|
|
348
|
+
to avoid the full (N, waveidx, flips, N) intermediate array.
|
|
349
|
+
|
|
350
|
+
Parameters
|
|
351
|
+
----------
|
|
352
|
+
avg_waveform_per_tp_flip : ndarray (3, n_units, spike_width, 2, n_flips)
|
|
353
|
+
The average waveform per time point with the x axis flipped and not flipped
|
|
354
|
+
avg_centroid : ndarray (3, n_units, 2)
|
|
355
|
+
The average spatial location for each unit, subtracted before distance
|
|
356
|
+
computation to isolate trajectory shape from absolute position.
|
|
357
|
+
param : dict
|
|
358
|
+
The param dictionary. Uses 'chunk_size' (default 500) to control the
|
|
359
|
+
number of rows processed per iteration.
|
|
360
|
+
|
|
361
|
+
Returns
|
|
362
|
+
-------
|
|
363
|
+
centroid_dist_recentered : ndarray (n_units, n_units)
|
|
364
|
+
Rescaled recentered centroid distance score
|
|
365
|
+
"""
|
|
366
|
+
waveidx = param['waveidx']
|
|
367
|
+
n_units = param['n_units']
|
|
368
|
+
spike_width = param['spike_width']
|
|
369
|
+
chunk_size = max(1, param.get('chunk_size', 500))
|
|
370
|
+
|
|
371
|
+
# Recenter: subtract avg_centroid from each timepoint (per-unit, no N×N)
|
|
372
|
+
avg_centroid_broadcast = np.tile(
|
|
373
|
+
np.expand_dims(avg_centroid, axis=(3, 4)), (1, 1, 1, spike_width, 2))
|
|
374
|
+
recentered = np.swapaxes(
|
|
375
|
+
np.swapaxes(avg_waveform_per_tp_flip, 2, 3) - avg_centroid_broadcast, 2, 3)
|
|
376
|
+
del avg_centroid_broadcast
|
|
377
|
+
|
|
378
|
+
# Extract CV halves at waveidx: (3, N, len_waveidx, n_flips)
|
|
379
|
+
rc_cv0 = recentered[:, :, waveidx, 0, :]
|
|
380
|
+
rc_cv1 = recentered[:, :, waveidx, 1, :]
|
|
381
|
+
del recentered
|
|
382
|
+
|
|
383
|
+
raw_result = np.full((n_units, n_units), np.nan)
|
|
384
|
+
|
|
385
|
+
for i_start in range(0, n_units, chunk_size):
|
|
386
|
+
i_end = min(i_start + chunk_size, n_units)
|
|
387
|
+
# (3, chunk, 1, waveidx, flips) - (3, 1, N, waveidx, flips) = (3, chunk, N, waveidx, flips)
|
|
388
|
+
diff = (rc_cv0[:, i_start:i_end, np.newaxis, :, :]
|
|
389
|
+
- rc_cv1[:, np.newaxis, :, :, :])
|
|
390
|
+
# Euclidean norm over spatial dims -> (chunk, N, waveidx, flips)
|
|
391
|
+
ed = np.linalg.norm(diff, axis=0)
|
|
392
|
+
del diff
|
|
393
|
+
|
|
394
|
+
# recentered_metrics: mean over waveidx, then min over flips
|
|
395
|
+
raw_result[i_start:i_end, :] = np.nanmin(
|
|
396
|
+
np.nanmean(ed, axis=2), axis=-1)
|
|
397
|
+
del ed
|
|
398
|
+
|
|
399
|
+
centroid_dist_recentered = re_scale(raw_result)
|
|
400
|
+
centroid_dist_recentered[np.isnan(centroid_dist_recentered)] = 0
|
|
401
|
+
|
|
402
|
+
return centroid_dist_recentered
|
|
403
|
+
|
|
255
404
|
def get_recentered_euclidean_dist(avg_waveform_per_tp_flip, avg_centroid, param):
|
|
256
405
|
"""
|
|
257
406
|
Find a Euclidean distance where the location per time has been centered around the average position
|
|
@@ -418,17 +567,39 @@ def get_threshold(total_score, within_session, euclid_dist, param, is_first_pass
|
|
|
418
567
|
tmp[within_session == 1] = np.nan
|
|
419
568
|
|
|
420
569
|
hd, __ = np.histogram(np.diag(tmp), Bins)
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
570
|
+
n_units = int(param['n_units'])
|
|
571
|
+
hd = hd / max(n_units, 1)
|
|
572
|
+
|
|
573
|
+
off_diag = tmp - tmp * np.eye(n_units)
|
|
574
|
+
hnd, __ = np.histogram(off_diag, Bins)
|
|
575
|
+
hnd_denom = np.nansum(off_diag)
|
|
576
|
+
if (not np.isfinite(hnd_denom)) or hnd_denom == 0:
|
|
577
|
+
hnd = np.zeros_like(hnd, dtype=float)
|
|
578
|
+
else:
|
|
579
|
+
hnd = hnd / hnd_denom
|
|
424
580
|
hp, __ = np.histogram(tmp, Bins)
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
581
|
+
hp_denom = np.nansum(tmp)
|
|
582
|
+
if (not np.isfinite(hp_denom)) or hp_denom == 0:
|
|
583
|
+
hp = np.zeros_like(hp, dtype=float)
|
|
584
|
+
else:
|
|
585
|
+
hp = hp / hp_denom
|
|
586
|
+
|
|
587
|
+
hd_s = pf.smooth(hd, 3)
|
|
588
|
+
hnd_s = pf.smooth(hnd, 3)
|
|
589
|
+
|
|
590
|
+
# Guard against edge cases where the histograms (or their normalisations) yield no crossing.
|
|
591
|
+
min_len = min(score_vector.shape[0], hd_s.shape[0], hnd_s.shape[0])
|
|
592
|
+
score_vector_use = score_vector[:min_len]
|
|
593
|
+
mask = (hd_s[:min_len] > hnd_s[:min_len]) & (score_vector_use > 0.6)
|
|
594
|
+
crossing_idx = np.flatnonzero(mask)
|
|
595
|
+
if crossing_idx.size == 0:
|
|
596
|
+
thrs_opt = 0.6
|
|
597
|
+
else:
|
|
598
|
+
thrs_opt = float(score_vector_use[crossing_idx[0]])
|
|
428
599
|
# if ThrsOpt.size == 0:
|
|
429
600
|
# ThrsOpt = 0.6 # give default threshold if above doestn return value
|
|
430
601
|
# fit tmp to a normal ditn
|
|
431
|
-
fit = tmp[
|
|
602
|
+
fit = tmp[(~np.isnan(tmp)) & (tmp < thrs_opt)]
|
|
432
603
|
muw = np.mean(fit)
|
|
433
604
|
stdw = np.std(fit)
|
|
434
605
|
|
|
@@ -442,8 +613,12 @@ def get_threshold(total_score, within_session, euclid_dist, param, is_first_pass
|
|
|
442
613
|
tmp[within_session == 0] = np.nan
|
|
443
614
|
|
|
444
615
|
ha, __ = np.histogram(tmp, Bins)
|
|
445
|
-
|
|
446
|
-
|
|
616
|
+
ha_denom = np.nansum(tmp)
|
|
617
|
+
if (not np.isfinite(ha_denom)) or ha_denom == 0:
|
|
618
|
+
ha = np.zeros_like(ha, dtype=float)
|
|
619
|
+
else:
|
|
620
|
+
ha = ha / ha_denom
|
|
621
|
+
fit = tmp[(~np.isnan(tmp)) & (tmp < thrs_opt)]
|
|
447
622
|
mua = np.mean(fit)
|
|
448
623
|
stda = np.std(fit)
|
|
449
624
|
|
|
@@ -451,7 +626,7 @@ def get_threshold(total_score, within_session, euclid_dist, param, is_first_pass
|
|
|
451
626
|
# for first pass only (i.e before drift correction)
|
|
452
627
|
#This is to decrease the threshold for the first pass so that the threshold is lowered
|
|
453
628
|
# as without drift correction even matches should have a lower total score
|
|
454
|
-
if
|
|
629
|
+
if np.isfinite(mua) and np.isfinite(muw) and (mua < muw):
|
|
455
630
|
thrs_opt = thrs_opt - np.abs(muw - mua)
|
|
456
631
|
|
|
457
632
|
return thrs_opt
|
UnitMatchPy/overlord.py
CHANGED
|
@@ -83,19 +83,15 @@ def extract_metric_scores(extracted_wave_properties, session_switch, within_sess
|
|
|
83
83
|
#effected by drift
|
|
84
84
|
for i in range(niter):
|
|
85
85
|
avg_waveform_per_tp_flip = mf.flip_dim(avg_waveform_per_tp, param)
|
|
86
|
-
euclid_dist = mf.get_Euclidean_dist(avg_waveform_per_tp_flip, param)
|
|
87
86
|
|
|
88
|
-
centroid_dist, centroid_var = mf.
|
|
87
|
+
centroid_dist, centroid_var, euclid_dist = mf.get_euclidean_metrics_chunked(
|
|
88
|
+
avg_waveform_per_tp_flip, param)
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
centroid_dist_recentered = mf.get_recentered_metrics_chunked(
|
|
91
|
+
avg_waveform_per_tp_flip, avg_centroid, param)
|
|
91
92
|
|
|
92
|
-
centroid_dist_recentered = mf.recentered_metrics(euclid_dist_rc)
|
|
93
93
|
traj_angle_score, traj_dist_score = mf.dist_angle(avg_waveform_per_tp_flip, param)
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
# Average Euc Dist
|
|
97
|
-
euclid_dist = np.nanmin(euclid_dist[:,param['peak_loc'] - param['waveidx'] == 0, :,:].squeeze(), axis = 1 )
|
|
98
|
-
|
|
99
95
|
# TotalScore
|
|
100
96
|
include_these_pairs = np.argwhere( euclid_dist < param['max_dist']) #array indices of pairs to include
|
|
101
97
|
include_these_pairs_idx = np.zeros_like(euclid_dist)
|
UnitMatchPy/param_functions.py
CHANGED
|
@@ -196,6 +196,14 @@ def decay_and_average_waveform(waveform, channel_pos, good_idx, max_site, max_si
|
|
|
196
196
|
tmp_amp = tmp_amp[dist_to_max_chan != 0]
|
|
197
197
|
dist_to_max_chan = dist_to_max_chan[dist_to_max_chan != 0]
|
|
198
198
|
|
|
199
|
+
if len(tmp_amp) == 0:
|
|
200
|
+
# Only the max channel itself is within the radius — no spatial decay can be estimated.
|
|
201
|
+
# Fall back to channel_radius so downstream code has a safe d_10 value.
|
|
202
|
+
spatial_decay_fit[i, cv] = np.nan
|
|
203
|
+
spatial_decay[i, cv] = np.nan
|
|
204
|
+
d_10[i, cv] = channel_radius
|
|
205
|
+
continue
|
|
206
|
+
|
|
199
207
|
# there is variation in how different programming languages/options fit to a curve
|
|
200
208
|
popt, pcurve = sp.optimize.curve_fit(
|
|
201
209
|
exponential_func,
|
UnitMatchPy/utils.py
CHANGED
|
@@ -99,6 +99,48 @@ def get_within_session(session_id, param):
|
|
|
99
99
|
|
|
100
100
|
return within_session
|
|
101
101
|
|
|
102
|
+
def filter_units_by_index(waveform, session_id, session_switch, good_units, kept_idx, param):
|
|
103
|
+
"""
|
|
104
|
+
Re-synchronise all per-unit data structures after some units have been dropped
|
|
105
|
+
(e.g. by get_snippets filtering bad waveforms).
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
waveform : ndarray (n_units, spike_width, n_channels, cv)
|
|
110
|
+
session_id : ndarray (n_units,)
|
|
111
|
+
session_switch : ndarray (n_sessions+1,)
|
|
112
|
+
good_units : list of per-session cluster-ID arrays
|
|
113
|
+
kept_idx : ndarray of int — indices into the original n_units dimension that were kept
|
|
114
|
+
param : dict
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
waveform, session_id, session_switch, within_session, good_units, param — all filtered
|
|
119
|
+
"""
|
|
120
|
+
n_dropped = len(session_id) - len(kept_idx)
|
|
121
|
+
if n_dropped > 0:
|
|
122
|
+
print(f"Filtering {n_dropped} unit(s) that were rejected by get_snippets.")
|
|
123
|
+
|
|
124
|
+
new_waveform = waveform[kept_idx]
|
|
125
|
+
n_sessions = param['n_sessions']
|
|
126
|
+
|
|
127
|
+
new_good_units = []
|
|
128
|
+
for s in range(n_sessions):
|
|
129
|
+
start, end = int(session_switch[s]), int(session_switch[s + 1])
|
|
130
|
+
in_session = kept_idx[(kept_idx >= start) & (kept_idx < end)] - start
|
|
131
|
+
new_good_units.append(good_units[s][in_session])
|
|
132
|
+
|
|
133
|
+
n_units_per_session = np.array([len(g) for g in new_good_units])
|
|
134
|
+
n_units, new_session_id, new_session_switch, _ = get_session_data(n_units_per_session)
|
|
135
|
+
|
|
136
|
+
param['n_units'] = n_units
|
|
137
|
+
param['good_units'] = new_good_units
|
|
138
|
+
param['n_channels'] = new_waveform.shape[2]
|
|
139
|
+
new_within_session = get_within_session(new_session_id, param)
|
|
140
|
+
|
|
141
|
+
return new_waveform, new_session_id, new_session_switch, new_within_session, new_good_units, param
|
|
142
|
+
|
|
143
|
+
|
|
102
144
|
def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=True):
|
|
103
145
|
if len(wave_paths) == len(unit_label_paths):
|
|
104
146
|
n_sessions = len(wave_paths)
|
|
@@ -125,8 +167,11 @@ def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=Tru
|
|
|
125
167
|
all_units.append(unit_label[:, 0])
|
|
126
168
|
|
|
127
169
|
waveforms = []
|
|
170
|
+
successful_sessions = []
|
|
128
171
|
if good_units_only:
|
|
129
172
|
for ls in range(len(wave_paths)):
|
|
173
|
+
tmp_waveform = None
|
|
174
|
+
tmp = None
|
|
130
175
|
try:
|
|
131
176
|
p_file = os.path.join(wave_paths[ls], f'Unit{int(good_units[ls][0].squeeze())}_RawSpikes.npy')
|
|
132
177
|
tmp = np.load(p_file)
|
|
@@ -136,6 +181,7 @@ def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=Tru
|
|
|
136
181
|
p_file_good = os.path.join(wave_paths[ls], f'Unit{int(good_units[ls][i].squeeze())}_RawSpikes.npy')
|
|
137
182
|
tmp_waveform[i] = np.load(p_file_good)
|
|
138
183
|
waveforms.append(tmp_waveform)
|
|
184
|
+
successful_sessions.append(ls)
|
|
139
185
|
except Exception as e:
|
|
140
186
|
print(f'Error loading waveform for session {ls}: {e}')
|
|
141
187
|
finally:
|
|
@@ -143,6 +189,8 @@ def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=Tru
|
|
|
143
189
|
del tmp
|
|
144
190
|
else:
|
|
145
191
|
for ls in range(len(wave_paths)):
|
|
192
|
+
tmp_waveform = None
|
|
193
|
+
tmp = None
|
|
146
194
|
try:
|
|
147
195
|
p_file = os.path.join(wave_paths[ls], f'Unit0_RawSpikes.npy')
|
|
148
196
|
tmp = np.load(p_file)
|
|
@@ -152,6 +200,7 @@ def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=Tru
|
|
|
152
200
|
p_file_good = os.path.join(wave_paths[ls], f'Unit{i}_RawSpikes.npy')
|
|
153
201
|
tmp_waveform[i] = np.load(p_file_good)
|
|
154
202
|
waveforms.append(tmp_waveform)
|
|
203
|
+
successful_sessions.append(ls)
|
|
155
204
|
print(f'UnitMatch is treating all the units as good and including all units from {wave_paths[ls]}, we recommended using curated data!')
|
|
156
205
|
except Exception as e:
|
|
157
206
|
print(f'Error loading waveform for session {ls}: {e}')
|
|
@@ -159,6 +208,13 @@ def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=Tru
|
|
|
159
208
|
del tmp_waveform
|
|
160
209
|
del tmp
|
|
161
210
|
|
|
211
|
+
if len(successful_sessions) < n_sessions:
|
|
212
|
+
failed = [i for i in range(n_sessions) if i not in successful_sessions]
|
|
213
|
+
print(f'Warning: failed to load waveforms for {len(failed)} session(s): {failed}. Excluding from analysis.')
|
|
214
|
+
good_units = [good_units[i] for i in successful_sessions]
|
|
215
|
+
n_units_per_session_all = [n_units_per_session_all[i] for i in successful_sessions]
|
|
216
|
+
n_sessions = len(successful_sessions)
|
|
217
|
+
|
|
162
218
|
n_units_per_session = np.zeros(n_sessions, dtype='int')
|
|
163
219
|
waveform = np.array([])
|
|
164
220
|
|
|
@@ -175,10 +231,13 @@ def load_good_waveforms(wave_paths, unit_label_paths, param, good_units_only=Tru
|
|
|
175
231
|
param['n_channels'] = waveform.shape[2]
|
|
176
232
|
param['n_units_per_session'] = n_units_per_session_all
|
|
177
233
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
234
|
+
actual_width = waveform.shape[1]
|
|
235
|
+
if param['spike_width'] != actual_width:
|
|
236
|
+
print(f"Warning: loaded waveform spike_width ({actual_width}) does not match "
|
|
237
|
+
f"param['spike_width'] ({param['spike_width']}). Updating to match data.")
|
|
238
|
+
param['spike_width'] = actual_width
|
|
239
|
+
param['peak_loc'] = int(np.floor(actual_width / 2))
|
|
240
|
+
param['waveidx'] = np.arange(param['peak_loc'] - 8, param['peak_loc'] + 15, dtype=int)
|
|
182
241
|
|
|
183
242
|
return waveform, session_id, session_switch, within_session, good_units, param
|
|
184
243
|
|
|
@@ -385,121 +444,114 @@ def isin_2d(test_arr, parent_arr):
|
|
|
385
444
|
|
|
386
445
|
def fill_missing_pos(KS_dir, n_channels):
|
|
387
446
|
"""
|
|
388
|
-
KiloSort
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
447
|
+
KiloSort may not include channel positions for inactive channels (e.g. channels
|
|
448
|
+
outside the brain). UnitMatch requires the full channel_pos array, so this
|
|
449
|
+
function reconstructs positions for the missing hardware channels.
|
|
450
|
+
|
|
451
|
+
Strategy: channel_map.npy maps the N_active entries in channel_positions.npy to
|
|
452
|
+
their hardware-channel indices (0 … n_channels-1). For each x-column found in
|
|
453
|
+
the known positions a linear model y = slope * hw_channel_index + intercept is
|
|
454
|
+
fit using the known (hw_index, y) pairs. Missing channels are then assigned to
|
|
455
|
+
the column given by hw_index % n_cols and their y is predicted by that model.
|
|
456
|
+
This correctly handles any number of missing channels, from a single gap to the
|
|
457
|
+
majority of the probe being outside the brain.
|
|
392
458
|
|
|
393
459
|
Parameters
|
|
394
460
|
----------
|
|
395
461
|
KS_dir : str
|
|
396
|
-
|
|
462
|
+
Path to the KiloSort output directory.
|
|
397
463
|
n_channels : int
|
|
398
|
-
|
|
464
|
+
Total number of hardware channels (waveform array dimension).
|
|
399
465
|
|
|
400
466
|
Returns
|
|
401
467
|
-------
|
|
402
|
-
ndarray
|
|
403
|
-
|
|
468
|
+
ndarray, shape (n_channels, 2)
|
|
469
|
+
Full channel_pos array; known positions are preserved exactly.
|
|
404
470
|
"""
|
|
405
|
-
print('The channel_positions.npy file does not match with the raw waveforms
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
pos = np.load(path_tmp)
|
|
409
|
-
|
|
410
|
-
path_tmp = os.path.join(KS_dir, 'channel_map.npy')
|
|
411
|
-
channel_map = np.load(path_tmp).squeeze()
|
|
412
|
-
|
|
413
|
-
channel_pos = np.full((n_channels,2), np.nan)
|
|
414
|
-
channel_pos[channel_map,:] = pos
|
|
415
|
-
|
|
416
|
-
channel_pos_new = []
|
|
417
|
-
#get the unique x positions
|
|
418
|
-
x_unique = np.unique(channel_pos[:,0])
|
|
419
|
-
x_unique = x_unique[~np.isnan(x_unique)]
|
|
420
|
-
|
|
421
|
-
#go through each column
|
|
422
|
-
for x in x_unique:
|
|
423
|
-
#get the known y-values for that column
|
|
424
|
-
y_column = channel_pos[np.argwhere(channel_pos[:,0] == x), 1].squeeze()
|
|
471
|
+
print('The channel_positions.npy file does not match with the raw waveforms. '
|
|
472
|
+
'Attempting to fill in missing positions using probe geometry inference. '
|
|
473
|
+
'Please verify channel_positions and RawWaveforms shapes afterwards.')
|
|
425
474
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
same_y_pattern = channel_pos[np.in1d(channel_pos[:,0], same_x_pattern), 1]
|
|
475
|
+
pos = np.load(os.path.join(KS_dir, 'channel_positions.npy'))
|
|
476
|
+
channel_map = np.load(os.path.join(KS_dir, 'channel_map.npy')).squeeze()
|
|
429
477
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
478
|
+
# Place known positions at their correct hardware-channel indices.
|
|
479
|
+
channel_pos = np.full((n_channels, 2), np.nan)
|
|
480
|
+
channel_pos[channel_map, :] = pos
|
|
433
481
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
ymax = np.max(same_y_pattern).astype(int)
|
|
437
|
-
ypos = np.arange(ymin, ymax+y_steps, y_steps)
|
|
438
|
-
|
|
439
|
-
channel_pos_column = np.stack((np.full_like(ypos,x), ypos)).T
|
|
440
|
-
channel_pos_new.append(channel_pos_column)
|
|
441
|
-
|
|
442
|
-
if pos.shape[0] == n_channels - 1:
|
|
482
|
+
nan_mask = np.isnan(channel_pos[:, 0])
|
|
483
|
+
if not np.any(nan_mask):
|
|
443
484
|
print('Likely to be correctly filled')
|
|
444
|
-
missed_pos_idx = np.argwhere(isin_2d(np.vstack(channel_pos_new), pos) == False)
|
|
445
|
-
channel_pos[np.isnan(channel_pos)[:,0],:] = np.vstack(channel_pos_new)[missed_pos_idx]
|
|
446
485
|
return channel_pos
|
|
447
486
|
|
|
448
|
-
|
|
449
|
-
#
|
|
450
|
-
|
|
451
|
-
#
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
487
|
+
# --- Geometry inference via per-column linear regression ---
|
|
488
|
+
# Assumes channels fill x-columns in round-robin order (ch % n_cols → column),
|
|
489
|
+
# which holds for all Neuropixels probes. For probes with a different layout the
|
|
490
|
+
# validation step below will detect the mismatch and fall back to off-probe
|
|
491
|
+
# placeholders rather than silently returning wrong positions.
|
|
492
|
+
x_unique = np.unique(pos[:, 0])
|
|
493
|
+
n_cols = len(x_unique)
|
|
494
|
+
|
|
495
|
+
# Estimate a global y-step as a fallback for columns with only one known channel.
|
|
496
|
+
all_y_diffs = []
|
|
497
|
+
for x in x_unique:
|
|
498
|
+
yj = np.sort(pos[pos[:, 0] == x, 1])
|
|
499
|
+
if len(yj) > 1:
|
|
500
|
+
all_y_diffs.extend(np.diff(yj).tolist())
|
|
501
|
+
y_step_global = float(np.median(all_y_diffs)) if all_y_diffs else 20.0
|
|
502
|
+
|
|
503
|
+
col_models = {} # col_index -> (slope, intercept)
|
|
504
|
+
for col_i, x in enumerate(x_unique):
|
|
505
|
+
col_mask = pos[:, 0] == x
|
|
506
|
+
ch_indices = channel_map[col_mask].astype(float)
|
|
507
|
+
y_vals = pos[col_mask, 1].astype(float)
|
|
508
|
+
if len(ch_indices) >= 2:
|
|
509
|
+
slope, intercept = np.polyfit(ch_indices, y_vals, 1)
|
|
510
|
+
# Validate: max residual must be well below one y-step.
|
|
511
|
+
residuals = np.abs(np.polyval([slope, intercept], ch_indices) - y_vals)
|
|
512
|
+
if np.max(residuals) > 0.4 * y_step_global:
|
|
513
|
+
# Column assignment by ch % n_cols is inconsistent with the known
|
|
514
|
+
# positions — this probe does not use round-robin column ordering.
|
|
515
|
+
print('Warning: probe geometry does not follow a round-robin column '
|
|
516
|
+
'pattern (max fit residual {:.1f} µm). Cannot infer positions '
|
|
517
|
+
'for inactive channels; off-probe placeholders will be used. '
|
|
518
|
+
'Supply the full channel_positions manually if needed.'.format(
|
|
519
|
+
float(np.max(residuals))))
|
|
520
|
+
x_fill = float(np.nanmedian(channel_pos[:, 0]))
|
|
521
|
+
y_fill = float(np.nanmin(channel_pos[:, 1])) - 10000.0
|
|
522
|
+
channel_pos[nan_mask] = [x_fill, y_fill]
|
|
523
|
+
return channel_pos
|
|
524
|
+
else:
|
|
525
|
+
# Single known channel: use global y-step scaled by column stride.
|
|
526
|
+
slope = y_step_global / n_cols
|
|
527
|
+
intercept = y_vals[0] - slope * ch_indices[0]
|
|
528
|
+
col_models[col_i] = (slope, intercept)
|
|
529
|
+
|
|
530
|
+
# Assign each inactive hardware channel to its column (ch % n_cols) and
|
|
531
|
+
# predict its y position from the column's linear model.
|
|
532
|
+
for ch_idx in np.where(nan_mask)[0]:
|
|
533
|
+
col_i = ch_idx % n_cols
|
|
534
|
+
slope, intercept = col_models[col_i]
|
|
535
|
+
channel_pos[ch_idx] = [x_unique[col_i], slope * ch_idx + intercept]
|
|
536
|
+
|
|
537
|
+
# Safety net: if any positions are still NaN (unexpected column layout),
|
|
538
|
+
# place them well off-probe so they do not interfere with active channels.
|
|
539
|
+
still_nan = np.isnan(channel_pos[:, 0])
|
|
540
|
+
if np.any(still_nan):
|
|
541
|
+
x_fill = float(np.nanmedian(channel_pos[:, 0]))
|
|
542
|
+
y_fill = float(np.nanmin(channel_pos[:, 1])) - 10000.0
|
|
543
|
+
channel_pos[still_nan] = [x_fill, y_fill]
|
|
544
|
+
print('Warning: could not infer positions for {:d} inactive channels; '
|
|
545
|
+
'off-probe placeholder used.'.format(int(np.sum(still_nan))))
|
|
546
|
+
|
|
547
|
+
if np.allclose(channel_pos[channel_map], pos):
|
|
495
548
|
print('Likely to be correctly filled')
|
|
496
|
-
return channel_pos_fill
|
|
497
549
|
else:
|
|
498
|
-
print('Error in filling channel positions, please fill in manually \n
|
|
499
|
-
|
|
500
|
-
|
|
550
|
+
print('Error in filling channel positions, please fill in manually \n'
|
|
551
|
+
' Have returned the known channel positions and NaN')
|
|
552
|
+
return channel_pos
|
|
501
553
|
|
|
502
|
-
def paths_from_KS(KS_dirs, custom_raw_waveform_paths=None, custom_bombcell_paths=None):
|
|
554
|
+
def paths_from_KS(KS_dirs, param=None, custom_raw_waveform_paths=None, custom_bombcell_paths=None):
|
|
503
555
|
"""
|
|
504
556
|
This function will find specific paths to required files from a KiloSort directory
|
|
505
557
|
or use custom paths if provided
|
|
@@ -508,6 +560,9 @@ def paths_from_KS(KS_dirs, custom_raw_waveform_paths=None, custom_bombcell_paths
|
|
|
508
560
|
----------
|
|
509
561
|
KS_dirs : list
|
|
510
562
|
The list of paths to the KiloSort directory for each session
|
|
563
|
+
param : dict, optional
|
|
564
|
+
Parameter dictionary. If provided, spike_width and peak_loc are updated
|
|
565
|
+
from the waveform files found in KS_dirs.
|
|
511
566
|
custom_raw_waveform_paths : list, optional
|
|
512
567
|
Custom paths to raw waveform directories for each session. If provided,
|
|
513
568
|
these will be used instead of searching within KS_dirs
|
|
@@ -549,16 +604,30 @@ def paths_from_KS(KS_dirs, custom_raw_waveform_paths=None, custom_bombcell_paths
|
|
|
549
604
|
wave_paths.append( os.path.join(KS_dirs[i],'bombcell', 'RawWaveforms'))
|
|
550
605
|
else:
|
|
551
606
|
raise Exception('Could not find RawWaveforms folder')
|
|
552
|
-
#load in a waveform from each session to get the number of channels
|
|
607
|
+
#load in a waveform from each session to get the number of channels and spike_width
|
|
553
608
|
n_channels = []
|
|
609
|
+
spike_widths = []
|
|
554
610
|
for i in range(n_sessions):
|
|
555
611
|
path_tmp = wave_paths[i]
|
|
556
612
|
file = os.listdir(path_tmp)
|
|
557
613
|
waveform_tmp = np.load(os.path.join(path_tmp,file[0]))
|
|
558
614
|
n_channels.append(waveform_tmp.shape[1])
|
|
615
|
+
spike_widths.append(waveform_tmp.shape[0])
|
|
559
616
|
|
|
560
617
|
os.chdir(tmp)
|
|
561
618
|
|
|
619
|
+
if param is not None:
|
|
620
|
+
unique_widths = set(spike_widths)
|
|
621
|
+
if len(unique_widths) > 1:
|
|
622
|
+
print(f"Warning: sessions have inconsistent spike_width values {spike_widths}. "
|
|
623
|
+
f"Using the first session's value ({spike_widths[0]}); check your data.")
|
|
624
|
+
detected_width = spike_widths[0]
|
|
625
|
+
if 'spike_width' in param and param['spike_width'] != detected_width:
|
|
626
|
+
print(f"Updating spike_width from {param['spike_width']} to {detected_width} based on waveform files.")
|
|
627
|
+
param['spike_width'] = detected_width
|
|
628
|
+
param['peak_loc'] = int(np.floor(detected_width / 2))
|
|
629
|
+
param['waveidx'] = np.arange(param['peak_loc'] - 8, param['peak_loc'] + 15, dtype=int)
|
|
630
|
+
|
|
562
631
|
#Load channel_pos
|
|
563
632
|
channel_pos = []
|
|
564
633
|
for i in range(n_sessions):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: UnitMatchPy
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.4.0
|
|
4
4
|
Summary: Automatic matching of neurons across sessions
|
|
5
5
|
Author: Enny van Beest, Célian Bimbard, Suyash Agarwal, Wentao Qiu
|
|
6
6
|
License: CC BY-NC-SA 4.0 International
|
|
@@ -13,16 +13,20 @@ Classifier: Operating System :: OS Independent
|
|
|
13
13
|
Requires-Python: <3.13,>=3.9
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
|
-
Requires-Dist: numpy<
|
|
17
|
-
Requires-Dist: scipy<2.0,>=1.
|
|
18
|
-
Requires-Dist: pandas<3.0,>=
|
|
19
|
-
Requires-Dist: matplotlib<4.0,>=3.
|
|
16
|
+
Requires-Dist: numpy<3.0,>=1.21
|
|
17
|
+
Requires-Dist: scipy<2.0,>=1.13
|
|
18
|
+
Requires-Dist: pandas<3.0,>=2.2
|
|
19
|
+
Requires-Dist: matplotlib<4.0,>=3.9
|
|
20
20
|
Requires-Dist: joblib<2.0,>=1.2
|
|
21
21
|
Requires-Dist: tqdm<5.0,>=4.64
|
|
22
|
-
Requires-Dist: h5py<4.0,>=3.
|
|
23
|
-
Requires-Dist: scikit-learn<2.0,>=1.
|
|
22
|
+
Requires-Dist: h5py<4.0,>=3.11
|
|
23
|
+
Requires-Dist: scikit-learn<2.0,>=1.5
|
|
24
24
|
Requires-Dist: mtscomp
|
|
25
|
-
Requires-Dist: torch<3.0,>=2.
|
|
25
|
+
Requires-Dist: torch<3.0,>=2.3
|
|
26
|
+
Requires-Dist: tensorboard
|
|
27
|
+
Requires-Dist: seaborn
|
|
28
|
+
Requires-Dist: matplotlib_venn
|
|
29
|
+
Requires-Dist: statsmodels
|
|
26
30
|
Provides-Extra: full
|
|
27
31
|
Requires-Dist: mat73<1.0,>=0.62; extra == "full"
|
|
28
32
|
Requires-Dist: spikeinterface<0.120,>=0.100; extra == "full"
|
|
@@ -36,22 +40,27 @@ Requires-Dist: build; extra == "dev"
|
|
|
36
40
|
Requires-Dist: twine; extra == "dev"
|
|
37
41
|
Dynamic: license-file
|
|
38
42
|
|
|
39
|
-
# UnitMatchPy
|
|
43
|
+
# UnitMatchPy and DeepUnitMatch
|
|
40
44
|
|
|
41
45
|
This repository contains:
|
|
42
|
-
- **UnitMatchPy
|
|
43
|
-
- **DeepUnitMatch
|
|
46
|
+
- **UnitMatchPy**: automatic matching of neurons across sessions (Python package).
|
|
47
|
+
- **DeepUnitMatch**: DeepUnitMatch pipeline and demos (see preprint below).
|
|
44
48
|
|
|
45
49
|
## References
|
|
46
50
|
|
|
47
|
-
- **UnitMatch
|
|
48
|
-
- **DeepUnitMatch
|
|
51
|
+
- **UnitMatch:** https://www.nature.com/articles/s41592-024-02440-1
|
|
52
|
+
- **DeepUnitMatch preprint:** https://www.biorxiv.org/content/10.64898/2026.01.30.702777v1
|
|
49
53
|
|
|
50
54
|
## Versions
|
|
51
55
|
|
|
52
|
-
- **UnitMatchPy version:** `3.
|
|
56
|
+
- **UnitMatchPy version:** `3.3.1` (from `pyproject.toml`)
|
|
53
57
|
- **DeepUnitMatch:** code lives under `DeepUnitMatch/` (see **DeepUnitMatch (DUM)** section)
|
|
54
58
|
|
|
59
|
+
## System requirements
|
|
60
|
+
|
|
61
|
+
Both UnitMatchPy and DeepUnitMatch can be ran on a standard computer, with sufficient RAM (>32GB for large datasets).
|
|
62
|
+
This software is supported for Windows and macOS, and has been tested on Windows 11.
|
|
63
|
+
|
|
55
64
|
## Installation
|
|
56
65
|
|
|
57
66
|
`pip install` (including `pip install -e .`) installs into whatever Python environment your `pip` points to (system Python, a conda env, or a virtualenv). `pip` does **not** create or name environments.
|
|
@@ -64,7 +73,7 @@ conda create -n UMPy python=3.11 pip #(press y when prompted)
|
|
|
64
73
|
conda activate UMPy
|
|
65
74
|
```
|
|
66
75
|
|
|
67
|
-
Then install using pip (options below).
|
|
76
|
+
Then install using pip (options below). This step should take less than few minutes.
|
|
68
77
|
|
|
69
78
|
### Option A: Install the released package (PyPI)
|
|
70
79
|
|
|
@@ -83,11 +92,13 @@ pip install "UnitMatchPy[full,notebooks]"
|
|
|
83
92
|
First, open a terminal and navigate to this folder (the one containing `pyproject.toml`). The `pip install -e` command must be run from here:
|
|
84
93
|
|
|
85
94
|
```bash
|
|
86
|
-
# Windows (PowerShell)
|
|
87
|
-
|
|
95
|
+
# Windows (PowerShell) - note; you may have to give writing access to the specific CONDA environment via Windows Security → Virus & threat protection → Ransomware protection → Manage ransomware protection. For example, if the below steps result in "could not create 'UnitMatchPy.egg-info'"
|
|
96
|
+
|
|
97
|
+
Look at Controlled folder access:
|
|
98
|
+
cd $HOME\Documents\GitHub\UnitMatch\UnitMatchPy
|
|
88
99
|
|
|
89
100
|
# macOS / Linux
|
|
90
|
-
cd ~/Documents/GitHub/
|
|
101
|
+
cd ~/Documents/GitHub/UnitMatch/UnitMatchPy
|
|
91
102
|
```
|
|
92
103
|
|
|
93
104
|
```bash
|
|
@@ -104,9 +115,9 @@ pip install -e ".[full,notebooks]"
|
|
|
104
115
|
|
|
105
116
|
All demo notebooks are in `Demo Notebooks/`.
|
|
106
117
|
|
|
107
|
-
### Run UnitMatchPy
|
|
118
|
+
### Run UnitMatchPy
|
|
108
119
|
|
|
109
|
-
To run
|
|
120
|
+
To run UnitMatchPy, standard spike sorting data is needed (channel positions and extracted raw waveforms for each unit). Waveforms can be extracted externally (e.g. [BombCell](https://github.com/Julie-Fabre/bombcell)) or using the demo notebooks:
|
|
110
121
|
- `Demo Notebooks/extract_raw_data_demo.ipynb` (compressed `.cbin`/`.ch` or raw)
|
|
111
122
|
- `Demo Notebooks/extract_raw_data_demo_open_ephys.ipynb` (Open Ephys)
|
|
112
123
|
- `Demo Notebooks/UMPy_spike_interface_demo.ipynb` ([SpikeInterface](https://spikeinterface.readthedocs.io/en/latest/) workflow)
|
|
@@ -117,11 +128,13 @@ Example notebooks:
|
|
|
117
128
|
|
|
118
129
|
The GUI is an optional step to curate and explore UnitMatch outputs; see `Demo Notebooks/GUI_Reference_Guide.md` for usage tips and shortcuts.
|
|
119
130
|
|
|
120
|
-
|
|
131
|
+
### Run DeepUnitMatch
|
|
121
132
|
|
|
122
133
|
To try the DeepUnitMatch version, start with:
|
|
123
134
|
- `Demo Notebooks/DeepUnitMatch.ipynb`
|
|
124
135
|
|
|
136
|
+
It should take just a few minutes to run on a standard PC.
|
|
137
|
+
|
|
125
138
|
If you want to train / fine-tune a model on your own data, see:
|
|
126
139
|
- `Demo Notebooks/DUM_training.ipynb`
|
|
127
140
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
UnitMatchPy/GUI.py,sha256=
|
|
1
|
+
UnitMatchPy/GUI.py,sha256=TENEtgPKOUZZm0PhXGGJYSp-NN75LvGFtMJld1qfykE,72500
|
|
2
2
|
UnitMatchPy/GUI_icon.png,sha256=hryy3e7itPSMu_aqRJ_EgGsrNU0tl6lP2RBA0FKkckY,1968
|
|
3
3
|
UnitMatchPy/UM Logo.ico,sha256=slwTUp3OGJzWtb0HkEu1xugU_CMeNv3ZrxrfnzKK4Pw,14872
|
|
4
4
|
UnitMatchPy/__init__.py,sha256=k7uCoTM8FbOhi1TV3tIgBUtuUwhRxh_pl5bebKAHwiM,268
|
|
5
5
|
UnitMatchPy/assign_unique_id.py,sha256=sBsjfamkuy6yY9GxHQ7oQJSvpUSxXk2uoVYNpxMF83k,8413
|
|
6
6
|
UnitMatchPy/bayes_functions.py,sha256=3sP-4cWcTTRtuE7HjKJHwN1iFDBY3Y-cmufetCgUZ_A,4511
|
|
7
|
-
UnitMatchPy/default_params.py,sha256=
|
|
7
|
+
UnitMatchPy/default_params.py,sha256=hMFCBbqUTD--kmuNK2HbNUgklC20MOi_ty3ozOcrJlM,1954
|
|
8
8
|
UnitMatchPy/extract_raw_data.py,sha256=BaPT5sSj3mVxHJomnlJWELbxDgwbC-VnUbako9JwFAk,10767
|
|
9
|
-
UnitMatchPy/metric_functions.py,sha256=
|
|
10
|
-
UnitMatchPy/overlord.py,sha256
|
|
11
|
-
UnitMatchPy/param_functions.py,sha256=
|
|
9
|
+
UnitMatchPy/metric_functions.py,sha256=oCINKcyr8qccaqvXnla_h54_dYK2s0WPisL3QzxcwZM,42371
|
|
10
|
+
UnitMatchPy/overlord.py,sha256=-TJi1ZnDWYdNlI-b27MW4-9BmzO94P9m0K6WC9yRKfY,6371
|
|
11
|
+
UnitMatchPy/param_functions.py,sha256=XKj3zpyjJIcIvO4gavWu0F6wMlMawOjEG2csK9gvjdw,17108
|
|
12
12
|
UnitMatchPy/run.py,sha256=pA0lQntiEQt8jTuxfC1eoIdESCkWttyBw3eheuk5hMA,5350
|
|
13
13
|
UnitMatchPy/save_utils.py,sha256=ZPlI60JYKt5cmZPiTYI2sPeA1OeKdgcWjeAT5yG4QyA,18672
|
|
14
|
-
UnitMatchPy/utils.py,sha256=
|
|
14
|
+
UnitMatchPy/utils.py,sha256=5owvqRm0PmOFG__JcvFANDiY0JzjHJ2tLMAYmNncg7I,43752
|
|
15
15
|
UnitMatchPy/TkinterTheme/awthemes-10.4.0/LICENSE,sha256=QLti2X2WgO5MQ5_zSH1BpTVF2KHSCliQa9HG1s4skQk,2215
|
|
16
16
|
UnitMatchPy/TkinterTheme/awthemes-10.4.0/README.txt,sha256=OszYA8mn7QelmAYtz0bHi6sf9YOvrXLGgmuCx3bRoJ4,15419
|
|
17
17
|
UnitMatchPy/TkinterTheme/awthemes-10.4.0/awdark.tcl,sha256=bGeLj0wiuOkXQR3R7lP9FpkdE1-mAJruUATnxdCmy0c,2024
|
|
@@ -279,8 +279,8 @@ UnitMatchPy/TkinterTheme/awthemes-10.4.0/i/awthemes/treeview/solid/tree-arrow-do
|
|
|
279
279
|
UnitMatchPy/TkinterTheme/awthemes-10.4.0/i/awthemes/treeview/solid/tree-arrow-right-n-base.svg,sha256=rhgTHm-xIGRkRz9sCSwNNZ3uKfDrK78lroyYbBJAZsk,2386
|
|
280
280
|
UnitMatchPy/TkinterTheme/awthemes-10.4.0/i/awthemes/treeview/solid/tree-arrow-right-n.svg,sha256=8x1rGSDH8eyFeQDJ-glAc63K1hl-UveaJTNBkDmP6vA,2497
|
|
281
281
|
UnitMatchPy/TkinterTheme/awthemes-10.4.0/i/awthemes/treeview/solid/tree-arrow-right-sn.svg,sha256=8x1rGSDH8eyFeQDJ-glAc63K1hl-UveaJTNBkDmP6vA,2497
|
|
282
|
-
unitmatchpy-3.
|
|
283
|
-
unitmatchpy-3.
|
|
284
|
-
unitmatchpy-3.
|
|
285
|
-
unitmatchpy-3.
|
|
286
|
-
unitmatchpy-3.
|
|
282
|
+
unitmatchpy-3.4.0.dist-info/licenses/LICENSE,sha256=WAMqgXMZUjcGirAtQplIvDIz2OaFjRud39xH47vD2Ec,20844
|
|
283
|
+
unitmatchpy-3.4.0.dist-info/METADATA,sha256=NpIrZuiuqBnFMtWhLAAjhF2G8FzXuD1bglx1YxEspVM,5425
|
|
284
|
+
unitmatchpy-3.4.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
285
|
+
unitmatchpy-3.4.0.dist-info/top_level.txt,sha256=EjaC3TLtFxUHy5xVS71T_IrmNpDUVUlXf-7GO32tuDI,12
|
|
286
|
+
unitmatchpy-3.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|