Documents · Verb reference
mean
Compute the mean along a dimension while keeping cubes pipe-ready.
Callable type: Grammar verb / pipe stage · Browse: Transform
Usage
from cubedynamics import verbs as v
v.mean(dim='time', *, over=None, keep_dim=True, skipna=True)
Arguments
| Argument | Meaning | Default |
|---|---|---|
| dim | Dimension to reduce. | 'time' |
| over | Readable alias for dim. Existing dim= calls remain supported. | None |
| keep_dim | Preserve the reduced dimension with length 1 to keep a (time, y, x) layout when applicable. | True |
| skipna | Whether to ignore NaN values during reduction. | True |
Accepts
An xarray DataArray or Dataset with the dimensions required by the selected operation. VirtualCube support is operation-specific; consult the implementation notes.
Returns
A callable stage. Applying it returns the transformed xarray object (or the supported VirtualCube result).
Order / grammar behavior
Apply before reductions that remove a required dimension. Choose the reduction dimensions explicitly; keep_dim=False removes reduced axes.
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"
result = (pipe(cube) | v.mean(dim="time", keep_dim=False)).unwrap()
result.plot()
plt.show()
Works with
An xarray DataArray or Dataset with the dimensions required by the selected operation. VirtualCube support is operation-specific; consult the implementation notes.
See also
- Working Lands · Read hot-and-dry weather as two nouns
- 03 · Two variables, two questions
- Elevation · read a landscape at its native scale
- 04 · Read the analysis from left to right
- 05 · One cube, six analytical views
- Learn: verbs
- Noun library
- Verbs by purpose
- All public callables (A–Z)
Implementation notes
Streaming VirtualCube inputs are processed tile-by-tile without forcing a
full load. Dask-backed arrays remain lazy. When keep_dim is False the
reduced dimension is dropped.
Implementation source. Signatures and descriptions on this page are generated from this checkout, not hand-maintained copies.