@@ -4,7 +4,7 @@ CubeDynamics is a streaming-first climate cube math library with ggplot-style pi
44
55## Features
66
7- - ** Streaming PRISM/gridMET/Sentinel-2 helpers** (` cd.load_prism_cube ` , ` cd.load_gridmet_cube ` , ` cd.load_s2_ndvi_cube ` ) for immediate analysis without bulk downloads.
7+ - ** Streaming PRISM/gridMET/Sentinel-2 helpers** (` cd.load_prism_cube ` , ` cd.load_gridmet_cube ` , ` cd.load_s2_ndvi_cube ` , ` cd.load_sentinel2_ndvi_cube ` ) for immediate analysis without bulk downloads.
88- ** Climate variance, correlation, trend, and synchrony cubes** that run on ` xarray ` objects and scale from laptops to clusters.
99- ** Pipe + verb system** – build readable cube workflows with ` pipe(cube) | v.month_filter(...) | v.variance(...) ` syntax inspired by ggplot/dplyr.
1010- ** Verbs namespace (` cubedynamics.verbs ` )** so transforms, stats, IO, and visualization live in focused modules.
@@ -95,10 +95,33 @@ pipe(cube) | v.month_filter([6, 7, 8]) | v.variance(dim="time")
9595### Sentinel-2 → NDVI Anomaly (z-score) Cube
9696
9797CubeDynamics works on remote-sensing image stacks in addition to climate
98- archives. A typical Sentinel-2 workflow is:
98+ archives. The convenience helper ` cd.load_sentinel2_ndvi_cube ` streams
99+ Sentinel-2 Level-2A chips via [ ` cubo ` ] ( https://github.com/carbonplan/cubo ) ,
100+ computes NDVI from B08 (NIR) and B04 (red), and standardizes the result across
101+ time. Install ` cubo ` alongside CubeDynamics to use the helper:
99102
100- 1 . Stream Level-2A chips with [ ` cubo ` ] ( https://github.com/carbonplan/cubo )
101- using bands B04 (red) and B08 (NIR).
103+ ``` python
104+ import cubedynamics as cd
105+ from cubedynamics import pipe, verbs as v
106+
107+ ndvi_z = cd.load_sentinel2_ndvi_cube(
108+ lat = 40.0 ,
109+ lon = - 105.25 ,
110+ start = " 2018-01-01" ,
111+ end = " 2020-12-31" ,
112+ )
113+
114+ pipe(ndvi_z) | v.show_cube_lexcube(title = " Sentinel-2 NDVI z-score" )
115+ ```
116+
117+ ` load_sentinel2_ndvi_cube ` returns a ` (time, y, x) ` NDVI z-score cube ready for
118+ the rest of the verbs API. Pass `` return_raw=True `` to also receive the raw
119+ Sentinel-2 reflectance stack and intermediate NDVI cube.
120+
121+ If you prefer to customize every step, the helper simply wraps the manual
122+ pipeline below:
123+
124+ 1 . Stream Level-2A chips with ` cubo ` using bands B04 (red) and B08 (NIR).
1021252 . Convert the reflectance cube to NDVI with ` v.ndvi_from_s2(...) ` .
1031263 . Standardize NDVI over time with ` v.zscore(dim="time") ` to highlight
104127 greenness anomalies.
@@ -119,7 +142,6 @@ LON = -102.18
119142START = " 2023-06-01"
120143END = " 2024-09-30"
121144
122- # 1. Stream Sentinel-2 reflectance without local downloads
123145with warnings.catch_warnings():
124146 warnings.simplefilter(" ignore" )
125147 s2 = cubo.create(
@@ -134,19 +156,16 @@ with warnings.catch_warnings():
134156 query = {" eo:cloud_cover" : {" lt" : 40 }},
135157 )
136158
137- # 2. Pipe reflectance -> NDVI -> z-scores
138159ndvi_z = (
139160 pipe(s2)
140161 | v.ndvi_from_s2(nir_band = " B08" , red_band = " B04" )
141162 | v.zscore(dim = " time" )
142163).unwrap()
143164
144- # 3. Optional: visualize and QA in notebooks
145165(pipe(ndvi_z) | v.show_cube_lexcube(title = " Sentinel-2 NDVI z-score" , clim = (- 3 , 3 )))
146166median_series = ndvi_z.median(dim = (" y" , " x" ))
147167median_series.plot.line(x = " time" , ylabel = " Median NDVI z-score" )
148168
149- # 4. Optional: correlate with a PRISM anomaly cube at each pixel
150169corr_cube = (
151170 pipe(ndvi_z)
152171 | v.correlation_cube(prism_anom_cube, dim = " time" )
@@ -189,7 +208,7 @@ Lexcube widgets require a live Python environment (Jupyter, Colab, Binder). They
189208
190209- ` pipe ` for wrapping any cube before piping.
191210- ` verbs ` (`` from cubedynamics import verbs as v `` ) exposes transforms, statistics, IO, and visualization helpers.
192- - Streaming helpers: ` cd.load_prism_cube ` , ` cd.load_gridmet_cube ` , ` cd.load_s2_cube ` , ` cd.load_s2_ndvi_cube ` .
211+ - Streaming helpers: ` cd.load_prism_cube ` , ` cd.load_gridmet_cube ` , ` cd.load_s2_cube ` , ` cd.load_s2_ndvi_cube ` , ` cd.load_sentinel2_ndvi_cube ` .
193212- Vegetation helper: ` v.ndvi_from_s2 ` for direct NDVI calculation on Sentinel-2 cubes.
194213- Stats verbs: ` v.anomaly ` , ` v.month_filter ` , ` v.variance ` , ` v.zscore ` , ` v.correlation_cube ` , and more under ` cubedynamics.ops.* ` .
195214- IO verbs: ` v.to_netcdf ` , ` v.to_zarr ` , etc.
0 commit comments