Open source modules for tracking animal behavior and closed-loop stimulation based on Open Ephys and Bonsai

J Neural Eng. 2018 Oct;15(5):055002. doi: 10.1088/1741-2552/aacf45. Epub 2018 Jun 27.


Objective: A major goal in systems neuroscience is to determine the causal relationship between neural activity and behavior. To this end, methods that combine monitoring neural activity, behavioral tracking, and targeted manipulation of neurons in closed-loop are powerful tools. However, commercial systems that allow these types of experiments are usually expensive and rely on non-standardized data formats and proprietary software which may hinder user-modifications for specific needs. In order to promote reproducibility and data-sharing in science, transparent software and standardized data formats are an advantage. Here, we present an open source, low-cost, adaptable, and easy to set-up system for combined behavioral tracking, electrophysiology, and closed-loop stimulation.

Approach: Based on the Open Ephys system ( we developed multiple modules to include real-time tracking and behavior-based closed-loop stimulation. We describe the equipment and provide a step-by-step guide to set up the system. Combining the open source software Bonsai ( for analyzing camera images in real time with the newly developed modules in Open Ephys, we acquire position information, visualize tracking, and perform tracking-based closed-loop stimulation experiments. To analyze the acquired data we provide an open source file reading package in Python.

Main results: The system robustly visualizes real-time tracking and reliably recovers tracking information recorded from a range of sampling frequencies (30-1000 Hz). We combined electrophysiology with the newly-developed tracking modules in Open Ephys to record place cell and grid cell activity in the hippocampus and in the medial entorhinal cortex, respectively. Moreover, we present a case in which we used the system for closed-loop optogenetic stimulation of entorhinal grid cells.

Significance: Expanding the Open Ephys system to include animal tracking and behavior-based closed-loop stimulation extends the availability of high-quality, low-cost experimental setup within standardized data formats serving the neuroscience community.

Publication types

  • Research Support, Non-U.S. Gov't

MeSH terms

  • Algorithms*
  • Animals
  • Behavior, Animal*
  • Computer Simulation
  • Computer Systems
  • Electric Stimulation*
  • Electrophysiological Phenomena
  • Entorhinal Cortex / physiology
  • Hippocampus / physiology
  • Image Processing, Computer-Assisted
  • Rats
  • Reproducibility of Results
  • Software*