Skip to content

Documents · Verb reference

month_filter

Keep the requested calendar months on a datetime-like time coordinate.

Callable type: Grammar verb / pipe stage · Browse: Transform

Usage

from cubedynamics import verbs as v
v.month_filter(months)

Arguments

Argument Meaning Default
months Calendar months to retain (1-12). Empty selections return an empty time axis. The iterable is captured once so the stage is reusable. required

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.month_filter([1])).unwrap()
result.mean("time").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

Implementation notes

Preserves the historical integer coercion and selection behavior. This is the supported implementation; the old ops import forwards here.

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