astronereus
Python client for Nereus, a Julia package for
Bayesian orbit inference: radial velocities, transits, absolute and relative
astrometry, Rossiter-McLaughlin, Doppler tomography, TTVs, spectroscopic binaries
and trans-dimensional planet counts, alone or jointly. This page documents
astronereus 0.4.48 against Nereus 0.9.9. Source:
jvines/nereus-py; licence:
LICENSE.
You do not need Julia. astronereus fetches a prebuilt Nereus runtime on first use,
starts it as a separate process (a warm daemon) and sends it JSON jobs. Nothing is
compiled at install time, and the daemon stays up between calls, so Julia's start-up
cost is paid once per session, not once per fit.
Tutorial. examples/tutorial_rv_transits_astrometry.ipynb
fits published systems from public data, adding one kind of data at a time: NGTS-6 b
from radial velocities and then with TESS transits, Gaia-4 b from Gaia DR4 epoch
astrometry alone and with velocities, and HD 114762 b from 29 years of velocities
with Gaia DR4. It is saved with its output, as run with astronereus 0.4.38.
Contents
- Install
- Sessions
- Getting data in
- Pre-fit tools
- Fit modes
- Radial velocities
- Transits
- RV and transit together
- Rossiter-McLaughlin
- Doppler tomography
- Transit timing variations
- Spectroscopic binaries
- Astrometry
- RV and HGCA
- Adding GOST
- Hipparcos and Gaia epoch astrometry (
iad)
- Relative astrometry (imaging)
- Getting the catalogue data
- Priors
- Samplers
- Trans-dimensional fits
- Results
- Job configs (
run_job)
- Known limitations
Install
pip install astronereus
The first call that needs Julia fetches the runtime (about 480 MB on
macos-arm64), unpacks it and warms it once, and says so:
astronereus: no Julia runtime yet -- fetching it once now.
astronereus: fetching runtime (macos-arm64, julia 1.13.3) ...
astronereus: unpacking ...
astronereus: warming the runtime (one-time, a few minutes) ...
astronereus: ready (207s)
Wheels have no post-install hook, so pip cannot do this step. To do it ahead of a
workshop or a flight:
python -c "import astronereus; astronereus.install()"
NEREUS_NO_AUTO_INSTALL=1 turns the automatic fetch off; the first call then fails
with instructions instead. Use it in CI and on air-gapped machines.
The distribution and the import are both astronereus. The name nereus on PyPI
belongs to an unrelated geophysics package.
Optional extras
The base install has one dependency (zstandard, to unpack the runtime). Everything
else is imported lazily, so install only what you use:
pip install "astronereus[arrays,tables]"
| extra |
installs |
enables |
arrays |
numpy |
numpy arrays in payloads. astronereus never imports numpy itself; lists, pandas columns and astropy columns also work |
tables |
pandas |
tables as pandas DataFrames in RV.from_table / Transit.from_table |
vizier |
astroquery |
RV.from_vizier |
lightcurves |
lightkurve |
Transit.from_lightkurve |
diagnostics |
netCDF4, arviz |
R-hat and ESS in result.diagnostics, recomputed from the saved chains |
zstd |
zstandard |
unpacking the runtime bundle. The base install already pulls it in, except on Python 3.14+, which unpacks with the standard library |
Runtime bundles
Prebuilt runtimes are attached to the
Nereus.jl releases with SHA256SUMS
alongside. install() picks the one for your platform and checks it against the
published checksum.
| platform |
size |
macos-arm64 |
466 MiB |
linux-x86_64 |
690 MiB |
linux-aarch64 |
650 MiB |
Every process after the first install() starts a session in about twenty seconds.
Windows is not supported.
Upgrading the package does not refresh a runtime you already have: the bundle is a
separate download, cached outside site-packages. When a release ships against a newer
Nereus, session() tells you at start-up. Fetch it with:
python -c "import astronereus; astronereus.install(force=True)"
For a classroom, fetch the bundle once and point everyone at the local copy:
export NEREUS_BUNDLE_URL=~/nereus-runtime-1.13.3-macos-arm64.tar.zst # path or file:// URL
NEREUS_HOME moves the runtime cache out of the default platform cache directory
(~/Library/Caches/nereus on macOS, $XDG_CACHE_HOME/nereus or ~/.cache/nereus
on Linux).
Update warnings
The first time a session starts, astronereus looks up the latest astronereus on PyPI
and the latest Nereus.jl release, and
emits an astronereus.UpdateAvailableWarning (a UserWarning) if either is ahead of
what you have. The client is compared with PyPI. The Nereus compared is the one your
client runs against: a client pins its runtime, so a Nereus release that no
astronereus ships yet is reported as such rather than as something you can update.
If you set NEREUS_JULIA or NEREUS_BUNDLE_URL you are running your own Nereus, and
only the client is compared.
The check runs once per process on a background thread with a 2 s timeout, fails
silently, and is cached for 24 hours in the runtime cache directory. It never runs at
import. To turn it off, set ASTRONEREUS_NO_UPDATE_CHECK=1 (it is also off when CI
is set) or filter the class:
warnings.simplefilter("ignore", astronereus.UpdateAvailableWarning)
astronereus.check_updates() runs it on demand, ignoring the opt-out and the cache,
and returns an UpdateStatus with the installed and latest versions.
Sessions
Every call goes to a Julia daemon. You can leave its lifetime implicit or hold it
yourself.
import astronereus
# One-shot: a process-wide daemon starts on first use, is reused, and closes at exit.
ds = astronereus.dataset("51peg")
astronereus.ping()
# Explicit: one daemon for the block, closed when it exits.
with astronereus.session() as s:
ds = s.dataset("51peg")
print(s.ping())
{'julia': '1.13.3', 'threads': 16, 'cpu': 'generic', 'api': 3, 'nereus': '0.9.9', 'pong': True}
Everything the module-level functions do is also a method on the session
(s.fit_rv, s.fit_joint, s.read_rv, s.dataset, ...), and the methods bind
themselves to that session. Prefer with astronereus.session() as s: for anything
beyond one call: the lifetime is explicit, and s.detect, s.detrend and
s.tomogram exist only there.
Cost. Starting a session takes about 20 s once the runtime is installed (loading
Nereus into a fresh Julia process). After that, calls are cheap, but each Julia
function is compiled on its first use in a session: the first s.detect.rv_periodogram
took 19 s and the first s.detrend.gp 40 s in a fresh session. A session that stays
open keeps that work, so keep one open across a script or notebook.
session() accepts threads (default "auto"), startup_timeout (300 s) and
idle_timeout (1800 s). The daemon exits by itself if its parent process dies or if
nothing talks to it for idle_timeout seconds.
| member |
use |
s.ping() |
liveness plus the Julia version, thread count, CPU target, API version and the Nereus version of the runtime |
s.log_path |
the daemon's stdout/stderr log. Read it when a job dies |
s.raw(action, payload) |
call a daemon action by name. An escape hatch for actions newer than the client |
s.close() |
stop the daemon. Called for you by the with block |
run_job(config) (module level and on the session) takes a Nereus job config dict;
see Job configs. The typed fit_* entry points described in
the later sections are the usual route.
Stopping a fit early
Four ways to end a PT fit (PTEmcee, the default, and TransdimPTEmcee) before
its n_steps and keep the draws. The sampler stops at the last fully recorded
step and the fit finishes normally: chains, tables and plots are written, and
r.summary["stopped"] (or r.stopped) says why, with stopped_at_step,
n_steps and n_draws_kept beside it.
| how |
stopped |
| Ctrl-C, or the stop button in a notebook, after burn-in |
"interrupted" |
engines.PTEmcee(convergence_stop=True, rhat_threshold=1.01, tail_ess_threshold=1000) (or Stopping(rhat_max=..., ess_min=...)) |
"converged" |
Stopping(max_seconds=3600) or max_evals= |
"max_seconds" / "max_evals" |
a file appears at stop_file= (default <output_dir>/STOP) |
"requested" |
r = s.fit_rv(ds.rv, planets=1, output_dir="out",
stopping=astronereus.Stopping(rhat_max=1.01, ess_min=1000))
r.stopped # "converged" -- the run ended early with a usable posterior
Ctrl-C asks for the graceful stop and the call keeps waiting for the result,
which comes back with a RuntimeWarning naming the step. Ctrl-C again aborts
instead and discards the draws. An interrupt during burn-in aborts too, since
there are no draws yet.
The convergence gate is off by default. For TransdimPTEmcee it watches the
model index, the planet-slot parameters (over the draws where each slot is
active) and rho_s, and the progress bar shows live Rhat and ESS either way.
Stopping.logz_tol sets dlogz for the nested engines; a Stopping field the
engine cannot honour raises and names the engines that can. These need a runtime
newer than 0.8.10 (see Runtime bundles).
From outside the process (a worker, a web front end), create the stop file:
pathlib.Path("out/STOP").touch() # looked for every ~5 s; never deleted for you
Interrupting a fit
Ctrl-C (or the stop button in a notebook) reaches both Python and the Julia
sampler. After burn-in it is a graceful stop, above. Otherwise (during burn-in, a
second Ctrl-C, or an engine that cannot stop early) the fit is cancelled,
FitInterrupted is raised, nothing is written to output_dir, and the daemon
stays up and warm:
try:
s.fit_rv(ds.rv, planets=1, output_dir="out")
except astronereus.FitInterrupted:
pass
s.ping() # still answers; the next fit reuses the same session
A timeout= (seconds) on run_job stops waiting, but does not stop the Julia job.
Call s.close() if you need it dead.
Errors
| exception |
when |
DaemonError |
Julia raised. The message carries the Julia error and backtrace. s.log_path has the daemon's full output |
FitInterrupted |
the fit was cancelled (above). A RuntimeError subclass |
RuntimeVersionError |
at session start: the cached runtime speaks a different API version than this client |
BundleError |
the runtime bundle could not be fetched, verified or unpacked |
try:
s.detect.transits(t=t) # forgot flux, flux_err
except astronereus.DaemonError as e:
print(str(e).splitlines()[0]) # missing required argument flux. Got: t
RuntimeVersionError names the fix: when the cached runtime is older than the client,
refresh it with astronereus.install(force=True); when it is newer, upgrade the
package. NEREUS_SKIP_API_CHECK=1 bypasses the check, and the mismatch then surfaces
as a Julia error in the middle of a fit.
A runtime that is older than the client but speaks the same API is not an error. The
session starts and prints to stderr that the cached runtime is Nereus X while the
client ships against Y, with astronereus.install(force=True) as the remedy. It is
printed once per session. Fixes in the newer runtime are not present until you
refresh it.
Getting data in
Every channel takes its data as {instrument: {t, <value>, <error>}}, with times in
MJD (days) and one instrument label per independent data source. Each instrument gets
its own offset and jitter downstream. There are three ways in: a file, a table or
arrays you already hold in Python, and the datasets Nereus ships.
Time conventions
Nereus models in MJD. time_offset is subtracted from the time column, and is applied
the same way by every reader and constructor below.
| call |
default time_offset |
effect |
read_rv, RV.from_file |
2400000.5 |
BJD in, MJD out. Pass 0 for times already in MJD |
read_photometry, Transit.from_file |
0.0 |
times are returned as read. For a BJD file pass time_offset=2400000.5 |
from_arrays, from_table, from_vizier |
"auto" |
see below |
"auto" subtracts 2400000.5 when the median time exceeds 2,000,000 (a full Julian
Date) and leaves the column alone otherwise (an MJD). It cannot recognise
mission-relative clocks: TESS BTJD (BJD - 2457000) and Kepler BKJD (BJD - 2454833)
look like small numbers and pass through unchanged. Give the offset yourself, with the
sign that makes t - offset an MJD:
TESS_BTJD_TO_MJD = 2400000.5 - 2457000 # t_mjd = t_btjd - (2400000.5 - 2457000)
Transit.from_arrays(btjd, flux, err, time_offset=TESS_BTJD_TO_MJD)
Transit.from_lightkurve avoids the problem by reading the epoch off the astropy
Time object.
Arrays and tables
import numpy as np
from astronereus import RV, Transit
rv = RV.from_arrays(t_bjd, rv_ms, err_ms, instrument="HARPS") # BJD -> MJD automatically
instrument is one label for every row, or a per-row sequence of labels. rename
maps labels to the names your priors use. Rows with a non-finite time, value or error
are dropped.
From a table, with the column names guessed or given: