pythonimporteuropean-data-format

Import .edf file directly from online archive in python


Using pyedflib to import edf files, is it possible to import datasets directly from their source? Or is it always necessary to download data and import locally?

for example, I would like to do this:

pyedflib.EdfReader("https://www.physionet.org/pn6/chbmit/chb02/chb02_02.edf")

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-64-d123ce671a2f> in <module>()
----> 1 pyedflib.EdfReader("https://www.physionet.org/pn6/chbmit/chb02/chb02_02.edf")

pyedflib/_extensions/_pyedflib.pyx in pyedflib._extensions._pyedflib.CyEdfReader.__init__()

pyedflib/_extensions/_pyedflib.pyx in pyedflib._extensions._pyedflib.CyEdfReader.open()

pyedflib/_extensions/_pyedflib.pyx in pyedflib._extensions._pyedflib.CyEdfReader.check_open_ok()

IOError: can not open file, no such file or directory

Solution

  • Answer received on GitHub page

    import pyedflib
    import os
    url = "https://www.physionet.org/pn6/chbmit/chb01/chb01_01.edf"
    filename = "./chb.edf"
    try:
        from urllib import urlretrieve # Python 2
    
    except ImportError:
        from urllib.request import urlretrieve # Python 3
    
    urlretrieve(url,filename)
    pyedflib.EdfReader(filename)
    os.remove(filename)
    

    https://github.com/holgern/pyedflib/issues/22#issuecomment-341649760