grib_tables 0.1.0

Retrieve details of each GRIB parameter from the parameter abbreviation or from the numeric identifier
Documentation

grib_tables

Retrieve details of each GRIB parameter from the parameter abbreviation or from the numeric identifier.

grib_tables loads the GDAL CSV files into memory and allows the user to:

  • Map from parameter abbreviation strings to the numerical representation of that parameter, and the full parameter name and unit.
  • Map from the numerical representation of each parameter to the parameter name, abbreviation, and unit.

Example

use grib_tables::{ParameterDatabase, MASTER_TABLE_VERSION, Abbrev};
# fn main() -> anyhow::Result<()> {

// Get a ParameterDatabase populated with the GRIB tables stored in the included CSV files:
let param_db = ParameterDatabase::new().populate()?;

// Get the numeric IDs and params associated with the abbreviation "TMP":
let params = param_db.abbrev_to_parameter(&Abbrev::from("TMP"));
// `params` is a `Vec` because some abbreviations are associated with multiple parameters.

// However, "TMP" is associated with exactly one parameter:
assert_eq!(params.len(), 1);
let (temperature_numeric_id, temperature_param) = params.first().as_ref().unwrap();
assert_eq!(temperature_param.name(), "Temperature");
assert_eq!(temperature_param.unit(), "K");
assert_eq!(temperature_numeric_id.product_discipline(), 0);
assert_eq!(temperature_numeric_id.parameter_category(), 0);
assert_eq!(temperature_numeric_id.parameter_number(), 0);
assert_eq!(
    temperature_numeric_id.master_table_version(),
    MASTER_TABLE_VERSION
);

// `MAX` values indicate missing values. "TMP" is part of the GRIB master tables, and
// so is not from a local originating center:
assert_eq!(temperature_numeric_id.originating_center(), u16::MAX);
assert_eq!(temperature_numeric_id.subcenter(), u8::MAX);
assert_eq!(temperature_numeric_id.local_table_version(), u8::MAX);
# Ok(())
# }

Why does grib_tables exist?

To build hypergrib, we need to be able to decode GRIB .idx files.

We're aware of two awesome existing GRIB readers implemented in Rust (gribberish and grib-rs) but, at the time of writing, neither can decode .idx files.

Hence grib_tables exists to enable hypergrib to decode GRIB .idx files.

Related