UnitMatchPy 3.4.0__py3-none-any.whl → 3.4.1__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/utils.py +95 -57
- {unitmatchpy-3.4.0.dist-info → unitmatchpy-3.4.1.dist-info}/METADATA +9 -9
- {unitmatchpy-3.4.0.dist-info → unitmatchpy-3.4.1.dist-info}/RECORD +6 -6
- {unitmatchpy-3.4.0.dist-info → unitmatchpy-3.4.1.dist-info}/WHEEL +0 -0
- {unitmatchpy-3.4.0.dist-info → unitmatchpy-3.4.1.dist-info}/licenses/LICENSE +0 -0
- {unitmatchpy-3.4.0.dist-info → unitmatchpy-3.4.1.dist-info}/top_level.txt +0 -0
UnitMatchPy/utils.py
CHANGED
|
@@ -448,13 +448,13 @@ def fill_missing_pos(KS_dir, n_channels):
|
|
|
448
448
|
outside the brain). UnitMatch requires the full channel_pos array, so this
|
|
449
449
|
function reconstructs positions for the missing hardware channels.
|
|
450
450
|
|
|
451
|
-
Strategy
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
451
|
+
Strategy (mirrors MATLAB fillmissingprobe.m): for each x-column that has known
|
|
452
|
+
positions, find the most similar column (one whose y-positions are a subset or
|
|
453
|
+
superset of the current column's y-positions). The y-positions present in that
|
|
454
|
+
reference column but absent from the current one are the missing positions.
|
|
455
|
+
The corresponding hardware-channel indices are inferred from the stride between
|
|
456
|
+
consecutive known channel indices in the same column, then matched against the
|
|
457
|
+
actual NaN entries. This makes no assumptions about round-robin column ordering.
|
|
458
458
|
|
|
459
459
|
Parameters
|
|
460
460
|
----------
|
|
@@ -484,58 +484,96 @@ def fill_missing_pos(KS_dir, n_channels):
|
|
|
484
484
|
print('Likely to be correctly filled')
|
|
485
485
|
return channel_pos
|
|
486
486
|
|
|
487
|
-
# ---
|
|
488
|
-
|
|
489
|
-
#
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
487
|
+
# --- MATLAB-style cross-column geometry inference ---
|
|
488
|
+
|
|
489
|
+
# Column assignment: ch_order[i] = column index for hardware channel i, -1 if unknown.
|
|
490
|
+
x_unique, ch_order_known = np.unique(channel_pos[~nan_mask, 0], return_inverse=True)
|
|
491
|
+
ch_order = np.full(n_channels, -1, dtype=int)
|
|
492
|
+
ch_order[~nan_mask] = ch_order_known
|
|
493
493
|
n_cols = len(x_unique)
|
|
494
494
|
|
|
495
|
-
#
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
|
495
|
+
# Sorted unique y-positions per column (known channels only).
|
|
496
|
+
y_unique = [np.unique(channel_pos[ch_order == col_i, 1]) for col_i in range(n_cols)]
|
|
497
|
+
|
|
498
|
+
miss_idx = np.where(nan_mask)[0]
|
|
499
|
+
missing_chan = [] # (x, y) pairs for missing positions
|
|
500
|
+
probable_ch_idx = [] # hardware channel indices for those positions
|
|
501
|
+
count_id = 0
|
|
502
|
+
|
|
503
|
+
for xid in range(n_cols):
|
|
504
|
+
y_col = y_unique[xid]
|
|
505
|
+
|
|
506
|
+
# Find the most similar column: one whose y-set is a subset or superset of y_col.
|
|
507
|
+
same_idx = [
|
|
508
|
+
j for j in range(n_cols) if j != xid and (
|
|
509
|
+
np.all(np.isin(y_col, y_unique[j])) or
|
|
510
|
+
np.all(np.isin(y_unique[j], y_col))
|
|
511
|
+
)
|
|
512
|
+
]
|
|
513
|
+
|
|
514
|
+
if same_idx:
|
|
515
|
+
# Prefer the column whose size is closest to y_col.
|
|
516
|
+
sizes = np.array([len(y_unique[j]) for j in same_idx])
|
|
517
|
+
y_ref = y_unique[same_idx[int(np.argmin(np.abs(sizes - len(y_col))))]]
|
|
524
518
|
else:
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
519
|
+
y_ref = np.array([])
|
|
520
|
+
|
|
521
|
+
# If the reference column itself has gaps, complete it via its minimum step.
|
|
522
|
+
if len(y_ref) > 1 and len(np.unique(np.diff(y_ref))) > 1:
|
|
523
|
+
step = float(np.min(np.diff(y_ref)))
|
|
524
|
+
y_ref = np.arange(y_ref[0], y_ref[-1] + step / 2, step)
|
|
525
|
+
|
|
526
|
+
# Skip this column if there are no missing y-positions.
|
|
527
|
+
if len(y_ref) == 0 or not np.any(~np.isin(y_ref, y_col)):
|
|
528
|
+
continue
|
|
529
|
+
|
|
530
|
+
missing_y = y_ref[~np.isin(y_ref, y_col)]
|
|
531
|
+
for y in missing_y:
|
|
532
|
+
missing_chan.append([x_unique[xid], y])
|
|
533
|
+
|
|
534
|
+
# Hardware channel indices already known in this column (sorted ascending).
|
|
535
|
+
these_chs = np.sort(np.where(ch_order == xid)[0])
|
|
536
|
+
|
|
537
|
+
if len(these_chs) > 1:
|
|
538
|
+
step_sz = int(np.min(np.diff(these_chs)))
|
|
539
|
+
else:
|
|
540
|
+
step_sz = n_cols # fallback: stride equals number of columns
|
|
541
|
+
|
|
542
|
+
# Potential missing indices: extend the known range downward by 2 steps
|
|
543
|
+
# (mirrors MATLAB: min-2*step : step : max).
|
|
544
|
+
potential_chans = np.arange(
|
|
545
|
+
these_chs[0] - step_sz * 2,
|
|
546
|
+
these_chs[-1] + 1,
|
|
547
|
+
step_sz,
|
|
548
|
+
dtype=int,
|
|
549
|
+
)
|
|
550
|
+
potential_chans = potential_chans[(potential_chans >= 0) & (potential_chans < n_channels)]
|
|
551
|
+
|
|
552
|
+
this_chans = miss_idx[np.isin(miss_idx, potential_chans)]
|
|
553
|
+
if len(this_chans) == 0:
|
|
554
|
+
# Fallback: take the next unassigned NaN channel.
|
|
555
|
+
if count_id < len(miss_idx):
|
|
556
|
+
this_chans = np.array([miss_idx[count_id]], dtype=int)
|
|
557
|
+
else:
|
|
558
|
+
this_chans = np.array([], dtype=int)
|
|
559
|
+
|
|
560
|
+
probable_ch_idx.extend(this_chans.tolist())
|
|
561
|
+
count_id += 1
|
|
562
|
+
|
|
563
|
+
# Apply inferred positions.
|
|
564
|
+
if probable_ch_idx:
|
|
565
|
+
idx_arr = np.array(probable_ch_idx)
|
|
566
|
+
if np.any(np.bincount(idx_arr, minlength=n_channels) > 1):
|
|
567
|
+
raise RuntimeError('Channel map filling in failed: duplicate channel assignments.')
|
|
568
|
+
missing_arr = np.array(missing_chan)
|
|
569
|
+
if len(idx_arr) == len(missing_arr):
|
|
570
|
+
channel_pos[idx_arr] = missing_arr
|
|
571
|
+
else:
|
|
572
|
+
print('Warning: mismatch between inferred positions ({}) and channel '
|
|
573
|
+
'indices ({}); skipping partial fill.'.format(
|
|
574
|
+
len(missing_arr), len(idx_arr)))
|
|
575
|
+
|
|
576
|
+
# Safety net: place any still-NaN channels well off-probe.
|
|
539
577
|
still_nan = np.isnan(channel_pos[:, 0])
|
|
540
578
|
if np.any(still_nan):
|
|
541
579
|
x_fill = float(np.nanmedian(channel_pos[:, 0]))
|
|
@@ -634,7 +672,7 @@ def paths_from_KS(KS_dirs, param=None, custom_raw_waveform_paths=None, custom_bo
|
|
|
634
672
|
path_tmp = os.path.join(KS_dirs[i], 'channel_positions.npy')
|
|
635
673
|
pos_tmp = np.load(path_tmp)
|
|
636
674
|
if pos_tmp.shape[0] != n_channels[i]:
|
|
637
|
-
print('
|
|
675
|
+
print('Attempting to fill in missing channel positions')
|
|
638
676
|
pos_tmp = fill_missing_pos(KS_dirs[i], n_channels[i])
|
|
639
677
|
|
|
640
678
|
# Want 3-D positions, however at the moment code only needs 2-D so add 1's to 0 axis position
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: UnitMatchPy
|
|
3
|
-
Version: 3.4.
|
|
3
|
+
Version: 3.4.1
|
|
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,16 @@ 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<2.0,>=1.21
|
|
17
|
+
Requires-Dist: scipy<2.0,>=1.9
|
|
18
|
+
Requires-Dist: pandas<3.0,>=1.5
|
|
19
|
+
Requires-Dist: matplotlib<4.0,>=3.6
|
|
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.8
|
|
23
|
+
Requires-Dist: scikit-learn<2.0,>=1.2
|
|
24
24
|
Requires-Dist: mtscomp
|
|
25
|
-
Requires-Dist: torch<3.0,>=2.
|
|
25
|
+
Requires-Dist: torch<3.0,>=2.1
|
|
26
26
|
Requires-Dist: tensorboard
|
|
27
27
|
Requires-Dist: seaborn
|
|
28
28
|
Requires-Dist: matplotlib_venn
|
|
@@ -53,7 +53,7 @@ This repository contains:
|
|
|
53
53
|
|
|
54
54
|
## Versions
|
|
55
55
|
|
|
56
|
-
- **UnitMatchPy version:** `3.
|
|
56
|
+
- **UnitMatchPy version:** `3.4.1` (from `pyproject.toml`)
|
|
57
57
|
- **DeepUnitMatch:** code lives under `DeepUnitMatch/` (see **DeepUnitMatch (DUM)** section)
|
|
58
58
|
|
|
59
59
|
## System requirements
|
|
@@ -11,7 +11,7 @@ UnitMatchPy/overlord.py,sha256=-TJi1ZnDWYdNlI-b27MW4-9BmzO94P9m0K6WC9yRKfY,6371
|
|
|
11
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=VaLBeTz6HF5vmMx2hxWxjxO4VEoSlf5-CUQQV7vsATM,44651
|
|
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.4.
|
|
283
|
-
unitmatchpy-3.4.
|
|
284
|
-
unitmatchpy-3.4.
|
|
285
|
-
unitmatchpy-3.4.
|
|
286
|
-
unitmatchpy-3.4.
|
|
282
|
+
unitmatchpy-3.4.1.dist-info/licenses/LICENSE,sha256=WAMqgXMZUjcGirAtQplIvDIz2OaFjRud39xH47vD2Ec,20844
|
|
283
|
+
unitmatchpy-3.4.1.dist-info/METADATA,sha256=895MkPNQ1uP96GL2ni-UNbhjOWN86UQ__wpCFxoW9Sw,5423
|
|
284
|
+
unitmatchpy-3.4.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
285
|
+
unitmatchpy-3.4.1.dist-info/top_level.txt,sha256=EjaC3TLtFxUHy5xVS71T_IrmNpDUVUlXf-7GO32tuDI,12
|
|
286
|
+
unitmatchpy-3.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|