Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

tracerax: Lagrangian particles and trajectories for JAX

tracerax carries positions forward in time and analyses where they went: particle seeding, deterministic and stochastic advection, binning to grids, footprints, finite-time Lyapunov exponents, residence times and connectivity. It sits at GeoNumerics tier 2, on functax’s interpolation, integrix’s stepping and geophysix’s sphere, and takes over the particle machinery now inside plumax. Status: built, with the consumers still to switch.

At a glance

Layer, tierGeoNumerics, tier 2
Importsfunctax, integrix and geophysix; diffrax, JAX, Equinox, einx; gridax as the gridax extra
Imported byplumax, sesmax-ocean and xrops, all planned
Takes overplumax lagrangian: ParticleState, langevin_step, integrate_particles, GriddedWind, bin_positions, compute_footprint and the generic loop of simulate_lagrangian
Does not ownoperators on fields, including semi-Lagrangian advection, whose departure points are discarded (integrix); turbulence closures, plume physics and source inversions (plumax); interpolation and binning (functax); steppers and adjoints (integrix)
Statusbuilt: jejjohnson/tracerax, Waves 0 to 3 of the backlog of geostack#304; Wave 4, the consumers, is open
Tracked inthe layer map; the companion integrix and gridax designs
where tracerax sits · GeoNumerics tier 2

Where tracerax sits · geonumerics tier 2.

