Mouse wiskers body kinematics and behavior
Project description
W2T Body Kinematics Pipeline (w2t-bkin)
A modular, reproducible Python pipeline for processing multi-camera rodent behavior recordings with synchronization, pose estimation, facial metrics, and behavioral events into standardized NWB datasets.
Features
- ๐ง NWB-Native: Direct NWB file creation, no intermediate formats
- ๐ Prefect Orchestration: Workflow management with monitoring UI
- ๐น Multi-Camera Support: Synchronized video processing with pose estimation
- ๐ญ Behavior Analysis: Bpod task recording and TTL synchronization
- ๐ฏ Pose Estimation: DeepLabCut and SLEAP integration
- ๐ Facial Metrics: Facemap-based facial movement analysis
- โ Validation: Automated NWB file validation and inspection
- ๐ณ Flexible Execution: Local Python or Docker workers
Prerequisites
- Python: 3.10
- Prefect: 3.6+ (included in base installation)
- Rancher Desktop: Recommended for Windows users (provides Docker runtime)
- Download from rancherdesktop.io
- Installs Docker automatically
- No Docker knowledge required
Installation
# Base installation (CLI + Prefect server/UI + data management)
pip install w2t-bkin
# OR full installation with worker capabilities (includes ML/video processing)
pip install w2t-bkin[worker]
Installation guide:
- Base:
pip install w2t-bkin(~MB, no ML dependencies)- Run Prefect UI and orchestration
- Use Docker containers for processing (recommended)
- Best for most users
- Worker extras:
pip install w2t-bkin[worker](~Gb, includes DeepLabCut, etc.)- Run processing tasks directly without Docker
- Good for development or machines without Docker
- All-in-one installation for single-user workstations
Quick Start
1. Initialize Workspace
# Create experiment directory structure
w2t-bkin data init /data/my-experiment
cd /data/my-experiment
2. Add Metadata
# Add subject
w2t-bkin data add-subject /data/my-experiment mouse-001 \
--species "Mus musculus" --sex F --age P90D -y
# Add session
w2t-bkin data add-session /data/my-experiment mouse-001 session-001 \
--description "Baseline recording" -y
# Copy your raw data files
cp /path/to/videos/* /data/my-experiment/data/raw/mouse-001/session-001/Video/
cp /path/to/ttls/* /data/my-experiment/data/raw/mouse-001/session-001/TTLs/
cp /path/to/bpod/* /data/my-experiment/data/raw/mouse-001/session-001/Bpod/
cp /path/to/dlc-model /data/my-experiment/models/
3. Start Prefect Server
cd /data/my-experiment
# Production mode (uses Docker workers)
w2t-bkin server start --config configs/standard.toml
# Development mode (runs flows locally with Runner - requires worker extras)
w2t-bkin server start --config configs/standard.toml --dev
# This will:
# 1. Start Prefect server
# 2. Create flow deployments (prod) or serve flows (dev)
# 3. Open browser to http://localhost:4200
4. Run Workflows in Prefect UI
- Open http://localhost:4200 (opens automatically)
- Navigate to Deployments
- Select process-session or batch-process
- Click Run and fill in parameters:
subject_id: mouse-001session_id: session-001
- Monitor progress in Flow Runs tab
5. Start Workers (Production Mode Only)
โ ๏ธ Important: The
w2t-bkin workercommand does not exist. Use Prefect CLI or Docker directly.
Production mode requires workers to execute flows. Choose one method:
Method 1: Prefect CLI (requires pip install w2t-bkin[worker])
# Start a process worker with concurrency limit
prefect worker start --pool default-pool --type process --limit 4
Method 2: Docker (recommended for production)
# Source the worker environment and start Docker worker
source .workers/.env
prefect worker start --pool docker-pool --type docker
Development mode runs flows in the server process - no worker needed!
Usage Examples
Discover Available Sessions
# List all sessions
w2t-bkin discover configs/standard.toml
# Filter by subject
w2t-bkin discover configs/standard.toml --subject mouse-001
# Output formats
w2t-bkin discover configs/standard.toml --format json
Validate NWB Output
w2t-bkin validate /data/my-experiment/data/processed/mouse-001/session-001/*.nwb
Inspect NWB File
w2t-bkin inspect /data/my-experiment/data/processed/mouse-001/session-001/*.nwb
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ User โ
โ 1. w2t-bkin server start [--dev] โ
โ 2. Open http://localhost:4200 โ
โ 3. Trigger workflows in UI โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Prefect Server (localhost:4200) โ
โ - Flow Deployments (production) โ
โ - Flow Services via Runner (dev mode) โ
โ - Work Pool (docker-pool, type: docker)โ
โ - UI Monitoring โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Workers (Production Only) โ
โ - Docker containers execute flows โ
โ - Managed via docker-pool โ
โ โ
โ Dev Mode (No Worker Needed) โ
โ - Flows run in server via Runner โ
โ - No work pool required โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Documentation
User Guides
- Templates - Example configuration and metadata files
- Cheat Sheet - Quick reference for common tasks
- Migration Guide - Migrate from old workflow
- FAQ - Frequently asked questions
- Troubleshooting - Common issues and solutions
- CLI Reference - Complete command-line documentation
Technical References
- Configuration Parameters - Pipeline behavior (HOW to process)
- Metadata Parameters - Data description (WHAT data exists)
- Architecture Diagram - System design
- Prefect UI Guide - Orchestration setup
Developer Documentation
- Requirements - Project requirements
- Design - Technical design document
- Tasks - Development task tracking
Architecture & Dependencies
Deployment Options
Option 1: Server + Docker Workers (Recommended)
# Server machine
pip install w2t-bkin # ~30 MB (Prefect, CLI, config)
w2t-bkin server start # Starts UI at localhost:4200
# Docker workers (pre-built images from GitHub Container Registry)
docker pull ghcr.io/borjaest/w2t-bkin:latest
docker run ... ghcr.io/borjaest/w2t-bkin:latest # Contains all ML/video dependencies
Benefits:
- Clean separation: Server handles UI, workers handle processing
- No dependency conflicts on server machine
- Easy scaling: Run multiple Docker workers
Option 2: Development Mode (Local)
# Single machine with worker extras installed
pip install w2t-bkin[worker] # ~630 MB (everything)
w2t-bkin server start --dev # Flows run in server process via Runner
Benefits:
- Fastest iteration (no container overhead)
- Simplest setup for development and debugging
- Live code changes without rebuild
Dependency Breakdown
| Component | Base Install | Worker Extras |
|---|---|---|
| CLI | โ Typer, Rich | โ |
| Prefect | โ Server + Client | โ |
| NWB | โ PyNWB, HDMF | โ |
| Config | โ Pydantic, TOML | โ |
| Processing | โ | โ DeepLabCut, Facemap |
| Video | โ | โ FFmpeg, scipy |
| Validation | โ | โ nwbinspector |
| Total Size | ~30 MB | ~630 MB |
Advanced Configuration
Custom Work Pools
# Start server with local work pool (requires [worker] extras)
w2t-bkin server start --work-pool local
# Start server with custom port
w2t-bkin server start --port 5000
Python API (Advanced Users)
For scripting and automation:
from w2t_bkin.api import SessionFlowConfig
from w2t_bkin.flows import process_session_flow
# Create configuration
config = SessionFlowConfig(
config_path="configs/standard.toml",
subject_id="mouse-001",
session_id="session-001",
skip_pose=True # Optional: skip specific steps
)
# Direct execution (no Prefect needed)
result = process_session_flow(config=config)
if result.success:
print(f"โ NWB written to: {result.nwb_path}")
Development
For contributors and developers:
# Clone repository
git clone https://github.com/BorjaEst/w2t-bkin.git
cd w2t-bkin
# Install in editable mode with dev dependencies
pip install -e .[dev,worker]
# Run tests
pytest
# Format code
black src/ tests/
isort src/ tests/
# Type checking
mypy src/
# Build Docker image locally
docker build -f docker/Dockerfile -t w2t-bkin:dev .
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Apache-2.0 - See LICENSE for details.
Citation
If you use this pipeline in your research, please cite:
@software{w2t_bkin,
title={W2T Body Kinematics Pipeline},
author={Larkum Lab},
year={2024},
url={https://github.com/BorjaEst/w2t-bkin}
}
Support
- Issues: https://github.com/BorjaEst/w2t-bkin/issues
- Discussions: https://github.com/BorjaEst/w2t-bkin/discussions
- Documentation: https://github.com/BorjaEst/w2t-bkin/tree/main/docs
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 w2t_bkin-0.0.11.tar.gz.
File metadata
- Download URL: w2t_bkin-0.0.11.tar.gz
- Upload date:
- Size: 171.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d47df5ab2ef70f9b474565f0fa9477eb886386da13ec485583c9cf722be6ee99
|
|
| MD5 |
fdadc376cc9fa17439c48442d3020195
|
|
| BLAKE2b-256 |
1d04521bdf1eef3a1dcb7d974f36e585f2bdc08d7bf8ecbb6ed6c8d902f35f8e
|
File details
Details for the file w2t_bkin-0.0.11-py3-none-any.whl.
File metadata
- Download URL: w2t_bkin-0.0.11-py3-none-any.whl
- Upload date:
- Size: 200.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0119f01141a69580b1b66bfa280f61616280aed38b822eaba5108f7f2e923278
|
|
| MD5 |
d91b7eb6d4c44c7d6635b96ed358ec22
|
|
| BLAKE2b-256 |
d1b4f7b3c5b5720269e2ea587647c5f0641ad6cda14063796365b16963bf4b7d
|