Skip to main content

RelatiPy

Documentation · PyPI · Source · Issues

Numerical tools for relativistic geometry: timelike geodesics in the Kerr spacetime, with a Python interface built on Astropy units and a native C core.

RelatiPy keeps the physics and the numerical integration in C. Python validates inputs, handles physical units, exposes immutable result objects, and performs post-integration interpolation. A private Cython binding connects the two layers; the integration loop makes no Python callbacks.

Status: research software under active development (version 1.3.0). The first public interface covers scalar timelike orbits around a Kerr black hole. See scope and limits before relying on results.

Features

  • Kerr geometry. Kerr(mass=..., spin=...) with 0 <= spin <= 1, gravitational radius r_g = GM/c², horizons, prograde/retrograde ISCO and photon-orbit radii, and the ergosurface.
  • Several initial-condition families. Classical elements (a, e, inc, Omega, omega, f), Cartesian, spherical, or Boyer–Lindquist position and coordinate velocity, and bound Kerr parameters (p, e, x, q_r0, q_theta0, q_phi0) via KerrOrbitalElements.
  • Native integrators. "radau" (default, Radau IIA(5)), "dop853", "dp45", and "projection_radau", which projects each accepted step toward the initial norm, energy, axial angular momentum, and Carter constant.
  • Read-only solutions. Solution objects with explicit status (0 endpoint reached, 1 terminal event such as the outer horizon, -1 numerical failure with partial result), coordinate views in several families, osculating Kepler elements, and Solution.at queries by proper or coordinate time.
  • Observables for MCMC. KerrMcmcModel predicts sky-plane offsets (arcsec) and line-of-sight velocity (km/s) from a timelike Kerr geodesic, including Rømer delay, fully evaluated in C.
  • Constants of motion. get_E, get_Lz and get_Q on orbits and solutions, Solution.plot_constants for their drift, and Orbit.get_keplerian_period as a time scale.
  • Plotting. Matplotlib or Plotly views of the osculating conic (Orbit.preview), of the integrated path (Solution.plot), and of several paths in one frame (relatipy.plot_sols).

Installation

Requirements: Python 3.11 or later.

python -m pip install relatipy

This installs the package together with all of its dependencies: NumPy, Astropy, SciPy, Matplotlib, and Plotly. Prebuilt wheels are published for Linux x86_64 and CPython 3.11–3.14; on other platforms pip builds from the source distribution, which needs a C11 compiler and the standard C math library.

KerrMcmcModel returns model predictions (astrometry and line-of-sight velocity); the likelihood and the sampler are left to the user, so RelatiPy does not depend on a specific sampler. The example notebooks use emcee, installed separately with python -m pip install emcee or through the notebook dependency group below.

To install from a source checkout:

git clone https://github.com/lldddv2/relatipy.git
cd relatipy
python -m pip install .

Development environment with uv:

uv sync --group dev
uv sync --group dev --group notebook   # adds pandas, ipykernel, nbclient, emcee for the examples

Quick start

from astropy import units as u
from astropy.constants import c
from relatipy import Kerr

bh = Kerr(mass=1 * u.Msun, spin=0.5)
orb = bh.orbit(x=12 * bh.r_g, vy=0.1 * c)
sol = orb.solve(tau_span=(0 * u.s, 2e-8 * u.s), method="dp45")

assert sol.success
print(sol.tau, sol.xyz.shape)

mid = sol.at(tau=sol.tau[-1] / 2)   # interpolated state, no reintegration
elements = mid.orbital_elements()   # instantaneous Kepler conic

Orbit.solve starts from the saved initial conditions and leaves the orbit unchanged. Orbit.integrate advances the orbit's current point to an absolute proper time; reset and copy restore or duplicate it.

Numerical controls shared by both methods: method, rtol, atol (scalar or shape (8,)), first_step, and max_step. When omitted, rtol is 1e-10 and atol is rtol times a characteristic scale of each native state component at the starting state. Explicit tolerances that are unfit for the orbit (for example rtol=1e-3) issue an IntegrationWarning. Tolerances control local error in the normalized native state; they do not bound global trajectory error.

Bound Kerr orbit

from astropy import units as u
from relatipy import Kerr
from relatipy.coordinates import KerrOrbitalElements

bh = Kerr(mass=4e6 * u.Msun, spin=0.7)
elements = KerrOrbitalElements(
    p=12 * bh.r_g, e=0.3, x=0.7,
    q_r0=0.4 * u.rad, q_theta0=1.2 * u.rad, q_phi0=0.2 * u.rad,
)
sol = bh.orbit(elements=elements).solve(
    tau_span=(0 * u.s, 1000 * u.s), method="dop853", rtol=1e-10, atol=1e-12,
)

MCMC observables

import numpy as np
from astropy import units as u
from relatipy import KerrMcmcModel

model = KerrMcmcModel()
alpha, delta, v_los = model.get_ra_dec_vr(
    kerr=dict(mass=4e6 * u.M_sun, spin=0.4, vec=(0.0, 0.0, 1.0)),
    orbit=dict(a=1000 * u.au, e=0.5, inc=0.6 * u.rad,
               Omega=0.4 * u.rad, omega=0.3 * u.rad),
    sol=dict(t_eval=np.array([0.0, 1e5]) * u.s),
    distance=8 * u.kpc,
)

