非官方中文翻译
本页译自 MNE-Python 官方文档:
查看英文原文 ↗。
文档版权归 MNE Developers 所有(BSD-3-Clause)。
说明
转到末尾下载完整示例代码。
计算空间分辨率指标以比较 MEG 与 EEG+MEG#
计算 dSPM 与 MNE 点扩散函数的峰值定位误差与空间偏差,绘制其分布及分布之差。本示例复现 [1] 的部分结果,即图 3 与图 4,并说明把 MEG 与 EEG 结合可减小点扩散函数、提高源成像的空间分辨率,尤其对较深的源。
# Author: Olaf Hauk <olaf.hauk@mrc-cbu.cam.ac.uk>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import mne
from mne.datasets import sample
from mne.minimum_norm.resolution_matrix import make_inverse_resolution_matrix
from mne.minimum_norm.spatial_resolution import resolution_metrics
print(__doc__)
data_path = sample.data_path()
subjects_dir = data_path / "subjects/"
meg_path = data_path / "MEG" / "sample"
fname_fwd_emeg = meg_path / "sample_audvis-meg-eeg-oct-6-fwd.fif"
fname_cov = meg_path / "sample_audvis-cov.fif"
fname_evo = meg_path / "sample_audvis-ave.fif"
# read forward solution with EEG and MEG
forward_emeg = mne.read_forward_solution(fname_fwd_emeg)
# forward operator with fixed source orientations
forward_emeg = mne.convert_forward_solution(
forward_emeg, surf_ori=True, force_fixed=True
)
# create a forward solution with MEG only
forward_meg = mne.pick_types_forward(forward_emeg, meg=True, eeg=False)
# noise covariance matrix
noise_cov = mne.read_cov(fname_cov)
# evoked data for info
evoked = mne.read_evokeds(fname_evo, 0)
# make inverse operator from forward solution for MEG and EEGMEG
inv_emeg = mne.minimum_norm.make_inverse_operator(
info=evoked.info, forward=forward_emeg, noise_cov=noise_cov, loose=0.0, depth=None
)
inv_meg = mne.minimum_norm.make_inverse_operator(
info=evoked.info, forward=forward_meg, noise_cov=noise_cov, loose=0.0, depth=None
)
# regularisation parameter
snr = 3.0
lambda2 = 1.0 / snr**2
Reading forward solution from /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif...
Reading a source space...
Computing patch statistics...
Patch information added...
Distance information added...
[done]
Reading a source space...
Computing patch statistics...
Patch information added...
Distance information added...
[done]
2 source spaces read
Desired named matrix (kind = 3523 (FIFF_MNE_FORWARD_SOLUTION_GRAD)) not available
Read MEG forward solution (7498 sources, 306 channels, free orientations)
Desired named matrix (kind = 3523 (FIFF_MNE_FORWARD_SOLUTION_GRAD)) not available
Read EEG forward solution (7498 sources, 60 channels, free orientations)
Forward solutions combined: MEG, EEG
Source spaces transformed to the forward solution coordinate frame
Average patch normals will be employed in the rotation to the local surface coordinates....
Converting to surface-based source orientations...
[done]
306 out of 366 channels remain after picking
366 x 366 full covariance (kind = 1) found.
Read a total of 4 projection items:
PCA-v1 (1 x 102) active
PCA-v2 (1 x 102) active
PCA-v3 (1 x 102) active
Average EEG reference (1 x 60) active
Reading /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-ave.fif ...
Read a total of 4 projection items:
PCA-v1 (1 x 102) active
PCA-v2 (1 x 102) active
PCA-v3 (1 x 102) active
Average EEG reference (1 x 60) active
Found the data of interest:
t = -199.80 ... 499.49 ms (Left Auditory)
0 CTF compensation matrices available
nave = 55 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
No baseline correction applied
Computing inverse operator with 364 channels.
364 out of 366 channels remain after picking
Selected 364 channels
Whitening the forward solution.
Created an SSP operator (subspace dimension = 4)
Computing rank from covariance with rank=None
Using tolerance 3.3e-13 (2.2e-16 eps * 305 dim * 4.8 max singular value)
Estimated rank (mag + grad): 302
MEG: rank 302 computed from 305 data channels with 3 projectors
Using tolerance 4.7e-14 (2.2e-16 eps * 59 dim * 3.6 max singular value)
Estimated rank (eeg): 58
EEG: rank 58 computed from 59 data channels with 1 projector
Setting small MEG eigenvalues to zero (without PCA)
Setting small EEG eigenvalues to zero (without PCA)
Creating the source covariance matrix
Adjusting source covariance matrix.
Computing SVD of whitened and weighted lead field matrix.
largest singular value = 4.31738
scaling factor to adjust the trace = 1.68644e+20 (nchan = 364 nzero = 4)
Computing inverse operator with 305 channels.
305 out of 306 channels remain after picking
Selected 305 channels
Whitening the forward solution.
Created an SSP operator (subspace dimension = 3)
Computing rank from covariance with rank=None
Using tolerance 3.3e-13 (2.2e-16 eps * 305 dim * 4.8 max singular value)
Estimated rank (mag + grad): 302
MEG: rank 302 computed from 305 data channels with 3 projectors
Setting small MEG eigenvalues to zero (without PCA)
Creating the source covariance matrix
Adjusting source covariance matrix.
Computing SVD of whitened and weighted lead field matrix.
largest singular value = 4.63485
scaling factor to adjust the trace = 1.05542e+20 (nchan = 305 nzero = 3)
EEG+MEG#
计算 MNE 的分辨率矩阵、定位误差与空间偏差:
rm_emeg = make_inverse_resolution_matrix(
forward_emeg, inv_emeg, method="MNE", lambda2=lambda2
)
ple_psf_emeg = resolution_metrics(
rm_emeg, inv_emeg["src"], function="psf", metric="peak_err"
)
sd_psf_emeg = resolution_metrics(
rm_emeg, inv_emeg["src"], function="psf", metric="sd_ext"
)
del rm_emeg
364 out of 366 channels remain after picking
Preparing the inverse operator for use...
Scaled noise and source covariance from nave = 1 to nave = 1
Created the regularized inverter
Created an SSP operator (subspace dimension = 4)
Created the whitener using a noise covariance matrix with rank 360 (4 small eigenvalues omitted)
Applying inverse operator to ""...
Picked 364 channels from the data
Computing inverse...
Eigenleads need to be weighted ...
Computing residual...
Explained 43.2% variance
[done]
Dimension of Inverse Matrix: (7498, 364)
Dimensions of resolution matrix: 7498 by 7498.
MEG#
对 MEG 做同样的计算:
rm_meg = make_inverse_resolution_matrix(
forward_meg, inv_meg, method="MNE", lambda2=lambda2
)
ple_psf_meg = resolution_metrics(
rm_meg, inv_meg["src"], function="psf", metric="peak_err"
)
sd_psf_meg = resolution_metrics(rm_meg, inv_meg["src"], function="psf", metric="sd_ext")
del rm_meg
305 out of 306 channels remain after picking
Preparing the inverse operator for use...
Scaled noise and source covariance from nave = 1 to nave = 1
Created the regularized inverter
Created an SSP operator (subspace dimension = 3)
Created the whitener using a noise covariance matrix with rank 302 (3 small eigenvalues omitted)
Applying inverse operator to ""...
Picked 305 channels from the data
Computing inverse...
Eigenleads need to be weighted ...
Computing residual...
Explained 46.7% variance
[done]
Dimension of Inverse Matrix: (7498, 305)
Dimensions of resolution matrix: 7498 by 7498.
可视化#
查看 PSF 在整个皮层上的峰值定位误差(PLE):
brain_ple_emeg = ple_psf_emeg.plot(
"sample",
"inflated",
"lh",
subjects_dir=subjects_dir,
figure=1,
clim=dict(kind="value", lims=(0, 2, 4)),
)
brain_ple_emeg.add_text(0.1, 0.9, "PLE PSF EMEG", "title", font_size=16)

