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 withrealizations: N(see Examples). A table is one simulation’s particles: one release and one realization.flux (
DataArray) – Surface flux field (seeparticles.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, asstilt.calc_footprint()does (sim.variant.stages["footprint"].hnf_plume), so the error is of the same enhancement the footprint gives.footprint_depth (
float) – The depthfootwas made with, which the near-field correction reads: the run’sveghtfor HYSPLIT’s ownfoot, the footprint’sfootprint_depthfor afootthe footprint stage computes.sim.variant.stages["footprint"].footprint_depthis 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 thanlevels(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).Nonetreats 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 (seebackground()). 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
lwithn_lofNparticles,dvar_lis the change in the variance of the per-particle enhancement under the perturbation. Two particles’ transport errors correlate asexp(-|h_p - h_q| / L), withhtheir release heights, and the column variance isΣ_l factor_l dvar_l.factor_lis the sum of that correlation over the particles of levelland every particle, divided byN², which isw_l Σ_m w_m R_lmwithw_l = n_l / NandR_lmthe mean correlation between the particles of two levels. A pair of levels therefore counts with the mean of their twodvar. For one level the variance isdvaritself, and withlength_scale=Noneit 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’sdvaraverages out over many releases. Where the error changes sharply with height within a correlation length, the mean of two levels’dvaris above the product of their standard deviations, and the column variance is high by up to about 20 %.noiseis the standard error ofvariance. A variance ofnvalues with fourth central momentm4has the sampling variance(m4 - var²) / n. Each level’snoiseadds that of the unperturbed run and of the perturbed run, and the column’s issqrt(Σ_l (factor_l noise_l)²).With several error realizations, each level’s
mean_errandvar_errare averaged over them beforedvaris formed, so the perturbed side’s sampling variance falls as1/N. The unperturbed side is the same particles in every realization, so its part does not fall. More realizations therefore tighten the estimate by aboutsqrt(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 signedvariancevalues with a mean instead of clipping each at zero.Examples
For the variant
hrrr-errwithrealizations: 4, select one release’s simulations and group their particles by realization. Grouping byvariantgives 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 passestransforms,directory, and the variant’shnf_plumeandfootprint_depth, which this call leaves at their defaults.