如何在Python 3中读取edf数据

问题描述 投票:0回答:2

如何使用Python读取edf数据?我想分析 edf 文件的数据,但无法使用 pyEDFlib 读取它。它引发了错误

OSError: The file is discontinous and cannot be read
,我不知道为什么。

python time-series european-data-format mne-python
2个回答
27
投票

我假设你的数据是像脑电图这样的生物时间序列,这是正确的吗?如果是这样,您可以使用 MNE 库。

您必须先安装它。由于它不是标准库,请查看here。然后,您可以使用

read_raw_edf()
方法。

例如:

import mne
file = "my_path\\my_file.edf"
data = mne.io.read_raw_edf(file)
raw_data = data.get_data()
# you can get the metadata included in the file and a list of all channels:
info = data.info
channels = data.ch_names

有关数据对象的其他属性,请参阅上面链接中的文档


0
投票

使用 pyedflib 读取 edf 文件的另一种方法 --> 数组(如果由于依赖性原因不想使用 mne):

 import pyedflib
 def edf_to_arr(edf_path):
    f = pyedflib.EdfReader(edf_path)
    n = f.signals_in_file
    signal_labels = f.getSignalLabels()
    sigbufs = np.zeros((n, f.getNSamples()[0]))
    for i in np.arange(n):
        sigbufs[i, :] = f.readSignal(i)
    
    return sigbufs

这里有更多文档:pyedflib docs

© www.soinside.com 2019 - 2024. All rights reserved.