brainaccess.utils.acquisition#

Attributes#

Classes#

EEG

EEG acquisition class.

EEGData

Object to store EEG data in accumulation mode

EEGData_roll

Data structure to store rolling EEG data buffer

Module Contents#

class brainaccess.utils.acquisition.EEG(mode='accumulate')[source]#

EEG acquisition class. Gathers data from brainaccess core and converts to MNE structure.

Creates EEG object and initializes device with default parameters.

Parameters:

mode (str) – Data storage modes accumulate (all data is accumulated in array) or roll (only last x seconds preserved)

annotate(msg)[source]#

Adds an annotation to the data stream. :param msg: annotation to send :type msg: str

Parameters:

msg (str)

Return type:

None

calc_impedances(tim=4)[source]#

Calculate impedance in last tim seconds Impedance calculated as in https://openbci.com/community/openbci-measuring-electrode-impedance/

Parameters:

tim (float) – Last x seconds in acquisition to get average impedance from

Returns:

Impedances

Return type:

list

close()[source]#

Close device connection.

get_annotations()[source]#

Returns annotations from the data stream.

Return type:

dict

get_battery()[source]#

Returns battery level in percent.

Return type:

int

get_mne(tim=None, samples=None, annotations=True)[source]#

Return MNE structure. If tim is None, returns all data; otherwise, returns the last tim seconds.

Parameters:
  • tim (float, optional) – Time in seconds.

  • samples (int, optional) – Number of samples.

  • annotations (bool) – Whether to include annotations.

Returns:

Raw MNE EEG data structure.

Return type:

mne.io.BaseRaw

setup(mgr, device_name, cap={0: 'F3', 1: 'F4', 2: 'C3', 3: 'C4', 4: 'P3', 5: 'P4', 6: 'O1', 7: 'O2'}, zeros_at_start=0, bias=None, gain=8, sfreq=250)[source]#

Connects to device and sets channels

Parameters:
  • mgr (EEGManager) – The EEG manager object.

  • device_name (str) – The name of the device to connect to.

  • cap (dict) – A dictionary mapping electrode numbers to channel names.

  • zeros_at_start (int) – The number of zeros to add at the beginning of the data.

  • bias (list, optional) – A list of channels to use for bias.

  • gain (int) – The gain to use for the EEG channels.

  • sfreq (int)

Raises:

BrainAccessException – If no devices are found, could not connect to the device, or the stream is incompatible.

Return type:

None

start_acquisition()[source]#

Starts streaming and collecting data.

start_impedance_measurement()[source]#

Starts impedance measurement.

stop_acquisition()[source]#

Stops the data acquisition stream.

stop_impedance_measurement()[source]#

Stops impedance measurement.

bias_channels: list | None = None[source]#
directory[source]#
eeg_channels: dict[source]#
gain: brainaccess.core.gain_mode.GainMode[source]#
impedances: dict[source]#
mode: str = 'accumulate'[source]#
time_step: float = 0.5[source]#
wait_max: int = 2[source]#
class brainaccess.utils.acquisition.EEGData(info, lock, zeros_at_start=2)[source]#

Object to store EEG data in accumulation mode

Initializes the EEGData object.

Parameters:
  • info (mne.Info) – The MNE info object.

  • lock (threading.Lock) – The threading lock.

  • zeros_at_start (int, optional) – The number of zeros to add at the beginning of the data, by default 2.

convert_to_mne(tim=None, samples=None, annotations=True, channels_indexes=None)[source]#

Convert arrays to MNE. If tim None returns all data from acquisition start. Otherwise last tim seconds

Parameters:
  • tim (float, default value = None) – time in seconds till the end to include in the output

  • samples (int, default value = None) – time in samples till the end to include in the output

  • annotations (bool, default value = True) – should annotations be included

  • channels_indexes (list, optional) – A list of channel indexes to include.

load(fname)[source]#

Loads raw data from a file.

Parameters:

fname (str) – The name of the file to load.

save(fname)[source]#

Saves the raw data to a file. :param fname: filename to save data to :type fname: str

Parameters:

fname (str)

annotations: dict[source]#
connectivity: list = [][source]#
data: list[source]#
eeg_info: mne.Info[source]#
lock[source]#
mne_raw: mne.io.BaseRaw[source]#
zeros_at_start = 2[source]#
class brainaccess.utils.acquisition.EEGData_roll(info, lock, zeros_at_start=1)[source]#

Data structure to store rolling EEG data buffer

Initializes the EEGData_roll object.

Parameters:
  • info (mne.Info) – The MNE info object.

  • lock (threading.Lock) – The threading lock.

  • zeros_at_start (int, optional) – The number of zeros to add at the beginning of the data, by default 1.

Raises:

BrainAccessException – If no lock is passed.

convert_to_mne(tim=None, samples=None, annotations=True, channels_indexes=None)[source]#

Convert arrays to MNE. If tim None returns all data from acquisition start. Otherwise last tim seconds

Parameters:
  • tim (float, default value = None) – time in seconds or samples to cut

  • samples (int, default value = None) – samples or time to cut

  • annotations (bool, default value = True) – should annotations be included

  • channels_indexes (list, optional) – A list of channel indexes to include.

load(fname)[source]#

Loads raw data from a file.

Parameters:

fname (str) – The name of the file to load.

save(fname)[source]#

Saves the raw data to a file. :param fname: filename to save data to :type fname: str

Parameters:

fname (str)

annotations: dict[source]#
chans[source]#
connectivity: list = [][source]#
data[source]#
eeg_info: mne.Info[source]#
lock[source]#
mne_raw: mne.io.BaseRaw[source]#
zeros_at_start = 1[source]#
brainaccess.utils.acquisition.BOARD_RESISTOR_OHMS = 4700.0[source]#
brainaccess.utils.acquisition.IMPEDANCE_DRIVE_AMPS = 6e-09[source]#