NetCDF — public API#
A one-line map of every public member the NetCDF class itself defines — 135 in all: 99 methods, 27 properties,
8 classmethods and 1 staticmethod, plus the four mapping dunders (__getitem__, __contains__, __iter__,
__len__). concat and merge are counted among the methods: each is callable on the class
(NetCDF.concat([a, b], dim)) and on a cube (a.concat([b], dim), which joins the
receiver first). For the full signatures, arguments and examples, see the rendered
NetCDF Class reference; this page is the index you scan to find the member you want.
NetCDF extends Dataset, so it also inherits a further 144 public members it does not redefine — band
handling, the COG surface, the missing-data members (where, fillna, isnull, notnull, equals,
identical), the cell-wise members (clip, round, astype, isin) and the rest of the raster API.
131 of those are declared in Dataset's own body and the
remaining 13 come from RasterBase above it. They live in the
Dataset reference — the missing-data six under
Missing data and comparison and the four cell-wise
members under Cell-wise transforms.
Two object shapes share this class, and several members behave differently across them:
- a Container — what
read_file/from_bytes/from_arrayreturn;band_count == 0; describes the file. - a Variable — what
get_variable/variables[name]/sel/subsetreturn;band_count >= 1; behaves as a single raster.
Opening, construction and lifetime#
| Member | What it does |
|---|---|
read_file() |
Opens a .nc from a path, URL, or archive member; returns a Container. |
from_bytes() |
Opens a NetCDF held in memory as a byte string. |
from_array() |
Builds a Container from a NumPy array plus a geo-reference. |
from_dataframe() |
Rebuilds a Container from a MultiIndex DataFrame — the inverse of to_dataframe. |
from_dict() |
Rebuilds a Container from a nested dict — the inverse of to_dict. |
from_xarray() |
Builds a NetCDF from an xarray.Dataset (needs the optional xarray peer dep). |
copy() |
Deep, standalone copy of this dataset, optionally written to path. |
close() |
Releases every GDAL handle this container holds, then closes the base. |
Variables, dimensions and groups#
| Member | What it does |
|---|---|
variable_names |
Names of the data variables, excluding dimension coordinate arrays. |
variables |
Lazy {name: subset} mapping of every data variable. |
get_variable() |
Extracts one variable as a classic-raster NetCDF (a Variable). |
get_variable_names() |
Deprecated alias for the variable_names property. |
nc[name] |
The variable called name; KeyError where get_variable gives ValueError. |
name in nc |
Whether name is one of the data variables. |
iter(nc) / len(nc) |
The data-variable names, and how many there are. |
get() |
The variable, or a default when the container has no such name. |
keys() |
The data-variable names, as a fresh list. |
values() |
Every variable, loading each. |
items() |
(name, variable) for every variable, loading each. |
dimension_names |
Names of all dimensions, in storage order. |
dimension_sizes |
{name: size} for every dimension, read from the multidimensional group. |
get_dimension_values() |
Stored coordinates of any dimension — level, depth, member, time. |
group_names |
Names of the sub-groups in the root group. |
get_group() |
Opens a netCDF-4 sub-group as its own Container, without copying data. |
is_subset |
Whether this object is a single-variable subset rather than a Container. |
is_md_array |
Whether the dataset was opened in multidimensional mode. |
file_name |
The file path, with any NETCDF:"path":var prefix stripped. |
xarray-compatible spellings#
Aliases so habits from xarray transfer without renaming anything. Each names its canonical member, and each docstring states where it diverges from the xarray member it echoes.
| Member | What it does |
|---|---|
data_vars |
variables under xarray's name — a mapping, so nc.data_vars["t2m"] works. |
dims |
{name: length} — not dimension_names, a list. sizes is the durable spelling. |
sizes |
The same mapping as dims; xarray is turning its own dims into a set of names. |
attrs |
global_attributes under xarray's name. |
coords |
{name: stored coordinate} for every indexed dimension, from get_dimension_values. |
Cheap introspection#
Metadata only: no data variable's array is read, though opening a variable does read its coordinate axes. A variable with no raster plane is the exception — see each member's docstring.
| Member | What it does |
|---|---|
dtypes |
{name: dtype} for every data variable, from the band description. |
nbytes |
Total size of the data variables, computed from shape and dtype rather than read. |
info() |
Prints an ncdump -h-shaped summary to a buffer, or to sys.stdout. |
Coordinates and time#
| Member | What it does |
|---|---|
lon / x |
Longitude / x coordinate values as a 1-D array. |
lat / y |
Latitude / y coordinate values as a 1-D array. |
top_left_corner |
Coordinates of the raster's top-left corner. |
geotransform |
Geotransform derived from the coordinate arrays, then cached. |
epsg |
EPSG code, resolved from the variables when asked of a Container. |
time_stamp |
Time coordinate values parsed from the CF time variable. |
get_time_variable() |
Decodes the time axis to date strings; time_format sets the precision. |
get_time_values() |
Raw, undecoded values of the time axis — get_dimension_values() for it. |
create_main_dimension() |
Creates a dimension with its indexing variable (static helper). |
convert_calendar() |
Restamps the time axis onto another CF calendar. |
interp_calendar() |
Interpolates onto another cube's calendar stamps. |
Reading and selecting#
| Member | What it does |
|---|---|
read_array() |
Reads eagerly, or lazily into dask with chunks=. Needs variable= on a Container. |
chunk() |
A lazy, dask-backed LazyNetCDF view of the cube — compute/chunks/persist. |
subset() |
Reads a windowed (variable, time, bbox) slice without materialising the cube. |
sel() |
Selects bands by coordinate value, date label, or method="nearest". |
isel() |
Selects bands by position along one or more band dims; works without coordinates. |
drop_sel() |
Drops bands by coordinate value — the complement of sel; errors. |
drop_isel() |
Drops bands by position — the complement of isel. |
head() |
Keeps the first n steps along a band dim; five along every one by default. |
tail() |
Keeps the last n steps along a band dim; five along every one by default. |
thin() |
Keeps every n-th step along a band dim, from the first. |
sortby() |
Reorders a band dim by its own coordinates, each plane with its stamp — ascending. |
drop_duplicates() |
Drops the steps whose stamp repeats — what concat can leave — keep. |
squeeze() |
Drops the band dims of length one; never a spatial axis. |
expand_dims() |
Adds a length-one band dim, outermost — lifts a raster into a cube before concat. |
open_mfdataset() |
Stacks one variable across many files into a single lazy dask array. |
reduce() |
Reduces a container or a variable along dim — how, q, groupby, skipna. |
coarsen() |
Reduces fixed-size windows along dim — window, boundary, how. |
groupby_bins() |
Reduces dim binned into value intervals — bins, right, include_lowest, how. |
rolling() |
Reduces a moving window along dim, keeping its length — center, min_periods. |
rolling_exp() |
Exponentially-weighted moving reduction along dim — alpha, how. |
diff() |
Differences neighbouring steps along dim — n, label. |
interp() |
Interpolates band dim(s) onto new coordinate values — method, **coords. |
interp_like() |
Interpolates shared band dims onto another cube's coordinates — other, method. |
rank() |
Ranks each pixel's values along band dim, ties averaged — pct. |
pad() |
Pads band or spatial dims with a constant fill — mode, constant_values. |
transpose() |
Reorders band dims (spatial plane stays trailing) — *dims. |
cumsum() |
Totals the values along dim, step by step — skipna. |
cumprod() |
Multiplies the values along dim, step by step — skipna. |
cumulative() |
Accessor form of the two above — .sum() / .prod(). |
differentiate() |
Derivative along dim, by its coordinate spacing. |
integrate() |
Trapezoidal integral along dim, which it consumes. |
cumulative_integrate() |
Running trapezoidal integral along dim. |
polyfit() |
Per-cell least-squares coefficients along dim. |
curvefit() |
Per-cell least-squares fit of an arbitrary model along dim — p0/bounds/full. |
shift() |
Moves the values along dim, filling the vacated steps — periods, fill_value. |
ffill() |
Carries the last valid value along dim into the gaps after it — limit. |
bfill() |
Carries the next valid value along dim back into the gaps before it — limit. |
dropna() |
Removes the steps of dim whose cells are missing — how, thresh. |
interpolate_na() |
Fills the interior gaps along dim from both sides — method, limit. |
to_dataframe() |
The cube as a pandas frame, indexed by its dimensions — variables, dropna. |
to_dict() |
The cube's whole structure as a nested dict — xarray's schema plus georeference. |
to_dask_dataframe() |
The lazy sibling of to_dataframe — a tidy dask.dataframe, read lazily. |
concat() |
Joins cubes end to end along dim (classmethod). |
merge() |
Puts several cubes' variables on one grid (classmethod) — compat. |
argmin() |
The position along dim of the smallest value; -1 where there is none. |
argmax() |
The position along dim of the largest value; -1 where there is none. |
idxmin() |
The coordinate along dim of the smallest value; NaN where there is none. |
idxmax() |
The coordinate along dim of the largest value; NaN where there is none. |
weighted() |
Weighted statistics over the spatial axes or a band dim — "area", how. |
rename_dims() |
Renames band dims — {old: new} / old=new; never a spatial axis. |
assign_coords() |
Restamps an existing band dim's coordinates — dim=values. |
drop_dims() |
Drops band dims and the variables along them (container) — errors. |
broadcast_like() |
Takes another cube's band layout, repeating cells along the added axes. |
broadcast_equals() |
Whether two cubes agree once broadcast against each other. |
set_coords() |
Marks variables as CF auxiliary coordinates (container); leaves data_vars. |
reset_coords() |
Demotes auxiliary coordinates back to data variables (container). |
Spatial operations#
| Member | What it does |
|---|---|
crop() |
Crops by polygon mask, raster mask, or bbox tuple. chunks= is Variable only. |
to_crs() |
Reprojects the dataset to another CRS. |
resample() |
Resamples to a different cell size. |
warped_view() |
A lazy, reprojected view of a Variable — no data is read until used. Variable only. |
Editing variables in place#
| Member | What it does |
|---|---|
set_variable() |
Writes a classic Dataset back into this container as an MDArray variable. |
add_variable() |
Copies MDArray variables in from another NetCDF. |
remove_variable() |
Deletes a variable from this container. |
rename_variable() |
Renames a variable in this container. |
update() |
Adds or replaces this container's variables from another cube, in place. |
crop_variable() |
Crops one variable and stores the result back. |
reproject_variable() |
Reprojects one variable and stores the result back. |
resample_variable() |
Resamples one variable and stores the result back. |
Metadata and attributes#
| Member | What it does |
|---|---|
meta_data |
Structured metadata for this NetCDF (cached). |
get_all_metadata() |
The same, re-traversed from GDAL rather than served from cache. |
global_attributes |
Global attributes on the root group. |
set_global_attribute() |
Sets one global attribute on the root group. |
delete_global_attribute() |
Deletes one global attribute from the root group. |
scale |
Per-band CF scale_factor a read applies, per band. |
offset |
Per-band CF add_offset a read applies, per band. |
Writing and interop#
| Member | What it does |
|---|---|
to_file() |
Saves the dataset to disk. |
to_xarray() |
Converts the container to an xarray.Dataset — chunks=, decode_times=. |
to_kerchunk() |
Emits a kerchunk JSON reference manifest for this file. |
combine_kerchunk() |
Combines per-file manifests into one cube index. |
to_cog() |
Writes a Cloud-Optimized GeoTIFF. Variable only. |
to_geodataframe() |
Converts the raster to a GeoDataFrame, one row per cell. Variable only. |
write_array() |
Writes an array into the raster bands. Variable only. |
Analysis and plotting#
| Member | What it does |
|---|---|
combine() |
Combines two rasters cell by cell, keeping the band dimensions. Variable only. |
plot() |
Plots a 2-D slice — selectors, facet, axes, animate, chunks, colour. |
stats() |
Per-band summary statistics. Variable only. |
summary() |
Per-variable summary table over the whole cube — works on a container too. |
slope() |
Slope raster from an elevation variable. Variable only. |
hillshade() |
Hillshade raster from an elevation variable. Variable only. |
zonal_stats() |
Statistics per zone of a mask or feature set. Variable only. |
sample() |
Samples values at points. Variable only. |
"Variable only" marks the members that are container-guarded: they are Dataset operations that need a
single raster, so calling them on a Container raises with a message pointing at get_variable. Two members
are restricted only in part, noted in their own rows: read_array() needs variable= on a Container, and
crop() accepts chunks= only on a Variable.