-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFPVS_InverseOperator.py
executable file
·94 lines (59 loc) · 2.79 KB
/
FPVS_InverseOperator.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
#!/imaging/local/software/miniconda/envs/mne0.20/bin/python
"""
=========================================================
Make inverse operator for FPVS.
=========================================================
"""
import sys
from os import path as op
import numpy as np
from importlib import reload
import mne
import config_sweep as config
reload(config)
subjects_dir = config.subjects_dir
def run_make_inverse_operator(sbj_id):
subject = config.mri_subjects[sbj_id]
if subject == '':
print('No subject name for MRI specified - doing nothing now.')
return
print('Making Inverse Operator for %s.' % subject)
sbj_path = op.join(config.data_path, config.map_subjects[sbj_id][0])
# doesn't matter which raw file, as long as transed
raw_stem = config.sss_map_fnames[sbj_id][1][0]
raw_fname = op.join(sbj_path, raw_stem[:-4] + '_f_' +
config.raw_ICA_suff + '.fif')
info = mne.io.read_info(raw_fname)
fwd_fname = op.join(sbj_path, subject + '_MEG-fwd.fif')
print('Reading MEG forward solution: %s.' % fwd_fname)
fwd_meg = mne.read_forward_solution(fwd_fname)
fwd_fname = op.join(sbj_path, subject + '_EEGMEG-fwd.fif')
print('Reading EEG/MEG forward solution: %s.' % fwd_fname)
fwd_eegmeg = mne.read_forward_solution(fwd_fname)
fname_cov = op.join(sbj_path, 'rest_sss_f_raw-cov.fif')
print('Reading covariance matrix: %s.' % fname_cov)
noise_cov = mne.cov.read_cov(fname=fname_cov)
# make inverse operator
loose = 0.2
depth = None
invop_meg = mne.minimum_norm.make_inverse_operator(info, fwd_meg, noise_cov,
fixed='auto', loose=loose, depth=depth,
rank='info')
invop_eegmeg = mne.minimum_norm.make_inverse_operator(info, fwd_eegmeg, noise_cov,
fixed='auto', loose=loose, depth=depth,
rank='info')
inv_fname = op.join(sbj_path, subject + '_MEG-inv.fif')
print('Writing MEG inverse operator: %s.' % inv_fname)
mne.minimum_norm.write_inverse_operator(fname=inv_fname, inv=invop_meg)
inv_fname = op.join(sbj_path, subject + '_EEGMEG-inv.fif')
print('Writing EEG/MEG inverse operator: %s.' % inv_fname)
mne.minimum_norm.write_inverse_operator(fname=inv_fname, inv=invop_eegmeg)
# get all input arguments except first
if len(sys.argv) == 1:
sbj_ids = np.arange(0, len(config.map_subjects)) + 1
else:
# get list of subjects IDs to process
sbj_ids = [int(aa) for aa in sys.argv[1:]]
for ss in sbj_ids:
run_make_inverse_operator(ss)
print('Done.')