Python MNE - 从数组中读取 EEG 数据

信息处理 信号分析 Python 脑电图
2022-02-11 20:24:57

我有以 3D numpy 数组(epoch * channel * timepoint)形式出现的 EEG 数据。timepoint 是一个 256 个元素的数组,包含每个采样的时间点(总共 1 秒,256Hz)。epoch 是一个实验性的试验。

我正在尝试将 numpy 数组导入 Python-MNE ( http://martinos.org/mne/stable/mne-python.html ) 可以理解的形式,但我遇到了一些麻烦

首先,我不确定是否应该将这些原始数据作为 RawArray 或 EpochsArray 导入。我用这个尝试了后者:

ch_names = list containing my 64 eeg channel names
allData = 3d numpy array as described above

info = mne.create_info(ch_names, 256, ch_types='eeg')

event_id = 1

#I got this from a tutorial but really unsure what it does and I think this may be the problem
events = np.array([200, event_id])  #I got this from a tutorial but really unsure what it does and I think this may be the problem

raw = mne.EpochsArray(allData, info, events=events)

picks = mne.pick_types(info, meg=False, eeg=True, misc=False)

raw.plot(picks=picks, show=True, block=True)

当我运行它时,我得到一个索引错误:“数组索引太多”

最终我想对数据进行一些 STFT 和 CSP 分析,但现在我需要一些帮助来进行初始重组和导入 MNE。

导入这个 numpy 数据的正确方法是什么,可以最容易地完成我的预期分析?

1个回答

mne.EpochsArray用于 3-D 数据(epochs * channels * times)。mne.RawArray用于二维数据。使用EpochsArray

events是一个 n * 3 整数数组。3 列是:时间(以采样点为单位)、长度(您可以在此处放置一个虚拟对象-几乎从未检查过-但您仍然需要 3 列)、值(例如条件)。你给它喂了一个 1 * 2 的数组。

尝试一下:

import numpy as np
from mne import create_info, EpochsArray
n_epochs = 100
channels = ["a", "b", "c", "d"]
n_channels = len(channels)
events = np.array([np.arange(n_epochs), np.ones(n_epochs), np.ones(n_epochs)]).T.astype(int)
d = np.random.random((n_epochs, n_channels, 256))

info = create_info(channels, 256, "eeg")
epochs = EpochsArray(d, info, events)

epochs.plot(show=True, block=True)