stilt.sampling.sample_met#

stilt.sampling.sample_met(particles, files, columns=('mlht', 'dens', 'pres', 'zsfc'))[source]#

Return the particles with met columns sampled from ARL files 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 its levels (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⁻¹.

  • pres is PRES, the pressure, in hPa.

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

The values are the met’s, not HYSPLIT’s. HYSPLIT’s mlht is the met’s PBLH only with kmixd: 0, and then it is at least kmix0; the default, kmixd: 3, finds the mixed layer from the profile. HYSPLIT also finds the heights of the met’s levels its own way, so its pres and dens differ from these; Meteorology says by how much.

Parameters:
Returns:

A copy of particles with the columns added. A row off the met’s grid, below its lowest level, or above its top 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, or a row is outside the files’ times.

  • KeyError – If the files lack a variable a column needs.

Examples

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