brainsatplay.py
A Python library for interfacing with Brains@Play
Installation
pip install brainsatplay
Example (with Brainflow)
import brainsatplay
import time
import math
from brainflow.board_shim import BoardShim, BrainFlowInputParams, LogLevels, BoardIds
from brainflow.data_filter import DataFilter, FilterTypes
import sys, signal
def main():
'''
Connect to the Brainstorm
'''
# Authentication
username = 'guest'
password = ''
## Set Connection Details
brainstorm = brainsatplay.Brainstorm('http://localhost','80') # URL, Port
## Connect
res = brainstorm.connect(username,password) # All optional (defaults to guest)
'''
Subscribe to a Particular Game
'''
# # Connection Settings
appname = 'brainstorm'
devices = []
props = ['raw','times','sps','deviceType','format','eegChannelTags']
sessionid = None
spectating = False # Spectate to view data without sending it
res = brainstorm.getSessions(appname)
if res['msg'] != 'appNotFound':
sessionid = res['sessions'][0]['id']
else:
res = brainstorm.createSession(appname, devices, props)
sessionid = res['sessionInfo']['id']
# Handle Data from Subscribed Games
def newData(json):
for user in json['userData']:
name = user['username']
print('Data for {}'.format(name))
res = brainstorm.subscribeToSession(sessionid,spectating, newData)
'''
Stream your Data
'''
# Setup Brainflow
params = BrainFlowInputParams()
board_id = BoardIds['SYNTHETIC_BOARD'].value
board = BoardShim(board_id, params)
board.rate = BoardShim.get_sampling_rate(board_id)
board.channels = BoardShim.get_eeg_channels(board_id)
board.time_channel = BoardShim.get_timestamp_channel(board_id)
board.eeg_channels = BoardShim.get_eeg_channels(board_id)
board.eeg_names = BoardShim.get_eeg_names(board_id)
board.prepare_session()
board.start_stream(num_samples=450000)
# Handle CTRL-C Exit
def onStop():
board.stop_stream()
board.release_session()
loopCount = 0
# Start Stream Loop
def streamLoop():
pass_data = []
rate = DataFilter.get_nearest_power_of_two(board.rate)
data = board.get_board_data()
t = data[board.time_channel]
data = data[board.eeg_channels]
for entry in data:
pass_data.append((entry).tolist())
data = {}
data['raw'] = pass_data
data['times'] = t.tolist()
# Send Metadata on First Loop
if loopCount == 0:
data['sps'] = board.rate
data['deviceType'] = 'eeg'
data['format'] = 'brainflow'
tags = []
for i, channel in enumerate(board.eeg_channels):
tags.append({'ch': channel-1, 'tag': board.eeg_names[i], 'analyze':True})
data['eegChannelTags'] = tags
return data
res = brainstorm.startStream(streamLoop, onStop)
if __name__ == "__main__":
main()
Support
If you are having issues, please email Garrett Flynn at gflynn@usc.edu
Metadata
Release files for brainsatplay 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| brainsatplay-0.1.2.tar.gz | 4.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| brainsatplay-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / brainsatplay-0.1.2.tar.gz
| Download URL | brainsatplay-0.1.2.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b56a7ca0dfe93dd489a192ba5aaae121d7f3fbc6d8238c7e197c337d7bacef19
|
|
BLAKE2b-256 checksum How to use checksums |
50877915cbe3e06af704b31d5ccae58336d1b69017efabb9ad310dd000e8c120
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.10
|
Release files / brainsatplay-0.1.2-py3-none-any.whl
| Download URL | brainsatplay-0.1.2-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac4f8d1963b2d486d08084e70c87acc547481a0a37e7cae0b2e7f53a427f2916
|
|
BLAKE2b-256 checksum How to use checksums |
3dd78ae680a62447b789b4c6b7e40c3ea01ff40209c3402d8596ce7b3e33258e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.10
|
Security for brainsatplay 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.