Skip to main content

A simple package for rat vision rendering simulation.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ratvision-0.2.0.tar.gz (18.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ratvision-0.2.0-py3-none-any.whl (18.6 MB view details)

Uploaded Python 3

File details

Details for the file ratvision-0.2.0.tar.gz.

File metadata

  • Download URL: ratvision-0.2.0.tar.gz
  • Upload date:
  • Size: 18.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ratvision-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bebf77f56df4cd4d7e9eeea0922b63fa7f456db27a9e6a9d48fd936a353f0501
MD5 d5d63782867bfab569655f1afeaf7791
BLAKE2b-256 f089f6beaf2cb39853d1e6d6fe281b379e58c90b91fe6c63cfde2d3d8c7cfb38

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratvision-0.2.0.tar.gz:

Publisher: publish.yml on marcoabrate/ratvision

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ratvision-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ratvision-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ratvision-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e597ed33921cfb465c277f09bcc5ff79f6df126bbd72f4408346e4d7eede78e3
MD5 030dc84e297d4295bb21f0e7b3af3f25
BLAKE2b-256 5d87d122e73587b7662f1960f6dbdfb17998d1fc410bf1c63a78b3433534f07c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ratvision-0.2.0-py3-none-any.whl:

Publisher: publish.yml on marcoabrate/ratvision

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page