使用标准模板 MRI 根据 EEG 数据计算前向算子

本文详细介绍了如何使用mne库中的fsaverage模板,根据实际EEG数据计算前向算子的过程,包括数据预处理、电极位置设置和源空间建模。

在这里插入图片描述

# https://mne.tools/stable/auto_tutorials/forward/35_eeg_no_mri.html

# 本教程说明如何使用标准模板 MRI 主题根据 EEG 数据计算前向算子
#
# 成人模板 MRI (fsaverage)
# 首先我们展示如何fsaverage用作替代subject

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

import os.path as op
import numpy as np

import mne
from mne.datasets import eegbci
from mne.datasets import fetch_fsaverage

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

# The files live in:
subject = "fsaverage"
trans = "fsaverage"  # MNE has a built-in fsaverage transformation
src = op.join(fs_dir, "bem", "fsaverage-ico-5-src.fif")
bem = op.join(fs_dir, "bem", "fsaverage-5120-5120-5120-bem-sol.fif")


#加载数据  BCI的
# (raw_fname,) = eegbci.load_data(subject=1, runs=[6])
# raw = mne.io.read_raw_edf(raw_fname, preload=True)

raw = mne.io.read_raw_eeglab('eeg_data/sub2.set')



# Clean channel names to be able to use a standard 1005 montage
# new_names = dict(
#     (ch_name, ch_name.rstrip(".").upper().replace("Z", "z").replace("FP", "Fp"))
#     for ch_name in raw.ch_names
# )
# raw.rename_channels(new_names)

# Read and set the EEG electrode locations, which are already in fsaverage's
# space (MNI space) for standard_1020:
# montage = mne.channels.make_standard_montage("standard_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",
# )

#Setup source space and compute forward
fwd = mne.make_forward_solution(
    raw.info, trans=trans, src=src, bem=bem, eeg=True, mindist=5.0, n_jobs=None
)

print()
#保存前向解到文件中
# mne.write_forward_solution('solution_bci4.fif',fwd,overwrite=True)
# 保存出问题,暂时先不保存




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值