Skip to main content

NcFile

Struct NcFile 

Source
pub struct NcFile { /* private fields */ }
Expand description

An opened NetCDF file.

Implementations§

Source§

impl NcFile

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open a NetCDF file from a path.

The format is auto-detected from the file’s magic bytes.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self>

Open a NetCDF file from in-memory bytes.

The format is auto-detected from the magic bytes.

Source

pub fn from_bytes_with_options( data: &[u8], options: NcOpenOptions, ) -> Result<Self>

Open a NetCDF file from in-memory bytes with custom options.

NC4 options are applied when the payload is HDF5-backed.

Source

pub fn format(&self) -> NcFormat

The detected file format.

Source

pub fn root_group(&self) -> &NcGroup

The root group of the file.

Classic files have a single implicit root group containing all dimensions, variables, and global attributes. NetCDF-4 files can have nested sub-groups.

Source

pub fn dimensions(&self) -> &[NcDimension]

Convenience: dimensions in the root group.

Source

pub fn variables(&self) -> &[NcVariable]

Convenience: variables in the root group.

Source

pub fn global_attributes(&self) -> &[NcAttribute]

Convenience: global attributes (attributes of the root group).

Source

pub fn group(&self, path: &str) -> Result<&NcGroup>

Find a group by path relative to the root group.

Source

pub fn variable(&self, name: &str) -> Result<&NcVariable>

Find a variable by name or path relative to the root group.

Source

pub fn dimension(&self, name: &str) -> Result<&NcDimension>

Find a dimension by name or path relative to the root group.

Source

pub fn global_attribute(&self, name: &str) -> Result<&NcAttribute>

Find a group attribute by name or path relative to the root group.

Source

pub fn read_variable<T: NcReadable>(&self, name: &str) -> Result<ArrayD<T>>

Read a variable’s data as a typed array.

Works for both classic (CDF-1/2/5) and NetCDF-4 files. NetCDF-4 nested variables can be addressed with paths like group/subgroup/var. The type parameter T must implement NcReadable, which is satisfied by: i8, u8, i16, u16, i32, u32, i64, u64, f32, f64.

Source

pub fn read_variable_parallel<T: NcReadable>( &self, name: &str, ) -> Result<ArrayD<T>>

Read a variable using internal chunk-level parallelism when available.

Classic formats fall back to read_variable.

Source

pub fn read_variable_in_pool<T: NcReadable>( &self, name: &str, pool: &ThreadPool, ) -> Result<ArrayD<T>>

Read a variable using the provided Rayon thread pool when available.

Classic formats fall back to read_variable.

Source

pub fn as_classic(&self) -> Option<&ClassicFile>

Access the underlying classic file (for reading data).

Returns None if this is a NetCDF-4 file.

Source

pub fn read_variable_as_f64(&self, name: &str) -> Result<ArrayD<f64>>

Read a variable with automatic type promotion to f64.

Reads in the native storage type (i8, i16, i32, f32, f64, u8, etc.) and promotes all values to f64. This avoids the TypeMismatch error that read_variable::<f64> produces for non-f64 variables.

Source

pub fn read_variable_as_string(&self, name: &str) -> Result<String>

Read a string variable as a single string.

Use NcFile::read_variable_as_strings when the variable contains multiple string elements.

Source

pub fn read_variable_as_strings(&self, name: &str) -> Result<Vec<String>>

Read a string or char variable as a flat vector of strings.

Classic char arrays interpret the last dimension as the string length and flatten the leading dimensions.

Source

pub fn read_variable_unpacked(&self, name: &str) -> Result<ArrayD<f64>>

Read a variable and apply scale_factor/add_offset unpacking.

Returns actual = stored * scale_factor + add_offset. If neither attribute is present, returns the raw data as f64. Uses type-promoting read so it works with any numeric storage type.

Source

pub fn read_variable_masked(&self, name: &str) -> Result<ArrayD<f64>>

Read a variable, replace _FillValue/missing_value with NaN, and mask values outside valid_min/valid_max/valid_range. Uses type-promoting read so it works with any numeric storage type.

Source

pub fn read_variable_unpacked_masked(&self, name: &str) -> Result<ArrayD<f64>>

Read a variable with both masking and unpacking (CF spec order).

Order: read → mask fill/missing → unpack (scale+offset). Uses type-promoting read so it works with any numeric storage type.

Source

pub fn read_variable_slice<T: NcReadable>( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<T>>

Read a slice (hyperslab) of a variable as a typed array.

Source

pub fn read_variable_slice_parallel<T: NcReadable>( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<T>>

Read a slice (hyperslab) using chunk-level parallelism when available.

For NetCDF-4 chunked datasets, overlapping chunks are decompressed in parallel via Rayon. Classic formats fall back to read_variable_slice.

Source

pub fn read_variable_slice_as_f64( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<f64>>

Read a slice of a variable with automatic type promotion to f64.

Source

pub fn read_variable_slice_unpacked( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<f64>>

Read a slice with scale_factor/add_offset unpacking.

Source

pub fn read_variable_slice_masked( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<f64>>

Read a slice with fill/missing value masking.

Source

pub fn read_variable_slice_unpacked_masked( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<f64>>

Read a slice with both masking and unpacking (CF spec order).

Source

pub fn iter_slices<T: NcReadable>( &self, name: &str, dim: usize, ) -> Result<NcSliceIterator<'_, T>>

Create an iterator that yields one slice per index along a given dimension.

Each call to next() reads one slice using the slice API. This is useful for iterating time steps, levels, etc. without loading the entire dataset into memory.

Source§

impl NcFile

Source

pub fn open_with_options( path: impl AsRef<Path>, options: NcOpenOptions, ) -> Result<Self>

Open a NetCDF file with custom options.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.