Skip to main content

Module netcdf

Module netcdf 

Source
Expand description

netCDF classic files: the classic (CDF\x01) and 64-bit offset (CDF\x02) formats, read from bytes.

Source. Unidata, NetCDF File Format Specifications, “The Classic Format” and “The 64-bit Offset Format” (netCDF-C documentation, captured 2026-09-26), whose grammar this reader follows: a header of dimensions, global attributes and variables, then each non-record variable’s values contiguously at its begin offset, then the records, each holding one slab of every record variable. Every number is big-endian; names and short values pad to four bytes. The two formats differ only in the width of begin, 32 or 64 bits.

Packed data. Variable::packing reads the attribute conventions of the netCDF Users Guide and CF Conventions 1.11 §8.1 (“Packed Data”) and §2.5.1 (“Missing data, valid and actual range of data”): a stored value p means p · scale_factor + add_offset, and is missing if it equals _FillValue or missing_value or lies outside valid_min, valid_max or valid_range. With no valid bound given, the fill bounds the valid range on its own side, as the Users Guide says: the valid range ends one step (integers) or two units in the last place (floats) short of the fill, toward zero, so with a fill of −32767 a stored −32768 is missing too. A byte variable with no _FillValue has no fill. netCDF4-python 1.7.4 masks only values equal to the fill, and masks the byte default; the tests pin each value where the two differ.

Not read. netCDF-4 files are HDF5 underneath (they begin \x89HDF) and the CDF-5 format (CDF\x05) is not in the cited specification; both are refused with the conversion that makes them readable (CONVERSION). A file whose record count was never written (numrecs “streaming”) is refused, as the specification leaves it unimplemented.

Structs§

Attribute
A named attribute of the file or of a variable.
Dimension
A dimension.
NetCdf
A netCDF classic or 64-bit offset file, read whole.
Packing
How a variable’s stored values map to physical ones: Variable::packing. Every bound is in the stored (packed) values’ domain, as the netCDF Users Guide’s attribute conventions ask.
Variable
A variable, with all its values read.

Enums§

Format
Which of the two classic formats a file is written in.
NetCdfError
Why a netCDF file could not be read.
Type
A netCDF external type.
Values
A block of values of one type, in row-major order.

Constants§

CONVERSION
How to rewrite a netCDF-4 or CDF-5 file as a 64-bit offset file, which this reader reads: with Python’s xarray, dropping any variable the classic formats cannot hold (64-bit integers other than times, strings). ERA5 files from the Climate Data Store carry two, number and expver.