Skip to content

Gaussian plume

Steady-state Gaussian plume with Briggs dispersion, plus NumPyro emission-rate inference. Tier I.

gauss_plume

Steady-state Gaussian plume model (JAX + NumPyro).

Submodules
  • dispersion — Briggs σ_y(x), σ_z(x) coefficients (A-F stability classes)
  • plume — coordinate rotation + JIT forward model + xarray wrapper
  • plume_rise — Briggs plume rise Δh(x) and the effective release height
  • column — closed-form column plume with a power-law width, and its backend
  • centreline_prior — Gaussian-process prior on the column plume's centreline
  • inference — NumPyro Bayesian inference for Q (and optional stability)
  • observation — column + averaging-kernel observation shared by every tier
  • likelihoods — Gaussian, Student-t and heteroscedastic observation noise
  • multi_source — masked-K source slots and their posterior

The inference submodule is imported lazily on first attribute access so that from plumax import gauss_plume does not pull in NumPyro for consumers of only the forward model.

plume_concentration_vmap module-attribute

plume_concentration_vmap = vmap(plume_concentration, in_axes=(0, 0, 0, None, None, None, None, None, None, None), out_axes=0)

Vectorised over receptor locations — x, y, z batched along axis 0.

CentrelinePrior

Bases: Module

Prior covariance of the centreline knots.

