How can I read edf data using Python? I want to analyze data of a edf file, but I cannot read it using pyEDFlib. It threw the error OSError: The file is discontinous and cannot be read
and I'm not sure why.
How to read edf data in Python 3
28.4k Views Asked by Mindy At
2
There are 2 best solutions below
0

Another way to read an edf file --> array using pyedflib (if you don't want to use mne for dependency reasons):
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
There's more documentation here: pyedflib docs
I assume that your data are biological time-series like EEG, is this correct? If so, you can use the MNE library.
You have to install it first. Since it is not a standard library, take a look here. Then, you can use the
read_raw_edf()
method.For example:
See documentation in the links above for other properties of the data object