Skip to main content

💻🧠🦄 EEG_UHB

Library for Electroencephalography (EEG) signal acquisition and processing using Unicorn Hybrid Black (UHB) commercial equipment using Lab Streaming Layer (LSL).

📑 Contents

⏬ Install

Welcome to the installation guide for the EEG UHB Library! Whether you're setting up a controlled virtual environment or installing system-wide, follow these steps to get started quickly. For optimal compatibility and to avoid conflicts with other Python packages, we strongly recommend using a virtual environment. Also, it is necessary to have the UHB software, see “Dependencies” section.

🐍 Installation in a Python virtual environment

  1. Open a terminal or Anaconda Prompt.
  2. Create a new virtual environment (for example: myenv):
  • Using a Command Prompt (Windows/Linux/Mac):
python -m venv myenv
  • Using Anaconda Prompt:
conda create --name myenv
  1. Enable the virtual environment:
  • Windows:
myenv\Scripts\activate
  • Anaconda Prompt:
conda activate myenv
  • macOS/Linux:
source myenv/bin/activate
  1. Install the library inside the virtual environment:
pip install eeg-uhb

🔽 Install on the whole system

You can install the library directly from PyPI using pip:

pip install eeg-uhb

:octocat: Installation from GitHub (optional)

If you want to install the latest version directly from the repository, run:

pip install git+https://github.com/IngAmaury/EEG_UHB_LIBRARY.git

[!NOTE] You should install it in a virtual environment to avoid conflicts with other system libraries. If you do not know the procedure to do it in a virtual environment go back to the “Installation in a Python virtual environment” section.

🔨 Dependencies

The library requires the following dependencies, which will be installed automatically with pip:

  • numpy
  • pylsl
  • scipy
  • scikit-fuzzy

🔻🔻🔻

[!IMPORTANT] If you want to make the acquisition with Unicorn Hybrid Black you need to install Unicorn Suite Hybrid Black, You can also watch their video tutorial. Within the application, you will need to install the Unicorn Recorder from the Apps section or the Unicorn LSL from the DevTools section.

🔺🔺🔺

🔄 Upgrade or uninstall

Already had an older version of the library, you can updated to the latest version with the code:

pip install --upgrade eeg-uhb

If you no longer wish to have the library installed, activate the virtual environment where you installed it and run it:

pip uninstall eeg-uhb -y

🎯 Use example

If you are acquiring through the Unicorn LSL Interface, see the image below, you can use the example code below the image, you must put in the start_adquisition function in the stream_name attribute the same name that you put in the “Streamname” box inside the LSL settings of the Unicorn LSL.

[!TIP] If you have never used the Unicorn LSL Interface before, we recommend that you read its user documentation.

Unicorn Hybrid Black acquisition tool using LSL protocol

from eeg_uhb import EEGAcquisitionManager
import time

if __name__=='__main__':
    EEG = EEGAcquisitionManager()
    start_time = time.time()
    duration = 0.04  # segundos

    '''
    # Connect to any available stream without saving
    eeg.start_acquisition(stream_name='UN-2023.07.40')  

    # Connect to specific stream and save data
    eeg.start_acquisition(stream_name='UN-2023.07.40', 
                        save=True,
                        save_path='./eeg_data/')
    '''
    
    # the stream_name depends on the one you choose
    EEG.start_acquisition(stream_name='UN-2023.07.40', save=True)
    start = time.sleep(duration)
    print(EEG.data)
    print(f'Length: {len(EEG.data)}')
    EEG.stop_acquisition()

If you are acquiring through the Unicorn Recorder App, see the image below, you can use the example code below the image, you must not put anything in start_acquisition in the stream_name attribute as the app assigns one internally, the other attributes can be used as normal.

Unicorn Recorder App acquisition tool

from eeg_uhb import EEGAcquisitionManager
import time

if __name__=='__main__':
    EEG = EEGAcquisitionManager()
    start_time = time.time()
    duration = 0.04  # segundos

    '''
    # Connect stream and save data
    eeg.start_acquisition(save=True, save_path='./eeg_data/')
    '''
    
    # the stream_name depends on the one you choose
    EEG.start_acquisition()
    start = time.sleep(duration)
    print(EEG.data)
    print(f'Length: {len(EEG.data)}')
    EEG.stop_acquisition()

⚙🧠 Class EEGAcquisitionManager

Initializes the EEG acquisition system.

from eeg_uhb import EEGAcquisitionManager

eeg = EEGAcquisitionManager()

🔷 Class attributes

Attributes Type Description
channels float Number of channels in the acquisition.
data list Raw EEG samples in format [[first samples per channel], [Second samples per channel], ...].
fs float Sampling frequency value
headers list List of headers for all possible channels of the 8-channel Unicorn Hybrid Black.
is_recording bool True during acquisition.
sample_count int Number of samples acquired.
start_time float Time from the beginning of the acquisition in UTC format.
timestamps list List of temporary marks by sample list (relative time in utc format).

🟢 Class Methods

Methods within EEGAcquisitionManager Class.

🔵 resolve_eeg_stream(name = None, timeout = 1)

Static method that searches and resolves an EEG data stream available through the Lab Streaming Layer (LSL) protocol.

Parameters:

  • name (None | str): Specific name of the EEG stream to search for. If None, it will search by default for a stream of type EEG.
  • timeout (float): Maximum waiting time (in seconds) to resolve the flow (default: 1).

Return:

  • Returns the EEG stream found or an empty list if none is found.

Example:

from eeg_uhb import EEGAcquisitionManager

stream = EEGAcquisitionManager.resolve_eeg_stream()

🔵 start_acquisition(stream_name = None, save = False, save_path = None)

Starts EEG data acquisition.

Parameters:

  • stream_name (None | str): Tag that identifies an LSL data stream. (default: None).
  • save (bool): If True, saves the data in save_path, otherwise it creates a “Data” folder in the current project. (default: False)
  • save_path (None | str): If True, serves as path to store the data (default: None).

Return:

  • True if the acquisition was started correctly, otherwise False.

Example:

eeg.start_acquisition(
    save=True,
)

🔵 stop_acquisition()

Stops the acquisition and closes open files.

Example:

# it is necessary to have used before: start_acquisition()
eeg.stop_acquisition(
    save=True,
)

📜 License

This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
See the LICENSE file for details.

Metadata

Release files for eeg-uhb 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eeg-uhb 0.1.9
File Size Uploaded
eeg_uhb-0.1.9.tar.gz 43.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eeg-uhb 0.1.9
File Interpreter ABI Platform
eeg_uhb-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 81.3 kB

Release files / eeg_uhb-0.1.9.tar.gz

Download URL eeg_uhb-0.1.9.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7956f68f9c3487d7b62dafe0489ed3ca258c99de1dc2313b06c108e45343cc31
BLAKE2b-256 checksum
How to use checksums
67ba74cc11c74338470b70bc0b7f36d1f1b5c6a69d3c4c00d306cc92c1484797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / eeg_uhb-0.1.9-py3-none-any.whl

Download URL eeg_uhb-0.1.9-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac438b2d70b885a697b860eed4a814bc08526630cf4258c20a7d1e68584527e0
BLAKE2b-256 checksum
How to use checksums
65da46516ab145feb853f22a0865496380546e4d9f3bd4ede2e4a36f97139f62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page