Struct netcdf::Variable

source ·
pub struct Variable<'g> { /* private fields */ }
Expand description

This struct defines a netCDF variable.

This type is used for retrieving data from a variable. Metadata on the netCDF-level can be retrieved using e.g. fill_value, endinanness. Use attributes to get additional metadata assigned by the data producer. This crate will not apply any of the transformations given by such attributes (e.g. add_offset and scale_factor are NOT considered).

Use the get*-functions to retrieve values.

Implementations§

source§

impl<'g> Variable<'g>

source

pub fn name(&self) -> String

Get the name of variable

source

pub fn attribute<'a>(&'a self, name: &str) -> Option<Attribute<'a>>

Get an attribute of this variable

source

pub fn attributes(&self) -> impl Iterator<Item = Attribute<'_>>

Iterator over all the attributes of this variable

source

pub fn attribute_value(&self, name: &str) -> Option<Result<AttributeValue>>

Get the attribute value

§Example
let capture_date: String = var.attribute_value("capture_date").transpose()?
                              .expect("no such attribute").try_into()?;
println!("Captured at {capture_date}");
source

pub fn dimensions(&self) -> &[Dimension<'_>]

Dimensions for a variable

source

pub fn vartype(&self) -> VariableType

Get the type of this variable

source

pub fn len(&self) -> usize

Get current length of the variable

source

pub fn endianness(&self) -> Result<Endianness>

Get endianness of the variable.

§Errors

Not a netCDF-4 file

source§

impl<'g> Variable<'g>

source

pub fn get_value<T: NcPutGet, E>(&self, indices: E) -> Result<T>
where E: TryInto<Extents>, E::Error: Into<Error>,

Fetches one specific value at specific indices indices must has the same length as self.dimensions.

source

pub fn get_string<E>(&self, indices: E) -> Result<String>
where E: TryInto<Extents>, E::Error: Into<Error>,

Reads a string variable. This involves two copies per read, and should be avoided in performance critical code

source

pub fn get_values<T: NcPutGet, E>(&self, extents: E) -> Result<Vec<T>>
where E: TryInto<Extents>, E::Error: Into<Error>,

Get multiple values from a variable

Take notice: scale_factor and offset_factor and other attributes are not automatically applied. To take such into account, you can use code like below

// let var = ...
// let values = ...
if let Some(scale_offset) = var.attribute_value("scale_offset").transpose()? {
    let scale_offset: f64 = scale_offset.try_into()?;
    // values += scale_offset
}

where Option::transpose is used to bubble up any read errors

source

pub fn get<T: NcPutGet, E>(&self, extents: E) -> Result<ArrayD<T>>
where E: TryInto<Extents>, E::Error: Into<Error>,

Available on crate feature ndarray only.

Get values from a variable

source

pub fn get_into<T: NcPutGet, E, D>( &self, extents: E, out: ArrayViewMut<'_, T, D> ) -> Result<()>
where D: Dimension, E: TryInto<Extents>, E::Error: Into<Error>,

Available on crate feature ndarray only.

Get values from a variable directly into an ndarray

source

pub fn fill_value<T: NcPutGet>(&self) -> Result<Option<T>>

Get the fill value of a variable

source

pub fn get_values_into<T: NcPutGet, E>( &self, buffer: &mut [T], extents: E ) -> Result<()>
where E: TryInto<Extents>, E::Error: Into<Error>,

Fetches variable into slice buffer must be able to hold all the requested elements

source

pub fn get_raw_values<E>(&self, buf: &mut [u8], extents: E) -> Result<()>
where E: TryInto<Extents>, E::Error: Into<Error>,

Get values of any type as bytes, with no further interpretation of the values.

§Note

When working with compound types, variable length arrays and strings will be allocated in buf, and this library will not keep track of the allocations. This can lead to memory leaks.

source

pub fn get_vlen<T: NcPutGet, E>(&self, indices: E) -> Result<Vec<T>>
where E: TryInto<Extents>, E::Error: Into<Error>,

Get a vlen element

Trait Implementations§

source§

impl<'g> Clone for Variable<'g>

source§

fn clone(&self) -> Variable<'g>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'g> Debug for Variable<'g>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'g> Freeze for Variable<'g>

§

impl<'g> RefUnwindSafe for Variable<'g>

§

impl<'g> Send for Variable<'g>

§

impl<'g> Sync for Variable<'g>

§

impl<'g> Unpin for Variable<'g>

§

impl<'g> UnwindSafe for Variable<'g>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.