非官方中文翻译
本页译自 MNE-Python 官方文档:
查看英文原文 ↗。
文档版权归 MNE Developers 所有(BSD-3-Clause)。
说明
转到末尾下载完整示例代码。
生成模拟的源数据#
本示例说明如何使用 mne.simulation.SourceSimulator 类生成源估计与原始数据。本示例仅作简要介绍,只展示最简单的用法。
# Author: Kostiantyn Maksymenko <kostiantyn.maksymenko@gmail.com>
# Samuel Deslauriers-Gauthier <sam.deslauriers@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import numpy as np
import mne
from mne.datasets import sample
print(__doc__)
本示例将使用示例受试者的信息;若本机尚无数据会自动下载。我们还会设置受试者目录,避免每次调用函数时重复传入。
data_path = sample.data_path()
subjects_dir = data_path / "subjects"
subject = "sample"
首先,从测试受试者获取 info 结构。
evoked_fname = data_path / "MEG" / subject / "sample_audvis-ave.fif"
info = mne.io.read_info(evoked_fname)
tstep = 1.0 / info["sfreq"]
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 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
为选择要激活的区域,我们以尾侧额中回为种子生长出一个感兴趣区域。
selected_label = mne.read_labels_from_annot(
subject, regexp="caudalmiddlefrontal-lh", subjects_dir=subjects_dir
)[0]
location = "center" # Use the center of the region as a seed.
extent = 10.0 # Extent in mm of the region.
label = mne.label.select_sources(
subject, selected_label, location=location, extent=extent, subjects_dir=subjects_dir
)
Reading labels from parcellation...
read 1 labels from /home/circleci/mne_data/MNE-sample-data/subjects/sample/label/lh.aparc.annot
read 0 labels from /home/circleci/mne_data/MNE-sample-data/subjects/sample/label/rh.aparc.annot
为待激活区域中的每个源定义活动的时间过程。这里使用 18 Hz 正弦波,峰值幅度为 10 nAm。
source_time_series = np.sin(2.0 * np.pi * 18.0 * np.arange(100) * tstep) * 10e-9
用事件定义活动发生的时间:第一列是事件所在的采样点,第二列不使用,第三列是事件 ID。这里事件每 200 个采样点出现一次。
创建模拟的源活动。这里使用 SourceSimulator,其 add_data 方法是关键:它指定事件类型发生的位置(label)、内容(source_time_series)与时间(events)。
把源时间序列投影到传感器空间并加入噪声。源模拟器可以直接传给 simulate_raw 函数。
raw = mne.simulation.simulate_raw(info, source_simulator, forward=fwd)
cov = mne.make_ad_hoc_cov(raw.info)
mne.simulation.add_noise(raw, cov, iir_filter=[0.2, -0.2, 0.04], rng=97)
raw.plot()

Setting up raw simulation: 1 position, "cos2" interpolation
Event information stored on channel: STI 014
Interval 0.000–1.665 s
Setting up forward solutions
Computing gain matrix for transform #1/1
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
Interval 0.000–1.665 s
10 STC iterations provided
[done]
Adding noise to 366/376 channels (366 channels in cov)
绘制诱发数据,从另一个角度查看模拟的原始数据。
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, 1, tmin=-0.05, tmax=0.2)
evoked = epochs.average()
evoked.plot()

Finding events on: STI 014
50 events found on stim channel STI 014
Event IDs: [1]
Not setting metadata
50 matching events found
Setting baseline interval to [-0.049948803289596964, 0.0] s
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 4)
4 projection items activated
脚本总运行时间:(0 分 1.667 秒)