Repository navigation
Expand file tree
/
Copy path09_forward.py
More file actions
executable file
·77 lines (62 loc) · 2.1 KB
/
Copy path09_forward.py
File metadata and controls
executable file
·77 lines (62 loc) · 2.1 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Forward modeling
"""
#%% Cell #0
""" First, we need to coregister MRI and MEG. Save the coregistration to the
sample_audvis_raw-trans.fif in the scratch folder.
https://mne.tools/1.7/auto_tutorials/forward/20_source_alignment.html#defining-the-headmri-trans-using-the-gui
"""
import mne
mne.gui.coregistration()
#%% see aligment with MNE Python,
# https://mne.tools/1.7/auto_tutorials/forward/20_source_alignment.html#understanding-coordinate-frames
# Where are the "raw" and "trans"?
fig = mne.viz.plot_alignment(
raw.info,
trans=trans,
subject="sample",
# subjects_dir=subjects_dir,
surfaces="head-dense",
show_axes=True,
dig=True,
eeg=[],
meg="sensors",
coord_frame="meg",
mri_fiducials="estimated",
)
#%% Cell #1
""" Create the source space
"""
src = mne.setup_source_space('sample', spacing='oct6', add_dist='patch')
mne.viz.plot_bem('sample', src=src)
#%% Cell #2
""" View all sources in 3d
"""
fig = mne.viz.plot_alignment(subject='sample',
surfaces='white',
coord_frame='mri',
src=src)
mne.viz.set_3d_view(fig, azimuth=173.78, elevation=101.75,
distance=0.30, focalpoint=(-0.03, -0.01, 0.03))
#%% Cell #3
""" BEM-related computations
"""
CONDUCTIVITY = (0.3,) # for a single layer, for three layers use
# (0.3, 0.006, 0.3)
model = mne.make_bem_model(subject='sample', ico=4, conductivity=CONDUCTIVITY)
bem = mne.make_bem_solution(model)
#%% Cell #4
""" Compute the forward solution ...
"""
TRANS_FNAME = mne.get_config('SCRATCH_DIR') + '/sample_audvis_raw-trans.fif'
RAW_FNAME = mne.get_config('DATA_DIR') + '/MEG/sample_audvis_raw.fif'
fwd = mne.make_forward_solution(RAW_FNAME, trans=TRANS_FNAME, src=src, bem=bem,
meg=True, eeg=False, mindist=5.0, n_jobs=1,
verbose=True)
#%% Cell #5
""" ... and write it to the disk
"""
FNAME = mne.get_config('SCRATCH_DIR') + '/sample_audvis_raw-fwd.fif'
mne.write_forward_solution(FNAME, fwd)