[K_DD]_jk = k₀(d_j, d_k), with k₀(d, d') = k(d, d') − k(d, 0) k(0, d') / k(0, 0) and k the Matérn-3/2 kernel, k(d, d') = σ_m² (1 + √3 r / ℓ) exp(−√3 r / ℓ), r = |d − d'|. The marginal variance is σ_m² (1 − ρ(d)²), with ρ(d) = (1 + √3 d / ℓ) exp(−√3 d / ℓ): zero at the source and σ_m² far downwind. The random walk k(d, d') = κ² min(d, d'), κ² = σ_m² / ℓ, is zero at the source already and needs no conditioning.

Algorithm
  1. Evaluate the kernel between the knots, and between the knots and the source at d = 0.
  2. Subtract the rank-one term that conditions on m(0) = 0.
  3. Add a jitter of jitter · amplitude² to the diagonal.

Attributes:

Name Type Description
length_scale float

Length scale ℓ [m].

amplitude float

Standard deviation σ_m [m] far from the source.

kind Literal['matern32', 'random_walk']

"matern32", or "random_walk" for k(d, d') = κ² min(d, d') with κ² = σ_m² / ℓ.

jitter float

Relative diagonal jitter.

Raises:

Type Description
ParameterError

If length_scale or amplitude is not positive, jitter is negative, or kind is unknown.

Examples:

The standard deviation grows from the source and levels off:

>>> import einx
>>> import jax.numpy as jnp
>>> knot_index = jnp.arange(1, 34)
>>> knot_distance = 180.0 * knot_index
>>> prior = CentrelinePrior(length_scale=1000.0, amplitude=300.0)
>>> covariance = prior(knot_distance)
>>> covariance.shape
(33, 33)
>>> std = jnp.sqrt(jnp.diagonal(covariance))
>>> bool(jnp.allclose(std[0], 84.0, atol=1.0))
True
>>> bool(std[-1] > 290.0)
True

The matrix is symmetric:

>>> transposed = einx.id("row col -> col row", covariance)
>>> bool(jnp.allclose(covariance, transposed))
True

A random walk's variance grows as κ² d without limit:

>>> walk = CentrelinePrior(length_scale=1000.0, kind="random_walk")
>>> variance = jnp.diagonal(walk(jnp.array([1000.0, 4000.0])))
>>> bool(jnp.allclose(variance, jnp.array([300.0, 1200.0]) * 300.0))
True
References

Rasmussen and Williams (2006), Gaussian Processes for Machine Learning, ch. 4.

ColumnPlume

Bases: Module

Column of a steady Gaussian plume per unit line density.

r(s; θ) = exp(−(c − m(d))² / 2w²) / (√(2π) w) for d > 0, else 0, with w² = w₀² + w_ref² (d / d_ref)^(2b), so that ΔΩ = q r for q = Q / U. The centreline m(d) is zero for a straight plume.

Algorithm
  1. Rotate the receptors into the plume frame: d = (s − s₀)ᵀ e_∥, c = (s − s₀)ᵀ e_⊥.
  2. Evaluate the width w(d) on d clipped at the source.
  3. Interpolate the centreline m(d), if the geometry has one.
  4. Evaluate the Gaussian ridge, or its average across a pixel.
  5. Apply the upwind cut, hard or as a logistic ramp.

Attributes:

Name Type Description
reference_distance float

Distance d_ref [m] at which the width is w_ref.

initial_width float

Width w₀ [m] at the source; g / √12 stands in for a pixel of side g.

upwind_scale float | None

Length ℓ_u [m] of the logistic ramp at the source; None is the hard cut.

pixel_size float | None

Pixel side g [m] for the crosswind average; None is point evaluation.

knot_spacing float | None

Downwind spacing Δ_d [m] of the centreline knots; required when the geometry carries a centreline.

Raises:

Type Description
ParameterError

If a length is not positive, initial_width is negative, or a geometry with a centreline meets a plume without knot_spacing.

Examples:

The crosswind integral of the response is 1 at every distance:

>>> import einx
>>> import jax.numpy as jnp
>>> crosswind = jnp.linspace(-3000.0, 3000.0, 6001)
>>> downwind = jnp.full_like(crosswind, 2000.0)
>>> receptors = einx.id(
...     "obs, obs -> obs (1 + 1)", downwind, crosswind
... )
>>> geometry = PlumeGeometry(
...     location=jnp.zeros(2),
...     direction=0.0,
...     reference_width=150.0,
...     width_exponent=0.9,
... )
>>> response = ColumnPlume()(receptors, geometry)
>>> response.shape
(6001,)
>>> spacing = 1.0
>>> integral = einx.sum("[obs]", response) * spacing
>>> bool(jnp.allclose(integral, 1.0, rtol=1e-4))
True

Upwind of the source the response is zero:

>>> upwind = jnp.array([[-500.0, 0.0]])
>>> float(ColumnPlume()(upwind, geometry)[0])
0.0

The configuration round-trips:

>>> plume = ColumnPlume(initial_width=17.3, upwind_scale=17.3)
>>> ColumnPlume.from_config(plume.get_config()) == plume
True
References

Seinfeld and Pandis, Atmospheric Chemistry and Physics, ch. 18.

get_config

get_config() -> dict[str, Any]

The five fixed choices, as plain floats.

Source code in src/plumax/gauss_plume/_src/column.py
def get_config(self) -> dict[str, Any]:
    """The five fixed choices, as plain floats."""
    return {
        "reference_distance": self.reference_distance,
        "initial_width": self.initial_width,
        "upwind_scale": self.upwind_scale,
        "pixel_size": self.pixel_size,
        "knot_spacing": self.knot_spacing,
    }

from_config classmethod

from_config(config: dict[str, Any]) -> ColumnPlume

The plume a :meth:get_config dictionary describes.

Source code in src/plumax/gauss_plume/_src/column.py
@classmethod
def from_config(cls, config: dict[str, Any]) -> ColumnPlume:
    """The plume a :meth:`get_config` dictionary describes."""
    return cls(**config)

ColumnPlumeKernel

Bases: Module

G(x, x_s) = r(x; geometry moved to x_s) / U, the column per unit emission rate.

A KernelLike view of :class:ColumnPlume for integrix: the column at a receptor x of a source at x_s emitting 1 kg s⁻¹, in s m⁻², so ΔΩ = G Q. The geometry's direction, widths and centreline are kept and its location is replaced by x_s, so every source carries the same plume shape. integrix.green.green_operator sums it against a rule of sources, u(xᵢ) = ∑ⱼ G(xᵢ, sⱼ) wⱼ Qⱼ, and gives the plume operator 𝒢 with its adjoint, so a gradient in Q costs one forward and one reverse application.

Attributes:

Name Type Description
plume ColumnPlume

The column plume r, with its fixed choices.

geometry PlumeGeometry

The plume geometry; its location is not used.

wind_speed Float[Array, '']

The wind speed U [m s⁻¹], positive.

Examples:

One source of Q = 2 kg s⁻¹ in a 4 m s⁻¹ wind gives q r with q = Q / U:

>>> import jax.numpy as jnp
>>> from functax.quad import Rule
>>> from integrix.green import green_operator
>>> geometry = PlumeGeometry(
...     location=jnp.zeros(2),
...     direction=0.0,
...     reference_width=150.0,
...     width_exponent=0.9,
... )
>>> kernel = ColumnPlumeKernel(ColumnPlume(), geometry, wind_speed=4.0)
>>> source = Rule(jnp.zeros((1, 2)), jnp.ones(1))
>>> receptors = jnp.array([[1000.0, 0.0], [1000.0, 150.0]])
>>> column = green_operator(kernel, source, receptors)(jnp.array([2.0]))
>>> expected = 2.0 / 4.0 * ColumnPlume()(receptors, geometry)
>>> bool(jnp.allclose(column, expected))
True

pairwise

pairwise(x: Float[Array, ' axis'], x_prime: Float[Array, ' axis']) -> Float[Array, '']

G(x, x′) at one receptor x and one source x′.

Parameters:

Name Type Description Default
x Float[Array, ' axis']

Receptor position [m].

required
x_prime Float[Array, ' axis']

Source position [m].

required

Returns:

Type Description
Float[Array, '']

G = r(x; geometry at x′) / U [s m⁻²].

Source code in src/plumax/gauss_plume/_src/column.py
def pairwise(
    self, x: Float[Array, " axis"], x_prime: Float[Array, " axis"]
) -> Float[Array, ""]:
    """G(x, x′) at one receptor x and one source x′.

    Args:
        x: Receptor position [m].
        x_prime: Source position [m].

    Returns:
        G = r(x; geometry at x′) / U [s m⁻²].
    """
    # the geometry with its source at x′
    moved = eqx.tree_at(lambda geometry: geometry.location, self.geometry, x_prime)
    # r(x), one receptor: (axis,) → (1, axis) → (1,)
    response = self.plume(einx.id("axis -> 1 axis", x), moved)
    # G = r / U
    return einx.sum("[obs]", response) / self.wind_speed

ColumnPlumeSource

Bases: AbstractControlledSource

A column plume as a controlled coupled transport backend.

r_inst = A_inst ⊙ r(s_inst; θ), the column per unit line density at an instrument's receptors, through its averaging kernel. The coupled forward then predicts y = q r_inst + Ω_bg + bias.

It declares the geometry as control blocks: location (2,), direction (), log_reference_width () and width_exponent (), and centreline (K,) when the geometry carries K knots, scaled by line_density or log_line_density. Q and U enter the column only as q = Q / U, so there is no wind block and no emission_rate; the wind is applied after the fit (CoupledResult.with_wind).

Attributes:

Name Type Description
plume ColumnPlume

The column model and its fixed choices.

geometry PlumeGeometry

The geometry the response is evaluated at.

background float

Additive background column Ω_bg [kg m⁻²].

Examples:

The response through a unit averaging kernel is the plume's own:

>>> import jax.numpy as jnp
>>> from plumax.coupled import Instrument
>>> receptors = jnp.array([[1000.0, 0.0], [1000.0, 300.0]])
>>> instrument = Instrument(name="EMIT", receptors=receptors)
>>> geometry = PlumeGeometry(
...     location=jnp.zeros(2),
...     direction=0.0,
...     reference_width=150.0,
...     width_exponent=0.9,
... )
>>> source = ColumnPlumeSource(plume=ColumnPlume(), geometry=geometry)
>>> response = source.column_response(instrument)
>>> bool(jnp.allclose(response, ColumnPlume()(receptors, geometry)))
True

A control swaps in the blocks it holds and keeps the others:

>>> turned = source.response_at(instrument, {"direction": jnp.pi / 2})
>>> float(turned[0])
0.0
>>> bool(jnp.allclose(source.response_at(instrument, {}), response))
True

control_blocks property

control_blocks: Mapping[str, tuple[int, ...]]

The geometry: location (2,) and three scalars.

direction, log_reference_width and width_exponent, plus centreline (K,) when the geometry carries K knots.

emission_blocks property

emission_blocks: tuple[str, ...]

line_density and log_line_density.

column_response

column_response(instrument: Instrument) -> Float[Array, ' obs']

Column per unit line density at the instrument's receptors [m⁻¹].

r_inst = A_inst ⊙ r(s_inst; θ).

Parameters:

Name Type Description Default
instrument Instrument

The observing instrument (receptors and kernel).

required

Returns:

Type Description
Float[Array, ' obs']

The unit response r_inst.

Source code in src/plumax/gauss_plume/_src/column.py
def column_response(self, instrument: Instrument) -> Float[Array, " obs"]:
    """Column per unit line density at the instrument's receptors [m⁻¹].

    r_inst = A_inst ⊙ r(s_inst; θ).

    Args:
        instrument: The observing instrument (receptors and kernel).

    Returns:
        The unit response r_inst.
    """
    return self.response_at(instrument, {})

response_at

response_at(instrument: Instrument, control: Mapping[str, Float[ArrayLike, '*shape']]) -> Float[Array, ' obs']

Column per unit line density with the control's geometry [m⁻¹].

r_inst(θ) = A_inst ⊙ r(s_inst; θ).

Parameters:

Name Type Description Default
instrument Instrument

The observing instrument (receptors and kernel).

required
control Mapping[str, Float[ArrayLike, '*shape']]

The control, by block; blocks missing from it keep this source's values, and other names are ignored.

required

Returns:

Type Description
Float[Array, ' obs']

The unit response r_inst(θ).

Source code in src/plumax/gauss_plume/_src/column.py
def response_at(
    self,
    instrument: Instrument,
    control: Mapping[str, Float[ArrayLike, "*shape"]],
) -> Float[Array, " obs"]:
    """Column per unit line density with the control's geometry [m⁻¹].

    r_inst(θ) = A_inst ⊙ r(s_inst; θ).

    Args:
        instrument: The observing instrument (receptors and kernel).
        control: The control, by block; blocks missing from it keep this
            source's values, and other names are ignored.

    Returns:
        The unit response r_inst(θ).
    """
    # θ → geometry
    geometry = self.geometry_at(control)
    receptors = jnp.asarray(instrument.receptors)
    # r = exp(−c² / 2w²) / (√(2π) w)
    response = self.plume(receptors, geometry)
    averaging_kernel = jnp.asarray(instrument.ak, dtype=response.dtype)
    # r_inst = A ⊙ r
    observed = averaging_kernel * response
    return observed

geometry_at

geometry_at(control: Mapping[str, Float[ArrayLike, '*shape']]) -> PlumeGeometry

This source's geometry with the control's blocks swapped in.

w_ref = exp(log w_ref); the other blocks are taken as they are.

Parameters:

Name Type Description Default
control Mapping[str, Float[ArrayLike, '*shape']]

The control, by block.

required

Returns:

Type Description
PlumeGeometry

The geometry at the control.

Source code in src/plumax/gauss_plume/_src/column.py
def geometry_at(
    self, control: Mapping[str, Float[ArrayLike, "*shape"]]
) -> PlumeGeometry:
    """This source's geometry with the control's blocks swapped in.

    w_ref = exp(log w_ref); the other blocks are taken as they are.

    Args:
        control: The control, by block.

    Returns:
        The geometry at the control.
    """
    reference_width = self.geometry.reference_width
    if "log_reference_width" in control:
        # w_ref = exp(log w_ref)
        reference_width = jnp.exp(control["log_reference_width"])
    geometry = PlumeGeometry(
        location=control.get("location", self.geometry.location),
        direction=control.get("direction", self.geometry.direction),
        reference_width=reference_width,
        width_exponent=control.get("width_exponent", self.geometry.width_exponent),
        centreline=control.get("centreline", self.geometry.centreline),
    )
    return geometry

PlumeGeometry

Bases: Module

The fitted variables of a column plume: where it starts, heads and widens.

Attributes:

Name Type Description
location Float[Array, ' axis']

Source position s₀ [m].

direction Float[Array, '']

Plume direction φ [rad], counter-clockwise from the x axis, pointing downwind.

reference_width Float[Array, '']

Width w_ref [m] at the reference distance.

width_exponent Float[Array, '']

Growth exponent b of the width law.

centreline Float[Array, ' knot'] | None

Crosswind offsets m_k [m] at the knots d_k = k Δ_d, with Δ_d the plume's knot_spacing; None is a straight plume.

Examples:

Scalars are stored as arrays, so the geometry is a pytree of leaves:

>>> import jax
>>> import jax.numpy as jnp
>>> geometry = PlumeGeometry(
...     location=jnp.zeros(2),
...     direction=0.3,
...     reference_width=150.0,
...     width_exponent=0.9,
... )
>>> len(jax.tree_util.tree_leaves(geometry))
4

A centreline adds one leaf of K knots:

>>> bent = PlumeGeometry(
...     location=jnp.zeros(2),
...     direction=0.3,
...     reference_width=150.0,
...     width_exponent=0.9,
...     centreline=jnp.zeros(5),
... )
>>> len(jax.tree_util.tree_leaves(bent))
5

GaussianNoise

Bases: Noise

Homoscedastic Gaussian noise, ε ~ 𝒩(0, σ²).

log p(y | ŷ) = −½ ((y − ŷ)/σ)² − log σ − ½ log 2π.

The Tier I models default to this with σ = obs_noise_std, so their numbers are unchanged.

Attributes:

Name Type Description
std float | Float[Array, '*#obs']

Noise standard deviation σ > 0, in the units of y; a scalar or an array that broadcasts against the observations.

Raises:

Type Description
ParameterError

If std is not positive.

Examples:

The log-density at the mean of a unit Gaussian is −½ log 2π:

>>> import jax.numpy as jnp
>>> noise = GaussianNoise(std=1.0)
>>> value = noise.log_prob(jnp.zeros(3), jnp.zeros(3))
>>> value.shape
(3,)
>>> bool(jnp.allclose(value, -0.5 * jnp.log(2.0 * jnp.pi)))
True

A non-positive scale is rejected:

>>> GaussianNoise(std=0.0)
Traceback (most recent call last):
...
ParameterError: `std` must be > 0 (got 0.0)

HeteroscedasticNoise

Bases: Noise

Per-observation Gaussian noise, ε_i ~ 𝒩(0, σ_i²), from a retrieval-error map.

log p(y_i | ŷ_i) = −½ ((y_i − ŷ_i)/σ_i)² − log σ_i − ½ log 2π.

Unlike :class:GaussianNoise, σ must give one value per observation, and a mismatch with the observations is an error rather than a broadcast.

Attributes:

Name Type Description
std Float[Array, ' obs']

Per-observation standard deviation σ_i > 0, in the units of y.

Raises:

Type Description
ParameterError

If any std is not positive, or (from log_prob and the NumPyro site) if its shape differs from the observations'.

Examples:

Doubling σ_i halves the weight of a residual:

>>> import jax.numpy as jnp
>>> noise = HeteroscedasticNoise(std=jnp.array([1.0, 2.0]))
>>> value = noise.log_prob(jnp.array([2.0, 4.0]), jnp.zeros(2))
>>> bool(jnp.allclose(value[0] - value[1], jnp.log(2.0)))
True

Build it from variances, e.g. Instrument.observation_variance():

>>> HeteroscedasticNoise.from_variance(jnp.array([4.0, 9.0])).std.tolist()
[2.0, 3.0]

from_variance classmethod

from_variance(variance: Float[Array, ' obs']) -> HeteroscedasticNoise

The noise with σ_i = √(variance_i).

Source code in src/plumax/gauss_plume/_src/likelihoods.py
@classmethod
def from_variance(cls, variance: Float[Array, " obs"]) -> HeteroscedasticNoise:
    """The noise with σ_i = √(variance_i)."""
    # σ_i = √(R_ii)
    std = jnp.sqrt(jnp.asarray(variance))
    return cls(std=std)

Noise

Bases: Module

Observation-noise model p(y | ŷ) for a Tier I likelihood.

Subclasses define :meth:distribution (the NumPyro distribution, for models) and :meth:log_prob (plain JAX, for losses); they must agree.

distribution abstractmethod

distribution(mean: Float[Array, '*obs']) -> dist.Distribution

The NumPyro distribution of y given the prediction ŷ = mean.

Source code in src/plumax/gauss_plume/_src/likelihoods.py
@abc.abstractmethod
def distribution(self, mean: Float[Array, "*obs"]) -> dist.Distribution:
    """The NumPyro distribution of y given the prediction ŷ = ``mean``."""

log_prob abstractmethod

log_prob(obs: Float[Array, '*obs'], mean: Float[Array, '*obs']) -> Float[Array, '*obs']

Pointwise log-density log p(y | ŷ), without NumPyro.

Source code in src/plumax/gauss_plume/_src/likelihoods.py
@abc.abstractmethod
def log_prob(
    self, obs: Float[Array, "*obs"], mean: Float[Array, "*obs"]
) -> Float[Array, "*obs"]:
    """Pointwise log-density log p(y | ŷ), without NumPyro."""

StudentTNoise

Bases: Noise

Heavy-tailed Student-t noise, ε ~ t_ν(0, s), for outliers near the detection floor.

log p(y | ŷ) = log Γ((ν+1)/2) − log Γ(ν/2) − ½ log(ν π) − log s − (ν+1)/2 · log(1 + ((y − ŷ)/s)² / ν).

ν ≈ 5 is the Tier I design's default for low-SNR retrievals; as ν → ∞ it tends to :class:GaussianNoise with σ = s.

Attributes:

Name Type Description
scale float | Float[Array, '*#obs']

Scale s > 0, in the units of y; a scalar or an array that broadcasts against the observations. The standard deviation is s √(ν/(ν − 2)) for ν > 2.

df float

Degrees of freedom ν > 0.

Raises:

Type Description
ParameterError

If scale or df is not positive.

Examples:

A 10-scale outlier costs far less than under a Gaussian:

>>> import jax.numpy as jnp
>>> obs, mean = jnp.array([10.0]), jnp.array([0.0])
>>> student = StudentTNoise(scale=1.0).log_prob(obs, mean)
>>> gaussian = GaussianNoise(std=1.0).log_prob(obs, mean)
>>> bool(student[0] > gaussian[0] + 30.0)
True

Large ν recovers the Gaussian:

>>> near = StudentTNoise(scale=1.0, df=1.0e8).log_prob(obs, mean)
>>> bool(jnp.allclose(near, gaussian, rtol=1.0e-6))
True

GolderDispersion

GolderDispersion(inverse_obukhov_length: Float[Array, ''] | float, z0: float, interpolate: bool = False)

Bases: Module

PG σ_y, σ_z with the class chosen from Monin–Obukhov scales (Golder 1972).

σ_i(x) = σ_i^PG(x; class(1/L, z₀)), i ∈ {y, z}, with the Briggs–PG curves of :func:~plumax.gauss_plume.calculate_briggs_dispersion. With interpolate=True the class index s = :func:golder_stability_index is continuous and σ_i(x) = (1 − w) σ_i^PG(x; ⌊s⌋) + w σ_i^PG(x; ⌊s⌋ + 1), w = s − ⌊s⌋, which is differentiable in L (a plumax modelling choice, not part of Golder). Pass it as dispersion_params to :func:~plumax.gauss_plume.plume_concentration or as stability_class to :func:~plumax.gauss_plume.simulate_plume.

Attributes:

Name Type Description
inverse_obukhov_length Float[Array, '']

1/L [m⁻¹] of the column; zero is neutral.

z0 float

Roughness length z₀ > 0 [m]; clamped to :data:GOLDER_Z0_RANGE.

interpolate bool

Blend neighbouring PG classes linearly in 1/L (default False: the hard class lookup, as in Golder and MMIF).

Raises:

Type Description
ParameterError

If z0 is not positive.

Examples:

Neutral air reproduces PG class D exactly:

>>> import jax.numpy as jnp
>>> from plumax.gauss_plume import calculate_briggs_dispersion
>>> from plumax.gauss_plume import get_dispersion_params
>>> distance = jnp.array([100.0, 1000.0])
>>> neutral = GolderDispersion(inverse_obukhov_length=0.0, z0=0.1)
>>> sigma_y, sigma_z = neutral(distance)
>>> pg_y, pg_z = calculate_briggs_dispersion(distance, get_dispersion_params("D"))
>>> bool(jnp.allclose(sigma_y, pg_y) & jnp.allclose(sigma_z, pg_z))
True

The interpolated σ moves smoothly with L inside a class:

>>> import jax
>>> def sigma_z_at_1km(inverse_length):
...     dispersion = GolderDispersion(inverse_length, z0=0.1, interpolate=True)
...     return dispersion(jnp.array(1000.0))[1]
>>> bool(jax.grad(sigma_z_at_1km)(-1.0 / 50.0) < 0.0)
True

Build it from a met column's surface-layer diagnosis:

>>> from plumax.les_fvm.grid import make_grid
>>> from plumax.met import MetField, MoninObukhov
>>> grid = make_grid(
...     (0.0, 400.0, 4), (0.0, 400.0, 4), (0.0, 200.0, 4), dtype=jnp.float64
... )
>>> shape = (1, 4, 4, 4)
>>> field = MetField(
...     plume_grid=grid, times=jnp.zeros(1), u=jnp.full(shape, 5.0),
...     v=jnp.zeros(shape), w=jnp.zeros(shape),
...     temperature=jnp.full(shape, 300.0), pressure=jnp.full(shape, 1.0e5),
...     pbl_height=jnp.full((1, 4, 4), 800.0),
... )
>>> layer = MoninObukhov()(field, z0=0.1, sensible_heat_flux=0.0)
>>> GolderDispersion.from_surface_layer(layer, z0=0.1, it=0, iy=1, ix=2).z0
0.1
References

Golder, D. (1972). Relations among stability parameters in the surface layer. Boundary-Layer Meteorology 3, 47–58. US EPA (2024). MMIF v4.1.1, pasquill_gifford.f90 (pg_golder).

Source code in src/plumax/gauss_plume/_src/mo_dispersion.py
def __init__(
    self,
    inverse_obukhov_length: Float[Array, ""] | float,
    z0: float,
    interpolate: bool = False,
) -> None:
    self.inverse_obukhov_length = jnp.asarray(inverse_obukhov_length)
    self.z0 = float(z0)
    self.interpolate = bool(interpolate)

from_surface_layer classmethod

from_surface_layer(layer: SurfaceLayer, *, z0: float, it: int, iy: int, ix: int, interpolate: bool = False) -> GolderDispersion

Golder dispersion at one column of a :class:plumax.met.SurfaceLayer.

Parameters:

Name Type Description Default
layer SurfaceLayer

Surface-layer scales from :class:plumax.met.MoninObukhov; only its 1/L is used.

required
z0 float

The roughness length z₀ [m] the layer was diagnosed with.

required
it int

Met time index.

required
iy int

Analysis y index.

required
ix int

Analysis x index.

required
interpolate bool

See the class attribute.

False

Returns:

Type Description
GolderDispersion

The dispersion model for that column.

Source code in src/plumax/gauss_plume/_src/mo_dispersion.py
@classmethod
def from_surface_layer(
    cls,
    layer: SurfaceLayer,
    *,
    z0: float,
    it: int,
    iy: int,
    ix: int,
    interpolate: bool = False,
) -> GolderDispersion:
    """Golder dispersion at one column of a :class:`plumax.met.SurfaceLayer`.

    Args:
        layer: Surface-layer scales from :class:`plumax.met.MoninObukhov`;
            only its 1/L is used.
        z0: The roughness length z₀ [m] the layer was diagnosed with.
        it: Met time index.
        iy: Analysis y index.
        ix: Analysis x index.
        interpolate: See the class attribute.

    Returns:
        The dispersion model for that column.
    """
    inverse_length = layer.inverse_obukhov_length[it, iy, ix]
    return cls(inverse_length, z0=z0, interpolate=interpolate)

MaskedSources

Bases: Module

K_max source slots with emission rates, locations and activity indicators.

c(𝐬) = Σ_k a_k Q_k c₁(𝐬; x_k, y_k).

Attributes:

Name Type Description
emission_rate Float[Array, ' source']

Q_k [kg s⁻¹] per slot.

x Float[Array, ' source']

Source x_k [m] per slot.

y Float[Array, ' source']

Source y_k [m] per slot.

active Float[Array, ' source']

Activity a_k per slot, 1 on and 0 off (a float, so a relaxed indicator in [0, 1] works too).

Examples:

Two slots, one on, one off: the field is the first source's alone.

>>> import jax.numpy as jnp
>>> from plumax.gauss_plume.dispersion import BRIGGS_DISPERSION_PARAMS
>>> sources = MaskedSources(
...     emission_rate=jnp.array([0.1, 5.0]), x=jnp.array([0.0, 50.0]),
...     y=jnp.array([0.0, 50.0]), active=jnp.array([1.0, 0.0]),
... )
>>> sources.active_count().tolist()
1.0
>>> receptors = (jnp.array([300.0]), jnp.array([0.0]), jnp.array([1.0]))
>>> params = BRIGGS_DISPERSION_PARAMS["D"]
>>> field = sources.concentration(
...     receptors, source_z=2.0, wind_u=5.0, wind_v=0.0, dispersion_params=params
... )
>>> single = plume_concentration(*receptors, 0.0, 0.0, 2.0, 5.0, 0.0, 0.1, params)
>>> bool(jnp.allclose(field, single))
True

k_max property

k_max: int

Number of slots K_max.

active_count

active_count() -> Float[Array, '']

K = Σ_k a_k.

Source code in src/plumax/gauss_plume/_src/multi_source.py
def active_count(self) -> Float[Array, ""]:
    """K = Σ_k a_k."""
    # K = Σ_k a_k
    return einx.sum("source ->", self.active)

unit_responses

unit_responses(receptor_coords: tuple[Float[Array, ' obs'], Float[Array, ' obs'], Float[Array, ' obs']], *, source_z: float | Float[Array, ''], wind_u: float | Float[Array, ''], wind_v: float | Float[Array, ''], dispersion_params: Float[Array, ' param']) -> Float[Array, 'source obs']

Unit-rate plume c₁(𝐬_i; x_k, y_k) of every slot at every receptor.

Source code in src/plumax/gauss_plume/_src/multi_source.py
def unit_responses(
    self,
    receptor_coords: tuple[
        Float[Array, " obs"], Float[Array, " obs"], Float[Array, " obs"]
    ],
    *,
    source_z: float | Float[Array, ""],
    wind_u: float | Float[Array, ""],
    wind_v: float | Float[Array, ""],
    dispersion_params: Float[Array, " param"],
) -> Float[Array, "source obs"]:
    """Unit-rate plume c₁(𝐬_i; x_k, y_k) of every slot at every receptor."""
    easting_obs, northing_obs, height_obs = receptor_coords

    def one_source(source_x, source_y):
        return plume_concentration(
            easting_obs,
            northing_obs,
            height_obs,
            source_x,
            source_y,
            source_z,
            wind_u,
            wind_v,
            1.0,
            dispersion_params,
        )

    return jax.vmap(one_source)(self.x, self.y)

concentration

concentration(receptor_coords: tuple[Float[Array, ' obs'], Float[Array, ' obs'], Float[Array, ' obs']], *, source_z: float | Float[Array, ''], wind_u: float | Float[Array, ''], wind_v: float | Float[Array, ''], dispersion_params: Float[Array, ' param']) -> Float[Array, ' obs']

c(𝐬_i) = Σ_k a_k Q_k c₁(𝐬_i; x_k, y_k) [kg m⁻³].

Source code in src/plumax/gauss_plume/_src/multi_source.py
def concentration(
    self,
    receptor_coords: tuple[
        Float[Array, " obs"], Float[Array, " obs"], Float[Array, " obs"]
    ],
    *,
    source_z: float | Float[Array, ""],
    wind_u: float | Float[Array, ""],
    wind_v: float | Float[Array, ""],
    dispersion_params: Float[Array, " param"],
) -> Float[Array, " obs"]:
    """c(𝐬_i) = Σ_k a_k Q_k c₁(𝐬_i; x_k, y_k) [kg m⁻³]."""
    responses = self.unit_responses(
        receptor_coords,
        source_z=source_z,
        wind_u=wind_u,
        wind_v=wind_v,
        dispersion_params=dispersion_params,
    )
    # a_k Q_k
    weights = self.active * self.emission_rate
    # Σ_k a_k Q_k c₁(𝐬_i; x_k, y_k)
    return einx.dot("source, source obs -> obs", weights, responses)

MultiSourcePosterior dataclass

MultiSourcePosterior(emission_rate: ndarray, x: ndarray, y: ndarray, active: ndarray, background: ndarray)

Posterior draws of a masked-K source model.

Attributes:

Name Type Description
emission_rate ndarray

Q_k per draw and slot [kg s⁻¹], shape (sample, source).

x ndarray

x_k per draw and slot [m].

y ndarray

y_k per draw and slot [m].

active ndarray

a_k per draw and slot (bool).

background ndarray

Background per draw [kg m⁻³], shape (sample,).

Examples:

Three draws of two slots:

>>> import numpy as np
>>> posterior = MultiSourcePosterior(
...     emission_rate=np.array([[0.1, 0.5], [0.2, 0.6], [0.3, 0.7]]),
...     x=np.zeros((3, 2)), y=np.zeros((3, 2)),
...     active=np.array([[True, False], [True, True], [True, False]]),
...     background=np.zeros(3),
... )
>>> posterior.count_probabilities().round(3).tolist()
[0.0, 0.667, 0.333]
>>> summary = posterior.per_source(1)
>>> summary.probability_active, summary.emission_rate
(0.3333333333333333, 0.6)

k_max property

k_max: int

Number of slots K_max.

active_count

active_count() -> np.ndarray

K = Σ_k a_k per draw, shape (sample,).

Source code in src/plumax/gauss_plume/_src/multi_source.py
def active_count(self) -> np.ndarray:
    """K = Σ_k a_k per draw, shape ``(sample,)``."""
    # K = Σ_k a_k
    return einx.sum("sample source -> sample", np.asarray(self.active, dtype=int))

count_probabilities

count_probabilities() -> np.ndarray

P(K = k | y) for k = 0, …, K_max, shape (K_max + 1,).

Source code in src/plumax/gauss_plume/_src/multi_source.py
def count_probabilities(self) -> np.ndarray:
    """P(K = k | y) for k = 0, …, K_max, shape ``(K_max + 1,)``."""
    counts = np.bincount(self.active_count(), minlength=self.k_max + 1)
    return counts / counts.sum()

saturated_fraction

saturated_fraction() -> float

P(K = K_max | y): the mass at the cap, which drives the RJMCMC promotion.

Source code in src/plumax/gauss_plume/_src/multi_source.py
def saturated_fraction(self) -> float:
    """P(K = K_max | y): the mass at the cap, which drives the RJMCMC promotion."""
    return float(self.count_probabilities()[-1])

per_source

per_source(k: int) -> SourceSummary

Summary of slot k over the draws where it is active.

Raises:

Type Description
ParameterError

If k is not a slot index.

Source code in src/plumax/gauss_plume/_src/multi_source.py
def per_source(self, k: int) -> SourceSummary:
    """Summary of slot ``k`` over the draws where it is active.

    Raises:
        ParameterError: If ``k`` is not a slot index.
    """
    if not 0 <= k < self.k_max:
        raise ParameterError(f"slot k must be in [0, {self.k_max}), got {k}")
    on = np.asarray(self.active[:, k], dtype=bool)
    probability = float(on.mean())
    if not on.any():
        nan = float("nan")
        return SourceSummary(nan, nan, nan, nan, probability)
    rates = np.asarray(self.emission_rate[on, k])
    return SourceSummary(
        emission_rate=float(rates.mean()),
        emission_std=float(rates.std()),
        x=float(np.asarray(self.x[on, k]).mean()),
        y=float(np.asarray(self.y[on, k]).mean()),
        probability_active=probability,
    )

SourceSummary dataclass

SourceSummary(emission_rate: float, emission_std: float, x: float, y: float, probability_active: float)

Posterior summary of one slot, conditioned on the slot being active.

It satisfies :class:plumax.population.PerEventPosterior, so event_from_posterior(summary, x=summary.x, y=summary.y, …) builds the slot's catalogue event.

Attributes:

Name Type Description
emission_rate float

Posterior mean of Q_k over draws with a_k = 1 [kg s⁻¹]; NaN when the slot is never active.

emission_std float

Posterior standard deviation of Q_k over those draws.

x float

Posterior mean of x_k over those draws [m].

y float

Posterior mean of y_k over those draws [m].

probability_active float

Posterior probability P(a_k = 1 | y).

ColumnObservation

Bases: Module

Averaging-kernel-weighted column at a set of receptors.

y_i = A_i Σ_k h_k c_{k,i}.

Attributes:

Name Type Description
layer_weights Float[Array, ' level']

Level weights h_k, the layer thicknesses [m] for a column integral.

averaging_kernel Float[Array, ' obs'] | None

Per-receptor scalar averaging kernel A_i. None is the identity kernel.

receptor_index Int[Array, 'obs 2'] | None

(iy, ix) interior-cell index of each receptor on the field :meth:from_field takes. None observes every column, flattened row-major over (y, x).

receptor_plan Plan | None

A functax plan from the flattened (y, x) columns to the receptors, read by :meth:from_field in place of receptor_index (opt-in; :meth:for_grid builds a bilinear one). None uses receptor_index.

Examples:

Two levels 10 m thick, every column of a uniform field:

>>> import jax.numpy as jnp
>>> observation = ColumnObservation(layer_weights=jnp.full(2, 10.0))
>>> observation.from_field(jnp.ones((2, 3, 4))).shape
(12,)

Two receptors with an averaging kernel:

>>> observation = ColumnObservation(
...     layer_weights=jnp.full(2, 10.0),
...     averaging_kernel=jnp.array([1.0, 0.5]),
...     receptor_index=jnp.array([[0, 0], [2, 3]]),
... )
>>> observation.from_field(jnp.ones((2, 3, 4))).tolist()
[20.0, 10.0]

Trapezoid weights for profiles on irregular levels:

>>> levels = jnp.array([0.0, 10.0, 30.0])
>>> ColumnObservation.trapezoid(levels).layer_weights.tolist()
[5.0, 15.0, 10.0]

trapezoid classmethod

trapezoid(levels: Float[Array, ' level'], averaging_kernel: Float[Array, ' obs'] | None = None) -> ColumnObservation

Column over profiles on strictly increasing levels, trapezoid rule.

h_0 = Δz_0 / 2, h_k = (Δz_{k-1} + Δz_k) / 2, h_{K-1} = Δz_{K-2} / 2,

so Σ_k h_k c_k is jnp.trapezoid(c, x=levels): the weights of functax's trapezoid rule on the levels.

Parameters:

Name Type Description Default
levels Float[Array, ' level']

Level heights z_k [m].

required
averaging_kernel Float[Array, ' obs'] | None

Per-receptor scalar averaging kernel A_i.

None

Returns:

Type Description
ColumnObservation

The observation, with no receptor index (it takes profiles).

Source code in src/plumax/gauss_plume/_src/observation.py
@classmethod
def trapezoid(
    cls,
    levels: Float[Array, " level"],
    averaging_kernel: Float[Array, " obs"] | None = None,
) -> ColumnObservation:
    """Column over profiles on strictly increasing levels, trapezoid rule.

    h_0 = Δz_0 / 2,  h_k = (Δz_{k-1} + Δz_k) / 2,  h_{K-1} = Δz_{K-2} / 2,

    so Σ_k h_k c_k is ``jnp.trapezoid(c, x=levels)``: the weights of
    functax's trapezoid rule on the levels.

    Args:
        levels: Level heights z_k [m].
        averaging_kernel: Per-receptor scalar averaging kernel A_i.

    Returns:
        The observation, with no receptor index (it takes profiles).
    """
    # h_k = (Δz_{k-1} + Δz_k) / 2, with Δz_{-1} = Δz_{K-1} = 0
    layer_weights = functax_quad.trapezoid(levels).weights
    return cls(layer_weights=layer_weights, averaging_kernel=averaging_kernel)

for_grid classmethod

for_grid(plume_grid: PlumeGrid3D, *, instrument: Instrument | None = None, receptor_index: Int[Array, 'obs 2'] | None = None, bilinear: bool = False) -> ColumnObservation

Column over a les_fvm analysis grid, midpoint rule (h_k = Δz).

An instrument places each receptor in the T-cell that contains it and brings its averaging kernel. Without one, receptor_index (or every column) is observed with the identity kernel.

With bilinear=True (opt-in) the column is read bilinearly at the receptor's own (x, y) between the T-points instead,

c_{k,i} = H c_k,  H the functax ``Linear`` plan on (y, x) at the receptors,

so a receptor must lie between the first and last T-points of each axis rather than inside the outer cells.

Parameters:

Name Type Description Default
plume_grid PlumeGrid3D

The analysis grid the field lives on.

required
instrument Instrument | None

Receptors (x, y) [m] and their averaging kernel.

None
receptor_index Int[Array, 'obs 2'] | None

(iy, ix) interior-cell indices, used when no instrument is given.

None
bilinear bool

Read each instrument receptor bilinearly at its (x, y) (a receptor_plan) instead of in its cell.

False

Returns:

Type Description
ColumnObservation

The observation for interior fields of shape (nz, ny, nx).

Raises:

Type Description
DomainError

If a receptor lies outside the grid (outside the T-points with bilinear=True).

ValueError

If both instrument and receptor_index are given, or bilinear without an instrument.

Source code in src/plumax/gauss_plume/_src/observation.py
@classmethod
def for_grid(
    cls,
    plume_grid: PlumeGrid3D,
    *,
    instrument: Instrument | None = None,
    receptor_index: Int[Array, "obs 2"] | None = None,
    bilinear: bool = False,
) -> ColumnObservation:
    """Column over a ``les_fvm`` analysis grid, midpoint rule (h_k = Δz).

    An instrument places each receptor in the T-cell that contains it and
    brings its averaging kernel. Without one, ``receptor_index`` (or every
    column) is observed with the identity kernel.

    With ``bilinear=True`` (opt-in) the column is read bilinearly at the
    receptor's own ``(x, y)`` between the T-points instead,

        c_{k,i} = H c_k,  H the functax ``Linear`` plan on (y, x) at the receptors,

    so a receptor must lie between the first and last T-points of each
    axis rather than inside the outer cells.

    Args:
        plume_grid: The analysis grid the field lives on.
        instrument: Receptors ``(x, y)`` [m] and their averaging kernel.
        receptor_index: ``(iy, ix)`` interior-cell indices, used when no
            instrument is given.
        bilinear: Read each instrument receptor bilinearly at its
            ``(x, y)`` (a ``receptor_plan``) instead of in its cell.

    Returns:
        The observation for interior fields of shape ``(nz, ny, nx)``.

    Raises:
        DomainError: If a receptor lies outside the grid (outside the
            T-points with ``bilinear=True``).
        ValueError: If both ``instrument`` and ``receptor_index`` are
            given, or ``bilinear`` without an instrument.
    """
    num_levels = plume_grid.interior_shape[0]
    layer_weights = jnp.full(num_levels, plume_grid.dz, dtype=plume_grid.z.dtype)
    if instrument is None:
        if bilinear:
            raise ValueError(
                "ColumnObservation.for_grid: `bilinear` reads an "
                "instrument's receptors; pass `instrument`."
            )
        return cls(layer_weights=layer_weights, receptor_index=receptor_index)
    if receptor_index is not None:
        raise ValueError(
            "ColumnObservation.for_grid: pass `instrument` or "
            "`receptor_index`, not both."
        )
    receptors = np.asarray(instrument.receptors, dtype=float)
    if bilinear:
        return cls(
            layer_weights=layer_weights,
            averaging_kernel=instrument.ak,
            receptor_plan=_receptor_plan(plume_grid, receptors),
        )
    col_index = _containing_cell(receptors[:, 0], np.asarray(plume_grid.x), "x")
    row_index = _containing_cell(receptors[:, 1], np.asarray(plume_grid.y), "y")
    # index_r = (iy_r, ix_r)
    index = einx.id("receptor, receptor -> receptor (1 + 1)", row_index, col_index)
    index = jnp.asarray(index)
    return cls(
        layer_weights=layer_weights,
        averaging_kernel=instrument.ak,
        receptor_index=index,
    )

column

column(profiles: Float[Array, 'obs level']) -> Float[Array, ' obs']

Apply the observation to per-receptor profiles c_{k,i}.

Parameters:

Name Type Description Default
profiles Float[Array, 'obs level']

Concentration at each receptor and level.

required

Returns:

Type Description
Float[Array, ' obs']

The observation y_i.

Source code in src/plumax/gauss_plume/_src/observation.py
def column(self, profiles: Float[Array, "obs level"]) -> Float[Array, " obs"]:
    """Apply the observation to per-receptor profiles c_{k,i}.

    Args:
        profiles: Concentration at each receptor and level.

    Returns:
        The observation y_i.
    """
    # Σ_k h_k c_{k,i}
    column = einx.dot("obs level, level -> obs", profiles, self.layer_weights)
    if self.averaging_kernel is None:
        return column
    # y_i = A_i Σ_k h_k c_{k,i}
    return self.averaging_kernel * column

from_field

from_field(concentration: Float[Array, 'level y x']) -> Float[Array, ' obs']

Apply the observation to an interior field on the analysis grid.

Parameters:

Name Type Description Default
concentration Float[Array, 'level y x']

Interior concentration c, ghost rings stripped.

required

Returns:

Type Description
Float[Array, ' obs']

The observation y_i at each receptor.

Source code in src/plumax/gauss_plume/_src/observation.py
def from_field(
    self, concentration: Float[Array, "level y x"]
) -> Float[Array, " obs"]:
    """Apply the observation to an interior field on the analysis grid.

    Args:
        concentration: Interior concentration c, ghost rings stripped.

    Returns:
        The observation y_i at each receptor.
    """
    if self.receptor_plan is not None:
        columns = einx.id("level y x -> level (y x)", concentration)
        # c_{k,i} = H c_k
        sampled = self.receptor_plan(columns)
        profiles = einx.id("level obs -> obs level", sampled)
    elif self.receptor_index is None:
        profiles = einx.id("level y x -> (y x) level", concentration)
    else:
        row_index = self.receptor_index[:, 0]
        col_index = self.receptor_index[:, 1]
        # c_{k,i} = c[k, iy_i, ix_i]
        gathered = concentration[:, row_index, col_index]
        profiles = einx.id("level obs -> obs level", gathered)
    return self.column(profiles)

BriggsPlumeRise

Bases: Module

Briggs plume rise Δh(x) of a stack plume, from its buoyancy and momentum.

Δh(x) = max(Δh_b(x), Δh_m(x)), with the buoyant and momentum rises of the module docstring.

Algorithm
  1. Fluxes F_b = g v_s d² (T_s − T_a)/(4 T_s), floored at 0, and F_m = v_s² d² T_a/(4 T_s).
  2. Buoyant rise: the 2/3 law 1.6 F_b^{1/3} x^{2/3}/u, capped at the class's final rise.
  3. Momentum rise: the jet law 1.44 d (v_s/u)^{2/3} (x/d)^{1/3}, capped at 3 d v_s/u, and in stable air also at 1.5 (F_m/u)^{1/3} s^{−1/6}.
  4. Take the larger of the two.

Attributes:

Name Type Description
exit_velocity float | Float[Array, '']

Stack exit velocity v_s ≥ 0 [m s⁻¹].

exit_temperature float | Float[Array, '']

Stack gas temperature T_s > 0 [K].

stack_diameter float | Float[Array, '']

Inside stack-top diameter d > 0 [m].

ambient_temperature float | Float[Array, '']

Ambient air temperature T_a > 0 [K].

stability_class str

Pasquill–Gifford class 'A' … 'F'; E and F use the stable formulas with ∂θ/∂z from :data:STABLE_THETA_GRADIENT.

Raises:

Type Description
ParameterError

If the class is not A–F or a parameter is out of range.

Examples:

A hot stack in neutral air: past x_f the rise is the final rise.

>>> import jax.numpy as jnp
>>> rise = BriggsPlumeRise(
...     exit_velocity=10.0, exit_temperature=400.0, stack_diameter=2.0,
...     ambient_temperature=290.0, stability_class="D",
... )
>>> heights = rise(jnp.array([100.0, 5000.0, 20000.0]), wind_speed=5.0)
>>> heights.shape
(3,)
>>> bool(heights[1] == heights[2])
True

A cold, still stack does not rise:

>>> still = BriggsPlumeRise(
...     exit_velocity=0.0, exit_temperature=290.0, stack_diameter=2.0,
...     ambient_temperature=290.0,
... )
>>> still(jnp.array([500.0]), wind_speed=5.0).tolist()
[0.0]

Classes outside A–F are rejected:

>>> BriggsPlumeRise(
...     exit_velocity=1.0, exit_temperature=300.0, stack_diameter=1.0,
...     ambient_temperature=290.0, stability_class="G",
... )
Traceback (most recent call last):
...
ParameterError: stability_class must be one of A-F, got 'G'
References

Briggs, G. A. (1969). Plume Rise. USAEC TID-25075 (Eqs. 4.19b, 4.28, 4.33, 5.2). U.S. EPA, User's Guide for the Industrial Source Complex (ISC3) Dispersion Models, Vol. II, §1.1.4 (after Briggs 1971, 1975).

is_stable property

is_stable: bool

Whether the class is E or F (the stable formulas).

buoyancy_flux

buoyancy_flux() -> Float[Array, '']

F_b = g v_s d² (T_s − T_a)/(4 T_s) [m⁴ s⁻³], floored at 0 (no sinking).

Source code in src/plumax/gauss_plume/_src/plume_rise.py
def buoyancy_flux(self) -> Float[Array, ""]:
    """F_b = g v_s d² (T_s − T_a)/(4 T_s) [m⁴ s⁻³], floored at 0 (no sinking)."""
    # T_s − T_a
    excess = self.exit_temperature - self.ambient_temperature
    # g v_s d² (T_s − T_a) / (4 T_s)
    flux = (
        GRAVITY
        * self.exit_velocity
        * self.stack_diameter**2
        * excess
        / (4.0 * self.exit_temperature)
    )
    return jnp.maximum(flux, 0.0)

momentum_flux

momentum_flux() -> Float[Array, '']

F_m = v_s² d² T_a/(4 T_s) [m⁴ s⁻²].

Source code in src/plumax/gauss_plume/_src/plume_rise.py
def momentum_flux(self) -> Float[Array, ""]:
    """F_m = v_s² d² T_a/(4 T_s) [m⁴ s⁻²]."""
    # v_s² d² T_a / (4 T_s)
    return jnp.asarray(
        self.exit_velocity**2
        * self.stack_diameter**2
        * self.ambient_temperature
        / (4.0 * self.exit_temperature)
    )

stability_parameter

stability_parameter() -> Float[Array, '']

s = (g / T_a) ∂θ/∂z [s⁻²] of the stable classes; 0 for A–D.

Source code in src/plumax/gauss_plume/_src/plume_rise.py
def stability_parameter(self) -> Float[Array, ""]:
    """s = (g / T_a) ∂θ/∂z [s⁻²] of the stable classes; 0 for A–D."""
    gradient = STABLE_THETA_GRADIENT.get(self.stability_class, 0.0)
    # s = g ∂θ/∂z / T_a
    return jnp.asarray(GRAVITY * gradient / self.ambient_temperature)

EmissionRateSamples

EmissionRateSamples(draws: dict[str, ndarray], *, prior_mean: float, prior_std: float)

Bases: dict

NUTS draws by site name, with the per-event payload Tier V reads.

A dict of posterior arrays (samples["emission_rate"] is unchanged) that also satisfies population.PerEventPosterior: the posterior mean and standard deviation of Q, resampled draws of Q, and the log-density of the emission-rate prior the draws were made under, Q ~ LogNormal(μ, σ²) moment-matched to (prior_mean, prior_std).

Parameters:

Name Type Description Default
draws dict[str, ndarray]

Posterior arrays keyed by site name.

required
prior_mean float

Real-scale prior mean of Q [kg/s].

required
prior_std float

Real-scale prior standard deviation of Q [kg/s].

required
Source code in src/plumax/gauss_plume/_src/inference.py
def __init__(
    self, draws: dict[str, np.ndarray], *, prior_mean: float, prior_std: float
) -> None:
    super().__init__(draws)
    self.prior_mean = prior_mean
    self.prior_std = prior_std

emission_rate property

emission_rate: float

Posterior mean of Q [kg/s].

emission_std property

emission_std: float

Posterior standard deviation of Q [kg/s].

samples

samples(key: Array, n: int) -> jax.Array

n draws of Q, resampled with replacement from the NUTS draws.

Source code in src/plumax/gauss_plume/_src/inference.py
def samples(self, key: jax.Array, n: int) -> jax.Array:
    """n draws of Q, resampled with replacement from the NUTS draws."""
    return EmpiricalEmission(self["emission_rate"]).sample(key, n)

prior_logpdf

prior_logpdf(q: Float[ArrayLike, '*draw']) -> jax.Array

log π(q) of the emission-rate prior of :func:gaussian_plume_model.

Source code in src/plumax/gauss_plume/_src/inference.py
def prior_logpdf(self, q: Float[ArrayLike, "*draw"]) -> jax.Array:
    """log π(q) of the emission-rate prior of :func:`gaussian_plume_model`."""
    prior = LognormalEmission.from_moments(self.prior_mean, self.prior_std)
    return prior.log_prob(q)

centreline_offset

centreline_offset(downwind: Float[Array, '*obs'], centreline: Float[Array, ' knot'], *, knot_spacing: float) -> Float[Array, '*obs']

Crosswind offset of the centreline at each downwind distance.

m(d) = m_k + (m_{k+1} − m_k) (d − d_k) / Δ_d between the knots d_k = k Δ_d, with m₀ = 0 at d₀ = 0, m(d) = m_K beyond the last knot and m(d) = 0 upwind.

Algorithm
  1. Prepend the source knot: d₀ = 0 with m₀ = 0.
  2. Interpolate linearly; hold m₀ upwind and m_K beyond d_K.

Parameters:

Name Type Description Default
downwind Float[Array, '*obs']

Downwind distance d [m].

required
centreline Float[Array, ' knot']

Offsets m_k [m] at the knots d_k = k Δ_d, k = 1, …, K.

required
knot_spacing float

Knot spacing Δ_d [m].

required

Returns:

Type Description
Float[Array, '*obs']

The offset m(d) [m].

Examples:

Halfway between the source and the first knot the offset is half of m₁; beyond the last knot it is held:

>>> import jax.numpy as jnp
>>> offset = centreline_offset(
...     jnp.array([-100.0, 90.0, 180.0, 270.0, 1000.0]),
...     jnp.array([20.0, 60.0]),
...     knot_spacing=180.0,
... )
>>> bool(jnp.allclose(offset, jnp.array([0.0, 10.0, 20.0, 40.0, 60.0])))
True
Source code in src/plumax/gauss_plume/_src/column.py
def centreline_offset(
    downwind: Float[Array, "*obs"],
    centreline: Float[Array, " knot"],
    *,
    knot_spacing: float,
) -> Float[Array, "*obs"]:
    """Crosswind offset of the centreline at each downwind distance.

    m(d) = m_k + (m_{k+1} − m_k) (d − d_k) / Δ_d between the knots d_k = k Δ_d,
    with m₀ = 0 at d₀ = 0, m(d) = m_K beyond the last knot and m(d) = 0 upwind.

    Algorithm:
        1. Prepend the source knot: d₀ = 0 with m₀ = 0.
        2. Interpolate linearly; hold m₀ upwind and m_K beyond d_K.

    Args:
        downwind: Downwind distance d [m].
        centreline: Offsets m_k [m] at the knots d_k = k Δ_d, k = 1, …, K.
        knot_spacing: Knot spacing Δ_d [m].

    Returns:
        The offset m(d) [m].

    Examples:
        Halfway between the source and the first knot the offset is half of
        m₁; beyond the last knot it is held:

        >>> import jax.numpy as jnp
        >>> offset = centreline_offset(
        ...     jnp.array([-100.0, 90.0, 180.0, 270.0, 1000.0]),
        ...     jnp.array([20.0, 60.0]),
        ...     knot_spacing=180.0,
        ... )
        >>> bool(jnp.allclose(offset, jnp.array([0.0, 10.0, 20.0, 40.0, 60.0])))
        True
    """
    centreline = jnp.asarray(centreline)
    num_knots = centreline.shape[0]
    # d_k = k Δ_d for k = 0, …, K
    knot_index = jnp.arange(num_knots + 1, dtype=centreline.dtype)
    knot_distance = knot_spacing * knot_index
    # (m₀, m₁, …, m_K) with m₀ = 0
    source_offset = jnp.zeros((1,), dtype=centreline.dtype)
    knot_offset = jnp.concatenate([source_offset, centreline])
    # m(d), linear between the knots, m₀ for d < 0 and m_K for d ≥ d_K
    offset = jnp.interp(downwind, knot_distance, knot_offset)
    return offset

plume_frame

plume_frame(receptors: Float[Array, 'obs axis'], location: Float[ArrayLike, ' axis'], direction: Float[ArrayLike, '']) -> tuple[Float[Array, ' obs'], Float[Array, ' obs']]

Downwind and crosswind distance of each receptor from the source.

d = (s − s₀)ᵀ e_∥ and c = (s − s₀)ᵀ e_⊥, with e_∥ = (cos φ, sin φ) and e_⊥ = (−sin φ, cos φ).

Parameters:

Name Type Description Default
receptors Float[Array, 'obs axis']

Receptor positions s [m], one (x, y) row each.

required
location Float[ArrayLike, ' axis']

Source position s₀ [m].

required
direction Float[ArrayLike, '']

Plume direction φ [rad], counter-clockwise from the x axis, pointing downwind.

required

Returns:

Type Description
tuple[Float[Array, ' obs'], Float[Array, ' obs']]

The downwind distance d and the crosswind distance c [m].

Examples:

A plume heading along y: a receptor 100 m north is 100 m downwind.

>>> import jax.numpy as jnp
>>> receptors = jnp.array([[0.0, 100.0], [50.0, 0.0]])
>>> downwind, crosswind = plume_frame(
...     receptors, jnp.zeros(2), jnp.asarray(jnp.pi / 2)
... )
>>> bool(jnp.allclose(downwind, jnp.array([100.0, 0.0]), atol=1e-4))
True
>>> bool(jnp.allclose(crosswind, jnp.array([0.0, -50.0]), atol=1e-4))
True
Source code in src/plumax/gauss_plume/_src/column.py
def plume_frame(
    receptors: Float[Array, "obs axis"],
    location: Float[ArrayLike, " axis"],
    direction: Float[ArrayLike, ""],
) -> tuple[Float[Array, " obs"], Float[Array, " obs"]]:
    """Downwind and crosswind distance of each receptor from the source.

    d = (s − s₀)ᵀ e_∥ and c = (s − s₀)ᵀ e_⊥, with e_∥ = (cos φ, sin φ) and
    e_⊥ = (−sin φ, cos φ).

    Args:
        receptors: Receptor positions s [m], one ``(x, y)`` row each.
        location: Source position s₀ [m].
        direction: Plume direction φ [rad], counter-clockwise from the x axis,
            pointing downwind.

    Returns:
        The downwind distance d and the crosswind distance c [m].

    Examples:
        A plume heading along y: a receptor 100 m north is 100 m downwind.

        >>> import jax.numpy as jnp
        >>> receptors = jnp.array([[0.0, 100.0], [50.0, 0.0]])
        >>> downwind, crosswind = plume_frame(
        ...     receptors, jnp.zeros(2), jnp.asarray(jnp.pi / 2)
        ... )
        >>> bool(jnp.allclose(downwind, jnp.array([100.0, 0.0]), atol=1e-4))
        True
        >>> bool(jnp.allclose(crosswind, jnp.array([0.0, -50.0]), atol=1e-4))
        True
    """
    direction = jnp.asarray(direction)
    cos_direction = jnp.cos(direction)
    sin_direction = jnp.sin(direction)
    # e_∥ = (cos φ, sin φ)
    along = jnp.stack([cos_direction, sin_direction])
    # e_⊥ = (−sin φ, cos φ)
    across = jnp.stack([-sin_direction, cos_direction])
    # Δs = s − s₀
    offset = einx.subtract("obs axis, axis -> obs axis", receptors, location)
    # d = Δsᵀ e_∥
    downwind = einx.dot("obs axis, axis -> obs", offset, along)
    # c = Δsᵀ e_⊥
    crosswind = einx.dot("obs axis, axis -> obs", offset, across)
    return downwind, crosswind

power_law_width

power_law_width(downwind: Float[Array, '*obs'], *, reference_width: Float[ArrayLike, ''], width_exponent: Float[ArrayLike, ''], reference_distance: float, initial_width: float = 0.0) -> Float[Array, '*obs']

Crosswind standard deviation of the plume at each downwind distance.

w(d) = √(w₀² + w_ref² (d / d_ref)^(2b)), with d clipped below at 1 mm.

Parameters:

Name Type Description Default
downwind Float[Array, '*obs']

Downwind distance d [m]; upwind values are clipped.

required
reference_width Float[ArrayLike, '']

Width w_ref [m] at the reference distance.

required
width_exponent Float[ArrayLike, '']

Growth exponent b.

required
reference_distance float

Reference distance d_ref [m].

required
initial_width float

Width w₀ [m] at the source.

0.0

Returns:

Type Description
Float[Array, '*obs']

The width w(d) [m].

Examples:

At the reference distance the width is the reference width:

>>> import jax.numpy as jnp
>>> width = power_law_width(
...     jnp.array([1000.0, 4000.0]),
...     reference_width=150.0,
...     width_exponent=0.5,
...     reference_distance=1000.0,
... )
>>> bool(jnp.allclose(width, jnp.array([150.0, 300.0])))
True

The initial width adds in quadrature:

>>> near = power_law_width(
...     jnp.array([0.0]),
...     reference_width=150.0,
...     width_exponent=0.9,
...     reference_distance=1000.0,
...     initial_width=17.0,
... )
>>> bool(jnp.allclose(near, 17.0, rtol=1e-6))
True
Source code in src/plumax/gauss_plume/_src/column.py
def power_law_width(
    downwind: Float[Array, "*obs"],
    *,
    reference_width: Float[ArrayLike, ""],
    width_exponent: Float[ArrayLike, ""],
    reference_distance: float,
    initial_width: float = 0.0,
) -> Float[Array, "*obs"]:
    """Crosswind standard deviation of the plume at each downwind distance.

    w(d) = √(w₀² + w_ref² (d / d_ref)^(2b)), with d clipped below at 1 mm.

    Args:
        downwind: Downwind distance d [m]; upwind values are clipped.
        reference_width: Width w_ref [m] at the reference distance.
        width_exponent: Growth exponent b.
        reference_distance: Reference distance d_ref [m].
        initial_width: Width w₀ [m] at the source.

    Returns:
        The width w(d) [m].

    Examples:
        At the reference distance the width is the reference width:

        >>> import jax.numpy as jnp
        >>> width = power_law_width(
        ...     jnp.array([1000.0, 4000.0]),
        ...     reference_width=150.0,
        ...     width_exponent=0.5,
        ...     reference_distance=1000.0,
        ... )
        >>> bool(jnp.allclose(width, jnp.array([150.0, 300.0])))
        True

        The initial width adds in quadrature:

        >>> near = power_law_width(
        ...     jnp.array([0.0]),
        ...     reference_width=150.0,
        ...     width_exponent=0.9,
        ...     reference_distance=1000.0,
        ...     initial_width=17.0,
        ... )
        >>> bool(jnp.allclose(near, 17.0, rtol=1e-6))
        True
    """
    # d ← max(d, 1 mm): the power law is evaluated in logs
    distance = jnp.maximum(downwind, _MIN_DISTANCE)
    # log(d / d_ref)
    log_ratio = jnp.log(distance / reference_distance)
    # (d / d_ref)^(2b) = exp(2b log(d / d_ref))
    growth = jnp.exp(2.0 * width_exponent * log_ratio)
    # w² = w₀² + w_ref² (d / d_ref)^(2b)
    variance = initial_width**2 + jnp.square(reference_width) * growth
    width = jnp.sqrt(variance)
    return width

unit_column

unit_column(downwind: Float[Array, '*obs'], crosswind: Float[Array, '*obs'], width: Float[Array, '*obs'], *, centreline: Float[Array, '*obs'] | None = None, upwind_scale: float | None = None, pixel_size: float | None = None) -> Float[Array, '*obs']

Column per unit line density, the Gaussian ridge across the plume.

r = exp(−(c − m)² / 2w²) / (√(2π) w) for d > 0, else 0 [m⁻¹]. With a pixel side g the ridge is averaged across the pixel, r = (erf((c − m + g/2) / √2 w) − erf((c − m − g/2) / √2 w)) / 2g. With an upwind scale ℓ_u the cut at the source becomes the ramp 1 / (1 + e^(−d/ℓ_u)).

Algorithm
  1. Shift the crosswind distance by the centreline: c − m.
  2. Evaluate the Gaussian at the point, or average it across the pixel.
  3. Apply the upwind cut, hard or as a logistic ramp.

Parameters:

Name Type Description Default
downwind Float[Array, '*obs']

Downwind distance d [m].

required
crosswind Float[Array, '*obs']

Crosswind distance c [m].

required
width Float[Array, '*obs']

Crosswind width w [m], positive.

required
centreline Float[Array, '*obs'] | None

Centreline offset m [m] at each receptor; None is zero.

None
upwind_scale float | None

Ramp length ℓ_u [m]; None is the hard cut.

None
pixel_size float | None

Pixel side g [m]; None is point evaluation.

None

Returns:

Type Description
Float[Array, '*obs']

The column per unit line density r [m⁻¹]; ΔΩ = q r.

Examples:

On the centreline the response is 1 / (√(2π) w):

>>> import einx
>>> import jax.numpy as jnp
>>> downwind = jnp.array([500.0, -500.0])
>>> crosswind = jnp.zeros(2)
>>> width = jnp.full(2, 100.0)
>>> response = unit_column(downwind, crosswind, width)
>>> bool(jnp.allclose(response[0], 1.0 / (2.5066282746 * 100.0)))
True
>>> float(response[1])
0.0

The pixel average integrates to one across a row of pixels:

>>> offsets = jnp.arange(-50.0, 51.0) * 60.0
>>> row = unit_column(
...     jnp.full_like(offsets, 500.0),
...     offsets,
...     jnp.full_like(offsets, 20.0),
...     pixel_size=60.0,
... )
>>> bool(jnp.allclose(einx.sum("[obs]", row) * 60.0, 1.0, rtol=1e-10))
True
Source code in src/plumax/gauss_plume/_src/column.py
def unit_column(
    downwind: Float[Array, "*obs"],
    crosswind: Float[Array, "*obs"],
    width: Float[Array, "*obs"],
    *,
    centreline: Float[Array, "*obs"] | None = None,
    upwind_scale: float | None = None,
    pixel_size: float | None = None,
) -> Float[Array, "*obs"]:
    """Column per unit line density, the Gaussian ridge across the plume.

    r = exp(−(c − m)² / 2w²) / (√(2π) w) for d > 0, else 0 [m⁻¹]. With a
    pixel side g the ridge is averaged across the pixel,
    r = (erf((c − m + g/2) / √2 w) − erf((c − m − g/2) / √2 w)) / 2g. With an
    upwind scale ℓ_u the cut at the source becomes the ramp 1 / (1 + e^(−d/ℓ_u)).

    Algorithm:
        1. Shift the crosswind distance by the centreline: c − m.
        2. Evaluate the Gaussian at the point, or average it across the pixel.
        3. Apply the upwind cut, hard or as a logistic ramp.

    Args:
        downwind: Downwind distance d [m].
        crosswind: Crosswind distance c [m].
        width: Crosswind width w [m], positive.
        centreline: Centreline offset m [m] at each receptor; ``None`` is zero.
        upwind_scale: Ramp length ℓ_u [m]; ``None`` is the hard cut.
        pixel_size: Pixel side g [m]; ``None`` is point evaluation.

    Returns:
        The column per unit line density r [m⁻¹]; ΔΩ = q r.

    Examples:
        On the centreline the response is 1 / (√(2π) w):

        >>> import einx
        >>> import jax.numpy as jnp
        >>> downwind = jnp.array([500.0, -500.0])
        >>> crosswind = jnp.zeros(2)
        >>> width = jnp.full(2, 100.0)
        >>> response = unit_column(downwind, crosswind, width)
        >>> bool(jnp.allclose(response[0], 1.0 / (2.5066282746 * 100.0)))
        True
        >>> float(response[1])
        0.0

        The pixel average integrates to one across a row of pixels:

        >>> offsets = jnp.arange(-50.0, 51.0) * 60.0
        >>> row = unit_column(
        ...     jnp.full_like(offsets, 500.0),
        ...     offsets,
        ...     jnp.full_like(offsets, 20.0),
        ...     pixel_size=60.0,
        ... )
        >>> bool(jnp.allclose(einx.sum("[obs]", row) * 60.0, 1.0, rtol=1e-10))
        True
    """
    # c − m
    shifted = crosswind if centreline is None else crosswind - centreline
    # the masked upwind branch still gets a gradient, so keep its width finite
    downstream = downwind > 0.0
    safe_width = jnp.where(downstream, width, 1.0) if upwind_scale is None else width

    # --- ridge ---
    if pixel_size is None:
        # (c − m) / w
        standardised = shifted / safe_width
        # exp(−(c − m)² / 2w²)
        kernel = jnp.exp(-0.5 * jnp.square(standardised))
        # r = exp(−(c − m)² / 2w²) / (√(2π) w)
        response = kernel / (_SQRT_TWO_PI * safe_width)
    else:
        # √2 w
        scale = math.sqrt(2.0) * safe_width
        # erf((c − m + g/2) / √2 w)
        upper = jax.scipy.special.erf((shifted + 0.5 * pixel_size) / scale)
        # erf((c − m − g/2) / √2 w)
        lower = jax.scipy.special.erf((shifted - 0.5 * pixel_size) / scale)
        # r = (erf(·) − erf(·)) / 2g
        response = (upper - lower) / (2.0 * pixel_size)

    # --- upwind cut ---
    if upwind_scale is None:
        # r = 0 for d ≤ 0
        return jnp.where(downstream, response, 0.0)
    # r ← r / (1 + exp(−d / ℓ_u))
    ramp = jax.nn.sigmoid(downwind / upwind_scale)
    return response * ramp

calculate_briggs_dispersion

calculate_briggs_dispersion(distance: ndarray, params: ndarray) -> tuple[jnp.ndarray, jnp.ndarray]

Evaluate σ_y(x), σ_z(x) from Briggs parameters.

σ_i(x) = a_i · x · (1 + b_i · x)^{c_i} for i ∈ {y, z}.

Parameters

distance : jnp.ndarray Downwind distance from source [m]. Negative / zero values are clamped to 1 m so that the coefficient evaluation stays finite; upwind points are masked elsewhere in the plume model. params : jnp.ndarray, shape (6,) [a_y, b_y, c_y, a_z, b_z, c_z].

Returns

sigma_y : jnp.ndarray Lateral dispersion coefficient [m], same shape as distance. sigma_z : jnp.ndarray Vertical dispersion coefficient [m], same shape as distance.

Source code in src/plumax/gauss_plume/_src/dispersion.py
@jit
def calculate_briggs_dispersion(
    distance: jnp.ndarray,
    params: jnp.ndarray,
) -> tuple[jnp.ndarray, jnp.ndarray]:
    """Evaluate σ_y(x), σ_z(x) from Briggs parameters.

    σ_i(x) = a_i · x · (1 + b_i · x)^{c_i} for i ∈ {y, z}.

    Parameters
    ----------
    distance : jnp.ndarray
        Downwind distance from source [m]. Negative / zero values are clamped
        to 1 m so that the coefficient evaluation stays finite; upwind points
        are masked elsewhere in the plume model.
    params : jnp.ndarray, shape (6,)
        ``[a_y, b_y, c_y, a_z, b_z, c_z]``.

    Returns
    -------
    sigma_y : jnp.ndarray
        Lateral dispersion coefficient [m], same shape as ``distance``.
    sigma_z : jnp.ndarray
        Vertical dispersion coefficient [m], same shape as ``distance``.
    """
    (
        scale_y,
        shift_y,
        exponent_y,
        scale_z,
        shift_z,
        exponent_z,
    ) = params
    downwind = jnp.maximum(distance, 1.0)
    # σ_y = a_y x (1 + b_y x)^{c_y}
    crosswind_spread = (
        scale_y * downwind * jnp.power(1.0 + shift_y * downwind, exponent_y)
    )
    # σ_z = a_z x (1 + b_z x)^{c_z}
    vertical_spread = (
        scale_z * downwind * jnp.power(1.0 + shift_z * downwind, exponent_z)
    )
    return crosswind_spread, vertical_spread

get_dispersion_params

get_dispersion_params(stability_class: str) -> jnp.ndarray

Return the Briggs parameter vector for a stability class.

Parameters

stability_class : str One of 'A', 'B', 'C', 'D', 'E', 'F'.

Returns

params : jnp.ndarray, shape (6,) [a_y, b_y, c_y, a_z, b_z, c_z].

Raises

ValueError If stability_class is not one of A-F.

Source code in src/plumax/gauss_plume/_src/dispersion.py
def get_dispersion_params(stability_class: str) -> jnp.ndarray:
    """Return the Briggs parameter vector for a stability class.

    Parameters
    ----------
    stability_class : str
        One of ``'A'``, ``'B'``, ``'C'``, ``'D'``, ``'E'``, ``'F'``.

    Returns
    -------
    params : jnp.ndarray, shape (6,)
        ``[a_y, b_y, c_y, a_z, b_z, c_z]``.

    Raises
    ------
    ValueError
        If ``stability_class`` is not one of A-F.
    """
    return lookup_stability(
        BRIGGS_DISPERSION_PARAMS, stability_class, caller="get_dispersion_params"
    )

golder_class_boundaries

golder_class_boundaries(z0: float) -> Float[Array, ' boundary']

Inverse Obukhov lengths at Golder's five PG class boundaries.

(1/L)_k = (ln z₀ − d_k) / c_k for the A/B, B/C, C/D, D/E and E/F boundaries, with z₀ clamped to :data:GOLDER_Z0_RANGE.

Parameters:

Name Type Description Default
z0 float

Roughness length z₀ > 0 [m].

required

Returns:

Type Description
Float[Array, ' boundary']

The five boundaries [m⁻¹], increasing from A/B (most negative) to E/F.

Examples:

At z₀ = 0.1 m the unstable boundaries sit at L ≈ −10.5, −30.4 and −104 m, the stable ones at L ≈ 112 and 26.9 m:

>>> import jax.numpy as jnp
>>> boundaries = golder_class_boundaries(0.1)
>>> [round(float(1.0 / b), 1) for b in boundaries]
[-10.5, -30.4, -104.1, 111.6, 26.9]

z₀ beyond 0.5 m is clamped:

>>> bool(jnp.allclose(golder_class_boundaries(2.0), golder_class_boundaries(0.5)))
True
Source code in src/plumax/gauss_plume/_src/mo_dispersion.py
def golder_class_boundaries(z0: float) -> Float[Array, " boundary"]:
    """Inverse Obukhov lengths at Golder's five PG class boundaries.

    (1/L)_k = (ln z₀ − d_k) / c_k for the A/B, B/C, C/D, D/E and E/F
    boundaries, with z₀ clamped to :data:`GOLDER_Z0_RANGE`.

    Args:
        z0: Roughness length z₀ > 0 [m].

    Returns:
        The five boundaries [m⁻¹], increasing from A/B (most negative) to E/F.

    Examples:
        At z₀ = 0.1 m the unstable boundaries sit at L ≈ −10.5, −30.4 and
        −104 m, the stable ones at L ≈ 112 and 26.9 m:

        >>> import jax.numpy as jnp
        >>> boundaries = golder_class_boundaries(0.1)
        >>> [round(float(1.0 / b), 1) for b in boundaries]
        [-10.5, -30.4, -104.1, 111.6, 26.9]

        z₀ beyond 0.5 m is clamped:

        >>> bool(jnp.allclose(golder_class_boundaries(2.0), golder_class_boundaries(0.5)))
        True
    """
    roughness = jnp.asarray(z0)
    xp = np if is_concrete(roughness) else jnp
    # bad = ¬(z₀ > 0), so NaN fails
    bad = ~xp.all(xp.asarray(roughness) > 0.0)
    roughness = check_values(
        roughness, bad, "z0 must be positive", error=ParameterError
    )
    clamped = jnp.clip(roughness, *GOLDER_Z0_RANGE)
    log_z0 = jnp.log(clamped)
    scale = jnp.asarray(GOLDER_BOUNDARY_SCALE, dtype=log_z0.dtype)
    offset = jnp.asarray(GOLDER_BOUNDARY_OFFSET, dtype=log_z0.dtype)
    # (1/L)_k = (ln z₀ − d_k) / c_k
    return (log_z0 - offset) / scale

golder_stability_class

golder_stability_class(inverse_obukhov_length: Float[Array, '*shape'] | float, z0: float) -> Int[Array, '*shape']

Golder's (1972) PG class for 1/L and z₀, as an index 0 (A) … 5 (F).

The class is the number of boundaries (1/L)_k strictly below 1/L, so a value on a boundary goes to the less stable class and 1/L = 0 is D.

Parameters:

Name Type Description Default
inverse_obukhov_length Float[Array, '*shape'] | float

1/L [m⁻¹]; zero is neutral, negative unstable.

required
z0 float

Roughness length z₀ > 0 [m].

required

Returns:

Type Description
Int[Array, '*shape']

The class index into :data:~plumax.gauss_plume.STABILITY_CLASSES.

Examples:

Over z₀ = 0.1 m, L = −20 m is B, neutral is D and L = 50 m is E:

>>> import jax.numpy as jnp
>>> inverse = jnp.array([-1.0 / 20.0, 0.0, 1.0 / 50.0])
>>> golder_stability_class(inverse, 0.1).tolist()
[1, 3, 4]
Source code in src/plumax/gauss_plume/_src/mo_dispersion.py
def golder_stability_class(
    inverse_obukhov_length: Float[Array, "*shape"] | float, z0: float
) -> Int[Array, "*shape"]:
    """Golder's (1972) PG class for 1/L and z₀, as an index 0 (A) … 5 (F).

    The class is the number of boundaries (1/L)_k strictly below 1/L, so a
    value on a boundary goes to the less stable class and 1/L = 0 is D.

    Args:
        inverse_obukhov_length: 1/L [m⁻¹]; zero is neutral, negative unstable.
        z0: Roughness length z₀ > 0 [m].

    Returns:
        The class index into :data:`~plumax.gauss_plume.STABILITY_CLASSES`.

    Examples:
        Over z₀ = 0.1 m, L = −20 m is B, neutral is D and L = 50 m is E:

        >>> import jax.numpy as jnp
        >>> inverse = jnp.array([-1.0 / 20.0, 0.0, 1.0 / 50.0])
        >>> golder_stability_class(inverse, 0.1).tolist()
        [1, 3, 4]
    """
    inverse_obukhov_length = jnp.asarray(inverse_obukhov_length)
    boundaries = golder_class_boundaries(z0)
    if inverse_obukhov_length.size == 0:
        # einx rejects a zero-size axis; no lengths, no classes
        return jnp.zeros(inverse_obukhov_length.shape, dtype=int)
    # 1[(1/L)_k < 1/L] for every boundary k
    above = einx.greater(
        "..., boundary -> ... boundary", inverse_obukhov_length, boundaries
    )
    # class = Σ_k 1[(1/L)_k < 1/L]
    return einx.sum("... [boundary]", above)

golder_stability_index

golder_stability_index(inverse_obukhov_length: Float[Array, '*shape'] | float, z0: float) -> Float[Array, '*shape']

Continuous PG class index from 1/L and z₀, piecewise linear in 1/L.

s(1/L) interpolates linearly through the knots (1/L, s) = ((1/L)_AB − Δ_A, 0), ((1/L)_AB, 0.5), ((1/L)_BC, 1.5), ((1/L)_CD, 2.5), (0, 3), ((1/L)_DE, 3.5), ((1/L)_EF, 4.5), ((1/L)_EF + Δ_F, 5), and is clamped to [0, 5] outside them, with Δ_A = ((1/L)_BC − (1/L)_AB)/2 and Δ_F = ((1/L)_EF − (1/L)_DE)/2 (the half-width of the neighbouring class).

This is a plumax modelling choice, not part of Golder (1972): Golder gives only the class boundaries. Each boundary maps to the half-integer between its two classes, so round of the index (ties to the less stable class) is the hard class of :func:golder_stability_class, and neutral maps to exactly 3 (class D). Its derivative in 1/L is non-zero everywhere except deep inside A (1/L < (1/L)_AB − Δ_A) and F (1/L > (1/L)_EF + Δ_F).

Parameters:

Name Type Description Default
inverse_obukhov_length Float[Array, '*shape'] | float

1/L [m⁻¹]; zero is neutral, negative unstable.

required
z0 float

Roughness length z₀ > 0 [m] (a scalar).

required

Returns:

Type Description
Float[Array, '*shape']

The class index s ∈ [0, 5], 0 for A and 5 for F.

Examples:

Boundaries land on half-integers and neutral on D:

>>> import jax.numpy as jnp
>>> boundaries = golder_class_boundaries(0.1)
>>> golder_stability_index(boundaries, 0.1).tolist()
[0.5, 1.5, 2.5, 3.5, 4.5]
>>> float(golder_stability_index(0.0, 0.1))
3.0
Source code in src/plumax/gauss_plume/_src/mo_dispersion.py
def golder_stability_index(
    inverse_obukhov_length: Float[Array, "*shape"] | float, z0: float
) -> Float[Array, "*shape"]:
    """Continuous PG class index from 1/L and z₀, piecewise linear in 1/L.

    s(1/L) interpolates linearly through the knots (1/L, s) =
    ((1/L)_AB − Δ_A, 0), ((1/L)_AB, 0.5), ((1/L)_BC, 1.5), ((1/L)_CD, 2.5),
    (0, 3), ((1/L)_DE, 3.5), ((1/L)_EF, 4.5), ((1/L)_EF + Δ_F, 5), and is
    clamped to [0, 5] outside them, with Δ_A = ((1/L)_BC − (1/L)_AB)/2 and
    Δ_F = ((1/L)_EF − (1/L)_DE)/2 (the half-width of the neighbouring class).

    This is a plumax modelling choice, not part of Golder (1972): Golder gives
    only the class boundaries. Each boundary maps to the half-integer between
    its two classes, so ``round`` of the index (ties to the less stable class)
    is the hard class of :func:`golder_stability_class`, and neutral maps to
    exactly 3 (class D). Its derivative in 1/L is non-zero everywhere except
    deep inside A (1/L < (1/L)_AB − Δ_A) and F (1/L > (1/L)_EF + Δ_F).

    Args:
        inverse_obukhov_length: 1/L [m⁻¹]; zero is neutral, negative unstable.
        z0: Roughness length z₀ > 0 [m] (a scalar).

    Returns:
        The class index s ∈ [0, 5], 0 for A and 5 for F.

    Examples:
        Boundaries land on half-integers and neutral on D:

        >>> import jax.numpy as jnp
        >>> boundaries = golder_class_boundaries(0.1)
        >>> golder_stability_index(boundaries, 0.1).tolist()
        [0.5, 1.5, 2.5, 3.5, 4.5]
        >>> float(golder_stability_index(0.0, 0.1))
        3.0
    """
    inverse_obukhov_length = jnp.asarray(inverse_obukhov_length)
    boundaries = golder_class_boundaries(z0)
    # Δ_A = ((1/L)_BC − (1/L)_AB) / 2
    half_width_a = 0.5 * (boundaries[1] - boundaries[0])
    # Δ_F = ((1/L)_EF − (1/L)_DE) / 2
    half_width_f = 0.5 * (boundaries[4] - boundaries[3])
    # first knot (1/L)_AB − Δ_A and last knot (1/L)_EF + Δ_F
    first_knot = boundaries[0] - half_width_a
    last_knot = boundaries[4] + half_width_f
    neutral = jnp.zeros((), dtype=boundaries.dtype)
    # knots in increasing 1/L, with the neutral knot 0 between C|D and D|E
    knots = einx.id(
        ", lower, , upper, -> (1 + lower + 1 + upper + 1)",
        first_knot,
        boundaries[:3],
        neutral,
        boundaries[3:],
        last_knot,
    )
    index_knots = jnp.asarray(_INDEX_KNOTS, dtype=boundaries.dtype)
    return jnp.interp(inverse_obukhov_length, knots, index_knots)

plume_concentration

plume_concentration(x: ndarray, y: ndarray, z: ndarray, source_x: Float[ArrayLike, ''], source_y: Float[ArrayLike, ''], source_z: Float[ArrayLike, ''], wind_u: Float[ArrayLike, ''], wind_v: Float[ArrayLike, ''], emission_rate: Float[ArrayLike, ''], dispersion_params: ndarray | GolderDispersion, plume_rise: BriggsPlumeRise | None = None) -> jnp.ndarray

Evaluate the steady-state Gaussian plume concentration.

Computes the mass concentration [kg/m³] at receptor points (x, y, z) in the fixed reference frame. Coordinates are rotated into the wind-aligned frame internally, upwind points are masked to zero, and ground reflection is applied.

Parameters

x, y, z : jnp.ndarray Receptor coordinates in the fixed frame [m]. Broadcast-compatible. source_x, source_y, source_z : float Source location [m]. source_z is the emission height above ground. wind_u, wind_v : float Wind velocity components [m/s]. The total wind speed is clamped below to :data:MIN_WIND_SPEED for numerical stability. emission_rate : float Continuous emission rate Q [kg/s]. dispersion_params : jnp.ndarray, shape (6,), or GolderDispersion [a_y, b_y, c_y, a_z, b_z, c_z] (Briggs parameters of one PG class), or a :class:~plumax.gauss_plume.GolderDispersion that picks the PG class from the Obukhov length and roughness length. plume_rise : BriggsPlumeRise, optional Plume rise Δh(x'). When given, the release height at each receptor is the effective height source_z + Δh(x') with Δh evaluated at the receptor's downwind distance and the (clamped) wind speed; it is differentiable in the stack parameters. Default None keeps the fixed height source_z.

Returns

concentration : jnp.ndarray Mass concentration [kg/m³], same shape as the broadcast of the input coordinates. Zero at upwind locations (x' ≤ 0).

Source code in src/plumax/gauss_plume/_src/plume.py
@jit
def plume_concentration(
    x: jnp.ndarray,
    y: jnp.ndarray,
    z: jnp.ndarray,
    source_x: Float[ArrayLike, ""],
    source_y: Float[ArrayLike, ""],
    source_z: Float[ArrayLike, ""],
    wind_u: Float[ArrayLike, ""],
    wind_v: Float[ArrayLike, ""],
    emission_rate: Float[ArrayLike, ""],
    dispersion_params: jnp.ndarray | GolderDispersion,
    plume_rise: BriggsPlumeRise | None = None,
) -> jnp.ndarray:
    """Evaluate the steady-state Gaussian plume concentration.

    Computes the mass concentration [kg/m³] at receptor points ``(x, y, z)``
    in the fixed reference frame. Coordinates are rotated into the
    wind-aligned frame internally, upwind points are masked to zero, and
    ground reflection is applied.

    Parameters
    ----------
    x, y, z : jnp.ndarray
        Receptor coordinates in the fixed frame [m]. Broadcast-compatible.
    source_x, source_y, source_z : float
        Source location [m]. ``source_z`` is the emission height above ground.
    wind_u, wind_v : float
        Wind velocity components [m/s]. The total wind speed is clamped
        below to :data:`MIN_WIND_SPEED` for numerical stability.
    emission_rate : float
        Continuous emission rate Q [kg/s].
    dispersion_params : jnp.ndarray, shape (6,), or GolderDispersion
        ``[a_y, b_y, c_y, a_z, b_z, c_z]`` (Briggs parameters of one PG
        class), or a :class:`~plumax.gauss_plume.GolderDispersion` that picks
        the PG class from the Obukhov length and roughness length.
    plume_rise : BriggsPlumeRise, optional
        Plume rise Δh(x'). When given, the release height at each receptor is
        the effective height ``source_z + Δh(x')`` with Δh evaluated at the
        receptor's downwind distance and the (clamped) wind speed; it is
        differentiable in the stack parameters. Default ``None`` keeps the
        fixed height ``source_z``.

    Returns
    -------
    concentration : jnp.ndarray
        Mass concentration [kg/m³], same shape as the broadcast of the
        input coordinates. Zero at upwind locations (x' ≤ 0).
    """
    # U = √(u² + v²), with a zero gradient in calm air, clamped below
    wind_speed = safe_sqrt(jnp.asarray(wind_u**2 + wind_v**2), jnp)
    wind_speed = jnp.maximum(wind_speed, MIN_WIND_SPEED)

    x_downwind, y_crosswind = rotate_to_wind_frame(
        x, y, source_x, source_y, wind_u, wind_v
    )

    x_positive = jnp.maximum(x_downwind, 1.0)
    if isinstance(dispersion_params, GolderDispersion):
        crosswind_spread, vertical_spread = dispersion_params(x_positive)
    else:
        crosswind_spread, vertical_spread = calculate_briggs_dispersion(
            x_positive, dispersion_params
        )

    # 2π U σ_y σ_z
    normalization = 2.0 * jnp.pi * wind_speed * crosswind_spread * vertical_spread

    # exp(−y'² / 2σ_y²)
    exp_y = jnp.exp(-0.5 * jnp.square(y_crosswind / crosswind_spread))

    if plume_rise is None:
        release_height = source_z
    else:
        # H_eff = H + Δh(x')
        release_height = source_z + plume_rise(x_positive, wind_speed=wind_speed)

    # z − H_eff and z + H_eff, the direct and ground-reflected images
    z_diff = z - release_height
    height_sum = z + release_height
    # exp(−(z − H)² / 2σ_z²)
    exp_z_direct = jnp.exp(-0.5 * jnp.square(z_diff / vertical_spread))
    # exp(−(z + H)² / 2σ_z²)
    exp_z_reflected = jnp.exp(-0.5 * jnp.square(height_sum / vertical_spread))

    concentration = (
        (emission_rate / normalization) * exp_y * (exp_z_direct + exp_z_reflected)
    )
    return jnp.where(x_downwind > 0.0, concentration, 0.0)

rotate_to_wind_frame

rotate_to_wind_frame(x: ndarray, y: ndarray, source_x: Float[ArrayLike, ''], source_y: Float[ArrayLike, ''], wind_u: Float[ArrayLike, ''], wind_v: Float[ArrayLike, '']) -> tuple[jnp.ndarray, jnp.ndarray]

Rotate fixed-frame coordinates into the wind-aligned frame.

The wind-aligned frame has its origin at the source, its x'-axis pointing downwind, and its y'-axis pointing crosswind (90° counter-clockwise from x', following the right-hand rule). The rotation angle is θ = atan2(wind_v, wind_u) [rad].

Parameters

x, y : jnp.ndarray Receptor coordinates in the fixed frame [m]. Must have matching shapes (or be broadcast-compatible). source_x, source_y : float Source location in the fixed frame [m]. wind_u, wind_v : float Wind velocity components [m/s].

Returns

x_wind : jnp.ndarray Downwind coordinate x' [m] (> 0 downwind, < 0 upwind of source). y_wind : jnp.ndarray Crosswind coordinate y' [m].

Source code in src/plumax/gauss_plume/_src/plume.py
@jit
def rotate_to_wind_frame(
    x: jnp.ndarray,
    y: jnp.ndarray,
    source_x: Float[ArrayLike, ""],
    source_y: Float[ArrayLike, ""],
    wind_u: Float[ArrayLike, ""],
    wind_v: Float[ArrayLike, ""],
) -> tuple[jnp.ndarray, jnp.ndarray]:
    """Rotate fixed-frame coordinates into the wind-aligned frame.

    The wind-aligned frame has its origin at the source, its x'-axis pointing
    downwind, and its y'-axis pointing crosswind (90° counter-clockwise from
    x', following the right-hand rule). The rotation angle is
    ``θ = atan2(wind_v, wind_u)`` [rad].

    Parameters
    ----------
    x, y : jnp.ndarray
        Receptor coordinates in the fixed frame [m]. Must have matching
        shapes (or be broadcast-compatible).
    source_x, source_y : float
        Source location in the fixed frame [m].
    wind_u, wind_v : float
        Wind velocity components [m/s].

    Returns
    -------
    x_wind : jnp.ndarray
        Downwind coordinate x' [m] (> 0 downwind, < 0 upwind of source).
    y_wind : jnp.ndarray
        Crosswind coordinate y' [m].
    """
    # Δx = x − x_s
    spacing_x = x - source_x
    # Δy = y − y_s
    spacing_y = y - source_y

    # θ = atan2(v, u), 0 with a zero gradient in calm air
    angle = safe_atan2(jnp.asarray(wind_v), jnp.asarray(wind_u), jnp)
    cos_theta = jnp.cos(angle)
    sin_theta = jnp.sin(angle)

    # x' = Δx cos θ + Δy sin θ
    x_wind = spacing_x * cos_theta + spacing_y * sin_theta
    # y' = −Δx sin θ + Δy cos θ
    y_wind = -spacing_x * sin_theta + spacing_y * cos_theta
    return x_wind, y_wind

simulate_plume

simulate_plume(emission_rate: float, source_location: tuple[float, float, float], wind_speed: float, wind_direction: float, stability_class: str | GolderDispersion, domain_x: tuple[float, float, int], domain_y: tuple[float, float, int], domain_z: tuple[float, float, int], background_conc: float = 0.0, plume_rise: BriggsPlumeRise | None = None) -> xr.Dataset

Simulate a steady-state Gaussian plume on a 3-D grid.

Wraps :func:plume_concentration with grid construction, wind-from-angle to (u, v) conversion, and column integration, returning an :class:xarray.Dataset suitable for plotting / I/O.

Wind-direction convention follows the meteorological "from" convention: wind_direction = 270° is a wind from the west (flowing east); wind_direction = 0° is a wind from the north (flowing south).

u = -wind_speed · sin(θ),     v = -wind_speed · cos(θ),
    with θ = wind_direction in radians.
Parameters

emission_rate : float Continuous emission rate Q [kg/s]. Must be strictly positive. source_location : tuple of float, (3,) (x, y, z) source coordinates [m]. z ≥ 0. wind_speed : float Wind speed magnitude [m/s]. Must be strictly positive. wind_direction : float Wind direction [degrees from North, meteorological "from" convention]. stability_class : str or GolderDispersion One of 'A', ..., 'F', or a :class:~plumax.gauss_plume.GolderDispersion that picks the class from the Obukhov length and roughness length. domain_x, domain_y, domain_z : tuple of (float, float, int) (start, stop, n_points) for each axis. start < stop and n_points ≥ 2. background_conc : float Additive background concentration [kg/m³]. Default 0.0. plume_rise : BriggsPlumeRise, optional Plume rise added to the source height z (see :func:plume_concentration). Default None: no rise.

Returns

ds : xarray.Dataset Variables: concentration (x, y, z) [kg/m³], column_concentration (x, y) [kg/m²].

Raises

ValueError On invalid stability class, non-positive emission rate, non-positive wind speed, malformed domain tuples, or negative source height.

Source code in src/plumax/gauss_plume/_src/plume.py
def simulate_plume(
    emission_rate: float,
    source_location: tuple[float, float, float],
    wind_speed: float,
    wind_direction: float,
    stability_class: str | GolderDispersion,
    domain_x: tuple[float, float, int],
    domain_y: tuple[float, float, int],
    domain_z: tuple[float, float, int],
    background_conc: float = 0.0,
    plume_rise: BriggsPlumeRise | None = None,
) -> xr.Dataset:
    """Simulate a steady-state Gaussian plume on a 3-D grid.

    Wraps :func:`plume_concentration` with grid construction, wind-from-angle
    to (u, v) conversion, and column integration, returning an
    :class:`xarray.Dataset` suitable for plotting / I/O.

    Wind-direction convention follows the meteorological "from" convention:
    ``wind_direction = 270°`` is a wind *from* the west (flowing east);
    ``wind_direction = 0°`` is a wind *from* the north (flowing south).

        u = -wind_speed · sin(θ),     v = -wind_speed · cos(θ),
            with θ = wind_direction in radians.

    Parameters
    ----------
    emission_rate : float
        Continuous emission rate Q [kg/s]. Must be strictly positive.
    source_location : tuple of float, (3,)
        (x, y, z) source coordinates [m]. ``z ≥ 0``.
    wind_speed : float
        Wind speed magnitude [m/s]. Must be strictly positive.
    wind_direction : float
        Wind direction [degrees from North, meteorological "from" convention].
    stability_class : str or GolderDispersion
        One of ``'A'``, ..., ``'F'``, or a
        :class:`~plumax.gauss_plume.GolderDispersion` that picks the class from
        the Obukhov length and roughness length.
    domain_x, domain_y, domain_z : tuple of (float, float, int)
        ``(start, stop, n_points)`` for each axis. ``start < stop`` and
        ``n_points ≥ 2``.
    background_conc : float
        Additive background concentration [kg/m³]. Default ``0.0``.
    plume_rise : BriggsPlumeRise, optional
        Plume rise added to the source height ``z`` (see
        :func:`plume_concentration`). Default ``None``: no rise.

    Returns
    -------
    ds : xarray.Dataset
        Variables: ``concentration`` (x, y, z) [kg/m³],
        ``column_concentration`` (x, y) [kg/m²].

    Raises
    ------
    ValueError
        On invalid stability class, non-positive emission rate, non-positive
        wind speed, malformed domain tuples, or negative source height.
    """
    import xarray as xr  # lazy — only this entry point requires xarray

    require_positive("emission_rate", emission_rate, caller="simulate_plume")
    require_positive("wind_speed", wind_speed, caller="simulate_plume")
    is_golder = isinstance(stability_class, GolderDispersion)
    if not is_golder:
        check_stability(stability_class, caller="simulate_plume")
    check_source(source_location, caller="simulate_plume")
    check_domain("domain_x", domain_x, caller="simulate_plume")
    check_domain("domain_y", domain_y, caller="simulate_plume")
    check_domain("domain_z", domain_z, caller="simulate_plume")

    if isinstance(stability_class, GolderDispersion):
        dispersion_params = stability_class
        stability_attr = "golder"
    else:
        dispersion_params = get_dispersion_params(stability_class)
        stability_attr = stability_class

    easting = node_axis(domain_x)
    northing = node_axis(domain_y)
    height = node_axis(domain_z)
    num_x, num_y = len(easting), len(northing)

    wind_u, wind_v = wind_components(wind_speed, wind_direction, xp=np)

    src_x, src_y, src_z = source_location

    easting_flat, northing_flat, height_flat = flat_mesh(easting, northing, height)
    conc_flat = plume_concentration(
        jnp.asarray(easting_flat),
        jnp.asarray(northing_flat),
        jnp.asarray(height_flat),
        src_x,
        src_y,
        src_z,
        float(wind_u),
        float(wind_v),
        emission_rate,
        dispersion_params,
        plume_rise=plume_rise,
    )
    conc_flat = np.asarray(conc_flat)
    concentration = einx.id("(x y z) -> x y z", conc_flat, x=num_x, y=num_y)
    concentration = concentration + background_conc

    # Trapezoidal vertical integration: the z grid from ``np.linspace`` includes
    # both endpoints, so a plain ``sum * dz`` over-counts a vertically uniform
    # component (e.g. a background) by one grid interval, a factor
    # num_z / (num_z − 1).
    # h_k, the trapezoid weights on the levels z_k
    levels = functax_quad.trapezoid(height)
    # Ω(x, y) = Σ_k h_k C(x, y, z_k)
    integral = integrix_rule.integrate(levels, concentration, axis=2)
    column = np.asarray(integral.value)

    dataset = xr.Dataset(
        data_vars={
            "concentration": (["x", "y", "z"], concentration),
            "column_concentration": (["x", "y"], column),
        },
        coords={"x": easting, "y": northing, "z": height},
        attrs={
            "title": "Steady-state Gaussian plume (JAX)",
            "emission_rate": emission_rate,
            "emission_rate_units": "kg/s",
            "source_x": src_x,
            "source_y": src_y,
            "source_z": src_z,
            "wind_speed": wind_speed,
            "wind_speed_units": "m/s",
            "wind_direction": wind_direction,
            "wind_direction_units": "degrees from North (meteorological)",
            "wind_u": float(wind_u),
            "wind_v": float(wind_v),
            "stability_class": stability_attr,
            "background_concentration": background_conc,
        },
    )
    label_concentrations(dataset)
    return dataset

briggs_plume_rise

briggs_plume_rise(x: Float[Array, '*obs'], *, exit_velocity: float | Float[Array, ''], exit_temperature: float | Float[Array, ''], stack_diameter: float | Float[Array, ''], ambient_temperature: float | Float[Array, ''], wind_speed: float | Float[Array, ''], stability_class: str = 'D') -> Float[Array, '*obs']

Briggs plume rise Δh(x) [m]; see :class:BriggsPlumeRise.

Parameters:

Name Type Description Default
x Float[Array, '*obs']

Downwind distance [m].

required
exit_velocity float | Float[Array, '']

Stack exit velocity v_s [m s⁻¹].

required
exit_temperature float | Float[Array, '']

Stack gas temperature T_s [K].

required
stack_diameter float | Float[Array, '']

Stack diameter d [m].

required
ambient_temperature float | Float[Array, '']

Ambient temperature T_a [K].

required
wind_speed float | Float[Array, '']

Wind speed u at the stack top [m s⁻¹].

required
stability_class str

Pasquill–Gifford class 'A' … 'F'.

'D'

Returns:

Type Description
Float[Array, '*obs']

Δh(x), with the final rise past x_f.

Examples:

The final rise of a buoyant plume in neutral air (F_b < 55):

>>> import jax.numpy as jnp
>>> rise = briggs_plume_rise(
...     jnp.array([1.0e5]), exit_velocity=10.0, exit_temperature=400.0,
...     stack_diameter=2.0, ambient_temperature=290.0, wind_speed=5.0,
... )
>>> flux = 9.80665 * 10.0 * 4.0 * 110.0 / 1600.0
>>> final = 1.6 * flux ** (1 / 3) * (49.0 * flux ** 0.625) ** (2 / 3) / 5.0
>>> bool(jnp.allclose(rise, final))
True
Source code in src/plumax/gauss_plume/_src/plume_rise.py
def briggs_plume_rise(
    x: Float[Array, "*obs"],
    *,
    exit_velocity: float | Float[Array, ""],
    exit_temperature: float | Float[Array, ""],
    stack_diameter: float | Float[Array, ""],
    ambient_temperature: float | Float[Array, ""],
    wind_speed: float | Float[Array, ""],
    stability_class: str = "D",
) -> Float[Array, "*obs"]:
    """Briggs plume rise Δh(x) [m]; see :class:`BriggsPlumeRise`.

    Args:
        x: Downwind distance [m].
        exit_velocity: Stack exit velocity v_s [m s⁻¹].
        exit_temperature: Stack gas temperature T_s [K].
        stack_diameter: Stack diameter d [m].
        ambient_temperature: Ambient temperature T_a [K].
        wind_speed: Wind speed u at the stack top [m s⁻¹].
        stability_class: Pasquill–Gifford class ``'A'`` … ``'F'``.

    Returns:
        Δh(x), with the final rise past x_f.

    Examples:
        The final rise of a buoyant plume in neutral air (F_b < 55):

        >>> import jax.numpy as jnp
        >>> rise = briggs_plume_rise(
        ...     jnp.array([1.0e5]), exit_velocity=10.0, exit_temperature=400.0,
        ...     stack_diameter=2.0, ambient_temperature=290.0, wind_speed=5.0,
        ... )
        >>> flux = 9.80665 * 10.0 * 4.0 * 110.0 / 1600.0
        >>> final = 1.6 * flux ** (1 / 3) * (49.0 * flux ** 0.625) ** (2 / 3) / 5.0
        >>> bool(jnp.allclose(rise, final))
        True
    """
    plume_rise = BriggsPlumeRise(
        exit_velocity=exit_velocity,
        exit_temperature=exit_temperature,
        stack_diameter=stack_diameter,
        ambient_temperature=ambient_temperature,
        stability_class=stability_class,
    )
    return plume_rise(x, wind_speed=wind_speed)

effective_height

effective_height(x: Float[Array, '*obs'], *, stack_height: float | Float[Array, ''], exit_velocity: float | Float[Array, ''], exit_temperature: float | Float[Array, ''], stack_diameter: float | Float[Array, ''], ambient_temperature: float | Float[Array, ''], wind_speed: float | Float[Array, ''], stability_class: str = 'D') -> Float[Array, '*obs']

Effective release height H_eff(x) = H_stack + Δh(x) [m].

Parameters:

Name Type Description Default
x Float[Array, '*obs']

Downwind distance [m].

required
stack_height float | Float[Array, '']

Physical stack height H_stack [m].

required
exit_velocity float | Float[Array, '']

Stack exit velocity v_s [m s⁻¹].

required
exit_temperature float | Float[Array, '']

Stack gas temperature T_s [K].

required
stack_diameter float | Float[Array, '']

Stack diameter d [m].

required
ambient_temperature float | Float[Array, '']

Ambient temperature T_a [K].

required
wind_speed float | Float[Array, '']

Wind speed u at the stack top [m s⁻¹].

required
stability_class str

Pasquill–Gifford class 'A' … 'F'.

'D'

Returns:

Type Description
Float[Array, '*obs']

H_eff at each x.

Examples:

At the stack itself the plume has not risen yet:

>>> import jax.numpy as jnp
>>> effective_height(
...     jnp.array([0.0]), stack_height=30.0, exit_velocity=10.0,
...     exit_temperature=400.0, stack_diameter=2.0,
...     ambient_temperature=290.0, wind_speed=5.0,
... ).tolist()
[30.0]
Source code in src/plumax/gauss_plume/_src/plume_rise.py
def effective_height(
    x: Float[Array, "*obs"],
    *,
    stack_height: float | Float[Array, ""],
    exit_velocity: float | Float[Array, ""],
    exit_temperature: float | Float[Array, ""],
    stack_diameter: float | Float[Array, ""],
    ambient_temperature: float | Float[Array, ""],
    wind_speed: float | Float[Array, ""],
    stability_class: str = "D",
) -> Float[Array, "*obs"]:
    """Effective release height H_eff(x) = H_stack + Δh(x) [m].

    Args:
        x: Downwind distance [m].
        stack_height: Physical stack height H_stack [m].
        exit_velocity: Stack exit velocity v_s [m s⁻¹].
        exit_temperature: Stack gas temperature T_s [K].
        stack_diameter: Stack diameter d [m].
        ambient_temperature: Ambient temperature T_a [K].
        wind_speed: Wind speed u at the stack top [m s⁻¹].
        stability_class: Pasquill–Gifford class ``'A'`` … ``'F'``.

    Returns:
        H_eff at each x.

    Examples:
        At the stack itself the plume has not risen yet:

        >>> import jax.numpy as jnp
        >>> effective_height(
        ...     jnp.array([0.0]), stack_height=30.0, exit_velocity=10.0,
        ...     exit_temperature=400.0, stack_diameter=2.0,
        ...     ambient_temperature=290.0, wind_speed=5.0,
        ... ).tolist()
        [30.0]
    """
    rise = briggs_plume_rise(
        x,
        exit_velocity=exit_velocity,
        exit_temperature=exit_temperature,
        stack_diameter=stack_diameter,
        ambient_temperature=ambient_temperature,
        wind_speed=wind_speed,
        stability_class=stability_class,
    )
    # H_eff = H_stack + Δh
    return stack_height + rise

gaussian_plume_model

gaussian_plume_model(observations: ndarray | None = None, receptor_coords: tuple[ndarray, ndarray, ndarray] | None = None, source_location: tuple[float, float, float] | None = None, wind_u: float | None = None, wind_v: float | None = None, stability_class: str = 'C', prior_emission_rate_mean: float = 0.1, prior_emission_rate_std: float = 0.05, infer_stability: bool = False, background_prior_std: float = 5e-07, obs_noise_std: float = 5e-07, noise: Noise | None = None) -> jnp.ndarray

NumPyro model for the steady-state Gaussian plume.

Priors

emission_rate ~ LogNormal(μ_log, σ_log) [kg/s] stability_idx ~ Categorical(1/6, ..., 1/6) (optional) [A..F] background ~ HalfNormal(σ_bg) [kg/m³]

where (μ_log, σ_log) are the log-space parameters derived from the requested real-scale (prior_emission_rate_mean, prior_emission_rate_std) via the method-of-moments inversion in :meth:~plumax._src.scalar_emission.LognormalEmission.from_moments.

Likelihood

obs ~ noise(f_plume(emission_rate, ...) + background)

with noise defaulting to GaussianNoise(obs_noise_std), i.e. obs ~ Normal(f_plume + background, σ_obs).

Parameters

observations : jnp.ndarray, shape (N,), optional Observed concentrations [kg/m³]. If None, runs in prior-predictive mode. receptor_coords : tuple of jnp.ndarray, optional (x, y, z), each shape (N,), in the fixed frame [m]. Required whenever observations is not None. source_location : tuple of float, optional (x, y, z) source coordinates [m]. Required whenever observations is not None. wind_u, wind_v : float, optional Wind velocity components [m/s]. Required whenever observations is not None. stability_class : str Stability class used if infer_stability=False. Default 'C'. prior_emission_rate_mean, prior_emission_rate_std : float Real-scale prior mean / std for the emission rate [kg/s]. The implementation converts these to log-space parameters internally, so the realised prior has the requested mean and variance. infer_stability : bool If True, sample a categorical stability_idx latent over A-F. background_prior_std : float HalfNormal scale for the background concentration [kg/m³]. obs_noise_std : float Observation noise σ [kg/m³] of the default Gaussian noise. Ignored when noise is given. noise : Noise, optional Observation-noise model, e.g. StudentTNoise(scale, df=5.0) or HeteroscedasticNoise(std) from :mod:plumax.gauss_plume.likelihoods. Default None is GaussianNoise(obs_noise_std).

Raises

ValueError If observations is provided but any of receptor_coords, source_location, wind_u, or wind_v is None — that combination disconnects the likelihood from the forward model and would produce a meaningless posterior. Prior-predictive runs (observations=None) are allowed with any subset of forward-model inputs.

Source code in src/plumax/gauss_plume/_src/inference.py
def gaussian_plume_model(
    observations: jnp.ndarray | None = None,
    receptor_coords: tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray] | None = None,
    source_location: tuple[float, float, float] | None = None,
    wind_u: float | None = None,
    wind_v: float | None = None,
    stability_class: str = "C",
    prior_emission_rate_mean: float = 0.1,
    prior_emission_rate_std: float = 0.05,
    infer_stability: bool = False,
    background_prior_std: float = 5e-7,
    obs_noise_std: float = 5e-7,
    noise: Noise | None = None,
) -> jnp.ndarray:
    """NumPyro model for the steady-state Gaussian plume.

    Priors:
        emission_rate ~ LogNormal(μ_log, σ_log)                    [kg/s]
        stability_idx ~ Categorical(1/6, ..., 1/6)  (optional)     [A..F]
        background    ~ HalfNormal(σ_bg)                            [kg/m³]

    where ``(μ_log, σ_log)`` are the log-space parameters derived from the
    requested real-scale ``(prior_emission_rate_mean, prior_emission_rate_std)``
    via the method-of-moments inversion in
    :meth:`~plumax._src.scalar_emission.LognormalEmission.from_moments`.

    Likelihood:
        obs ~ noise(f_plume(emission_rate, ...) + background)

    with ``noise`` defaulting to ``GaussianNoise(obs_noise_std)``, i.e.
    ``obs ~ Normal(f_plume + background, σ_obs)``.

    Parameters
    ----------
    observations : jnp.ndarray, shape (N,), optional
        Observed concentrations [kg/m³]. If None, runs in prior-predictive mode.
    receptor_coords : tuple of jnp.ndarray, optional
        ``(x, y, z)``, each shape (N,), in the fixed frame [m]. Required
        whenever ``observations`` is not None.
    source_location : tuple of float, optional
        ``(x, y, z)`` source coordinates [m]. Required whenever ``observations``
        is not None.
    wind_u, wind_v : float, optional
        Wind velocity components [m/s]. Required whenever ``observations``
        is not None.
    stability_class : str
        Stability class used if ``infer_stability=False``. Default ``'C'``.
    prior_emission_rate_mean, prior_emission_rate_std : float
        **Real-scale** prior mean / std for the emission rate [kg/s]. The
        implementation converts these to log-space parameters internally, so
        the realised prior has the requested mean and variance.
    infer_stability : bool
        If True, sample a categorical ``stability_idx`` latent over A-F.
    background_prior_std : float
        HalfNormal scale for the background concentration [kg/m³].
    obs_noise_std : float
        Observation noise σ [kg/m³] of the default Gaussian noise. Ignored
        when ``noise`` is given.
    noise : Noise, optional
        Observation-noise model, e.g. ``StudentTNoise(scale, df=5.0)`` or
        ``HeteroscedasticNoise(std)`` from :mod:`plumax.gauss_plume.likelihoods`.
        Default ``None`` is ``GaussianNoise(obs_noise_std)``.

    Raises
    ------
    ValueError
        If ``observations`` is provided but any of ``receptor_coords``,
        ``source_location``, ``wind_u``, or ``wind_v`` is ``None`` — that
        combination disconnects the likelihood from the forward model and
        would produce a meaningless posterior. Prior-predictive runs
        (``observations=None``) are allowed with any subset of forward-model
        inputs.
    """
    forward_inputs_present = (
        receptor_coords is not None
        and source_location is not None
        and wind_u is not None
        and wind_v is not None
    )
    if observations is not None and not forward_inputs_present:
        missing = [
            name
            for name, value in (
                ("receptor_coords", receptor_coords),
                ("source_location", source_location),
                ("wind_u", wind_u),
                ("wind_v", wind_v),
            )
            if value is None
        ]
        raise ValueError(
            "gaussian_plume_model: `observations` were provided but the "
            "forward model cannot be evaluated — missing inputs: "
            f"{', '.join(missing)}. Either pass all of "
            "(receptor_coords, source_location, wind_u, wind_v) or set "
            "observations=None for prior-predictive mode."
        )

    emission = LognormalEmission.from_moments(
        prior_emission_rate_mean, prior_emission_rate_std
    )
    emission_rate = numpyro.sample(
        "emission_rate", dist.LogNormal(emission.loc, emission.scale)
    )

    if infer_stability:
        stability_probs = jnp.ones(len(STABILITY_CLASSES)) / len(STABILITY_CLASSES)
        stability_idx = numpyro.sample(
            "stability_idx", dist.Categorical(probs=stability_probs)
        )
        all_params = stacked_params(BRIGGS_DISPERSION_PARAMS)
        dispersion_params = all_params[stability_idx]
    else:
        dispersion_params = get_dispersion_params(stability_class)

    background = numpyro.sample("background", dist.HalfNormal(background_prior_std))

    if forward_inputs_present:
        easting_obs, northing_obs, height_obs = receptor_coords
        src_x, src_y, src_z = source_location
        predicted = plume_concentration(
            easting_obs,
            northing_obs,
            height_obs,
            src_x,
            src_y,
            src_z,
            wind_u,
            wind_v,
            emission_rate,
            dispersion_params,
        )
        predicted = predicted + background
    else:
        # Prior-predictive mode (observations is None and no forward inputs).
        predicted = background

    noise_model = GaussianNoise(std=obs_noise_std) if noise is None else noise
    return noise_model("obs", predicted, observations)

infer_emission_rate

infer_emission_rate(observations: ndarray, observation_coords: tuple[ndarray, ndarray, ndarray], source_location: tuple[float, float, float], wind_speed: float, wind_direction: float, stability_class: str = 'C', infer_stability: bool = False, prior_mean: float = 0.1, prior_std: float = 0.05, num_warmup: int = 500, num_samples: int = 1000, num_chains: int = 1, seed: int = 0, progress_bar: bool = False, print_summary: bool = False, obs_noise_std: float = 5e-07, background_prior_std: float = 5e-07, noise: Noise | None = None) -> EmissionRateSamples

Infer the plume emission rate via NUTS.

Wraps :func:gaussian_plume_model with input validation, wind-from-angle to (u, v) conversion, and posterior unpacking into NumPy arrays.

Identifiability target: three overpasses with varied wind direction should give a posterior CV(Q) ≤ 50 %, and a single overpass CV(Q) ≤ 100 % under a tight met wind prior (Tier I design, "Identifiability — quantitative target"). A wider posterior means the data do not constrain Q yet.

Parameters

observations : ndarray, shape (N,) Observed concentrations [kg/m³]. observation_coords : tuple of ndarray (x, y, z), each shape (N,), in the fixed frame [m]. source_location : tuple of float, (3,) (x, y, z) source coordinates [m]. wind_speed : float Wind speed magnitude [m/s]. Must be > 0. wind_direction : float Wind direction [degrees from North, meteorological "from" convention]. stability_class : str Stability class used if infer_stability=False. Default 'C'. infer_stability : bool If True, jointly sample a categorical stability-class latent. prior_mean, prior_std : float Prior parameters for the emission rate [kg/s]. num_warmup, num_samples, num_chains : int NUTS sampler configuration. seed : int PRNG seed. progress_bar : bool If True, show the NumPyro progress bar. Default False. print_summary : bool If True, call mcmc.print_summary() after the run. obs_noise_std : float Observation-noise σ for the Gaussian likelihood [kg/m³]. Set this to the sensor noise so the posterior width reflects the instrument rather than the hard-coded default. Ignored when noise is given. background_prior_std : float HalfNormal scale for the background-concentration prior [kg/m³]. noise : Noise, optional Observation-noise model (see :func:gaussian_plume_model). Default None is GaussianNoise(obs_noise_std), today's likelihood.

Returns

samples : EmissionRateSamples Posterior draws keyed by site name: 'emission_rate', 'background', and (if infer_stability) 'stability_idx'. A dict that also carries the Tier V per-event payload (emission_rate / emission_std attributes, samples and prior_logpdf).

Raises

ValueError On invalid stability class, non-positive wind speed, shape mismatches between observations and observation_coords, or empty data.

Source code in src/plumax/gauss_plume/_src/inference.py
def infer_emission_rate(
    observations: np.ndarray,
    observation_coords: tuple[np.ndarray, np.ndarray, np.ndarray],
    source_location: tuple[float, float, float],
    wind_speed: float,
    wind_direction: float,
    stability_class: str = "C",
    infer_stability: bool = False,
    prior_mean: float = 0.1,
    prior_std: float = 0.05,
    num_warmup: int = 500,
    num_samples: int = 1000,
    num_chains: int = 1,
    seed: int = 0,
    progress_bar: bool = False,
    print_summary: bool = False,
    obs_noise_std: float = 5e-7,
    background_prior_std: float = 5e-7,
    noise: Noise | None = None,
) -> EmissionRateSamples:
    """Infer the plume emission rate via NUTS.

    Wraps :func:`gaussian_plume_model` with input validation, wind-from-angle
    to (u, v) conversion, and posterior unpacking into NumPy arrays.

    Identifiability target: three overpasses with varied wind direction
    should give a posterior CV(Q) ≤ 50 %, and a single overpass CV(Q) ≤ 100 %
    under a tight met wind prior (Tier I design, "Identifiability —
    quantitative target"). A wider posterior means the data do not constrain
    Q yet.

    Parameters
    ----------
    observations : ndarray, shape (N,)
        Observed concentrations [kg/m³].
    observation_coords : tuple of ndarray
        ``(x, y, z)``, each shape (N,), in the fixed frame [m].
    source_location : tuple of float, (3,)
        ``(x, y, z)`` source coordinates [m].
    wind_speed : float
        Wind speed magnitude [m/s]. Must be > 0.
    wind_direction : float
        Wind direction [degrees from North, meteorological "from" convention].
    stability_class : str
        Stability class used if ``infer_stability=False``. Default ``'C'``.
    infer_stability : bool
        If True, jointly sample a categorical stability-class latent.
    prior_mean, prior_std : float
        Prior parameters for the emission rate [kg/s].
    num_warmup, num_samples, num_chains : int
        NUTS sampler configuration.
    seed : int
        PRNG seed.
    progress_bar : bool
        If True, show the NumPyro progress bar. Default False.
    print_summary : bool
        If True, call ``mcmc.print_summary()`` after the run.
    obs_noise_std : float
        Observation-noise σ for the Gaussian likelihood [kg/m³]. Set this to
        the sensor noise so the posterior width reflects the instrument rather
        than the hard-coded default. Ignored when ``noise`` is given.
    background_prior_std : float
        HalfNormal scale for the background-concentration prior [kg/m³].
    noise : Noise, optional
        Observation-noise model (see :func:`gaussian_plume_model`). Default
        ``None`` is ``GaussianNoise(obs_noise_std)``, today's likelihood.

    Returns
    -------
    samples : EmissionRateSamples
        Posterior draws keyed by site name: ``'emission_rate'``,
        ``'background'``, and (if ``infer_stability``) ``'stability_idx'``.
        A ``dict`` that also carries the Tier V per-event payload
        (``emission_rate`` / ``emission_std`` attributes, ``samples`` and
        ``prior_logpdf``).

    Raises
    ------
    ValueError
        On invalid stability class, non-positive wind speed, shape mismatches
        between ``observations`` and ``observation_coords``, or empty data.
    """
    require_positive("wind_speed", wind_speed, caller="infer_emission_rate")
    if not infer_stability:
        check_stability(stability_class, caller="infer_emission_rate")
    obs, coords = check_observations(
        "infer_emission_rate", observations, observation_coords
    )
    require_positive("prior_mean", prior_mean, caller="infer_emission_rate")
    require_positive("prior_std", prior_std, caller="infer_emission_rate")
    require_positive("obs_noise_std", obs_noise_std, caller="infer_emission_rate")
    require_positive(
        "background_prior_std", background_prior_std, caller="infer_emission_rate"
    )

    wind_east, wind_north = wind_components(wind_speed, wind_direction, xp=np)
    wind_u, wind_v = float(wind_east), float(wind_north)

    obs_jax = jnp.asarray(obs)
    coords_jax = tuple(jnp.asarray(coord) for coord in coords)

    # Discrete latents can't be handled by NUTS on their own without
    # `funsor` enumeration. `DiscreteHMCGibbs` wraps NUTS with a Gibbs
    # step over the categorical stability-class site, avoiding the extra
    # dependency while giving a valid joint sampler.
    samples = run_nuts(
        gaussian_plume_model,
        seed=seed,
        num_warmup=num_warmup,
        num_samples=num_samples,
        num_chains=num_chains,
        progress_bar=progress_bar,
        print_summary=print_summary,
        discrete_gibbs=infer_stability,
        observations=obs_jax,
        receptor_coords=coords_jax,
        source_location=source_location,
        wind_u=wind_u,
        wind_v=wind_v,
        stability_class=stability_class,
        prior_emission_rate_mean=prior_mean,
        prior_emission_rate_std=prior_std,
        infer_stability=infer_stability,
        obs_noise_std=obs_noise_std,
        background_prior_std=background_prior_std,
        noise=noise,
    )

    draws = {name: np.asarray(value) for name, value in samples.items()}
    return EmissionRateSamples(draws, prior_mean=prior_mean, prior_std=prior_std)

infer_multi_source

infer_multi_source(observations: ndarray, observation_coords: tuple[ndarray, ndarray, ndarray], *, wind_speed: float, wind_direction: float, k_max: int = 10, candidate_locations: Float[ArrayLike, 'candidate 2'] | None = None, source_bounds: tuple[tuple[float, float], tuple[float, float]] | None = None, source_height: float = 0.0, stability_class: str = 'C', prior_mean: float = 0.1, prior_std: float = 0.05, prior_active: float = 0.3, obs_noise_std: float = 5e-07, background_prior_std: float = 5e-07, noise: Noise | None = None, num_warmup: int = 500, num_samples: int = 1000, num_chains: int = 1, seed: int = 0, progress_bar: bool = False) -> MultiSourcePosterior

Infer up to K_max sources and their on/off indicators.

Wraps :func:multi_source_plume_model: NUTS for the continuous sites, and a Gibbs step (DiscreteHMCGibbs) over the activity indicators, as for the stability class in :func:infer_emission_rate.

Parameters

observations : ndarray, shape (N,) Observed concentrations [kg/m³]. observation_coords : tuple of ndarray (x, y, z), each shape (N,), in the fixed frame [m]. wind_speed : float Wind speed [m/s], > 0. wind_direction : float Wind direction [degrees from North, meteorological "from" convention]. k_max, candidate_locations, source_bounds, source_height, stability_class Slot layout; see :func:multi_source_plume_model. prior_mean, prior_std : float Real-scale prior moments of each Q_k [kg/s]. prior_active, obs_noise_std, background_prior_std, noise See :func:multi_source_plume_model. num_warmup, num_samples, num_chains, seed : int Sampler configuration. progress_bar : bool Show NumPyro's progress bar.

Returns

posterior : MultiSourcePosterior Draws of every slot; count_probabilities() is the posterior over the active count and per_source(k) the slot's summary.

Raises

ValueError On a non-positive wind speed, an unknown stability class, mismatched shapes, non-positive prior or noise scales, or an invalid slot layout.

Source code in src/plumax/gauss_plume/_src/inference.py
def infer_multi_source(
    observations: np.ndarray,
    observation_coords: tuple[np.ndarray, np.ndarray, np.ndarray],
    *,
    wind_speed: float,
    wind_direction: float,
    k_max: int = 10,
    candidate_locations: Float[ArrayLike, "candidate 2"] | None = None,
    source_bounds: tuple[tuple[float, float], tuple[float, float]] | None = None,
    source_height: float = 0.0,
    stability_class: str = "C",
    prior_mean: float = 0.1,
    prior_std: float = 0.05,
    prior_active: float = 0.3,
    obs_noise_std: float = 5e-7,
    background_prior_std: float = 5e-7,
    noise: Noise | None = None,
    num_warmup: int = 500,
    num_samples: int = 1000,
    num_chains: int = 1,
    seed: int = 0,
    progress_bar: bool = False,
) -> MultiSourcePosterior:
    """Infer up to K_max sources and their on/off indicators.

    Wraps :func:`multi_source_plume_model`: NUTS for the continuous sites, and
    a Gibbs step (``DiscreteHMCGibbs``) over the activity indicators, as for
    the stability class in :func:`infer_emission_rate`.

    Parameters
    ----------
    observations : ndarray, shape (N,)
        Observed concentrations [kg/m³].
    observation_coords : tuple of ndarray
        ``(x, y, z)``, each shape (N,), in the fixed frame [m].
    wind_speed : float
        Wind speed [m/s], > 0.
    wind_direction : float
        Wind direction [degrees from North, meteorological "from" convention].
    k_max, candidate_locations, source_bounds, source_height, stability_class
        Slot layout; see :func:`multi_source_plume_model`.
    prior_mean, prior_std : float
        Real-scale prior moments of each Q_k [kg/s].
    prior_active, obs_noise_std, background_prior_std, noise
        See :func:`multi_source_plume_model`.
    num_warmup, num_samples, num_chains, seed : int
        Sampler configuration.
    progress_bar : bool
        Show NumPyro's progress bar.

    Returns
    -------
    posterior : MultiSourcePosterior
        Draws of every slot; ``count_probabilities()`` is the posterior over
        the active count and ``per_source(k)`` the slot's summary.

    Raises
    ------
    ValueError
        On a non-positive wind speed, an unknown stability class, mismatched
        shapes, non-positive prior or noise scales, or an invalid slot layout.
    """
    require_positive("wind_speed", wind_speed, caller="infer_multi_source")
    check_stability(stability_class, caller="infer_multi_source")
    obs, coords = check_observations(
        "infer_multi_source", observations, observation_coords
    )
    for name, value in (
        ("prior_mean", prior_mean),
        ("prior_std", prior_std),
        ("obs_noise_std", obs_noise_std),
        ("background_prior_std", background_prior_std),
    ):
        require_positive(name, value, caller="infer_multi_source")
    _check_multi_source_layout(k_max, candidate_locations, source_bounds, prior_active)

    wind_east, wind_north = wind_components(wind_speed, wind_direction, xp=np)
    wind_u, wind_v = float(wind_east), float(wind_north)

    return _run_masked_k(
        multi_source_plume_model,
        jnp.asarray(obs),
        k_max=k_max,
        candidate_locations=candidate_locations,
        prior_active=prior_active,
        num_warmup=num_warmup,
        num_samples=num_samples,
        num_chains=num_chains,
        seed=seed,
        progress_bar=progress_bar,
        receptor_coords=tuple(jnp.asarray(coord) for coord in coords),
        wind_u=wind_u,
        wind_v=wind_v,
        source_bounds=source_bounds,
        source_height=source_height,
        stability_class=stability_class,
        prior_emission_rate_mean=prior_mean,
        prior_emission_rate_std=prior_std,
        background_prior_std=background_prior_std,
        obs_noise_std=obs_noise_std,
        noise=noise,
    )

multi_source_plume_model

multi_source_plume_model(observations: ndarray | None = None, *, receptor_coords: tuple[ndarray, ndarray, ndarray], wind_u: float, wind_v: float, k_max: int = 10, candidate_locations: Float[ArrayLike, 'candidate 2'] | None = None, source_bounds: tuple[tuple[float, float], tuple[float, float]] | None = None, source_height: float = 0.0, stability_class: str = 'C', prior_emission_rate_mean: float = 0.1, prior_emission_rate_std: float = 0.05, prior_active: float = 0.3, background_prior_std: float = 5e-07, obs_noise_std: float = 5e-07, noise: Noise | None = None) -> jnp.ndarray

Masked-K NumPyro model: up to K_max plumes, each switched on or off.

Priors, for each slot k = 1 … K_max: a_k ~ Bernoulli(prior_active) [on/off] Q_k ~ LogNormal(μ_log, σ_log) [kg/s] (x_k, y_k) = candidate k, or x ordered uniform and y uniform in source_bounds [m] background ~ HalfNormal(σ_bg) [kg/m³]

Likelihood

obs ~ noise(Σ_k a_k Q_k c₁(x_k, y_k) + background)

with noise defaulting to GaussianNoise(obs_noise_std). The active count K = Σ_k a_k is the posterior over the number of sources.

Label switching: with free locations the slots are exchangeable, so their x positions are drawn as the order statistics of K_max uniforms on [x_low, x_high] (x_low + (x_high − x_low) · cumsum(w)[:K_max] with w ~ Dirichlet(1, …, 1) of length K_max + 1), which pins slot k to the k-th source from the west. Fixed candidate locations (known facilities) have no symmetry to break.

Promotion to RJMCMC (Tier I / IV design): masked-K caps K at K_max. Track the posterior mass at the cap, P(K = K_max | y) (:meth:MultiSourcePosterior.saturated_fraction), per overpass; when more than 5 % of overpasses saturate K_max, the cap is binding and the trans-dimensional (RJMCMC) model is due.

Parameters

observations : jnp.ndarray, shape (N,), optional Observed concentrations [kg/m³]; None for predictive draws. receptor_coords : tuple of jnp.ndarray (x, y, z), each shape (N,), in the fixed frame [m]. wind_u, wind_v : float Wind velocity components [m/s]. k_max : int Number of slots K_max (default 10, the design's v1 cap). candidate_locations : jnp.ndarray, shape (k_max, 2), optional Fixed (x, y) per slot, e.g. inventory facilities. source_bounds : ((x_low, x_high), (y_low, y_high)), optional Box the free slot locations are drawn from. Give exactly one of this and candidate_locations. source_height : float Release height shared by every slot [m]. stability_class : str Pasquill–Gifford class 'A' … 'F'. prior_emission_rate_mean, prior_emission_rate_std : float Real-scale prior moments of each Q_k [kg/s]. prior_active : float Prior probability that a slot is on, in (0, 1]. 1.0 keeps every slot on (no discrete sites), which with K_max = 1 is the single-source model. background_prior_std : float HalfNormal scale of the background [kg/m³]. obs_noise_std : float σ of the default Gaussian noise; ignored when noise is given. noise : Noise, optional Observation-noise model from :mod:plumax.gauss_plume.likelihoods.

Raises

ValueError On an invalid slot layout, k_max < 1 or prior_active outside (0, 1].

Source code in src/plumax/gauss_plume/_src/inference.py
def multi_source_plume_model(
    observations: jnp.ndarray | None = None,
    *,
    receptor_coords: tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray],
    wind_u: float,
    wind_v: float,
    k_max: int = 10,
    candidate_locations: Float[ArrayLike, "candidate 2"] | None = None,
    source_bounds: tuple[tuple[float, float], tuple[float, float]] | None = None,
    source_height: float = 0.0,
    stability_class: str = "C",
    prior_emission_rate_mean: float = 0.1,
    prior_emission_rate_std: float = 0.05,
    prior_active: float = 0.3,
    background_prior_std: float = 5e-7,
    obs_noise_std: float = 5e-7,
    noise: Noise | None = None,
) -> jnp.ndarray:
    """Masked-K NumPyro model: up to K_max plumes, each switched on or off.

    Priors, for each slot k = 1 … K_max:
        a_k ~ Bernoulli(prior_active)                               [on/off]
        Q_k ~ LogNormal(μ_log, σ_log)                               [kg/s]
        (x_k, y_k) = candidate k, or x ordered uniform and y uniform in
                     ``source_bounds``                               [m]
        background ~ HalfNormal(σ_bg)                               [kg/m³]

    Likelihood:
        obs ~ noise(Σ_k a_k Q_k c₁(x_k, y_k) + background)

    with ``noise`` defaulting to ``GaussianNoise(obs_noise_std)``. The active
    count K = Σ_k a_k is the posterior over the number of sources.

    Label switching: with free locations the slots are exchangeable, so their
    x positions are drawn as the order statistics of K_max uniforms on
    ``[x_low, x_high]`` (``x_low + (x_high − x_low) · cumsum(w)[:K_max]`` with
    ``w ~ Dirichlet(1, …, 1)`` of length K_max + 1), which pins slot k to the
    k-th source from the west. Fixed candidate locations (known facilities)
    have no symmetry to break.

    Promotion to RJMCMC (Tier I / IV design): masked-K caps K at K_max. Track
    the posterior mass at the cap, P(K = K_max | y)
    (:meth:`MultiSourcePosterior.saturated_fraction`), per overpass; when more
    than 5 % of overpasses saturate K_max, the cap is binding and the
    trans-dimensional (RJMCMC) model is due.

    Parameters
    ----------
    observations : jnp.ndarray, shape (N,), optional
        Observed concentrations [kg/m³]; ``None`` for predictive draws.
    receptor_coords : tuple of jnp.ndarray
        ``(x, y, z)``, each shape (N,), in the fixed frame [m].
    wind_u, wind_v : float
        Wind velocity components [m/s].
    k_max : int
        Number of slots K_max (default 10, the design's v1 cap).
    candidate_locations : jnp.ndarray, shape (k_max, 2), optional
        Fixed ``(x, y)`` per slot, e.g. inventory facilities.
    source_bounds : ((x_low, x_high), (y_low, y_high)), optional
        Box the free slot locations are drawn from. Give exactly one of this
        and ``candidate_locations``.
    source_height : float
        Release height shared by every slot [m].
    stability_class : str
        Pasquill–Gifford class ``'A'`` … ``'F'``.
    prior_emission_rate_mean, prior_emission_rate_std : float
        Real-scale prior moments of each Q_k [kg/s].
    prior_active : float
        Prior probability that a slot is on, in (0, 1]. ``1.0`` keeps every
        slot on (no discrete sites), which with K_max = 1 is the single-source
        model.
    background_prior_std : float
        HalfNormal scale of the background [kg/m³].
    obs_noise_std : float
        σ of the default Gaussian noise; ignored when ``noise`` is given.
    noise : Noise, optional
        Observation-noise model from :mod:`plumax.gauss_plume.likelihoods`.

    Raises
    ------
    ValueError
        On an invalid slot layout, ``k_max < 1`` or ``prior_active`` outside
        (0, 1].
    """
    _check_multi_source_layout(k_max, candidate_locations, source_bounds, prior_active)
    dispersion_params = get_dispersion_params(stability_class)

    sources, background = _masked_source_prior(
        k_max=k_max,
        candidate_locations=candidate_locations,
        source_bounds=source_bounds,
        prior_emission_rate_mean=prior_emission_rate_mean,
        prior_emission_rate_std=prior_emission_rate_std,
        prior_active=prior_active,
        background_prior_std=background_prior_std,
    )
    predicted = sources.concentration(
        receptor_coords,
        source_z=source_height,
        wind_u=wind_u,
        wind_v=wind_v,
        dispersion_params=dispersion_params,
    )
    predicted = predicted + background

    noise_model = GaussianNoise(std=obs_noise_std) if noise is None else noise
    return noise_model("obs", predicted, observations)