非官方中文翻译 本页译自 MNE-Python 官方文档: 查看英文原文 ↗。 文档版权归 MNE Developers 所有(BSD-3-Clause)。

使用模板 MRI 计算 EEG 前向算子#

本教程说明如何使用标准模板 MRI 被试 fsaverage 从 EEG 数据计算前向算子。

警告

在没有被试个体 T1 MRI 的情况下进行源重建,精度会降低。请不要过度解读活动位置,其偏差可能达到数厘米。

成人模板 MRI(fsaverage)#

首先,我们演示如何将 fsaverage 用作替代被试。

# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
#          Joan Massich <mailsik@gmail.com>
#          Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

import numpy as np

import mne
from mne.datasets import eegbci, fetch_fsaverage

# Download fsaverage files
fs_dir = fetch_fsaverage(verbose=True)
subjects_dir = fs_dir.parent

# The files live in:
subject = "fsaverage"
trans = "fsaverage"  # MNE has a built-in fsaverage transformation
src = fs_dir / "bem" / "fsaverage-ico-5-src.fif"
bem = fs_dir / "bem" / "fsaverage-5120-5120-5120-bem-sol.fif"
0 files missing from root.txt in /home/circleci/mne_data/MNE-fsaverage-data
0 files missing from bem.txt in /home/circleci/mne_data/MNE-fsaverage-data/fsaverage

加载数据#

这里我们使用来自 BCI 数据集的 EEG 数据。

提示

参见“Plotting sensor layouts of EEG systems”页面,查看 MNE-Python 中所有可用的标准 EEG 电极布局。

(raw_fname,) = eegbci.load_data(subjects=1, runs=[6])
raw = mne.io.read_raw_edf(raw_fname, preload=True)

# Clean channel names to be able to use a standard 1005 montage
eegbci.standardize(raw)

# Read and set the EEG electrode locations using an anatomically
# shaped 10-05 montage:
montage = mne.channels.make_standard_montage("fsaverage_1005")
raw.set_montage(montage)
raw.set_eeg_reference(projection=True)  # needed for inverse modeling

# Check that the locations of EEG electrodes is correct with respect to MRI
mne.viz.plot_alignment(
    raw.info,
    src=src,
    eeg=["original", "projected"],
    trans=trans,
    show_axes=True,
    mri_fiducials=True,
    dig="fiducials",
)
35 eeg no mri
Extracting EDF parameters from /home/circleci/mne_data/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R06.edf...
Setting channel info structure...
Creating raw.info structure...
Reading 0 ... 19999  =      0.000 ...   124.994 secs...
EEG channel type selected for re-referencing
Adding average EEG reference projection.
1 projection items deactivated
Average reference projection was added, but has not been applied yet. Use the apply_proj method to apply it.
Reading /home/circleci/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-ico-5-src.fif...
Using outer_skin.surf for head surface.
Channel types:: eeg: 64
Projecting sensors to the head surface

设置源空间并计算前向算子#

fwd = mne.make_forward_solution(
    raw.info, trans=trans, src=src, bem=bem, eeg=True, mindist=5.0, n_jobs=None
)
fwd
Source space          : /home/circleci/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-ico-5-src.fif
MRI -> head transform : /home/circleci/project/mne/data/fsaverage/fsaverage-trans.fif
Measurement data      : instance of Info
Conductor model   : /home/circleci/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-5120-5120-5120-bem-sol.fif
Accurate field computations
Do computations in head coordinates
Free source orientations

Reading /home/circleci/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-ico-5-src.fif...
Read 2 source spaces a total of 20484 active source locations

Coordinate transformation: MRI (surface RAS) -> head
    0.999994 0.003552 0.000202      -1.76 mm
    -0.003558 0.998389 0.056626      31.09 mm
    -0.000001 -0.056626 0.998395      39.60 mm
    0.000000 0.000000 0.000000       1.00

Read  64 EEG channels from info
Head coordinate coil definitions created.
Source spaces are now in head coordinates.

Setting up the BEM model using /home/circleci/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-5120-5120-5120-bem-sol.fif...

Loading surfaces...

Loading the solution matrix...

Three-layer model surfaces loaded.
Loaded linear collocation BEM solution from /home/circleci/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-5120-5120-5120-bem-sol.fif
Employing the head->MRI coordinate transform with the BEM model.
BEM model fsaverage-5120-5120-5120-bem-sol.fif is now set up


Source spaces are in head coordinates.
Checking that the sources are inside the surface and at least    5.0 mm away (will take a few...)
Checking surface interior status for 10242 points...
    Found  2433/10242 points inside  an interior sphere of radius   47.7 mm
    Found     0/10242 points outside an exterior sphere of radius   98.3 mm
    Found     0/ 7809 points outside using surface Qhull
    Found     0/ 7809 points outside using solid angles
    Total 10242/10242 points inside the surface
