-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxfilter_data.py
70 lines (62 loc) · 2.61 KB
/
maxfilter_data.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 26 12:23:40 2017
Little maxfilter routine using default parameters except st_correlation 90
rather than 98 and st_duration because those are the parameters Chris used.
I hope these correspond - looked at flash with Elekta vs this and it seemed
pretty much the same.
@author: alex
"""
# preparing everything:
import os.path as op
import mne
from os import makedirs
import re
mne.set_log_level('WARNING')
#
# 1421 1431 are the worst affected MAGs of slow artefact.
# Can this be harnessed? ICA?
subject = '0001'
recdate = '20170801' #'20171215' '20180302'
# where are the data?
proj_path = '/projects/MINDLAB2016_MEG-ERG-flash/'
output_path = op.join(proj_path, 'scratch', 'maxfilter', subject, recdate)
if not op.exists(output_path):
makedirs(output_path)
data_path = op.join(proj_path, 'raw',
subject, recdate +
# 20180302:
# '_000000/MEG/001.audioOnly/files/')
# '_000000/MEG/003.audioVisual/files/')
# '_000000/MEG/005.flash_longerISI/files/')
# bads = ['MEG1143', 'MEG0121', 'MEG0441']
# 20171215:
# ' _000000/MEG/003.eyes_open_rest/files/')
# ' _000000/MEG/002.eyes_closed_rest/files/')
# '_000000/MEG/001.empty_room_2min/files/')
'_000000/MEG/004.flash_open/files/')
#bads = ['MEG0121', 'MEG1143', 'MEG0712'] # noisy, flat, spiky, respectively
bads = ['MEG0121', 'MEG1143', 'MEG1423', 'MEG1433'] #excluded by ELEKTA
task_name = re.search('(?<=MEG/00\d\.)\w+', data_path).group(0)
print task_name
raw_fname = data_path + task_name + '.fif'
raw = mne.io.read_raw_fif(raw_fname)
if bads is not None:
raw.info['bads'] = bads
print 'Done with preliminaries.'
# %% try maxwell filter
win = 30
corr = 0.90
raw = mne.preprocessing.maxwell_filter(raw, origin='auto', int_order=8,
ext_order=3, calibration=None,
cross_talk=None, st_duration=win,
st_correlation=corr,
coord_frame='head', destination=None,
regularize='in', ignore_ref=False,
bad_condition='error', head_pos=None,
st_fixed=True, st_only=False,
mag_scale=100.0)
maxfilt_fname = output_path + '/' + task_name + '-MNE_tsss_win' + str(win) \
+ '_corr' + str(int(corr * 100)) + '.fif'
raw.save(maxfilt_fname, overwrite=True)