Skip to content

Commit 3900b1c

Browse files
authored
Merge pull request #20 from CU-ESIIL/codex/add-show_cube_lexcube-verb-for-pipe
Add Lexcube pipe verb
2 parents 1d49186 + 026ee1a commit 3900b1c

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/cubedynamics/tests/test_piping_ops.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pandas as pd
77
import xarray as xr
88

9+
import cubedynamics.viz as viz
910
from cubedynamics import pipe, verbs as v
1011

1112

@@ -47,3 +48,21 @@ def test_to_netcdf_roundtrip(tmp_path):
4748
loaded = xr.load_dataarray(path)
4849
xr.testing.assert_identical(da, loaded)
4950
xr.testing.assert_identical(da, result)
51+
52+
53+
def test_show_cube_lexcube_returns_original_cube(monkeypatch):
54+
da = _make_time_series()
55+
captured = {}
56+
57+
def fake_show(cube, **kwargs):
58+
captured["cube"] = cube
59+
captured["kwargs"] = kwargs
60+
return "widget"
61+
62+
monkeypatch.setattr(viz, "show_cube_lexcube", fake_show)
63+
64+
result = (pipe(da) | v.show_cube_lexcube(cmap="Blues")).unwrap()
65+
66+
assert result is da
67+
assert captured["cube"] is da
68+
assert captured["kwargs"] == {"cmap": "Blues"}

src/cubedynamics/verbs/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22

33
from __future__ import annotations
44

5+
from .. import viz
56
from ..ops.io import to_netcdf
67
from ..ops.ndvi import ndvi_from_s2
78
from ..ops.stats import correlation_cube, variance, zscore
89
from ..ops.transforms import anomaly, month_filter
910

11+
12+
def show_cube_lexcube(**kwargs):
13+
"""Pipe verb that renders the current cube via Lexcube widgets."""
14+
15+
def _op(da):
16+
viz.show_cube_lexcube(da, **kwargs)
17+
return da
18+
19+
return _op
20+
21+
1022
__all__ = [
1123
"anomaly",
1224
"month_filter",
@@ -15,4 +27,5 @@
1527
"to_netcdf",
1628
"zscore",
1729
"ndvi_from_s2",
30+
"show_cube_lexcube",
1831
]

src/cubedynamics/viz/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
"""Subpackage for cubedynamics."""
1+
"""Visualization helpers exposed at the package level."""
2+
3+
from __future__ import annotations
4+
5+
from .lexcube_viz import show_cube_lexcube
6+
from .qa_plots import plot_median_over_space
7+
8+
__all__ = ["show_cube_lexcube", "plot_median_over_space"]

0 commit comments

Comments
 (0)