Interior check completed in 595.1 ms
Checking surface interior status for 10242 points...
    Found  2241/10242 points inside  an interior sphere of radius   47.7 mm
    Found     0/10242 points outside an exterior sphere of radius   98.3 mm
    Found     0/ 8001 points outside using surface Qhull
    Found     0/ 8001 points outside using solid angles
    Total 10242/10242 points inside the surface
Interior check completed in 607.9 ms
Setting up for EEG...
Computing EEG at 20484 source locations (free orientations)...

Finished.
Forward
EEG
Source space Surface with 20484 vertices
Source orientation Free


至此,就可以使用标准的逆成像方法了!

婴儿 MRI 替代模板#

MNE 没有现成的婴儿示例数据集,因此我们来伪造一个 10-20 数据集:

ch_names = "Fz Cz Pz Oz Fp1 Fp2 F3 F4 F7 F8 C3 C4 T7 T8 P3 P4 P7 P8 O1 O2".split()
data = np.random.default_rng(0).standard_normal((len(ch_names), 1000))
info = mne.create_info(ch_names, 1000.0, "eeg")
raw = mne.io.RawArray(data, info)
Creating RawArray with float64 data, n_channels=20, n_times=1000
    Range : 0 ... 999 =      0.000 ...     0.999 secs
Ready.

获取婴儿 MRI 模板#

要将婴儿头模型用于 M/EEG 数据,可以使用 mne.datasets.fetch_infant_template() 下载婴儿模板:

0 files missing from ANTS6-0Months3T.txt in /home/circleci/mne_data/MNE-fsaverage-data/ANTS6-0Months3T

它附带若干有用的内置文件,其中包括位于 MRI 坐标系中的 10-20 电极布局,可用于计算 MRI 与头部之间的变换 trans:

fname_1020 = subjects_dir / subject / "montages" / "10-20-montage.fif"
mon = mne.channels.read_dig_fif(fname_1020, verbose="error")  # should be named -dig.fif
mon.rename_channels({f"EEG{ii:03d}": ch_name for ii, ch_name in enumerate(ch_names, 1)})
trans = mne.channels.compute_native_head_t(mon)
raw.set_montage(mon)
print(trans)
<Transform | MRI (surface RAS)->head>
[[ 0.99975431 -0.01839625  0.01236795 -0.00087239]
 [ 0.0143472   0.96230429  0.27159646  0.01252444]
 [-0.01689809 -0.27135229  0.96233177  0.03137219]
 [ 0.          0.          0.          1.        ]]

此外还提供 BEM 模型和源空间:

bem_dir = subjects_dir / subject / "bem"
fname_src = bem_dir / f"{subject}-oct-6-src.fif"
src = mne.read_source_spaces(fname_src)
print(src)
fname_bem = bem_dir / f"{subject}-5120-5120-5120-bem-sol.fif"
bem = mne.read_bem_solution(fname_bem)
    Reading a source space...
    Distance information added...
    [done]
    Reading a source space...
    Distance information added...
    [done]
    2 source spaces read
<SourceSpaces: [<surface (lh), n_vertices=48640, n_used=4098>, <surface (rh), n_vertices=48214, n_used=4098>] MRI (surface RAS) coords, subject 'ANTS6-0Months3T', ~6.9 MiB>
Loading surfaces...

Loading the solution matrix...

Three-layer model surfaces loaded.
Loaded linear collocation BEM solution from /home/circleci/mne_data/MNE-fsaverage-data/ANTS6-0Months3T/bem/ANTS6-0Months3T-5120-5120-5120-bem-sol.fif

可以通过绘制结果来确认一切是否符合预期:

fig = mne.viz.plot_alignment(
    raw.info,
    subject=subject,
    subjects_dir=subjects_dir,
    trans=trans,
    src=src,
    bem=bem,
    coord_frame="mri",
    mri_fiducials=True,
    show_axes=True,
    surfaces=("white", "outer_skin", "inner_skull", "outer_skull"),
)
mne.viz.set_3d_view(fig, 25, 70, focalpoint=[0, -0.005, 0.01])
35 eeg no mri
Channel types:: eeg: 20

至此,即可计算标准的前向算子和逆算子

如果你有数字化的头位信息或 MEG 数据,可以考虑使用 mne coreg 将合适的婴儿模板 MRI 配准(warp)到你的数字化信息上。

脚本总运行时间:(0 分钟 20.042 秒)

图库由 Sphinx-Gallery 生成