BrainflowCyton


NameBrainflowCyton JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryPython wrapper for BrainFlow API + Cyton SDK for collecting realtime or offline (SDCard) EEG, EMG, EKG data.
upload_time2025-10-20 11:49:27
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords biosignals brainflow cyton eeg ekg emg
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BrainflowCytonEEGWrapper

[![Test](https://github.com/zeyus-research/BrainflowCytonEEGWrapper/actions/workflows/test.yml/badge.svg)](https://github.com/zeyus-research/BrainflowCytonEEGWrapper/actions/workflows/test.yml)
[![PyPI version](https://badge.fury.io/py/BrainflowCyton.svg)](https://badge.fury.io/py/BrainflowCyton)
[![Python versions](https://img.shields.io/pypi/pyversions/BrainflowCyton.svg)](https://pypi.org/project/BrainflowCyton/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

This is particularly aimed at the OpenBCI Cyton/Cyton + Daisy biosensing board.

It allows for low-level board commands such as configuring channels and setting sample rate, making it easier to configure the way you retrieve data from the board.

## Status

Fully functional, working with Cyton and Cyton + Daisy.

Todo:
- [ ] Include script to process SDCard data (exists but in a different repo)
- [ ] Make the interface more consistent
- [ ] Bake in multithreading support for easier parallel data collection + processing
- [ ] ???

## Details

Default channels coming in with cyton and daisy with the ultracortex mk4 are:

- 0: "pkg"
- 1: "Fp1"
- 2: "Fp2"
- 3: "C3"
- 4: "C4"
- 5: "P7"
- 6: "P8"
- 7: "O1"
- 8: "O2"
- 9: "F7"
- 10: "F8"
- 11: "F3"
- 12: "F4"
- 13: "T7"
- 14: "T8"
- 15: "P3"
- 16: "P4"
- 17: "AX" (accelerometer x)
- 18: "AY" (accelerometer y)
- 19: "AZ" (accelerometer z)
- 31: "marker" (this can be used to put event markers in the EEG data, which is extremely useful, BUT the accelerometer will be disabled)

## Installation

```bash
pip install BrainflowCyton
```

### Optional: Audio Utilities

If you want to use the Audio class for EEG sonification, install with the `audio` extra:

```bash
pip install BrainflowCyton[audio]
```

This requires PortAudio to be installed on your system:

**macOS:**
```bash
brew install portaudio
```

**Ubuntu/Debian:**
```bash
sudo apt-get install portaudio19-dev
```

**Windows:** PortAudio should be installed automatically with the package.

Or for development:

```bash
git clone https://github.com/zeyus-research/BrainflowCytonEEGWrapper
cd BrainflowCytonEEGWrapper
pip install -e .
```

## Features

- Low-level control of OpenBCI Cyton/Cyton + Daisy boards
- Support for custom sample rates (250Hz - 16kHz)
- SD card recording and real-time streaming
- Channel configuration (gain, input type, bias, SRB settings)
- EMG channel support
- Event markers/tags for experiment synchronization
- Built-in filtering (bandpass, lowpass, 50Hz noise removal)
- Context manager support for automatic resource cleanup
- Type hints for better IDE support
- Comprehensive test suite

## Usage examples

### Read data from a dummy board in real time (recommended pattern)

Using context manager (automatically handles cleanup):

```python
from BrainflowCyton.eeg import EEG
from time import sleep

# Context manager automatically calls prepare() and stop()
with EEG(dummyBoard=True) as eeg:
    eeg.start_stream(sdcard=False)
    while True:
        try:
            sleep(0.5)
            data = eeg.poll()
            print(f"Got {data.shape[1]} samples")
        except KeyboardInterrupt:
            break
```

Or manually managing the connection:

```python
from BrainflowCyton.eeg import EEG
from time import sleep

eeg = EEG(dummyBoard=True)
eeg.start_stream(sdcard=False)

while True:
    try:
        sleep(0.5)
        data = eeg.poll()
    except KeyboardInterrupt:
        eeg.stop()
        break
```

### Read data from a real board in real time

```python
from BrainflowCyton.eeg import EEG
from time import sleep

eeg_source = EEG()
eeg_source.start_stream(sdcard = False)

while True:
  try:
    sleep(0.5)
    data = eeg_source.poll()
  except KeyboardInterrupt:
    eeg_source.stop()
  
```

### Set a custom sample rate

*Note: to use sample rates above 250, an SDCard is required, streaming is limited to 250 Hz.*

```python
from BrainflowCyton.eeg import EEG, CytonSampleRate
from time import sleep

eeg_source = EEG()
eeg_source.start_stream(sdcard = True, sr = CytonSampleRate.SR_1000)

while True:
  try:
    sleep(0.5)
    data = eeg_source.poll()
  except KeyboardInterrupt:
    eeg_source.stop()
  
```

### Enable logging

```python
from BrainflowCyton.eeg import EEG
import logging

# Configure logging before creating EEG object
EEG.configure_logging(level=logging.DEBUG)

with EEG(dummyBoard=True) as eeg:
    eeg.start_stream(sdcard=False)
    # Will now see detailed logs
```

### Bandpass the data

```python
from BrainflowCyton.eeg import EEG, Filtering
from time import sleep

# Set the indexes of channels you want to filter
ch_idx = [1, 2, 3, 4, 5, 6, 7]
eeg_filter = Filtering(exg_channels=ch_idx, sampling_rate=250)

with EEG(dummyBoard=True) as eeg:
    eeg.start_stream(sdcard=False)
    while True:
        try:
            sleep(0.5)
            data = eeg.poll()
            if data is not None:
                # Apply 8-32 Hz bandpass (alpha + beta band)
                filtered_data = eeg_filter.bandpass(data, lowcut=8, highcut=32)
        except KeyboardInterrupt:
            break
```

## Development

### Running tests

```bash
# Install dev dependencies
uv sync --all-extras --dev

# Run tests
uv run pytest tests/ -v
```

### Contributing

Contributions are welcome! Please see [CONTRIBUTING.md](.github/CONTRIBUTING.md) for guidelines.

## CI/CD

This project uses GitHub Actions for continuous integration and deployment:

- **Tests**: Run on every push/PR across Python 3.9-3.13 and Linux/macOS/Windows
- **Pre-releases**: Automatically published to GitHub releases on main branch commits
- **Releases**: Triggered by version tags (e.g., `v0.3.0`), publishes to PyPI

## License

MIT License - see LICENSE file for details

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "BrainflowCyton",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "biosignals, brainflow, cyton, eeg, ekg, emg",
    "author": null,
    "author_email": "zeyus <dev@zeyus.com>",
    "download_url": "https://files.pythonhosted.org/packages/46/87/1f0b274224074956324ef385e686797e773305ded6c081d90eb84ae8dd5f/brainflowcyton-0.2.2.tar.gz",
    "platform": null,
    "description": "# BrainflowCytonEEGWrapper\n\n[![Test](https://github.com/zeyus-research/BrainflowCytonEEGWrapper/actions/workflows/test.yml/badge.svg)](https://github.com/zeyus-research/BrainflowCytonEEGWrapper/actions/workflows/test.yml)\n[![PyPI version](https://badge.fury.io/py/BrainflowCyton.svg)](https://badge.fury.io/py/BrainflowCyton)\n[![Python versions](https://img.shields.io/pypi/pyversions/BrainflowCyton.svg)](https://pypi.org/project/BrainflowCyton/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThis is particularly aimed at the OpenBCI Cyton/Cyton + Daisy biosensing board.\n\nIt allows for low-level board commands such as configuring channels and setting sample rate, making it easier to configure the way you retrieve data from the board.\n\n## Status\n\nFully functional, working with Cyton and Cyton + Daisy.\n\nTodo:\n- [ ] Include script to process SDCard data (exists but in a different repo)\n- [ ] Make the interface more consistent\n- [ ] Bake in multithreading support for easier parallel data collection + processing\n- [ ] ???\n\n## Details\n\nDefault channels coming in with cyton and daisy with the ultracortex mk4 are:\n\n- 0: \"pkg\"\n- 1: \"Fp1\"\n- 2: \"Fp2\"\n- 3: \"C3\"\n- 4: \"C4\"\n- 5: \"P7\"\n- 6: \"P8\"\n- 7: \"O1\"\n- 8: \"O2\"\n- 9: \"F7\"\n- 10: \"F8\"\n- 11: \"F3\"\n- 12: \"F4\"\n- 13: \"T7\"\n- 14: \"T8\"\n- 15: \"P3\"\n- 16: \"P4\"\n- 17: \"AX\" (accelerometer x)\n- 18: \"AY\" (accelerometer y)\n- 19: \"AZ\" (accelerometer z)\n- 31: \"marker\" (this can be used to put event markers in the EEG data, which is extremely useful, BUT the accelerometer will be disabled)\n\n## Installation\n\n```bash\npip install BrainflowCyton\n```\n\n### Optional: Audio Utilities\n\nIf you want to use the Audio class for EEG sonification, install with the `audio` extra:\n\n```bash\npip install BrainflowCyton[audio]\n```\n\nThis requires PortAudio to be installed on your system:\n\n**macOS:**\n```bash\nbrew install portaudio\n```\n\n**Ubuntu/Debian:**\n```bash\nsudo apt-get install portaudio19-dev\n```\n\n**Windows:** PortAudio should be installed automatically with the package.\n\nOr for development:\n\n```bash\ngit clone https://github.com/zeyus-research/BrainflowCytonEEGWrapper\ncd BrainflowCytonEEGWrapper\npip install -e .\n```\n\n## Features\n\n- Low-level control of OpenBCI Cyton/Cyton + Daisy boards\n- Support for custom sample rates (250Hz - 16kHz)\n- SD card recording and real-time streaming\n- Channel configuration (gain, input type, bias, SRB settings)\n- EMG channel support\n- Event markers/tags for experiment synchronization\n- Built-in filtering (bandpass, lowpass, 50Hz noise removal)\n- Context manager support for automatic resource cleanup\n- Type hints for better IDE support\n- Comprehensive test suite\n\n## Usage examples\n\n### Read data from a dummy board in real time (recommended pattern)\n\nUsing context manager (automatically handles cleanup):\n\n```python\nfrom BrainflowCyton.eeg import EEG\nfrom time import sleep\n\n# Context manager automatically calls prepare() and stop()\nwith EEG(dummyBoard=True) as eeg:\n    eeg.start_stream(sdcard=False)\n    while True:\n        try:\n            sleep(0.5)\n            data = eeg.poll()\n            print(f\"Got {data.shape[1]} samples\")\n        except KeyboardInterrupt:\n            break\n```\n\nOr manually managing the connection:\n\n```python\nfrom BrainflowCyton.eeg import EEG\nfrom time import sleep\n\neeg = EEG(dummyBoard=True)\neeg.start_stream(sdcard=False)\n\nwhile True:\n    try:\n        sleep(0.5)\n        data = eeg.poll()\n    except KeyboardInterrupt:\n        eeg.stop()\n        break\n```\n\n### Read data from a real board in real time\n\n```python\nfrom BrainflowCyton.eeg import EEG\nfrom time import sleep\n\neeg_source = EEG()\neeg_source.start_stream(sdcard = False)\n\nwhile True:\n  try:\n    sleep(0.5)\n    data = eeg_source.poll()\n  except KeyboardInterrupt:\n    eeg_source.stop()\n  \n```\n\n### Set a custom sample rate\n\n*Note: to use sample rates above 250, an SDCard is required, streaming is limited to 250 Hz.*\n\n```python\nfrom BrainflowCyton.eeg import EEG, CytonSampleRate\nfrom time import sleep\n\neeg_source = EEG()\neeg_source.start_stream(sdcard = True, sr = CytonSampleRate.SR_1000)\n\nwhile True:\n  try:\n    sleep(0.5)\n    data = eeg_source.poll()\n  except KeyboardInterrupt:\n    eeg_source.stop()\n  \n```\n\n### Enable logging\n\n```python\nfrom BrainflowCyton.eeg import EEG\nimport logging\n\n# Configure logging before creating EEG object\nEEG.configure_logging(level=logging.DEBUG)\n\nwith EEG(dummyBoard=True) as eeg:\n    eeg.start_stream(sdcard=False)\n    # Will now see detailed logs\n```\n\n### Bandpass the data\n\n```python\nfrom BrainflowCyton.eeg import EEG, Filtering\nfrom time import sleep\n\n# Set the indexes of channels you want to filter\nch_idx = [1, 2, 3, 4, 5, 6, 7]\neeg_filter = Filtering(exg_channels=ch_idx, sampling_rate=250)\n\nwith EEG(dummyBoard=True) as eeg:\n    eeg.start_stream(sdcard=False)\n    while True:\n        try:\n            sleep(0.5)\n            data = eeg.poll()\n            if data is not None:\n                # Apply 8-32 Hz bandpass (alpha + beta band)\n                filtered_data = eeg_filter.bandpass(data, lowcut=8, highcut=32)\n        except KeyboardInterrupt:\n            break\n```\n\n## Development\n\n### Running tests\n\n```bash\n# Install dev dependencies\nuv sync --all-extras --dev\n\n# Run tests\nuv run pytest tests/ -v\n```\n\n### Contributing\n\nContributions are welcome! Please see [CONTRIBUTING.md](.github/CONTRIBUTING.md) for guidelines.\n\n## CI/CD\n\nThis project uses GitHub Actions for continuous integration and deployment:\n\n- **Tests**: Run on every push/PR across Python 3.9-3.13 and Linux/macOS/Windows\n- **Pre-releases**: Automatically published to GitHub releases on main branch commits\n- **Releases**: Triggered by version tags (e.g., `v0.3.0`), publishes to PyPI\n\n## License\n\nMIT License - see LICENSE file for details\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python wrapper for BrainFlow API + Cyton SDK for collecting realtime or offline (SDCard) EEG, EMG, EKG data.",
    "version": "0.2.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/zeyus-research/BrainflowCytonEEGWrapper/issues",
        "Homepage": "https://github.com/zeyus-research/BrainflowCytonEEGWrapper",
        "Repository": "https://github.com/zeyus-research/BrainflowCytonEEGWrapper"
    },
    "split_keywords": [
        "biosignals",
        " brainflow",
        " cyton",
        " eeg",
        " ekg",
        " emg"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "09e5211c6badc75056a9b9c729811d2fa1fd8e4f48532e6ff5c3ebf06450ef7d",
                "md5": "034f51af5d3067ce4b8fd5d2f13b8f45",
                "sha256": "eafa311476e5f62f2d7c0071220234f2428ecaae274a869ed9f5209df391979c"
            },
            "downloads": -1,
            "filename": "brainflowcyton-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "034f51af5d3067ce4b8fd5d2f13b8f45",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 11204,
            "upload_time": "2025-10-20T11:49:26",
            "upload_time_iso_8601": "2025-10-20T11:49:26.596134Z",
            "url": "https://files.pythonhosted.org/packages/09/e5/211c6badc75056a9b9c729811d2fa1fd8e4f48532e6ff5c3ebf06450ef7d/brainflowcyton-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "46871f0b274224074956324ef385e686797e773305ded6c081d90eb84ae8dd5f",
                "md5": "033ec4064064872db23bc063d6484819",
                "sha256": "e3048720ee831ae8c32c3f7f5b162a2237216187878c042c51f834e3185030fc"
            },
            "downloads": -1,
            "filename": "brainflowcyton-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "033ec4064064872db23bc063d6484819",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 15415,
            "upload_time": "2025-10-20T11:49:27",
            "upload_time_iso_8601": "2025-10-20T11:49:27.323972Z",
            "url": "https://files.pythonhosted.org/packages/46/87/1f0b274224074956324ef385e686797e773305ded6c081d90eb84ae8dd5f/brainflowcyton-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-20 11:49:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zeyus-research",
    "github_project": "BrainflowCytonEEGWrapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "brainflowcyton"
}
        
Elapsed time: 1.82016s