arlmet.converters.from_gfs#
- arlmet.converters.from_gfs(datasets, *, bbox=None)[source]#
Convert GFS or GDAS GRIB2 files on pressure levels to a Dataset for
arlmet.write_dataset().This is HYSPLIT’s
api2arlfor NCEP’spgrb2files on a lat/lon grid (GFS forecasts and GDAS analyses at 0.25, 0.5 or 1 degree), taking the Datasetscfgrib.open_datasets()returns for one or several files. Each valid time is one time step. Where two files hold a field at the same valid time, the one with the shorter forecast step is used: an analysis (f000) gives the instantaneous fields and the previous cycle’s 6-hour forecast the precipitation and fluxes the analysis lacks, as NOAA’s GDAS ARL files are made. A field a time step has no file for is written as a missing record there. The index record’s forecast hour is the step of the file that gave the pressure-level fields.GRIB2 (cfgrib name)
ARL
conversion
ghHGTS
geopotential height (m)
t,u,vTEMP, UWND, VWND
K, m s-1
wWWND
Pa s-1 to hPa s-1
rRELH
%
qSPHU
kg kg-1
spPRSS
Pa to hPa
prmslMSLP
Pa to hPa
orogSHGT
m
t(surface)TMPS
K
t2m,r2T02M, RH2M
K, %
u10,v10U10M, V10M
m s-1
tcc(instant)TCLD
%
cape,cinCAPE, CINH
J kg-1
fricvUSTR
m s-1
HPBL(see below)PBLH
m
tpTPP6
kg m-2 to m, since the bucket’s start
avg_ishfSHTF
W m-2, positive upward
avg_slhtfLHTF
W m-2, positive upward
sdswrfDSWF
W m-2
avg_utaua,UMOF,
N m-2
avg_vtauaVMOF
Older ecCodes name the averaged fluxes
shtfl,lhtfl,dswrf,uflxandvflx; both names are read.NCEP’s planetary boundary layer height,
HPBL, is a local GRIB2 parameter that ecCodes (2.50 and earlier) has no name for, so cfgrib calls itunknown, andcfgrib.open_datasets()drops it from a forecast file, where a second unnamed field shares its level. Open it on its own withGFS_HPBL(Examples): it is found by its numbers and written asPBLH. Without it noPBLHis written. A future ecCodes that names ithpblneeds no second open.- Parameters:
datasets (
Iterable[Dataset]) – The Datasets of one or more GRIB2 files, ascfgrib.open_datasets()returns them (each with a scalarvalid_time), one list after another. Datasets and variables not in the table are left out. Every time step must have the same pressure levels; select them first (ds.sel(isobaricInhPa=...)) to write fewer.bbox (
tuple[float,float,float,float] |None) – A bounding box(west, south, east, north)in degrees, asarlmet.open_dataset()takes: only the grid cells inside it are converted. Longitudes may be from -180 to 180 or from 0 to 360, and the box may cross 0.Noneconverts the whole grid.
- Returns:
The fields in
arlmet.open_dataset()’s layout, with source"GFS"and each variable’s ARLunitsin its attrs.- Return type:
- Raises:
ValueError – If no Dataset holds pressure-level fields, a Dataset has no scalar valid time, the time steps have different pressure levels, or the grids differ.
Notes
A field missing at every point (the GDAS files’ instantaneous
tcc) is left out when it is written. NoDIF*records are written, asapi2arlwrites none.Each field is read from its file once, cropped to bbox first, and is then in memory: a global 0.25 degree time step is about 3 GB, the western United States about 0.2 GB.
Examples
>>> import cfgrib >>> import arlmet >>> files = ["gdas.t18z.pgrb2.1p00.f006", "gdas.t00z.pgrb2.1p00.f000"] >>> import xarray as xr >>> hpbl = { ... "filter_by_keys": arlmet.converters.GFS_HPBL, ... "read_keys": list(arlmet.converters.GFS_HPBL), ... } >>> datasets = [ ... ds for f in files for ds in cfgrib.open_datasets(f) ... ] >>> datasets += [ ... xr.open_dataset(f, engine="cfgrib", backend_kwargs=hpbl) for f in files ... ] >>> ds = arlmet.converters.from_gfs(datasets) >>> arlmet.write_dataset(ds, "gdas.arl")