pub struct NcFile { /* private fields */ }Expand description
An opened NetCDF file.
Implementations§
Source§impl NcFile
impl NcFile
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
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.
Sourcepub fn root_group(&self) -> &NcGroup
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.
Sourcepub fn dimensions(&self) -> &[NcDimension]
pub fn dimensions(&self) -> &[NcDimension]
Convenience: dimensions in the root group.
Sourcepub fn variables(&self) -> &[NcVariable]
pub fn variables(&self) -> &[NcVariable]
Convenience: variables in the root group.
Sourcepub fn global_attributes(&self) -> &[NcAttribute]
pub fn global_attributes(&self) -> &[NcAttribute]
Convenience: global attributes (attributes of the root group).
Sourcepub fn group(&self, path: &str) -> Result<&NcGroup>
pub fn group(&self, path: &str) -> Result<&NcGroup>
Find a group by path relative to the root group.
Sourcepub fn variable(&self, name: &str) -> Result<&NcVariable>
pub fn variable(&self, name: &str) -> Result<&NcVariable>
Find a variable by name or path relative to the root group.
Sourcepub fn dimension(&self, name: &str) -> Result<&NcDimension>
pub fn dimension(&self, name: &str) -> Result<&NcDimension>
Find a dimension by name or path relative to the root group.
Sourcepub fn global_attribute(&self, name: &str) -> Result<&NcAttribute>
pub fn global_attribute(&self, name: &str) -> Result<&NcAttribute>
Find a group attribute by name or path relative to the root group.
Sourcepub fn read_variable<T: NcReadable>(&self, name: &str) -> Result<ArrayD<T>>
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.
Sourcepub fn read_variable_parallel<T: NcReadable>(
&self,
name: &str,
) -> Result<ArrayD<T>>
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.
Sourcepub fn read_variable_in_pool<T: NcReadable>(
&self,
name: &str,
pool: &ThreadPool,
) -> Result<ArrayD<T>>
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.
Sourcepub fn as_classic(&self) -> Option<&ClassicFile>
pub fn as_classic(&self) -> Option<&ClassicFile>
Access the underlying classic file (for reading data).
Returns None if this is a NetCDF-4 file.
Sourcepub fn read_variable_as_f64(&self, name: &str) -> Result<ArrayD<f64>>
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.
Sourcepub fn read_variable_unpacked(&self, name: &str) -> Result<ArrayD<f64>>
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.
Sourcepub fn read_variable_masked(&self, name: &str) -> Result<ArrayD<f64>>
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.
Sourcepub fn read_variable_unpacked_masked(&self, name: &str) -> Result<ArrayD<f64>>
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.
Sourcepub fn read_variable_slice<T: NcReadable>(
&self,
name: &str,
selection: &NcSliceInfo,
) -> Result<ArrayD<T>>
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.
Sourcepub fn read_variable_slice_parallel<T: NcReadable>(
&self,
name: &str,
selection: &NcSliceInfo,
) -> Result<ArrayD<T>>
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.
Sourcepub fn read_variable_slice_as_f64(
&self,
name: &str,
selection: &NcSliceInfo,
) -> Result<ArrayD<f64>>
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.
Sourcepub fn read_variable_slice_unpacked(
&self,
name: &str,
selection: &NcSliceInfo,
) -> Result<ArrayD<f64>>
pub fn read_variable_slice_unpacked( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<f64>>
Read a slice with scale_factor/add_offset unpacking.
Sourcepub fn read_variable_slice_masked(
&self,
name: &str,
selection: &NcSliceInfo,
) -> Result<ArrayD<f64>>
pub fn read_variable_slice_masked( &self, name: &str, selection: &NcSliceInfo, ) -> Result<ArrayD<f64>>
Read a slice with fill/missing value masking.
Sourcepub fn read_variable_slice_unpacked_masked(
&self,
name: &str,
selection: &NcSliceInfo,
) -> Result<ArrayD<f64>>
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).
Sourcepub fn iter_slices<T: NcReadable>(
&self,
name: &str,
dim: usize,
) -> Result<NcSliceIterator<'_, T>>
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
impl NcFile
Sourcepub fn open_with_options(
path: impl AsRef<Path>,
options: NcOpenOptions,
) -> Result<Self>
pub fn open_with_options( path: impl AsRef<Path>, options: NcOpenOptions, ) -> Result<Self>
Open a NetCDF file with custom options.
Auto Trait Implementations§
impl Freeze for NcFile
impl !RefUnwindSafe for NcFile
impl Send for NcFile
impl Sync for NcFile
impl Unpin for NcFile
impl UnsafeUnpin for NcFile
impl !UnwindSafe for NcFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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