Struct VariableMut

Source
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<'_>

Source

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

Source

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<'_>

Source

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<'_>

Source

pub fn put_values<T: NcTypeDescriptor, E>( &mut self, values: &[T], extents: E, ) -> Result<()>
where E: TryInto<Extents>, E::Error: Into<Error>,

Put a slice of values at indices

Source

pub fn put_value<T: NcTypeDescriptor, E>( &mut self, value: T, extents: E, ) -> Result<()>
where E: TryInto<Extents>, E::Error: Into<Error>,

Put a value at the specified indices

Source

pub fn put_string<E>(&mut self, value: &str, extents: E) -> Result<()>
where E: TryInto<Extents>, E::Error: Into<Error>,

Put a string at the specified indices

Source

pub fn set_fill_value<T>(&mut self, fill_value: T) -> Result<()>

Set a Fill Value

§Errors

Not a netCDF-4 file, late define, fill_value has the wrong type

Source

pub unsafe fn set_nofill(&mut self) -> Result<()>

Set the fill value to no value. Use this when wanting to avoid duplicate writes into empty variables.

§Errors

Not a netCDF-4 file

§Safety

Reading from this variable after having defined nofill will read potentially uninitialized data. Normally one will expect to find some filler value

Source

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

Source

pub fn put<T: NcTypeDescriptor, E, D>( &mut self, arr: ArrayView<'_, T, D>, extent: E, ) -> Result<()>
where E: TryInto<Extents>, E::Error: Into<Error>, D: Dimension,

Available on crate feature ndarray only.

Put values in an ndarray into the variable

Methods from Deref<Target = 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) -> NcVariableType

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

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.

Source

pub fn get_values<T: NcTypeDescriptor + Copy, 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_value<T: NcTypeDescriptor + Copy, E>(&self, extents: E) -> Result<T>
where E: TryInto<Extents>, E::Error: Into<Error>,

Get a single value

Source

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

Get a string from this variable

Source

pub fn get<T: NcTypeDescriptor + Copy, 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: NcTypeDescriptor + Copy, E, D>( &self, out: ArrayViewMut<'_, T, D>, extents: E, ) -> 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: NcTypeDescriptor + Copy>(&self) -> Result<Option<T>>

Get the fill value of a variable

Source

pub fn get_values_into<T: NcTypeDescriptor + Copy, 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, extents: E) -> Result<Vec<u8>>
where E: TryInto<Extents>, E::Error: Into<Error>,

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

Source

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

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

Trait Implementations§

Source§

impl<'g> Debug for VariableMut<'g>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'g> Deref for VariableMut<'g>

Source§

type Target = Variable<'g>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'g> Freeze for VariableMut<'g>

§

impl<'g> RefUnwindSafe for VariableMut<'g>

§

impl<'g> Send for VariableMut<'g>

§

impl<'g> Sync for VariableMut<'g>

§

impl<'g> Unpin for VariableMut<'g>

§

impl<'g> !UnwindSafe for VariableMut<'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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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>,

Source§

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.