BrainFlow to MNE Python Notebook

In [1]:
import time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import brainflow
from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds

import mne
from mne.channels import read_layout
/home/docs/checkouts/readthedocs.org/user_builds/brainflow/envs/stable/lib/python3.7/site-packages/traitlets/traitlets.py:3036: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  FutureWarning,
In [2]:
# use synthetic board for demo
params = BrainFlowInputParams()
board = BoardShim(BoardIds.SYNTHETIC_BOARD.value, params)
board.prepare_session()
board.start_stream()
time.sleep(10)
data = board.get_board_data()
board.stop_stream()
board.release_session()
In [3]:
eeg_channels = BoardShim.get_eeg_channels(BoardIds.SYNTHETIC_BOARD.value)
eeg_data = data[eeg_channels, :]
eeg_data = eeg_data / 1000000 # BrainFlow returns uV, convert to V for MNE
In [4]:
# Creating MNE objects from brainflow data arrays
ch_types = ['eeg'] * len(eeg_channels)
ch_names = BoardShim.get_eeg_names(BoardIds.SYNTHETIC_BOARD.value)
sfreq = BoardShim.get_sampling_rate(BoardIds.SYNTHETIC_BOARD.value)
info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
raw = mne.io.RawArray(eeg_data, info)
# its time to plot something!
raw.plot_psd(average=False)
Creating RawArray with float64 data, n_channels=16, n_times=2482
    Range : 0 ... 2481 =      0.000 ...     9.924 secs
Ready.
Effective window size : 8.192 (s)
<ipython-input-1-26921b74558c>:8: RuntimeWarning: Channel locations not available. Disabling spatial colors.
  raw.plot_psd(average=False)
../_images/notebooks_brainflow_mne_4_2.svg
Out[4]:
../_images/notebooks_brainflow_mne_4_3.svg