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.

Installation

pip install sleap-io

For development, use one of the following syntaxes:

conda env create -f environment.yml
pip install -e .[dev]

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.4.0.tar.gz (132.0 kB view details)

Uploaded Source

Built Distribution

sleap_io-0.4.0-py3-none-any.whl (146.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sleap_io-0.4.0.tar.gz
  • Upload date:
  • Size: 132.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for sleap_io-0.4.0.tar.gz
Algorithm Hash digest
SHA256 216dbc3bc7acdbdd8323e950583904ad051db8464bebdb62f7a7ff4622e7f490
MD5 87489f99928b41dce0429e9464b39665
BLAKE2b-256 61921c1d986e6e3c4d2e302c66e7ff806036868fcad873e1007b2235b9aab885

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sleap_io-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 146.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for sleap_io-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e15a05ec2bf2c31efc365290d4be21ddca5d2c56cebb1fc06a335bc2ba95babb
MD5 51ad295fc2b037aec1605b01959e6c02
BLAKE2b-256 cc743fb9b4139221061e9210b57dff84117e697adf399d94a2c4000b44b2e62a

See more details on using hashes here.

Supported by

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