Skip to main content

Library for live and offline denoising of multi-channel EEG data powered by auto-encoders, created by Synaptrix Labs Inc.

Project description

Synaptrix

A library for live and offline denoising of multi-channel EEG data powered by auto-encoders, created by Synaptrix Labs Inc. This README covers how to prepare LabStreamingLayer (LSL) for your platform, and how to install and initialize the SynaptrixClient.

Table of Contents

Overview

Synaptrix provides a convenient Python API for EEG denoising using your own model or pre-trained models. It also integrates with LabStreamingLayer (LSL) for real-time data acquisition. To use LSL functionality, you must first install the native LSL libraries on your system (see Prerequisites).

Prerequisites

Install LSL on macOS

  1. Ensure you have Homebrew installed.
  2. Run:
    brew install labstreaminglayer/tap/lsl
    

This installs the native LSL libraries that pylsl depends on.

Install LSL on Windows

  1. Visit the official LSL Windows Installation Docs
  2. Download the appropriate installer/zip.
  3. Follow instructions to install the .dlls so that pylsl can detect them.

Install LSL on Linux

  1. Ubuntu/Debian (example):
    sudo apt-get update
    sudo apt-get install cmake build-essential
    git clone https://github.com/sccn/labstreaminglayer.git
    cd labstreaminglayer/LSL
    # Then follow build instructions from the official docs
    

Installation

After installing the native LSL libraries for your platform, you can install Synaptrix:

    pip install synaptrix

Usage

Initialize SynaptrixClient

    from synaptrix import SynaptrixClient
    import pandas as pd

    # Initialize the client
    client = SynaptrixClient(
        API_KEY="YourAPIKey"
    )

After initializing the client, you can then access all the functions of synaptrix.

Our model works best with filtered and normalized data. If your data is not preprocessed don't worry! The library will apply a notch filter at 50 and 60hz (powerline), a bandpass filter from 1-100hz, and normalize your data by default.

Here is an example of how you can denoise a csv file called data.csv. Let's say the columns you want to denoise has indices [1,2,5,7], you want to skip the first 2 rows of data because they contain header data, the column with index 0 contains datetime data, your data is at 512hz, and you want to output a df:

    data_in = pd.read_csv("data.csv")
    
    denoised = client.denoise_batch(
        data_in,
        data_columns=[1,2,5,7],
        skip_rows=2,
        datetime_column=0,
        sample_rate=512,
        output_format="df") 
    
    print("Denoised Data: ", denoised)

Now let's say you have a dataset that is already filtered and normalized. Set the filter and normalize parameters to False first. Now let's say you want to denoise columns with indices [4,6,7], you want to skip no rows of data, the datetime column has index 3, and you want to output a csv called "denoised_data.csv":

    data_in = pd.read_csv("data.csv")
    
    client.denoise_batch(
        data_in,
        normalize=False,
        data_columns=[4,6,7],
        filter=False,
        skip_rows=0,
        datetime_column=3,
        sample_rate=512,
        output_format="csv",
        file_name="denoised_data.csv") 

You can also customize the placement of the notch and bandpass filters. Just keep in mind that any filter must be less than half of your sampling rate. If the data has a sampling rate of 200hz, the highest filter you can apply is 99hz:

    data_in = pd.read_csv("data.csv")
    
    client.denoise_batch(
        data_in,
        data_columns=[4,6,7],
        datetime_column=3,
        sample_rate=512,
        notch_freqs=[45,70],
        low_freq=15,
        high_freq=75,
        output_format="csv",
        file_name="denoised_data.csv")

Here is an example of how you can generate a plot of the denoised data:

    data_in = pd.read_csv("data.csv)
    client.plot_denoised(
        data_in,
        data_columns=[4,6,7], #remove this parameter to plot all columns
        datetime_column=3,
        sample_rate=512,
        initial_window_sec=2)
    
    # initial_window_sec dictates how wide is the sliding viewing window

Here is an example of how to stream data through lsl into synaptrix and output denoised data:

    lsl_output = client.lsl_denoise(
        stream_duration = 10, # in seconds, change parameter to 0 for indefinite streaming
        num_channels = 4,
        sample_rate = 512, # adjust to match sampling rate of your device
        output_format = "csv",
        file_name = "denoised_lsl.csv") 
        
    # at the conclusion of the stream, all denoised data will be saved to this file

License

This project is licensed under the Apache 2.0 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

synaptrix-1.2.0.tar.gz (5.0 MB view details)

Uploaded Source

Built Distribution

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

synaptrix-1.2.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file synaptrix-1.2.0.tar.gz.

File metadata

  • Download URL: synaptrix-1.2.0.tar.gz
  • Upload date:
  • Size: 5.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for synaptrix-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d61b7f64d28d0ca382309e0ac28888fe459035d2d5d4c59b79d4bebe0cf8c3e1
MD5 54e80b240b7edafc323a1de04b574073
BLAKE2b-256 37252cb7d7bcd9210219a2127295e35ac04b2596bb063326f690ee7aded61656

See more details on using hashes here.

File details

Details for the file synaptrix-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: synaptrix-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for synaptrix-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d679a6851b9b02c1cc6f43aec2301b1f1b6853231a2b47f25e4fbcb68fad018
MD5 e7345ec74fdbcc64a4b5dac1e94c3d88
BLAKE2b-256 1b9659bc8fca898bfc2a22725d31eff5b3b5dac21e16f2efa7ea203967e0948a

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