grib-rust
Pure-Rust GRIB reader, writer, and shared core primitives for weather and climate data. No C libraries, no build scripts, and no unsafe beyond memmap2.
Crates
| Crate | Description |
|---|---|
grib-core |
Shared GRIB data model, code tables, binary primitives, bit I/O, and validation helpers |
grib-reader |
GRIB1/GRIB2 file opening, message scanning, metadata parsing, and packed data decoding |
grib-writer |
GRIB1/GRIB2 field builders, simple packing, bitmap handling, and message serialization |
Reader Usage
use GribFile;
let file = open?;
println!;
for msg in file.messages
let field = file.message?;
let flat = field.read_flat_data_as_f32?;
println!;
let mut reused = vec!;
field.decode_into?;
let data = field.read_data_as_f64?;
println!;
let tolerant = from_bytes_with_options?;
println!;
Writer Usage
use ;
use ;
let grid = LatLon;
let id = Identification ;
let product = ProductDefinition ;
let values = ;
let field = new
.identification
.grid
.product
.packing
.values
.build?;
let mut bytes = Vecnew;
new.write_grib2_message?;
Supported Now
- GRIB1 and GRIB2 message scanning with
"GRIB"/"7777"boundary detection - Logical field indexing for multi-field GRIB2 messages
- Regular latitude/longitude grids for GRIB1 and GRIB2
- Reader simple packing for GRIB1 and GRIB2
- GRIB2 complex packing with general group splitting, including spatial differencing
- WMO parameter table lookups (Code Table 4.2)
- Typed metadata access for reference time, parameter identity, product metadata, grid geometry, and lat/lon coordinates
- Forecast valid-time helpers for supported fixed-width GRIB1/GRIB2 time units
OpenOptionsfor strict or tolerant scanning- Bitmap application with missing values surfaced as
NaN - Parallel field decoding via Rayon
- Output: caller-owned
&mut [f32]/&mut [f64], flatVec<f32>/Vec<f64>, orndarray::ArrayD<f32>/ArrayD<f64> - Memory-mapped I/O or owned byte buffers
- Writer GRIB2 regular lat/lon fields with product template 4.0 and simple packing template 5.0
- Writer GRIB2 bitmap section generation from explicit masks or
NaNvalues - Writer single-message multi-field GRIB2 output with reused grid sections
- Writer GRIB1 regular lat/lon fields with simple packing and optional bitmap section
Not Yet Supported
- Non-lat/lon grid templates
- Writer complex packing templates 5.2/5.3 and row-by-row complex packing
- JPEG2000 and PNG-packed GRIB2 fields
- GRIB1 predefined bitmaps
Unsupported cases fail explicitly with typed errors.
Calendar-dependent forecast units such as months and years are exposed through
raw metadata but currently return None from valid_time().
Feature flags
| Flag | Default | Description |
|---|---|---|
rayon |
yes | Parallel field decoding |
Testing
Reference compatibility checks are intentionally outside default PR CI:
Release Checklist
Corpus And Fuzzing
- Bootstrap corpus samples live in
grib-reader/tests/corpus/bootstrap/ - Real interoperability samples belong in
grib-reader/tests/corpus/interop/samples/ - Regenerate the bootstrap and fuzz seed corpora with
cargo run -p grib-reader --example sync_corpus - Fuzzer entry points and usage notes live in
grib-reader/fuzz/README.md
Reference Checks
./scripts/run-reference-parity.shruns the Dockerized ecCodes parity suite.grib-writerhas a versioned dev-dependency ongrib-readerfor local validation tests and benchmarks, so dry-run and publish it aftergrib-readerv0.3.0 is visible in the crates.io index.- For reference comparisons and current benchmark results against ecCodes, see docs/benchmark-report.md. Re-run the benchmark scripts after corpus changes before using those numbers as current throughput claims.
License
MIT OR Apache-2.0