Skip to content

Commit 87e4f85

Browse files
authored
v0.0.10
v0.0.10
2 parents 467b0e4 + 8502796 commit 87e4f85

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

CHANGELOG.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8-
## [0.0.10] - Unreleased
8+
## [0.0.10] - 2024-03-05
99

10+
### Added
11+
12+
- `ed.whittaker` adapted from pywapor github.
13+
- `ed.zonal_stats` using new `geocube` zonal_stats engine.
14+
15+
### Changed
16+
17+
- `zonal_stats` now uses `geocube` as default processing method.
18+
19+
### Removed
20+
21+
- `ed.plot_index` deprecated, use `ed.plot_band` instead.
1022

1123
## [0.0.9] - 2024-02-29
1224

@@ -19,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1931

2032
### Added
2133

22-
- better management of `col_wrap` in `ed` xarray accessor.
34+
- better management of `col_wrap` in `ed` xarray accessor.
2335

2436
### Fixed
2537

earthdaily/accessor/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,9 @@ def whittaker(
334334
max_value=max_value,
335335
max_iter=max_iter,
336336
)
337+
338+
def zonal_stats(self, geometry, operations: list = ["mean"]):
339+
from ..earthdatastore.cube_utils import zonal_stats, GeometryManager
340+
341+
geometry = GeometryManager(geometry).to_geopandas()
342+
return zonal_stats(self._obj, geometry, operations=operations)

earthdaily/earthdatastore/cube_utils/_zonal.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,24 @@ def zonal_stats(
107107
gdf,
108108
operations=["mean"],
109109
all_touched=False,
110-
method="optimized",
110+
method="geocube",
111111
verbose=False,
112112
):
113+
if method == "geocube":
114+
from geocube.api.core import make_geocube
115+
116+
gdf["feature"] = list(gdf.index)
117+
out_grid = make_geocube(
118+
gdf,
119+
measurements=["feature"],
120+
like=dataset, # ensure the data are on the same grid
121+
)
122+
cube = dataset.groupby(out_grid.feature)
123+
zonal_stats = xr.concat(
124+
[getattr(cube, operation)() for operation in operations], dim="stats"
125+
)
126+
zonal_stats["stats"] = operations
127+
return zonal_stats
113128
tqdm_bar = tqdm.tqdm(total=gdf.shape[0])
114129

115130
if dataset.rio.crs != gdf.crs:

examples/field_evolution.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@
5555
# Compute zonal stats for the pivot
5656
# ----------------------------------------------------
5757

58-
zonal_stats = earthdatastore.cube_utils.zonal_stats(
59-
pivot_cube, pivot, operations=["mean", "max", "min"],
60-
method="standard"
61-
)
62-
zonal_stats = zonal_stats.load()
58+
zonal_stats = pivot_cube.ed.zonal_stats(pivot, ['mean','max','min'])
6359

6460
zonal_stats.isel(feature=0).to_array(dim="band").plot.line(
6561
x="time", col="band", hue="stats"

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"dask",
3838
"spyndex",
3939
"dask-image",
40-
"numba"
40+
"numba",
41+
"geocube"
4142
],
4243
include_package_data=True,
4344
package_data={"":['*.geojson','*.json']},

0 commit comments

Comments
 (0)