EEG records exploring — BCI-Framework documentation

# EEG records exploring

BCI-Framework store the record by default using the data format defined by OpenBCI-Stream, this makes it a lot easy to extract and crop data based on markers. We are working with a run generated by the 4-Class motor imagery (Arrows).

    [1]:

    from openbci_stream.utils.hdf5 import HDF5Reader

    filename = "record-04_10_21-18_07_25.h5"
    file = HDF5Reader(filename)
    print(file)
    file.close()

    ==================================================
    record-04_10_21-18_07_25.h5
    2021-04-10 18:07:25.843257
    ==================================================
    MARKERS: ['Up', 'Bottom', 'Left', 'Right']
    SAMPLE_RATE: 1000
    STREAMING_SAMPLE_RATE: 100
    DATETIME: 1618096045.843257
    MONTAGE: standard_1020
    CHANNELS: {1: 'Fp1', 2: 'Fp2', 3: 'T3', 4: 'C3', 5: 'C4', 6: 'T4', 7: 'O1', 8: 'O2'}
    START-OFFSET: 11.801958084106445
    SHAPE: [8, 259700]
    END-OFFSET: 12.935876846313477
    ==================================================

Notice the 4 markers, and the channels.

## MNE epochs

`get_epochs()` return an `mne.EpochsArray` object:

    [2]:

    with HDF5Reader(filename) as file:
        epochs = file.get_epochs(tmin=-2, duration=6)

    epochs.info

    [2]:

    <Info | 8 non-empty values
     bads: []
     ch_names: C3, Fp1, Fp2, C4, T3, T4, O2, O1
     chs: 8 EEG
     custom_ref_applied: False
     dig: 11 items (3 Cardinal, 8 EEG)
     highpass: 0.0 Hz
     lowpass: 500.0 Hz
     meas_date: unspecified
     nchan: 8
     projs: []
     sfreq: 1000.0 Hz
    >

## Export to EDF

    [3]:

    with HDF5Reader(filename) as file:
        file.to_edf(filename.replace('.h5', '.edf'))

## RAW `ndarray` objects

`get_data()` return a standard array `(epochs, channels, time)` and their respective (`classes`):

    [4]:

    with HDF5Reader(filename) as file:
        data, classes = file.get_data(tmin=-2, duration=6)

    data.shape, classes.shape

    [4]:

    ((40, 8, 6000), (40,))