-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoh_view_data.py
133 lines (110 loc) · 3.42 KB
/
coh_view_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""Plots data for annotating.
METHODS
-------
inspect_data
- Plots power spectra of signals.
annotate_data
- Plots non-epoched signals for annotating.
"""
from os.path import exists
from coh_handle_files import (
generate_analysiswise_fpath,
generate_sessionwise_fpath,
load_file,
)
from coh_signal_viewer import SignalViewer
import coh_signal
def inspect_data(
signal: coh_signal.Signal,
folderpath_preprocessing: str,
analysis: str,
) -> None:
"""Plots power spectra of signals.
PARAMETERS
----------
signal : coh_signal.Signal
- The pre-processed data to plot.
folderpath_preprocessing : str
- The folderpath to the location of the preprocessing folder.
analysis : str
- The name of the analysis folder within "'folderpath_extras'/settings".
"""
### Analysis setup
## Gets the relevant filepaths
analysis_settings = load_file(
fpath=generate_analysiswise_fpath(
f"{folderpath_preprocessing}\\Settings\\Generic", analysis, ".json"
)
)["power"]
### Data plotting
## Plots the power spectra
signal_viewer = SignalViewer(signal=signal)
signal_viewer.plot_power(
mode=analysis_settings["mode"],
fmin=analysis_settings["fmin"],
fmax=analysis_settings["fmax"],
mode_kwargs=analysis_settings["mode_kwargs"],
pick_types=analysis_settings["pick_types"],
include_bads=analysis_settings["include_bads"],
n_jobs=analysis_settings["n_jobs"],
)
def annotate_data(
signal: coh_signal.Signal,
folderpath_preprocessing: str,
dataset: str,
subject: str,
session: str,
task: str,
acquisition: str,
run: str,
load_annotations: bool = True,
) -> None:
"""Plots non-epoched signals for annotating.
PARAMETERS
----------
signal : coh_signal.Signal
- The pre-processed data to plot.
folderpath_preprocessing : str
- The folderpath to the location of the preprocessing folder.
dataset : str
- The name of the dataset folder found in 'folderpath_data'.
subject : str
- The name of the subject whose data will be plotted.
session : str
- The name of the session for which the data will be plotted.
task : str
- The name of the task for which the data will be plotted.
acquisition : str
- The name of the acquisition mode for which the data will be plotted.
run : str
- The name of the run for which the data will be plotted.
load_annotations : bool; default True
- Whether or not to load pre-existing annotations, if present, when
viewing the signals.
"""
### Analysis setup
## Gets the relevant filepaths
annotations_fpath = generate_sessionwise_fpath(
f"{folderpath_preprocessing}\\Settings\\Specific",
dataset,
subject,
session,
task,
acquisition,
run,
"annotations",
".csv",
)
### Data plotting
## Plots the data for annotating
signal_viewer = SignalViewer(signal=signal)
if load_annotations:
if exists(annotations_fpath):
signal_viewer.load_annotations(fpath=annotations_fpath)
else:
print(
"No pre-existing annotations to load from the filepath:\n"
f"{annotations_fpath}"
)
signal_viewer.plot_raw()
signal_viewer.save_annotations(fpath=annotations_fpath)