Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: support exactextract as a method in zonal_stats #68

Merged
merged 18 commits into from
Jul 2, 2024
Prev Previous commit
Next Next commit
fix errors
masawdah committed Jun 25, 2024
commit 222be565dc9c4430abf66ee6c48bd9eed603b9c7
28 changes: 13 additions & 15 deletions xvec/zonal.py
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ def _zonal_stats_exactextract(

# Get the original information to use for unstacking the resulte later
coords_info = {name: geometry}
original_shape = [geometry.size]
original_shape = [len(geometry)]
for dim in arr_dims:
original_shape.append(acc._obj[dim].size)
coords_info[dim] = acc._obj[dim].values
@@ -344,20 +344,18 @@ def _zonal_stats_exactextract(
)

# Unstack the results
agg = {}
i = 0
for stat in stats:
df = results.iloc[:, i : i + locs]

# Unstack the result
arr = df.values.reshape(original_shape)
result = xr.DataArray(
arr, coords=coords_info, dims=coords_info.keys()
).xvec.set_geom_indexes(name, crs=crs)

agg[stat] = result

i += locs
if pd.api.types.is_list_like(stats):
agg = {}
i = 0
for stat in stats:
df = results.iloc[:, i : i + locs]
# Unstack the result
arr = df.values.reshape(original_shape)
result = xr.DataArray(
arr, coords=coords_info, dims=coords_info.keys()
).xvec.set_geom_indexes(name, crs=crs)
agg[stat] = result
i += locs

vec_cube = xr.concat(
agg.values(),