The line with integrix: a scheme that discards its departure points after each step is integrix’s (integrix.march.semi_lagrangian_step, integrix#92); anything whose state is the positions themselves is tracerax’s. This page is the design; core types, algorithms and the code survey are in tracerax: design details.

The problem

Two questions about a methane plume are Lagrangian. Forward: where does the gas from this source go, and what concentration does it leave in each pixel? Backward: which surface cells could have produced the enhancement this satellite pixel saw? Both release particles, move them with the wind plus turbulence, and count where they end up:

StepWhat it computesWhere plumax codes it (96449d2, under lagrangian/_src/)
Release and carry particlesa particle state (positions and velocities, all released at t = 0), a Markov-1 Langevin step and its loopparticles.py: ParticleState, langevin_step, integrate_particles
Wind at each particlea wind read from a grid in space and time, since plumax#180wind_interp.py: GriddedWind
Concentration on a gridparticles binned to cellsconcentration.py: bin_positions, simulate_lagrangian
Sensitivity of a receptor to surface fluxesbackward integration and residence near the groundfootprint.py: compute_footprint
Turbulence for the stepσ_w(z) and τ_L(z)turbulence.py: HannaTurbulence, HomogeneousTurbulence; stays
Meteorological ensembles, a footprint emulatormany footprints, and a model of themmet_ensemble.py, emulator.py; stay
Transport barriers, retention, connectivityFTLE, residence time, connectivity matricesnowhere; tracerax.analysis has them since Wave 3

The particle machinery is generic, but it sits inside a plume model, so the ocean side (sesmax’s drifters, larval connectivity, retention in eddies) and xrops’ planned Lagrangian views would have had to import plumax to use it, or write it again.

Positions carried forward

The state of a Lagrangian calculation is a set of N particles: positions xₚ, masses mₚ, a release time per particle, an active flag, and the step’s memory (the velocity fluctuation u’ₚ of a stochastic model, or an object’s own velocity). Everything in tracerax either moves that state or reads it.

Deterministic advection. Each particle follows the resolved wind, dxₚ/dt = u(xₚ, t), with u at the particle’s position read from a grid by a functax interpolant and the step taken by an integrix or diffrax solver. On the sphere the step works on unit vectors, so a path crosses the date line and the poles.

Stochastic advection. Unresolved turbulence enters as a Markov-1 Langevin model for the velocity fluctuations: an Ornstein–Uhlenbeck update on all three components, as plumax does it, with the well-mixed drift of Thomson (1987) acting in the vertical, with σ_w(z) the velocity standard deviation and τ_L(z) the Lagrangian time scale supplied by a turbulence closure:

duw′=−uw′τLdt+12∂σw2∂z(1+uw′2σw2)dt+2σw2τLdWdu'_w = -\frac{u'_w}{\tau_L} dt + \frac{1}{2} \frac{\partial \sigma_w^2}{\partial z} \left( 1 + \frac{u_w'^2}{\sigma_w^2} \right) dt + \sqrt{\frac{2 \sigma_w^2}{\tau_L}} dW

Particles reflect at the ground and, when it is given, at the top of the boundary layer, by a fold that leaves none outside however far a step goes.

Diffusion and inertia. A surface drifter has a diffusivity in place of a closure, and follows a random displacement with the drift ∂K/∂x that keeps a uniform cloud uniform. A buoyant object of finite size follows the Maxey–Riley equation for the surface ocean, or its slow manifold.

Binning. The concentration in cell j of volume Vⱼ is the particle mass inside it:

cj=1Vj∑pmp1[xp∈j]c_j = \frac{1}{V_j} \sum_p m_p \mathbb{1}[x_p \in j]

Footprints. Released backward in time from a receptor, particles that spend time near the ground say how sensitive the receptor is to a surface flux in each cell. With h_s the depth of the surface layer and ρ the air density:

Fj=1Nρhs∑p∫1[xp(t)∈j,zp(t)<hs]dtF_j = \frac{1}{N \rho h_s} \sum_p \int \mathbb{1}[x_p(t) \in j, z_p(t) < h_s] dt

Trajectory analysis. With Φ the flow map that carries a position from t₀ to t₁, the finite-time Lyapunov exponent measures how fast neighbours separate; its ridges are transport barriers:

Λ(x0)=1∣t1−t0∣ln⁡λmax⁡(∇Φ(x0)⊤∇Φ(x0))\Lambda(x_0) = \frac{1}{|t_1 - t_0|} \ln \sqrt{\lambda_{\max}\left( \nabla\Phi(x_0)^\top \nabla\Phi(x_0) \right)}

In JAX the gradient of the flow map is the forward-mode derivative of the integration itself, so no finite-difference grid of seeds is needed. Residence time counts how long particles stay in a region; a connectivity matrix Cᵢⱼ counts the fraction released in region i that reaches region j.

Modules and boundaries

Six modules. The particle state is an Equinox module of arrays, so it is a pytree that jax.lax.scan, jit and vmap carry as plumax’s already is.

ModuleOwnsComes from
tracerax.particlesthe particle state, with a release time per particle; the step protocol ParticleStep; seeding at points, along lines, in boxes and over timeplumax ParticleState; releases over time are new
tracerax.velocityvelocities at particles, velocity(t, position): uniform, gridded through a functax Interpolant on staggered nodes, and weighted sums (a current and a share of the wind)plumax GriddedWind, uniform_wind
tracerax.advectone loop that runs any step; deterministic steps, on the plane and on the sphere, and the Langevin, random-displacement and inertial steps; the TurbulenceModel and Diffusivity protocols; walls and the domainplumax langevin_step, integrate_particles, n_steps_for_horizon, step_durations; the rest is new
tracerax.bincells from edges, deposits that keep the mass at walls, accumulated residence, concentrationsplumax bin_positions and the accumulation in simulate_lagrangian
tracerax.footprintbackward runs from receptors and surface footprintsplumax compute_footprint
tracerax.analysisFTLE, residence time and connectivity of labelled regions, absolute and pair dispersion, the skill of a trajectorynew; the stub in xrops metrics/_src/lagrangian.py wraps it

What tracerax owns, and what it hands off

The test for every name: is its state a set of positions carried forward in time, or does it analyse such positions? Then tracerax owns it.

Neighbourtracerax ownsThe neighbour ownsThe line
integrixthe right-hand side, the loop and the boundariessolvers, adjoints through time, semi-Lagrangian schemesdeparture points that are discarded are integrix’s; positions kept from step to step are tracerax’s
gridax, spectraldiffxparticles that persistoperators on fieldsa field’s state stays on its grid
plumaxthe particle machineryturbulence closures (HannaTurbulence, σ_w(z) and τ_L(z) profiles), plume physics, source inversionsparticles take the closure as an argument
functaxwhere the particles go, the cellsreading a grid at points and its transpose, axes with edges, cell areas (quad.cell_area)tracerax calls functax interpolants and plans
geophysixpaths on the spherethe sphere’s radius and the great-circle distancepassed as an Ellipsoid record, earth=
gridax—staggered coordinates and masks of a model’s gridan adapter behind the gridax extra, when a consumer needs it
diagnostixLagrangian analysis and trajectory skillEulerian diagnostics of fieldsFTLE is tracerax’s; vorticity is diagnostix’s
xropsthe mathsDataArray views of trajectories (geotoolz#696)xrops wraps tracerax

What moves in

FromWhatIts users then import
plumax lagrangian/_src/particles.pyParticleState, langevin_step, integrate_particles, n_steps_for_horizon, step_durations, the TurbulenceModel protocoltracerax.particles, tracerax.advect; the closures stay and satisfy tracerax’s protocol
plumax lagrangian/_src/wind_interp.pyGriddedWind and its helperstracerax.velocity.GriddedVelocity; the functions that build one from meteorology stay
plumax lagrangian/_src/concentration.pybin_positions, the generic loop of simulate_lagrangiantracerax.bin; plumax keeps a plume-specific simulate_lagrangian built on it
plumax lagrangian/_src/footprint.pycompute_footprinttracerax.footprint.surface, behind a thin call
xropsthe empty Lagrangian metrics stubtracerax.analysis, wrapped by xrops

In use

The plume both ways: release particles at the source and bin them into a concentration field; release them backward from a satellite pixel and read its surface footprint.

# Shapes: N particles; Nx × Ny × Nz cells, Nx × Ny of them at the surface

import jax
import jax.numpy as jnp
from plumax.lagrangian import HannaTurbulence
from tracerax.advect import Langevin, Walls, integrate
from tracerax.bin import Cells, concentration
from tracerax.footprint import surface
from tracerax.particles import at_point, release_times, with_turbulent_velocity
from tracerax.velocity import GriddedVelocity

start_key, forward_key, backward_key = jax.random.split(jax.random.key(0), 3)

# today (tracerax)
# u_d(t, x) = ∑ₛ wₛ c_{d, iₛ}, each component on its own staggered grid
wind = GriddedVelocity.fit(grids, (u, v, w))
# today* (plumax)
# σ(z), τ_L(z) from boundary-layer scaling, as an eqx.Module
turbulence = HannaTurbulence(...)
walls = Walls(bottom=0.0, top=boundary_layer_height)
cells = Cells((x_edges, y_edges, z_edges))

# --- forward: where the gas goes ---
# today (tracerax)
# one release time per particle
state = at_point(  # N particles
    source, N, mass=rate * duration, release_time=release_times(0.0, duration, N)
)
# today (tracerax)
# u' ~ 𝒩(0, σ(z)²)
state = with_turbulent_velocity(state, turbulence, key=start_key)
# today (tracerax)
# du' = −u'/τ_L dt + ½ ∂σ_w²/∂z (1 + u'²/σ_w²) dt + (2σ_w²/τ_L)^½ dW
result = integrate(
    state,
    Langevin(wind, turbulence, walls),
    t0=0.0,
    duration=duration,
    step_size=2.0,
    key=forward_key,
)
# today (tracerax)
# c_j = ∑ₚ mₚ 1[xₚ ∈ j] / V_j
field = concentration(result.state, cells, t=duration)  # → (Nx, Ny, Nz)

# --- backward: what the pixel could have seen ---
# today (tracerax)
# F_j = ∑ₚ ∫ 1[xₚ(t) ∈ j, zₚ(t) < h_s] dt / (N ρ h_s)
footprint = surface(
    receptor,
    wind,
    turbulence,
    Cells((x_edges, y_edges)),
    n_particles=N,
    receptor_time=duration,
    duration=600.0,
    step_size=2.0,
    surface_depth=100.0,
    air_density=1.2,
    key=backward_key,
    walls=walls,
)
sensitivity = footprint.sensitivity  # → (Nx, Ny)

The footprint times a prior flux map is the pixel’s predicted enhancement, which is what an inversion in plumax fits. Because the run is a JAX function, the same footprint is differentiable in the wind and the closure’s parameters.

Integration across the stack

ConsumerUses todayWith tracerax
plumaxits own particle state, wind, Langevin step, binning and footprinttracerax for all five; keeps the turbulence closures, the plume-specific simulation, the ensembles, the emulator and the inversions
sesmax-ocean (planned)—drifters, inertial particles, retention in eddies and connectivity on its own velocity fields
xropsan empty Lagrangian stubDataArray views of trajectories and of tracerax.analysis

For plumax the change is an import, and the argument order of a wind, which becomes velocity(t, position):

# Today:
# today (plumax)
from plumax.lagrangian.particles import ParticleState, langevin_step

# After:
# today (tracerax)
from tracerax.particles import ParticleState

# today (tracerax)
from tracerax.advect import langevin_step

Decisions and open questions

All decided but decision 7. The owner took decisions 1 to 6 and 8 to 12 on 23 Nov 2026, after a scan of 25 stack repositories; the measurements are in tracerax#14. Each entry gives the position first, then the trade-off.

1. Layer and dependencies

Decided: GeoNumerics tier 2, on functax, integrix and diffrax; geophysix for the sphere; gridax as an extra; nothing else from the stack. The cells and their volumes come from functax (Axis edges, quad.cell_area), so a grid library is not needed to bin particles. GeoStack may import GeoNumerics (geostack#306), so xrops may wrap tracerax.

2. The line with the Eulerian libraries

Decided. A scheme that traces back to departure points and then discards them is integrix’s (integrix.march.semi_lagrangian_step). tracerax owns everything whose state is the positions.

3. Turbulence closures stay in plumax

Decided: tracerax defines the protocol. Particles take σ(z) and τ_L(z) through TurbulenceModel, any object with at(height), and plumax’s closures satisfy it. So sesmax-ocean can write its own closures without plumax.

4. Stepping through integrix or a loop of its own

Decided: one loop, which runs any step. Deterministic steps use integrix’s and diffrax’s solvers. The Langevin step reflects particles at walls, a discrete event that diffrax’s SDE solvers handle awkwardly, so it is tracerax’s. Every step is a ParticleStep, and the loop scans it with integrix.adjoint.checkpointed_scan or truncated_scan.

5. Trajectories stored or accumulated

Decided: accumulate by default. A footprint or a concentration needs only running sums, an Accumulator inside the scan; storing K × N × 3 positions is optional, every few steps.

6. Randomness and time

Decided. One key per run, split up front into one key per step, or the noise itself passed in. A run has a start that may be traced and a static signed duration, negative for a backward run; times inside it are offsets, because float32 resolves only 128 s at Unix-epoch seconds.

7. Coastlines and other boundaries

Open, for Wave 4. The ground and the boundary-layer top fold a particle any number of times. A coastline waits for an ocean consumer: on unstaggered grids the velocity is extended onto land with a slip coefficient. Putting a particle back on the nearest wet cell was measured and made coasts worse, so it is not planned.

8. Diffusion

Decided. A random displacement with the drift ∂K/∂x, without which particles gather where K is small at every step size. The closures that give K stay upstream.

9. Inertial particles

Decided. The Maxey–Riley equation is a step with the object’s velocity as its memory, forward only, and its slow manifold is a velocity, which runs backward and on the sphere.

10. Trajectory skill

Decided: tracerax’s, so that it can be a loss. Scores of an ensemble are not particle calculations, and are not here.

11. Gaps found in functax

Decided: issues there, worked around here. Nearest binning ignores an axis’s edges (functax#168) and linear binning drops the outer half cells (functax#169).

12. JAX only

Decided. functax’s interpolation and integrix both require JAX. Nothing inside the library calls jax.jit; the caller does, once, at the top.

Roadmap

Five waves, each a GitHub issue epic in the tracerax repository. The umbrella is geostack#304.

WaveDeliversEndsState
0. Scaffold and decisionsthe repository from the library template; CI, capability index; reference tests against plumax’s stored outputs—done, v0.0.1
1. Particles and advectiontracerax.particles, tracerax.velocity, tracerax.advectplumax’s particle state, wind and Langevin stepdone, v0.0.2
2. Deposits and footprintstracerax.bin, tracerax.footprintplumax’s binning and footprintdone, v0.0.3
3. The sphere and trajectory analysisparticles on the sphere and inertial ones; FTLE, residence time, connectivity, dispersion, trajectory skillthe xrops stubdone, v0.0.4
4. Consumers switchplumax onto tracerax; xrops’ Lagrangian epic; sesmax-ocean from the start; coastlinesthe copiesopen

Sources

References
  1. Thomson, D. J. (1987). Criteria for the selection of stochastic models of particle trajectories in turbulent flows. Journal of Fluid Mechanics, 180, 529–556.
  2. Lin, J. C., Gerbig, C., Wofsy, S. C., Andrews, A. E., Daube, B. C., Davis, K. J., & Grainger, C. A. (2003). A near-field tool for simulating the upstream influence of atmospheric observations: the Stochastic Time-Inverted Lagrangian Transport (STILT) model. Journal of Geophysical Research: Atmospheres, 108(D16), 4493.
  3. Haller, G. (2015). Lagrangian coherent structures. Annual Review of Fluid Mechanics, 47, 137–162.