runtraj.sampling.sample_met#

runtraj.sampling.sample_met(particles, met, columns=('mlht', 'dens', 'pres', 'zsfc'), *, z_top=25000.0)[source]#

Return the particles with met columns sampled at each particle’s position.

A transport model that writes only positions can get the columns HYSPLIT writes from the met this way. Each row is sampled at its lon, lat, zagl, and time: bilinear across the met’s grid and linear in height between the internal levels of a HYSPLIT run with the top z_top (arlmet.sample_points()), then linear in time between the two met times around the particle’s, as HYSPLIT does. Each column comes from these ARL variables:

  • mlht is PBLH, the met model’s boundary-layer height, in m above ground.

  • dens is 100 PRES / (R TEMP (1 + 0.61 SPHU)), the density of moist air in kg m⁻³, with R = 287.04 J kg⁻¹ K⁻¹. Met without SPHU gives the density of dry air, up to about 1 % higher, as calc_pbl_height() uses.

  • pres is PRES, the pressure, in hPa. Met without a PRES field, such as GFS on pressure levels or ERA5 on model levels, gives the pressure of its vertical axis instead.

  • zsfc is SHGT, the terrain height, in m above sea level.

pres and dens follow what HYSPLIT reads, to the differences under Notes. mlht is the met’s. HYSPLIT’s own mlht is the met’s PBLH (at least kmix0) only when HYSPLIT runs with kmixd: 0; with HYSPLIT’s default, kmixd: 3, it finds the mixed layer from the profile, as calc_pbl_height() does.

Parameters:
Returns:

A copy of particles with the columns added. A row off the met’s grid is NaN.

Return type:

DataFrame

Raises:
  • ValueError – If a column is not one of the four or is in particles already (drop it first), particles has no time column, a row is outside the files’ times, or z_top is not positive or is below a particle.

  • KeyError – If the met lacks a variable a column needs.

Notes

On two 6-hour HRRR runs from Salt Lake City, one in winter and one in summer, the sampled columns differ from the ones HYSPLIT wrote by:

  • zsfc: a few meters, since HYSPLIT reads the terrain where the particle was before its turbulent step.

  • mlht: a median of 16 to 30 m, against a HYSPLIT run with kmixd: 0 floored at kmix0. HYSPLIT reads the nearest grid point’s PBLH; this function interpolates it.

  • pres: a median of 0.02 hPa, 0.23 to 0.30 hPa at the 95th percentile, and 1.4 to 4.6 hPa at worst.

  • dens: 0.17 to 0.57 % higher, more in moister air.

Examples

>>> meta = runtraj.particles.particles_metadata(
...     sim.particles_path
... )
>>> hysplit = sim.particles
>>> sampled = runtraj.sampling.sample_met(
...     hysplit.drop(columns="pres"),
...     meta.met_files,
...     columns=["pres"],
...     z_top=meta.settings["z_top"],
... )
>>> (sampled["pres"] - hysplit["pres"]).describe()