In [1]:
import sys
print(sys.version_info)
del sys
sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0)

導体モデルと分散行列作成

In [2]:
import mne
from mne.datasets import sample
mne.set_log_level('INFO')
data_path=sample.data_path()

raw_fname=data_path+'\\MEG\\sample\\sample_audvis_raw.fif'
subjects_dir=data_path+'\\subjects'
subject='sample'

頭座標と脳磁図座標の座標合わせを行った-trans.fifが必要になります。これはMNEのmne_analyzeを実行して取得します。
また境界要素モデル(BEM)が必要になります。FreeSurferで以下の2つのcommandを実行します
mne watershed_bem
mne flash_bem

各境界の二次元表示

In [3]:
mne.viz.plot_bem(subject=subject,subjects_dir=subjects_dir,brain_surfaces='white',orientation='coronal');
Using surface: C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\inner_skull.surf
Using surface: C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\outer_skull.surf
Using surface: C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\outer_skin.surf

頭とセンサの三次元表示

In [4]:
trans=data_path+'\\MEG\\sample\\sample_audvis_raw-trans.fif'
info=mne.io.read_info(raw_fname)
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
In [5]:
# jupyterでは実行できず
mne.viz.plot_trans(info,trans,subject=subject,dig=True,meg_sensors=True,subjects_dir=subjects_dir)
Using surface from C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\sample-5120-5120-5120-bem.fif.
Getting helmet for system 306m
Out[5]:
<mayavi.core.scene.Scene at 0x1638a8e0>

Windowは開くのですが、何も出てきません。

%matplotlib inline→ダメ

from mayavi import mlab
%gui qt→ダメ

from mayavi import mlab
mlab.init_notebook()→ダメ
jupyter上で動かすのはあきらめました。
python console上で実行すると以下のような絵が出てきます。

格子点の設定

In [6]:
src=mne.setup_source_space(subject,spacing='oct6',subjects_dir=subjects_dir,add_dist=False,overwrite=True)
print(src[0]) # 左半球
print(src[1]) # 右半球
Setting up the source space with the following parameters:

SUBJECTS_DIR = C:\Users\akira\mne_data\MNE-sample-data\subjects
Subject      = sample
Surface      = white
Octahedron subdivision grade 6

Parameters 'fname' and 'overwrite' are deprecated and will be removed in version 0.16. In version 0.15 fname will default to None. Use mne.write_source_spaces instead.
Overwriting existing file.
>>> 1. Creating the source space...

Doing the octahedral vertex picking...
Loading C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\surf\lh.white...
Mapping lh sample -> oct (6) ...
    Triangle neighbors and vertex normals...
<ipython-input-6-ccb054a4d5fb>:1: RuntimeWarning: Parameters 'fname' and 'overwrite' are deprecated and will be removed in version 0.16. In version 0.15 fname will default to None. Use mne.write_source_spaces instead.
  src=mne.setup_source_space(subject,spacing='oct6',subjects_dir=subjects_dir,add_dist=False,overwrite=True)
Loading geometry from C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\surf\lh.sphere...
    Triangle neighbors and vertex normals...
Setting up the triangulation for the decimated surface...
loaded lh.white 4098/155407 selected to source space (oct = 6)

Loading C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\surf\rh.white...
Mapping rh sample -> oct (6) ...
    Triangle neighbors and vertex normals...
Loading geometry from C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\surf\rh.sphere...
    Triangle neighbors and vertex normals...
Setting up the triangulation for the decimated surface...
loaded rh.white 4098/156866 selected to source space (oct = 6)

Overwriting existing file.
    Write a source space...
    [done]
    Write a source space...
    [done]
    2 source spaces written