仅 MEG:
brain_ple_meg = ple_psf_meg.plot(
"sample",
"inflated",
"lh",
subjects_dir=subjects_dir,
figure=2,
clim=dict(kind="value", lims=(0, 2, 4)),
)
brain_ple_meg.add_text(0.1, 0.9, "PLE PSF MEG", "title", font_size=16)

两个分布相减并绘制差值:
diff_ple = ple_psf_emeg - ple_psf_meg
brain_ple_diff = diff_ple.plot(
"sample",
"inflated",
"lh",
subjects_dir=subjects_dir,
figure=3,
clim=dict(kind="value", pos_lims=(0.0, 0.5, 1.0)),
smoothing_steps=20,
)
brain_ple_diff.add_text(0.1, 0.9, "PLE EMEG-MEG", "title", font_size=16)

这些图显示,就峰值定位误差而言,把 EEG 加入 MEG 带来的益处不大。接下来可视化 PSF 在整个皮层上的空间偏差(SD):
brain_sd_emeg = sd_psf_emeg.plot(
"sample",
"inflated",
"lh",
subjects_dir=subjects_dir,
figure=4,
clim=dict(kind="value", lims=(0, 2, 4)),
)
brain_sd_emeg.add_text(0.1, 0.9, "SD PSF EMEG", "title", font_size=16)

仅 MEG:
brain_sd_meg = sd_psf_meg.plot(
"sample",
"inflated",
"lh",
subjects_dir=subjects_dir,
figure=5,
clim=dict(kind="value", lims=(0, 2, 4)),
)
brain_sd_meg.add_text(0.1, 0.9, "SD PSF MEG", "title", font_size=16)

两个分布相减并绘制差值:
diff_sd = sd_psf_emeg - sd_psf_meg
brain_sd_diff = diff_sd.plot(
"sample",
"inflated",
"lh",
subjects_dir=subjects_dir,
figure=6,
clim=dict(kind="value", pos_lims=(0.0, 0.5, 1.0)),
smoothing_steps=20,
)
brain_sd_diff.add_text(0.1, 0.9, "SD EMEG-MEG", "title", font_size=16)

把 EEG 加入 MEG 会减小点扩散函数的空间范围(空间偏差更低,蓝色),从而提高分辨率,尤其对较深的源位置。
参考文献#
脚本总运行时间:(0 分 14.235 秒)