Skip to main content

photomancy

PyPI Documentation Status Tests License Python 3.12+

Divination from light.

photomancy is a JAX-native engine for Bayesian inference and value of information over astrophysical scenes observed by direct imaging. It is part of the Habitable Worlds Observatory simulation suite: orbix builds the geometry, skyscapes builds the scene, and photomancy divines the scene back from the data, producing posteriors over the scene parameters, the Bayesian evidence for model comparison, and the expected information gain of a candidate next observation.

The engine is forward-model agnostic. A fit is a normalized log density over the free entries of a model: the model holds every quantity, a dictionary names the free entries and their priors, and data terms score the measurements. run(fit, backend, key) turns a fit into a Posterior, a cloud of weighted draws with the evidence and its standard error, whichever backend produced it. The same machinery serves orbit fitting from astrometry, radial velocity and photometry, and fitting of coronagraph images pixel by pixel (photomancy.image.ImageTerm), so an improvement to a backend or to the information-gain calculation reaches every domain at once.

Installation

pip install photomancy

The importance, Laplace, quadrature and staged MAP backends work from the base install. The sampler backends are optional extras: photomancy[blackjax] for NUTS, MCLMC and Pathfinder, photomancy[jaxns] for nested sampling, or photomancy[samplers] for both.

pip install "photomancy[samplers]"

photomancy requires Python 3.12 or newer and is in early development, so the API may still change. For a source checkout with the test and documentation extras, clone the repository and run pip install -e ".[test,docs]".

Quick start

Fit the orbit of one planet from four epochs of relative astrometry. The model is an orbix System, the orbit is freed by a ThieleInnesBlock with its prior, and the data are a RelativeAstrometryTerm drawn at the true orbit.

import jax
import jax.numpy as jnp
import numpy as np
from orbix.system import Body, OrbitLaw, SkyFrame, System, ThieleInnesBlock
from priorities import LogUniform, Uniform
from skyscapes.population import kipping_eccentricity

from photomancy.infer import Fit, run
from photomancy.measurements import AstrometryData, RelativeAstrometryTerm
from photomancy.orbit import any_epoch, classical_elements

jax.config.update("jax_enable_x64", True)

truth = System.from_classical(
    Body(jnp.asarray(1.0)),  # star mass, solar masses
    Body(jnp.array([0.0])),  # planet masses, solar masses
    SkyFrame(jnp.asarray(10.0)),  # distance, pc
    a_AU=jnp.array([1.0]),
    e=jnp.array([0.1]),
    i_rad=jnp.array([1.0]),
    W_rad=jnp.array([1.0]),
    w_rad=jnp.array([2.0]),
    M0_rad=jnp.array([1.0]),
)
layout = AstrometryData.from_separation_pa(
    time_d=[0.0, 90.0, 180.0, 270.0],
    separation_arcsec=[0.1] * 4,
    separation_err_arcsec=[0.004] * 4,
    pa_deg=[0.0] * 4,
    pa_err_deg=[1.0] * 4,
)
term = RelativeAstrometryTerm(layout).draw(jax.random.key(0), truth)

law = OrbitLaw(
    period_d=LogUniform(50.0, 5000.0), eccentricity=kipping_eccentricity(0.9)
)
block = ThieleInnesBlock(law, Uniform(0.9, 1.1), rows=(0,), system="")
fit = Fit(truth, {"orbits": block}, (term,))

posterior = run(fit, any_epoch(), jax.random.key(1))
elements = classical_elements(posterior, jax.random.key(2), 1000, orbit_path="orbits")
print(posterior.log_evidence, np.percentile(elements["period_d"], [16, 50, 84]))

When a fifth epoch arrives, update(posterior, new_term, any_epoch(), key, min_n_eff=..., max_khat=...) reweights the existing draws by the new term and refits only when the reweighting fails its gate.

What it does

  • Posteriors over the free entries of a model behind one type, Posterior, whichever backend produced them: the draws, their normalized weights, the fit's density at each draw, and the fit itself, so any quantity of the model can be read at every draw.
  • Bayesian evidence with a standard error for model comparison and detection. A backend that cannot vouch for its estimate returns NaN rather than a wrong number; a fit that misses a mode entirely is the one failure it cannot detect.
  • Multimodal posteriors carried as weighted draws, so period aliases and mirror ambiguities stay in the cloud rather than being collapsed onto one answer.
  • Sequential updating: Posterior.append_term and Posterior.replace_term reweight a posterior by new data without refitting, under a gate on the effective sample size and the k-hat of the new weights, and update refits only where that gate refuses.
  • Expected information gain of a candidate next observation, turning a fit into a recommendation for where to look next.

Backends

Every backend is passed to run(fit, backend, key) and returns a Posterior.

Backend Method Evidence
Importance importance sampling from one proposal yes
AdaptiveImportance rounds of Gaussian mixtures refitted to the weighted draws yes
Laplace a Gaussian at each mode, importance weighted to the fit yes
Pathfinder Pathfinder Gaussians, importance weighted to the fit yes
NUTS the No-U-Turn sampler with window adaptation no
MCLMC microcanonical Langevin Monte Carlo no
NestedSampling jaxns nested sampling yes
MAP staged gradient optimization, one draw at the optimum no
Grid quadrature on a product grid yes, without a standard error

When an evidence is finite and when it is NaN is one contract, stated on Posterior.log_evidence and explained in the Fits and posteriors page of the documentation.

The orbit package adds two configured backends named for the data in hand: few_epoch() for one or two astrometric epochs, and any_epoch() for everything else.

Documentation

The full documentation lives in docs/ and builds with Sphinx once the docs extra is installed:

sphinx-build -b html docs docs/.build/html

It explains fits and posteriors step by step on a problem with a known answer, describes the orbit coordinates and engines, and works through an orbit fit as the epochs arrive.

Status

Orbit fitting is implemented across radial-velocity, astrometry, photometry and detection-report data, and the pixel likelihood fits coronagraph images through the coronagraphoto forward model. Disk fitting and atmospheric retrieval are in progress. On the backend side, a stochastic variational backend with a normalizing-flow guide is planned.

License

photomancy is released under the MIT license, see LICENSE.

Metadata

Release files for photomancy 2.0.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 photomancy 2.0.0
File Size Uploaded Provenance Actions
photomancy-2.0.0.tar.gz 275.2 kB With provenance Details for photomancy-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for photomancy 2.0.0
File Interpreter ABI Platform Actions
photomancy-2.0.0-py3-none-any.whl Python 3 none any Details for photomancy-2.0.0-py3-none-any.whl

Total release size: 559.2 kB

Release files / photomancy-2.0.0.tar.gz

Download URL photomancy-2.0.0.tar.gz
Size 275.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b544eef7cb02873eebc9de16ecf5f2f2c71c440c84516a95596d2387e57fc6b1
BLAKE2b-256 checksum
How to use checksums
06324ac73a5545f91a1040a71d1292b78379c96ca8323159f4d1c79ebcc6410c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 28, 2026.

Transparency log

Release files / photomancy-2.0.0-py3-none-any.whl

Download URL photomancy-2.0.0-py3-none-any.whl
Size 284.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ca5b9d7dba7996a4c25d4f9508e00632ac92eab2fb50eeb0390ce6f6cadea72
BLAKE2b-256 checksum
How to use checksums
7d11d6583fc69fdda3af693a4c393d448f2d29ae2ccb9a39900d0d9dd19b8f4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 28, 2026.

Transparency log

Security for photomancy 2.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for photomancy-2.0.0.tar.gz

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 Nov 28, 2026.

Transparency log

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