Documents · Verb reference
detect_events
Detect contiguous state runs as events.
Callable type: Grammar verb / pipe stage · Browse: State and events
Usage
from cubedynamics import verbs as v
v.detect_events(*, state_var='state', magnitude_var='magnitude', min_duration=1, max_gap=0)
Arguments
| Argument | Meaning | Default |
|---|---|---|
| state_var | See implementation docstring below; no parameter-specific description supplied. | 'state' |
| magnitude_var | See implementation docstring below; no parameter-specific description supplied. | 'magnitude' |
| min_duration | See implementation docstring below; no parameter-specific description supplied. | 1 |
| max_gap | See implementation docstring below; no parameter-specific description supplied. | 0 |
Accepts
State Dataset -> EventResult containing event cube variables and a catalog.
Returns
State Dataset -> EventResult containing event cube variables and a catalog.
Order / grammar behavior
State Dataset -> EventResult containing event cube variables and a catalog.
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.threshold_state(threshold=0, direction="below") | v.detect_events(min_duration=2)).unwrap()
# Count days belonging to detected events, not just all threshold crossings.
print(result.catalog.head())
result.dataset["event_active"].sum("time").plot(cbar_kwargs={"label": "Days in cold events"})
plt.show()
Works with
State Dataset -> EventResult containing event cube variables and a catalog.
See also
- 06 · From cold observations to event evidence
- Learn: verbs
- Noun library
- Verbs by purpose
- All public callables (A–Z)
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.