stilt.transport_error#

stilt.transport_error(particles, error_particles, flux, *, transforms=(), release=None, directory=None, hnf_plume=True, footprint_depth=0.5, levels=20, length_scale=356.0, percentile=1.0, background=None)[source]#

Return the transport-error variance of a modeled enhancement (Lin and Gerbig, 2005).

Parameters:
  • particles (DataFrame) – Unperturbed particle table of a release (sim.particles).

  • error_particles (DataFrame | Sequence[DataFrame]) – Particle table of a wind-error variant of the same release, or one table per realization for a variant with realizations: N (see Examples). A table is one simulation’s particles: one release and one realization.

  • flux (DataArray) – Surface flux field (see particles.stilt.enhancement).

  • transforms (Sequence[Any]) – The footprint’s particle transforms (sim.variant.stages["footprint"].transforms), applied to both tables so the error is weighted like the footprint.

  • release (runtraj.releases.Release | None) – The release (sim.release), for the near-field correction and the transforms. Needed when hnf_plume is set.

  • directory (str | Path | None) – Where a kernel table’s relative path starts (project.directory).

  • hnf_plume (bool) – Apply the near-field correction to both tables first, as stilt.calc_footprint() does (sim.variant.stages["footprint"].hnf_plume), so the error is of the same enhancement the footprint gives.

  • footprint_depth (float) – The depth foot was made with, which the near-field correction reads: the run’s veght for HYSPLIT’s own foot, the footprint’s footprint_depth for a foot the footprint stage computes. sim.variant.stages["footprint"].footprint_depth is the right one either way.

  • levels (int | Sequence[float]) – Release-height levels to compute statistics on: a number of equal-width bins between the lowest and highest release height, or bin edges in meters. When the particles have no more distinct release heights than levels (a multipoint release), each height is a level. A point release is one level.

  • length_scale (float | None) – Vertical e-folding length of the error correlation between levels, in meters (X-STILT’s value). None treats the levels as independent. It has no effect for a point release.

  • percentile (float) – In each level, drop particles above this quantile of the enhancement before taking the variance. 1.0 keeps every particle, as Lin and Gerbig do. X-STILT uses 0.99 to limit the few particles that cross a point source. Means always use every particle.

  • background (DataArray | None) – Background field sampled at each particle’s endpoint (see background()). Wind errors move the endpoints as well as the surface contact, so with a field the statistics are of the modeled mole fraction per particle, as X-STILT computes them.

Return type:

TransportError

Notes

Per level l with n_l of N particles, dvar_l is the change in the variance of the per-particle enhancement under the perturbation. Two particles’ transport errors correlate as exp(-|h_p - h_q| / L), with h their release heights, and the column variance is Σ_l factor_l dvar_l. factor_l is the sum of that correlation over the particles of level l and every particle, divided by N², which is w_l Σ_m w_m R_lm with w_l = n_l / N and R_lm the mean correlation between the particles of two levels. A pair of levels therefore counts with the mean of their two dvar. For one level the variance is dvar itself, and with length_scale=None it is Σ_l w_l² dvar_l. The transforms are applied to the particles first, so the level statistics are already column-weighted and the level weights are particle counts.

The sum is linear in dvar, so the sampling noise in each level’s dvar averages out over many releases. Where the error changes sharply with height within a correlation length, the mean of two levels’ dvar is above the product of their standard deviations, and the column variance is high by up to about 20 %.

noise is the standard error of variance. A variance of n values with fourth central moment m4 has the sampling variance (m4 - var²) / n. Each level’s noise adds that of the unperturbed run and of the perturbed run, and the column’s is sqrt(Σ_l (factor_l noise_l)²).

With several error realizations, each level’s mean_err and var_err are averaged over them before dvar is formed, so the perturbed side’s sampling variance falls as 1/N. The unperturbed side is the same particles in every realization, so its part does not fall. More realizations therefore tighten the estimate by about sqrt(2) at most and cannot resolve a case that one realization leaves far from resolved.

The signal is the extra spread the perturbation adds. It is small when the wind error decorrelates quickly (HYSPLIT decorrelates it with the distance a particle travels as well as with time), and when turbulence already spreads the particles widely, as on a convective afternoon. Compare a single value with noise. Over many releases, combine the signed variance values with a mean instead of clipping each at zero.

Examples

For the variant hrrr-err with realizations: 4, select one release’s simulations and group their particles by realization. Grouping by variant gives one table, which counts as one realization and gives a wrong variance. Without the release, each realization’s table holds every release’s particles.

>>> from stilt import transport_error
>>> sim = project.simulation(rid, "hrrr")
>>> sims = project.simulations
>>> ensemble = sims[
...     (sims.variant == "hrrr-err") & (sims.release == rid)
... ]
>>> by_realization = project.particles(ensemble).groupby(
...     "realization"
... )
>>> error_particles = [rows for _, rows in by_realization]
>>> result = transport_error(
...     sim.particles, error_particles, flux, release=sim.release
... )
>>> result.realizations
4

sim.transport_error(realizations, flux) builds this list from the realizations’ simulations. It also passes transforms, directory, and the variant’s hnf_plume and footprint_depth, which this call leaves at their defaults.