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

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

The integral

One day of Earth observation

Take one day of a methane-observing satellite and follow the numbers. An imaging spectrometer records radiance in a few hundred channels, and each channel is an integral of the spectrum against the instrument’s spectral response. The retrieval turns the radiance into a column of methane, which is an integral of the mole fraction over pressure. The level-3 product averages the columns onto a map, and the global mean of that map is an integral over the sphere weighted by the cosine of latitude. The ocean model that the same group runs reports the heat content of the upper ocean, an integral of temperature over depth. Finally, the emission rate of a plume comes with an uncertainty, and that uncertainty is an expectation, which is an integral against a posterior density.

So one day of data has at least five integrals in it, over five different domains: wavelength, pressure, the sphere, depth and a parameter space. They look very different, but they are the same object, and integrix treats them with the same few operations. In this chapter we write that object down once, so that the rest of the section can be about how we compute it.

The definition

Let Ω\Omega be a domain (an interval of wavelength, a column of pressure, the sphere, a parameter space) with coordinates s∈Ω⊂RDs\vect{s} \in \Omega \subset \mathbb{R}^{D_s}, and let μ\mu be a measure on it. The integral of a function f:Ω→Rf: \Omega \to \mathbb{R} is

I[f]=∫Ωf(s)dμ(s)I[f] = \int_\Omega f(\vect{s}) \mathrm{d}\mu(\vect{s})

where I[f]∈RI[f] \in \mathbb{R} is a number. When the measure has a density ρμ(s)≥0\rho_\mu(\vect{s}) \ge 0 with respect to the ordinary volume element (length, area, volume), (1.1) is ∫Ωf(s)ρμ(s)ds\int_\Omega f(\vect{s}) \rho_\mu(\vect{s}) \mathrm{d}\vect{s}. The density is where most of the geoscience hides: the cos⁡ϕ\cos \phi of an area on the sphere, the spectral response of a channel, the posterior density of an emission rate.

A function ff can carry extra axes that are not integrated (channels, time steps, ensemble members), so f:Ω→RDff: \Omega \to \mathbb{R}^{D_f} and I[f]∈RDfI[f] \in \mathbb{R}^{D_f} are integrated entry by entry. integrix calls these the batch axes.

Five integrals, one form

The five integrals of the day all fit (1.1). For each one we write the full form, then read off its domain Ω\Omega, its measure dμ\mathrm{d}\mu and the integrand ff that is left inside, and name the integrix function that computes it. Table 1.1 collects the physical symbols.

Table 1.1:The physical symbols of this page, with their shapes and units.

SymbolShape, unitsMeaning
λ\lambdaR>0\mathbb{R}_{>0}, nmwavelength, in the spectral domain S\mathcal{S}
L(λ)L(\lambda), LcL_cR≥0\mathbb{R}_{\ge 0}, radiance unitsthe spectrum and the band radiance of channel cc
Rc(λ)R_c(\lambda)R≥0\mathbb{R}_{\ge 0}the spectral response of channel cc
pp, psp_\text{s}R≥0\mathbb{R}_{\ge 0}, hPapressure and surface pressure
c(p)c(p)R>0\mathbb{R}_{>0}, ppbthe methane dry-air mole fraction
ϕ\phi, ϑ\varthetaradianslatitude and longitude
TT, Θ\ThetaK, °Csurface temperature and ocean potential temperature
zz, HHmheight (negative below the sea surface) and the depth of the layer
ρ0\rho_0, cpc_pkg m⁻³, J kg⁻¹ K⁻¹reference density and heat capacity of seawater
QQ, y\vect{y}kg h⁻¹, RDy\mathbb{R}^{D_y}the emission rate and the observations it is inferred from
ppost(Q∣y)p_\text{post}(Q \mid \vect{y})R≥0\mathbb{R}_{\ge 0}, h kg⁻¹the posterior density of the emission rate, labelled because pp is pressure on this page

Band radiance. An imaging spectrometer never sees the spectrum itself, since each channel sees the spectrum averaged under its own spectral response. We have the full form

Lc=∫SL(λ)Rc(λ)dλ∫SRc(λ)dλL_c = \frac{\int_{\mathcal{S}} L(\lambda) R_c(\lambda) \mathrm{d}\lambda}{\int_{\mathcal{S}} R_c(\lambda) \mathrm{d}\lambda}

