Skip to content

Commit a15120d

Browse files
author
nicolasK
committed
fix(zonal_stats)
1 parent 130d7e2 commit a15120d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

earthdaily/earthdatastore/cube_utils/_zonal.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,21 @@ def zonal_stats(
112112
):
113113
if method == "geocube":
114114
from geocube.api.core import make_geocube
115-
116-
gdf["index"] = np.arange(gdf.shape[0])
115+
116+
gdf["tmp_index"] = np.arange(gdf.shape[0])
117117
out_grid = make_geocube(
118118
gdf,
119-
measurements=["index"],
119+
measurements=["tmp_index"],
120120
like=dataset, # ensure the data are on the same grid
121121
)
122-
cube = dataset.groupby(out_grid.index)
122+
cube = dataset.groupby(out_grid.tmp_index)
123123
zonal_stats = xr.concat(
124124
[getattr(cube, operation)() for operation in operations], dim="stats"
125125
)
126126
zonal_stats["stats"] = operations
127-
zonal_stats["index"] = gdf.index
128-
return zonal_stats.rename(dict(index="feature"))
127+
zonal_stats["tmp_index"] = list(gdf.index)
128+
129+
return zonal_stats.rename(dict(tmp_index="feature"))
129130

130131
tqdm_bar = tqdm.tqdm(total=gdf.shape[0])
131132

examples/field_evolution.py

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
# Compute zonal stats for the pivot
5454
# ----------------------------------------------------
5555

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

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

0 commit comments

Comments
 (0)