noritada / grib-rs

GRIB format parser for Rust
Apache License 2.0
57 stars 9 forks source link

Error "NotSupported('template 40')" When Running GRIB Parsing Code #85

Closed BruAPAHE closed 2 months ago

BruAPAHE commented 2 months ago

Motivation


Problem

I encountered an error while trying to parse a GRIB2 file using the grib crate in Rust. The code fails with the error NotSupported("template 40").

Steps to Reproduce

  1. Open a GRIB2 file named gfs.t06z.sfluxgrbf000.grib2.
  2. Attempt to read the file and find a specific submessage.
  3. The code crashes with the error NotSupported("template 40").

Code

use std::fs::File;
use std::io::BufReader;
use grib::Grib;

fn main() {
    let fname = "gfs.t06z.sfluxgrbf000.grib2";
    // Open the input file in a normal way.
    let f = File::open(fname).unwrap();
    let f = BufReader::new(f);

    // Read with the reader.
    let grib2 = grib::from_reader(f).unwrap();

    // Find the target submessage.
    let (_index, submessage) = grib2
        .iter()
        .find(|(index, _)| *index == (1, 0))
        .ok_or("no such index").unwrap();

    let latlons = submessage.latlons().unwrap();
}

Error

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotSupported("template 40")', src/main.rs:XX:YY

Environment

Additional Information

The error suggests that the specific GRIB2 template (template 40) is not supported by the grib crate. It would be helpful if support for this template could be added or if there is a workaround to handle this template.

Expected Behavior

The code should parse the GRIB2 file without encountering the NotSupported("template 40") error and should successfully retrieve the latitude and longitude information.


Proposed Solution

-

Additional Context

noritada commented 2 months ago

Thank you very much for the report. Yes, there is a branch named as feat/gaussian-grid-support that contains test data (testdata/gdas.t00z.sfluxgrbf000.grib2.0.xz) for the same issue where the latitude and longitude of grid points cannot be calculated.

If I can figure out how to calculate the latitude/longitude of a Gaussian grid, it should not be difficult to implement, but since I don't really understand the difference between a Gaussian grid and a latitude/longitude grid (whose support is already included), I have not yet been able to implement the process even though I have prepared the branch. I will look into it.

BruAPAHE commented 2 months ago

@noritada Thank you for answer!!

noritada commented 2 months ago

I have understood what I need to implement and how to implement. This issue will be resolved in the near future.

noritada commented 2 months ago

@BruAPAHE I think the feat/gaussian-grid-support branch now has implementation of latitude/longitude calculation for points in the Gaussian grid.

It should work for the most standard data, including the GFS flux data documented in the issue. Since some implementations are still missing, working on support for data starting in from the south, error handling, etc. will need to be done before the branch getting merged. But if you are interested in checking it out, feel free to try the branch.

Many thanks.

BruAPAHE commented 2 months ago

@noritada Thanks for the update!! I'll address the remaining implementations and look into the branch soon. Thanks again!