carmenalab / brain-python-interface

Other
6 stars 8 forks source link

brain-python-interface (a.k.a. bmi3d)

This the python 3 branch. It has not been as extensively tested as the python 2 version on the master branch. However, the python 2 version is no longer being actively maintained.

This package contains Python code to run electrophysiology behavioral tasks, with emphasis on brain-machine interface (BMIs) tasks. This package differs from other similar packages (e.g., BCI2000--http://www.schalklab.org/research/bci2000) in that it is primarily intended for intracortical BMI experiments.

This package has been used with the following recording systems:

Code documentation can be found at http://carmenalab.github.io/bmi3d_docs/

Getting started

Dependencies

Ubuntu

sudo xargs apt-get -y install < requirements.system

Windows

Visual C++ Build tools (for the 'traits' package)

Installation

This package depends on many other python packages and is sensitive to the version numbers of some of those dependencies. For that reason, it is recommended that you install into a virtual environment to isolate the python packages for bmi3d from the rest of your system python use:

git clone -b develop https://github.com/carmenalab/brain-python-interface.git
cd brain-python-interface
python3 -m venv env                 # create virtual environment for python package isolation
source env/bin/activate             # open virtual environment
pip install -r requirements.txt
pip install -e .                    # install in editable mode. Now 'git pull' updates in this directory will automatically propagate to the installation
deactivate                          # exit virtual environment

OS X

After installing the main requirements, you also need to install pygame

source env/bin/activate             # open virtual environment
pip instal -r requirements_osx.txt
deactivate                          # exit virtual environment

Installation in Docker

Graphics generation from inside the image has only been tested in Ubuntu. To test, load the image using run_docker.sh and

cd /src/tests/unit_tests/
python3 test_built_in_vfb_task.py

If successful, you'll see the pygame window pop up looking like a poorly-made video game. If unsuccessful, you'll see the graphics in the terminal itself in ASCII art.

Setting up the database

cd db
touch db.sql                   # Make empty file for database
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py makemigrations tracker
python3 manage.py migrate                  # make sure to do this twice!

Start server

python3 manage.py runserver

Setup paths and configurations

Once the server is running, open up Chrome and navigate to localhost:8000/setup

Run a task

Navigate to http://localhost:8000/exp_log/ in chrome. Then press 'Start new experiment' and run your task.

Remote access

On Ubuntu, use the ufw package to open the port that Django is using

sudo ufw allow 8000/tcp
sudo ufw allow ssh
sudo ufw enable    # this is needed even if raspi-config enables SSH

Then start the server with

python3 manage.py runserver 0.0.0.0:8000

Remote access

On Ubuntu, use the ufw package to open the port that Django is using

sudo ufw allow 8000/tcp
sudo ufw allow ssh
sudo ufw enable    # this is needed even if raspi-config enables SSH

Then start the server with

python3 manage.py runserver 0.0.0.0:8000

Troubleshooting

This package has a lot of dependencies which makes installation somewhat brittle due to versions of different dependencies not getting along.

Running javascript tests

Javascript tests require the qunit library. To run the tests from the browser, open up db/html/static/resources/js/qunit.html in your browser of choice for running experiments.

If you are developing in javascript, you may want to run the tests from the command line. To install the qunit command-line setup, execute as root

cd db/html/static/resources/js
apt install npm
npm install -g qunit
npm install jquery
npm install jsdom

Then run qunit to run the tests in the test folder.

Papers which have used this package