Skip to main content

Crate oxigdal_grib

Crate oxigdal_grib 

Source
Expand description

OxiGDAL GRIB Driver - Pure Rust GRIB1/GRIB2 Meteorological Data Format Support

This crate provides comprehensive support for reading GRIB (GRIdded Binary) format files, which are commonly used for meteorological and climate data. Both GRIB Edition 1 and GRIB Edition 2 formats are supported.

§Features

  • Pure Rust Implementation: No C/Fortran dependencies, fully compliant with COOLJAPAN policies
  • GRIB1 and GRIB2 Support: Read both legacy and modern GRIB formats
  • Parameter Tables: WMO standard parameter lookups for meteorological variables
  • Grid Definitions: Support for regular lat/lon, Lambert conformal, Mercator, polar stereographic
  • Data Decoding: Efficient unpacking of packed binary data with proper scaling
  • Integration: Designed to integrate seamlessly with oxigdal-core Dataset

§Quick Start

use oxigdal_grib::reader::GribReader;

// Open a GRIB file
let mut reader = GribReader::open("data/forecast.grib2")?;

// Read all messages
for record in reader {
    let record = record?;

    // Get parameter information
    let param = record.parameter()?;
    println!("Parameter: {} ({})", param.long_name, param.units);

    // Get level information
    println!("Level: {:?} = {}", record.level_type(), record.level_value());

    // Decode data
    let data = record.decode_data()?;
    println!("Data points: {}", data.len());
}

§GRIB Format Overview

GRIB (GRIdded Binary) is a concise data format commonly used in meteorology for storing historical and forecast weather data. It is standardized by the World Meteorological Organization (WMO).

§GRIB1 Structure

  • Indicator Section (IS): Magic bytes ‘GRIB’ and edition number
  • Product Definition Section (PDS): Metadata about the parameter, level, time
  • Grid Definition Section (GDS): Grid geometry and projection
  • Bit Map Section (BMS): Optional bitmap for missing values
  • Binary Data Section (BDS): Packed binary data
  • End Section: Magic bytes ‘7777’

§GRIB2 Structure

  • Section 0: Indicator Section
  • Section 1: Identification Section
  • Section 2: Local Use Section (optional)
  • Section 3: Grid Definition Section
  • Section 4: Product Definition Section
  • Section 5: Data Representation Section
  • Section 6: Bit-Map Section (optional)
  • Section 7: Data Section
  • Section 8: End Section

§Architecture

The crate is organized into several modules:

  • error: Error types for GRIB operations
  • message: Core message parsing and iteration
  • parameter: WMO parameter tables and lookups
  • grid: Grid definitions and coordinate systems
  • grib1: GRIB Edition 1 format support
  • grib2: GRIB Edition 2 format support
  • reader: High-level file reading API

§Performance

This implementation focuses on correctness and simplicity while maintaining reasonable performance. For production use with large GRIB files, consider:

  • Using buffered I/O (automatically done with GribReader::open)
  • Processing messages in parallel when appropriate
  • Caching decoded data if the same message is accessed multiple times

Re-exports§

pub use error::GribError;
pub use error::Result;
pub use grid::GridDefinition;
pub use message::GribEdition;
pub use message::GribMessage;
pub use parameter::LevelType;
pub use parameter::Parameter;
pub use reader::GribReader;
pub use reader::GribRecord;

Modules§

error
Error types for GRIB format parsing and processing.
grib1
GRIB Edition 1 format support.
grib2
GRIB Edition 2 format support.
grid
Grid definitions and coordinate transformations for GRIB formats.
message
GRIB message parsing and structure.
parameter
Parameter tables for GRIB1 and GRIB2 formats.
reader
GRIB file reader with high-level API.
templates
GRIB2 Product Definition Template (PDT) support

Constants§

VERSION
Crate version

Functions§

has_grib1_support
Check if GRIB1 support is enabled
has_grib2_support
Check if GRIB2 support is enabled