State control system for automated, high-throughput behavioral training.
Project description
Ethopy
Ethopy is a state control system for automated, high-throughput behavioral training based on Python. It provides a flexible framework for designing and running behavioral experiments with:
- Tight integration with database storage & control using Datajoint
- Cross-platform support (Linux, macOS, Windows)
- Optimized for Raspberry Pi boards
- Modular architecture with overridable components
- Built-in support for various experiment types, stimuli, and behavioral interfaces
The full documentation is available at:
Features
- Modular Design: Comprised of several overridable modules that define the structure of experiments, stimuli, and behavioral control
- Database Integration: Automatic storage and management of experimental data using Datajoint
- Multiple Experiment Types: Support for various experiment paradigms (match to sample, 2AFC, open field, etc.)
- Hardware Integration: Interfaces with multiple hardware setups (raspberry, arduino, desktop computer, screen, camera etc.)
- Stimulus Control: Various stimulus types supported (Gratings, Movies, Olfactory, 3D Objects)
- Real-time Control: State-based experiment control with precise timing
- Extensible: Easy to add new experiment types, stimuli, or behavioral interfaces
System Architecture
The following diagram illustrates the relationship between the core modules:
Installation & Setup
Requirements
- Python 3.8 or higher
- Maria DB Database (instructions for database setup)
Basic Installation
pip install ethopy
Running Experiments
Example of running a task:
# Run a grating test experiment
ethopy -p grating_test.py
# Run a specific task by ID
ethopy --task-idx 1
Core Architecture
Understanding Ethopy's core architecture is essential for both using the system effectively and extending it for your needs. Ethopy is built around four core modules that work together to provide a flexible and extensible experimental framework. Each module handles a specific aspect of the experiment, from controlling the overall flow to managing stimuli and recording behavior.
1. Experiment Module
The base experiment module defines the state control system. Each experiment is composed of multiple states, with Entry and Exit states being mandatory.
Example of a State Machine Diagram
This diagram illustrates a simple state machine, a computational model that transitions between discrete states in response to inputs or events. State machines are used to model systems with a finite number of possible states and well-defined transitions between them.
- Entry: The initial state, marking the start of the process.
- PreTrial: A preparatory state before the actual trial begins.
- Trial: The main state where the trial takes place. It can loop back to itself, representing iterative actions within the trial.
- Abort, Reward, Punish: Possible outcomes of the trial, leading to different branches.
- InterTrial: A state between trials, possibly for processing results or preparing for the next trial.
- Exit: The final state, indicating the end of the process.
State Machine Diagram
Each state has four overridable functions that control its behavior:
State Functions
Available Experiment Types
- MatchPort: Stimulus-port matching experiments
- Passive: Passive stimulus presentation
- FreeWater: Water delivery experiments
- Calibrate: Port calibration for water delivery
2. Behavior Module
Handles animal behavior tracking and response processing.
Available Behavior Types
- MultiPort: Standard setup with lick detection, liquid delivery, and proximity sensing
- HeadFixed: Passive head fixed setup
Important: Regular liquid calibration is essential for accurate reward delivery. We recommend calibrating at least once per week to ensure consistent reward volumes and reliable experimental results.
3. Stimulus Module
Controls stimulus presentation and management.
Available Stimulus Types
- Visual
- Grating: Orientation gratings
- Bar: Moving bars for retinotopic mapping
- Dot: Moving dots
Logger Module (Non-overridable)
Manages all database interactions across modules. Data is stored in three schemas:
lab_experiments:
lab_behavior:
lab_stimuli:
interface:
Interface Module (Non-overridable)
Manages hardware interactions and the configuration of hardware based on setup index.
Available Interfaces
- Arduino: Interfaces with Arduino microcontrollers for reward delivery, lick detection, and proximity sensing
- Ball: Tracks animal movement on a spherical treadmill using two mice for position, orientation, and speed
- Camera: Manages camera recordings with timestamping and HTTP streaming capabilities
- dlc: DeepLabCut integration for real-time animal pose tracking and arena detection
- DummyPorts: Simulates animal interaction ports for testing and development without physical hardware
- PCPorts: Controls PC hardware interfaces via serial connections for synchronization and stimulation
- RPPorts: Interfaces with Raspberry Pi GPIO pins to control lick ports, valves, sensors, and stimulation
- RPVR: Extends RPPorts for virtual reality experiments with additional odor control capabilities
Development & Contributing
Development Setup
- Clone the repository:
git clone https://github.com/ef-lab/ethopy_package/ # Main repository
cd ethopy
- Install development dependencies:
pip install -e ".[dev,docs]"
Code Quality
The project uses several tools to maintain code quality:
- ruff: Code formatting and linting
- isort: Import sorting
- mypy: Static type checking
- pytest: Testing and test coverage
Run tests:
pytest tests/
Documentation
Documentation is built using MkDocs. Install documentation dependencies and serve locally:
pip install ".[docs]"
mkdocs serve
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions and support:
- Open an issue on GitHub
- Check the full documentation
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ethopy-0.0.8.4.tar.gz.
File metadata
- Download URL: ethopy-0.0.8.4.tar.gz
- Upload date:
- Size: 543.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e37cbeadef3ac1f4a0450a1feb8ed47901dfb4deba6df2f7d1e91c2e691f28f1
|
|
| MD5 |
8090eb4bd0ed874e0972e27cdff042a9
|
|
| BLAKE2b-256 |
74538d01e9c06da36d68789d29613e53175925f25d9f79df93f44ee6f53c73a9
|
File details
Details for the file ethopy-0.0.8.4-py3-none-any.whl.
File metadata
- Download URL: ethopy-0.0.8.4-py3-none-any.whl
- Upload date:
- Size: 112.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7ab2c2c92ff0fb0a7404ce0696bf91e817a4263f7b5d5e44f511f6553570c64
|
|
| MD5 |
0593cd432f03878af79262a1f891abd6
|
|
| BLAKE2b-256 |
ca62016c4be3869a2d7274141334548967ce2e577d87c5d2e0b279fbfaae2d69
|