Wrote C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\sample-oct-6-src.fif
You are now one step closer to computing the gain matrix
{'nearest_dist': None, 'dist': None, 'use_tris': array([[150508, 151338, 150461],
       [151338, 150854, 151675],
       [150461, 151338, 151675],
       ..., 
       [ 16806,  17942,  15465],
       [ 12077,  16806,  15465],
       [ 12077,  15465,  10857]]), 'nearest': None, 'nuse': 4098, 'dist_limit': None, 'pinfo': None, 'nuse_tri': 8192, 'tris': array([[     0,      1,      3],
       [     4,      3,      1],
       [     0,     61,     62],
       ..., 
       [153723, 153732, 153919],
       [153900, 153907, 153901],
       [154073, 154322, 154245]]), 'patch_inds': None, 'nn': array([[-0.01874355, -0.95650626,  0.291109  ],
       [-0.39538466, -0.91271418,  0.10307183],
       [-0.42436735, -0.90215294, -0.07766874],
       ..., 
       [ 0.32397546,  0.32694985,  0.88777458],
       [ 0.53388722,  0.56742684,  0.62689012],
       [-0.85292747,  0.3917218 , -0.34506343]]), 'rr': array([[-0.02095193, -0.08627678,  0.01324033],
       [-0.02110974, -0.08622514,  0.01331493],
       [-0.02139933, -0.08605659,  0.01338905],
       ..., 
       [-0.01231463,  0.0725397 ,  0.05550697],
       [-0.01401764,  0.07201006,  0.0569932 ],
       [-0.01484421,  0.0722774 ,  0.05620262]]), 'inuse': array([0, 0, 0, ..., 0, 0, 0]), 'vertno': array([    14,     54,     59, ..., 155295, 155323, 155330], dtype=int64), 'id': 101, 'coord_frame': array([5]), 'subject_his_id': 'sample', 'np': 155407, 'type': 'surf', 'ntri': 310810}
{'nearest_dist': None, 'dist': None, 'use_tris': array([[151685, 152951, 152173],
       [152951, 152041, 151684],
       [152173, 152951, 151684],
       ..., 
       [ 11739,  16625,  13944],
       [ 15309,  11739,  13944],
       [ 15309,  13944,  11658]]), 'nearest': None, 'nuse': 4098, 'dist_limit': None, 'pinfo': None, 'nuse_tri': 8192, 'tris': array([[     0,      1,      5],
       [     6,      5,      1],
       [     0,     89,      1],
       ..., 
       [155499, 155850, 155706],
       [155294, 155505, 155293],
       [155505, 155292, 155293]]), 'patch_inds': None, 'nn': array([[ 0.20626849, -0.93710853,  0.28156865],
       [ 0.02692161, -0.96664675,  0.25469449],
       [-0.07228359, -0.98700267,  0.14352985],
       ..., 
       [ 0.21276483,  0.95748461, -0.19481876],
       [ 0.22123635,  0.47268354, -0.85300923],
       [ 0.338483  ,  0.85620799, -0.3903039 ]]), 'rr': array([[ 0.01782518, -0.08578899,  0.00835241],
       [ 0.01745624, -0.08581509,  0.00832477],
       [ 0.01662625, -0.08585951,  0.00786901],
       ..., 
       [ 0.02126309,  0.07187699,  0.05374235],
       [ 0.02258363,  0.07139014,  0.05383597],
       [ 0.02202678,  0.07162484,  0.05389726]]), 'inuse': array([0, 0, 0, ..., 0, 0, 0]), 'vertno': array([    30,     98,    180, ..., 156775, 156791, 156838], dtype=int64), 'id': 102, 'coord_frame': array([5]), 'subject_his_id': 'sample', 'np': 156866, 'type': 'surf', 'ntri': 313728}
In [7]:
mne.viz.plot_bem(subject=subject,subjects_dir=subjects_dir,brain_surfaces='white',src=src,orientation='coronal');
Using surface: C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\inner_skull.surf
Using surface: C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\outer_skull.surf
Using surface: C:\Users\akira\mne_data\MNE-sample-data\subjects\sample\bem\outer_skin.surf

緑の皮質の・・が格子点です。

In [8]: