arlmet.converters.from_era5#
- arlmet.converters.from_era5(levels, single_levels)[source]#
Convert ERA5 hourly fields to a Dataset that
arlmet.write_dataset()writes.This is HYSPLIT’s
era52arlfor ERA5 on pressure levels and itsapi2arlfor ERA5 on model levels, taking two Datasets of a Copernicus Climate Data Store download as xarray opens them, from netCDF or, withcfgrib, from GRIB:levels(reanalysis-era5-pressure-levels, or model levels fromreanalysis-era5-complete) andsingle_levels(reanalysis-era5-single-levels). The result is on the same lat/lon grid, rows south to north, levels from the ground up; nothing is read until it is written, when the inputs are lazy (opened withchunks=).Pressure levels give an ARL pressure-level Dataset (vertical flag 2), its levels from the highest pressure up.
Model levels (a
model_levelor cfgrib’shybriddimension, 1 at the top to 137 at the ground) give an ARL hybrid Dataset (flag 4), its levels from model level 137 up, each written asapi2arlwrites it (Notes). HYSPLIT finds each level’s pressure from the surface pressure, sosingle_levelsmust holdsp. Levels above about model level 24 cannot be written: their pressure offsets round to the same whole hPa; and an ARL file holds at most 99 levels, so model levels 39 to 137 at most (see Raises).
The variables converted are those of
era52arl’s default list, plus specific humidity, and on model levels those ofapi2arl’s. Each is written when the input has it; others are ignored.ERA5
ARL
conversion
zHGTS
geopotential / 9.80665 (m; pressure levels)
tTEMP
K
u,vUWND, VWND
m s-1
wWWND
Pa s-1 to hPa s-1, with a
DIFWrecordrRELH
% (pressure levels)
qSPHU
kg kg-1
spPRSS
Pa to hPa
zSHGT
surface geopotential / 9.80665 (m)
t2mT02M
K
d2mDP2M
K
u10,U10M,
m s-1
v10V10M
blhPBLH
m
capeCAPE
J kg-1
tccTCLD
fraction to %
tpTPP1
m in the hour, with a
DIFRrecordsshfSHTF
J m-2 in the hour to W m-2, positive upward
slhfLHTF
J m-2 in the hour to W m-2, positive upward
ssrdDSWF
J m-2 in the hour to W m-2
zustUSTR
m s-1
- Parameters:
levels (
Dataset) – ERA5 fields on pressure levels or on model levels, with dims valid time (valid_timeortime), the level (pressure_level,isobaricInhPaorlevel, in hPa; ormodel_levelorhybrid),latitudeandlongitude.single_levels (
Dataset) – ERA5 single-level fields on the same grid, at every valid time oflevels(it may hold others, which are left out). A CDS netCDF download comes as two files, the instantaneous and the accumulated fields: merge them first (xarray.merge()).
- Returns:
The fields in
arlmet.open_dataset()’s layout, with source"ERA5", each variable’s ARLunitsin its attrs, andattrs["diff"]onWWNDandTPP1.- Return type:
- Raises:
ValueError – If a Dataset has none of the variables above, a dimension is missing or extra (an ensemble
number, a forecaststep), the latitudes or longitudes are not equally spaced, the two grids differ, orsingle_levelslacks a valid time oflevels. On model levels, also ifsingle_levelshas nosp, two of the levels would be stored as the same pressure (any above about model level 24), or there are more than 99 levels (an ARL record’s header numbers its level in two characters): select the lowest 99 or fewer, for examplelevels.sel(model_level=slice(39, None)).
Notes
Where this differs from
era52arl:era52arldivides geopotential by 9.8 (a factor of 0.102), turns the hourly totals of the heat fluxes and solar radiation into W m-2 with a factor of 0.00028 for 1/3600 (so itsDSWFis 0.8 % high), writesTCLDas a fraction where HYSPLIT reads percent, keeps ECMWF’s downward-positive heat fluxes where HYSPLIT takes them positive upward (stbanl.f; HYSPLIT changes the sign only forETAfiles, inprfcom.f), so HYSPLIT reads a sunny afternoon in anera52arlfile as stable, and names the latent heat fluxLTHF, a name HYSPLIT does not read.era52arldoes not convert model levels.An ARL hybrid level is one number, a pressure offset in whole hPa plus a sigma, the level’s pressure being
offset + sigma * surface pressure(HYSPLIT’sprfecm). As inapi2arl, model leveln’s offset is the meanaof its two half levels in hPa, rounded, and its sigma their meanb(ECMWF’s L137 coefficients). The index record holds each level in six characters, so above an offset of 100 hPa sigma keeps two decimals: HYSPLIT reads some mid-troposphere levels up to about 5 hPa from ERA5’s pressure (model level 100: 584.6 hPa for 589.7 at a surface pressure of 1013.25 hPa).api2arl’s files are rounded the same way.Examples
>>> import xarray as xr >>> import arlmet >>> pl = xr.open_dataset("era5_pressure_levels.nc", chunks={}) >>> sfc = xr.merge( ... [xr.open_dataset("era5_instant.nc"), xr.open_dataset("era5_accum.nc")], ... compat="override", ... ) >>> ds = arlmet.converters.from_era5(pl, sfc) >>> arlmet.write_dataset(ds, "era5.arl")
On model levels, from GRIB (
cfgribnames the dimensionhybrid):>>> ml = xr.open_dataset( ... "era5_model_levels.grib", ... engine="cfgrib", ... backend_kwargs={"filter_by_keys": {"typeOfLevel": "hybrid"}}, ... ) >>> ds = arlmet.converters.from_era5( ... ml.sel(hybrid=slice(60, None)), sfc ... )