where the domain is the spectral window S\mathcal{S}, the integrand is the spectrum L(λ)L(\lambda), and the measure is the normalised response Rc(λ)dλ/∫SRc(λ)dλR_c(\lambda) \mathrm{d}\lambda / \int_{\mathcal{S}} R_c(\lambda) \mathrm{d}\lambda. It is a ratio of two integrals with the same measure, so integrix computes it with weighted_mean, which uses the same weights for both sums. If the two sums used different weights, the ratio would drift for a reason that has nothing to do with the spectrum.

Column average. A retrieval reports methane as a column-averaged dry-air mole fraction, which is what a model column has to be compared with. Assuming dry air and a constant gravity, a pressure interval is proportional to the mass of air in it, and we have the full form

XCH4=1ps∫0psc(p)dp\mathrm{XCH_4} = \frac{1}{p_\text{s}} \int_0^{p_\text{s}} c(p) \mathrm{d}p

where the domain is the column [0,ps][0, p_\text{s}] from the top of the atmosphere to the surface, the integrand is the mole fraction c(p)c(p), and the measure is dp/ps\mathrm{d}p / p_\text{s}, the fraction of the column’s air in each pressure interval. It is a plain integrate over the levels. A real retrieval adds water vapour and an averaging kernel on top, which change the weights but not the form.

Global mean. A level-3 map is averaged to one number per day, and every cell has to count by its area, not by its index. We have the full form

Tˉ=14π∫02π∫−π/2π/2T(ϕ,ϑ)cos⁡ϕdϕdϑ\bar{T} = \frac{1}{4 \pi} \int_0^{2 \pi} \int_{-\pi/2}^{\pi/2} T(\phi, \vartheta) \cos \phi \mathrm{d}\phi \mathrm{d}\vartheta

where the domain is the unit sphere S2\mathbb{S}^2 in latitude ϕ\phi and longitude ϑ\vartheta, the integrand is the surface temperature T(ϕ,ϑ)T(\phi, \vartheta), and the measure is the area element cos⁡ϕdϕdϑ\cos \phi \mathrm{d}\phi \mathrm{d}\vartheta divided by the sphere’s area 4π4 \pi. The measure is a product of one factor per axis, so integrix computes it with integrate and a tensor rule, one rule in latitude and one in longitude.

Ocean heat content. The heat stored in the upper ocean is the quantity behind most statements about ocean warming, and it comes from a temperature profile. We have the full form

OHC=ρ0cp∫−H0Θ(z)dz\mathrm{OHC} = \rho_0 c_p \int_{-H}^{0} \Theta(z) \mathrm{d}z

where the domain is the layer [−H,0][-H, 0] from depth HH to the sea surface, the integrand is the potential temperature Θ(z)\Theta(z), and the measure is ρ0cpdz\rho_0 c_p \mathrm{d}z, the heat capacity of each slab of water. The total is an integrate over depth, and the heat content above every depth, a profile instead of a number, is a cumulative scan.

Expected emission rate. An inversion does not return one emission rate for a plume but a posterior over rates, and the number we report is its mean, with an uncertainty from the same posterior. We have the full form

E[Q∣y]=∫0∞Qppost(Q∣y)dQ\mathbb{E}[Q \mid \vect{y}] = \int_0^\infty Q p_\text{post}(Q \mid \vect{y}) \mathrm{d}Q

where the domain is the positive rates R>0\mathbb{R}_{>0}, the integrand is the rate QQ itself, and the measure is the posterior ppost(Q∣y)dQp_\text{post}(Q \mid \vect{y}) \mathrm{d}Q given the observations y\vect{y}. We can usually sample the posterior but not write it down, so integrix computes this with monte_carlo on posterior samples, or with qmc when the rate is a transform of uniform variables.

Three properties we lean on

The integral is a linear functional, and we lean on three of its properties over and over again.

  1. Linearity. I[af+bg]=aI[f]+bI[g]I[a f + b g] = a I[f] + b I[g] for scalars a,ba, b. Every rule in this section is linear in the samples too, which is what makes its gradient a vector of weights (chapter 9).

  2. Positivity. If f≥0f \ge 0 then I[f]≥0I[f] \ge 0. A rule with positive weights keeps this, and a rule with negative weights can return a negative column of methane from a positive profile (chapter 2).

  3. Additivity over the domain. If Ω=Ω1∪Ω2\Omega = \Omega_1 \cup \Omega_2 with no overlap, then IΩ[f]=IΩ1[f]+IΩ2[f]I_\Omega[f] = I_{\Omega_1}[f] + I_{\Omega_2}[f]. This is the property behind composite rules, scans and every finite-volume budget, and it is the start of the global and local thread of chapter 3.

