py-neuromodulation 0.0.4__py3-none-any.whl → 0.0.6__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.
- py_neuromodulation/ConnectivityDecoding/_get_grid_hull.m +34 -34
- py_neuromodulation/ConnectivityDecoding/_get_grid_whole_brain.py +95 -106
- py_neuromodulation/ConnectivityDecoding/_helper_write_connectome.py +107 -119
- py_neuromodulation/__init__.py +80 -13
- py_neuromodulation/{nm_RMAP.py → analysis/RMAP.py} +496 -531
- py_neuromodulation/analysis/__init__.py +4 -0
- py_neuromodulation/{nm_decode.py → analysis/decode.py} +918 -992
- py_neuromodulation/{nm_analysis.py → analysis/feature_reader.py} +994 -1074
- py_neuromodulation/{nm_plots.py → analysis/plots.py} +627 -612
- py_neuromodulation/{nm_stats.py → analysis/stats.py} +458 -480
- py_neuromodulation/data/README +6 -6
- py_neuromodulation/data/dataset_description.json +8 -8
- py_neuromodulation/data/participants.json +32 -32
- py_neuromodulation/data/participants.tsv +2 -2
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_coordsystem.json +5 -5
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_space-mni_electrodes.tsv +11 -11
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_channels.tsv +11 -11
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.json +18 -18
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vhdr +35 -35
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/ieeg/sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vmrk +13 -13
- py_neuromodulation/data/sub-testsub/ses-EphysMedOff/sub-testsub_ses-EphysMedOff_scans.tsv +2 -2
- py_neuromodulation/default_settings.yaml +241 -0
- py_neuromodulation/features/__init__.py +31 -0
- py_neuromodulation/features/bandpower.py +165 -0
- py_neuromodulation/features/bispectra.py +157 -0
- py_neuromodulation/features/bursts.py +297 -0
- py_neuromodulation/features/coherence.py +255 -0
- py_neuromodulation/features/feature_processor.py +121 -0
- py_neuromodulation/features/fooof.py +142 -0
- py_neuromodulation/features/hjorth_raw.py +57 -0
- py_neuromodulation/features/linelength.py +21 -0
- py_neuromodulation/features/mne_connectivity.py +148 -0
- py_neuromodulation/features/nolds.py +94 -0
- py_neuromodulation/features/oscillatory.py +249 -0
- py_neuromodulation/features/sharpwaves.py +432 -0
- py_neuromodulation/filter/__init__.py +3 -0
- py_neuromodulation/filter/kalman_filter.py +67 -0
- py_neuromodulation/filter/kalman_filter_external.py +1890 -0
- py_neuromodulation/filter/mne_filter.py +128 -0
- py_neuromodulation/filter/notch_filter.py +93 -0
- py_neuromodulation/grid_cortex.tsv +40 -40
- py_neuromodulation/liblsl/libpugixml.so.1.12 +0 -0
- py_neuromodulation/liblsl/linux/bionic_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/bookworm_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/focal_amd46/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/jammy_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/jammy_x86/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/linux/noble_amd64/liblsl.1.16.2.so +0 -0
- py_neuromodulation/liblsl/macos/amd64/liblsl.1.16.2.dylib +0 -0
- py_neuromodulation/liblsl/macos/arm64/liblsl.1.16.0.dylib +0 -0
- py_neuromodulation/liblsl/windows/amd64/liblsl.1.16.2.dll +0 -0
- py_neuromodulation/liblsl/windows/x86/liblsl.1.16.2.dll +0 -0
- py_neuromodulation/processing/__init__.py +10 -0
- py_neuromodulation/{nm_artifacts.py → processing/artifacts.py} +29 -25
- py_neuromodulation/processing/data_preprocessor.py +77 -0
- py_neuromodulation/processing/filter_preprocessing.py +78 -0
- py_neuromodulation/processing/normalization.py +175 -0
- py_neuromodulation/{nm_projection.py → processing/projection.py} +370 -394
- py_neuromodulation/{nm_rereference.py → processing/rereference.py} +97 -95
- py_neuromodulation/{nm_resample.py → processing/resample.py} +56 -50
- py_neuromodulation/stream/__init__.py +3 -0
- py_neuromodulation/stream/data_processor.py +325 -0
- py_neuromodulation/stream/generator.py +53 -0
- py_neuromodulation/stream/mnelsl_player.py +94 -0
- py_neuromodulation/stream/mnelsl_stream.py +120 -0
- py_neuromodulation/stream/settings.py +292 -0
- py_neuromodulation/stream/stream.py +427 -0
- py_neuromodulation/utils/__init__.py +2 -0
- py_neuromodulation/{nm_define_nmchannels.py → utils/channels.py} +305 -302
- py_neuromodulation/utils/database.py +149 -0
- py_neuromodulation/utils/io.py +378 -0
- py_neuromodulation/utils/keyboard.py +52 -0
- py_neuromodulation/utils/logging.py +66 -0
- py_neuromodulation/utils/types.py +251 -0
- {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.6.dist-info}/METADATA +28 -33
- py_neuromodulation-0.0.6.dist-info/RECORD +89 -0
- {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.6.dist-info}/WHEEL +1 -1
- {py_neuromodulation-0.0.4.dist-info → py_neuromodulation-0.0.6.dist-info}/licenses/LICENSE +21 -21
- py_neuromodulation/FieldTrip.py +0 -589
- py_neuromodulation/_write_example_dataset_helper.py +0 -65
- py_neuromodulation/nm_EpochStream.py +0 -92
- py_neuromodulation/nm_IO.py +0 -417
- py_neuromodulation/nm_across_patient_decoding.py +0 -927
- py_neuromodulation/nm_bispectra.py +0 -168
- py_neuromodulation/nm_bursts.py +0 -198
- py_neuromodulation/nm_coherence.py +0 -205
- py_neuromodulation/nm_cohortwrapper.py +0 -435
- py_neuromodulation/nm_eval_timing.py +0 -239
- py_neuromodulation/nm_features.py +0 -116
- py_neuromodulation/nm_features_abc.py +0 -39
- py_neuromodulation/nm_filter.py +0 -219
- py_neuromodulation/nm_filter_preprocessing.py +0 -91
- py_neuromodulation/nm_fooof.py +0 -159
- py_neuromodulation/nm_generator.py +0 -37
- py_neuromodulation/nm_hjorth_raw.py +0 -73
- py_neuromodulation/nm_kalmanfilter.py +0 -58
- py_neuromodulation/nm_linelength.py +0 -33
- py_neuromodulation/nm_mne_connectivity.py +0 -112
- py_neuromodulation/nm_nolds.py +0 -93
- py_neuromodulation/nm_normalization.py +0 -214
- py_neuromodulation/nm_oscillatory.py +0 -448
- py_neuromodulation/nm_run_analysis.py +0 -435
- py_neuromodulation/nm_settings.json +0 -338
- py_neuromodulation/nm_settings.py +0 -68
- py_neuromodulation/nm_sharpwaves.py +0 -401
- py_neuromodulation/nm_stream_abc.py +0 -218
- py_neuromodulation/nm_stream_offline.py +0 -359
- py_neuromodulation/utils/_logging.py +0 -24
- py_neuromodulation-0.0.4.dist-info/RECORD +0 -72
|
@@ -1,612 +1,627 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
from matplotlib import
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
plt.
|
|
70
|
-
plt.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
plt.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
plt.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
plt.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
plt.
|
|
125
|
-
plt.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
plt.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
plt.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
plt.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if feature_name
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
plt.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
)
|
|
357
|
-
plt.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
plt.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
self
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
grid_cortex
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
if
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from matplotlib import pyplot as plt
|
|
4
|
+
from matplotlib import gridspec
|
|
5
|
+
import seaborn as sb
|
|
6
|
+
from pathlib import PurePath
|
|
7
|
+
from py_neuromodulation import logger, PYNM_DIR
|
|
8
|
+
from py_neuromodulation.utils.types import _PathLike
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def plot_df_subjects(
|
|
12
|
+
df,
|
|
13
|
+
x_col="sub",
|
|
14
|
+
y_col="performance_test",
|
|
15
|
+
hue=None,
|
|
16
|
+
title="channel specific performances",
|
|
17
|
+
PATH_SAVE: _PathLike = "",
|
|
18
|
+
figsize_tuple: tuple[float, float] = (5, 3),
|
|
19
|
+
):
|
|
20
|
+
alpha_box = 0.4
|
|
21
|
+
plt.figure(figsize=figsize_tuple, dpi=300)
|
|
22
|
+
sb.boxplot(
|
|
23
|
+
x=x_col,
|
|
24
|
+
y=y_col,
|
|
25
|
+
hue=hue,
|
|
26
|
+
data=df,
|
|
27
|
+
palette="viridis",
|
|
28
|
+
showmeans=False,
|
|
29
|
+
boxprops=dict(alpha=alpha_box),
|
|
30
|
+
showcaps=True,
|
|
31
|
+
showbox=True,
|
|
32
|
+
showfliers=False,
|
|
33
|
+
notch=False,
|
|
34
|
+
whiskerprops={"linewidth": 2, "zorder": 10, "alpha": alpha_box},
|
|
35
|
+
capprops={"alpha": alpha_box},
|
|
36
|
+
medianprops=dict(linestyle="-", linewidth=5, color="gray", alpha=alpha_box),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
ax = sb.stripplot(
|
|
40
|
+
x=x_col,
|
|
41
|
+
y=y_col,
|
|
42
|
+
hue=hue,
|
|
43
|
+
data=df,
|
|
44
|
+
palette="viridis",
|
|
45
|
+
dodge=True,
|
|
46
|
+
s=5,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if hue is not None:
|
|
50
|
+
n_hues = df[hue].nunique()
|
|
51
|
+
|
|
52
|
+
handles, labels = ax.get_legend_handles_labels()
|
|
53
|
+
plt.legend(
|
|
54
|
+
handles[0:n_hues],
|
|
55
|
+
labels[0:n_hues],
|
|
56
|
+
bbox_to_anchor=(1.05, 1),
|
|
57
|
+
loc=2,
|
|
58
|
+
title=hue,
|
|
59
|
+
borderaxespad=0.0,
|
|
60
|
+
)
|
|
61
|
+
plt.title(title)
|
|
62
|
+
plt.ylabel(y_col)
|
|
63
|
+
plt.xticks(rotation=90)
|
|
64
|
+
if PATH_SAVE:
|
|
65
|
+
plt.savefig(
|
|
66
|
+
PATH_SAVE,
|
|
67
|
+
bbox_inches="tight",
|
|
68
|
+
)
|
|
69
|
+
# plt.show()
|
|
70
|
+
return plt.gca()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def plot_epoch(
|
|
74
|
+
X_epoch: np.ndarray,
|
|
75
|
+
y_epoch: np.ndarray,
|
|
76
|
+
feature_names: list,
|
|
77
|
+
z_score: bool | None = None,
|
|
78
|
+
epoch_len: int = 4,
|
|
79
|
+
sfreq: int = 10,
|
|
80
|
+
str_title: str = "",
|
|
81
|
+
str_label: str = "",
|
|
82
|
+
ytick_labelsize: float | None = None,
|
|
83
|
+
):
|
|
84
|
+
from scipy.stats import zscore
|
|
85
|
+
|
|
86
|
+
if z_score is None:
|
|
87
|
+
X_epoch = zscore(
|
|
88
|
+
np.nan_to_num(np.nanmean(np.squeeze(X_epoch), axis=0)),
|
|
89
|
+
axis=0,
|
|
90
|
+
nan_policy="omit",
|
|
91
|
+
).T
|
|
92
|
+
y_epoch = np.stack([np.array(y_epoch)])
|
|
93
|
+
plt.figure(figsize=(6, 6))
|
|
94
|
+
plt.subplot(211)
|
|
95
|
+
plt.imshow(X_epoch, aspect="auto")
|
|
96
|
+
plt.yticks(np.arange(0, len(feature_names), 1), feature_names, size=ytick_labelsize)
|
|
97
|
+
plt.xticks(
|
|
98
|
+
np.arange(0, X_epoch.shape[1], 1),
|
|
99
|
+
np.round(np.arange(-epoch_len / 2, epoch_len / 2, 1 / sfreq), 2),
|
|
100
|
+
rotation=90,
|
|
101
|
+
)
|
|
102
|
+
plt.gca().invert_yaxis()
|
|
103
|
+
plt.xlabel("Time [s]")
|
|
104
|
+
plt.title(str_title)
|
|
105
|
+
|
|
106
|
+
plt.subplot(212)
|
|
107
|
+
for i in range(y_epoch.shape[0]):
|
|
108
|
+
plt.plot(y_epoch[i, :], color="black", alpha=0.4)
|
|
109
|
+
plt.plot(
|
|
110
|
+
y_epoch.mean(axis=0),
|
|
111
|
+
color="black",
|
|
112
|
+
alpha=1,
|
|
113
|
+
linewidth=3.0,
|
|
114
|
+
label="mean target",
|
|
115
|
+
)
|
|
116
|
+
plt.legend()
|
|
117
|
+
plt.ylabel("Target")
|
|
118
|
+
plt.title(str_label)
|
|
119
|
+
plt.xticks(
|
|
120
|
+
np.arange(0, X_epoch.shape[1], 1),
|
|
121
|
+
np.round(np.arange(-epoch_len / 2, epoch_len / 2, 1 / sfreq), 2),
|
|
122
|
+
rotation=90,
|
|
123
|
+
)
|
|
124
|
+
plt.xlabel("Time [s]")
|
|
125
|
+
plt.tight_layout()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def reg_plot(
|
|
129
|
+
x_col: str, y_col: str, data: pd.DataFrame, out_path_save: str | None = None
|
|
130
|
+
):
|
|
131
|
+
from py_neuromodulation.analysis.stats import permutationTestSpearmansRho
|
|
132
|
+
|
|
133
|
+
plt.figure(figsize=(4, 4), dpi=300)
|
|
134
|
+
rho, p = permutationTestSpearmansRho(
|
|
135
|
+
data[x_col],
|
|
136
|
+
data[y_col],
|
|
137
|
+
False,
|
|
138
|
+
"R^2",
|
|
139
|
+
5000,
|
|
140
|
+
)
|
|
141
|
+
sb.regplot(x=x_col, y=y_col, data=data)
|
|
142
|
+
plt.title(f"{y_col}~{x_col} p={np.round(p, 2)} rho={np.round(rho, 2)}")
|
|
143
|
+
|
|
144
|
+
if out_path_save is not None:
|
|
145
|
+
plt.savefig(
|
|
146
|
+
out_path_save,
|
|
147
|
+
bbox_inches="tight",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def plot_bar_performance_per_channel(
|
|
152
|
+
ch_names,
|
|
153
|
+
performances: dict,
|
|
154
|
+
PATH_OUT: _PathLike,
|
|
155
|
+
sub: str | None = None,
|
|
156
|
+
save_str: str = "ch_comp_bar_plt.png",
|
|
157
|
+
performance_metric: str = "Balanced Accuracy",
|
|
158
|
+
):
|
|
159
|
+
"""
|
|
160
|
+
performances dict is output of ml_decode
|
|
161
|
+
"""
|
|
162
|
+
plt.figure(figsize=(4, 3), dpi=300)
|
|
163
|
+
if sub is None:
|
|
164
|
+
sub = list(performances.keys())[0]
|
|
165
|
+
plt.bar(
|
|
166
|
+
np.arange(len(ch_names)),
|
|
167
|
+
[performances[sub][p]["performance_test"] for p in performances[sub]],
|
|
168
|
+
)
|
|
169
|
+
plt.xticks(np.arange(len(ch_names)), ch_names, rotation=90)
|
|
170
|
+
plt.xlabel("channels")
|
|
171
|
+
plt.ylabel(performance_metric)
|
|
172
|
+
plt.savefig(
|
|
173
|
+
PurePath(PATH_OUT, save_str),
|
|
174
|
+
bbox_inches="tight",
|
|
175
|
+
)
|
|
176
|
+
plt.close()
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def plot_corr_matrix(
|
|
180
|
+
feature: pd.DataFrame,
|
|
181
|
+
feature_file: _PathLike = "",
|
|
182
|
+
ch_name: str = "",
|
|
183
|
+
feature_names: list[str] = [],
|
|
184
|
+
show_plot=True,
|
|
185
|
+
OUT_PATH: _PathLike = "",
|
|
186
|
+
feature_name_plt="Features_corr_matr",
|
|
187
|
+
save_plot: bool = False,
|
|
188
|
+
save_plot_name: str = "",
|
|
189
|
+
figsize: tuple[float, float] = (7, 7),
|
|
190
|
+
title: str = "",
|
|
191
|
+
cbar_vmin: float = -1,
|
|
192
|
+
cbar_vmax: float = 1.0,
|
|
193
|
+
):
|
|
194
|
+
# cut out channel name for each column
|
|
195
|
+
if not ch_name:
|
|
196
|
+
feature_col_name = [
|
|
197
|
+
i[len(ch_name) + 1 :] for i in feature_names if ch_name in i
|
|
198
|
+
]
|
|
199
|
+
else:
|
|
200
|
+
feature_col_name = feature.columns
|
|
201
|
+
|
|
202
|
+
plt.figure(figsize=figsize)
|
|
203
|
+
if (
|
|
204
|
+
len(feature_names) > 0
|
|
205
|
+
): # Checking length to accomodate for tests passing a pandas Index
|
|
206
|
+
corr = feature[feature_names].corr()
|
|
207
|
+
else:
|
|
208
|
+
corr = feature.corr()
|
|
209
|
+
sb.heatmap(
|
|
210
|
+
corr,
|
|
211
|
+
xticklabels=feature_col_name,
|
|
212
|
+
yticklabels=feature_col_name,
|
|
213
|
+
vmin=cbar_vmin,
|
|
214
|
+
vmax=cbar_vmax,
|
|
215
|
+
cmap="viridis",
|
|
216
|
+
)
|
|
217
|
+
if not title:
|
|
218
|
+
if ch_name:
|
|
219
|
+
plt.title("Correlation matrix features channel: " + str(ch_name))
|
|
220
|
+
else:
|
|
221
|
+
plt.title("Correlation matrix")
|
|
222
|
+
else:
|
|
223
|
+
plt.title(title)
|
|
224
|
+
|
|
225
|
+
# if len(feature_col_name) > 50:
|
|
226
|
+
# plt.xticks([])
|
|
227
|
+
# plt.yticks([])
|
|
228
|
+
|
|
229
|
+
if save_plot:
|
|
230
|
+
plt_path = (
|
|
231
|
+
PurePath(OUT_PATH, save_plot_name)
|
|
232
|
+
if save_plot_name
|
|
233
|
+
else get_plt_path(
|
|
234
|
+
OUT_PATH=OUT_PATH,
|
|
235
|
+
feature_file=feature_file,
|
|
236
|
+
ch_name=ch_name,
|
|
237
|
+
str_plt_type=feature_name_plt,
|
|
238
|
+
feature_name="_".join(feature_names),
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
plt.savefig(plt_path, bbox_inches="tight")
|
|
243
|
+
logger.info(f"Correlation matrix figure saved to {plt_path}")
|
|
244
|
+
|
|
245
|
+
if not show_plot:
|
|
246
|
+
plt.close()
|
|
247
|
+
|
|
248
|
+
plt.tight_layout()
|
|
249
|
+
|
|
250
|
+
return plt.gca()
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def plot_feature_series_time(features) -> None:
|
|
254
|
+
plt.imshow(features.T, aspect="auto")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def get_plt_path(
|
|
258
|
+
OUT_PATH: _PathLike = "",
|
|
259
|
+
feature_file: str = "",
|
|
260
|
+
ch_name: str = "",
|
|
261
|
+
str_plt_type: str = "",
|
|
262
|
+
feature_name: str = "",
|
|
263
|
+
) -> _PathLike:
|
|
264
|
+
"""[summary]
|
|
265
|
+
|
|
266
|
+
Parameters
|
|
267
|
+
----------
|
|
268
|
+
OUT_PATH : str, optional
|
|
269
|
+
folder of preprocessed runs, by default None
|
|
270
|
+
feature_file : str, optional
|
|
271
|
+
run_name, by default None
|
|
272
|
+
ch_name : str, optional
|
|
273
|
+
ch_name, by default None
|
|
274
|
+
str_plt_type : str, optional
|
|
275
|
+
type of plot, e.g. mov_avg_feature or corr_matr, by default None
|
|
276
|
+
feature_name : str, optional
|
|
277
|
+
e.g. bandpower, stft, sharpwave_prominence, by default None
|
|
278
|
+
"""
|
|
279
|
+
filename = (
|
|
280
|
+
str_plt_type
|
|
281
|
+
+ (("_ch_" + ch_name) if ch_name else "")
|
|
282
|
+
+ (("_" + feature_name) if feature_name else "")
|
|
283
|
+
+ ".png"
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
return PurePath(OUT_PATH, feature_file, filename)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def plot_epochs_avg(
|
|
290
|
+
X_epoch: np.ndarray,
|
|
291
|
+
y_epoch: np.ndarray,
|
|
292
|
+
epoch_len: int,
|
|
293
|
+
sfreq: int,
|
|
294
|
+
feature_names: list[str] = [],
|
|
295
|
+
feature_str_add: str = "",
|
|
296
|
+
cut_ch_name_cols: bool = True,
|
|
297
|
+
ch_name: str = "",
|
|
298
|
+
label_name: str = "",
|
|
299
|
+
normalize_data: bool = True,
|
|
300
|
+
show_plot: bool = True,
|
|
301
|
+
save: bool = False,
|
|
302
|
+
OUT_PATH: _PathLike = "",
|
|
303
|
+
feature_file: str = "",
|
|
304
|
+
str_title: str = "Movement aligned features",
|
|
305
|
+
ytick_labelsize=None,
|
|
306
|
+
figsize_x: float = 8,
|
|
307
|
+
figsize_y: float = 8,
|
|
308
|
+
) -> None:
|
|
309
|
+
from scipy.stats import zscore
|
|
310
|
+
|
|
311
|
+
# cut channel name of for axis + "_" for more dense plot
|
|
312
|
+
if not feature_names:
|
|
313
|
+
if cut_ch_name_cols and None not in (ch_name, feature_names):
|
|
314
|
+
feature_names = [
|
|
315
|
+
i[len(ch_name) + 1 :] for i in list(feature_names) if ch_name in i
|
|
316
|
+
]
|
|
317
|
+
|
|
318
|
+
if normalize_data:
|
|
319
|
+
X_epoch_mean = zscore(
|
|
320
|
+
np.nanmean(np.squeeze(X_epoch), axis=0), axis=0, nan_policy="omit"
|
|
321
|
+
).T
|
|
322
|
+
else:
|
|
323
|
+
X_epoch_mean = np.nanmean(np.squeeze(X_epoch), axis=0).T
|
|
324
|
+
|
|
325
|
+
if len(X_epoch_mean.shape) == 1:
|
|
326
|
+
X_epoch_mean = np.expand_dims(X_epoch_mean, axis=0)
|
|
327
|
+
|
|
328
|
+
plt.figure(figsize=(figsize_x, figsize_y))
|
|
329
|
+
gs = gridspec.GridSpec(2, 1, height_ratios=[2.5, 1])
|
|
330
|
+
plt.subplot(gs[0])
|
|
331
|
+
plt.imshow(X_epoch_mean, aspect="auto")
|
|
332
|
+
plt.yticks(np.arange(0, len(feature_names), 1), feature_names, size=ytick_labelsize)
|
|
333
|
+
plt.xticks(
|
|
334
|
+
np.arange(0, X_epoch.shape[1], int(X_epoch.shape[1] / 10)),
|
|
335
|
+
np.round(np.arange(-epoch_len / 2, epoch_len / 2, epoch_len / 10), 2),
|
|
336
|
+
rotation=90,
|
|
337
|
+
)
|
|
338
|
+
plt.xlabel("Time [s]")
|
|
339
|
+
str_title = str_title
|
|
340
|
+
if ch_name:
|
|
341
|
+
str_title += f" channel: {ch_name}"
|
|
342
|
+
plt.title(str_title)
|
|
343
|
+
|
|
344
|
+
plt.subplot(gs[1])
|
|
345
|
+
for i in range(y_epoch.shape[0]):
|
|
346
|
+
plt.plot(y_epoch[i, :], color="black", alpha=0.4)
|
|
347
|
+
plt.plot(
|
|
348
|
+
y_epoch.mean(axis=0),
|
|
349
|
+
color="black",
|
|
350
|
+
alpha=1,
|
|
351
|
+
linewidth=3.0,
|
|
352
|
+
label="mean target",
|
|
353
|
+
)
|
|
354
|
+
plt.legend()
|
|
355
|
+
plt.ylabel("Target")
|
|
356
|
+
plt.title(label_name)
|
|
357
|
+
plt.xticks(
|
|
358
|
+
np.arange(0, X_epoch.shape[1], int(X_epoch.shape[1] / 10)),
|
|
359
|
+
np.round(np.arange(-epoch_len / 2, epoch_len / 2, epoch_len / 10), 2),
|
|
360
|
+
rotation=90,
|
|
361
|
+
)
|
|
362
|
+
plt.xlabel("Time [s]")
|
|
363
|
+
plt.tight_layout()
|
|
364
|
+
|
|
365
|
+
if save:
|
|
366
|
+
plt_path = get_plt_path(
|
|
367
|
+
OUT_PATH,
|
|
368
|
+
feature_file,
|
|
369
|
+
ch_name,
|
|
370
|
+
str_plt_type="MOV_aligned_features",
|
|
371
|
+
feature_name=feature_str_add,
|
|
372
|
+
)
|
|
373
|
+
plt.savefig(plt_path, bbox_inches="tight")
|
|
374
|
+
logger.info(f"Feature epoch average figure saved to: {str(plt_path)}")
|
|
375
|
+
if not show_plot:
|
|
376
|
+
plt.close()
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def plot_grid_elec_3d(
|
|
380
|
+
cortex_grid: np.ndarray | None = None,
|
|
381
|
+
ecog_strip: np.ndarray | None = None,
|
|
382
|
+
grid_color: np.ndarray | None = None,
|
|
383
|
+
strip_color: np.ndarray | None = None,
|
|
384
|
+
):
|
|
385
|
+
ax = plt.axes(projection="3d")
|
|
386
|
+
|
|
387
|
+
if cortex_grid is not None:
|
|
388
|
+
grid_color = np.ones(cortex_grid.shape[0]) if grid_color is None else grid_color
|
|
389
|
+
_ = ax.scatter3D(
|
|
390
|
+
cortex_grid[:, 0],
|
|
391
|
+
cortex_grid[:, 1],
|
|
392
|
+
cortex_grid[:, 2],
|
|
393
|
+
c=grid_color,
|
|
394
|
+
s=300,
|
|
395
|
+
alpha=0.8,
|
|
396
|
+
cmap="viridis",
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
if ecog_strip is not None:
|
|
400
|
+
strip_color = (
|
|
401
|
+
np.ones(ecog_strip.shape[0]) if strip_color is None else strip_color
|
|
402
|
+
)
|
|
403
|
+
_ = ax.scatter(
|
|
404
|
+
ecog_strip[:, 0],
|
|
405
|
+
ecog_strip[:, 1],
|
|
406
|
+
ecog_strip[:, 2],
|
|
407
|
+
c=strip_color,
|
|
408
|
+
s=500, # Bug? Third argument is s, what is this value?
|
|
409
|
+
alpha=0.8,
|
|
410
|
+
cmap="gray",
|
|
411
|
+
marker="o",
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def plot_all_features(
|
|
416
|
+
df: pd.DataFrame,
|
|
417
|
+
time_limit_low_s: float | None = None,
|
|
418
|
+
time_limit_high_s: float | None = None,
|
|
419
|
+
normalize: bool = True,
|
|
420
|
+
ytick_labelsize: int = 4,
|
|
421
|
+
clim_low: float | None = None,
|
|
422
|
+
clim_high: float | None = None,
|
|
423
|
+
save: bool = False,
|
|
424
|
+
title="all_feature_plt.pdf",
|
|
425
|
+
OUT_PATH: _PathLike = "",
|
|
426
|
+
feature_file: str = "",
|
|
427
|
+
):
|
|
428
|
+
from scipy.stats import zscore
|
|
429
|
+
|
|
430
|
+
if time_limit_high_s is not None:
|
|
431
|
+
df = df[df["time"] < time_limit_high_s * 1000]
|
|
432
|
+
if time_limit_low_s is not None:
|
|
433
|
+
df = df[df["time"] > time_limit_low_s * 1000]
|
|
434
|
+
|
|
435
|
+
cols_plt = [c for c in df.columns if c != "time"]
|
|
436
|
+
if normalize:
|
|
437
|
+
data_plt = zscore(df[cols_plt], nan_policy="omit")
|
|
438
|
+
else:
|
|
439
|
+
data_plt = df[cols_plt]
|
|
440
|
+
|
|
441
|
+
plt.figure() # figsize=(7, 5), dpi=300
|
|
442
|
+
plt.imshow(data_plt.T, aspect="auto")
|
|
443
|
+
plt.xlabel("Time [s]")
|
|
444
|
+
plt.ylabel("Feature Names")
|
|
445
|
+
plt.yticks(np.arange(len(cols_plt)), cols_plt, size=ytick_labelsize)
|
|
446
|
+
|
|
447
|
+
tick_num = np.arange(0, df.shape[0], int(df.shape[0] / 10))
|
|
448
|
+
tick_labels = np.array(np.rint(df["time"].iloc[tick_num] / 1000), dtype=int)
|
|
449
|
+
plt.xticks(tick_num, tick_labels)
|
|
450
|
+
|
|
451
|
+
plt.title(f"Feature Plot {feature_file}")
|
|
452
|
+
|
|
453
|
+
if clim_low is not None:
|
|
454
|
+
plt.clim(vmin=clim_low)
|
|
455
|
+
if clim_high is not None:
|
|
456
|
+
plt.clim(vmax=clim_high)
|
|
457
|
+
|
|
458
|
+
plt.colorbar()
|
|
459
|
+
plt.tight_layout()
|
|
460
|
+
|
|
461
|
+
if save:
|
|
462
|
+
plt_path = PurePath(OUT_PATH, feature_file, title)
|
|
463
|
+
plt.savefig(plt_path, bbox_inches="tight")
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def read_plot_modules(
|
|
467
|
+
PATH_PLOT: _PathLike = PYNM_DIR / "plots",
|
|
468
|
+
):
|
|
469
|
+
"""Read required .mat files for plotting
|
|
470
|
+
|
|
471
|
+
Parameters
|
|
472
|
+
----------
|
|
473
|
+
PATH_PLOT : regexp, optional
|
|
474
|
+
path to plotting files, by default
|
|
475
|
+
"""
|
|
476
|
+
from py_neuromodulation.utils.io import loadmat
|
|
477
|
+
|
|
478
|
+
faces = loadmat(PurePath(PATH_PLOT, "faces.mat"))
|
|
479
|
+
vertices = loadmat(PurePath(PATH_PLOT, "Vertices.mat"))
|
|
480
|
+
grid = loadmat(PurePath(PATH_PLOT, "grid.mat"))["grid"]
|
|
481
|
+
stn_surf = loadmat(PurePath(PATH_PLOT, "STN_surf.mat"))
|
|
482
|
+
x_ver = stn_surf["vertices"][::2, 0]
|
|
483
|
+
y_ver = stn_surf["vertices"][::2, 1]
|
|
484
|
+
x_ecog = vertices["Vertices"][::1, 0]
|
|
485
|
+
y_ecog = vertices["Vertices"][::1, 1]
|
|
486
|
+
z_ecog = vertices["Vertices"][::1, 2]
|
|
487
|
+
x_stn = stn_surf["vertices"][::1, 0]
|
|
488
|
+
y_stn = stn_surf["vertices"][::1, 1]
|
|
489
|
+
z_stn = stn_surf["vertices"][::1, 2]
|
|
490
|
+
|
|
491
|
+
return (
|
|
492
|
+
faces,
|
|
493
|
+
vertices,
|
|
494
|
+
grid,
|
|
495
|
+
stn_surf,
|
|
496
|
+
x_ver,
|
|
497
|
+
y_ver,
|
|
498
|
+
x_ecog,
|
|
499
|
+
y_ecog,
|
|
500
|
+
z_ecog,
|
|
501
|
+
x_stn,
|
|
502
|
+
y_stn,
|
|
503
|
+
z_stn,
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
class NM_Plot:
|
|
508
|
+
def __init__(
|
|
509
|
+
self,
|
|
510
|
+
ecog_strip: np.ndarray | None = None,
|
|
511
|
+
grid_cortex: np.ndarray | None = None,
|
|
512
|
+
grid_subcortex: np.ndarray | None = None,
|
|
513
|
+
sess_right: bool | None = False,
|
|
514
|
+
proj_matrix_cortex: np.ndarray | None = None,
|
|
515
|
+
) -> None:
|
|
516
|
+
self.grid_cortex = grid_cortex
|
|
517
|
+
self.grid_subcortex = grid_subcortex
|
|
518
|
+
self.ecog_strip = ecog_strip
|
|
519
|
+
self.sess_right = sess_right
|
|
520
|
+
self.proj_matrix_cortex = proj_matrix_cortex
|
|
521
|
+
|
|
522
|
+
(
|
|
523
|
+
self.faces,
|
|
524
|
+
self.vertices,
|
|
525
|
+
self.grid,
|
|
526
|
+
self.stn_surf,
|
|
527
|
+
self.x_ver,
|
|
528
|
+
self.y_ver,
|
|
529
|
+
self.x_ecog,
|
|
530
|
+
self.y_ecog,
|
|
531
|
+
self.z_ecog,
|
|
532
|
+
self.x_stn,
|
|
533
|
+
self.y_stn,
|
|
534
|
+
self.z_stn,
|
|
535
|
+
) = read_plot_modules()
|
|
536
|
+
|
|
537
|
+
def plot_grid_elec_3d(self) -> None:
|
|
538
|
+
plot_grid_elec_3d(np.array(self.grid_cortex), np.array(self.ecog_strip))
|
|
539
|
+
|
|
540
|
+
def plot_cortex(
|
|
541
|
+
self,
|
|
542
|
+
grid_cortex: np.ndarray | pd.DataFrame | None = None,
|
|
543
|
+
grid_color: np.ndarray | None = None,
|
|
544
|
+
ecog_strip: np.ndarray | None = None,
|
|
545
|
+
strip_color: np.ndarray | None = None,
|
|
546
|
+
sess_right: bool | None = None,
|
|
547
|
+
save: bool = False,
|
|
548
|
+
OUT_PATH: _PathLike = "",
|
|
549
|
+
feature_file: str = "",
|
|
550
|
+
feature_str_add: str = "",
|
|
551
|
+
show_plot: bool = True,
|
|
552
|
+
title: str = "Cortical grid",
|
|
553
|
+
set_clim: bool = True,
|
|
554
|
+
lower_clim: float = 0.5,
|
|
555
|
+
upper_clim: float = 0.7,
|
|
556
|
+
cbar_label: str = "Balanced Accuracy",
|
|
557
|
+
):
|
|
558
|
+
"""Plot MNI brain including selected MNI cortical projection grid + used strip ECoG electrodes
|
|
559
|
+
Colorcoded by grid_color
|
|
560
|
+
"""
|
|
561
|
+
|
|
562
|
+
if grid_cortex is None:
|
|
563
|
+
if type(self.grid_cortex) is pd.DataFrame:
|
|
564
|
+
grid_cortex = np.array(self.grid_cortex)
|
|
565
|
+
else:
|
|
566
|
+
grid_cortex = self.grid_cortex
|
|
567
|
+
|
|
568
|
+
if ecog_strip is None:
|
|
569
|
+
ecog_strip = self.ecog_strip
|
|
570
|
+
|
|
571
|
+
if sess_right:
|
|
572
|
+
grid_cortex[0, :] = grid_cortex[0, :] * -1 # type: ignore # Handled above
|
|
573
|
+
|
|
574
|
+
fig, axes = plt.subplots(1, 1, facecolor=(1, 1, 1), figsize=(14, 9))
|
|
575
|
+
axes.scatter(self.x_ecog, self.y_ecog, c="gray", s=0.01)
|
|
576
|
+
axes.axes.set_aspect("equal", anchor="C")
|
|
577
|
+
|
|
578
|
+
if grid_cortex is not None:
|
|
579
|
+
grid_color = (
|
|
580
|
+
np.ones(grid_cortex.shape[0]) if grid_color is None else grid_color
|
|
581
|
+
)
|
|
582
|
+
|
|
583
|
+
pos_ecog = axes.scatter(
|
|
584
|
+
grid_cortex[:, 0],
|
|
585
|
+
grid_cortex[:, 1],
|
|
586
|
+
c=grid_color,
|
|
587
|
+
s=150,
|
|
588
|
+
alpha=0.8,
|
|
589
|
+
cmap="viridis",
|
|
590
|
+
label="grid points",
|
|
591
|
+
)
|
|
592
|
+
if set_clim:
|
|
593
|
+
pos_ecog.set_clim(lower_clim, upper_clim)
|
|
594
|
+
if ecog_strip is not None:
|
|
595
|
+
strip_color = (
|
|
596
|
+
np.ones(ecog_strip.shape[0]) if strip_color is None else strip_color
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
pos_ecog = axes.scatter(
|
|
600
|
+
ecog_strip[:, 0],
|
|
601
|
+
ecog_strip[:, 1],
|
|
602
|
+
c=strip_color,
|
|
603
|
+
s=400,
|
|
604
|
+
alpha=0.8,
|
|
605
|
+
cmap="viridis",
|
|
606
|
+
marker="x",
|
|
607
|
+
label="ecog electrode",
|
|
608
|
+
)
|
|
609
|
+
plt.axis("off")
|
|
610
|
+
plt.legend()
|
|
611
|
+
plt.title(title)
|
|
612
|
+
if set_clim:
|
|
613
|
+
pos_ecog.set_clim(lower_clim, upper_clim)
|
|
614
|
+
cbar = fig.colorbar(pos_ecog)
|
|
615
|
+
cbar.set_label(cbar_label)
|
|
616
|
+
|
|
617
|
+
if save:
|
|
618
|
+
plt_path = get_plt_path(
|
|
619
|
+
OUT_PATH,
|
|
620
|
+
feature_file,
|
|
621
|
+
str_plt_type="PLOT_CORTEX",
|
|
622
|
+
feature_name=feature_str_add,
|
|
623
|
+
)
|
|
624
|
+
plt.savefig(plt_path, bbox_inches="tight")
|
|
625
|
+
logger.info(f"Feature epoch average figure saved to: {str(plt_path)}")
|
|
626
|
+
if not show_plot:
|
|
627
|
+
plt.close()
|