-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPVS_MorphSTC.py
executable file
·218 lines (176 loc) · 7.51 KB
/
FPVS_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
#!/imaging/local/software/miniconda/envs/mne0.20/bin/python
"""
Morph individual STCs for FPVS.
==========================================
OH, April 2020
"""
import sys
from os import path as op
import numpy as np
from importlib import reload
import mne
import FPVS_functions
reload(FPVS_functions)
import config_sweep as config
reload(config)
print(mne.__version__)
# for some plots of SNRs
unit_scalings = dict(eeg=1., mag=1., grad=1.)
# Base frequencies for frequency sweep for words (not faces)
freqs_all = [str(ff) for ff in config.fpvs_freqs]
# separate filename prefixes for ICAed and non-ICAed data
prefix = ''
if 'ica' in config.raw_ICA_suff:
prefix = 'ICA'
subjects_dir = config.subjects_dir
# conditions
# conds = ['face', 'pwhf', 'pwlf', 'lfhf']
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
# getting an STC for source space for this subject
fname_stc = op.join(
sbj_path, 'STC', '%sPSDTopo_%s_%s-lh.stc' % (prefix, 'face',
'6.0')
)
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('Condition: %s.' % cond)
if cond == 'face': # no frequency sweep for faces
freqs = ['6.0'] # base frequency for this condition (Hz, str)
else: # for all word condition, use all sweep frequencies
# base frequencies for this condition (Hz as string)
freqs = freqs_all
for (fi, freq) in enumerate(freqs):
print('Reading PSD results from STC files:')
fname_stc = op.join(
sbj_path, 'STC', '%sPSDTopo_%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', '%sPSDTopo_%s_%s_mph-lh.stc' %
(prefix, cond, freq)
)
stc_mph.save(fname_mph)
#
# 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)