-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFPVSWORDS_MorphSTC.py
executable file
·271 lines (231 loc) · 8.89 KB
/
FPVSWORDS_MorphSTC.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
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
171
172
173
174
175
176
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/imaging/local/software/mne_python/mne1.4.0_1/bin/python
"""
Morph individual STCs for FPVS.
==========================================
OH, April 2020
"""
import sys
from os import remove
from os import path as op
import numpy as np
from importlib import reload
import mne
import FPVS_functions as Ff
reload(Ff)
import config_fpvswords as config
reload(config)
print(mne.__version__)
# for some plots of SNRs
unit_scalings = dict(eeg=1.0, mag=1.0, grad=1.0)
subjects_dir = config.subjects_dir
conds = config.do_conds
def morph_stcs(sbj_ids):
"""Morph STCs for sbj_ids."""
print("Morphing STCs for subjects:")
print(*sbj_ids)
# for Evoked data are in one file for all frequencies
# for STC data are in separate files per condition and freq
for sbj_id in sbj_ids: # across all subjects, EDIT ###
# path to subject's data
sbj_path = op.join(config.data_path, config.map_subjects[sbj_id][0])
subject = config.mri_subjects[sbj_id]
if subject == "":
print("No subject name for MRI specified - doing nothing now.")
return
# create morphing matrix
tmp = [i for i in config.event_ids[conds[0]].keys()][0]
fname_stc = op.join(
sbj_path,
"STC",
"PSDSumTopoOdd_%s_%s" % (conds[0], tmp),
)
print(tmp, fname_stc)
stc_from = mne.read_source_estimate(fname_stc)
print("Computing morphing matrix for %s." % subject)
morph_mat = mne.compute_source_morph(
src=stc_from,
subject_from=subject,
subject_to=config.stc_morph,
subjects_dir=subjects_dir,
)
for cond in conds: # conditions
print("###\nCondition: %s.\n###" % cond)
if cond[:4] == "rest":
task = "rest"
else:
task = cond
for ev_type in config.event_ids[cond]:
print("Reading PSD results from STC files:")
fname_stc = op.join(
sbj_path,
"STC",
"PSDSumTopoOdd_%s_%s" % (cond, ev_type),
)
print(fname_stc)
stc = mne.read_source_estimate(fname_stc)
stc_mph = morph_mat.apply(stc)
fname_mph = op.join(
sbj_path,
"STC",
"PSDSumTopoOdd_%s_%s_mph" % (cond, ev_type),
)
print('Saving to %s.' % fname_mph)
stc_mph.save(fname_mph, overwrite=True)
fname_stc = op.join(
sbj_path,
"STC",
"PSDSumTopoBase_%s_%s" % (cond, ev_type),
)
print(fname_stc)
stc = mne.read_source_estimate(fname_stc)
stc_mph = morph_mat.apply(stc)
fname_mph = op.join(
sbj_path,
"STC",
"PSDSumTopoBase_%s_%s_mph" % (cond, ev_type),
)
stc_mph.save(fname_mph, overwrite=True)
fname_stc = op.join(
sbj_path,
"STC",
"PSDZSumTopoOdd_%s_%s" % (cond, ev_type),
)
print(fname_stc)
stc = mne.read_source_estimate(fname_stc)
stc_mph = morph_mat.apply(stc)
fname_mph = op.join(
sbj_path,
"STC",
"PSDZSumTopoOdd_%s_%s_mph" % (cond, ev_type),
)
print('Saving to %s.' % fname_mph)
stc_mph.save(fname_mph, overwrite=True)
fname_stc = op.join(
sbj_path,
"STC",
"PSDZSumTopoBase_%s_%s" % (cond, ev_type),
)
print(fname_stc)
stc = mne.read_source_estimate(fname_stc)
stc_mph = morph_mat.apply(stc)
fname_mph = op.join(
sbj_path,
"STC",
"PSDZSumTopoBase_%s_%s_mph" % (cond, ev_type),
)
stc_mph.save(fname_mph, overwrite=True)
#
# fname_stc = op.join(
# sbj_path, 'STC', '%sPSDTopoZ_%s_%s-lh.stc' %
# (prefix, cond, freq)
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path, 'STC', '%sPSDTopoZ_%s_%s_mph-lh.stc' %
# (prefix, cond, freq)
# )
# stc_mph.save(fname_mph)
#
# fname_stc = op.join(
# sbj_path,
# "STC",
# "%sPSDHarm_%s_%s-lh.stc" % (prefix, cond, freq),
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path,
# "STC",
# "%sPSDHarm_%s_%s_mph-lh.stc" % (prefix, cond, freq),
# )
# stc_mph.save(fname_mph)
# #
# fname_stc = op.join(
# sbj_path,
# "STC",
# "%sPSDHarmBase_%s_%s-lh.stc" % (prefix, cond, freq),
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path,
# "STC",
# "%sPSDHarmBase_%s_%s_mph-lh.stc" % (prefix, cond, freq),
# )
# stc_mph.save(fname_mph)
# #
# fname_stc = op.join(
# sbj_path,
# "STC",
# "%sPSDSumTopoOdd_%s_%s-lh.stc" % (prefix, cond, freq),
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path,
# "STC",
# "%sPSDSumTopoOdd_%s_%s_mph-lh.stc" % (prefix, cond, freq),
# )
# stc_mph.save(fname_mph)
# #
# fname_stc = op.join(
# sbj_path,
# "STC",
# "%sPSDSumTopoBase_%s_%s-lh.stc" % (prefix, cond, freq),
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path,
# "STC",
# "%sPSDSumTopoBase_%s_%s_mph-lh.stc" % (prefix, cond, freq),
# )
# stc_mph.save(fname_mph)
# #
# fname_stc = op.join(
# sbj_path,
# "STC",
# "%sPSDSumToposOdd_%s_%s-lh.stc" % (prefix, cond, freq),
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path,
# "STC",
# "%sPSDSumToposOdd_%s_%s_mph-lh.stc" % (prefix, cond, freq),
# )
# stc_mph.save(fname_mph)
# #
# fname_stc = op.join(
# sbj_path,
# "STC",
# "%sPSDSumToposBase_%s_%s-lh.stc" % (prefix, cond, freq),
# )
# print(fname_stc)
# stc = mne.read_source_estimate(fname_stc)
# stc_mph = morph_mat.apply(stc)
# fname_mph = op.join(
# sbj_path,
# "STC",
# "%sPSDSumToposBase_%s_%s_mph-lh.stc" % (prefix, cond, freq),
# )
# stc_mph.save(fname_mph)
return
# get all input arguments except first
if (len(sys.argv) == 1) or (
int(sys.argv[1]) > np.max(list(config.map_subjects.keys()))
):
# IDs don't start at 0
sbj_ids = config.do_subjs
else:
# get list of subjects IDs to process
sbj_ids = [int(aa) for aa in sys.argv[1:]]
# requires all subjects to average across
morph_stcs(sbj_ids)