eeg_tools.read_eeg

eeg_tools.read_eeg(eegpath, outfile, electrodelist=None, savemat=True)[source]

Read raw EEG data from binary *.EEG/*.eeg and *.21E files

Parameters:

eegpath : str

Path to the .EEG/.eeg file (the code assumes that the corresponding .21E/.21e file is in the same location)

outfile : str

Path specifying the HDF5 file to be created. WARNING: File MUST NOT exist!

electrodelist : list

Python list of strings holding names of electrodes to be saved (if not the entire EEG file is needed/wanted). By default the entire EEG file is converted to HDF5.

savemat : bool

Specifiy if data should be saved as a NumPy 2darray (format is: number of electrodes by number of samples) or by electrodenames (see Examples for details)

Returns:

Nothing : None

See also

h5py
A Pythonic interface to the HDF5 binary data format

Notes

Depending on the value of savemat the HDF5 file structure will differ. The HDF5 file always contain the groups EEG. In EEG the raw data is stored either as NumPy 2darray (savemat = True) or sorted by electrode name (savemat = False). Metadata of the EEG scan (record date, sampling rate, session length etc.) are stored as attributes of the EEG group. Note: The code allocates 25% of RAM available on the machine to temporarily hold the EEG data. Thus, reading/writing may take longer on computers with little memory.

Examples

Suppose the files test.eeg and test.21E are in the directory mytest. Suppose further that the EEG file contains recordings of 84 electrodes and the output HDF5 container should be Results/test.h5. If the entire EEG file has to be converted to HDF5 as a matrix then, cd to the parent directory of mytest and type

>>> read_eeg('mytest/test.eeg','Results/test.h5')

The resulting HDF5 file contains the group EEG with attributes holding the corresponding metadata (see Notes for details). The EEG time-courses can be found in EEG:

>>> f = h5py.File('Results/test.h5')
>>> f['EEG'].keys()
>>> ['eeg_mat']

The dataset eeg_mat holds the entire EEG dataset as matrix (NumPy 2darray),

>>> f['EEG']['eeg_mat'].value
>>> array([[32079, 32045, 32001, ..., 33607, 33556, 33530],
          [31708, 31712, 31712, ..., 33607, 33597, 33599],
          [31719, 31722, 31704, ..., 33733, 33713, 33708],
          ..., 
          [39749, 34844, 36671, ..., 44616, 43642, 41030],
          [30206, 28126, 30805, ..., 39691, 36586, 34550],
          [31084, 30167, 31580, ..., 38113, 36470, 35205]], dtype=uint16)

The attribute electrode_list is a NumPy array of electrodenames corresponding to the rows of eeg_mat, i.e., f[‘EEG’][‘eeg_mat’][23,:] is the time-series of electrode f[‘EEG’].attrs[‘electrode_list’][23]

>>> f['EEG'].attrs['electrode_list'][23]
>>> 'RFC8'
>>> f['EEG']['eeg_mat'][23,:]
>>> array([33602, 33593, 33649, ..., 32626, 32648, 32650], dtype=uint16)

Additional meta-data (like scanning date, session length, etc.) are also saved as group attributes where summary is a string representation of all meta values, i.e.,

>>> f['EEG'].attrs['summary']
>>>  Data was recorded on Friday, April 11 2014
     Begin of session: 10:1:49
     Sampling rate: 1000 Hz
     Length of session: 2.0 hours

The respective meta values are stored as individual attributes (using numeric values), e.g.,

>>> f['EEG'].attrs['session_length']
>>> 2.0

If only the electrodes ‘RFA1’ and ‘RFA3’ are of interest and the read-out should be saved by the respective electrode names then the following command could be used

>>> read_eeg('mytest/test.eeg','Results/test.h5',electrodelist=['RFA1','RFA3'],savemat=False)

In this case the EEG group of the resulting HDF5 file looks like this

>>> f = h5py.File('Results/test.h5')
>>> f['EEG'].keys()
>>> ['RFA1', 'RFA3']
>>> f['EEG']['RFA1'].value
>>> array([32079, 32045, 32001, ..., 33607, 33556, 33530], dtype=uint16)

Thus, the electrode time-courses are saved using the respective electrode names.