Skip to main content

gpimg

Exact O(n) two-dimensional Gaussian processes for multi-band light curves.

gpimg fits a Gaussian process jointly in time and wavelength to a multi-band light curve and returns the posterior flux on any time × wavelength grid. The kernel is a Matérn-3/2 in time times a squared exponential in ln λ:

k((t,λ),(t',λ')) = A² (1 + √3|t−t'|/ℓt) exp(−√3|t−t'|/ℓt) · exp(−(ln λ − ln λ')² / 2ℓλ²)

Because the time kernel is a linear stochastic differential equation and the kernel is separable, a light curve observed in up to six bands is exactly a small linear Gaussian state-space model. gpimg evaluates the likelihood, its analytic gradient, maximum-likelihood fits and posterior images with Kalman filters and smoothers in O(n), with no approximation.

  • Exact: likelihoods agree with a dense Cholesky GP to ~1e-11 (relative).
  • Fast: one likelihood + gradient of an 18 668-point light curve in 4.7 ms on one core; a fit of a typical deep-drilling LSST light curve (~660 points) in ~19 ms with five starts — 279× faster than PISCOLA's GP fit, and 1 100× faster for wide-fast-deep light curves (~64 points).
  • Compiled C core, no JIT and no warm-up; AVX2 + FMA code selected at run time; OpenMP batches.
  • Posteriors at any wavelength, smoothed or causal (real time), with an optional numerically stable Rauch–Tung–Striebel smoother, and exact band–band covariances for colors.
  • Optional fitted jitter for scatter the quoted errors do not describe; off by default, and off costs nothing.
  • Python package and plain C library (Makefile, CMake, pkg-config).

Documentation: the Sphinx sources under docs/ (guide, Python API, C API, theory). A hosted build is not up yet.

Installation

$ pip install gpimg

gpimg ships as a source distribution, so this compiles the C core for your machine: you need a C compiler (gcc or clang). OpenMP is optional — without it gpimg.batch runs serially and everything else is unaffected. An AVX2 + FMA copy is built alongside the portable one and chosen at import when the CPU supports it.

From a source checkout, which also gets you the plain C library:

$ pip install .                        # the Python package
$ pytest                               # optional: pip install ".[test]" first
$ make -C c && make -C c test          # the C library: build/libgpimg.so, build/libgpimg.a
$ sudo make -C c install               # or: cmake -S c -B build && cmake --build build

Python quick start

import numpy as np
import gpimg

# t [days], band ('u','g','r','i','z','y' or 0..5; LSST by default), flux and flux_err in any flux unit
gp = gpimg.GP(t, band, flux, flux_err)
res = gp.fit()                                     # maximum likelihood, 5 starting points
print(res.amplitude, res.length_time, res.length_wave, res.message)
res = gp.fit(jitter=True)                          # + a white jitter for extra scatter; res.jitter

img = gp.predict(np.linspace(-30, 120, 300),       # times [d]
                 np.geomspace(3200, 10200, 200))   # wavelengths [Å]
img.mean.shape, img.std.shape                      # (200, 300): wavelengths x times

curves = gp.predict_bands(np.linspace(-30, 120, 300))     # {'u': (mean, std), ...}
curves, covs = gp.predict_bands(t_grid, cov=True)         # + {('g','r'): cov, ...} for color errors
live = gp.predict(t_grid, causal=True)                    # filtered: data up to each time only
stable = gp.predict(t_grid, wave_grid, smoother="rts")    # numerically stable smoother

Many light curves from one long table (pandas, astropy, dict of arrays), fitted and imaged in parallel:

lcs = gpimg.LightCurves.from_table(table, id="oid", t="t", band="band", flux="flux", flux_err="flux_err")
res = gpimg.batch(lcs, np.linspace(-30, 120, 300), np.geomspace(3200, 10200, 200))
res.mean.shape        # (n_objects, 200, 300), float32

Other surveys: gpimg.GP(t, band, flux, err, wavelengths={"g": 4800.0, "r": 6400.0, "i": 7900.0}).

Runnable examples are in examples/ (quickstart.py, batch_table.py, causal_vs_smoothed.py, other_survey.py).

C quick start

#include "gpimg.h"

double lnwave[6];                               /* ln of the band wavelengths */
gp_fit_opts opts;
gp_fit_default_opts(&opts);
opts.nstart = 5;
gp_fit_result res;
gp_fit(n, t, band, y, err, lnwave, theta0, &opts, &res);                  /* res.theta = (ln A, ln lt, ln ll) */
gp_image(n, t, band, y, err, 6, lnwave, res.theta, nt, tg, nl, lng, mean, var, GPIMG_SMOOTH(GPIMG_RTS));
/* gp_image_cov(...) additionally fills cov[npair][nt] for pairs (pa[p], pb[p]) of grid wavelengths */

See c/examples/example.c and the C API reference in docs/c_api.rst.

Performance and accuracy

Single core, Intel Core Ultra 7 255U; simulated LSST light curves (details in docs/guide/performance.rst and docs/guide/accuracy.rst).

likelihood + gradient gpimg dense GP (tinygp, warm) smolgp, same model (warm)
1 000 points 0.20 ms 165 ms 12 ms
12 000 points 2.8 ms 242 s 0.27 s
18 668 points 4.7 ms — 0.41 s
median per fit DDF (~660 points) WFD (~64 points)
gpimg, 5 starts 18.7 ms 1.7 ms
PISCOLA as shipped 4.95 s 2.17 s

Against a dense double-precision GP with the same hyperparameters: likelihood ≤ 3.5e-11, gradient ≤ 8.4e-9 and posterior mean ≤ 1.1e-10 (relative). With smoother="rts" the posterior variance agrees with a 200-bit reference to 7e-10 at the grid points where the default smoother is worst (4.8e-3).

Citing

A paper describing gpimg is in preparation (ApJ Letters). Until then please cite the software and the works in the references (docs/references.rst), in particular Hartikainen & Särkkä (2010) for the state-space formulation of temporal Gaussian processes.

License

MIT — see LICENSE.

Metadata

Release files for gpimg 0.1.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 gpimg 0.1.0
File Size Uploaded Provenance Actions
gpimg-0.1.0.tar.gz 59.0 kB Without provenance Details for gpimg-0.1.0.tar.gz

Release files / gpimg-0.1.0.tar.gz

Download URL gpimg-0.1.0.tar.gz
Size 59.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cf83faa0b059dfb114e59986c1eb5b209bbee0373d6f1672de49a3ef8fd5ac9e
BLAKE2b-256 checksum
How to use checksums
15dfa02907d4233c9588dfdf4ee53555adabeadd15b2fcd8434bb20733e15e2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for gpimg 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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