forked from mne-tools/mne-bids-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 11
/
05b-run_ssp.py
51 lines (37 loc) · 1.4 KB
/
05b-run_ssp.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
"""
===========
05. Run SSP
===========
Compute Signal Suspace Projections (SSP).
"""
import os.path as op
import mne
from mne.parallel import parallel_func
import config
from mne.preprocessing import compute_proj_ecg, compute_proj_eog
def run_ssp(subject):
print("Processing subject: %s" % subject)
meg_subject_dir = op.join(config.meg_dir, subject)
print(" Loading one run to compute SSPs")
# compute SSP on first run of raw
run = config.runs[0]
extension = run + '_filt_raw'
raw_fname_in = op.join(meg_subject_dir,
config.base_fname.format(**locals()))
extension = run + '_ssp-proj'
proj_fname_out = op.join(meg_subject_dir,
config.base_fname.format(**locals()))
print("Input: ", raw_fname_in)
print("Output: ", proj_fname_out)
raw = mne.io.read_raw_fif(raw_fname_in)
# XXX : n_xxx should be options in config
print(" Computing SSPs for ECG")
ecg_projs, ecg_events = \
compute_proj_ecg(raw, n_grad=1, n_mag=1, n_eeg=0, average=True)
print(" Computing SSPs for EOG")
eog_projs, eog_events = \
compute_proj_eog(raw, n_grad=1, n_mag=1, n_eeg=1, average=True)
mne.write_proj(proj_fname_out, eog_projs + ecg_projs)
if config.use_ssp:
parallel, run_func, _ = parallel_func(run_ssp, n_jobs=config.N_JOBS)
parallel(run_func(subject) for subject in config.subjects_list)