UnitMatchPy 3.4.1__py3-none-any.whl → 3.5.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 +1167 -702
- UnitMatchPy/__init__.py +2 -2
- UnitMatchPy/assign_unique_id.py +235 -63
- UnitMatchPy/bayes_functions.py +46 -29
- UnitMatchPy/default_params.py +30 -23
- UnitMatchPy/extract_raw_data.py +99 -65
- UnitMatchPy/metric_functions.py +424 -255
- UnitMatchPy/overlord.py +108 -44
- UnitMatchPy/param_functions.py +239 -164
- UnitMatchPy/run.py +75 -31
- UnitMatchPy/save_utils.py +327 -151
- UnitMatchPy/utils.py +403 -248
- {unitmatchpy-3.4.1.dist-info → unitmatchpy-3.5.0.dist-info}/METADATA +3 -2
- {unitmatchpy-3.4.1.dist-info → unitmatchpy-3.5.0.dist-info}/RECORD +17 -17
- {unitmatchpy-3.4.1.dist-info → unitmatchpy-3.5.0.dist-info}/WHEEL +1 -1
- {unitmatchpy-3.4.1.dist-info → unitmatchpy-3.5.0.dist-info}/licenses/LICENSE +0 -0
- {unitmatchpy-3.4.1.dist-info → unitmatchpy-3.5.0.dist-info}/top_level.txt +0 -0
UnitMatchPy/GUI.py
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
from tkinter import *
|
|
2
2
|
from tkinter import ttk
|
|
3
|
-
|
|
4
|
-
from matplotlib.
|
|
5
|
-
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
|
|
3
|
+
from matplotlib.figure import Figure
|
|
4
|
+
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
|
6
5
|
import numpy as np
|
|
7
6
|
from matplotlib import rcParams
|
|
8
7
|
import os
|
|
9
8
|
import pickle
|
|
10
9
|
|
|
11
10
|
|
|
12
|
-
def precalculate_all_acgs(
|
|
11
|
+
def precalculate_all_acgs(
|
|
12
|
+
clus_info, param, save_path=None, bin_size=0.001, max_lag=0.05
|
|
13
|
+
):
|
|
13
14
|
"""
|
|
14
15
|
Pre-calculate and save autocorrelograms for all units to speed up GUI loading
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
Parameters
|
|
17
18
|
----------
|
|
18
19
|
clus_info : dict
|
|
@@ -25,54 +26,56 @@ def precalculate_all_acgs(clus_info, param, save_path=None, bin_size=0.001, max_
|
|
|
25
26
|
Bin size in seconds (default 1ms)
|
|
26
27
|
max_lag : float
|
|
27
28
|
Maximum lag in seconds (default 50ms)
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
Returns
|
|
30
31
|
-------
|
|
31
32
|
acg_cache : dict
|
|
32
33
|
Dictionary mapping unit_id to (autocorr, bin_centers) tuples
|
|
33
34
|
"""
|
|
34
35
|
print("Pre-calculating autocorrelograms for all units...")
|
|
35
|
-
|
|
36
|
+
|
|
36
37
|
if save_path is None:
|
|
37
|
-
save_path =
|
|
38
|
-
|
|
38
|
+
save_path = "acg_cache.pkl"
|
|
39
|
+
|
|
39
40
|
acg_cache = {}
|
|
40
|
-
n_units = len(clus_info.get(
|
|
41
|
-
|
|
41
|
+
n_units = len(clus_info.get("session_id", []))
|
|
42
|
+
|
|
42
43
|
for unit_id in range(n_units):
|
|
43
44
|
try:
|
|
44
45
|
# Get spike times for this unit
|
|
45
46
|
spike_times = get_spike_times_for_unit_precalc(unit_id, clus_info, param)
|
|
46
|
-
|
|
47
|
+
|
|
47
48
|
if len(spike_times) > 1:
|
|
48
49
|
# Compute ACG
|
|
49
|
-
autocorr, bin_centers = compute_acg_precalc(
|
|
50
|
+
autocorr, bin_centers = compute_acg_precalc(
|
|
51
|
+
spike_times, bin_size, max_lag
|
|
52
|
+
)
|
|
50
53
|
acg_cache[unit_id] = (autocorr, bin_centers)
|
|
51
|
-
|
|
54
|
+
|
|
52
55
|
if (unit_id + 1) % 50 == 0: # Progress update every 50 units
|
|
53
56
|
print(f"Processed {unit_id + 1}/{n_units} units")
|
|
54
57
|
else:
|
|
55
58
|
acg_cache[unit_id] = (np.array([]), np.array([]))
|
|
56
|
-
|
|
59
|
+
|
|
57
60
|
except Exception as e:
|
|
58
61
|
print(f"Error computing ACG for unit {unit_id}: {e}")
|
|
59
62
|
acg_cache[unit_id] = (np.array([]), np.array([]))
|
|
60
|
-
|
|
63
|
+
|
|
61
64
|
# Save to file
|
|
62
65
|
try:
|
|
63
|
-
with open(save_path,
|
|
66
|
+
with open(save_path, "wb") as f:
|
|
64
67
|
pickle.dump(acg_cache, f)
|
|
65
68
|
print(f"ACG cache saved to {save_path}")
|
|
66
69
|
except Exception as e:
|
|
67
70
|
print(f"Error saving ACG cache: {e}")
|
|
68
|
-
|
|
71
|
+
|
|
69
72
|
return acg_cache
|
|
70
73
|
|
|
71
74
|
|
|
72
75
|
def get_spike_times_for_unit_precalc(unit_id, clus_info, param):
|
|
73
76
|
"""
|
|
74
77
|
Get spike times for a specific unit (used in pre-calculation)
|
|
75
|
-
|
|
78
|
+
|
|
76
79
|
Parameters
|
|
77
80
|
----------
|
|
78
81
|
unit_id : int
|
|
@@ -81,7 +84,7 @@ def get_spike_times_for_unit_precalc(unit_id, clus_info, param):
|
|
|
81
84
|
Cluster information dictionary
|
|
82
85
|
param : dict
|
|
83
86
|
Parameters dictionary
|
|
84
|
-
|
|
87
|
+
|
|
85
88
|
Returns
|
|
86
89
|
-------
|
|
87
90
|
spike_times : array
|
|
@@ -89,56 +92,58 @@ def get_spike_times_for_unit_precalc(unit_id, clus_info, param):
|
|
|
89
92
|
"""
|
|
90
93
|
try:
|
|
91
94
|
# Get session information for this unit
|
|
92
|
-
session_id = clus_info[
|
|
93
|
-
original_id = clus_info[
|
|
94
|
-
|
|
95
|
+
session_id = clus_info["session_id"][unit_id]
|
|
96
|
+
original_id = clus_info["original_ids"][unit_id]
|
|
97
|
+
|
|
95
98
|
# Get the Kilosort directory for this session
|
|
96
|
-
if
|
|
97
|
-
ks_dir = param[
|
|
99
|
+
if "KS_dirs" in param:
|
|
100
|
+
ks_dir = param["KS_dirs"][session_id]
|
|
98
101
|
else:
|
|
99
102
|
return np.array([])
|
|
100
|
-
|
|
103
|
+
|
|
101
104
|
# Load Kilosort spike times and cluster assignments
|
|
102
|
-
spike_times_path = os.path.join(ks_dir,
|
|
103
|
-
spike_clusters_path = os.path.join(ks_dir,
|
|
104
|
-
|
|
105
|
+
spike_times_path = os.path.join(ks_dir, "spike_times.npy")
|
|
106
|
+
spike_clusters_path = os.path.join(ks_dir, "spike_clusters.npy")
|
|
107
|
+
|
|
105
108
|
if os.path.exists(spike_times_path) and os.path.exists(spike_clusters_path):
|
|
106
109
|
# Load spike times (in samples) and cluster assignments
|
|
107
110
|
spike_times_samples = np.load(spike_times_path).flatten()
|
|
108
111
|
spike_clusters = np.load(spike_clusters_path).flatten()
|
|
109
|
-
|
|
112
|
+
|
|
110
113
|
# Get sampling rate - try to load from params.py or use default
|
|
111
114
|
try:
|
|
112
|
-
params_path = os.path.join(ks_dir,
|
|
115
|
+
params_path = os.path.join(ks_dir, "params.py")
|
|
113
116
|
sample_rate = 30000 # Default sample rate
|
|
114
117
|
if os.path.exists(params_path):
|
|
115
118
|
# Parse params.py for sample_rate
|
|
116
|
-
with open(params_path,
|
|
119
|
+
with open(params_path, "r") as f:
|
|
117
120
|
params_content = f.read()
|
|
118
121
|
# Extract sample_rate
|
|
119
|
-
for line in params_content.split(
|
|
120
|
-
if
|
|
121
|
-
sample_rate = float(line.split(
|
|
122
|
+
for line in params_content.split("\n"):
|
|
123
|
+
if "sample_rate" in line and "=" in line:
|
|
124
|
+
sample_rate = float(line.split("=")[1].strip())
|
|
122
125
|
break
|
|
123
126
|
except:
|
|
124
127
|
sample_rate = 30000 # Fallback
|
|
125
|
-
|
|
128
|
+
|
|
126
129
|
# Get spike times for this specific unit
|
|
127
130
|
unit_mask = spike_clusters == original_id
|
|
128
|
-
unit_spike_times =
|
|
129
|
-
|
|
131
|
+
unit_spike_times = (
|
|
132
|
+
spike_times_samples[unit_mask] / sample_rate
|
|
133
|
+
) # Convert to seconds
|
|
134
|
+
|
|
130
135
|
return unit_spike_times
|
|
131
136
|
else:
|
|
132
137
|
return np.array([])
|
|
133
|
-
|
|
134
|
-
except Exception
|
|
138
|
+
|
|
139
|
+
except Exception:
|
|
135
140
|
return np.array([])
|
|
136
141
|
|
|
137
142
|
|
|
138
143
|
def compute_acg_precalc(spike_times, bin_size=0.001, max_lag=0.05):
|
|
139
144
|
"""
|
|
140
145
|
Compute autocorrelogram for a unit (used in pre-calculation)
|
|
141
|
-
|
|
146
|
+
|
|
142
147
|
Parameters
|
|
143
148
|
----------
|
|
144
149
|
spike_times : array
|
|
@@ -147,7 +152,7 @@ def compute_acg_precalc(spike_times, bin_size=0.001, max_lag=0.05):
|
|
|
147
152
|
Bin size in seconds (default 1ms)
|
|
148
153
|
max_lag : float
|
|
149
154
|
Maximum lag in seconds (default 50ms)
|
|
150
|
-
|
|
155
|
+
|
|
151
156
|
Returns
|
|
152
157
|
-------
|
|
153
158
|
autocorr : array
|
|
@@ -157,48 +162,48 @@ def compute_acg_precalc(spike_times, bin_size=0.001, max_lag=0.05):
|
|
|
157
162
|
"""
|
|
158
163
|
if len(spike_times) < 2:
|
|
159
164
|
return np.array([]), np.array([])
|
|
160
|
-
|
|
165
|
+
|
|
161
166
|
# Create bins centered around 0
|
|
162
167
|
bins = np.arange(-max_lag, max_lag + bin_size, bin_size)
|
|
163
|
-
bin_centers = bins[:-1] + bin_size/2
|
|
164
|
-
|
|
168
|
+
bin_centers = bins[:-1] + bin_size / 2
|
|
169
|
+
|
|
165
170
|
# Calculate autocorrelogram
|
|
166
171
|
autocorr = np.zeros(len(bin_centers))
|
|
167
|
-
|
|
172
|
+
|
|
168
173
|
# For each spike, find all other spikes within max_lag
|
|
169
174
|
for i, spike_time in enumerate(spike_times):
|
|
170
175
|
# Find spikes within the lag window
|
|
171
176
|
time_diffs = spike_times - spike_time
|
|
172
177
|
valid_diffs = time_diffs[(np.abs(time_diffs) <= max_lag) & (time_diffs != 0)]
|
|
173
|
-
|
|
178
|
+
|
|
174
179
|
# Bin the time differences
|
|
175
180
|
hist, _ = np.histogram(valid_diffs, bins)
|
|
176
181
|
autocorr += hist
|
|
177
|
-
|
|
182
|
+
|
|
178
183
|
# Convert to firing rate (Hz)
|
|
179
184
|
total_time = spike_times[-1] - spike_times[0] if len(spike_times) > 1 else 1
|
|
180
185
|
n_spikes = len(spike_times)
|
|
181
186
|
autocorr = autocorr / (bin_size * n_spikes * total_time)
|
|
182
|
-
|
|
187
|
+
|
|
183
188
|
return autocorr, bin_centers
|
|
184
189
|
|
|
185
190
|
|
|
186
|
-
def load_acg_cache(cache_path=
|
|
191
|
+
def load_acg_cache(cache_path="acg_cache.pkl"):
|
|
187
192
|
"""
|
|
188
193
|
Load pre-calculated ACG cache from file
|
|
189
|
-
|
|
194
|
+
|
|
190
195
|
Parameters
|
|
191
196
|
----------
|
|
192
197
|
cache_path : str
|
|
193
198
|
Path to the ACG cache file
|
|
194
|
-
|
|
199
|
+
|
|
195
200
|
Returns
|
|
196
201
|
-------
|
|
197
202
|
acg_cache : dict or None
|
|
198
203
|
Dictionary mapping unit_id to (autocorr, bin_centers) tuples, or None if loading failed
|
|
199
204
|
"""
|
|
200
205
|
try:
|
|
201
|
-
with open(cache_path,
|
|
206
|
+
with open(cache_path, "rb") as f:
|
|
202
207
|
acg_cache = pickle.load(f)
|
|
203
208
|
print(f"ACG cache loaded from {cache_path}")
|
|
204
209
|
return acg_cache
|
|
@@ -247,16 +252,15 @@ def run_GUI():
|
|
|
247
252
|
# Try to load pre-calculated ACG cache
|
|
248
253
|
acg_cache = load_acg_cache()
|
|
249
254
|
|
|
250
|
-
rcParams.update({
|
|
251
|
-
rcParams.update({
|
|
252
|
-
rcParams.update({
|
|
253
|
-
color =
|
|
254
|
-
rcParams[
|
|
255
|
-
rcParams[
|
|
256
|
-
rcParams[
|
|
257
|
-
rcParams[
|
|
255
|
+
rcParams.update({"figure.autolayout": True})
|
|
256
|
+
rcParams.update({"font.size": 14})
|
|
257
|
+
rcParams.update({"font.family": "DejaVu Sans"})
|
|
258
|
+
color = "white"
|
|
259
|
+
rcParams["text.color"] = color
|
|
260
|
+
rcParams["axes.labelcolor"] = color
|
|
261
|
+
rcParams["xtick.color"] = color
|
|
262
|
+
rcParams["ytick.color"] = color
|
|
258
263
|
|
|
259
|
-
|
|
260
264
|
np.set_printoptions(suppress=True)
|
|
261
265
|
is_match = []
|
|
262
266
|
not_match = []
|
|
@@ -269,7 +273,7 @@ def run_GUI():
|
|
|
269
273
|
window_width = screen_width - 100
|
|
270
274
|
window_height = screen_height - 100
|
|
271
275
|
root.geometry(f"{window_width}x{window_height}+50+50")
|
|
272
|
-
|
|
276
|
+
|
|
273
277
|
# Configure column weights to prevent plot squashing
|
|
274
278
|
for i in range(7): # Configure columns 0-6
|
|
275
279
|
root.columnconfigure(i, weight=1)
|
|
@@ -278,29 +282,31 @@ def run_GUI():
|
|
|
278
282
|
root.rowconfigure(i, weight=1)
|
|
279
283
|
|
|
280
284
|
# downloaded theme from https://sourceforge.net/projects/tcl-awthemes/
|
|
281
|
-
theme_path_rel = os.path.join(
|
|
282
|
-
theme_path = os.path.join(
|
|
285
|
+
theme_path_rel = os.path.join("TkinterTheme", "awthemes-10.4.0")
|
|
286
|
+
theme_path = os.path.join(
|
|
287
|
+
os.path.dirname(os.path.abspath(__file__)), theme_path_rel
|
|
288
|
+
)
|
|
283
289
|
|
|
284
|
-
root.tk.call(
|
|
285
|
-
root.tk.call(
|
|
290
|
+
root.tk.call("lappend", "auto_path", theme_path)
|
|
291
|
+
root.tk.call("package", "require", "awdark")
|
|
286
292
|
s = ttk.Style(root)
|
|
287
|
-
s.theme_use(
|
|
288
|
-
|
|
293
|
+
s.theme_use("awdark")
|
|
294
|
+
|
|
289
295
|
# Configure fonts for all TTK widgets to use DejaVu Sans
|
|
290
|
-
s.configure(
|
|
291
|
-
s.configure(
|
|
292
|
-
s.configure(
|
|
293
|
-
s.configure(
|
|
294
|
-
s.configure(
|
|
295
|
-
s.configure(
|
|
296
|
-
s.configure(
|
|
297
|
-
s.configure(
|
|
298
|
-
|
|
299
|
-
root.title(
|
|
300
|
-
#root.geometry('800x800')
|
|
296
|
+
s.configure(".", font=("DejaVu Sans", 12))
|
|
297
|
+
s.configure("TLabel", font=("DejaVu Sans", 12))
|
|
298
|
+
s.configure("TButton", font=("DejaVu Sans", 12))
|
|
299
|
+
s.configure("TEntry", font=("DejaVu Sans", 10))
|
|
300
|
+
s.configure("TCombobox", font=("DejaVu Sans", 10))
|
|
301
|
+
s.configure("TCheckbutton", font=("DejaVu Sans", 12))
|
|
302
|
+
s.configure("TRadiobutton", font=("DejaVu Sans", 12))
|
|
303
|
+
s.configure("TLabelFrame.Label", font=("DejaVu Sans", 12, "bold"))
|
|
304
|
+
|
|
305
|
+
root.title("UMPy - Manual Curation")
|
|
306
|
+
# root.geometry('800x800')
|
|
301
307
|
|
|
302
308
|
# Construct the file path to the icon
|
|
303
|
-
icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
|
309
|
+
icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "GUI_icon.png")
|
|
304
310
|
|
|
305
311
|
# Debugging print statements
|
|
306
312
|
print(f"Icon path: {icon_path}")
|
|
@@ -314,98 +320,133 @@ def run_GUI():
|
|
|
314
320
|
except Exception as e:
|
|
315
321
|
print(f"Error loading icon: {e}")
|
|
316
322
|
|
|
317
|
-
|
|
318
323
|
background = ttk.Frame(root)
|
|
319
324
|
background.place(x=0, y=0, relwidth=1.0, relheight=1.0)
|
|
320
325
|
|
|
321
326
|
frame_table = ttk.LabelFrame(root)
|
|
322
327
|
score_table = ttk.LabelFrame(root)
|
|
323
|
-
avg_waveform_plot = Canvas(root)
|
|
328
|
+
avg_waveform_plot = Canvas(root)
|
|
324
329
|
trajectory_plot = Canvas(root)
|
|
325
330
|
bayes_label = ttk.Label(root)
|
|
326
331
|
original_id_label = ttk.Label(root)
|
|
327
332
|
raw_waveform_plot = Canvas(root)
|
|
328
333
|
hist_plot = Canvas(root)
|
|
329
334
|
|
|
330
|
-
#Unit entry
|
|
335
|
+
# Unit entry
|
|
331
336
|
######################################################################################
|
|
332
|
-
#Will have Unit A - color green and unit B- color Blue
|
|
333
|
-
entry_frame = ttk.LabelFrame(root, text
|
|
334
|
-
label_a = ttk.Label(entry_frame, text
|
|
335
|
-
label_a.configure(foreground=
|
|
336
|
-
label_b = ttk.Label(entry_frame, text
|
|
337
|
-
label_b.configure(foreground=
|
|
338
|
-
|
|
339
|
-
#select the session
|
|
340
|
-
sessions_list = np.arange(1,param[
|
|
341
|
-
session_entry_a = ttk.Combobox(entry_frame, value
|
|
342
|
-
session_entry_b = ttk.Combobox(entry_frame, value
|
|
343
|
-
session_entry_a.set(1)
|
|
337
|
+
# Will have Unit A - color green and unit B- color Blue
|
|
338
|
+
entry_frame = ttk.LabelFrame(root, text="Select Units")
|
|
339
|
+
label_a = ttk.Label(entry_frame, text="Unit A")
|
|
340
|
+
label_a.configure(foreground="green")
|
|
341
|
+
label_b = ttk.Label(entry_frame, text="Unit B")
|
|
342
|
+
label_b.configure(foreground="blue")
|
|
343
|
+
|
|
344
|
+
# select the session
|
|
345
|
+
sessions_list = np.arange(1, param["n_sessions"] + 1).tolist()
|
|
346
|
+
session_entry_a = ttk.Combobox(entry_frame, value=sessions_list, width=2)
|
|
347
|
+
session_entry_b = ttk.Combobox(entry_frame, value=sessions_list, width=2)
|
|
348
|
+
session_entry_a.set(1) # Start wiht session 1,2 if more than 1 session given
|
|
344
349
|
if len(sessions_list) == 1:
|
|
345
350
|
session_entry_b.set(1)
|
|
346
351
|
else:
|
|
347
352
|
session_entry_b.set(2)
|
|
348
|
-
label_session_a = ttk.Label(entry_frame, text
|
|
349
|
-
label_session_b = ttk.Label(entry_frame, text
|
|
353
|
+
label_session_a = ttk.Label(entry_frame, text="Session No.")
|
|
354
|
+
label_session_b = ttk.Label(entry_frame, text="Session No.")
|
|
350
355
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
CV_options = [('Avg', 0), ('(1,2)', 1), ('(2,1)',2)]
|
|
356
|
+
# select CV
|
|
357
|
+
CV_options = [("Avg", 0), ("(1,2)", 1), ("(2,1)", 2)]
|
|
354
358
|
CV_tkinter = IntVar()
|
|
355
359
|
CV_tkinter.set(0)
|
|
356
|
-
label_cv = ttk.Label(entry_frame, text
|
|
360
|
+
label_cv = ttk.Label(entry_frame, text="Select the cv option")
|
|
357
361
|
for i, option in enumerate(CV_options):
|
|
358
|
-
RadioCV = ttk.Radiobutton(
|
|
359
|
-
|
|
360
|
-
|
|
362
|
+
RadioCV = ttk.Radiobutton(
|
|
363
|
+
entry_frame,
|
|
364
|
+
text=option[0],
|
|
365
|
+
value=option[1],
|
|
366
|
+
variable=CV_tkinter,
|
|
367
|
+
command=update_unit_cv,
|
|
368
|
+
).grid(row=i + 1, column=0)
|
|
369
|
+
|
|
370
|
+
# selecting the unit
|
|
361
371
|
session_a = int(session_entry_a.get())
|
|
362
|
-
session_b = int(session_entry_b.get())
|
|
372
|
+
session_b = int(session_entry_b.get())
|
|
363
373
|
CV = get_cv_option()
|
|
364
|
-
CV_option = CV_tkinter.get() - 1
|
|
365
|
-
if CV ==
|
|
366
|
-
#Use average CV values
|
|
367
|
-
tmp_idx_a = np.argwhere(
|
|
368
|
-
|
|
374
|
+
CV_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
375
|
+
if CV == "Avg":
|
|
376
|
+
# Use average CV values
|
|
377
|
+
tmp_idx_a = np.argwhere(
|
|
378
|
+
(session_switch[session_a - 1] <= matches_avg[:, 0])
|
|
379
|
+
* (matches_avg[:, 0] < session_switch[session_a])
|
|
380
|
+
== True
|
|
381
|
+
).squeeze()
|
|
382
|
+
tmp_idx_b = np.argwhere(
|
|
383
|
+
(session_switch[session_b - 1] <= matches_avg[:, 1])
|
|
384
|
+
* (matches_avg[:, 1] < session_switch[session_b])
|
|
385
|
+
== True
|
|
386
|
+
).squeeze()
|
|
369
387
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
370
|
-
option_a = matches_avg[tmp_idx_a[in_both]
|
|
388
|
+
option_a = matches_avg[tmp_idx_a[in_both], :].tolist()
|
|
371
389
|
|
|
372
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
390
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
373
391
|
entry_a.set(option_a[0][0])
|
|
374
392
|
|
|
375
|
-
option_b = np.flip(
|
|
393
|
+
option_b = np.flip(
|
|
394
|
+
np.argsort(
|
|
395
|
+
output_avg[
|
|
396
|
+
int(entry_a.get()),
|
|
397
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
398
|
+
]
|
|
399
|
+
)
|
|
400
|
+
+ session_switch[session_b - 1]
|
|
401
|
+
)
|
|
376
402
|
option_b = option_b.tolist()
|
|
377
403
|
|
|
378
|
-
else
|
|
379
|
-
tmp_idx_a = np.argwhere(
|
|
380
|
-
|
|
404
|
+
else:
|
|
405
|
+
tmp_idx_a = np.argwhere(
|
|
406
|
+
(session_switch[session_a - 1] <= matches_GUI[CV_option][:, 0])
|
|
407
|
+
* (matches_GUI[CV_option][:, 0] < session_switch[session_a])
|
|
408
|
+
== True
|
|
409
|
+
).squeeze()
|
|
410
|
+
tmp_idx_b = np.argwhere(
|
|
411
|
+
(session_switch[session_b - 1] <= matches_GUI[CV_option][:, 1])
|
|
412
|
+
* (matches_GUI[CV_option][:, 1] < session_switch[session_b])
|
|
413
|
+
== True
|
|
414
|
+
).squeeze()
|
|
381
415
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
382
416
|
|
|
383
|
-
option_a =
|
|
417
|
+
option_a = matches_GUI[CV_option][tmp_idx_a[in_both], :].tolist()
|
|
384
418
|
if CV_option == 0:
|
|
385
419
|
option_a = sorted(option_a)
|
|
386
420
|
|
|
387
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
421
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
388
422
|
entry_a.set(option_a[0][0])
|
|
389
423
|
|
|
390
|
-
|
|
391
|
-
|
|
424
|
+
option_b = np.flip(
|
|
425
|
+
np.argsort(
|
|
426
|
+
output_GUI[CV_option][
|
|
427
|
+
int(entry_a.get()),
|
|
428
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
429
|
+
]
|
|
430
|
+
)
|
|
431
|
+
+ session_switch[session_b - 1]
|
|
432
|
+
)
|
|
392
433
|
option_b = option_b.tolist()
|
|
393
434
|
|
|
394
435
|
##################
|
|
395
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
436
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
396
437
|
entry_b.set(option_b[0])
|
|
397
|
-
entry_a.bind(
|
|
398
|
-
entry_b.bind(
|
|
438
|
+
entry_a.bind("<<ComboboxSelected>>", update_units)
|
|
439
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
399
440
|
|
|
400
|
-
session_entry_a.bind(
|
|
401
|
-
session_entry_b.bind(
|
|
441
|
+
session_entry_a.bind("<<ComboboxSelected>>", update_unit_entryA)
|
|
442
|
+
session_entry_b.bind("<<ComboboxSelected>>", update_unit_entryB)
|
|
402
443
|
|
|
403
|
-
#adding a button which swaps unit A and B
|
|
404
|
-
swap_button = ttk.Button(entry_frame, text
|
|
444
|
+
# adding a button which swaps unit A and B
|
|
445
|
+
swap_button = ttk.Button(entry_frame, text="Swap Units", command=swap_units)
|
|
405
446
|
|
|
406
|
-
#Calculate the score histograms
|
|
407
|
-
#for each CV pair
|
|
408
|
-
#make global variable so the functions can access the histograms.
|
|
447
|
+
# Calculate the score histograms
|
|
448
|
+
# for each CV pair
|
|
449
|
+
# make global variable so the functions can access the histograms.
|
|
409
450
|
global hist_names_avg
|
|
410
451
|
global hist_names_12
|
|
411
452
|
global hist_names_21
|
|
@@ -416,31 +457,35 @@ def run_GUI():
|
|
|
416
457
|
global hist_matches_12
|
|
417
458
|
global hist_matches_21
|
|
418
459
|
|
|
419
|
-
hist_names_avg, hist_avg, hist_matches_avg =
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
460
|
+
hist_names_avg, hist_avg, hist_matches_avg = get_score_histograms(
|
|
461
|
+
scores_to_include_avg, (output_avg > match_threshold)
|
|
462
|
+
)
|
|
463
|
+
hist_names_12, hist_12, hist_matches_12 = get_score_histograms(
|
|
464
|
+
scores_to_include_GUI[0], (output_GUI[0] > match_threshold)
|
|
465
|
+
)
|
|
466
|
+
hist_names_21, hist_21, hist_matches_21 = get_score_histograms(
|
|
467
|
+
scores_to_include_GUI[1], (output_GUI[1] > match_threshold)
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
# place the widgets on the EntryFrame
|
|
471
|
+
label_cv.grid(row=0, column=0)
|
|
472
|
+
label_a.grid(row=0, column=1)
|
|
473
|
+
label_b.grid(row=0, column=3)
|
|
474
|
+
label_session_a.grid(row=1, column=1)
|
|
475
|
+
session_entry_a.grid(row=1, column=2, padx=15)
|
|
476
|
+
label_session_b.grid(row=1, column=3)
|
|
477
|
+
session_entry_b.grid(row=1, column=4, padx=15)
|
|
478
|
+
entry_a.grid(row=2, column=1, columnspan=2, stick="WE", padx=5)
|
|
479
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
480
|
+
swap_button.grid(row=3, column=2, columnspan=2, sticky="WE")
|
|
435
481
|
######################################################################################
|
|
436
482
|
|
|
437
|
-
|
|
438
|
-
#MatchButtons
|
|
483
|
+
# MatchButtons
|
|
439
484
|
######################################################################################
|
|
440
|
-
match_button = ttk.Button(root, text
|
|
441
|
-
non_match_button = ttk.Button(root, text=
|
|
485
|
+
match_button = ttk.Button(root, text="Set as Match", command=set_match)
|
|
486
|
+
non_match_button = ttk.Button(root, text="Set as Non Match", command=set_not_match)
|
|
442
487
|
|
|
443
|
-
#Toggle Plots
|
|
488
|
+
# Toggle Plots
|
|
444
489
|
######################################################################################
|
|
445
490
|
toggle_raw_val = BooleanVar()
|
|
446
491
|
toggle_UM_score_val = BooleanVar()
|
|
@@ -448,40 +493,44 @@ def run_GUI():
|
|
|
448
493
|
toggle_raw_val.set(False)
|
|
449
494
|
toggle_UM_score_val.set(False)
|
|
450
495
|
toggle_acg_val.set(True) # Default to hiding ACGs
|
|
451
|
-
toggle_raw_plot = ttk.Checkbutton(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
496
|
+
toggle_raw_plot = ttk.Checkbutton(
|
|
497
|
+
root, text="Hide Raw Data", variable=toggle_raw_val
|
|
498
|
+
)
|
|
499
|
+
toggle_UM_score_plot = ttk.Checkbutton(
|
|
500
|
+
root, text="Hide UM Score Histograms", variable=toggle_UM_score_val
|
|
501
|
+
)
|
|
502
|
+
toggle_acg_plot = ttk.Checkbutton(
|
|
503
|
+
root, text="Hide Autocorrelograms (ACGs)", variable=toggle_acg_val
|
|
504
|
+
)
|
|
456
505
|
|
|
457
506
|
# Set up Key-Board shortcuts
|
|
458
|
-
root.bind_all(
|
|
459
|
-
root.bind_all(
|
|
460
|
-
root.bind_all(
|
|
461
|
-
root.bind_all(
|
|
462
|
-
root.bind_all(
|
|
463
|
-
root.bind_all(
|
|
464
|
-
root.bind_all(
|
|
465
|
-
root.bind_all(
|
|
466
|
-
root.bind_all(
|
|
467
|
-
root.bind_all(
|
|
468
|
-
|
|
469
|
-
#Grid the units
|
|
470
|
-
entry_frame.grid(row
|
|
471
|
-
match_button.grid(row
|
|
472
|
-
non_match_button.grid(row
|
|
473
|
-
toggle_UM_score_plot.grid(row
|
|
474
|
-
toggle_raw_plot.grid(row
|
|
475
|
-
toggle_acg_plot.grid(row
|
|
476
|
-
|
|
507
|
+
root.bind_all("u", update)
|
|
508
|
+
root.bind_all("<Return>", update)
|
|
509
|
+
root.bind_all("<Right>", next_pair)
|
|
510
|
+
root.bind_all("<Left>", previous_pair)
|
|
511
|
+
root.bind_all("<Up>", up_options_b_list)
|
|
512
|
+
root.bind_all("<Down>", down_options_b_list)
|
|
513
|
+
root.bind_all("q", set_match)
|
|
514
|
+
root.bind_all("m", set_match)
|
|
515
|
+
root.bind_all("e", set_not_match)
|
|
516
|
+
root.bind_all("n", set_not_match)
|
|
517
|
+
|
|
518
|
+
# Grid the units
|
|
519
|
+
entry_frame.grid(row=2, column=0, pady=5, padx=5)
|
|
520
|
+
match_button.grid(row=1, column=0, sticky="W", padx=10, pady=5)
|
|
521
|
+
non_match_button.grid(row=1, column=1, sticky="W", padx=10, pady=5)
|
|
522
|
+
toggle_UM_score_plot.grid(row=1, column=2, sticky="W", padx=10, pady=5)
|
|
523
|
+
toggle_raw_plot.grid(row=1, column=3, sticky="W", padx=10, pady=5)
|
|
524
|
+
toggle_acg_plot.grid(row=1, column=4, sticky="W", padx=10, pady=5)
|
|
525
|
+
|
|
477
526
|
# Create visual legend plots outside plots
|
|
478
527
|
global unit_legend_plot
|
|
479
528
|
global hist_legend_plot
|
|
480
529
|
create_unit_legend()
|
|
481
530
|
create_hist_legend()
|
|
482
|
-
|
|
483
|
-
unit_legend_plot.grid(row
|
|
484
|
-
hist_legend_plot.grid(row
|
|
531
|
+
|
|
532
|
+
unit_legend_plot.grid(row=0, column=1, columnspan=2, sticky="W", padx=10, pady=5)
|
|
533
|
+
hist_legend_plot.grid(row=0, column=3, columnspan=4, sticky="W", padx=10, pady=5)
|
|
485
534
|
|
|
486
535
|
# Configure grid weights to auto-adjust subpanels
|
|
487
536
|
root.grid_rowconfigure(0, weight=1)
|
|
@@ -494,18 +543,35 @@ def run_GUI():
|
|
|
494
543
|
|
|
495
544
|
root.mainloop()
|
|
496
545
|
|
|
497
|
-
#set default plot color back to black
|
|
498
|
-
color =
|
|
499
|
-
rcParams[
|
|
500
|
-
rcParams[
|
|
501
|
-
rcParams[
|
|
502
|
-
rcParams[
|
|
546
|
+
# set default plot color back to black
|
|
547
|
+
color = "black"
|
|
548
|
+
rcParams["text.color"] = color
|
|
549
|
+
rcParams["axes.labelcolor"] = color
|
|
550
|
+
rcParams["xtick.color"] = color
|
|
551
|
+
rcParams["ytick.color"] = color
|
|
503
552
|
|
|
504
553
|
return is_match, not_match, matches_GUI
|
|
505
554
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
555
|
+
|
|
556
|
+
def process_info_for_GUI(
|
|
557
|
+
output,
|
|
558
|
+
match_threshold_in,
|
|
559
|
+
scores_to_include,
|
|
560
|
+
total_score,
|
|
561
|
+
amplitude_in,
|
|
562
|
+
spatial_decay_in,
|
|
563
|
+
avg_centroid_in,
|
|
564
|
+
avg_waveform_in,
|
|
565
|
+
avg_waveform_per_tp_in,
|
|
566
|
+
wave_idx_in,
|
|
567
|
+
max_site_in,
|
|
568
|
+
max_site_mean_in,
|
|
569
|
+
waveform_in,
|
|
570
|
+
within_session_in,
|
|
571
|
+
channel_pos_in,
|
|
572
|
+
clus_info_in,
|
|
573
|
+
param_in,
|
|
574
|
+
):
|
|
509
575
|
"""
|
|
510
576
|
This function:
|
|
511
577
|
1 - passes data to the GUI
|
|
@@ -548,7 +614,7 @@ def process_info_for_GUI(output, match_threshold_in, scores_to_include, total_sc
|
|
|
548
614
|
max_site_mean = max_site_mean_in
|
|
549
615
|
waveform = waveform_in
|
|
550
616
|
clus_info = clus_info_in
|
|
551
|
-
session_switch = clus_info[
|
|
617
|
+
session_switch = clus_info["session_switch"]
|
|
552
618
|
param = param_in
|
|
553
619
|
match_threshold = match_threshold_in
|
|
554
620
|
within_session = within_session_in
|
|
@@ -557,19 +623,23 @@ def process_info_for_GUI(output, match_threshold_in, scores_to_include, total_sc
|
|
|
557
623
|
output_threshold = np.zeros_like(output)
|
|
558
624
|
output_threshold[output > match_threshold] = 1
|
|
559
625
|
|
|
560
|
-
matches = np.argwhere(
|
|
561
|
-
|
|
626
|
+
matches = np.argwhere(
|
|
627
|
+
output_threshold == 1
|
|
628
|
+
) # need all matches including same session for GUI
|
|
562
629
|
|
|
563
|
-
#for the code it is helpful for matches to contain both (session 1, session 2) and (session 2, session 1)
|
|
630
|
+
# for the code it is helpful for matches to contain both (session 1, session 2) and (session 2, session 1)
|
|
564
631
|
# so when changing Unit A/B session it can find matches for all permutations
|
|
565
|
-
matches_12_part_1 = np.argwhere(np.tril(output) > match_threshold)
|
|
632
|
+
matches_12_part_1 = np.argwhere(np.tril(output) > match_threshold)
|
|
566
633
|
matches_12_part_2 = np.argwhere(np.tril(output).T > match_threshold)
|
|
567
|
-
matches_12 = np.unique(
|
|
634
|
+
matches_12 = np.unique(
|
|
635
|
+
np.concatenate((matches_12_part_1, matches_12_part_2)), axis=0
|
|
636
|
+
)
|
|
568
637
|
|
|
569
|
-
|
|
570
|
-
matches_21_part_1 = np.argwhere(np.triu(output) > match_threshold)
|
|
638
|
+
matches_21_part_1 = np.argwhere(np.triu(output) > match_threshold)
|
|
571
639
|
matches_21_part_2 = np.argwhere(np.triu(output).T > match_threshold)
|
|
572
|
-
matches_21 = np.unique(
|
|
640
|
+
matches_21 = np.unique(
|
|
641
|
+
np.concatenate((matches_21_part_1, matches_21_part_2)), axis=0
|
|
642
|
+
)
|
|
573
643
|
|
|
574
644
|
matches_GUI = [matches_12, matches_21]
|
|
575
645
|
|
|
@@ -597,15 +667,14 @@ def process_info_for_GUI(output, match_threshold_in, scores_to_include, total_sc
|
|
|
597
667
|
tmp4 = np.triu(value).T
|
|
598
668
|
np.fill_diagonal(tmp4, 0)
|
|
599
669
|
|
|
600
|
-
scores_to_include_12[key] = tmp1 + tmp2
|
|
601
|
-
scores_to_include_21[key] = tmp3 + tmp4
|
|
670
|
+
scores_to_include_12[key] = tmp1 + tmp2
|
|
671
|
+
scores_to_include_21[key] = tmp3 + tmp4
|
|
602
672
|
|
|
603
673
|
scores_to_include_GUI = [scores_to_include_12, scores_to_include_21]
|
|
604
674
|
|
|
605
|
-
|
|
606
|
-
#getting avg CV data
|
|
675
|
+
# getting avg CV data
|
|
607
676
|
# for the Scores where can do (X + X.T)/2 and take upper triangular part
|
|
608
|
-
total_score_avg = np.triu(
|
|
677
|
+
total_score_avg = np.triu((total_score + total_score.T) / 2)
|
|
609
678
|
|
|
610
679
|
scores_to_include_avg = {}
|
|
611
680
|
for key, value in scores_to_include.items():
|
|
@@ -613,74 +682,79 @@ def process_info_for_GUI(output, match_threshold_in, scores_to_include, total_sc
|
|
|
613
682
|
|
|
614
683
|
output_avg = (output_GUI[0] + output_GUI[1]) / 2
|
|
615
684
|
|
|
616
|
-
matches_avg_part_1 = np.argwhere(
|
|
617
|
-
matches_avg_part_2 = np.argwhere(
|
|
618
|
-
matches_avg = np.unique(
|
|
685
|
+
matches_avg_part_1 = np.argwhere(output_avg > match_threshold)
|
|
686
|
+
matches_avg_part_2 = np.argwhere(output_avg.T > match_threshold)
|
|
687
|
+
matches_avg = np.unique(
|
|
688
|
+
np.concatenate((matches_avg_part_1, matches_avg_part_2)), axis=0
|
|
689
|
+
)
|
|
619
690
|
|
|
620
691
|
# or an simply average over both CV
|
|
621
|
-
amplitude_avg = np.mean(amplitude, axis
|
|
622
|
-
spatial_decay_avg = np.mean(spatial_decay, axis
|
|
623
|
-
avg_centroid_avg = np.mean(avg_centroid, axis
|
|
624
|
-
avg_waveform_avg = np.mean(avg_waveform, axis
|
|
625
|
-
avg_waveform_per_tp_avg = np.mean(avg_waveform_per_tp, axis
|
|
692
|
+
amplitude_avg = np.mean(amplitude, axis=-1)
|
|
693
|
+
spatial_decay_avg = np.mean(spatial_decay, axis=-1)
|
|
694
|
+
avg_centroid_avg = np.mean(avg_centroid, axis=-1)
|
|
695
|
+
avg_waveform_avg = np.mean(avg_waveform, axis=-1)
|
|
696
|
+
avg_waveform_per_tp_avg = np.mean(avg_waveform_per_tp, axis=-1)
|
|
697
|
+
|
|
626
698
|
|
|
627
699
|
def create_unit_legend():
|
|
628
700
|
"""Create visual legend for unit colors"""
|
|
629
701
|
global unit_legend_plot
|
|
630
|
-
|
|
702
|
+
|
|
631
703
|
fig = Figure(figsize=(6, 0.5), dpi=100)
|
|
632
|
-
fig.patch.set_facecolor(
|
|
633
|
-
|
|
704
|
+
fig.patch.set_facecolor("#33393b")
|
|
705
|
+
|
|
634
706
|
ax = fig.add_subplot(111)
|
|
635
|
-
ax.set_facecolor(
|
|
636
|
-
|
|
707
|
+
ax.set_facecolor("#33393b")
|
|
708
|
+
|
|
637
709
|
# Draw legend lines and text
|
|
638
|
-
ax.plot([0, 0.15], [0.5, 0.5],
|
|
639
|
-
ax.text(0.18, 0.5,
|
|
640
|
-
|
|
641
|
-
ax.plot([0.6, 0.75], [0.5, 0.5],
|
|
642
|
-
ax.text(0.78, 0.5,
|
|
643
|
-
|
|
710
|
+
ax.plot([0, 0.15], [0.5, 0.5], "g-", lw=3)
|
|
711
|
+
ax.text(0.18, 0.5, "Unit A", color="white", fontsize=12, va="center")
|
|
712
|
+
|
|
713
|
+
ax.plot([0.6, 0.75], [0.5, 0.5], "b-", lw=3)
|
|
714
|
+
ax.text(0.78, 0.5, "Unit B", color="white", fontsize=12, va="center")
|
|
715
|
+
|
|
644
716
|
ax.set_xlim(0, 1.2)
|
|
645
717
|
ax.set_ylim(0, 1)
|
|
646
|
-
ax.axis(
|
|
647
|
-
|
|
718
|
+
ax.axis("off")
|
|
719
|
+
|
|
648
720
|
unit_legend_plot = FigureCanvasTkAgg(fig, master=root)
|
|
649
721
|
unit_legend_plot.draw()
|
|
650
722
|
unit_legend_plot = unit_legend_plot.get_tk_widget()
|
|
651
723
|
|
|
724
|
+
|
|
652
725
|
def create_hist_legend():
|
|
653
726
|
"""Create visual legend for histogram colors"""
|
|
654
727
|
global hist_legend_plot
|
|
655
|
-
|
|
728
|
+
|
|
656
729
|
fig = Figure(figsize=(8, 0.5), dpi=100)
|
|
657
|
-
fig.patch.set_facecolor(
|
|
658
|
-
|
|
730
|
+
fig.patch.set_facecolor("#33393b")
|
|
731
|
+
|
|
659
732
|
ax = fig.add_subplot(111)
|
|
660
|
-
ax.set_facecolor(
|
|
661
|
-
|
|
733
|
+
ax.set_facecolor("#33393b")
|
|
734
|
+
|
|
662
735
|
# Draw legend elements
|
|
663
|
-
ax.plot([0, 0.1], [0.5, 0.5],
|
|
664
|
-
ax.text(0.12, 0.5,
|
|
665
|
-
|
|
666
|
-
ax.plot([0.35, 0.45], [0.5, 0.5],
|
|
667
|
-
ax.text(0.47, 0.5,
|
|
668
|
-
|
|
669
|
-
ax.plot([0.75, 0.85], [0.5, 0.5],
|
|
670
|
-
ax.text(0.87, 0.5,
|
|
671
|
-
|
|
736
|
+
ax.plot([0, 0.1], [0.5, 0.5], "orange", lw=3)
|
|
737
|
+
ax.text(0.12, 0.5, "All scores", color="white", fontsize=10, va="center")
|
|
738
|
+
|
|
739
|
+
ax.plot([0.35, 0.45], [0.5, 0.5], "magenta", lw=3)
|
|
740
|
+
ax.text(0.47, 0.5, "Expected matches", color="white", fontsize=10, va="center")
|
|
741
|
+
|
|
742
|
+
ax.plot([0.75, 0.85], [0.5, 0.5], "white", lw=2, linestyle="--")
|
|
743
|
+
ax.text(0.87, 0.5, "Current pair", color="white", fontsize=10, va="center")
|
|
744
|
+
|
|
672
745
|
ax.set_xlim(0, 1.2)
|
|
673
746
|
ax.set_ylim(0, 1)
|
|
674
|
-
ax.axis(
|
|
675
|
-
|
|
747
|
+
ax.axis("off")
|
|
748
|
+
|
|
676
749
|
hist_legend_plot = FigureCanvasTkAgg(fig, master=root)
|
|
677
750
|
hist_legend_plot.draw()
|
|
678
751
|
hist_legend_plot = hist_legend_plot.get_tk_widget()
|
|
679
752
|
|
|
753
|
+
|
|
680
754
|
def compute_acg(spike_times, bin_size=0.001, max_lag=0.05):
|
|
681
755
|
"""
|
|
682
756
|
Compute autocorrelogram for a unit
|
|
683
|
-
|
|
757
|
+
|
|
684
758
|
Parameters
|
|
685
759
|
----------
|
|
686
760
|
spike_times : array
|
|
@@ -689,7 +763,7 @@ def compute_acg(spike_times, bin_size=0.001, max_lag=0.05):
|
|
|
689
763
|
Bin size in seconds (default 1ms)
|
|
690
764
|
max_lag : float
|
|
691
765
|
Maximum lag in seconds (default 50ms)
|
|
692
|
-
|
|
766
|
+
|
|
693
767
|
Returns
|
|
694
768
|
-------
|
|
695
769
|
autocorr : array
|
|
@@ -699,59 +773,65 @@ def compute_acg(spike_times, bin_size=0.001, max_lag=0.05):
|
|
|
699
773
|
"""
|
|
700
774
|
if len(spike_times) < 2:
|
|
701
775
|
return np.array([]), np.array([])
|
|
702
|
-
|
|
776
|
+
|
|
703
777
|
# Create bins centered around 0
|
|
704
778
|
bins = np.arange(-max_lag, max_lag + bin_size, bin_size)
|
|
705
|
-
bin_centers = bins[:-1] + bin_size/2
|
|
706
|
-
|
|
779
|
+
bin_centers = bins[:-1] + bin_size / 2
|
|
780
|
+
|
|
707
781
|
# Calculate autocorrelogram
|
|
708
782
|
autocorr = np.zeros(len(bin_centers))
|
|
709
|
-
|
|
783
|
+
|
|
710
784
|
# For efficiency, subsample spikes if there are too many
|
|
711
785
|
if len(spike_times) > 10000:
|
|
712
786
|
indices = np.random.choice(len(spike_times), 10000, replace=False)
|
|
713
787
|
spike_subset = spike_times[indices]
|
|
714
788
|
else:
|
|
715
789
|
spike_subset = spike_times
|
|
716
|
-
|
|
717
|
-
# Calculate cross-correlation with itself
|
|
790
|
+
|
|
791
|
+
# Calculate cross-correlation with itself
|
|
718
792
|
for i, spike_time in enumerate(spike_subset[::10]): # Subsample further for speed
|
|
719
793
|
# Find spikes within max_lag of this spike
|
|
720
794
|
time_diffs = spike_times - spike_time
|
|
721
795
|
valid_diffs = time_diffs[(np.abs(time_diffs) <= max_lag) & (time_diffs != 0)]
|
|
722
|
-
|
|
796
|
+
|
|
723
797
|
if len(valid_diffs) > 0:
|
|
724
798
|
hist, _ = np.histogram(valid_diffs, bins=bins)
|
|
725
799
|
autocorr += hist
|
|
726
|
-
|
|
800
|
+
|
|
727
801
|
# Convert to firing rate (spikes/sec)
|
|
728
802
|
if len(spike_subset) > 0:
|
|
729
|
-
recording_duration =
|
|
730
|
-
|
|
731
|
-
|
|
803
|
+
recording_duration = (
|
|
804
|
+
np.max(spike_times) - np.min(spike_times) if len(spike_times) > 0 else 1
|
|
805
|
+
)
|
|
806
|
+
autocorr = (
|
|
807
|
+
autocorr / (len(spike_subset) * bin_size)
|
|
808
|
+
if recording_duration > 0
|
|
809
|
+
else autocorr
|
|
810
|
+
)
|
|
811
|
+
|
|
732
812
|
return autocorr, bin_centers
|
|
733
813
|
|
|
814
|
+
|
|
734
815
|
def plot_acgs(unit_a, unit_b):
|
|
735
816
|
"""Plot autocorrelograms for both units overlaid in single plot"""
|
|
736
817
|
global acg_plot
|
|
737
818
|
global clus_info
|
|
738
819
|
global acg_cache
|
|
739
|
-
|
|
820
|
+
|
|
740
821
|
# Destroy existing plot
|
|
741
|
-
if
|
|
822
|
+
if "acg_plot" in globals() and acg_plot.winfo_exists():
|
|
742
823
|
acg_plot.destroy()
|
|
743
|
-
|
|
744
|
-
|
|
824
|
+
|
|
745
825
|
# Create figure for single overlaid ACG plot
|
|
746
826
|
fig = Figure(figsize=(3, 3), dpi=100)
|
|
747
|
-
fig.patch.set_facecolor(
|
|
748
|
-
|
|
827
|
+
fig.patch.set_facecolor("#33393b")
|
|
828
|
+
|
|
749
829
|
# Create single subplot for overlaid ACGs
|
|
750
830
|
ax = fig.add_subplot(1, 1, 1)
|
|
751
|
-
ax.set_facecolor(
|
|
752
|
-
|
|
831
|
+
ax.set_facecolor("#2d2d2d")
|
|
832
|
+
|
|
753
833
|
max_rate = 0 # Track max rate for y-axis scaling
|
|
754
|
-
|
|
834
|
+
|
|
755
835
|
# Try to get ACGs from cache first, otherwise compute them
|
|
756
836
|
try:
|
|
757
837
|
# Get ACG for Unit A
|
|
@@ -765,17 +845,25 @@ def plot_acgs(unit_a, unit_b):
|
|
|
765
845
|
autocorr_a, bin_centers_a = compute_acg(spike_times_a)
|
|
766
846
|
else:
|
|
767
847
|
autocorr_a, bin_centers_a = np.array([]), np.array([])
|
|
768
|
-
|
|
848
|
+
|
|
769
849
|
# Plot ACG for Unit A
|
|
770
850
|
if len(autocorr_a) > 0:
|
|
771
851
|
positive_mask = bin_centers_a >= 0
|
|
772
852
|
positive_centers = bin_centers_a[positive_mask] * 1000 # Convert to ms
|
|
773
853
|
positive_autocorr = autocorr_a[positive_mask]
|
|
774
|
-
|
|
775
|
-
ax.plot(
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
854
|
+
|
|
855
|
+
ax.plot(
|
|
856
|
+
positive_centers,
|
|
857
|
+
positive_autocorr,
|
|
858
|
+
color="green",
|
|
859
|
+
linewidth=2,
|
|
860
|
+
alpha=0.8,
|
|
861
|
+
label=f"Unit A ({unit_a})",
|
|
862
|
+
)
|
|
863
|
+
max_rate = max(
|
|
864
|
+
max_rate, np.max(positive_autocorr) if len(positive_autocorr) > 0 else 0
|
|
865
|
+
)
|
|
866
|
+
|
|
779
867
|
# Get ACG for Unit B
|
|
780
868
|
if acg_cache is not None and unit_b in acg_cache:
|
|
781
869
|
# Use cached ACG
|
|
@@ -787,64 +875,80 @@ def plot_acgs(unit_a, unit_b):
|
|
|
787
875
|
autocorr_b, bin_centers_b = compute_acg(spike_times_b)
|
|
788
876
|
else:
|
|
789
877
|
autocorr_b, bin_centers_b = np.array([]), np.array([])
|
|
790
|
-
|
|
878
|
+
|
|
791
879
|
# Plot ACG for Unit B
|
|
792
880
|
if len(autocorr_b) > 0:
|
|
793
881
|
positive_mask = bin_centers_b >= 0
|
|
794
882
|
positive_centers = bin_centers_b[positive_mask] * 1000 # Convert to ms
|
|
795
883
|
positive_autocorr = autocorr_b[positive_mask]
|
|
796
|
-
|
|
797
|
-
ax.plot(
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
884
|
+
|
|
885
|
+
ax.plot(
|
|
886
|
+
positive_centers,
|
|
887
|
+
positive_autocorr,
|
|
888
|
+
color="blue",
|
|
889
|
+
linewidth=2,
|
|
890
|
+
alpha=0.8,
|
|
891
|
+
label=f"Unit B ({unit_b})",
|
|
892
|
+
)
|
|
893
|
+
max_rate = max(
|
|
894
|
+
max_rate, np.max(positive_autocorr) if len(positive_autocorr) > 0 else 0
|
|
895
|
+
)
|
|
896
|
+
|
|
801
897
|
# Set labels and title
|
|
802
|
-
ax.set_xlabel(
|
|
803
|
-
ax.set_ylabel(
|
|
804
|
-
ax.set_title(
|
|
898
|
+
ax.set_xlabel("Time lag (ms)", fontsize=10, color="white")
|
|
899
|
+
ax.set_ylabel("Rate (Hz)", fontsize=10, color="white")
|
|
900
|
+
ax.set_title("Autocorrelograms", fontsize=12, color="white")
|
|
805
901
|
ax.set_xlim(0, 50) # 50ms
|
|
806
902
|
if max_rate > 0:
|
|
807
903
|
ax.set_ylim(0, max_rate * 1.1)
|
|
808
|
-
|
|
904
|
+
|
|
809
905
|
# Add legend
|
|
810
|
-
legend = ax.legend(fontsize=8, loc=
|
|
811
|
-
legend.get_frame().set_facecolor(
|
|
906
|
+
legend = ax.legend(fontsize=8, loc="upper right")
|
|
907
|
+
legend.get_frame().set_facecolor("#33393b")
|
|
812
908
|
legend.get_frame().set_alpha(0.8)
|
|
813
909
|
for text in legend.get_texts():
|
|
814
|
-
text.set_color(
|
|
815
|
-
|
|
910
|
+
text.set_color("white")
|
|
911
|
+
|
|
816
912
|
# Style the plot
|
|
817
|
-
ax.tick_params(colors=
|
|
818
|
-
ax.spines[
|
|
819
|
-
ax.spines[
|
|
820
|
-
ax.spines[
|
|
821
|
-
ax.spines[
|
|
822
|
-
|
|
823
|
-
except Exception
|
|
913
|
+
ax.tick_params(colors="white", labelsize=8)
|
|
914
|
+
ax.spines["bottom"].set_color("white")
|
|
915
|
+
ax.spines["left"].set_color("white")
|
|
916
|
+
ax.spines["top"].set_visible(False)
|
|
917
|
+
ax.spines["right"].set_visible(False)
|
|
918
|
+
|
|
919
|
+
except Exception:
|
|
824
920
|
# If spike times not available, show placeholder
|
|
825
921
|
ax = fig.add_subplot(1, 1, 1)
|
|
826
|
-
ax.set_facecolor(
|
|
827
|
-
ax.text(
|
|
828
|
-
|
|
922
|
+
ax.set_facecolor("#2d2d2d")
|
|
923
|
+
ax.text(
|
|
924
|
+
0.5,
|
|
925
|
+
0.5,
|
|
926
|
+
"ACG data\nnot available",
|
|
927
|
+
ha="center",
|
|
928
|
+
va="center",
|
|
929
|
+
color="white",
|
|
930
|
+
fontsize=12,
|
|
931
|
+
)
|
|
829
932
|
ax.set_xlim(0, 1)
|
|
830
933
|
ax.set_ylim(0, 1)
|
|
831
|
-
ax.axis(
|
|
832
|
-
|
|
934
|
+
ax.axis("off")
|
|
935
|
+
|
|
833
936
|
# Create canvas and position to the right of waveform plot
|
|
834
937
|
acg_canvas = FigureCanvasTkAgg(fig, master=root)
|
|
835
938
|
acg_canvas.draw()
|
|
836
939
|
acg_plot = acg_canvas.get_tk_widget()
|
|
837
|
-
acg_plot.grid(row=3, column=3, rowspan=2, padx=5, pady=5, sticky=
|
|
940
|
+
acg_plot.grid(row=3, column=3, rowspan=2, padx=5, pady=5, sticky="nsew")
|
|
941
|
+
|
|
838
942
|
|
|
839
943
|
def get_spike_times_for_unit(unit_id):
|
|
840
944
|
"""
|
|
841
945
|
Get spike times for a specific unit from Kilosort data
|
|
842
|
-
|
|
946
|
+
|
|
843
947
|
Parameters
|
|
844
948
|
----------
|
|
845
949
|
unit_id : int
|
|
846
950
|
UnitMatch unit ID
|
|
847
|
-
|
|
951
|
+
|
|
848
952
|
Returns
|
|
849
953
|
-------
|
|
850
954
|
spike_times : array
|
|
@@ -853,36 +957,36 @@ def get_spike_times_for_unit(unit_id):
|
|
|
853
957
|
try:
|
|
854
958
|
# Get session information for this unit
|
|
855
959
|
global clus_info, param
|
|
856
|
-
session_id = clus_info[
|
|
857
|
-
original_id = clus_info[
|
|
858
|
-
|
|
960
|
+
session_id = clus_info["session_id"][unit_id]
|
|
961
|
+
original_id = clus_info["original_ids"][unit_id]
|
|
962
|
+
|
|
859
963
|
# Get the Kilosort directory for this session
|
|
860
|
-
if
|
|
861
|
-
ks_dir = param[
|
|
964
|
+
if "KS_dirs" in param:
|
|
965
|
+
ks_dir = param["KS_dirs"][session_id]
|
|
862
966
|
else:
|
|
863
967
|
# Try to infer from existing paths
|
|
864
968
|
return np.array([])
|
|
865
|
-
|
|
969
|
+
|
|
866
970
|
# Load Kilosort spike times and cluster assignments
|
|
867
|
-
spike_times_path = os.path.join(ks_dir,
|
|
868
|
-
spike_clusters_path = os.path.join(ks_dir,
|
|
869
|
-
|
|
971
|
+
spike_times_path = os.path.join(ks_dir, "spike_times.npy")
|
|
972
|
+
spike_clusters_path = os.path.join(ks_dir, "spike_clusters.npy")
|
|
973
|
+
|
|
870
974
|
if os.path.exists(spike_times_path) and os.path.exists(spike_clusters_path):
|
|
871
975
|
# Load spike times (in samples) and cluster assignments
|
|
872
976
|
spike_times_samples = np.load(spike_times_path).flatten()
|
|
873
977
|
spike_clusters = np.load(spike_clusters_path).flatten()
|
|
874
|
-
|
|
978
|
+
|
|
875
979
|
# Get sampling rate - try to load from params.py or use default
|
|
876
980
|
try:
|
|
877
|
-
params_path = os.path.join(ks_dir,
|
|
981
|
+
params_path = os.path.join(ks_dir, "params.py")
|
|
878
982
|
if os.path.exists(params_path):
|
|
879
983
|
# Parse params.py for sample_rate
|
|
880
|
-
with open(params_path,
|
|
984
|
+
with open(params_path, "r") as f:
|
|
881
985
|
params_content = f.read()
|
|
882
986
|
# Extract sample_rate
|
|
883
|
-
for line in params_content.split(
|
|
884
|
-
if
|
|
885
|
-
sample_rate = float(line.split(
|
|
987
|
+
for line in params_content.split("\n"):
|
|
988
|
+
if "sample_rate" in line and "=" in line:
|
|
989
|
+
sample_rate = float(line.split("=")[1].strip())
|
|
886
990
|
break
|
|
887
991
|
else:
|
|
888
992
|
sample_rate = 30000.0 # Default Neuropixels sample rate
|
|
@@ -890,32 +994,33 @@ def get_spike_times_for_unit(unit_id):
|
|
|
890
994
|
sample_rate = 30000.0 # Default
|
|
891
995
|
except:
|
|
892
996
|
sample_rate = 30000.0 # Default
|
|
893
|
-
|
|
997
|
+
|
|
894
998
|
# Filter spikes for this unit
|
|
895
999
|
unit_mask = spike_clusters == int(original_id)
|
|
896
1000
|
unit_spike_times = spike_times_samples[unit_mask]
|
|
897
|
-
|
|
1001
|
+
|
|
898
1002
|
# Convert to seconds
|
|
899
1003
|
unit_spike_times_sec = unit_spike_times / sample_rate
|
|
900
|
-
|
|
1004
|
+
|
|
901
1005
|
return unit_spike_times_sec
|
|
902
1006
|
else:
|
|
903
1007
|
print(f"Could not find spike_times.npy or spike_clusters.npy in {ks_dir}")
|
|
904
1008
|
return np.array([])
|
|
905
|
-
|
|
1009
|
+
|
|
906
1010
|
except Exception as e:
|
|
907
1011
|
print(f"Error loading spike times for unit {unit_id}: {e}")
|
|
908
1012
|
return np.array([])
|
|
909
1013
|
|
|
1014
|
+
|
|
910
1015
|
def update(event):
|
|
911
1016
|
"""
|
|
912
1017
|
Updates the GUI.
|
|
913
1018
|
"""
|
|
914
|
-
|
|
1019
|
+
|
|
915
1020
|
unit_a = int(entry_a.get())
|
|
916
1021
|
unit_b = int(entry_b.get())
|
|
917
1022
|
|
|
918
|
-
CV = get_cv_option()
|
|
1023
|
+
CV = get_cv_option() # CV = 'Avg', if AVG is selcted else it equal [0,1] or [1,0]
|
|
919
1024
|
CV_option = CV_tkinter.get() - 1
|
|
920
1025
|
|
|
921
1026
|
table = get_table_data(unit_a, unit_b, CV)
|
|
@@ -937,27 +1042,48 @@ def update(event):
|
|
|
937
1042
|
add_original_ID(unit_a, unit_b)
|
|
938
1043
|
|
|
939
1044
|
if toggle_UM_score_val.get() is False:
|
|
940
|
-
#plot histograms based of off the CV
|
|
1045
|
+
# plot histograms based of off the CV
|
|
941
1046
|
if CV_option == -1:
|
|
942
|
-
plot_histograms(
|
|
1047
|
+
plot_histograms(
|
|
1048
|
+
hist_names_avg,
|
|
1049
|
+
hist_avg,
|
|
1050
|
+
hist_matches_avg,
|
|
1051
|
+
scores_to_include_avg,
|
|
1052
|
+
unit_a,
|
|
1053
|
+
unit_b,
|
|
1054
|
+
)
|
|
943
1055
|
if CV_option == 0:
|
|
944
|
-
plot_histograms(
|
|
1056
|
+
plot_histograms(
|
|
1057
|
+
hist_names_12,
|
|
1058
|
+
hist_12,
|
|
1059
|
+
hist_matches_12,
|
|
1060
|
+
scores_to_include_GUI[CV_option],
|
|
1061
|
+
unit_a,
|
|
1062
|
+
unit_b,
|
|
1063
|
+
)
|
|
945
1064
|
if CV_option == 1:
|
|
946
|
-
plot_histograms(
|
|
1065
|
+
plot_histograms(
|
|
1066
|
+
hist_names_21,
|
|
1067
|
+
hist_21,
|
|
1068
|
+
hist_matches_21,
|
|
1069
|
+
scores_to_include_GUI[CV_option],
|
|
1070
|
+
unit_a,
|
|
1071
|
+
unit_b,
|
|
1072
|
+
)
|
|
947
1073
|
else:
|
|
948
1074
|
if hist_plot.winfo_exists() == 1:
|
|
949
1075
|
hist_plot.destroy()
|
|
950
|
-
|
|
1076
|
+
|
|
951
1077
|
# Plot ACGs for both units if not hidden
|
|
952
1078
|
if toggle_acg_val.get() is False:
|
|
953
1079
|
plot_acgs(unit_a, unit_b)
|
|
954
1080
|
else:
|
|
955
|
-
if
|
|
1081
|
+
if "acg_plot" in globals() and acg_plot.winfo_exists() == 1:
|
|
956
1082
|
acg_plot.destroy()
|
|
957
|
-
|
|
1083
|
+
|
|
958
1084
|
|
|
959
1085
|
def up_options_b_list(event):
|
|
960
|
-
"""
|
|
1086
|
+
"""
|
|
961
1087
|
moves up the option B list, chose the unit with th next highest probabilty of being a match with unit A.
|
|
962
1088
|
"""
|
|
963
1089
|
global entry_frame
|
|
@@ -971,26 +1097,26 @@ def up_options_b_list(event):
|
|
|
971
1097
|
if current_idx == 0:
|
|
972
1098
|
return
|
|
973
1099
|
else:
|
|
974
|
-
current_idx -=1
|
|
1100
|
+
current_idx -= 1
|
|
975
1101
|
if entry_b.winfo_exists() == 1:
|
|
976
|
-
|
|
1102
|
+
entry_b.destroy()
|
|
977
1103
|
|
|
978
1104
|
new_entry_b = tmp_list[current_idx]
|
|
979
1105
|
|
|
980
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
981
|
-
entry_b.set(new_entry_b
|
|
982
|
-
entry_b.bind(
|
|
1106
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1107
|
+
entry_b.set(new_entry_b)
|
|
1108
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
983
1109
|
|
|
984
|
-
entry_b.grid(row
|
|
1110
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
985
1111
|
|
|
986
1112
|
update(event)
|
|
987
1113
|
|
|
988
1114
|
|
|
989
1115
|
def down_options_b_list(event):
|
|
990
|
-
"""
|
|
1116
|
+
"""
|
|
991
1117
|
moves down the option B list, chose the unit with th next highest probabilty of being a match with unit A.
|
|
992
1118
|
"""
|
|
993
|
-
global entry_frame
|
|
1119
|
+
global entry_frame
|
|
994
1120
|
global option_b
|
|
995
1121
|
global entry_b
|
|
996
1122
|
|
|
@@ -998,40 +1124,42 @@ def down_options_b_list(event):
|
|
|
998
1124
|
|
|
999
1125
|
tmp_list = np.asarray(option_b)
|
|
1000
1126
|
current_idx = int(np.argwhere(tmp_list == tmp_entry_b))
|
|
1001
|
-
if current_idx == (len(tmp_list) -1):
|
|
1127
|
+
if current_idx == (len(tmp_list) - 1):
|
|
1002
1128
|
return
|
|
1003
1129
|
else:
|
|
1004
|
-
current_idx +=1
|
|
1130
|
+
current_idx += 1
|
|
1005
1131
|
if entry_b.winfo_exists() == 1:
|
|
1006
1132
|
entry_b.destroy()
|
|
1007
1133
|
|
|
1008
1134
|
new_entry_b = tmp_list[current_idx]
|
|
1009
1135
|
|
|
1010
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1136
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1011
1137
|
entry_b.set(new_entry_b)
|
|
1012
|
-
entry_b.bind(
|
|
1138
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1013
1139
|
|
|
1014
|
-
entry_b.grid(row
|
|
1140
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1015
1141
|
|
|
1016
1142
|
update(event)
|
|
1017
1143
|
|
|
1018
|
-
|
|
1144
|
+
|
|
1145
|
+
# sort CV function as to be calleed as part of update
|
|
1019
1146
|
def get_cv_option():
|
|
1020
1147
|
"""
|
|
1021
1148
|
Will read in the values of the radio button and assign an appropriate value to CV.
|
|
1022
|
-
In general this is a list where itis [Unit A cv, UnitB cv], however it could be the string 'Avg'
|
|
1149
|
+
In general this is a list where itis [Unit A cv, UnitB cv], however it could be the string 'Avg'
|
|
1023
1150
|
"""
|
|
1024
1151
|
global CV_tkinter
|
|
1025
1152
|
ChosenOption = CV_tkinter.get()
|
|
1026
1153
|
if ChosenOption == 0:
|
|
1027
|
-
CV =
|
|
1154
|
+
CV = "Avg"
|
|
1028
1155
|
elif ChosenOption == 1:
|
|
1029
1156
|
CV = [0, 1]
|
|
1030
1157
|
elif ChosenOption == 2:
|
|
1031
|
-
CV = [1, 0]
|
|
1158
|
+
CV = [1, 0]
|
|
1032
1159
|
return CV
|
|
1033
1160
|
|
|
1034
|
-
|
|
1161
|
+
|
|
1162
|
+
# These are the function used to selct units, including how the CV selctition radio buttons, session selction, unitselection andmoving left and rigthfor next units
|
|
1035
1163
|
def update_unit_cv():
|
|
1036
1164
|
"""
|
|
1037
1165
|
When updating the CV we need to do /not do the following:
|
|
@@ -1046,12 +1174,12 @@ def update_unit_cv():
|
|
|
1046
1174
|
global session_entry_a
|
|
1047
1175
|
global session_entry_b
|
|
1048
1176
|
global match_idx
|
|
1049
|
-
|
|
1050
|
-
#selecting the unit
|
|
1177
|
+
|
|
1178
|
+
# selecting the unit
|
|
1051
1179
|
session_a = int(session_entry_a.get())
|
|
1052
|
-
session_b = int(session_entry_b.get())
|
|
1180
|
+
session_b = int(session_entry_b.get())
|
|
1053
1181
|
|
|
1054
|
-
#Keep track of the unit it was before as we dont want to change theunit viewed when changing the CV
|
|
1182
|
+
# Keep track of the unit it was before as we dont want to change theunit viewed when changing the CV
|
|
1055
1183
|
entry_a_tmp = int(entry_a.get())
|
|
1056
1184
|
entry_b_tmp = int(entry_b.get())
|
|
1057
1185
|
|
|
@@ -1061,46 +1189,77 @@ def update_unit_cv():
|
|
|
1061
1189
|
entry_b.destroy()
|
|
1062
1190
|
|
|
1063
1191
|
CV = get_cv_option()
|
|
1064
|
-
CV_option = CV_tkinter.get() - 1
|
|
1065
|
-
if CV ==
|
|
1066
|
-
#Use average CV values
|
|
1067
|
-
tmp_idx_a = np.argwhere(
|
|
1068
|
-
|
|
1192
|
+
CV_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1193
|
+
if CV == "Avg":
|
|
1194
|
+
# Use average CV values
|
|
1195
|
+
tmp_idx_a = np.argwhere(
|
|
1196
|
+
(session_switch[session_a - 1] <= matches_avg[:, 0])
|
|
1197
|
+
* (matches_avg[:, 0] < session_switch[session_a])
|
|
1198
|
+
== True
|
|
1199
|
+
).squeeze()
|
|
1200
|
+
tmp_idx_b = np.argwhere(
|
|
1201
|
+
(session_switch[session_b - 1] <= matches_avg[:, 1])
|
|
1202
|
+
* (matches_avg[:, 1] < session_switch[session_b])
|
|
1203
|
+
== True
|
|
1204
|
+
).squeeze()
|
|
1069
1205
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1070
|
-
option_a = matches_avg[tmp_idx_a[in_both]
|
|
1206
|
+
option_a = matches_avg[tmp_idx_a[in_both], :].tolist()
|
|
1071
1207
|
|
|
1072
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1208
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1073
1209
|
entry_a.set(entry_a_tmp)
|
|
1074
1210
|
|
|
1075
|
-
option_b = np.flip(
|
|
1211
|
+
option_b = np.flip(
|
|
1212
|
+
np.argsort(
|
|
1213
|
+
output_avg[
|
|
1214
|
+
int(entry_a.get()),
|
|
1215
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1216
|
+
]
|
|
1217
|
+
)
|
|
1218
|
+
+ session_switch[session_b - 1]
|
|
1219
|
+
)
|
|
1076
1220
|
option_b = option_b.tolist()
|
|
1077
1221
|
|
|
1078
|
-
else
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1222
|
+
else:
|
|
1223
|
+
tmp_idx_a = np.argwhere(
|
|
1224
|
+
(session_switch[session_a - 1] <= matches_GUI[CV_option][:, 0])
|
|
1225
|
+
* (matches_GUI[CV_option][:, 0] < session_switch[session_a])
|
|
1226
|
+
== True
|
|
1227
|
+
).squeeze()
|
|
1228
|
+
tmp_idx_b = np.argwhere(
|
|
1229
|
+
(session_switch[session_b - 1] <= matches_GUI[CV_option][:, 1])
|
|
1230
|
+
* (matches_GUI[CV_option][:, 1] < session_switch[session_b])
|
|
1231
|
+
== True
|
|
1232
|
+
).squeeze()
|
|
1082
1233
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1083
1234
|
|
|
1084
|
-
#So is orderby unit A
|
|
1085
|
-
option_a =
|
|
1235
|
+
# So is orderby unit A
|
|
1236
|
+
option_a = matches_GUI[CV_option][tmp_idx_a[in_both], :].tolist()
|
|
1086
1237
|
if CV_option == 0:
|
|
1087
1238
|
option_a = sorted(option_a)
|
|
1088
1239
|
|
|
1089
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1240
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1090
1241
|
entry_a.set(entry_a_tmp)
|
|
1091
1242
|
|
|
1092
1243
|
##NOT SORTED FOR CV
|
|
1093
|
-
option_b = np.flip(
|
|
1244
|
+
option_b = np.flip(
|
|
1245
|
+
np.argsort(
|
|
1246
|
+
output_GUI[CV_option][
|
|
1247
|
+
int(entry_a.get()),
|
|
1248
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1249
|
+
]
|
|
1250
|
+
)
|
|
1251
|
+
+ session_switch[session_b - 1]
|
|
1252
|
+
)
|
|
1094
1253
|
option_b = option_b.tolist()
|
|
1095
1254
|
|
|
1096
1255
|
##################
|
|
1097
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1256
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1098
1257
|
entry_b.set(entry_b_tmp)
|
|
1099
|
-
|
|
1100
|
-
entry_a.bind(
|
|
1101
|
-
entry_b.bind(
|
|
1102
|
-
entry_a.grid(row
|
|
1103
|
-
entry_b.grid(row
|
|
1258
|
+
|
|
1259
|
+
entry_a.bind("<<ComboboxSelected>>", update_units)
|
|
1260
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1261
|
+
entry_a.grid(row=2, column=1, columnspan=2, stick="WE", padx=5)
|
|
1262
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1104
1263
|
|
|
1105
1264
|
tmp_list = [int(entry_a_tmp), int(entry_b_tmp)]
|
|
1106
1265
|
if tmp_list in option_a:
|
|
@@ -1113,7 +1272,7 @@ def update_unit_entryA(event):
|
|
|
1113
1272
|
"""
|
|
1114
1273
|
This will be called when the user changes the sesion A, and the following will happen:
|
|
1115
1274
|
- Keep the same B unit
|
|
1116
|
-
- Set A to the first match of the new session
|
|
1275
|
+
- Set A to the first match of the new session
|
|
1117
1276
|
- Set the Match IDX at 0, for the new list of match pairs
|
|
1118
1277
|
- update the options in list A
|
|
1119
1278
|
- update the options for list B
|
|
@@ -1124,9 +1283,9 @@ def update_unit_entryA(event):
|
|
|
1124
1283
|
global option_a
|
|
1125
1284
|
global match_idx
|
|
1126
1285
|
global session_entry_b
|
|
1127
|
-
|
|
1286
|
+
|
|
1128
1287
|
session_a = int(session_entry_a.get())
|
|
1129
|
-
session_b = int(session_entry_b.get())
|
|
1288
|
+
session_b = int(session_entry_b.get())
|
|
1130
1289
|
EntryBtmp = int(entry_b.get())
|
|
1131
1290
|
|
|
1132
1291
|
if entry_a.winfo_exists() == 1:
|
|
@@ -1135,53 +1294,85 @@ def update_unit_entryA(event):
|
|
|
1135
1294
|
entry_b.destroy()
|
|
1136
1295
|
|
|
1137
1296
|
CV = get_cv_option()
|
|
1138
|
-
cv_option = CV_tkinter.get() - 1
|
|
1139
|
-
if CV ==
|
|
1140
|
-
#Use average CV values
|
|
1141
|
-
tmp_idx_a = np.argwhere(
|
|
1142
|
-
|
|
1297
|
+
cv_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1298
|
+
if CV == "Avg":
|
|
1299
|
+
# Use average CV values
|
|
1300
|
+
tmp_idx_a = np.argwhere(
|
|
1301
|
+
(session_switch[session_a - 1] <= matches_avg[:, 0])
|
|
1302
|
+
* (matches_avg[:, 0] < session_switch[session_a])
|
|
1303
|
+
== True
|
|
1304
|
+
).squeeze()
|
|
1305
|
+
tmp_idx_b = np.argwhere(
|
|
1306
|
+
(session_switch[session_b - 1] <= matches_avg[:, 1])
|
|
1307
|
+
* (matches_avg[:, 1] < session_switch[session_b])
|
|
1308
|
+
== True
|
|
1309
|
+
).squeeze()
|
|
1143
1310
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1144
|
-
option_a = matches_avg[tmp_idx_a[in_both]
|
|
1311
|
+
option_a = matches_avg[tmp_idx_a[in_both], :].tolist()
|
|
1145
1312
|
|
|
1146
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1313
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1147
1314
|
entry_a.set(option_a[0][0])
|
|
1148
1315
|
|
|
1149
|
-
option_b = np.flip(
|
|
1316
|
+
option_b = np.flip(
|
|
1317
|
+
np.argsort(
|
|
1318
|
+
output_avg[
|
|
1319
|
+
int(entry_a.get()),
|
|
1320
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1321
|
+
]
|
|
1322
|
+
)
|
|
1323
|
+
+ session_switch[session_b - 1]
|
|
1324
|
+
)
|
|
1150
1325
|
option_b = option_b.tolist()
|
|
1151
1326
|
|
|
1152
|
-
else
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1327
|
+
else:
|
|
1328
|
+
tmp_idx_a = np.argwhere(
|
|
1329
|
+
(session_switch[session_a - 1] <= matches_GUI[cv_option][:, 0])
|
|
1330
|
+
* (matches_GUI[cv_option][:, 0] < session_switch[session_a])
|
|
1331
|
+
== True
|
|
1332
|
+
).squeeze()
|
|
1333
|
+
tmp_idx_b = np.argwhere(
|
|
1334
|
+
(session_switch[session_b - 1] <= matches_GUI[cv_option][:, 1])
|
|
1335
|
+
* (matches_GUI[cv_option][:, 1] < session_switch[session_b])
|
|
1336
|
+
== True
|
|
1337
|
+
).squeeze()
|
|
1156
1338
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1157
|
-
option_a =
|
|
1339
|
+
option_a = matches_GUI[cv_option][tmp_idx_a[in_both], :].tolist()
|
|
1158
1340
|
if cv_option == 0:
|
|
1159
1341
|
option_a = sorted(option_a)
|
|
1160
1342
|
|
|
1161
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1343
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1162
1344
|
entry_a.set(option_a[0][0])
|
|
1163
1345
|
|
|
1164
|
-
option_b = np.flip(
|
|
1346
|
+
option_b = np.flip(
|
|
1347
|
+
np.argsort(
|
|
1348
|
+
output_GUI[cv_option][
|
|
1349
|
+
int(entry_a.get()),
|
|
1350
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1351
|
+
]
|
|
1352
|
+
)
|
|
1353
|
+
+ session_switch[session_b - 1]
|
|
1354
|
+
)
|
|
1165
1355
|
option_b = option_b.tolist()
|
|
1166
1356
|
##################
|
|
1167
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1357
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1168
1358
|
entry_b.set(EntryBtmp)
|
|
1169
|
-
entry_a.bind(
|
|
1170
|
-
entry_b.bind(
|
|
1359
|
+
entry_a.bind("<<ComboboxSelected>>", update_units)
|
|
1360
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1171
1361
|
|
|
1172
|
-
entry_a.grid(row
|
|
1173
|
-
entry_b.grid(row
|
|
1362
|
+
entry_a.grid(row=2, column=1, columnspan=2, stick="WE", padx=5)
|
|
1363
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1174
1364
|
match_idx = 0
|
|
1175
1365
|
|
|
1176
1366
|
update(event)
|
|
1177
1367
|
|
|
1368
|
+
|
|
1178
1369
|
def update_unit_entryB(event):
|
|
1179
1370
|
"""
|
|
1180
1371
|
This will be called when the user changes the sesion B, and the following will happen:
|
|
1181
1372
|
- Keep the same A unit
|
|
1182
1373
|
- update the options in list A
|
|
1183
1374
|
- update the options for list B
|
|
1184
|
-
- Set B to the highest match of unit A for the new session B
|
|
1375
|
+
- Set B to the highest match of unit A for the new session B
|
|
1185
1376
|
- Set the Match IDX at 0, for the new list of match pairs
|
|
1186
1377
|
- update what is in the screen
|
|
1187
1378
|
"""
|
|
@@ -1190,9 +1381,9 @@ def update_unit_entryB(event):
|
|
|
1190
1381
|
global option_a
|
|
1191
1382
|
global match_idx
|
|
1192
1383
|
global session_entry_a
|
|
1193
|
-
|
|
1384
|
+
|
|
1194
1385
|
session_a = int(session_entry_a.get())
|
|
1195
|
-
session_b = int(session_entry_b.get())
|
|
1386
|
+
session_b = int(session_entry_b.get())
|
|
1196
1387
|
entry_a_tmp = int(entry_a.get())
|
|
1197
1388
|
|
|
1198
1389
|
if entry_a.winfo_exists() == 1:
|
|
@@ -1201,49 +1392,81 @@ def update_unit_entryB(event):
|
|
|
1201
1392
|
entry_b.destroy()
|
|
1202
1393
|
|
|
1203
1394
|
CV = get_cv_option()
|
|
1204
|
-
CV_option = CV_tkinter.get() - 1
|
|
1205
|
-
if CV ==
|
|
1206
|
-
#Use average CV values
|
|
1207
|
-
tmp_idx_a = np.argwhere(
|
|
1208
|
-
|
|
1395
|
+
CV_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1396
|
+
if CV == "Avg":
|
|
1397
|
+
# Use average CV values
|
|
1398
|
+
tmp_idx_a = np.argwhere(
|
|
1399
|
+
(session_switch[session_a - 1] <= matches_avg[:, 0])
|
|
1400
|
+
* (matches_avg[:, 0] < session_switch[session_a])
|
|
1401
|
+
== True
|
|
1402
|
+
).squeeze()
|
|
1403
|
+
tmp_idx_b = np.argwhere(
|
|
1404
|
+
(session_switch[session_b - 1] <= matches_avg[:, 1])
|
|
1405
|
+
* (matches_avg[:, 1] < session_switch[session_b])
|
|
1406
|
+
== True
|
|
1407
|
+
).squeeze()
|
|
1209
1408
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1210
|
-
option_a = matches_avg[tmp_idx_a[in_both]
|
|
1409
|
+
option_a = matches_avg[tmp_idx_a[in_both], :].tolist()
|
|
1211
1410
|
|
|
1212
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1411
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1213
1412
|
entry_a.set(entry_a_tmp)
|
|
1214
1413
|
|
|
1215
|
-
option_b = np.flip(
|
|
1414
|
+
option_b = np.flip(
|
|
1415
|
+
np.argsort(
|
|
1416
|
+
output_avg[
|
|
1417
|
+
int(entry_a.get()),
|
|
1418
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1419
|
+
]
|
|
1420
|
+
)
|
|
1421
|
+
+ session_switch[session_b - 1]
|
|
1422
|
+
)
|
|
1216
1423
|
option_b = option_b.tolist()
|
|
1217
1424
|
|
|
1218
|
-
else
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1425
|
+
else:
|
|
1426
|
+
tmp_idx_a = np.argwhere(
|
|
1427
|
+
(session_switch[session_a - 1] <= matches_GUI[CV_option][:, 0])
|
|
1428
|
+
* (matches_GUI[CV_option][:, 0] < session_switch[session_a])
|
|
1429
|
+
== True
|
|
1430
|
+
).squeeze()
|
|
1431
|
+
tmp_idx_b = np.argwhere(
|
|
1432
|
+
(session_switch[session_b - 1] <= matches_GUI[CV_option][:, 1])
|
|
1433
|
+
* (matches_GUI[CV_option][:, 1] < session_switch[session_b])
|
|
1434
|
+
== True
|
|
1435
|
+
).squeeze()
|
|
1222
1436
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1223
|
-
option_a =
|
|
1437
|
+
option_a = matches_GUI[CV_option][tmp_idx_a[in_both], :].tolist()
|
|
1224
1438
|
if CV_option == 0:
|
|
1225
1439
|
option_a = sorted(option_a)
|
|
1226
1440
|
|
|
1227
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1441
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1228
1442
|
entry_a.set(entry_a_tmp)
|
|
1229
1443
|
|
|
1230
|
-
option_b = np.flip(
|
|
1444
|
+
option_b = np.flip(
|
|
1445
|
+
np.argsort(
|
|
1446
|
+
output_GUI[CV_option][
|
|
1447
|
+
int(entry_a_tmp),
|
|
1448
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1449
|
+
]
|
|
1450
|
+
)
|
|
1451
|
+
+ session_switch[session_b - 1]
|
|
1452
|
+
)
|
|
1231
1453
|
option_b = option_b.tolist()
|
|
1232
|
-
|
|
1454
|
+
|
|
1233
1455
|
##################
|
|
1234
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1456
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1235
1457
|
entry_b.set(option_b[0])
|
|
1236
|
-
entry_a.bind(
|
|
1237
|
-
entry_b.bind(
|
|
1458
|
+
entry_a.bind("<<ComboboxSelected>>", update_units)
|
|
1459
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1238
1460
|
|
|
1239
|
-
entry_a.grid(row
|
|
1240
|
-
entry_b.grid(row
|
|
1241
|
-
match_idx = 0
|
|
1461
|
+
entry_a.grid(row=2, column=1, columnspan=2, stick="WE", padx=5)
|
|
1462
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1463
|
+
match_idx = 0
|
|
1242
1464
|
|
|
1243
1465
|
update(event)
|
|
1244
1466
|
|
|
1467
|
+
|
|
1245
1468
|
def update_units(event):
|
|
1246
|
-
"""
|
|
1469
|
+
"""
|
|
1247
1470
|
This function is called when a option in the Unit A dropdown is selected (is a pair of units)
|
|
1248
1471
|
- split the list of units into two pairs for unit labels for UnitA and UnitB
|
|
1249
1472
|
- Update the unit B dropdown box to reflect matches for the new Unit A
|
|
@@ -1254,7 +1477,6 @@ def update_units(event):
|
|
|
1254
1477
|
global entry_b
|
|
1255
1478
|
global option_a
|
|
1256
1479
|
global session_entry_b
|
|
1257
|
-
|
|
1258
1480
|
|
|
1259
1481
|
session_b = int(session_entry_b.get())
|
|
1260
1482
|
selected = entry_a.get()
|
|
@@ -1265,34 +1487,47 @@ def update_units(event):
|
|
|
1265
1487
|
tmpA = selected.split()[0]
|
|
1266
1488
|
tmpB = selected.split()[1]
|
|
1267
1489
|
entry_a.set(tmpA)
|
|
1268
|
-
|
|
1269
1490
|
|
|
1270
|
-
#need to make it so the list for B updates
|
|
1491
|
+
# need to make it so the list for B updates
|
|
1271
1492
|
CV = get_cv_option()
|
|
1272
|
-
CV_option = CV_tkinter.get() - 1
|
|
1273
|
-
if CV ==
|
|
1274
|
-
#Use average CV value
|
|
1275
|
-
option_b = np.flip(
|
|
1493
|
+
CV_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1494
|
+
if CV == "Avg":
|
|
1495
|
+
# Use average CV value
|
|
1496
|
+
option_b = np.flip(
|
|
1497
|
+
np.argsort(
|
|
1498
|
+
output_avg[
|
|
1499
|
+
int(tmpA), session_switch[session_b - 1] : session_switch[session_b]
|
|
1500
|
+
]
|
|
1501
|
+
)
|
|
1502
|
+
+ session_switch[session_b - 1]
|
|
1503
|
+
)
|
|
1276
1504
|
option_b = option_b.tolist()
|
|
1277
|
-
else
|
|
1278
|
-
option_b = np.flip(
|
|
1505
|
+
else:
|
|
1506
|
+
option_b = np.flip(
|
|
1507
|
+
np.argsort(
|
|
1508
|
+
output_GUI[CV_option][
|
|
1509
|
+
int(tmpA), session_switch[session_b - 1] : session_switch[session_b]
|
|
1510
|
+
]
|
|
1511
|
+
)
|
|
1512
|
+
+ session_switch[session_b - 1]
|
|
1513
|
+
)
|
|
1279
1514
|
option_b = option_b.tolist()
|
|
1280
|
-
|
|
1515
|
+
|
|
1281
1516
|
##################
|
|
1282
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1517
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1283
1518
|
entry_b.set(tmpB)
|
|
1284
|
-
entry_b.bind(
|
|
1285
|
-
|
|
1286
|
-
entry_b.grid(row = 2, column = 3, columnspan = 2, sticky = 'WE', padx = 5)
|
|
1519
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1287
1520
|
|
|
1521
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1288
1522
|
|
|
1289
|
-
#need to get list index of the selected postion
|
|
1523
|
+
# need to get list index of the selected postion
|
|
1290
1524
|
tmp_list = [int(tmpA), int(tmpB)]
|
|
1291
1525
|
match_idx = option_a.index(tmp_list)
|
|
1292
1526
|
update(event)
|
|
1293
1527
|
|
|
1528
|
+
|
|
1294
1529
|
def next_pair(event):
|
|
1295
|
-
"""
|
|
1530
|
+
"""
|
|
1296
1531
|
This function is called when moving to the next unit in the mathc list:
|
|
1297
1532
|
- get the new unit idx for unit A and unit B
|
|
1298
1533
|
- update the Units
|
|
@@ -1305,35 +1540,52 @@ def next_pair(event):
|
|
|
1305
1540
|
global session_entry_b
|
|
1306
1541
|
|
|
1307
1542
|
session_b = int(session_entry_b.get())
|
|
1308
|
-
match_idx +=1
|
|
1543
|
+
match_idx += 1
|
|
1309
1544
|
tmp_a, tmp_b = option_a[match_idx]
|
|
1310
1545
|
entry_a.set(tmp_a)
|
|
1311
1546
|
|
|
1312
1547
|
if entry_b.winfo_exists() == 1:
|
|
1313
1548
|
entry_b.destroy()
|
|
1314
1549
|
|
|
1315
|
-
#Update B, and change it's dropbox
|
|
1550
|
+
# Update B, and change it's dropbox
|
|
1316
1551
|
CV = get_cv_option()
|
|
1317
|
-
cv_option = CV_tkinter.get() - 1
|
|
1318
|
-
if CV ==
|
|
1319
|
-
#Use average CV value
|
|
1320
|
-
option_b = np.flip(
|
|
1552
|
+
cv_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1553
|
+
if CV == "Avg":
|
|
1554
|
+
# Use average CV value
|
|
1555
|
+
option_b = np.flip(
|
|
1556
|
+
np.argsort(
|
|
1557
|
+
output_avg[
|
|
1558
|
+
int(tmp_a),
|
|
1559
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1560
|
+
]
|
|
1561
|
+
)
|
|
1562
|
+
+ session_switch[session_b - 1]
|
|
1563
|
+
)
|
|
1321
1564
|
option_b = option_b.tolist()
|
|
1322
|
-
else
|
|
1323
|
-
option_b = np.flip(
|
|
1565
|
+
else:
|
|
1566
|
+
option_b = np.flip(
|
|
1567
|
+
np.argsort(
|
|
1568
|
+
output_GUI[cv_option][
|
|
1569
|
+
int(tmp_a),
|
|
1570
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1571
|
+
]
|
|
1572
|
+
)
|
|
1573
|
+
+ session_switch[session_b - 1]
|
|
1574
|
+
)
|
|
1324
1575
|
option_b = option_b.tolist()
|
|
1325
|
-
|
|
1576
|
+
|
|
1326
1577
|
##################
|
|
1327
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1578
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1328
1579
|
entry_b.set(tmp_b)
|
|
1329
|
-
entry_b.bind(
|
|
1580
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1330
1581
|
|
|
1331
|
-
entry_b.grid(row
|
|
1582
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1332
1583
|
|
|
1333
1584
|
update(event)
|
|
1334
1585
|
|
|
1586
|
+
|
|
1335
1587
|
def previous_pair(event):
|
|
1336
|
-
"""
|
|
1588
|
+
"""
|
|
1337
1589
|
This function is called when moving to the previous unit in the mathc list:
|
|
1338
1590
|
- get the new unit idx for unit A and unit B
|
|
1339
1591
|
- update the Units
|
|
@@ -1344,36 +1596,52 @@ def previous_pair(event):
|
|
|
1344
1596
|
global entry_b
|
|
1345
1597
|
global option_a
|
|
1346
1598
|
global session_entry_b
|
|
1347
|
-
|
|
1599
|
+
|
|
1348
1600
|
session_b = int(session_entry_b.get())
|
|
1349
|
-
match_idx -=1
|
|
1601
|
+
match_idx -= 1
|
|
1350
1602
|
tmp_a, tmp_b = option_a[match_idx]
|
|
1351
1603
|
entry_a.set(tmp_a)
|
|
1352
1604
|
|
|
1353
|
-
|
|
1354
1605
|
if entry_b.winfo_exists() == 1:
|
|
1355
1606
|
entry_b.destroy()
|
|
1356
1607
|
|
|
1357
|
-
#Update B, and change it's dropbox
|
|
1608
|
+
# Update B, and change it's dropbox
|
|
1358
1609
|
CV = get_cv_option()
|
|
1359
|
-
CV_option = CV_tkinter.get() - 1
|
|
1360
|
-
if CV ==
|
|
1361
|
-
#Use average CV value
|
|
1362
|
-
option_b = np.flip(
|
|
1610
|
+
CV_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1611
|
+
if CV == "Avg":
|
|
1612
|
+
# Use average CV value
|
|
1613
|
+
option_b = np.flip(
|
|
1614
|
+
np.argsort(
|
|
1615
|
+
output_avg[
|
|
1616
|
+
int(tmp_a),
|
|
1617
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1618
|
+
]
|
|
1619
|
+
)
|
|
1620
|
+
+ session_switch[session_b - 1]
|
|
1621
|
+
)
|
|
1363
1622
|
option_b = option_b.tolist()
|
|
1364
|
-
else
|
|
1365
|
-
option_b = np.flip(
|
|
1623
|
+
else:
|
|
1624
|
+
option_b = np.flip(
|
|
1625
|
+
np.argsort(
|
|
1626
|
+
output_GUI[CV_option][
|
|
1627
|
+
int(tmp_a),
|
|
1628
|
+
session_switch[session_b - 1] : session_switch[session_b],
|
|
1629
|
+
]
|
|
1630
|
+
)
|
|
1631
|
+
+ session_switch[session_b - 1]
|
|
1632
|
+
)
|
|
1366
1633
|
option_b = option_b.tolist()
|
|
1367
|
-
|
|
1634
|
+
|
|
1368
1635
|
##################
|
|
1369
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1636
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1370
1637
|
entry_b.set(tmp_b)
|
|
1371
|
-
entry_b.bind(
|
|
1638
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1372
1639
|
|
|
1373
|
-
entry_b.grid(row
|
|
1640
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1374
1641
|
|
|
1375
1642
|
update(event)
|
|
1376
1643
|
|
|
1644
|
+
|
|
1377
1645
|
def swap_units():
|
|
1378
1646
|
global entry_frame
|
|
1379
1647
|
global entry_a
|
|
@@ -1383,86 +1651,121 @@ def swap_units():
|
|
|
1383
1651
|
global match_idx
|
|
1384
1652
|
global option_a
|
|
1385
1653
|
|
|
1386
|
-
#get all initial info
|
|
1654
|
+
# get all initial info
|
|
1387
1655
|
entry_a_tmp = int(entry_a.get())
|
|
1388
1656
|
entry_b_tmp = int(entry_b.get())
|
|
1389
1657
|
session_a_tmp = int(session_entry_a.get())
|
|
1390
1658
|
session_b_tmp = int(session_entry_b.get())
|
|
1391
1659
|
|
|
1392
|
-
#delte old box a and b
|
|
1660
|
+
# delte old box a and b
|
|
1393
1661
|
if entry_a.winfo_exists() == 1:
|
|
1394
1662
|
entry_a.destroy()
|
|
1395
1663
|
if entry_b.winfo_exists() == 1:
|
|
1396
1664
|
entry_b.destroy()
|
|
1397
1665
|
|
|
1398
|
-
#swap allpairs
|
|
1666
|
+
# swap allpairs
|
|
1399
1667
|
session_entry_a.set(session_b_tmp)
|
|
1400
1668
|
session_entry_b.set(session_a_tmp)
|
|
1401
|
-
|
|
1402
|
-
#Update A and B dropsown boxs
|
|
1669
|
+
|
|
1670
|
+
# Update A and B dropsown boxs
|
|
1403
1671
|
CV = get_cv_option()
|
|
1404
|
-
cv_option = CV_tkinter.get() - 1
|
|
1405
|
-
if CV ==
|
|
1406
|
-
#Use average CV values
|
|
1407
|
-
tmp_idx_a = np.argwhere(
|
|
1408
|
-
|
|
1672
|
+
cv_option = CV_tkinter.get() - 1 # want 0 for cv (1,2) , want 1 for cv (2,1)
|
|
1673
|
+
if CV == "Avg":
|
|
1674
|
+
# Use average CV values
|
|
1675
|
+
tmp_idx_a = np.argwhere(
|
|
1676
|
+
(session_switch[session_b_tmp - 1] <= matches_avg[:, 0])
|
|
1677
|
+
* (matches_avg[:, 0] < session_switch[session_b_tmp])
|
|
1678
|
+
== True
|
|
1679
|
+
).squeeze()
|
|
1680
|
+
tmp_idx_b = np.argwhere(
|
|
1681
|
+
(session_switch[session_a_tmp - 1] <= matches_avg[:, 1])
|
|
1682
|
+
* (matches_avg[:, 1] < session_switch[session_a_tmp])
|
|
1683
|
+
== True
|
|
1684
|
+
).squeeze()
|
|
1409
1685
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1410
|
-
option_a = matches_avg[tmp_idx_a[in_both]
|
|
1686
|
+
option_a = matches_avg[tmp_idx_a[in_both], :].tolist()
|
|
1411
1687
|
|
|
1412
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1688
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1413
1689
|
entry_a.set(entry_b_tmp)
|
|
1414
1690
|
|
|
1415
|
-
option_b = np.flip(
|
|
1691
|
+
option_b = np.flip(
|
|
1692
|
+
np.argsort(
|
|
1693
|
+
output_avg[
|
|
1694
|
+
int(entry_a.get()),
|
|
1695
|
+
session_switch[session_a_tmp - 1] : session_switch[session_a_tmp],
|
|
1696
|
+
]
|
|
1697
|
+
)
|
|
1698
|
+
+ session_switch[session_a_tmp - 1]
|
|
1699
|
+
)
|
|
1416
1700
|
option_b = option_b.tolist()
|
|
1417
1701
|
|
|
1418
|
-
else
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1702
|
+
else:
|
|
1703
|
+
tmp_idx_a = np.argwhere(
|
|
1704
|
+
(session_switch[session_b_tmp - 1] <= matches_GUI[cv_option][:, 0])
|
|
1705
|
+
* (matches_GUI[cv_option][:, 0] < session_switch[session_b_tmp])
|
|
1706
|
+
== True
|
|
1707
|
+
).squeeze()
|
|
1708
|
+
tmp_idx_b = np.argwhere(
|
|
1709
|
+
(session_switch[session_a_tmp - 1] <= matches_GUI[cv_option][:, 1])
|
|
1710
|
+
* (matches_GUI[cv_option][:, 1] < session_switch[session_a_tmp])
|
|
1711
|
+
== True
|
|
1712
|
+
).squeeze()
|
|
1422
1713
|
in_both = np.isin(tmp_idx_a, tmp_idx_b)
|
|
1423
1714
|
|
|
1424
|
-
#So is orderby unit A
|
|
1425
|
-
option_a =
|
|
1715
|
+
# So is orderby unit A
|
|
1716
|
+
option_a = matches_GUI[cv_option][tmp_idx_a[in_both], :].tolist()
|
|
1426
1717
|
if cv_option == 0:
|
|
1427
1718
|
option_a = sorted(option_a)
|
|
1428
1719
|
|
|
1429
|
-
entry_a = ttk.Combobox(entry_frame, values
|
|
1720
|
+
entry_a = ttk.Combobox(entry_frame, values=option_a, width=10)
|
|
1430
1721
|
entry_a.set(entry_b_tmp)
|
|
1431
1722
|
|
|
1432
1723
|
##NOT SORTED FOR CV
|
|
1433
|
-
option_b = np.flip(
|
|
1724
|
+
option_b = np.flip(
|
|
1725
|
+
np.argsort(
|
|
1726
|
+
output_GUI[cv_option][
|
|
1727
|
+
int(entry_a.get()),
|
|
1728
|
+
session_switch[session_a_tmp - 1] : session_switch[session_a_tmp],
|
|
1729
|
+
]
|
|
1730
|
+
)
|
|
1731
|
+
+ session_switch[session_a_tmp - 1]
|
|
1732
|
+
)
|
|
1434
1733
|
option_b = option_b.tolist()
|
|
1435
1734
|
|
|
1436
1735
|
##################
|
|
1437
|
-
entry_b = ttk.Combobox(entry_frame, values
|
|
1736
|
+
entry_b = ttk.Combobox(entry_frame, values=option_b, width=10)
|
|
1438
1737
|
entry_b.set(entry_a_tmp)
|
|
1439
|
-
|
|
1440
|
-
entry_a.bind(
|
|
1441
|
-
entry_b.bind(
|
|
1442
|
-
entry_a.grid(row
|
|
1443
|
-
entry_b.grid(row
|
|
1738
|
+
|
|
1739
|
+
entry_a.bind("<<ComboboxSelected>>", update_units)
|
|
1740
|
+
entry_b.bind("<<ComboboxSelected>>", update)
|
|
1741
|
+
entry_a.grid(row=2, column=1, columnspan=2, stick="WE", padx=5)
|
|
1742
|
+
entry_b.grid(row=2, column=3, columnspan=2, sticky="WE", padx=5)
|
|
1444
1743
|
|
|
1445
1744
|
tmp_list = [int(entry_b_tmp), int(entry_a_tmp)]
|
|
1446
1745
|
|
|
1447
1746
|
match_idx = option_a.index(tmp_list)
|
|
1448
1747
|
update(None)
|
|
1449
1748
|
|
|
1749
|
+
|
|
1450
1750
|
def get_score_histograms(scores_to_include, output_threshold):
|
|
1451
|
-
"""
|
|
1751
|
+
"""
|
|
1452
1752
|
Scores2Include is the dictionary of all scores.
|
|
1453
1753
|
ProbThreshold is a nUnits*nUnits array where each index is 0 (Not Match) 1 (Match)
|
|
1454
1754
|
"""
|
|
1455
1755
|
|
|
1456
|
-
#are lsit of length 6 each list item is 2 np arrays(bins, values)
|
|
1756
|
+
# are lsit of length 6 each list item is 2 np arrays(bins, values)
|
|
1457
1757
|
hist_names = []
|
|
1458
1758
|
hist = []
|
|
1459
1759
|
hist_matches = []
|
|
1460
1760
|
for key, values in scores_to_include.items():
|
|
1461
1761
|
hist_names.append(key)
|
|
1462
|
-
hist.append(np.histogram(values, bins
|
|
1463
|
-
hist_matches.append(
|
|
1762
|
+
hist.append(np.histogram(values, bins=100, density=True))
|
|
1763
|
+
hist_matches.append(
|
|
1764
|
+
np.histogram(values[output_threshold.astype(bool)], bins=100, density=True)
|
|
1765
|
+
)
|
|
1766
|
+
|
|
1767
|
+
return hist_names, hist, hist_matches
|
|
1464
1768
|
|
|
1465
|
-
return hist_names, hist, hist_matches
|
|
1466
1769
|
|
|
1467
1770
|
def add_original_ID(UnitA, UnitB):
|
|
1468
1771
|
global original_id_label
|
|
@@ -1475,13 +1778,21 @@ def add_original_ID(UnitA, UnitB):
|
|
|
1475
1778
|
try:
|
|
1476
1779
|
original_id_a = int(clus_info["original_ids"][UnitA].squeeze())
|
|
1477
1780
|
original_id_b = int(clus_info["original_ids"][UnitB].squeeze())
|
|
1478
|
-
original_id_label = ttk.Label(
|
|
1781
|
+
original_id_label = ttk.Label(
|
|
1782
|
+
root,
|
|
1783
|
+
text=f"The Original Unit IDs are:\nUnit A: {original_id_a} Unit B: {original_id_b}",
|
|
1784
|
+
borderwidth=2,
|
|
1785
|
+
relief="groove",
|
|
1786
|
+
)
|
|
1479
1787
|
except IndexError as e:
|
|
1480
1788
|
print(f"Error: {e}")
|
|
1481
|
-
original_id_label = ttk.Label(
|
|
1789
|
+
original_id_label = ttk.Label(
|
|
1790
|
+
root, text="Error: Unit ID out of bounds", borderwidth=2, relief="groove"
|
|
1791
|
+
)
|
|
1482
1792
|
|
|
1483
1793
|
original_id_label.grid(row=2, column=2, ipadx=5, ipady=5)
|
|
1484
1794
|
|
|
1795
|
+
|
|
1485
1796
|
def add_probability_label(UnitA, UnitB, CVoption):
|
|
1486
1797
|
global bayes_label
|
|
1487
1798
|
|
|
@@ -1489,148 +1800,202 @@ def add_probability_label(UnitA, UnitB, CVoption):
|
|
|
1489
1800
|
bayes_label.destroy()
|
|
1490
1801
|
|
|
1491
1802
|
if CVoption == -1:
|
|
1492
|
-
bayes_label = ttk.Label(
|
|
1493
|
-
|
|
1803
|
+
bayes_label = ttk.Label(
|
|
1804
|
+
root,
|
|
1805
|
+
text=f"The UM probabilty for this match is:\n {np.round(output_avg[UnitA, UnitB], 5)}",
|
|
1806
|
+
borderwidth=2,
|
|
1807
|
+
relief="groove",
|
|
1808
|
+
)
|
|
1809
|
+
bayes_label.grid(row=2, column=1, ipadx=5, ipady=5)
|
|
1494
1810
|
else:
|
|
1495
|
-
bayes_label = ttk.Label(
|
|
1496
|
-
|
|
1811
|
+
bayes_label = ttk.Label(
|
|
1812
|
+
root,
|
|
1813
|
+
text=f"The UM probabilty for this match is:\n {np.round(output_GUI[CVoption][UnitA, UnitB], 5)}",
|
|
1814
|
+
borderwidth=2,
|
|
1815
|
+
relief="groove",
|
|
1816
|
+
)
|
|
1817
|
+
bayes_label.grid(row=2, column=1, ipadx=5, ipady=5)
|
|
1497
1818
|
|
|
1498
1819
|
|
|
1499
|
-
def set_match(event
|
|
1820
|
+
def set_match(event=None):
|
|
1500
1821
|
global is_match
|
|
1501
1822
|
unit_a = int(entry_a.get())
|
|
1502
1823
|
unit_b = int(entry_b.get())
|
|
1503
1824
|
|
|
1504
|
-
is_match.append(
|
|
1505
|
-
is_match.append(
|
|
1825
|
+
is_match.append([unit_a, unit_b])
|
|
1826
|
+
is_match.append([unit_b, unit_a])
|
|
1506
1827
|
|
|
1507
|
-
|
|
1508
1828
|
|
|
1509
|
-
def set_not_match(event
|
|
1829
|
+
def set_not_match(event=None):
|
|
1510
1830
|
global not_match
|
|
1511
1831
|
unit_a = int(entry_a.get())
|
|
1512
1832
|
unit_b = int(entry_b.get())
|
|
1513
1833
|
|
|
1514
|
-
not_match.append(
|
|
1515
|
-
not_match.append(
|
|
1834
|
+
not_match.append([unit_a, unit_b])
|
|
1835
|
+
not_match.append([unit_b, unit_a])
|
|
1516
1836
|
|
|
1517
1837
|
|
|
1518
1838
|
def MakeTable(table):
|
|
1519
1839
|
global frame_table
|
|
1520
|
-
|
|
1840
|
+
|
|
1521
1841
|
if frame_table.winfo_exists() == 1:
|
|
1522
1842
|
frame_table.destroy()
|
|
1523
1843
|
|
|
1524
1844
|
total_rows = len(table)
|
|
1525
1845
|
total_columns = len(table[0])
|
|
1526
1846
|
|
|
1527
|
-
colors = [
|
|
1528
|
-
frame_table = ttk.LabelFrame(root, text
|
|
1847
|
+
colors = ["black", "green", "blue"]
|
|
1848
|
+
frame_table = ttk.LabelFrame(root, text="UnitData")
|
|
1529
1849
|
for i in range(total_rows):
|
|
1530
1850
|
for j in range(total_columns):
|
|
1531
|
-
|
|
1532
1851
|
e = ttk.Entry(frame_table, width=20)
|
|
1533
1852
|
e.insert(END, table[i][j])
|
|
1534
|
-
e.configure(state=
|
|
1853
|
+
e.configure(state="readonly")
|
|
1535
1854
|
e.grid(row=i, column=j)
|
|
1536
|
-
frame_table.grid(row
|
|
1855
|
+
frame_table.grid(row=4, column=0, padx=10, pady=10)
|
|
1856
|
+
|
|
1537
1857
|
|
|
1538
|
-
#get table data #ADD STABILTY - prob of unit with itself accros cv
|
|
1858
|
+
# get table data #ADD STABILTY - prob of unit with itself accros cv
|
|
1539
1859
|
def get_table_data(UnitA, UnitB, CV):
|
|
1540
|
-
template = [
|
|
1541
|
-
[
|
|
1542
|
-
[
|
|
1543
|
-
[
|
|
1544
|
-
[
|
|
1545
|
-
[
|
|
1860
|
+
template = [
|
|
1861
|
+
["Unit", "A", "B"],
|
|
1862
|
+
["Avg Centroid", "tmp", "tmp"],
|
|
1863
|
+
["Amplitude", "tmp", "tmp"],
|
|
1864
|
+
["Spatial Decay", "tmp", "tmp"],
|
|
1865
|
+
["Units Matches", "tmp", "tmp"],
|
|
1866
|
+
["Stability", "tmp", "tmp"],
|
|
1867
|
+
]
|
|
1546
1868
|
|
|
1547
1869
|
total_rows = len(template)
|
|
1548
1870
|
total_columns = len(template[0])
|
|
1549
|
-
unit_idx_tmp =[0
|
|
1871
|
+
unit_idx_tmp = [0, UnitA, UnitB]
|
|
1550
1872
|
table = template
|
|
1551
1873
|
|
|
1552
|
-
if CV ==
|
|
1874
|
+
if CV == "Avg":
|
|
1553
1875
|
for i in range(total_rows):
|
|
1554
1876
|
for j in range(total_columns):
|
|
1555
|
-
if j == 0
|
|
1556
|
-
continue
|
|
1877
|
+
if j == 0:
|
|
1878
|
+
continue
|
|
1557
1879
|
if i == 0:
|
|
1558
1880
|
table[i][j] = str(unit_idx_tmp[j])
|
|
1559
1881
|
if i == 1:
|
|
1560
|
-
table[i][j] = str(
|
|
1561
|
-
if
|
|
1562
|
-
table[i][j] = str(
|
|
1882
|
+
table[i][j] = str(np.round(avg_centroid_avg[:, unit_idx_tmp[j]], 2))
|
|
1883
|
+
if i == 2:
|
|
1884
|
+
table[i][j] = str(np.round(amplitude_avg[unit_idx_tmp[j]], 2))
|
|
1563
1885
|
if i == 3:
|
|
1564
|
-
table[i][j] = str(
|
|
1886
|
+
table[i][j] = str(np.round(spatial_decay_avg[unit_idx_tmp[j]], 3))
|
|
1565
1887
|
if i == 4:
|
|
1566
|
-
table[i][j] =
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1888
|
+
table[i][j] = (
|
|
1889
|
+
str(
|
|
1890
|
+
np.argwhere(
|
|
1891
|
+
(within_session * output_avg)[unit_idx_tmp[j], :]
|
|
1892
|
+
> match_threshold
|
|
1893
|
+
)
|
|
1894
|
+
)
|
|
1895
|
+
.replace("[", "")
|
|
1896
|
+
.replace("]", "")
|
|
1897
|
+
)
|
|
1898
|
+
if i == 5:
|
|
1899
|
+
table[i][j] = str(
|
|
1900
|
+
np.round(output_GUI[0][unit_idx_tmp[j], unit_idx_tmp[j]], 3)
|
|
1901
|
+
)
|
|
1902
|
+
|
|
1570
1903
|
else:
|
|
1571
1904
|
for i in range(total_rows):
|
|
1572
1905
|
for j in range(total_columns):
|
|
1573
|
-
if j == 0
|
|
1574
|
-
continue
|
|
1906
|
+
if j == 0:
|
|
1907
|
+
continue
|
|
1575
1908
|
if i == 0:
|
|
1576
1909
|
table[i][j] = str(unit_idx_tmp[j])
|
|
1577
1910
|
if i == 1:
|
|
1578
|
-
table[i][j] = str(
|
|
1579
|
-
|
|
1580
|
-
|
|
1911
|
+
table[i][j] = str(
|
|
1912
|
+
np.round(avg_centroid[:, unit_idx_tmp[j], CV[j - 1]], 2)
|
|
1913
|
+
)
|
|
1914
|
+
if i == 2:
|
|
1915
|
+
table[i][j] = str(
|
|
1916
|
+
np.round(amplitude[unit_idx_tmp[j], CV[j - 1]], 2)
|
|
1917
|
+
)
|
|
1581
1918
|
if i == 3:
|
|
1582
|
-
table[i][j] = str(
|
|
1919
|
+
table[i][j] = str(
|
|
1920
|
+
np.round(spatial_decay[unit_idx_tmp[j], CV[j - 1]], 3)
|
|
1921
|
+
)
|
|
1583
1922
|
if i == 4:
|
|
1584
|
-
table[i][j] =
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1923
|
+
table[i][j] = (
|
|
1924
|
+
str(
|
|
1925
|
+
np.argwhere(
|
|
1926
|
+
(within_session * output_GUI[CV[0]])[unit_idx_tmp[j], :]
|
|
1927
|
+
> match_threshold
|
|
1928
|
+
)
|
|
1929
|
+
)
|
|
1930
|
+
.replace("[", "")
|
|
1931
|
+
.replace("]", "")
|
|
1932
|
+
)
|
|
1933
|
+
if i == 5:
|
|
1934
|
+
table[i][j] = str(
|
|
1935
|
+
np.round(output_GUI[0][unit_idx_tmp[j], unit_idx_tmp[j]], 3)
|
|
1936
|
+
)
|
|
1937
|
+
|
|
1588
1938
|
return table
|
|
1589
1939
|
|
|
1940
|
+
|
|
1590
1941
|
def get_unit_score_table(UnitA, UnitB, CVoption):
|
|
1591
|
-
|
|
1592
|
-
table = [['tmp'] * 2 for i in range((len(scores_to_include_avg) +1))]
|
|
1593
1942
|
|
|
1594
|
-
table
|
|
1943
|
+
table = [["tmp"] * 2 for i in range((len(scores_to_include_avg) + 1))]
|
|
1944
|
+
|
|
1945
|
+
table[0] = ["Score", f"{UnitA} and {UnitB}"]
|
|
1595
1946
|
|
|
1596
1947
|
if CVoption == -1:
|
|
1597
1948
|
for i in range(len(scores_to_include_avg)):
|
|
1598
1949
|
for j in range(2):
|
|
1599
|
-
if j ==0:
|
|
1600
|
-
table[i+1][j] = list(scores_to_include_avg.keys())[i]
|
|
1950
|
+
if j == 0:
|
|
1951
|
+
table[i + 1][j] = list(scores_to_include_avg.keys())[i]
|
|
1601
1952
|
else:
|
|
1602
|
-
table[i+1][j] = str(
|
|
1603
|
-
|
|
1953
|
+
table[i + 1][j] = str(
|
|
1954
|
+
np.round(
|
|
1955
|
+
scores_to_include_avg[
|
|
1956
|
+
list(scores_to_include_avg.keys())[i]
|
|
1957
|
+
][UnitA, UnitB],
|
|
1958
|
+
3,
|
|
1959
|
+
)
|
|
1960
|
+
)
|
|
1961
|
+
|
|
1604
1962
|
else:
|
|
1605
1963
|
for i in range(len(scores_to_include_avg)):
|
|
1606
1964
|
for j in range(2):
|
|
1607
|
-
if j ==0:
|
|
1608
|
-
table[i+1][j] = list(scores_to_include_GUI[CVoption].keys())[i]
|
|
1965
|
+
if j == 0:
|
|
1966
|
+
table[i + 1][j] = list(scores_to_include_GUI[CVoption].keys())[i]
|
|
1609
1967
|
else:
|
|
1610
|
-
table[i+1][j] = str(
|
|
1968
|
+
table[i + 1][j] = str(
|
|
1969
|
+
np.round(
|
|
1970
|
+
scores_to_include_GUI[CVoption][
|
|
1971
|
+
list(scores_to_include_GUI[CVoption].keys())[i]
|
|
1972
|
+
][UnitA, UnitB],
|
|
1973
|
+
3,
|
|
1974
|
+
)
|
|
1975
|
+
)
|
|
1611
1976
|
|
|
1612
1977
|
return table
|
|
1613
1978
|
|
|
1979
|
+
|
|
1614
1980
|
def make_unit_score_table(table):
|
|
1615
1981
|
global score_table
|
|
1616
|
-
|
|
1982
|
+
|
|
1617
1983
|
if score_table.winfo_exists() == 1:
|
|
1618
1984
|
score_table.destroy()
|
|
1619
1985
|
|
|
1620
1986
|
total_rows = len(table)
|
|
1621
1987
|
total_columns = len(table[0])
|
|
1622
1988
|
|
|
1623
|
-
colors = [
|
|
1624
|
-
score_table = ttk.LabelFrame(root, text
|
|
1989
|
+
colors = ["black", "Purple"]
|
|
1990
|
+
score_table = ttk.LabelFrame(root, text="UM Scores")
|
|
1625
1991
|
for i in range(total_rows):
|
|
1626
1992
|
for j in range(total_columns):
|
|
1627
|
-
|
|
1628
|
-
e = ttk.Entry(score_table, width = 30)
|
|
1993
|
+
e = ttk.Entry(score_table, width=30)
|
|
1629
1994
|
e.insert(END, table[i][j])
|
|
1630
|
-
e.configure(state=
|
|
1995
|
+
e.configure(state="readonly")
|
|
1631
1996
|
e.grid(row=i, column=j)
|
|
1632
1997
|
|
|
1633
|
-
score_table.grid(row
|
|
1998
|
+
score_table.grid(row=5, column=0, columnspan=2, padx=10, pady=10)
|
|
1634
1999
|
|
|
1635
2000
|
|
|
1636
2001
|
def plot_avg_waveforms(UnitA, UnitB, CV):
|
|
@@ -1638,212 +2003,300 @@ def plot_avg_waveforms(UnitA, UnitB, CV):
|
|
|
1638
2003
|
if avg_waveform_plot.winfo_exists() == 1:
|
|
1639
2004
|
avg_waveform_plot.destroy()
|
|
1640
2005
|
|
|
1641
|
-
fig = Figure(figsize
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
2006
|
+
fig = Figure(figsize=(3, 3), dpi=100)
|
|
2007
|
+
fig.patch.set_facecolor("#33393b")
|
|
2008
|
+
|
|
1645
2009
|
plt1 = fig.add_subplot(111)
|
|
1646
|
-
#plt1.spines[["left", "bottom"]].set_position(("data", 0))
|
|
2010
|
+
# plt1.spines[["left", "bottom"]].set_position(("data", 0))
|
|
1647
2011
|
plt1.spines[["bottom"]].set_position(("data", 0))
|
|
1648
2012
|
plt1.spines[["top", "right"]].set_visible(False)
|
|
1649
|
-
plt1.patch.set_facecolor(
|
|
1650
|
-
plt1.xaxis.set_label_coords(0.9,0)
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
plt1.plot(avg_waveform_avg[:,
|
|
1655
|
-
plt1.
|
|
1656
|
-
plt1.
|
|
1657
|
-
plt1.set_ylabel('Amplitude (µV)')
|
|
2013
|
+
plt1.patch.set_facecolor("#2d2d2d")
|
|
2014
|
+
plt1.xaxis.set_label_coords(0.9, 0)
|
|
2015
|
+
|
|
2016
|
+
if CV == "Avg":
|
|
2017
|
+
plt1.plot(avg_waveform_avg[:, UnitA], "g", label=f"Unit A ({UnitA})")
|
|
2018
|
+
plt1.plot(avg_waveform_avg[:, UnitB], "b", label=f"Unit B ({UnitB})")
|
|
2019
|
+
plt1.set_xlabel("Time (ms)")
|
|
2020
|
+
plt1.set_ylabel("Amplitude (µV)")
|
|
1658
2021
|
# plt1.set_xlim(left = 0)
|
|
1659
2022
|
# plt1.set_xticks([])
|
|
1660
2023
|
|
|
1661
2024
|
else:
|
|
1662
|
-
plt1.plot(avg_waveform[:,UnitA,CV[0]],
|
|
1663
|
-
plt1.plot(avg_waveform[:,UnitB,CV[1]],
|
|
1664
|
-
plt1.set_xlabel(
|
|
1665
|
-
plt1.set_ylabel(
|
|
2025
|
+
plt1.plot(avg_waveform[:, UnitA, CV[0]], "g", label=f"Unit A ({UnitA})")
|
|
2026
|
+
plt1.plot(avg_waveform[:, UnitB, CV[1]], "b", label=f"Unit B ({UnitB})")
|
|
2027
|
+
plt1.set_xlabel("Time (ms)")
|
|
2028
|
+
plt1.set_ylabel("Amplitude (µV)")
|
|
1666
2029
|
# plt1.set_xlim(left = 0)
|
|
1667
2030
|
|
|
1668
|
-
avg_waveform_plot = FigureCanvasTkAgg(fig, master
|
|
2031
|
+
avg_waveform_plot = FigureCanvasTkAgg(fig, master=root)
|
|
1669
2032
|
avg_waveform_plot.draw()
|
|
1670
2033
|
avg_waveform_plot = avg_waveform_plot.get_tk_widget()
|
|
1671
|
-
avg_waveform_plot.grid(row
|
|
2034
|
+
avg_waveform_plot.grid(row=3, column=0)
|
|
2035
|
+
|
|
1672
2036
|
|
|
1673
2037
|
def plot_trajectories(UnitA, UnitB, CV):
|
|
1674
2038
|
global trajectory_plot
|
|
1675
2039
|
if trajectory_plot.winfo_exists() == 1:
|
|
1676
2040
|
trajectory_plot.destroy()
|
|
1677
2041
|
|
|
1678
|
-
fig = Figure(figsize
|
|
1679
|
-
|
|
1680
|
-
fig.patch.set_facecolor('#33393b')
|
|
2042
|
+
fig = Figure(figsize=(3, 3), dpi=100)
|
|
2043
|
+
fig.patch.set_facecolor("#33393b")
|
|
1681
2044
|
|
|
1682
|
-
|
|
1683
2045
|
plt2 = fig.add_subplot(111)
|
|
1684
|
-
plt2.patch.set_facecolor(
|
|
2046
|
+
plt2.patch.set_facecolor("#2d2d2d")
|
|
1685
2047
|
plt2.set_aspect(0.5)
|
|
1686
|
-
plt2.spines[[
|
|
1687
|
-
|
|
2048
|
+
plt2.spines[["right", "top"]].set_visible(False)
|
|
1688
2049
|
|
|
1689
|
-
if CV ==
|
|
1690
|
-
|
|
2050
|
+
if CV == "Avg":
|
|
1691
2051
|
# AM not doing a time averaged WaveIDX (where you fins goodtimepoints), will just uses CV 0 for both
|
|
1692
|
-
plt2.plot(
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
plt2.
|
|
1699
|
-
|
|
2052
|
+
plt2.plot(
|
|
2053
|
+
avg_waveform_per_tp_avg[1, UnitA, wave_idx[UnitA, :, 0].astype(bool)],
|
|
2054
|
+
avg_waveform_per_tp_avg[2, UnitA, wave_idx[UnitA, :, 0].astype(bool)],
|
|
2055
|
+
"g",
|
|
2056
|
+
label=f"Unit A ({UnitA})",
|
|
2057
|
+
)
|
|
2058
|
+
plt2.scatter(avg_centroid_avg[1, UnitA], avg_centroid_avg[2, UnitA], c="g")
|
|
2059
|
+
|
|
2060
|
+
plt2.plot(
|
|
2061
|
+
avg_waveform_per_tp_avg[1, UnitB, wave_idx[UnitB, :, 0].astype(bool)],
|
|
2062
|
+
avg_waveform_per_tp_avg[2, UnitB, wave_idx[UnitB, :, 0].astype(bool)],
|
|
2063
|
+
"b",
|
|
2064
|
+
label=f"Unit B ({UnitB})",
|
|
2065
|
+
)
|
|
2066
|
+
plt2.scatter(avg_centroid_avg[1, UnitB], avg_centroid_avg[2, UnitB], c="b")
|
|
2067
|
+
|
|
2068
|
+
plt2.set_xlabel(r"X position ($\mu$m)")
|
|
2069
|
+
plt2.set_ylabel(r"Y position ($\mu$m)")
|
|
1700
2070
|
|
|
1701
2071
|
else:
|
|
1702
|
-
plt2.plot(
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
2072
|
+
plt2.plot(
|
|
2073
|
+
avg_waveform_per_tp[
|
|
2074
|
+
1, UnitA, wave_idx[UnitA, :, CV[0]].astype(bool), CV[0]
|
|
2075
|
+
],
|
|
2076
|
+
avg_waveform_per_tp[
|
|
2077
|
+
2, UnitA, wave_idx[UnitA, :, CV[0]].astype(bool), CV[0]
|
|
2078
|
+
],
|
|
2079
|
+
"g",
|
|
2080
|
+
label=f"Unit A ({UnitA})",
|
|
2081
|
+
)
|
|
2082
|
+
plt2.scatter(
|
|
2083
|
+
avg_centroid[1, UnitA, CV[0]], avg_centroid[2, UnitA, CV[0]], c="g"
|
|
2084
|
+
)
|
|
2085
|
+
|
|
2086
|
+
plt2.plot(
|
|
2087
|
+
avg_waveform_per_tp[
|
|
2088
|
+
1, UnitB, wave_idx[UnitB, :, CV[1]].astype(bool), CV[1]
|
|
2089
|
+
],
|
|
2090
|
+
avg_waveform_per_tp[
|
|
2091
|
+
2, UnitB, wave_idx[UnitB, :, CV[1]].astype(bool), CV[1]
|
|
2092
|
+
],
|
|
2093
|
+
"b",
|
|
2094
|
+
label=f"Unit B ({UnitB})",
|
|
2095
|
+
)
|
|
2096
|
+
plt2.scatter(
|
|
2097
|
+
avg_centroid[1, UnitB, CV[1]], avg_centroid[2, UnitB, CV[1]], c="b"
|
|
2098
|
+
)
|
|
2099
|
+
|
|
2100
|
+
plt2.set_xlabel(r"X position ($\mu$m)")
|
|
2101
|
+
plt2.set_ylabel(r"Y position ($\mu$m)")
|
|
2102
|
+
|
|
2103
|
+
trajectory_plot = FigureCanvasTkAgg(fig, master=root)
|
|
1712
2104
|
trajectory_plot.draw()
|
|
1713
2105
|
trajectory_plot = trajectory_plot.get_tk_widget()
|
|
1714
|
-
# TrajectoryPlot.configure(bg = '#33393b')
|
|
1715
|
-
trajectory_plot.grid(row
|
|
2106
|
+
# TrajectoryPlot.configure(bg = '#33393b')
|
|
2107
|
+
trajectory_plot.grid(row=3, column=1, columnspan=2)
|
|
2108
|
+
|
|
1716
2109
|
|
|
1717
2110
|
def order_good_sites(good_sites, channel_pos, n_sessions):
|
|
1718
2111
|
# make it so it goes from biggest to smallest
|
|
1719
|
-
reordered_idx = np.argsort(-channel_pos[n_sessions][good_sites,2].squeeze())
|
|
2112
|
+
reordered_idx = np.argsort(-channel_pos[n_sessions][good_sites, 2].squeeze())
|
|
1720
2113
|
reordered_good_sites = good_sites[reordered_idx]
|
|
1721
2114
|
|
|
1722
|
-
#re-arange x-axis so it goes (smaller x, bigger x)
|
|
2115
|
+
# re-arange x-axis so it goes (smaller x, bigger x)
|
|
1723
2116
|
for i in range(9):
|
|
1724
|
-
a,b = channel_pos[n_sessions][reordered_good_sites[[2*i, 2*i+1]],1]
|
|
2117
|
+
a, b = channel_pos[n_sessions][reordered_good_sites[[2 * i, 2 * i + 1]], 1]
|
|
1725
2118
|
|
|
1726
2119
|
if a > b:
|
|
1727
|
-
#swap order
|
|
1728
|
-
reordered_good_sites[[2*i + 1, 2*i]] = reordered_good_sites[
|
|
2120
|
+
# swap order
|
|
2121
|
+
reordered_good_sites[[2 * i + 1, 2 * i]] = reordered_good_sites[
|
|
2122
|
+
[2 * i, 2 * i + 1]
|
|
2123
|
+
]
|
|
1729
2124
|
return reordered_good_sites
|
|
1730
2125
|
|
|
2126
|
+
|
|
1731
2127
|
def nearest_channels(max_site, max_site_mean, channel_pos, clus_info, unit, CV):
|
|
1732
2128
|
|
|
1733
|
-
n_sessions = clus_info[
|
|
1734
|
-
if CV ==
|
|
2129
|
+
n_sessions = clus_info["session_id"][unit]
|
|
2130
|
+
if CV == "Avg":
|
|
1735
2131
|
maxsite = max_site_mean[unit].squeeze()
|
|
1736
|
-
__, x, y = channel_pos[n_sessions][maxsite
|
|
1737
|
-
|
|
1738
|
-
good_x_sites = np.argwhere(
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
2132
|
+
__, x, y = channel_pos[n_sessions][maxsite, :]
|
|
2133
|
+
|
|
2134
|
+
good_x_sites = np.argwhere(
|
|
2135
|
+
np.logical_and(
|
|
2136
|
+
(x - 50 < channel_pos[n_sessions][:, 1]) == True,
|
|
2137
|
+
(channel_pos[n_sessions][:, 1] < x + 50) == True,
|
|
2138
|
+
)
|
|
2139
|
+
)
|
|
2140
|
+
y_values = channel_pos[n_sessions][good_x_sites, 2]
|
|
2141
|
+
|
|
2142
|
+
y_dist_to_max_site = np.abs(y_values - channel_pos[n_sessions][maxsite, 2])
|
|
2143
|
+
good_sites = np.argsort(y_dist_to_max_site, axis=0)[:18]
|
|
1743
2144
|
good_sites = good_x_sites[good_sites]
|
|
1744
2145
|
reordered_good_sites = order_good_sites(good_sites, channel_pos, n_sessions)
|
|
1745
2146
|
|
|
1746
2147
|
else:
|
|
1747
|
-
maxsite = max_site[unit,CV]
|
|
1748
|
-
__, x, y = channel_pos[n_sessions][maxsite
|
|
1749
|
-
|
|
1750
|
-
good_x_sites = np.argwhere(
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
2148
|
+
maxsite = max_site[unit, CV]
|
|
2149
|
+
__, x, y = channel_pos[n_sessions][maxsite, :]
|
|
2150
|
+
|
|
2151
|
+
good_x_sites = np.argwhere(
|
|
2152
|
+
np.logical_and(
|
|
2153
|
+
(x - 50 < channel_pos[n_sessions][:, 1]) == True,
|
|
2154
|
+
(channel_pos[n_sessions][:, 1] < x + 50) == True,
|
|
2155
|
+
)
|
|
2156
|
+
)
|
|
2157
|
+
y_values = channel_pos[n_sessions][good_x_sites, 2]
|
|
2158
|
+
|
|
2159
|
+
y_dist_to_max_site = np.abs(y_values - channel_pos[n_sessions][maxsite, 2])
|
|
2160
|
+
good_sites = np.argsort(y_dist_to_max_site, axis=0)[:18]
|
|
1755
2161
|
good_sites = good_x_sites[good_sites]
|
|
1756
2162
|
reordered_good_sites = order_good_sites(good_sites, channel_pos, n_sessions)
|
|
1757
|
-
|
|
2163
|
+
|
|
1758
2164
|
return reordered_good_sites
|
|
1759
2165
|
|
|
2166
|
+
|
|
1760
2167
|
def plot_raw_waveforms(unit_a, unit_b, CV):
|
|
1761
2168
|
|
|
1762
|
-
session_no_a = clus_info[
|
|
2169
|
+
session_no_a = clus_info["session_id"][unit_a]
|
|
1763
2170
|
global raw_waveform_plot
|
|
1764
2171
|
if raw_waveform_plot.winfo_exists() == 1:
|
|
1765
2172
|
raw_waveform_plot.destroy()
|
|
1766
2173
|
|
|
1767
|
-
fig = Figure(figsize=(4,6), dpi
|
|
2174
|
+
fig = Figure(figsize=(4, 6), dpi=100)
|
|
1768
2175
|
fig.set_tight_layout(False)
|
|
1769
|
-
fig.patch.set_facecolor(
|
|
2176
|
+
fig.patch.set_facecolor("#33393b")
|
|
1770
2177
|
|
|
1771
|
-
main_ax = fig.add_axes([0.2,0.2,0.8,0.8])
|
|
1772
|
-
main_ax.set_facecolor(
|
|
2178
|
+
main_ax = fig.add_axes([0.2, 0.2, 0.8, 0.8])
|
|
2179
|
+
main_ax.set_facecolor("#2d2d2d")
|
|
1773
2180
|
main_ax_offset = 0.2
|
|
1774
2181
|
main_ax_scale = 0.8
|
|
1775
2182
|
|
|
1776
|
-
if CV ==
|
|
1777
|
-
good_channels = nearest_channels(
|
|
2183
|
+
if CV == "Avg":
|
|
2184
|
+
good_channels = nearest_channels(
|
|
2185
|
+
max_site, max_site_mean, channel_pos, clus_info, unit_a, CV
|
|
2186
|
+
)
|
|
1778
2187
|
|
|
1779
|
-
min_x, min_y = channel_pos[session_no_a][good_channels[-2],[1,2]].squeeze()
|
|
1780
|
-
max_x, maxy = channel_pos[session_no_a][good_channels[1],[1,2]].squeeze()
|
|
2188
|
+
min_x, min_y = channel_pos[session_no_a][good_channels[-2], [1, 2]].squeeze()
|
|
2189
|
+
max_x, maxy = channel_pos[session_no_a][good_channels[1], [1, 2]].squeeze()
|
|
1781
2190
|
delta_x = (max_x - min_x) / 2
|
|
1782
2191
|
delta_y = (maxy - min_y) / 18
|
|
1783
2192
|
|
|
1784
|
-
#may want to change so it find this for both units and selects the most extreme arguments
|
|
1785
|
-
#however i dont think tis will be necessary
|
|
1786
|
-
sub_min_y = np.nanmin(waveform[unit_a
|
|
1787
|
-
sub_max_y = np.nanmax(waveform[unit_a
|
|
2193
|
+
# may want to change so it find this for both units and selects the most extreme arguments
|
|
2194
|
+
# however i dont think tis will be necessary
|
|
2195
|
+
sub_min_y = np.nanmin(waveform[unit_a, :, good_channels].mean(axis=-1))
|
|
2196
|
+
sub_max_y = np.nanmax(waveform[unit_a, :, good_channels].mean(axis=-1))
|
|
1788
2197
|
# shift each waveform so 0 is at the channel site, 1/9 is width of a y waveform plot
|
|
1789
|
-
waveform_y_offset = (
|
|
1790
|
-
|
|
2198
|
+
waveform_y_offset = (
|
|
2199
|
+
(np.abs(sub_max_y) / (np.abs(sub_min_y) + np.abs(sub_max_y))) * 1 / 9
|
|
2200
|
+
)
|
|
2201
|
+
|
|
1791
2202
|
else:
|
|
1792
|
-
good_channels = nearest_channels(
|
|
2203
|
+
good_channels = nearest_channels(
|
|
2204
|
+
max_site, max_site_mean, channel_pos, clus_info, unit_a, CV[0]
|
|
2205
|
+
)
|
|
1793
2206
|
|
|
1794
|
-
min_x, min_y = channel_pos[session_no_a][good_channels[-2],[1,2]].squeeze()
|
|
1795
|
-
max_x, maxy = channel_pos[session_no_a][good_channels[1],[1,2]].squeeze()
|
|
2207
|
+
min_x, min_y = channel_pos[session_no_a][good_channels[-2], [1, 2]].squeeze()
|
|
2208
|
+
max_x, maxy = channel_pos[session_no_a][good_channels[1], [1, 2]].squeeze()
|
|
1796
2209
|
delta_x = (max_x - min_x) / 2
|
|
1797
2210
|
delta_y = (maxy - min_y) / 18
|
|
1798
|
-
#may want to change so it find this for both units and selects the most extreme arguments
|
|
1799
|
-
#however i dont think this will be necessary
|
|
1800
|
-
sub_min_y = np.nanmin(waveform[unit_a
|
|
1801
|
-
sub_max_y = np.nanmax(waveform[unit_a
|
|
2211
|
+
# may want to change so it find this for both units and selects the most extreme arguments
|
|
2212
|
+
# however i dont think this will be necessary
|
|
2213
|
+
sub_min_y = np.nanmin(waveform[unit_a, :, good_channels, CV[0]])
|
|
2214
|
+
sub_max_y = np.nanmax(waveform[unit_a, :, good_channels, CV[0]])
|
|
1802
2215
|
# shift each waveform so 0 is at the channel site, 1/9 is width of a y waveform plot
|
|
1803
|
-
waveform_y_offset = (
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
2216
|
+
waveform_y_offset = (
|
|
2217
|
+
(np.abs(sub_max_y) / (np.abs(sub_min_y) + np.abs(sub_max_y))) * 1 / 9
|
|
2218
|
+
)
|
|
2219
|
+
|
|
2220
|
+
# make the main scatter positiose site as scatter with opacity
|
|
2221
|
+
main_ax.scatter(
|
|
2222
|
+
channel_pos[session_no_a][good_channels, 1],
|
|
2223
|
+
channel_pos[session_no_a][good_channels, 2],
|
|
2224
|
+
c="grey",
|
|
2225
|
+
alpha=0.3,
|
|
2226
|
+
)
|
|
1808
2227
|
main_ax.set_xlim(min_x - delta_x, max_x + delta_x)
|
|
1809
2228
|
main_ax.set_ylim(min_y - delta_y, maxy + delta_y)
|
|
1810
2229
|
|
|
1811
2230
|
for i in range(9):
|
|
1812
2231
|
for j in range(2):
|
|
1813
|
-
#may need to change this positioning if units sizes are irregular
|
|
2232
|
+
# may need to change this positioning if units sizes are irregular
|
|
1814
2233
|
if j == 0:
|
|
1815
|
-
#The peak in the waveform is not half way, so maths says the x axis should be starting at
|
|
1816
|
-
#0.1 and 0.6 so the middle is at 0.25/0.76 however chosen these values so it loks better by eye
|
|
2234
|
+
# The peak in the waveform is not half way, so maths says the x axis should be starting at
|
|
2235
|
+
# 0.1 and 0.6 so the middle is at 0.25/0.76 however chosen these values so it loks better by eye
|
|
1817
2236
|
|
|
1818
2237
|
#
|
|
1819
|
-
ax =
|
|
2238
|
+
ax = fig.add_axes(
|
|
2239
|
+
[
|
|
2240
|
+
main_ax_offset + main_ax_scale * 0.25,
|
|
2241
|
+
main_ax_offset
|
|
2242
|
+
+ main_ax_scale * (i / 9 - 1 / 18 + waveform_y_offset),
|
|
2243
|
+
main_ax_scale * 0.25,
|
|
2244
|
+
main_ax_scale * 1 / 9,
|
|
2245
|
+
]
|
|
2246
|
+
)
|
|
1820
2247
|
if j == 1:
|
|
1821
|
-
ax = fig.add_axes(
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
2248
|
+
ax = fig.add_axes(
|
|
2249
|
+
[
|
|
2250
|
+
main_ax_offset + main_ax_scale * 0.75,
|
|
2251
|
+
main_ax_offset
|
|
2252
|
+
+ main_ax_scale * (i / 9 - 1 / 18 + waveform_y_offset),
|
|
2253
|
+
main_ax_scale * 0.25,
|
|
2254
|
+
main_ax_scale * 1 / 9,
|
|
2255
|
+
]
|
|
2256
|
+
)
|
|
2257
|
+
|
|
2258
|
+
if CV == "Avg":
|
|
2259
|
+
ax.plot(
|
|
2260
|
+
waveform[unit_a, :, good_channels[i * 2 + j]]
|
|
2261
|
+
.mean(axis=-1)
|
|
2262
|
+
.squeeze(),
|
|
2263
|
+
color="g",
|
|
2264
|
+
)
|
|
2265
|
+
ax.plot(
|
|
2266
|
+
waveform[unit_b, :, good_channels[i * 2 + j]]
|
|
2267
|
+
.mean(axis=-1)
|
|
2268
|
+
.squeeze(),
|
|
2269
|
+
color="b",
|
|
2270
|
+
lw=0.8,
|
|
2271
|
+
)
|
|
1826
2272
|
else:
|
|
1827
|
-
ax.plot(
|
|
1828
|
-
|
|
1829
|
-
|
|
2273
|
+
ax.plot(
|
|
2274
|
+
waveform[unit_a, :, good_channels[i * 2 + j], CV[0]].squeeze(),
|
|
2275
|
+
color="g",
|
|
2276
|
+
)
|
|
2277
|
+
ax.plot(
|
|
2278
|
+
waveform[unit_b, :, good_channels[i * 2 + j], CV[1]].squeeze(),
|
|
2279
|
+
color="b",
|
|
2280
|
+
lw=0.8,
|
|
2281
|
+
)
|
|
2282
|
+
ax.set_ylim(sub_min_y, sub_max_y)
|
|
1830
2283
|
ax.set_axis_off()
|
|
1831
2284
|
|
|
1832
|
-
|
|
1833
2285
|
main_ax.spines.right.set_visible(False)
|
|
1834
2286
|
main_ax.spines.top.set_visible(False)
|
|
1835
2287
|
main_ax.set_xticks([min_x, max_x])
|
|
1836
|
-
main_ax.set_xlabel(
|
|
1837
|
-
main_ax.set_ylabel(
|
|
1838
|
-
|
|
1839
|
-
|
|
2288
|
+
main_ax.set_xlabel("X position ($\mu$m)", size=14)
|
|
2289
|
+
main_ax.set_ylabel("Y position ($\mu$m)", size=14)
|
|
1840
2290
|
|
|
1841
|
-
raw_waveform_plot = FigureCanvasTkAgg(fig, master
|
|
2291
|
+
raw_waveform_plot = FigureCanvasTkAgg(fig, master=root)
|
|
1842
2292
|
raw_waveform_plot.draw()
|
|
1843
2293
|
raw_waveform_plot = raw_waveform_plot.get_tk_widget()
|
|
1844
|
-
#RawWaveformPlot.configure(bg = '#33393b')
|
|
2294
|
+
# RawWaveformPlot.configure(bg = '#33393b')
|
|
2295
|
+
|
|
2296
|
+
raw_waveform_plot.grid(
|
|
2297
|
+
row=3, column=4, columnspan=2, rowspan=4, padx=15, pady=25, ipadx=15
|
|
2298
|
+
)
|
|
1845
2299
|
|
|
1846
|
-
raw_waveform_plot.grid(row = 3, column = 4, columnspan = 2, rowspan = 4, padx = 15, pady = 25, ipadx = 15)
|
|
1847
2300
|
|
|
1848
2301
|
def plot_histograms(hist_names, hist, hist_matched, scores_to_include, unit_a, unit_b):
|
|
1849
2302
|
|
|
@@ -1851,42 +2304,54 @@ def plot_histograms(hist_names, hist, hist_matched, scores_to_include, unit_a, u
|
|
|
1851
2304
|
if hist_plot.winfo_exists() == 1:
|
|
1852
2305
|
hist_plot.destroy()
|
|
1853
2306
|
|
|
1854
|
-
fig = Figure(figsize=
|
|
1855
|
-
fig.patch.set_facecolor(
|
|
1856
|
-
axs = fig.subplots(3,2, sharex=
|
|
2307
|
+
fig = Figure(figsize=(4, 6), dpi=100, layout="constrained")
|
|
2308
|
+
fig.patch.set_facecolor("#33393b")
|
|
2309
|
+
axs = fig.subplots(3, 2, sharex="col")
|
|
1857
2310
|
axs = axs.flat
|
|
1858
2311
|
|
|
1859
|
-
|
|
1860
2312
|
# Create title mapping
|
|
1861
2313
|
title_mapping = {
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
2314
|
+
"amp_score": "Amplitude score",
|
|
2315
|
+
"spatial_decay_score": "Spatial decay score",
|
|
2316
|
+
"centroid_overlord_score": "C'oid overlord score",
|
|
2317
|
+
"centroid_dist": "C'oid distance score",
|
|
2318
|
+
"waveform_score": "Waveform score",
|
|
2319
|
+
"trajectory_score": "Trajectory score",
|
|
1868
2320
|
}
|
|
1869
|
-
|
|
1870
|
-
#loop over indexes..
|
|
2321
|
+
|
|
2322
|
+
# loop over indexes..
|
|
1871
2323
|
for i in range(len(hist)):
|
|
1872
|
-
axs[i].step(
|
|
1873
|
-
|
|
2324
|
+
axs[i].step(
|
|
2325
|
+
hist[i][1][:-1],
|
|
2326
|
+
hist[i][0],
|
|
2327
|
+
color="orange",
|
|
2328
|
+
label="All scores" if i == 0 else "",
|
|
2329
|
+
)
|
|
2330
|
+
axs[i].step(
|
|
2331
|
+
hist_matched[i][1][:-1],
|
|
2332
|
+
hist_matched[i][0],
|
|
2333
|
+
color="magenta",
|
|
2334
|
+
label="Expected matches" if i == 0 else "",
|
|
2335
|
+
)
|
|
1874
2336
|
axs[i].set_ylim(bottom=0)
|
|
1875
|
-
|
|
2337
|
+
|
|
1876
2338
|
# Use improved title from mapping
|
|
1877
2339
|
plot_title = title_mapping.get(hist_names[i], hist_names[i])
|
|
1878
|
-
axs[i].set_title(plot_title, fontsize
|
|
1879
|
-
|
|
2340
|
+
axs[i].set_title(plot_title, fontsize=12)
|
|
2341
|
+
|
|
1880
2342
|
# Add ylabel
|
|
1881
|
-
axs[i].set_ylabel(
|
|
1882
|
-
|
|
1883
|
-
axs[i].axvline(
|
|
1884
|
-
|
|
1885
|
-
|
|
2343
|
+
axs[i].set_ylabel("% units", fontsize=10)
|
|
2344
|
+
|
|
2345
|
+
axs[i].axvline(
|
|
2346
|
+
scores_to_include[hist_names[i]][unit_a, unit_b],
|
|
2347
|
+
ls="--",
|
|
2348
|
+
color="white",
|
|
2349
|
+
label="Current match pair" if i == 0 else "",
|
|
2350
|
+
)
|
|
2351
|
+
axs[i].set_facecolor("#2d2d2d")
|
|
1886
2352
|
|
|
1887
|
-
hist_plot = FigureCanvasTkAgg(fig, master
|
|
2353
|
+
hist_plot = FigureCanvasTkAgg(fig, master=root)
|
|
1888
2354
|
hist_plot.draw()
|
|
1889
2355
|
hist_plot = hist_plot.get_tk_widget()
|
|
1890
2356
|
|
|
1891
|
-
hist_plot.grid(row
|
|
1892
|
-
|
|
2357
|
+
hist_plot.grid(row=3, column=6, columnspan=2, rowspan=4, padx=5, pady=20)
|