forked from brainthemind/CogBrainDyn_MEG_Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-make_forward.py
54 lines (39 loc) · 1.71 KB
/
11-make_forward.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
"""
====================
12. Forward solution
====================
Calculate forward solution for MEG channels.
"""
import os.path as op
import mne
from mne.parallel import parallel_func
import config
def run_forward(subject):
print("Processing subject: %s" % subject)
meg_subject_dir = op.join(config.meg_dir, subject)
extension = '-ave'
fname_evoked = op.join(meg_subject_dir,
config.base_fname.format(**locals()))
print("Input: ", fname_evoked)
extension = '_%s-fwd' % (config.spacing)
fname_fwd = op.join(meg_subject_dir,
config.base_fname.format(**locals()))
print("Output: ", fname_fwd)
fname_trans = op.join(meg_subject_dir,
config.base_fname_trans.format(**locals()))
src = mne.setup_source_space(subject, spacing=config.spacing,
subjects_dir=config.subjects_dir,
add_dist=False)
evoked = mne.read_evokeds(fname_evoked, condition=0)
# Here we only use 3-layers BEM only if EEG is available.
if 'eeg' in config.ch_types:
fname_bem = op.join(config.subjects_dir, subject, 'bem',
'%s-5120-5120-5120-bem-sol.fif' % subject)
else:
fname_bem = op.join(config.subjects_dir, subject, 'bem',
'%s-5120-bem-sol.fif' % subject)
fwd = mne.make_forward_solution(evoked.info, fname_trans, src, fname_bem,
mindist=config.mindist)
mne.write_forward_solution(fname_fwd, fwd, overwrite=True)
parallel, run_func, _ = parallel_func(run_forward, n_jobs=config.N_JOBS)
parallel(run_func(subject) for subject in config.subjects_list)