Skip to main content

Standalone utilities for working with pose data from SLEAP and other tools.

Project description

sleap-io

CI codecov Release PyPI PyPI - Python Version

Standalone utilities for working with animal pose tracking data.

This is intended to be a complement to the core SLEAP package that aims to provide functionality for interacting with pose tracking-related data structures and file formats with minimal dependencies. This package does not have any functionality related to labeling, training, or inference.

📚 Documentation - Comprehensive guides and API reference

Installation

From PyPI

pip install sleap-io

From source (latest version)

pip install git+https://github.com/talmolab/sleap-io.git@main

For video backend support, install with extras:

pip install sleap-io[opencv]  # For OpenCV backend (fastest)
pip install sleap-io[ffmpeg]   # For FFMPEG backend (most reliable)
pip install sleap-io[pyav]     # For PyAV backend (balanced)
pip install sleap-io[all]      # For all video backends

For development, use one of the following:

uv sync --all-extras           # Recommended: install with uv
conda env create -f environment.yml
pip install -e .[dev,all]      # Install with all extras for development

See CONTRIBUTING.md for more information on development.

Usage

Load and save in different formats

import sleap_io as sio

# Load from SLEAP file.
labels = sio.load_file("predictions.slp")

# Save to NWB file.
sio.save_file(labels, "predictions.nwb")
# Or:
# labels.save("predictions.nwb")

Convert labels to raw arrays

import sleap_io as sio

labels = sio.load_slp("tests/data/slp/centered_pair_predictions.slp")

# Convert predictions to point coordinates in a single array.
trx = labels.numpy()
n_frames, n_tracks, n_nodes, xy = trx.shape
assert xy == 2

# Convert to array with confidence scores appended.
trx_with_scores = labels.numpy(return_confidence=True)
n_frames, n_tracks, n_nodes, xy_score = trx.shape 
assert xy_score == 3

Read video data

import sleap_io as sio

video = sio.load_video("test.mp4")
n_frames, height, width, channels = video.shape

frame = video[0]
height, width, channels = frame.shape

Create labels from raw data

import sleap_io as sio
import numpy as np

# Create skeleton.
skeleton = sio.Skeleton(
    nodes=["head", "thorax", "abdomen"],
    edges=[("head", "thorax"), ("thorax", "abdomen")]
)

# Create video.
video = sio.load_video("test.mp4")

# Create instance.
instance = sio.Instance.from_numpy(
    points=np.array([
        [10.2, 20.4],
        [5.8, 15.1],
        [0.3, 10.6],
    ]),
    skeleton=skeleton
)

# Create labeled frame.
lf = sio.LabeledFrame(video=video, frame_idx=0, instances=[instance])

# Create labels.
labels = sio.Labels(videos=[video], skeletons=[skeleton], labeled_frames=[lf])

# Save.
labels.save("labels.slp")

Support

For technical inquiries specific to this package, please open an Issue with a description of your problem or request.

For general SLEAP usage, see the main website.

Other questions? Reach out to talmo@salk.edu.

License

This package is distributed under a BSD 3-Clause License and can be used without restrictions. See LICENSE for details.

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

sleap_io-0.6.4.tar.gz (588.7 kB view details)

Uploaded Source

Built Distribution

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

sleap_io-0.6.4-py3-none-any.whl (636.2 kB view details)

Uploaded Python 3

File details

Details for the file sleap_io-0.6.4.tar.gz.

File metadata

  • Download URL: sleap_io-0.6.4.tar.gz
  • Upload date:
  • Size: 588.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sleap_io-0.6.4.tar.gz
Algorithm Hash digest
SHA256 de42afd65ca02e1c63c2979503d3b795e702d0325d0407c386ea8e70c0c15e7e
MD5 fd7b817abb680616d444b8b678ee72ec
BLAKE2b-256 545241471a5831b590e81ac961d8b3eab3fc55c9a74616eb69562b7ad7acf325

See more details on using hashes here.

File details

Details for the file sleap_io-0.6.4-py3-none-any.whl.

File metadata

  • Download URL: sleap_io-0.6.4-py3-none-any.whl
  • Upload date:
  • Size: 636.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sleap_io-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9e99023c59329d2e5cf02f99e3ff30800d04b732f2dd7a7a2f7f2502c7b9dafd
MD5 e9e3f73ed16c5c750d0e75c738462c59
BLAKE2b-256 2042da4667e6513f93ac2910f9a990ec045474c96352790a12fa0b4fe6c0fb74

See more details on using hashes here.

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