arlmet.converters.from_flex_extract#

arlmet.converters.from_flex_extract(datasets)[source]#

Convert the ERA5 files flex_extract writes for FLEXPART to a Dataset for arlmet.write_dataset().

flex_extract retrieves ERA5 for FLEXPART and writes one GRIB file per hour (EAyymmddhh), with the model levels, the surface fields and the precipitation on ERA5’s own lat/lon grid. This takes the Datasets cfgrib.open_datasets() returns for one or several of those files and gives an ARL hybrid Dataset (vertical flag 4) on model levels, as from_era5() writes ERA5 on model levels. Each file’s valid time is one time step.

The files are not ERA5 as the Climate Data Store serves it, so this is not from_era5():

  • flex_extract has turned ERA5’s hourly totals into rates at the valid time (W m-2, N m-2, mm h-1), but keeps their GRIB names, units and stepType=accum; they are read as the rates they are.

  • Some fields are on longitudes from 0 to 360 and others from -180 to 180, on the same grid; all are put on one.

  • The files hold all 137 model levels, more than an ARL file can: the lowest 99 are kept (model levels 137 to 39, up to about 25 hPa), as a record’s header numbers its level in two characters. Fewer are kept when the files hold fewer, and none above about model level 24, whose pressure offsets round to the same whole hPa as the level below.

flex_extract

ARL

conversion

t

TEMP

K

u, v

UWND, VWND

m s-1

q

SPHU

kg kg-1

sp

PRSS

Pa to hPa

msl

MSLP

Pa to hPa

z

SHGT

surface geopotential / 9.80665 (m)

t2m, d2m

T02M, DP2M

K

u10, v10

U10M, V10M

m s-1

tcc

TCLD

fraction to %

sshf

SHTF

W m-2, positive upward

ssr

DSWF

W m-2, net (not downward) shortwave

ewss, nsss

USTR

sqrt(sqrt(ewss² + nsss²) / ρ) (m s-1), ρ = sp / (R_d t2m)

lsp + cp

TPP1

mm h-1 at the valid time to m in an hour

Not written, because the files do not hold them: PBLH, LHTF and WWND. flex_extract’s vertical velocity is etadot (s-1), the rate of change of the hybrid coordinate, not a pressure velocity; without WWND HYSPLIT finds the vertical velocity from the divergence of the horizontal wind, and its mixed layer from the temperature profile.

Parameters:

datasets (Iterable[Dataset]) – The Datasets of one or more flex_extract files, as cfgrib.open_datasets() returns them (each with a scalar valid_time; the precipitation’s with a step dimension, of which the first is the valid time’s), one list after another. Datasets and variables not in the table (the invariant fields, etadot, the cloud water) are left out.

Returns:

The fields in arlmet.open_dataset()’s layout, with source "ERA5" and each variable’s ARL units in its attrs.

Return type:

Dataset

Raises:

ValueError – If no Dataset holds model-level fields, a Dataset has no scalar valid time, the time steps have different model levels, the grids differ, or a time step has no surface pressure sp.

Notes

FLEXPART finds the friction velocity from the surface stress as above (calcpar), with the air density at 2 m. The precipitation is the rate at the valid time, which flex_extract interpolates from ERA5’s hourly totals (its RRINT option); written as TPP1 it stands for the hour before.

Each field is read once and is then in memory: flex_extract’s files are already cropped to the domain they were retrieved for.

Examples

>>> import cfgrib
>>> import arlmet
>>> files = ["EA23053118", "EA23053119", "EA23053120"]
>>> datasets = [
...     ds for f in files for ds in cfgrib.open_datasets(f)
... ]
>>> ds = arlmet.converters.from_flex_extract(datasets)
>>> arlmet.write_dataset(ds, "era5.arl")