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.

Puff — state estimation

Gaussian puff — state estimation of a time-varying emission rate

When the source strength changes over time — a turned-valve event, a burst, or a slowly-modulating leak — fitting a constant Q to observations is model-mis-specified. The posterior mean becomes the time-average of the true Q series, and per-time residuals inflate the inferred observation noise. The puff model is natively time-indexed (each puff has its own release time), so we can relax the constant-Q assumption by giving each puff its own Q_i with a Gaussian random-walk prior on ln Q_i.

This notebook: (1) simulates observations from a step-change in Q, (2) fits both a constant-Q baseline and the random-walk model, (3) compares the two posteriors, showing that the random-walk recovers the step.

1. Synthetic step-change in Q

Q switches from 0.05 kg/s (low) to 0.20 kg/s (high) at t = 90 s. Winds are constant 5 m/s from the west; stability class C.

Plot the ground-truth observation time series — the step at t=90 s is visible downstream with a transport delay (larger for further receptors).

<Figure size 900x600 with 2 Axes>

2. Constant-Q baseline (expected to be biased)

Constant-Q posterior: mean = 0.1037, std = 0.0001
Time-average of truth: 0.1250

The constant-Q posterior sits around the time-average of the truth (≈0.12 kg/s) — it averages over the step and is misleading if you read off “Q ≈ 0.12” and report a leak rate.

3. Random-walk state-space model

Each puff i has its own emission rate QiQ_i with ln⁡Qi=ln⁡Qi−1+εi\ln Q_i = \ln Q_{i-1} + \varepsilon_i, εi∼N(0,σrw)\varepsilon_i \sim \mathcal N(0, \sigma_\text{rw}). We pick σrw=0.15\sigma_\text{rw} = 0.15 — a 15% per-puff log-scale innovation, wide enough to accommodate the step but tight enough that unconstrained noise doesn’t dominate.

Random-walk posterior shape: (600, 180)
Posterior mean Q(t=80s):  0.0430  (truth = 0.0500)
Posterior mean Q(t=120s): 0.2310  (truth = 0.2000)

4. Compare posteriors

<Figure size 1000x450 with 1 Axes>

The random-walk posterior tracks the step almost exactly: before t=90 s it sits near 0.05 kg/s, after it jumps to 0.20. The 90% credible band is wide near the transition (reflecting the uncertainty about exactly when the step occurred) and tighter in the stationary phases where more observations constrain Q.

Constant-Q inference cannot do this at all — the only information it can extract from data generated by a non-constant source is the time-average. For fielded leak-detection work, the choice between constant-Q and state-space inference is the choice between “how much did the source emit on average” and “when did the emission change”.

5. Posterior-predictive fit

<Figure size 900x400 with 1 Axes>

The random-walk model’s predictive intervals cover the observations cleanly, especially around the step — the constant-Q model cannot do this without inflating the noise variance to absorb the systematic bias.

Caveats

  • The random-walk prior has a scale parameter σrw\sigma_\text{rw} that must be chosen. Too small → posterior is stuck near the prior mean and can’t track the step; too large → noisy posterior that overfits measurement error. A hierarchical prior (sampling σrw\sigma_\text{rw} itself) is the natural next step.

  • We assumed the wind is exactly known. In practice the wind itself is a noisy measurement — propagating wind uncertainty through the inference requires putting a prior on WindSchedule and marginalising.

  • The forward model re-does the full diffrax wind-integral solve at every NUTS evaluation. For long windows with many puffs, caching the schedule-level cumulative integrals at fixed points (release + observation times) is a lossless optimisation worth implementing before scaling up.