flexprep.io_grib

Write FLEXPART-ready GRIB2 files.

FLEXPART expects its meteorological inputs in GRIB2 format, one file per forecast step (e.g., dispfYYYYMMDDHH.grib). This module takes a mapping of {shortName: xarray.DataArray} and writes each forecast step to GRIB2.

All GRIB1 messages are converted to GRIB2 by overriding their metadata based on a GRIB2 Template 4.0 (instantaneous forecast). The main rules are:

  1. GRIB2 fields not processed (q, u, v, t): kept unchanged.

  2. GRIB1 fields not processed (10u, 10v, 2t, 2d, sp, tcc, sd, lsm, z, sdor): converted to GRIB2 with the correct vertical definition.

  3. Processed fields (cp, lsp, ssr, sshf, ewss, nsss): written as 1-hour accumulations (PDT 8)

  4. Omega/w: instantaneous (PDT 0) on hybrid model level K (Pa s⁻¹) with shortName=”w”

Functions

write_grib(fields[, output_dir, prefix, suffix])

Write one GRIB file per forecast step by overriding message metadata.