Skip to content

Radiometry

What an instrument adds to Planck's law: the band-integrated Planck radiance and the band brightness temperature that inverts it, by Newton with implicit differentiation. Planck's law in wavenumber, its logarithm, its per-µm and per-GHz views and the monochromatic brightness temperature are radiomax's (radiomax.thermal).

radiomax's Planck function is held here to the checks that radtrax's own was (gate TH12): the constants against the SI 2019 exact h, c and k, the Stefan–Boltzmann law from the spectral integral, the Wien peaks, and pyradi's ryplanck (radiance, derivatives and Widger–Woodall band integrals, rtol 1e-12). pyradi is never imported: scripts/make_planck_oracle.py evaluates ryplanck.py at commit c7cfe9df96fdf0e6c258ee6fd624f62f19ebab06 (MIT licence at the root, BSD-3 per file) in an isolated interpreter and stores the values, with the commit, the NumPy and SciPy versions and SciPy's constants, in tests/data/planck_pyradi_c7cfe9d.npz.

radiometry

Band radiances and brightness temperatures through an instrument.

Planck's law in wavenumber, its views per µm and per GHz and the monochromatic brightness temperature are radiomax.thermal's. What needs an instrument is here: the Planck radiance of its bands, and its inverse (radtrax#248).

surface/ (emission), solvers/ (layer sources), instrument/ (NEΔT) and the retrievals all reach it; it depends on radiomax and exceptions, and names Instrument for type checkers only (radtrax#246).

brightness

Band Planck radiance, and the band brightness temperature that inverts it.

radiomax.thermal holds the monochromatic functions: the Planck radiance \(B(\tilde\nu, T)\) and its closed-form inverse \(T_b(\tilde\nu, L)\). This module holds what an instrument adds.

An instrument is linear in radiance, \(y = A L\) with \(A\) its response matrix (Instrument.response_matrix, (B, G)), so the band-integrated Planck radiance at one temperature per band is

\[ \bar B_b(T_b) = \sum_g A_{bg} B(\tilde\nu_g, T_b), \]

and the band brightness temperature solves \(\bar B_b(T_b) = y_b\) for every band. The bands decouple (the Jacobian of the residual is diagonal), so band_brightness_temperature runs optimistix.Newton with a diagonal linear solve, from the monochromatic \(T_b\) at each band's centroid \(\bar\nu_b = \sum_g A_{bg} \tilde\nu_g / \sum_g A_{bg}\), and is differentiated by the implicit function theorem: \(\partial T_b / \partial y_b = 1 / (\partial \bar B_b / \partial T_b)\) and \(\partial T_b / \partial \theta = -(\partial \bar B_b / \partial \theta) / (\partial \bar B_b / \partial T_b)\) for instrument parameters \(\theta\).

Every formula holds for any linear \(A\); the centroid divides by the row sum, so an instrument in other radiance units (rows that do not sum to 1) works in its own units. The dense \(A\) is materialised once per call, so band brightness temperature is for multispectral thermal bands (tens of bands); for a hyperspectral instrument use the monochromatic \(T_b\) at the centroid.

Shapes: G wavenumbers, B bands; *B means a scalar or (B,).

band_planck_radiance

band_planck_radiance(instrument: Instrument, t_k: Float[ArrayLike, '*B']) -> Float[Array, ' B']

Band-integrated Planck radiance \(\bar B_b(T_b) = \sum_g A_{bg} B(\tilde\nu_g, T_b)\).

One temperature for every band (a scalar) is one instrument call, instrument(planck_radiance(instrument.nu_cm, t_k)); one temperature per band, (B,), contracts the response matrix with \(B\) on the (B, G) grid. Differentiable in t_k and in the instrument.

Parameters:

Name Type Description Default
instrument Instrument

The bands, any Instrument (linear in radiance).

required
t_k Float[ArrayLike, '*B']

Temperature [K], a scalar or one per band, (B,).

required

Returns:

Type Description
Float[Array, ' B']

\(\bar B\) (B,), in the instrument's radiance units

Float[Array, ' B']

(W m⁻² sr⁻¹ (cm⁻¹)⁻¹ for a response whose rows sum to 1).

Examples:

>>> import jax.numpy as jnp
>>> from radtrax.instrument import GaussianInstrument
>>> nu = jnp.linspace(700.0, 1300.0, 1201)
>>> tir = GaussianInstrument(nu, jnp.array([10900.0]), jnp.array([500.0]))
>>> f"{float(band_planck_radiance(tir, 300.0)[0]):.4f}"
'0.1142'
Source code in src/radtrax/radiometry/brightness.py
def band_planck_radiance(
    instrument: Instrument, t_k: Float[ArrayLike, "*B"]
) -> Float[Array, " B"]:
    """Band-integrated Planck radiance $\\bar B_b(T_b) = \\sum_g A_{bg} B(\\tilde\\nu_g, T_b)$.

    One temperature for every band (a scalar) is one instrument call,
    ``instrument(planck_radiance(instrument.nu_cm, t_k))``; one temperature
    per band, ``(B,)``, contracts the response matrix with $B$ on the
    ``(B, G)`` grid. Differentiable in ``t_k`` and in the instrument.

    Args:
        instrument: The bands, any `Instrument` (linear in radiance).
        t_k: Temperature [K], a scalar or one per band, ``(B,)``.

    Returns:
        $\\bar B$ ``(B,)``, in the instrument's radiance units
        (W m⁻² sr⁻¹ (cm⁻¹)⁻¹ for a response whose rows sum to 1).

    Examples:
        >>> import jax.numpy as jnp
        >>> from radtrax.instrument import GaussianInstrument
        >>> nu = jnp.linspace(700.0, 1300.0, 1201)
        >>> tir = GaussianInstrument(nu, jnp.array([10900.0]), jnp.array([500.0]))
        >>> f"{float(band_planck_radiance(tir, 300.0)[0]):.4f}"
        '0.1142'
    """
    t = jnp.asarray(t_k)
    if t.ndim == 0:
        return instrument(planck_radiance(instrument.nu_cm, t))
    return _band_planck(instrument.response_matrix(), instrument.nu_cm, t)

band_brightness_temperature

band_brightness_temperature(instrument: Instrument, y: Float[ArrayLike, ' B'], *, rtol: float = 1e-12, atol: float = 1e-10, max_steps: int = 32, throw: bool = True) -> Float[Array, ' B']

Band brightness temperature: the \(T_b\) with \(\bar B_b(T_b) = y_b\) [K].

Solves \(\ln \bar B_b(T_b) - \ln y_b = 0\) for every band by optimistix.Newton, with a diagonal Jacobian (one JVP per step) and a diagonal linear solve, from the monochromatic \(T_b\) at each band's centroid. The residual is taken in log radiance so that the tolerances mean the same at 0.4 µm and at 15 µm; it has the same root and the same implicit derivatives as \(\bar B_b - y_b\). The unknown is \(u = \ln T_b\), so no Newton step can leave \(T_b > 0\): in \(T\) a broad band's first step from the centroid guess can overshoot below 0 K. Gradients come from the implicit function theorem (optimistix.ImplicitAdjoint), in y and in the instrument's parameters alike.

A band with \(y_b \le 0\) has no brightness temperature: it is solved on a safe value and returned as NaN (double where), so a masked band does not poison the gradient of the others.

Parameters:

Name Type Description Default
instrument Instrument

The bands, any Instrument (linear in radiance).

required
y Float[ArrayLike, ' B']

Band values, (B,), in the instrument's radiance units.

required
rtol float

Relative tolerance of the Newton solve in \(\ln T\).

1e-12
atol float

Absolute tolerance of the Newton solve (in \(\ln T\) and in the log residual).

1e-10
max_steps int

The most Newton steps.

32
throw bool

Raise when the solve fails to converge (equinox.EquinoxRuntimeError under jit); otherwise return the last iterate.

True

Returns:

Type Description
Float[Array, ' B']

\(T_b\) [K], (B,); NaN where \(y_b \le 0\).

Examples:

>>> import jax.numpy as jnp
>>> from radtrax.instrument import GaussianInstrument
>>> nu = jnp.linspace(700.0, 1300.0, 1201)
>>> tir = GaussianInstrument(nu, jnp.array([10900.0]), jnp.array([500.0]))
>>> y = band_planck_radiance(tir, 300.0)
>>> round(float(band_brightness_temperature(tir, y)[0]), 9)
300.0
Source code in src/radtrax/radiometry/brightness.py
def band_brightness_temperature(
    instrument: Instrument,
    y: Float[ArrayLike, " B"],
    *,
    rtol: float = 1e-12,
    atol: float = 1e-10,
    max_steps: int = 32,
    throw: bool = True,
) -> Float[Array, " B"]:
    """Band brightness temperature: the $T_b$ with $\\bar B_b(T_b) = y_b$ [K].

    Solves $\\ln \\bar B_b(T_b) - \\ln y_b = 0$ for every band by
    `optimistix.Newton`, with a diagonal Jacobian (one JVP per step) and a
    diagonal linear solve, from the monochromatic $T_b$ at each band's
    centroid. The residual is taken in log radiance so that the tolerances
    mean the same at 0.4 µm and at 15 µm; it has the same root and the same
    implicit derivatives as $\\bar B_b - y_b$. The unknown is $u = \\ln T_b$,
    so no Newton step can leave $T_b > 0$: in $T$ a broad band's first step
    from the centroid guess can overshoot below 0 K. Gradients come from the
    implicit function theorem (`optimistix.ImplicitAdjoint`), in ``y`` and in
    the instrument's parameters alike.

    A band with $y_b \\le 0$ has no brightness temperature: it is solved on a
    safe value and returned as NaN (double where), so a masked band does not
    poison the gradient of the others.

    Args:
        instrument: The bands, any `Instrument` (linear in radiance).
        y: Band values, ``(B,)``, in the instrument's radiance units.
        rtol: Relative tolerance of the Newton solve in $\\ln T$.
        atol: Absolute tolerance of the Newton solve (in $\\ln T$ and in the
            log residual).
        max_steps: The most Newton steps.
        throw: Raise when the solve fails to converge
            (``equinox.EquinoxRuntimeError`` under ``jit``); otherwise
            return the last iterate.

    Returns:
        $T_b$ [K], ``(B,)``; NaN where $y_b \\le 0$.

    Examples:
        >>> import jax.numpy as jnp
        >>> from radtrax.instrument import GaussianInstrument
        >>> nu = jnp.linspace(700.0, 1300.0, 1201)
        >>> tir = GaussianInstrument(nu, jnp.array([10900.0]), jnp.array([500.0]))
        >>> y = band_planck_radiance(tir, 300.0)
        >>> round(float(band_brightness_temperature(tir, y)[0]), 9)
        300.0
    """
    response = instrument.response_matrix()  # (B, G)
    nu = instrument.nu_cm  # (G,)
    y = jnp.asarray(y, dtype=response.dtype)
    row_sum = jnp.sum(response, axis=1)  # (B,)
    centroid = response @ nu / row_sum  # (B,)
    positive = y > 0
    y_safe = jnp.where(positive, y, row_sum * planck_radiance(centroid, 300.0))
    t0 = brightness_temperature(centroid, y_safe / row_sum)

    def residual(
        u: Float[Array, " B"],
        args: tuple[Float[Array, "B G"], Float[Array, " G"], Float[Array, " B"]],
    ) -> Float[Array, " B"]:
        a, grid, log_y = args
        return jnp.log(_band_planck(a, grid, jnp.exp(u))) - log_y

    solver = optx.Newton(rtol=rtol, atol=atol, linear_solver=lx.Diagonal())
    solution = optx.root_find(
        residual,
        solver,
        jnp.log(t0),
        args=(response, nu, jnp.log(y_safe)),
        max_steps=max_steps,
        throw=throw,
        tags=frozenset({lx.diagonal_tag}),
        adjoint=optx.ImplicitAdjoint(linear_solver=lx.Diagonal()),
    )
    return jnp.where(positive, jnp.exp(solution.value), jnp.nan)