Skip to main content

Librería modular para adquisición y procesamiento EEG de UHB

Project description

💻🧠🦄 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.

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

eeg_uhb-0.1.9.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eeg_uhb-0.1.9-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file eeg_uhb-0.1.9.tar.gz.

File metadata

  • Download URL: eeg_uhb-0.1.9.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for eeg_uhb-0.1.9.tar.gz
Algorithm Hash digest
SHA256 7956f68f9c3487d7b62dafe0489ed3ca258c99de1dc2313b06c108e45343cc31
MD5 e9de83bb154911973501e4933953fe24
BLAKE2b-256 67ba74cc11c74338470b70bc0b7f36d1f1b5c6a69d3c4c00d306cc92c1484797

See more details on using hashes here.

File details

Details for the file eeg_uhb-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: eeg_uhb-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for eeg_uhb-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ac438b2d70b885a697b860eed4a814bc08526630cf4258c20a7d1e68584527e0
MD5 3b7151512b4d8f9fbc46d604c0cf40bb
BLAKE2b-256 65da46516ab145feb853f22a0865496380546e4d9f3bd4ede2e4a36f97139f62

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