Skip to main content

Python package to record and analyse data from OpenBCI boards

Project description

electrography

This Python package is intended for use with OpenBCI boards and/or their data. You can use it to stream data from any of the OpenBCI boards, add triggers to data files, and to analyse the results.

Dependencies

Citation

A tutorial paper associated with this package will be made available soon. Please cite this if you use electrography in your work.

  • Citation to follow!

Example Data Acquisition

import time
from electrography.boards import OpenBCI

# Create a new OpenBCI instance, in this example for a Ganglion board.
# Note that the `serial_port` address may be different on your system!
board = OpenBCI("ganglion", serial_port="/dev/ttyACM0", \
    log_file="example_egg.tsv")

# Stream for 30 seconds, sending a trigger after 1 second.
board.start_stream()
time.sleep(1)
board.trigger(200)
time.sleep(29)
board.stop_stream()

# Close the connection
board.close()

Example Data Analysis

from openbci.data import read_file, get_physiology, hampel, \
    butter_bandpass_filter, movement_filter

# Set the low (high-pass) and high (low-pass) bounds for the data (EGG). For 
# electrogastrography, you'd typically use 0.5-10 cycles per minute (cpm), i.e.
# 0.0083-0.17 Herz (Hz).
low_bound = 0.0083
high_bound = 0.17

# Define the normogastric band (2-4 cpm, i.e. 0.033-0.067 Hz) and main 
# frequency (3 cpm, i.e. 0.05 Hz).
normogastric_freq = 0.05
normogastric_band = [0.033, 0.067]

# Load the data from a file at `fpath`.
raw = read_file(fpath)
data, t, triggers, sampling_rate = get_physiology(raw, "ganglion")

# Mean-centre the data.
m_per_channel = numpy.nanmean(data, axis=1, keepdims=True)
data = data - m_per_channel

# Hampel-filter the data.
data = hampel_filter(data, k=2000, n_sigma=3)

# Filter the data for EGG frequencies.
for channel in range(data.shape[0]):
    data[channel,:] = butter_bandpass_filter(data[channel,:], \
        low_bound, high_bound, sampling_rate, bidirectional=True)

# Employ a movement filter for frequencies below the normogastric frequency.
data, noise = movement_filter(data, sampling_rate, normogastric_freq)

# Perform ICA denoising on the data, using the normogastric band.
data = ica_denoise(data, sampling_rate, low_bound, high_bound, \
    normogastric_band, snr_threshold=3.0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

electrography-1.1.1.tar.gz (50.9 kB view details)

Uploaded Source

File details

Details for the file electrography-1.1.1.tar.gz.

File metadata

  • Download URL: electrography-1.1.1.tar.gz
  • Upload date:
  • Size: 50.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for electrography-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ab3693ffe0421f1dacf26f03fd85c4719ef6d29c512cf7b145498f80ed7c4f8c
MD5 a36fbaa7518806fd6d6fb64d89695ff5
BLAKE2b-256 97e04f7cefe3ebc53876d06578d7fb41949fb7b9a18d2aa4ea7106405f91d049

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page