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 Datasetscfgrib.open_datasets()returns for one or several of those files and gives an ARL hybrid Dataset (vertical flag 4) on model levels, asfrom_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
tTEMP
K
u,vUWND, VWND
m s-1
qSPHU
kg kg-1
spPRSS
Pa to hPa
mslMSLP
Pa to hPa
zSHGT
surface geopotential / 9.80665 (m)
t2m,d2mT02M, DP2M
K
u10,v10U10M, V10M
m s-1
tccTCLD
fraction to %
sshfSHTF
W m-2, positive upward
ssrDSWF
W m-2, net (not downward) shortwave
ewss,nsssUSTR
sqrt(sqrt(ewss² + nsss²) / ρ)(m s-1),ρ = sp / (R_d t2m)lsp+cpTPP1
mm h-1 at the valid time to m in an hour
Not written, because the files do not hold them:
PBLH,LHTFandWWND. flex_extract’s vertical velocity isetadot(s-1), the rate of change of the hybrid coordinate, not a pressure velocity; withoutWWNDHYSPLIT 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, ascfgrib.open_datasets()returns them (each with a scalarvalid_time; the precipitation’s with astepdimension, 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 ARLunitsin its attrs.- Return type:
- 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 (itsRRINToption); written asTPP1it 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")