FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mne-python/examples/datasets/spm_faces_dataset.py at main · mne-tools/mne-python · GitHub
mne-tools
mne-python
Repository navigation
Code
Issues
503
(503)
Pull requests
112
(112)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
mne-python
/
examples
/
datasets
/
spm_faces_dataset.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (87 loc) · 3.2 KB
Breadcrumbs
mne-python
/
examples
/
datasets
/
spm_faces_dataset.py
Copy path
File metadata and controls
102 lines (87 loc) · 3.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
.. _ex-spm-faces:
==========================================
From raw data to dSPM on SPM Faces dataset
==========================================
Runs a full pipeline using MNE-Python. This example does quite a bit of processing, so
even on a fast machine it can take several minutes to complete.
"""
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
# Denis Engemann <denis.engemann@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import
mne
from
mne
import
combine_evoked
,
io
from
mne
.
datasets
import
spm_face
from
mne
.
minimum_norm
import
apply_inverse
,
make_inverse_operator
from
mne
.
preprocessing
import
ICA
,
create_eog_epochs
print
(
__doc__
)
data_path
=
spm_face
.
data_path
()
subjects_dir
=
data_path
/
"subjects"
spm_path
=
data_path
/
"MEG"
/
"spm"
# %%
# Load data, filter it, and fit ICA.
raw_fname
=
spm_path
/
"SPM_CTF_MEG_example_faces1_3D.ds"
raw
=
io
.
read_raw_ctf
(
raw_fname
,
preload
=
True
)
# Take first run
# Here to save memory and time we'll downsample heavily -- this is not
# advised for real data as it can effectively jitter events!
raw
.
resample
(
100
)
raw
.
filter
(
1.0
,
None
)
# high-pass
reject
=
dict
(
mag
=
5e-12
)
ica
=
ICA
(
n_components
=
0.95
,
max_iter
=
"auto"
,
rng
=
97
)
ica
.
fit
(
raw
,
reject
=
reject
)
# compute correlation scores, get bad indices sorted by score
eog_epochs
=
create_eog_epochs
(
raw
,
ch_name
=
"MRT31-2908"
,
reject
=
reject
)
eog_inds
,
eog_scores
=
ica
.
find_bads_eog
(
eog_epochs
,
ch_name
=
"MRT31-2908"
)
ica
.
plot_scores
(
eog_scores
,
eog_inds
)
# see scores the selection is based on
ica
.
plot_components
(
eog_inds
)
# view topographic sensitivity of components
ica
.
exclude
+=
eog_inds
[:
1
]
# we saw the 2nd ECG component looked too dipolar
ica
.
plot_overlay
(
eog_epochs
.
average
())
# inspect artifact removal
# %%
# Epoch data and apply ICA.
events
=
mne
.
find_events
(
raw
,
stim_channel
=
"UPPT001"
)
event_ids
=
{
"faces"
:
1
,
"scrambled"
:
2
}
tmin
,
tmax
=
-
0.2
,
0.6
epochs
=
mne
.
Epochs
(
raw
,
events
,
event_ids
,
tmin
,
tmax
,
picks
=
"meg"
,
baseline
=
None
,
preload
=
True
,
reject
=
reject
,
)
del
raw
ica
.
apply
(
epochs
)
# clean data, default in place
evoked
=
[
epochs
[
k
].
average
()
for
k
in
event_ids
]
contrast
=
combine_evoked
(
evoked
,
weights
=
[
-
1
,
1
])
# Faces - scrambled
evoked
.
append
(
contrast
)
for
e
in
evoked
:
e
.
plot
(
ylim
=
dict
(
mag
=
[
-
400
,
400
]))
# %%
# Estimate noise covariance and look at the whitened evoked data
noise_cov
=
mne
.
compute_covariance
(
epochs
,
tmax
=
0
,
method
=
"shrunk"
,
rank
=
None
)
evoked
[
0
].
plot_white
(
noise_cov
)
# %%
# Compute forward model
trans_fname
=
spm_path
/
"SPM_CTF_MEG_example_faces1_3D_raw-trans.fif"
src
=
subjects_dir
/
"spm"
/
"bem"
/
"spm-oct-6-src.fif"
bem
=
subjects_dir
/
"spm"
/
"bem"
/
"spm-5120-5120-5120-bem-sol.fif"
forward
=
mne
.
make_forward_solution
(
contrast
.
info
,
trans_fname
,
src
,
bem
)
# %%
# Compute inverse solution and plot
# sphinx_gallery_thumbnail_number = 8
snr
=
3.0
lambda2
=
1.0
/
snr
**
2
inverse_operator
=
make_inverse_operator
(
contrast
.
info
,
forward
,
noise_cov
)
stc
=
apply_inverse
(
contrast
,
inverse_operator
,
lambda2
,
method
=
"dSPM"
,
pick_ori
=
None
)
brain
=
stc
.
plot
(
hemi
=
"both"
,
subjects_dir
=
subjects_dir
,
initial_time
=
0.170
,
views
=
[
"ven"
],
clim
=
{
"kind"
:
"value"
,
"lims"
: [
3.0
,
6.0
,
9.0
]},
)
Back
|
FazBrowse Home
|
New Git URL