Skip to content

Documents · Verb reference

to_netcdf

Factory for a pipeable .to_netcdf side-effect operation.

Callable type: Grammar verb / pipe stage · Browse: Output and side effects

Usage

from cubedynamics import verbs as v
v.to_netcdf(path, **to_netcdf_kwargs)

Arguments

Argument Meaning Default
path See implementation docstring below; no parameter-specific description supplied. required
to_netcdf_kwargs See implementation docstring below; no parameter-specific description supplied. forwarded arguments

Accepts

Consult the input parameters and implementation notes below. This namespace also includes direct helpers, not only pipe factories.

Returns

The public docstring does not specify a return contract. Do not assume a pipe-ready return; consult the linked implementation.

Order / grammar behavior

A pipe passes the preceding result to the next callable. Confirm that the previous step's dimensions and semantic state satisfy the input contract. Reductions can remove dimensions; plotting may produce side effects.

Minimal example

Run from the repository root after python -m pip install -e '.[vignettes]'. Uses the checked observational PRISM fixture; no network is required.

from pathlib import Path
import xarray as xr
import matplotlib.pyplot as plt
from cubedynamics import pipe, verbs as v

# Frozen, reviewed PRISM observations; run from the repository root.
path = Path("tests/fixtures/real_data/prism_boulder_january_2024.nc")
with xr.open_dataset(path, engine="scipy") as observed:
    cube = observed["tmax"].load()
assert cube.attrs["units"] == "degC"

from tempfile import TemporaryDirectory
# Export is an explicit side effect. Use a temporary path for this demonstration.
with TemporaryDirectory() as directory:
    target = Path(directory) / "observed_mean.nc"
    result = (pipe(cube) | v.mean(dim="time", keep_dim=False) | v.to_netcdf(str(target), engine="scipy")).unwrap()
    with xr.open_dataarray(target) as restored:
        xr.testing.assert_allclose(result, restored)
        restored.plot()
        plt.show()

Works with

Use only the input types documented by this callable; not every helper accepts every noun or VirtualCube.

See also

Implementation notes

No additional implementation notes in the current docstring.

Implementation source. Signatures and descriptions on this page are generated from this checkout, not hand-maintained copies.