∫Ωf(s)dμ(s)=∑r=1Ntile∫Ω(r)f(s)dμ(s)\int_\Omega f(\vect{s}) \mathrm{d}\mu(\vect{s}) = \sum_{r=1}^{N_\text{tile}} \int_{\Omega^{(r)}} f(\vect{s}) \mathrm{d}\mu(\vect{s})

Here Ω(r)\Omega^{(r)}, r=1,…,Ntiler = 1, \ldots, N_\text{tile}, are tiles that cover Ω\Omega without overlap: grid cells, pressure layers or time steps.

In code

The column and the band radiance of the day, on toy data. A linear methane profile on 21 pressure levels has the exact column average 1750 ppb, and the trapezoid rule (chapter 2) gets it exactly, because the rule is exact for straight lines.

import jax.numpy as jnp
from integrix import rule
from jaxtyping import Array, Float

# Shapes: N_P = 21 pressure levels; N_S = 401 wavelengths; N nodes of a rule


# user
def trapezoid_weights(nodes: Float[Array, "node"]) -> Float[Array, "node"]:
    """wₙ = (sₙ₊₁ − sₙ₋₁)/2 inside, half a spacing at each end."""
    # hₙ = sₙ₊₁ − sₙ
    widths = jnp.diff(nodes)                                 # (N,) → (N - 1,)
    # padding for the two ends, where one neighbour is missing
    zero = jnp.zeros(1, dtype=nodes.dtype)                   # → (1,)
    # rₙ = hₙ, with r_N = 0
    right = jnp.concatenate([widths, zero])                  # (N - 1,) → (N,)
    # lₙ = hₙ₋₁, with l₁ = 0
    left = jnp.concatenate([zero, widths])                   # (N - 1,) → (N,)
    # wₙ = (rₙ + lₙ)/2
    return 0.5 * (right + left)


# pₙ from the top of the atmosphere to the surface, hPa
pressure = jnp.linspace(0.0, 1013.0, 21)                     # → (N_P,)
# 300 pₙ
slope_term = 300.0 * pressure                                # (N_P,) → (N_P,)
# c(pₙ) = 1600 + 300 pₙ/p_s, ppb
methane = 1600.0 + slope_term / 1013.0                       # (N_P,) → (N_P,)
# wₙ = (pₙ₊₁ − pₙ₋₁)/2
pressure_weights = trapezoid_weights(pressure)               # (N_P,) → (N_P,)
# today (integrix)
# I = ∑ₙ wₙ c(pₙ)
column_integral = rule.integrate(pressure_weights, methane)  # → ()
# XCH₄ = I / p_s
column_average = column_integral.value / pressure[-1]        # → ()
print(f"XCH4 = {float(column_average):.1f} ppb")
XCH4 = 1750.0 ppb

The band radiance is a weighted mean: a toy spectrum with one absorption line at 2300 nm, seen by a channel with a Gaussian response 5 nm wide.

# Shapes: N_S = 401 wavelengths

# λₙ, nm
wavelength = jnp.linspace(2280.0, 2320.0, 401)    # → (N_S,)
# δₙ = λₙ − 2300
offset = wavelength - 2300.0                      # (N_S,) → (N_S,)
# gₙ = exp(−δₙ²/2)
line_shape = jnp.exp(-0.5 * offset**2)            # (N_S,) → (N_S,)
# L(λₙ) = 1 − 0.4 gₙ
spectrum = 1.0 - 0.4 * line_shape                 # (N_S,) → (N_S,)
# uₙ = δₙ/5
scaled = offset / 5.0                             # (N_S,) → (N_S,)
# R_c(λₙ) = exp(−uₙ²/2)
response = jnp.exp(-0.5 * scaled**2)              # (N_S,) → (N_S,)
# wₙ = (λₙ₊₁ − λₙ₋₁)/2
spectral_weights = trapezoid_weights(wavelength)  # (N_S,) → (N_S,)
# today (integrix)
# L_c = ∑ₙ wₙ Rₙ Lₙ / ∑ₙ wₙ Rₙ
band_radiance = rule.weighted_mean(               # → ()
    spectral_weights, spectrum, weight=response
)
print(f"L_c = {float(band_radiance):.3f}")
L_c = 0.922

The line takes about 8 % of the light in the channel, since its width (1 nm) is a fifth of the response’s. Everything in the rest of the section is about the line rule.integrate(weights, samples): where the weights come from, how good they are, and what happens when we cannot write them down in advance.