Skip to content

Documents · Verb reference

binary_state

Normalize an existing boolean mask into a state cube.

Callable type: Grammar verb / pipe stage · Browse: State and events

Usage

from cubedynamics import verbs as v
v.binary_state(*, variable=None, name=None)

Arguments

Argument Meaning Default
variable See implementation docstring below; no parameter-specific description supplied. None
name See implementation docstring below; no parameter-specific description supplied. None

Accepts

Boolean cube -> Dataset with state, magnitude, and threshold.

Returns

Boolean cube -> Dataset with state, magnitude, and threshold.

Order / grammar behavior

Boolean cube -> Dataset with state, magnitude, and threshold.

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 < 0) | v.binary_state()).unwrap()
result.state.mean("time").plot()
plt.show()

Works with

Boolean cube -> Dataset with state, magnitude, and threshold.

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.