2014-07-10

Reading Physiology Data in EDF+ Format Using EEGTools

For years, I always converted EDF+ format data into text files for processing. Recently, I was tired of this and decided to try directly read EDF+ data. I tried out a Python module EEGTools by Boris Reuderink and it turned out to be great. It's super easy to use. Just use these two lines:

import eegtools
Data = eegtools.io.load_edf('Sample.edf')

The structure of Data is like this
EDF(X=array([[ -14.,    9.,  -70., ...,  -50.,  -99.,  -93.],
       [ -35.,  -21.,  -87., ...,  -45.,  -98.,  -81.],
       [ -72.,  -62., -116., ...,  -32.,  -79.,  -52.],
       ..., 
       [ -37.,  -89.,  -63., ...,  -41.,  -16.,  -45.],
       [ -69., -120.,  -99., ...,  -46.,  -25.,  -55.],
       [ -44.,  -87.,  -57., ...,  -29.,   -4.,  -41.]], dtype=float32), sample_rate=160.0, chan_lab=['Fc5.', 'Fc3.', 'Fc1.', 'Fcz.', 'Fc2.', 'Fc4.', 'Fc6.', 'C5..', 'C3..', 'C1..', 'Cz..', 'C2..', 'C4..', 'C6..', 'Cp5.', 'Cp3.', 'Cp1.', 'Cpz.', 'Cp2.', 'Cp4.', 'Cp6.', 'Fp1.', 'Fpz.', 'Fp2.', 'Af7.', 'Af3.', 'Afz.', 'Af4.', 'Af8.', 'F7..', 'F5..', 'F3..', 'F1..', 'Fz..', 'F2..', 'F4..', 'F6..', 'F8..', 'Ft7.', 'Ft8.', 'T7..', 'T8..', 'T9..', 'T10.', 'Tp7.', 'Tp8.', 'P7..', 'P5..', 'P3..', 'P1..', 'Pz..', 'P2..', 'P4..', 'P6..', 'P8..', 'Po7.', 'Po3.', 'Poz.', 'Po4.', 'Po8.', 'O1..', 'Oz..', 'O2..', 'Iz..'], time=array([  0.00000000e+00,   6.25000000e-03,   1.25000000e-02, ...,
         1.22981250e+02,   1.22987500e+02,   1.22993750e+02]), annotations=[(0.0, 4.1, [u'T0']), (4.1, 4.1, [u'T1']), (8.2, 4.1, [u'T0']), (12.3, 4.1, [u'T2']), (16.4, 4.1, [u'T0']), (20.5, 4.1, [u'T2']), (24.6, 4.1, [u'T0']), (28.7, 4.1, [u'T1']), (32.8, 4.1, [u'T0']), (36.9, 4.1, [u'T2']), (41.0, 4.1, [u'T0']), (45.1, 4.1, [u'T1']), (49.2, 4.1, [u'T0']), (53.3, 4.1, [u'T2']), (57.4, 4.1, [u'T0']), (61.5, 4.1, [u'T1']), (65.6, 4.1, [u'T0']), (69.7, 4.1, [u'T1']), (73.8, 4.1, [u'T0']), (77.9, 4.1, [u'T2']), (82.0, 4.1, [u'T0']), (86.1, 4.1, [u'T1']), (90.2, 4.1, [u'T0']), (94.3, 4.1, [u'T2']), (98.4, 4.1, [u'T0']), (102.5, 4.1, [u'T1']), (106.6, 4.1, [u'T0']), (110.7, 4.1, [u'T2']), (114.8, 4.1, [u'T0']), (118.9, 4.1, [u'T1'])])

As you can see, the recordings are in the member X. The channels that member arrays of X correspond to are sequentially given in the member chan_lab. Sampling rate and time instants are given in sample_rate and time. Lastly, you can access the annotation on EEG from annotations.

To download or install, see EEGTools' GitHub page: http://borisreuderink.nl/ Read the instruction at the bottom and use PIP to install - easier than cloning and setup.py.

No comments: