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, andtime: 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:mlhtisPBLH, the met model’s boundary-layer height, in m above ground.densis 100PRES/ (RTEMP(1 + 0.61SPHU)), the density of moist air in kg m⁻³, with R = 287.04 J kg⁻¹ K⁻¹. Met withoutSPHUgives the density of dry air, up to about 1 % higher, ascalc_pbl_height()uses.presisPRES, the pressure, in hPa. Met without aPRESfield, such as GFS on pressure levels or ERA5 on model levels, gives the pressure of its vertical axis instead.zsfcisSHGT, the terrain height, in m above sea level.
presanddensfollow what HYSPLIT reads, to the differences under Notes.mlhtis the met’s. HYSPLIT’s ownmlhtis the met’sPBLH(at leastkmix0) only when HYSPLIT runs withkmixd: 0; with HYSPLIT’s default,kmixd: 3, it finds the mixed layer from the profile, ascalc_pbl_height()does.- Parameters:
particles (
DataFrame) – A particle table withlon,lat,zagl, andtime(UTC; a time with a time zone is converted to UTC).sim.particleshastime. For a table a transport model returned, add it: the release time plusageminutes.met (
str|PathLike[str] |Iterable[str|PathLike[str]] |Dataset) – ARL met files that cover the particles’ times, such as the files the run read (met_filesofruntraj.models.ModelRunor ofruntraj.particles.particles_metadata()), or met in another format as one Dataset inarlmet.open_dataset()’s layout (runtraj.models.open_met(), or an arlmet converter’s output).z_top (
float|None) – The top of the run’s domain in meters (z_topofruntraj.models.hysplit.HysplitConfig), since HYSPLIT’s internal levels depend on it. A stored run records it:particles_metadata(path).settings["z_top"].Nonereads the met’s own levels, for a transport model that is not HYSPLIT; a row below their lowest or above their top is then NaN.
- Returns:
A copy of particles with the columns added. A row off the met’s grid is NaN.
- Return type:
- Raises:
ValueError – If a column is not one of the four or is in particles already (drop it first), particles has no
timecolumn, 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 withkmixd: 0floored atkmix0. HYSPLIT reads the nearest grid point’sPBLH; 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()