-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPVS_Maxfilter_sweep.py
executable file
·131 lines (97 loc) · 3.68 KB
/
FPVS_Maxfilter_sweep.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
#!/imaging/local/software/miniconda/envs/mne0.20/bin/python
"""
Maxfilter data from FPVS with Frequency Sweep.
=============================================
OH, modified October 2019
"""
import sys
import os
from os import path as op
import numpy as np
from importlib import reload
import config_sweep as config
reload(config)
MF = config.MF # Maxfilter parameters
def run_maxfilter(sbj_id):
"""Run maxfilter for one subject."""
# path to raw data for maxfilter
map_subject = config.map_subjects[sbj_id]
# raw-filename mappings for this subject
sss_map_fname = config.sss_map_fnames[sbj_id]
raw_path = op.join(config.cbu_path, map_subject[0], map_subject[1])
# use sixth filename for trans
raw_fname_ref = op.join(raw_path,
sss_map_fname[0][config.MF['trans']] + '.fif')
# maxfilter option for bad channels
if config.bad_channels[sbj_id]['meg'] != []:
# bad MEG channels without 'MEG'
bad_channels = config.bad_channels[sbj_id]['meg']
bads = [chn[3:] for chn in bad_channels]
bad_cmd = '-bad %s' % ' '.join(bads)
else:
bad_cmd = ''
for (raw_fname_in, raw_fname_out) in zip(sss_map_fname[0],
sss_map_fname[1]):
fname_in = op.join(config.cbu_path, map_subject[0], map_subject[1],
raw_fname_in + '.fif')
fname_out = op.join(config.data_path, map_subject[0],
raw_fname_out + '.fif')
log_fname_out = op.join(config.data_path, map_subject[0],
raw_fname_out + '_sss.log') # log-file
if op.exists(fname_out): # if necessary delete existing MF output file
os.remove(fname_out)
# replace period to avoid confusion with file names
if MF['st_duration'] is None:
st_cmd = ''
else:
st_cmd = ' -st %s -corr %f' % (str(int(MF['st_duration'])),
MF['st_correlation'])
origin = MF['origin']
ori_cmd = ' -origin %.0f %.0f %.0f ' % (1000 * origin[0], 1000 *
origin[1], 1000 * origin[2])
order_cmd = '-in %d -out %d' % (MF['in'], MF['out'])
if not(MF['mv'] == ''):
mv_cmd = '-movecomp %s' % MF['mv']
mf_cmd = ' %s \
-f %s \
-o %s \
-trans %s \
-cal %s \
-ctc %s \
-frame %s \
-regularize %s \
%s \
%s \
%s \
%s \
%s \
-autobad on \
-force \
-linefreq 50 \
-v \
| tee %s' \
% (MF['NM_cmd'],
fname_in,
fname_out,
raw_fname_ref,
MF['cal'],
MF['ctc'],
MF['frame'],
MF['regularize'],
st_cmd,
ori_cmd,
order_cmd,
mv_cmd,
bad_cmd,
log_fname_out)
print('Maxfilter command: %s' % mf_cmd)
# Execute maxfilter command
# os.system(mf_cmd)
# 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_maxfilter(ss)