非官方中文翻译
本页译自 MNE-Python 官方文档:
查看英文原文 ↗。
文档版权归 MNE Developers 所有(BSD-3-Clause)。
说明
转到末尾下载完整示例代码。
带运动补偿的 Maxwell 滤波#
在模拟数据上演示运动补偿。模拟数据包含双侧听觉皮层激活,在 14 种不同的头部旋转下重复(头中心固定)。详见:
# Authors: Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import mne
from mne.preprocessing import maxwell_filter
print(__doc__)
data_path = mne.datasets.misc.data_path(verbose=True) / "movement"
head_pos = mne.chpi.read_head_pos(data_path / "simulated_quats.pos")
raw = mne.io.read_raw_fif(data_path / "simulated_movement_raw.fif")
raw_stat = mne.io.read_raw_fif(data_path / "simulated_stationary_raw.fif")
Opening raw data file /home/circleci/mne_data/MNE-misc-data/movement/simulated_movement_raw.fif...
Range : 25800 ... 34208 = 42.956 ... 56.955 secs
Ready.
Opening raw data file /home/circleci/mne_data/MNE-misc-data/movement/simulated_stationary_raw.fif...
Range : 25800 ... 34208 = 42.956 ... 56.955 secs
Ready.
可视化“受试者”的头部运动。通过提供测量信息,可用蓝色显示各方向上到最近传感器的距离(如 X 方向为左右、Y 方向为前后),并可用红色显示目标位置(若给出)。
mne.viz.plot_head_positions(
head_pos, mode="traces", destination=raw.info["dev_head_t"], info=raw.info
)

也可以用箭头图(quiver)可视化。
mne.viz.plot_head_positions(
head_pos, mode="field", destination=raw.info["dev_head_t"], info=raw.info
)

Getting helmet for system 306m
处理模拟的原始数据(考虑头部运动)。
# extract our resulting events
events = mne.find_events(raw, stim_channel="STI 014")
events[:, 2] = 1
raw.plot(events=events)
topo_kwargs = dict(times=[0, 0.1, 0.2], ch_type="mag", vlim=(-500, 500))

Finding events on: STI 014
14 events found on stim channel STI 014
Event IDs: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
首先,对静止数据(双侧听觉模式)求平均。
evoked_stat = mne.Epochs(raw_stat, events, 1, -0.2, 0.8).average()
fig = evoked_stat.plot_topomap(**topo_kwargs)
fig.suptitle("Stationary")

Not setting metadata
14 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
其次,做朴素平均:对模拟为不同头部位置与朝向的分段求平均,这会从空间上模糊活动。
epochs = mne.Epochs(raw, events, 1, -0.2, 0.8)
evoked = epochs.average()
fig = evoked.plot_topomap(**topo_kwargs)
fig.suptitle("Moving: naive average")

Not setting metadata
14 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
第三,使用原始数据运动补偿(可恢复模式)。
raw_sss = maxwell_filter(raw, head_pos=head_pos, mc_interp="hann")
evoked_raw_mc = mne.Epochs(raw_sss, events, 1, -0.2, 0.8).average()
fig = evoked_raw_mc.plot_topomap(**topo_kwargs)
fig.suptitle("Moving: movement compensated (raw)")

Maxwell filtering raw data
No bad MEG channels
Processing 203 gradiometers and 102 magnetometers
Automatic origin fit: head of radius 91.2 mm
Using origin -4.2, 16.4, 51.8 mm in the head frame
Appending head position result channels and loading raw data from disk
Using 90/95 harmonic components for 0.000 (75/80 in, 15/15 out)
Processing 1 data chunk of (at least) 10.0 s with 0.0 s overlap and boxcar windowing
The final 4.000899143496717 s will be lumped into the final window
Using 87/95 harmonic components for 0.000 (72/80 in, 15/15 out)
Using 88/95 harmonic components for 1.001 (73/80 in, 15/15 out)
Using 90/95 harmonic components for 2.000 (75/80 in, 15/15 out)
Using 88/95 harmonic components for 3.000 (73/80 in, 15/15 out)
Using 88/95 harmonic components for 3.999 (73/80 in, 15/15 out)
Using 88/95 harmonic components for 5.000 (73/80 in, 15/15 out)
Using 89/95 harmonic components for 6.001 (74/80 in, 15/15 out)
Using 93/95 harmonic components for 6.999 (78/80 in, 15/15 out)
Using 88/95 harmonic components for 8.000 (73/80 in, 15/15 out)
Using 91/95 harmonic components for 9.001 (76/80 in, 15/15 out)
Using 93/95 harmonic components for 10.000 (78/80 in, 15/15 out)
Using 93/95 harmonic components for 11.000 (78/80 in, 15/15 out)
Using 89/95 harmonic components for 11.999 (74/80 in, 15/15 out)
Using 88/95 harmonic components for 13.000 (73/80 in, 15/15 out)
[done]
Not setting metadata
14 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
第四,使用诱发数据运动补偿。对于这些包含很大旋转的数据,它恢复模式的效果不那么干净。
evoked_evo_mc = mne.epochs.average_movements(epochs, head_pos=head_pos)
fig = evoked_evo_mc.plot_topomap(**topo_kwargs)
fig.suptitle("Moving: movement compensated (evoked)")

Automatic origin fit: head of radius 91.2 mm
Aligning and averaging up to 14 epochs
No bad MEG channels
Processing 203 gradiometers and 102 magnetometers
Processing epoch 1 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 2 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 3 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 4 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 5 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 6 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 7 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 8 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 9 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 10 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 11 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 12 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 13 (device location: 0.0, 0.0, 40.0 mm)
Processing epoch 14 (device location: 0.0, 0.0, 40.0 mm)
Created Evoked dataset from 14 epochs
脚本总运行时间:(0 分 3.000 秒)