GithubHelp home page GithubHelp logo

ds7711 / rteeg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kaczmarj/rteeg

0.0 2.0 0.0 1.06 MB

Python module to stream and analyze EEG data in real-time

License: MIT License

Shell 1.35% Python 98.65%

rteeg's Introduction

Real-Time EEG

Build Status Code Coverage

rteeg provides the infrastructure to access EEG data in Python in real-time. The package uses LabStreamingLayer to stream EEG data and event markers and MNE-Python to analyze data. TCP/IP will be supported soon.

How it works

rteeg connects to a LabStreamingLayer (LSL) stream of raw EEG data or event markers and records the data being transmitted. The EEG data can then be analyzed in real-time in chunks with an analysis workflow provided by the user. The analysis workflow can be triggered whenever a buffer of a user-defined size becomes full, and visual feedback can be provided using HTML and CSS.

How to use it

To connect to a LabStreamingLayer (LSL) stream of EEG data, create an instance of the class EEGStream. The EEG system being used must be specified in the eeg_system argument. The program will search for a stream that matches the predicate default_predicates.eeg[`eeg_system`]. Predicates must be written in XML Path Language and can be added or removed to suit the user's needs.

Once connected to an EEG stream, data can be converted to mne.Raw or mne.Epochs objects with methods make_raw() and make_epochs(), respectively. A stream of event markers is required to make an mne.Epochs object. Connect to a LSL stream of event markers by creating an instance of the class MarkerStream.

Independent Component Analysis

It is also possible to use Independent Component Analysis (ICA) to remove artifacts each time data is retrieved. The ICA solution must first be computed (a.k.a. "fit") on some data, and components must be selected for removal. Use the method EEGStream.fit_ica() to fit the ICA. This returns an mne.preprocessing.ICA object, which is stored in EEGStream.ica. Plot the sources of the ICA using EEGStream.viz_ica(), and select the components that should be removed. If the ICA object has been fit and components have been selected for removal, these components will be removed from incoming data when using EEGStream.make_raw().

Looping analysis

A function can be called each time a buffer of EEG data increases by a user-defined amount.

Saving data

To save the data at the end of the recording session, use make_raw().save(fname), where fname is the filename. This saves the EEG data as a FIF file. If an instance of MarkerStream is supplied, events should be present in the EEG data.

How to use it if you don't have an EEG cap

Included in this repo is a script that transmits synthetic EEG data over a LabStreamingLayer stream. Simply run that file (python send_eeg_data.py in a terminal) in order to try rteeg. Event markers can be sent by running the file send_markers.py in the same directory.

How to save fitted models

Fitted machine learning models should be included in a dictionary that also includes important information about that model. The information included in the dictionary is very important because the number of features in the training set must be equal to the number of features in the testing set. Seemingly minor differences between the processing steps of training and testing sets could result in unequal numbers of features. The dictionary can look like this:

clf_dictionary = {
    'paradigm' : "In inattention condition, subjects looked at a crosshair. "
                 "In attention, subjects played sudoku.",
    'processing': "Data were FIR filtered (0.5 to 40 Hz), and "
                  "artifacts were removed with ICA. Power "
                  "spectral density was computed (0.5 to 7.0 Hz), and PCA "
                  "(15 components) was computed on the power. The output "
                  "of PCA served as the features for the model.",
    'n_samples_for_training' : 65,
    'n_features': 15,
    'classifier' : ExtraTreesClassifier(),  # Fitted model here.
}

The dictionary should be saved to a JSON file. Pickling the dictionary is discouraged because of the instability and security risks of pickle files.

rteeg's People

Contributors

kaczmarj avatar

Watchers

James Cloos avatar Mingwen Dong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.