ratvision
A Python library for simulating rat vision through 3D rendering.
ratvision provides a simple interface to render what a rat would see based on its position and head direction in a 3D environment. Three rendering back-ends are available: a Blender-based photorealistic renderer, a fast CPU raycaster, and a GPU-accelerated PyTorch renderer suitable for end-to-end differentiable pipelines.
Documentation
Full API documentation is available at marcoabrate.github.io/ratvision.
Installation
pip install ratvision
Or by cloning this repository:
git clone git@github.com:marcoabrate/ratvision.git
cd ratvision
pip install .
For GPU-accelerated rendering with TorchRenderer (Note: it installs torch):
pip install ratvision[gpu]
Quick start
Raycasting renderer (no external dependencies):
from ratvision import RaycastingRenderer
renderer = RaycastingRenderer() # default box environment
frame = renderer.render_frame(0.3, 0.3, 0.0) # (H, W) numpy array
frames = renderer.render_path(positions, head_directions)
PyTorch renderer (GPU-accelerated):
from ratvision import TorchRenderer
import torch
renderer = TorchRenderer(config={'frame_dim': (64, 32)}).to('cuda')
frames = renderer(positions_tensor, head_directions_tensor) # (B, H, W) tensor
Blender renderer (photorealistic):
from ratvision import BlenderRenderer
renderer = BlenderRenderer(blender_exec='/path/to/blender')
renderer.render(positions, head_directions)
See the examples/ directory for full runnable demos with each back-end:
python examples/raycasting_render_demo.py
python examples/torch_render_demo.py
python examples/blender_render_demo.py --blender_exec "/path/to/Blender"
Requirements
- Python 3.9+
- Blender (only required for
BlenderRenderer, not included in the package)
The Blender renderer was tested with Blender 3.6 on Linux and macOS.
Features
- Three rendering back-ends (Blender, CPU raycasting, GPU PyTorch)
- Generate rat-eye-view video animations from movement trajectories
- Easy to use Python API
- Compatible with custom 3D environments and procedural landmarks
- Built-in visualisation utilities (
get_video_animation) - GPU batch rendering for training loops (
TorchRenderer)
Configuration options
Each renderer can be configured with parameters such as:
| Parameter | Description | Default |
|---|---|---|
frame_dim |
Dimensions of the rendered frames (width, height) | (128, 64) |
camera_height |
Height of the camera from the ground in metres | 0.035 |
hfov |
Horizontal field of view in radians | 4π/3 (240°) |
vfov |
Vertical field of view in radians | 2π/3 (120°) |
output_dir |
Directory where rendered frames are saved | ./output |
Additional Blender-specific options:
| Parameter | Description | Default |
|---|---|---|
env_file |
Path to Blender environment file | Built-in box |
camera_name |
Name of the camera in the Blender scene | Camera_main |
camera_vertical_angle |
Vertical inclination of the camera in radians | π/2 |
You can view and update the configuration at runtime:
renderer.config_description() # print all available keys
renderer.update_config({'frame_dim': (64, 32)})
Customisable 3D environment
While ratvision comes with a default 3D environment, you can create custom environments programmatically or use your own Blender files:
from ratvision import BoxEnvironment, Landmark, RaycastingRenderer
env = BoxEnvironment(width=1.0, depth=1.0, height=0.8, wall_color=0.6)
renderer = RaycastingRenderer(env=env)
For Blender-based rendering with a custom .blend file:
renderer.update_config({'env_file': '/path/to/environment.blend'})
Note: All rendering and camera settings defined in the Blender file will be preserved. Only the parameters set through the config will be overwritten. For biologically-plausible rendering and camera settings, check the provided environment
environments/box_messy.blend.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Marco P Abrate marcopietro.abrate@gmail.com
Metadata
Release files for ratvision 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ratvision-0.2.0.tar.gz | 18.6 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ratvision-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.1 MB
Release files / ratvision-0.2.0.tar.gz
| Download URL | ratvision-0.2.0.tar.gz |
|---|---|
| Size | 18.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bebf77f56df4cd4d7e9eeea0922b63fa7f456db27a9e6a9d48fd936a353f0501
|
|
BLAKE2b-256 checksum How to use checksums |
f089f6beaf2cb39853d1e6d6fe281b379e58c90b91fe6c63cfde2d3d8c7cfb38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency logRelease files / ratvision-0.2.0-py3-none-any.whl
| Download URL | ratvision-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e597ed33921cfb465c277f09bcc5ff79f6df126bbd72f4408346e4d7eede78e3
|
|
BLAKE2b-256 checksum How to use checksums |
5d87d122e73587b7662f1960f6dbdfb17998d1fc410bf1c63a78b3433534f07c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency log