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 era52arl for ERA5 on pressure levels and its api2arl for ERA5 on model levels, taking two Datasets of a Copernicus Climate Data Store download as xarray opens them, from netCDF or, with cfgrib, from GRIB: levels (reanalysis-era5-pressure-levels, or model levels from reanalysis-era5-complete) and single_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 with chunks=).

  • Pressure levels give an ARL pressure-level Dataset (vertical flag 2), its levels from the highest pressure up.

  • Model levels (a model_level or cfgrib’s hybrid dimension, 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 as api2arl writes it (Notes). HYSPLIT finds each level’s pressure from the surface pressure, so single_levels must hold sp. 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 of api2arl’s. Each is written when the input has it; others are ignored.

ERA5

ARL

conversion

z

HGTS

geopotential / 9.80665 (m; pressure levels)

t

TEMP

K

u, v

UWND, VWND

m s-1

w

WWND

Pa s-1 to hPa s-1, with a DIFW record

r

RELH

% (pressure levels)

q

SPHU

kg kg-1

sp

PRSS

Pa to hPa

z

SHGT

surface geopotential / 9.80665 (m)

t2m

T02M

K

d2m

DP2M

K

u10,

U10M,

m s-1

v10

V10M

blh

PBLH

m

cape

CAPE

J kg-1

tcc

TCLD

fraction to %

tp

TPP1

m in the hour, with a DIFR record

sshf

SHTF

J m-2 in the hour to W m-2, positive upward

slhf

LHTF

J m-2 in the hour to W m-2, positive upward

ssrd

DSWF

J m-2 in the hour to W m-2

zust

USTR

m s-1

Parameters:
  • levels (Dataset) – ERA5 fields on pressure levels or on model levels, with dims valid time (valid_time or time), the level (pressure_level, isobaricInhPa or level, in hPa; or model_level or hybrid), latitude and longitude.

  • single_levels (Dataset) – ERA5 single-level fields on the same grid, at every valid time of levels (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 ARL units in its attrs, and attrs["diff"] on WWND and TPP1.

Return type:

Dataset

Raises:

ValueError – If a Dataset has none of the variables above, a dimension is missing or extra (an ensemble number, a forecast step), the latitudes or longitudes are not equally spaced, the two grids differ, or single_levels lacks a valid time of levels. On model levels, also if single_levels has no sp, 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 example levels.sel(model_level=slice(39, None)).

Notes

Where this differs from era52arl: era52arl divides 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 its DSWF is 0.8 % high), writes TCLD as 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 for ETA files, in prfcom.f), so HYSPLIT reads a sunny afternoon in an era52arl file as stable, and names the latent heat flux LTHF, a name HYSPLIT does not read. era52arl does 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’s prfecm). As in api2arl, model level n’s offset is the mean a of its two half levels in hPa, rounded, and its sigma their mean b (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 (cfgrib names the dimension hybrid):

>>> 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
... )