2

I have a .edf file that I can read with "pyedflib" with the code given below. The code is basically taking .edf file and converting it to numpy array. The array shape is 65*20000.

file = pyedflib.EdfReader(file_name)
n = file.signals_in_file
signal_labels = file.getSignalLabels()
sigbufs = np.zeros((n,file.getNSamples()[0]))
for i in np.arange(n):
    sigbufs[i,:]=file.readSignal(i)

return sigbufs

And also I have a .edf.event file which correspond with the information about the .edf file. The file text based content given in below.

"""Xü## time resolution: 160 ìÿÿÿÿ XüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1ZüT0 duration: 4.2 ZüT2 duration: 4.1ZüT0 duration: 4.2 ZüT1 duration: 4.1 """

T0, T1 and T2 are an experiment types and this file gives the duration of experiments.

My purpose is to extract these information to use for above data. I can do this with implementing some regular expression technique. But since there are a lot of data for my future implementations it's really time consuming to find the pattern.

Therefore, my question is: Is there any library or tool that can read the .edf.event file?

Also if you want to see the .edf.event files you can check the link below.

https://www.physionet.org/pn4/eegmmidb/S001/

ibrahimG.
  • 73
  • 2
  • 8

2 Answers2

2

I ran into this issue as well. It turns out the edf.event files seem to be of a file type that is only compatible with specific physionet software. Luckily, all of the annotation information from the event file is available in the edf files that they provide. In order to retrieve the annotations, use this bit of code which will print all annotations of an edf file as numpy arrays:

file = pyedflib.EdfReader(file_name)  
annotations = file.readAnnotations()  
print(annotations)  

EDIT: To assign the annotated codes to the data in each file for your particular dataset (plus remove the last half second of 0 values), use the below script:

import urllib.request
import numpy as np
import pyedflib

timeArray = np.array([round(x,5) for x in np.arange(0,124.5,.00625)])
timeArray = timeArray.reshape(19920,1)
reader = pyedflib.EdfReader('your/path/here/S001R05.edf')
annotations = reader.readAnnotations()
intervals = np.append(annotations[0],[124.5])
codes = annotations[2]
codeArray = []     
counter = 1
for timeVal in timeArray:
    if timeVal == 124.5:
        break
    elif timeVal / intervals[counter] == 1.0:
        counter += 1

    codeArray.append(codes[counter - 1])

invertCodeArray = np.array(codeArray).reshape(19920,1)
numSignals = reader.signals_in_file
signal_labels = reader.getSignalLabels()
dataset = np.zeros((numSignals, reader.getNSamples()[0]))
for signal in np.arange(numSignals):
    dataset[signal, :] = reader.readSignal(signal)

dataset = dataset[:,:-80].transpose()
masterSet = np.concatenate((timeArray,invertCodeArray,dataset),axis=1)
  • I actually thought like this and i extract information with regular experessions. But as you said i want something like a tool. – ibrahimG. Apr 11 '18 at 19:46
  • I'm not sure what you mean. All of the information in the event file can be accessed using the readAnnotations() method. As far as assigning the annotated codes to the correct rows of data, I will provide an edit with that script. – stefanLopez Apr 11 '18 at 20:14
0
import wfdb

path='staffiii/data/'
#location of file on physionet server. This corresponds to STAFF III database

filename='001c'
#patient file name

sig, fields = wfdb.rdsamp(filename, pn_dir=path)

ann_ref = wfdb.rdann(filename,'event',pn_dir=path)

Use this, in rdann pass parameter as 'event' for reading *.event files and 'atr' for reading *.atr files.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103