Struct grib::SubMessage

source ·
pub struct SubMessage<'a, R>(pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub Option<SubMessageSection<'a>>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, pub SubMessageSection<'a>, _);

Tuple Fields§

§0: SubMessageSection<'a>§1: SubMessageSection<'a>§2: Option<SubMessageSection<'a>>§3: SubMessageSection<'a>§4: SubMessageSection<'a>§5: SubMessageSection<'a>§6: SubMessageSection<'a>§7: SubMessageSection<'a>§8: SubMessageSection<'a>

Implementations§

source§

impl<R> SubMessage<'_, R>

source

pub fn parameter(&self) -> Option<Parameter>

Returns the product’s parameter.

In the context of GRIB products, parameters refer to weather elements such as air temperature, air pressure, and humidity, and other physical quantities.

§Examples
use std::{
    fs::File,
    io::{BufReader, Read},
};

use grib::codetables::NCEP;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut buf = Vec::new();

    let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
    let f = BufReader::new(f);
    let mut f = xz2::bufread::XzDecoder::new(f);
    f.read_to_end(&mut buf)?;

    let f = std::io::Cursor::new(buf);
    let grib2 = grib::from_reader(f)?;

    let mut iter = grib2.iter();
    let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;

    let param = message.parameter();
    assert_eq!(
        param,
        Some(grib::Parameter {
            discipline: 0,
            centre: 7,
            master_ver: 2,
            local_ver: 1,
            category: 3,
            num: 1
        })
    );
    let param = param.unwrap();
    assert_eq!(
        param.description(),
        Some("Pressure reduced to MSL".to_owned())
    );
    assert!(param.is_identical_to(NCEP::PRMSL));
    Ok(())
}
source

pub fn indicator(&self) -> &Indicator

source

pub fn grid_def(&self) -> &GridDefinition

source

pub fn prod_def(&self) -> &ProdDefinition

source

pub fn repr_def(&self) -> &ReprDefinition

source

pub fn describe(&self) -> String

source

pub fn grid_shape(&self) -> Result<(usize, usize), GribError>

Returns the shape of the grid, i.e. a tuple of the number of grids in the i and j directions.

§Examples
use std::{
    fs::File,
    io::{BufReader, Read},
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut buf = Vec::new();

    let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
    let f = BufReader::new(f);
    let mut f = xz2::bufread::XzDecoder::new(f);
    f.read_to_end(&mut buf)?;

    let f = std::io::Cursor::new(buf);
    let grib2 = grib::from_reader(f)?;

    let mut iter = grib2.iter();
    let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;

    let shape = message.grid_shape()?;
    assert_eq!(shape, (1440, 721));
    Ok(())
}
source

pub fn ij(&self) -> Result<GridPointIndexIterator, GribError>

Computes and returns an iterator over (i, j) of grid points.

The order of items is the same as the order of the grid point values, defined by the scanning mode (ScanningMode) in the data.

This iterator allows users to perform their own coordinate calculations for unsupported grid systems and map the results to grid point values.

§Examples
use std::{
    fs::File,
    io::{BufReader, Read},
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut buf = Vec::new();

    let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
    let f = BufReader::new(f);
    let mut f = xz2::bufread::XzDecoder::new(f);
    f.read_to_end(&mut buf)?;

    let f = std::io::Cursor::new(buf);
    let grib2 = grib::from_reader(f)?;

    let mut iter = grib2.iter();
    let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;

    let mut latlons = message.ij()?;
    assert_eq!(latlons.next(), Some((0, 0)));
    assert_eq!(latlons.next(), Some((1, 0)));
    Ok(())
}
source

pub fn latlons(&self) -> Result<GridPointIterator, GribError>

Computes and returns an iterator over latitudes and longitudes of grid points.

The order of lat/lon data of grid points is the same as the order of the grid point values, defined by the scanning mode (ScanningMode) in the data.

§Examples
use std::{
    fs::File,
    io::{BufReader, Read},
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut buf = Vec::new();

    let f = File::open("testdata/gdas.t12z.pgrb2.0p25.f000.0-10.xz")?;
    let f = BufReader::new(f);
    let mut f = xz2::bufread::XzDecoder::new(f);
    f.read_to_end(&mut buf)?;

    let f = std::io::Cursor::new(buf);
    let grib2 = grib::from_reader(f)?;

    let mut iter = grib2.iter();
    let (_, message) = iter.next().ok_or_else(|| "first message is not found")?;

    let mut latlons = message.latlons()?;
    assert_eq!(latlons.next(), Some((90.0, 0.0)));
    assert_eq!(latlons.next(), Some((90.0, 0.25000003)));
    Ok(())
}

Auto Trait Implementations§

§

impl<'a, R> Freeze for SubMessage<'a, R>

§

impl<'a, R> !RefUnwindSafe for SubMessage<'a, R>

§

impl<'a, R> !Send for SubMessage<'a, R>

§

impl<'a, R> !Sync for SubMessage<'a, R>

§

impl<'a, R> Unpin for SubMessage<'a, R>

§

impl<'a, R> !UnwindSafe for SubMessage<'a, R>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.