alpha and delta are offsets in arcsec and v_los is in km/s, returned as read-only NumPy arrays. See Kerr MCMC guide for the fixed-epoch API and solver settings.

A minimal runnable script is in examples/bound_orbit.py.

Conventions

  • Metric signature (-,+,+,+); Boyer–Lindquist coordinates (t, r, theta, phi).
  • Public inputs and outputs are Astropy quantities in physical units.
  • The native backend works in geometric units G = c = M = 1; its state is (t/T0, R/r_g, Theta, Phi, u^t, u^R, u^Theta, u^Phi).
  • Orbital angles use a right-handed Cartesian frame centered on the black hole, with z along the spin axis. The initial radius must lie outside the outer horizon.

Project layout

src/relatipy/      Public Python API (coordinates, geodesic, metrics,
                   observables, plotting)
bindings/cython/   Private Cython adapters (_core, _mcmc_core)
native/            C implementation: Kerr geometry, geodesic RHS, integrators,
                   native tests
tests/             Python tests: api/ (by subpackage), internal/, reference/
                   (peer comparisons, invariant drift, domain extremes);
                   see tests/README.md
docs/              Sphinx documentation (reStructuredText)
examples/          Minimal runnable example

Testing

pytest is a development-only dependency declared in the dev dependency group (never installed by pip install relatipy). Run from the repository root:

uv run --group dev pytest

The layout and placement rules are described in tests/README.md.

Native C tests are standalone programs under native/tests/. Build each one with the exact source list and compiler flags given in native/README.md.

Documentation

Full documentation: https://relatipy.readthedocs.io/en/latest/.

Sphinx sources live in docs/ and are published through Read the Docs. Build locally with warnings treated as errors:

uv sync --group docs
uv run --group docs sphinx-build -W --keep-going -b html docs docs/_build/html

Key pages: usage, scope and limits, developer architecture, native Kerr reference, and peer-library validation.

Validation status

Native integrators and geometry have unit tests, invariant-drift checks, and comparisons against SciPy. A peer-library harness with KerrGeoPy and PyGRO exists, but its RelatiPy comparison gate is still skipped and the associated scientific records await manual review. Do not treat those comparisons as a validation of RelatiPy. Details: peer-library validation.

Contributing

Read the contributing guide and developer architecture first. In short: physics and integration stay in C, the Python layer handles API, units, objects, and interpolation, private extension modules are not public API, and public docstrings follow the NumPy style.

AI assistance

RelatiPy was developed with the help of AI coding assistants:

  • Codex (OpenAI).
  • Claude Code (Anthropic).

License

GPL-3.0-only. See LICENSE.

Metadata

Release files for relatipy 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for relatipy 1.3.0
File Size Uploaded Provenance Actions
relatipy-1.3.0.tar.gz 662.8 kB Without provenance Details for relatipy-1.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for relatipy 1.3.0
File Actions
relatipy-1.3.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details for relatipy-1.3.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
relatipy-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details for relatipy-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
relatipy-1.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details for relatipy-1.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
relatipy-1.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details for relatipy-1.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Total release size: 7.9 MB

Release files / relatipy-1.3.0.tar.gz

Download URL relatipy-1.3.0.tar.gz
Size 662.8 kB
Tags Source
SHA-256 checksum
How to use checksums
392ed45e78ec02892e25050b3df880707e35b2bc4cd63cd5602b380981086666
BLAKE2b-256 checksum
How to use checksums
2ca888df41e285e8ff8a818b42044fb4144d3743fafa8975e096c06ac2ec7979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / relatipy-1.3.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL relatipy-1.3.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d046a6b6964e66d3338bc99cb5cca2633efba417fb7d575dbf80657d0a2ae197
BLAKE2b-256 checksum
How to use checksums
6485767f51d35f1a76f6d091b746c7a4534816cbe43c222c69e2058b5e0cc3fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / relatipy-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL relatipy-1.3.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ae524e3e827ec23db1140c1a2715d62f7533ee0d4ada746162f2dc77d64fb57d
BLAKE2b-256 checksum
How to use checksums
4deb53c4091c85e7a0bc6bb27354a2ec3934367c66623f74c280c0d2e963e747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / relatipy-1.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL relatipy-1.3.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3fbb404541f6be7a3d7754f3e7b72d2392e7e41438cfd2636534cb9fce908e3e
BLAKE2b-256 checksum
How to use checksums
15d38c223dbf4538413ce3db4016ba396849895905f3924c30cfe13748656ee6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / relatipy-1.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL relatipy-1.3.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
035a8d2825a5e43ffc6b775957a4f0f3c9da78d96de628a81211a7b70fe1dce6
BLAKE2b-256 checksum
How to use checksums
6a60461bda11666ee8335b07c03315cd498c7269f201be8d80eb76618558712a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for relatipy 1.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page