A matched filter in milliseconds: how the modeling cycle finds where it is wrong
GeoStack · background · the modeling cycle · example 1 of 3 · L1B → L2
Abstract¶
The first of three worked examples of the modeling cycle. The job is the one every methane pipeline starts with: turn a cube of radiances into a map of how much extra gas each pixel holds. This page writes the job as a ladder of models. The forward model says what the sensor sees. Optimal estimation inverts it pixel by pixel, slowly, and serves as the referee. The matched filter replaces the forward model by its tangent and solves in closed form. Comparing the two exposes three systematic misfits, and each is derived here from the assumption that causes it, together with the change to the model that removes it.
The operators¶
1 · Forward model
radtrax computes what the sensor would see: the optical depth of each layer, the radiance that reaches the sensor through all of them, and the value in each band. Nothing is fitted.
| Role | Symbol | Name | Shape | Unit | Note |
|---|---|---|---|---|---|
| Input | methane enhancement | () | ppm·m | added below the plume height | |
| Input | surface albedo | () | — | ||
| External input | layer pressure | (layer,) | Pa | the background atmosphere | |
| layer temperature | (layer,) | K | |||
| mixing ratio | (layer,) | mol mol⁻¹ | |||
| air column of layer | (layer,) | mol m⁻² | |||
| Constant | absorption cross-section | (wavelength,) | cm² molecule⁻¹ | ||
| band response | (band, wavelength) | — | |||
| air mass | () | — | |||
| , | cosines of the solar and viewing zenith angles | () | — | ||
| solar irradiance | (wavelength,) | µW cm⁻² nm⁻¹ | |||
| radiance at the top of the atmosphere, an intermediate | (wavelength,) | [L] | eq. 2 | ||
| Parameter | none | — | nothing is fitted | ||
| Output | band radiances | (band,) | [L] | eq. 3 |
2 · Optimal estimation
Invert the forward model pixel by pixel, with Gauss–Newton on the full model. It is slow, and it is the referee that the fast method is checked against; the second equation is its posterior covariance.
| Role | Symbol | Name | Shape | Unit | Note |
|---|---|---|---|---|---|
| Input | pixel spectrum | (band,) | [L] | one pixel | |
| Constant | forward model | — | |||
| Jacobian of | (band, 2) | [L] per state unit | |||
| noise covariance | — | ||||
| Parameter | prior mean | (2,) | prior on | ||
| prior covariance | (2, 2) | ||||
| Output | estimate | (2,) | ppm·m, — | eq. 1 | |
| posterior covariance | (2, 2) | eq. 2 |
3 · Matched filter
Replace the model by its tangent, which is fast; this is the method under test. The target signature is the background spectrum times the unit absorption, and each pixel’s enhancement is its whitened projection onto that target.
| Role | Symbol | Name | Shape | Unit | Note |
|---|---|---|---|---|---|
| Input | pixel spectra | (row, col, band) | [L] | the whole scene, rows are the | |
| Constant | unit absorption spectrum | (band,) | (ppm·m)⁻¹ | from the forward model | |
| Estimated | background mean spectrum | (band,) | [L] | from the scene itself | |
| background covariance | (band, band) | [L]² | from the scene itself | ||
| Output | enhancement map | (row, col) | ppm·m | eq. 2 |
The running example¶
Notation¶
indexes the pixels of a scene, the bands, the atmospheric layers and the wavelengths of the fine spectral grid. [L] is the radiance unit. The counts are the sizes of the index sets, and .
| Symbol | Role | Shape | Unit |
|---|---|---|---|
| observation · radiance of pixel | (band,) | [L] | |
| state · column enhancement of pixel | () | ppm·m | |
| state · surface albedo, a nuisance | () | — | |
| state · | (2,) | ppm·m, — | |
| forward model, state to bands | [L] | ||
| const · unit absorption, at | (band,) | (ppm·m)⁻¹ | |
| est · background mean and covariance | , | [L], [L]² | |
| est · target signature, | (band,) | [L] (ppm·m)⁻¹ | |
| out · the filter’s score | () | ppm·m | |
| est · sensitivity, score per unit of true enhancement | () | — | |
| const · noise covariance of one spectrum | , diagonal | [L]² | |
| out · the objective of optimal estimation | () | — | |
| const · radiance of pixel without the plume | (band,) | [L] |
Model 1 · A model you can run forwards¶
Sunlight goes down through the atmosphere, reflects off the ground and comes back up to the sensor. On the way, each layer absorbs a little at the wavelengths where methane has lines; more methane means deeper lines. With no scattering, the radiance at the top of the atmosphere is Beer–Lambert along the two-way path:
where and are the solar and viewing zenith angles, the two-way air mass, the solar irradiance, the absorption cross-section, the mixing ratio and the air column of layer . The instrument averages the fine spectrum into bands, , with the band response .
A plume adds a column near the surface. Because the exponent is linear in the column, the radiance responds multiplicatively:
The second equality is exact for monochromatic bands and a good approximation for real ones; is negative where methane absorbs. In radtrax, is one automatic-differentiation call through the forward model, so it carries the instrument’s band responses and the scene’s geometry.
import radtrax
import radtrax.retrieval.matched_filter as mf
# Shapes: B = 285 bands; G fine wavelengths; N_layer layers
# Units: [L] = µW cm⁻² sr⁻¹ nm⁻¹; [α] = ppm·m
# today (radtrax)
# y = I(S(O(x))): opacity, Beer–Lambert solver, band instrument
model = radtrax.ForwardModel(opacity, radtrax.solvers.BeerLambert(), instrument)
# today (radtrax)
# k = ∂ ln y / ∂α at α = 0
unit_absorption = radtrax.unit_absorption_target( # → (B,) [α]⁻¹
model, atmosphere, surface, geometry
)Model 2 · The referee: optimal estimation¶
The slow method inverts eq. (8) for each pixel. It is written once, probabilistically, before any approximation.
Under Assumption 1 the objective is a weighted least-squares problem. Gauss–Newton linearises at the current iterate , where counts the inner solver iterations, with Jacobian , and solves the quadratic exactly:
At convergence the curvature gives the Laplace posterior covariance of card 2, and the averaging kernel says how much of each retrieved number came from the data rather than the prior: its trace is the degrees of freedom for signal.
import einx
import jax
import jax.numpy as jnp
import lineax as lx
import optimistix as optx
# Shapes: B bands; D = 2 states (α, ρ)
# user
# r(x) = Σ_ε^(-1/2) (y − h(x))
def whitened_residual(theta, spectrum):
predicted = band_radiance(model, atmosphere, geometry, theta[0], theta[1]) # (B,)
return (spectrum - predicted) / noise_std # (B,)
# today (optimistix)
# x̂ = argmin ½ ‖r(x)‖²
solution = optx.least_squares(
whitened_residual, optx.GaussNewton(rtol=1e-8, atol=1e-10), first_guess, args=spectrum
)
# J_r = ∂r/∂x at x̂
jacobian = jax.jacfwd(whitened_residual)(solution.value, spectrum) # (B, D)
# Σ_x|y = (J_rᵀ J_r)⁻¹
precision = einx.dot("b i, b j -> i j", jacobian, jacobian) # (D, D)
posterior_cov = lx.linear_solve(lx.MatrixLinearOperator(precision), jnp.eye(2)).valueThe packaged version, with priors, quality flags and the slab-model variant, is radtrax’s retrieval.var3d; the per-pixel optimal estimation with flags is radtrax#110.
Model 3 · The fast method: the matched filter¶
The matched filter makes three assumptions and gets a formula.
Under A1 to A3 the likelihood of pixel is Gaussian in , and maximising it is a weighted projection:
with variance . The direction , is computed once per scene and applied to every pixel, which is why the filter is fast: it is already amortized. It is also the flat-prior limit of the dual form of 3D-Var with the linear observation operator , which is how the radtrax theory notes connect it to model 2.
import radtrax.retrieval.matched_filter as mf
# Shapes: row × col pixels; B bands
# Units: [L] = µW cm⁻² sr⁻¹ nm⁻¹; [α] = ppm·m
# today (radtrax)
# μ_y = mean_n y_n
mean = mf.estimate_mean(cube) # (row, col, band) → (band,)
# today (radtrax)
# Σ_y: Ledoit–Wolf shrinkage of the sample covariance
covariance = mf.estimate_cov_shrunk(cube, mean) # (B, B) PSD operator
# t = μ_y ⊙ k
target = mean * unit_absorption # (B,) [L][α]⁻¹
# today (radtrax)
# α̂_n = tᵀ Σ_y⁻¹ (y_n − μ_y) / (tᵀ Σ_y⁻¹ t)
score = mf.apply_image(cube, mean, covariance, target) # (row, col) [α]
# today (radtrax)
# σ_α̂ = (tᵀ Σ_y⁻¹ t)^(−1/2)
score_std = mf.score_std(covariance, target) # () [α]Compare: the filter against the referee¶
Run both on the same pixels and regress the filter’s enhancement on the referee’s. Agreement is a slope of 1 everywhere and an intercept of 0. Noise scatters the points about that line. A misfit with a pattern, a slope that depends on where you look, is systematic, and the modeling cycle says what to do with it: do not tune the filter, find the assumption that broke and change the model.
The outer loop on retrieval: each misfit names an assumption
Model 3 · Matched filterA1 linear · A2 one background · A3 Gaussian
offset off the plumegain on it
compare: an offset where there is no plumethe plume is inside its own background (A2)
Model 3a · Plume masked outbackground from plume-free pixels
offset 0gain
compare: the slope follows the surface brightnessone target cannot fit every surface (A2)
Model 3b · Divided by the sensitivityeach pixel’s own response
gain 1 on every surfacestrong pixels read low
compare: strong pixels read lowabsorption is not linear in the gas (A1)
Model 3c · With saturationsolve by fixed point
slope 1 against the refereenoise unchanged
The outer loop on retrieval. Each rung is a model; each arrow is the systematic misfit that comparison with the referee exposed, and the assumption it traces to.
Three patterns appear, and each can be derived before it is seen.
Misfit 1 · The plume is inside its own background (A2)¶
The background is estimated from every pixel, plume included. If a fraction of the pixels hold the plume with mean enhancement , the estimated mean is pulled towards the plume:
Inserting this into eq. (13) subtracts the same amount from every score:
The covariance is contaminated too, by a rank-one term along the target: with . By the Sherman–Morrison identity, since , so the factor cancels between numerator and denominator of eq. (13). The score keeps its mean; its reported noise grows by , and every detection looks less significant than it is.
Repair. Estimate the background from plume-free pixels. That needs the plume’s location, which needs the filter, so iterate: filter, mask what stands out (smoothed, at a robust threshold, dilated), re-estimate, repeat.
# user
# mask⁽ⁱ⁺¹⁾ = dilate(smooth(α̂⁽ⁱ⁾) > median + thr · 1.4826 MAD)
plume_mask = jnp.zeros((rows, cols), bool) # (row, col)
for _ in range(iterations):
# today (radtrax)
mean = mf.estimate_mean(cube[~plume_mask][:, None, :]) # (B,)
# today (radtrax)
covariance = mf.estimate_cov_shrunk(cube[~plume_mask][:, None, :], mean)
# today (radtrax)
score = mf.apply_image(cube, mean, covariance, mean * unit_absorption) # (row, col)
plume_mask = robust_mask(score) # userMisfit 2 · One target cannot fit every surface (A2 again)¶
Methane removes a fixed fraction of the light, so it removes more radiance from a bright pixel than from a dark one. Write the plume-free radiance of pixel as and keep A1. Then , and eq. (13) gives
For a grey surface, and the sensitivity is simply : the filter over-reads bright ground and under-reads dark ground in proportion to the albedo. The comparison shows this as a slope that changes with the surface.
Repair. Divide by the sensitivity. radtrax computes from the observed spectrum, which needs no albedo map.
# today (radtrax)
# A_n = tᵀ Σ_y⁻¹ (y_n ⊙ k) / (tᵀ Σ_y⁻¹ t)
gain = mf.score_sensitivity(cube, covariance, target, unit_absorption) # (row, col)
# α̂_{n,corr} = α̂_n / A_n
enhancement = score / gain # (row, col) [α]Dividing by does not cost precision when the noise is proportional to the signal: a dark pixel’s score is smaller and quieter by the same factor, so its signal-to-noise ratio is unchanged.
Misfit 3 · Absorption saturates (A1)¶
The second unit of methane absorbs slightly less than the first, because the first already removed some of the light at the line centres. Keep the exact response of eq. (9) instead of its tangent. The sensitivity then depends on the enhancement itself:
where the second form keeps the second-order term of with a band-weighted mean. Since , the gain falls as the plume strengthens: strong pixels read low, and the plume’s core and its mass are underestimated.
| Enhancement (ppm·m) | , exact | first order, | |
|---|---|---|---|
| 750 | −0.015 | 0.9925 | 0.9925 |
| 1 500 | −0.030 | 0.9851 | 0.9850 |
| 3 000 | −0.060 | 0.9706 | 0.9700 |
| 6 000 | −0.120 | 0.9423 | 0.9400 |
Repair. Since now depends on the answer, solve for by fixed-point iteration. It converges in a few steps because changes slowly with .
# user
# α⁰ = α̂ / A(0)
enhancement = score / mf.score_sensitivity(cube, covariance, target, unit_absorption)
for _ in range(4):
# today (radtrax)
# α^{j+1} = α̂ / A(α^j)
gain = mf.score_sensitivity(
cube, covariance, target, unit_absorption, enhancement=jnp.clip(enhancement, 0)
) # (row, col)
enhancement = score / gain # (row, col) [α]Worked numbers¶
| Model | What it assumes | Bias it leaves | Cost per scene |
|---|---|---|---|
| 1 · Forward model | Beer–Lambert, no scattering | — | one evaluation per state |
| 2 · Optimal estimation | Gaussian noise and prior | none beyond the model’s | a few full-model iterations per pixel |
| 3 · Matched filter | A1, A2, A3 | offset ; gain ; saturation | one solve, one dot product per pixel |
| 3a · plume masked | A1, A3, plume-free background | gain and saturation | a few filter passes |
| 3b · with sensitivity | A1, A3 | saturation | one more dot product per pixel |
| 3c · with saturation | A3 | none of the three | three or four more passes |
The 439 kg is what example 2 starts from. If the saturation correction were skipped, the core pixels would read 1 to 6 % low and the mass about 1.5 % low; if the gain were skipped, the mass would be off by the plume-weighted mean of , which can be tens of percent over mixed ground.
The six steps, for this problem¶
The modeling cycle found and fixed the errors. The six steps explain why there was a fast method to fix in the first place.
| Step | In this example | Status |
|---|---|---|
| 1 · Simple model | radtrax.ForwardModel: table opacity, Beer–Lambert, band instrument | today |
| 2 · Model-based inference | Optimal estimation per pixel; retrieval.var3d for fields | today* · radtrax#110 |
| 3 · Emulator | The tangent-linear model , with by autodiff; a learned emulator is radtrax#259 | today · radtrax#259 |
| 4 · Emulator-based inference | The matched filter: the closed-form inversion of the tangent model | today |
| 5 · Amortized inference | Already amortized for the linear model: one direction per scene | — |
| 6 · Improve | This page’s three repairs (score_sensitivity); the EMIT gate against the operational product, radtrax#117 | today · radtrax#117 |
What example 2 receives¶
| Handed on | Value | Used in example 2 as |
|---|---|---|
| Enhancement map, saturation-corrected | (row, col) in ppm·m | the observation of the plume fit |
| Its standard deviation | , per pixel | the observation error |
| The plume’s mass | 439 kg | the integrated mass enhancement |
Sources and status
The matched filter and its sensitivity follow radtrax’s docs/theory/matched_filter.md, after Thompson et al. (2015); optimal estimation follows Rodgers (2000). The six-step mapping follows plumax’s docs/design/04_rtm_stack.md. Lines marked today call names that exist in radtrax at f1cdea1, newer than the submodule pin; today* marks a name that exists with the arguments sketched; user marks what the sketch defines itself. The running example’s numbers are the explainer kit’s; the unit absorption and the score’s noise are illustrative, and the saturation table is computed from them.