Crates.io | grib |
lib.rs | grib |
version | 0.10.2 |
source | src |
created_at | 2020-06-07 07:33:36.321521 |
updated_at | 2024-10-02 15:54:30.301696 |
description | GRIB format parser for Rust |
homepage | https://github.com/noritada/grib-rs |
repository | https://github.com/noritada/grib-rs |
max_upload_size | |
id | 250893 |
size | 61,166,842 |
GRIB format parser for Rust
This is a GRIB format parser library written in Rust programming language. This project aims to provide a set of library and tools which is simple-to-use, efficient, and educational.
GRIB is a concise data format commonly used in meteorology to store historical and forecast weather data. It is intended to be a container of a collection of records of 2D data. GRIB files are huge and binary and should be processed efficiently. Also, since GRIB is designed to support various grid types and data compression using parameters defined in external code tables and templates, some popular existing softwares cannot handle some GRIB data.
GRIB2 viewer web app for demo using the crate is available here.
After loaded, the app works completely on your web browser and will not send the data you drop anywhere.
A world where everyone can read weather data easily although its interpretation needs some specific knowledge and experience.
grib
gribber
built on the top of the Rust library
GRIB2 can contain grid point values for various grid systems. This diversity is supported by a mechanism called "templates".
Although GRIB2 contains a large number of grid point values, the coordinates and values of individual grid points are not encoded directly as numerical data. Since the grid points are regularly arranged, the coordinates can be defined by the type of projection method used for the grid system and the specific parameters for that projection method, so only a simple definition of the grid system is encoded in the data.
Also, since the best encoding method for values varies from data to data, there are multiple methods that can be used to encode values, and the method used and the specific parameters needed to encode it are defined along with the data itself.
These definitions of grid systems and data representation are represented by sequences of bytes called templates, which should be supported in order for the reader to read GRIB2 data. grib-rs supports the following templates. We would love to support other templates as well, so please let us know if there is any data that is not readable.
For data using the following grid systems, latitudes and longitudes of grid points can be computed.
Template number | Grid system | Notes |
---|---|---|
3.0 | latitude/longitude (or equidistant cylindrical, or Plate Carree) | supporting only regular grids |
3.20 | Polar stereographic projection | enabling feature gridpoints-proj required |
3.30 | Lambert conformal | enabling feature gridpoints-proj required |
3.40 | Gaussian latitude/longitude | supporting only regular grids |
For data using the following encoding methods, grid point values can be extracted.
Template number | Encoding method |
---|---|
5.0 | simple packing |
5.2 | complex packing |
5.3 | complex packing and spatial differencing |
5.40 | JPEG 2000 code stream format |
5.41 | Portable Network Graphics (PNG) |
5.200 | run length packing with level values |
Please check the ROADMAP to see planned features.
API Documentation of the released version of the library crate is available on Docs.rs although it is not extensive. The development version is available on GitHub Pages.
If you feel a feature is missing, please send us your suggestions through the GitHub Issues. We are working on expanding the basic functionality as our top priority in this project, so we would be happy to receive any requests.
use grib::{codetables::grib2::*, ForecastTime, Grib2SubmessageDecoder, Name};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let fname = "testdata/Z__C_RJTD_20160822020000_NOWC_GPV_Ggis10km_Pphw10_FH0000-0100_grib2.bin";
let f = std::fs::File::open(fname)?;
let f = std::io::BufReader::new(f);
let grib2 = grib::from_reader(f)?;
let (_index, submessage) = grib2
.iter()
.find(|(_index, submessage)| {
matches!(
submessage.prod_def().forecast_time(),
Some(ForecastTime {
unit: Name(Table4_4::Minute),
value: minutes,
}) if minutes == 30
)
})
.ok_or("message with FT being 30 minutes not found")?;
let latlons = submessage.latlons()?;
let decoder = Grib2SubmessageDecoder::from(submessage)?;
let values = decoder.dispatch()?;
for ((lat, lon), value) in latlons.zip(values) {
println!("{lat} {lon} {value}");
}
Ok(())
}
The examples directory may help you understand the API.
gribber
CLI application gribber
built on the top of the grib
library is available. It is in the grib-cli
package and can be installed via cargo install grib-cli
.
Usage: gribber [COMMAND]
Commands:
completions Generate shell completions for your shell to stdout
decode Export decoded data with latitudes and longitudes
info Show identification information
inspect Inspect and describes the data structure
list List layers contained in the data
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Note that binaries exported from gribber decode --big-endian
use 0x7fc00000
as a missing value, although those from wgrib
use 0x6258d19a
.
This repository uses the submodules functionality of Git. So, before running cargo build
, please add submodules in one of following ways:
--recursive
to git clone
will automatically clone submodules in addition to this repositorygit submodule update --init --recursive
after cloning will update the repository to have submodulesThen you can build it in the usual way in the Rust world.
cargo build
If you have questions or want to have discussions, feel free to use GitHub Discussions as a forum.
Contribution is always welcome. Please check CONTRIBUTING.md if you are interested.
This project is licensed under either of
at your option.
SPDX-License-Identifier: Apache-2.0 OR MIT