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>
impl<'g> Variable<'g>
sourcepub fn attribute<'a>(&'a self, name: &str) -> Option<Attribute<'a>>
pub fn attribute<'a>(&'a self, name: &str) -> Option<Attribute<'a>>
Get an attribute of this variable
sourcepub fn attributes(&self) -> impl Iterator<Item = Attribute<'_>>
pub fn attributes(&self) -> impl Iterator<Item = Attribute<'_>>
Iterator over all the attributes of this variable
sourcepub fn attribute_value(&self, name: &str) -> Option<Result<AttributeValue>>
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}");
sourcepub fn dimensions(&self) -> &[Dimension<'_>]
pub fn dimensions(&self) -> &[Dimension<'_>]
Dimensions for a variable
sourcepub fn vartype(&self) -> VariableType
pub fn vartype(&self) -> VariableType
Get the type of this variable
sourcepub fn endianness(&self) -> Result<Endianness>
pub fn endianness(&self) -> Result<Endianness>
source§impl<'g> Variable<'g>
impl<'g> Variable<'g>
sourcepub fn get_value<T: NcPutGet, E>(&self, indices: E) -> Result<T>
pub fn get_value<T: NcPutGet, E>(&self, indices: E) -> Result<T>
Fetches one specific value at specific indices indices must has the same length as self.dimensions.
sourcepub fn get_string<E>(&self, indices: E) -> Result<String>
pub fn get_string<E>(&self, indices: E) -> Result<String>
Reads a string variable. This involves two copies per read, and should be avoided in performance critical code
sourcepub fn get_values<T: NcPutGet, E>(&self, extents: E) -> Result<Vec<T>>
pub fn get_values<T: NcPutGet, E>(&self, extents: E) -> Result<Vec<T>>
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
sourcepub fn get<T: NcPutGet, E>(&self, extents: E) -> Result<ArrayD<T>>
Available on crate feature ndarray
only.
pub fn get<T: NcPutGet, E>(&self, extents: E) -> Result<ArrayD<T>>
ndarray
only.Get values from a variable
sourcepub fn get_into<T: NcPutGet, E, D>(
&self,
extents: E,
out: ArrayViewMut<'_, T, D>
) -> Result<()>
Available on crate feature ndarray
only.
pub fn get_into<T: NcPutGet, E, D>( &self, extents: E, out: ArrayViewMut<'_, T, D> ) -> Result<()>
ndarray
only.Get values from a variable directly into an ndarray
sourcepub fn fill_value<T: NcPutGet>(&self) -> Result<Option<T>>
pub fn fill_value<T: NcPutGet>(&self) -> Result<Option<T>>
Get the fill value of a variable
sourcepub fn get_values_into<T: NcPutGet, E>(
&self,
buffer: &mut [T],
extents: E
) -> Result<()>
pub fn get_values_into<T: NcPutGet, E>( &self, buffer: &mut [T], extents: E ) -> Result<()>
Fetches variable into slice buffer must be able to hold all the requested elements
sourcepub fn get_raw_values<E>(&self, buf: &mut [u8], extents: E) -> Result<()>
pub fn get_raw_values<E>(&self, buf: &mut [u8], extents: E) -> Result<()>
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.