Skip to content

Commit a28db91

Browse files
author
nicolasK
committed
fix(zonal_stats id)
1 parent 5ed3ca2 commit a28db91

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ 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.11] - Unreleased
9+
10+
### Fixed
11+
12+
- `zonal_stats` manages index independently from row.
13+
814
## [0.0.10] - 2024-03-05
915

1016
### Added
1117

12-
- `ed.whittaker` adapted from pywapor github.
18+
- `ed.whittaker` adapted from pywapor github.
1319
- `ed.zonal_stats` using new `geocube` zonal_stats engine.
1420

1521
### Changed

earthdaily/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# to hide warnings from rioxarray or nano seconds conversion
66
warnings.filterwarnings("ignore")
77

8-
__version__ = "0.0.10"
8+
__version__ = "0.0.11"

earthdaily/earthdatastore/cube_utils/_zonal.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,20 @@ def zonal_stats(
113113
if method == "geocube":
114114
from geocube.api.core import make_geocube
115115

116-
gdf["feature"] = list(gdf.index)
116+
gdf["index"] = np.arange(gdf.shape[0])
117117
out_grid = make_geocube(
118118
gdf,
119-
measurements=["feature"],
119+
measurements=["index"],
120120
like=dataset, # ensure the data are on the same grid
121121
)
122-
cube = dataset.groupby(out_grid.feature)
122+
cube = dataset.groupby(out_grid.index)
123123
zonal_stats = xr.concat(
124124
[getattr(cube, operation)() for operation in operations], dim="stats"
125125
)
126126
zonal_stats["stats"] = operations
127-
return zonal_stats
127+
zonal_stats["index"] = gdf.index
128+
return zonal_stats.rename(dict(index="feature"))
129+
128130
tqdm_bar = tqdm.tqdm(total=gdf.shape[0])
129131

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

examples/field_evolution.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@
4545
# ----------------------------------------------------
4646
pivot_cube = pivot_cube.load()
4747
pivot_cube.ed.plot_rgb(col_wrap=3)
48-
49-
plt.title("Clear cover percent with SCL")
50-
plt.title("Pivot evolution with SCL masks")
48+
plt.title("Pivot evolution masked with native cloudmasks")
5149
plt.show()
5250

5351

5452
##############################################################################
5553
# Compute zonal stats for the pivot
5654
# ----------------------------------------------------
5755

56+
pivot.index = ['my_pivot']
5857
zonal_stats = pivot_cube.ed.zonal_stats(pivot, ['mean','max','min'])
5958

6059
zonal_stats.isel(feature=0).to_array(dim="band").plot.line(

0 commit comments

Comments
 (0)