pub struct VariableMut<'g>(/* private fields */);
Expand description
Mutable access to a variable.
This type is used for defining and inserting data into a variable.
Some properties is required to be set before putting data, such as
set_chunking
and set_compression
.
After these are defined one can use the put*
-functions to insert data into the variable.
This type derefs to a Variable
, which means VariableMut
can be used where Variable
is expected.
Implementations§
Source§impl VariableMut<'_>
impl VariableMut<'_>
Sourcepub fn set_compression(
&mut self,
deflate_level: nc_type,
shuffle: bool,
) -> Result<()>
pub fn set_compression( &mut self, deflate_level: nc_type, shuffle: bool, ) -> Result<()>
Sets compression on the variable. Must be set before filling in data.
deflate_level
can take a value 0..=9, with 0 being no
compression (good for CPU bound tasks), and 9 providing the
highest compression level (good for memory bound tasks)
shuffle
enables a filter to reorder bytes before compressing, which
can improve compression ratios
§Errors
Not a netcdf-4
file or deflate_level
not valid
Sourcepub fn set_chunking(&mut self, chunksize: &[usize]) -> Result<()>
pub fn set_chunking(&mut self, chunksize: &[usize]) -> Result<()>
Set chunking for variable. Must be set before inserting data
Use this when reading or writing smaller units of the hypercube than the full dimensions lengths, to change how the variable is stored in the file. This has no effect on the memory order when reading/putting a buffer.
§Errors
Not a netCDF-4
file or invalid chunksize
Source§impl VariableMut<'_>
impl VariableMut<'_>
Sourcepub fn put_attribute<T>(&mut self, name: &str, val: T) -> Result<Attribute<'_>>where
T: Into<AttributeValue>,
pub fn put_attribute<T>(&mut self, name: &str, val: T) -> Result<Attribute<'_>>where
T: Into<AttributeValue>,
Adds an attribute to the variable
Source§impl VariableMut<'_>
impl VariableMut<'_>
Sourcepub fn put_values<T: NcTypeDescriptor, E>(
&mut self,
values: &[T],
extents: E,
) -> Result<()>
pub fn put_values<T: NcTypeDescriptor, E>( &mut self, values: &[T], extents: E, ) -> Result<()>
Put a slice of values at indices
Sourcepub fn put_value<T: NcTypeDescriptor, E>(
&mut self,
value: T,
extents: E,
) -> Result<()>
pub fn put_value<T: NcTypeDescriptor, E>( &mut self, value: T, extents: E, ) -> Result<()>
Put a value at the specified indices
Sourcepub fn put_string<E>(&mut self, value: &str, extents: E) -> Result<()>
pub fn put_string<E>(&mut self, value: &str, extents: E) -> Result<()>
Put a string at the specified indices
Sourcepub fn set_fill_value<T>(&mut self, fill_value: T) -> Result<()>where
T: NcTypeDescriptor,
pub fn set_fill_value<T>(&mut self, fill_value: T) -> Result<()>where
T: NcTypeDescriptor,
Sourcepub unsafe fn set_nofill(&mut self) -> Result<()>
pub unsafe fn set_nofill(&mut self) -> Result<()>
Sourcepub fn set_endianness(&mut self, e: Endianness) -> Result<()>
pub fn set_endianness(&mut self, e: Endianness) -> Result<()>
Set endianness of the variable. Must be set before inserting data
endian
can take a Endianness
value with Native being NC_ENDIAN_NATIVE
(0),
Little NC_ENDIAN_LITTLE
(1), Big NC_ENDIAN_BIG
(2)
§Errors
Not a netCDF-4
file, late define
Methods from Deref<Target = 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) -> NcVariableType
pub fn vartype(&self) -> NcVariableType
Get the type of this variable
Sourcepub fn endianness(&self) -> Result<Endianness>
pub fn endianness(&self) -> Result<Endianness>
Sourcepub fn chunking(&self) -> Result<Option<Vec<usize>>>
pub fn chunking(&self) -> Result<Option<Vec<usize>>>
Get the chunking for the variable. Returns None for a contiguous variable.
§Errors
Not a netCDF-4
file.
Sourcepub fn get_values<T: NcTypeDescriptor + Copy, E>(
&self,
extents: E,
) -> Result<Vec<T>>
pub fn get_values<T: NcTypeDescriptor + Copy, 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_value<T: NcTypeDescriptor + Copy, E>(&self, extents: E) -> Result<T>
pub fn get_value<T: NcTypeDescriptor + Copy, E>(&self, extents: E) -> Result<T>
Get a single value
Sourcepub fn get_string<E>(&self, extents: E) -> Result<String>
pub fn get_string<E>(&self, extents: E) -> Result<String>
Get a string from this variable
Sourcepub fn get<T: NcTypeDescriptor + Copy, E>(
&self,
extents: E,
) -> Result<ArrayD<T>>
Available on crate feature ndarray
only.
pub fn get<T: NcTypeDescriptor + Copy, E>( &self, extents: E, ) -> Result<ArrayD<T>>
ndarray
only.Get values from a variable
Sourcepub fn get_into<T: NcTypeDescriptor + Copy, E, D>(
&self,
out: ArrayViewMut<'_, T, D>,
extents: E,
) -> Result<()>
Available on crate feature ndarray
only.
pub fn get_into<T: NcTypeDescriptor + Copy, E, D>( &self, out: ArrayViewMut<'_, T, D>, extents: E, ) -> Result<()>
ndarray
only.Get values from a variable directly into an ndarray
Sourcepub fn fill_value<T: NcTypeDescriptor + Copy>(&self) -> Result<Option<T>>
pub fn fill_value<T: NcTypeDescriptor + Copy>(&self) -> Result<Option<T>>
Get the fill value of a variable
Sourcepub fn get_values_into<T: NcTypeDescriptor + Copy, E>(
&self,
buffer: &mut [T],
extents: E,
) -> Result<()>
pub fn get_values_into<T: NcTypeDescriptor + Copy, 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, extents: E) -> Result<Vec<u8>>
pub fn get_raw_values<E>(&self, extents: E) -> Result<Vec<u8>>
Fetches variable and returns the bytes. It is up to the caller to decide what to do with these bytes, including interpretation and freeing memory if this is a vlen/string type
Sourcepub fn get_raw_values_into<E>(
&self,
buffer: &mut [u8],
extents: E,
) -> Result<()>
pub fn get_raw_values_into<E>( &self, buffer: &mut [u8], extents: E, ) -> Result<()>
Fetches variable into provided buffer. This functions returns bytes and it is up to the caller to decide what to do with it, including freeing memory if this is a vlen/string type