Skip to content

fastgrib

GRIB2 and GRIB1 decoding for Python. fastgrib reads files and URLs into numpy arrays on every CPU core with numba, or on an NVIDIA GPU, and every value is bit-for-bit what wgrib2 returns.

pip install git+https://github.com/Rochy111/fastgrib@v0.2.1

Get started Browse the gallery

GEFS ensemble sensitivity: day-5 spaghetti and the day-2 flow that decides it

0.28 msper field to decode a whole GFS 0.25° file, using every core
2.67 msper field for wgrib2 on one thread, and 7.32 ms for pygrib
1,486GFS fields checked against wgrib2, every value identical to the bit
2required dependencies: numpy and numba

Overview

fastgrib opens GRIB files from disk, from memory or over HTTP, lists their contents the way wgrib2 -s does, and returns fields as numpy arrays. Fields can be selected with wgrib2 -match regular expressions, with pygrib-style keywords or with ecCodes short names. It also regrids fields, turns grid-relative winds to east and north, exposes every key under ecCodes' names, and writes GRIB2.

It reads the data published by the main operational centres, including GFS, GEFS, HRRR, NAM, RAP, NBM and MRMS from NOAA, IFS fields from ECMWF, and GRIB1 archives such as NARR, in every common packing: simple, complex, IEEE, JPEG2000, PNG, CCSDS and run-length.

Example

import fastgrib

f = fastgrib.open('gfs.t00z.pgrb2.0p25.f006')    # a path, an http(s):// or s3:// URL, or bytes
print(f)                                         # the inventory, as wgrib2 -s prints it
t2m = f.read('TMP:2 m above ground')             # (ny, nx) float32, NaN where undefined
z500 = f.read(name='HGT', level=500)             # pygrib-style keywords
lat, lon = f.latlon()                            # rows run south to north
u, v = f.winds(level=850)                        # east and north components
ds = f.to_xarray()                               # all fields as an xarray Dataset

Given a URL, fastgrib reads the index file published next to the data and downloads only the fields that are read. The gallery has complete scripts, drawn with fastplot.

Compared with other readers

fastgrib wgrib2 pygrib
Decoded values wgrib2's, to the bit the reference ecCodes'
GFS 0.25°, ms per field 0.28 (all cores), 1.25 (one) 2.67 (one thread) 7.32
Installation pip; numpy and numba compiled binary pip; wheels include ecCodes
Remote files byte ranges, using the index no no
GPU decoding yes no no
Writes GRIB2 yes yes through ecCodes

The performance page describes how these were measured.