Real-time processing and plotting of data streamed over LSL, with a focus on student-led BCI projects.
Project description
WizardHat
WizardHat is a library for handling, transforming, and visualizing EEG data streamed from consumer-grade devices over the Lab Streaming Layer (LSL) protocol. WizardHat's purpose is to enable users to easily and flexibly build brain-computer interfaces (BCIs) using a high-level API, with technical details managed in the background. Paired with ble2lsl, WizardHat currently supports streaming from the Muse (2016) brain-sensing headband and the OpenBCI Ganglion. WizardHat is easy to use and only requires three lines of code to get started.
WizardHat was built by Merlin Neurotech at Queen's University.
Note : Active Development
Our dedicated team at Merlin Neurotech is continously working to improve WizardHat and add new functionality. Current on-going projects:
- MNE Library Compatibility
- Implementing simple filters
Check back soon if the feature you are looking for is under development!
Getting Started
The procedure for installing WizardHat depends on whether or not you will be contributing to its development. In either case, begin by creating and activating a new Python virtual environment.
Installing for use only
Simply run
pip install wizardhat
This will automatically install the most recent release of WizardHat along with the required dependencies, including ble2lsl.
Installing for development
To set up WizardHat for development, begin by forking the repository on GitHub, then clone your fork:
git clone https://github.com/<your-github-username>/WizardHat.git
If you are also developing for ble2lsl, fork and then clone the ble2lsl repository as well, and install its dependencies:
git clone https://github.com/<your-github-username>/ble2lsl.git
cd ble2lsl
pip install -e .
cd ..
Whether or not you cloned ble2lsl, install the remaining dependencies for WizardHat:
cd WizardHat
pip install -e .
The last command creates an editable install of WizardHat; i.e. after installation into an active virtual environment, running import wizardhat
in any Python terminal/script will import the current (i.e. working) version of the modules from your fork's folder.
Finally
To ensure a bug free experience, open [your virtual env name]/lib/python3.6/site packages/pygatt/backends/bgapi/bgapi.py in a text or code editor and add:
time.sleep(0.25)
between line 200 and 201 and save the file. This ensures that the Bluetooth protocol will be given adequate time to connect to the Muse before timing out.
Now you are ready to use WizardHat!
Working with WizardHat
Our library provides two options when building, debugging, or testing your BCI code:
- Streaming data from Muse or other EEG device
- Streaming randomly generated data for testing and debugging
To begin streaming, you will need first to import ble2lsl
and wizardhat.acquire
into your Python workspace. The BLE device parameters for different devices are stored in respective modules in ble2lsl.devices
.
import ble2lsl
from ble2lsl.devices import muse2016
from wizardhat import acquire
You then need to create a streaming outlet which establishes a Bluetooth connection with the EEG device:
streamer = ble2lsl.Streamer(muse2016)
To stream dummy data through an outlet that mimics (number of channels, sample rate, and metadata) the Muse 2016:
dummy_streamer = ble2lsl.Dummy(muse2016)
Next, to store and record the data, add the following line to capture the outlet stream:
receiver = acquire.Receiver()
Notice how you do not need to pass the outlet streamer as an argument to this function. LSL can stream over a local network, and ble2lsl
doesn't need to run in the same process as wizardhat
. Instead, Receiver
automatically finds and connects to the LSL outlet; if multiple outlets are available, it will prompt you to choose from a list.
Now that your streamer is receiving data, you can visualize and manipulate it online. Data is streamed into structured arrays with timestamps in their first columns and channel data in their remaining columns. By default, these arrays contain the last 10 s (to the nearest sample) of streamed data, and are accessed through the streamer.buffers
dictionary. For example, the structured array of most recent timestamps and samples for the Muse 2016's EEG stream (labeled "EEG") is accessed by:
streamer.buffers["EEG"].data
The available streams depend on the device, and are specified in the device's module in ble2lsl.devices
. For example, the Muse 2016 headband provides the following stream types: "EEG", "accelerometer", "gyroscope", "telemetry", and "status". After each time window, data is saved to a CSV file in your directory under a folder called 'data' and is constantly updated while your stream is running. Each data buffer has an associated CSV file, accompanied by a JSON file of the same name providing metadata.
To gain a deeper understanding into how our framework operates, take a look under the hood.
Acknowledgements
This project was inspired by Alexander Barachant's muse-lsl from which some of the modules were originally based. The device specification for the OpenBCI Ganglion is largely derived from OpenBCI_Python.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file WizardHat-0.2.1.tar.gz
.
File metadata
- Download URL: WizardHat-0.2.1.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 508c7c8e8e171c3f09ea7b2451de2eeb847aea91bcec4a11d2a21b7c4a012bed |
|
MD5 | 230067e9aa10e5536fdd2200c0ed22bb |
|
BLAKE2b-256 | b1b50fdffa10d2fe7b054c2f41266479191b70be68cc8643badd4294353281f2 |
File details
Details for the file WizardHat-0.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: WizardHat-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d266c1eb2e5ba6d59a6235cbfbc1c683fb0d013654adf1e41513453bc76f3d5 |
|
MD5 | 87db9e63288b35c30690e7934c96d2a2 |
|
BLAKE2b-256 | 5c6fc0f34bfc3b29fc2b5f2c2b8a26e4ee0562e586fa63f968de6db9fba1bacf |