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

Compatibility with rasterio 1.4.0 #85

Open
martinfleis opened this issue Sep 30, 2024 · 3 comments
Open

Compatibility with rasterio 1.4.0 #85

martinfleis opened this issue Sep 30, 2024 · 3 comments

Comments

@martinfleis
Copy link
Member

Some dtype changes in rasterio 1.4.0 broke zonal stats in certain occasions - see https://github.com/martinfleis/sds/actions/runs/11103109876/job/30844359444

Zeitsperre added a commit to hydrologie/xhydro that referenced this issue Oct 7, 2024
Temporary fix until  xarray-contrib/xvec#85 is resolved

### What kind of change does this PR introduce?

- pinned rasterio <=1.3.11
@coolzhao
Copy link

Hi @martinfleis, I encountered the same problem when doing zonal statistics for a binary DataArray. I found the problem is already solved in the source code by specifying the dtype as float32 since the rasterize function tries to fill np.nan for all areas not covered by input geometries.

I suggest that instead of forcing a float32 dtype, it's better to check the input raster data type first. If the input data type is float64 or float32, the output should use the original data type. If integer, then the output can use float32.

Also, I think it's better to set fill and dtype as two input parameters for the _zonal_stats_rasterize function so that the user can be aware of that and may change it as needed for memory efficiency. Cheers.

@martinfleis
Copy link
Member Author

@coolzhao Could you turn these suggestions in a PR? I am aware this is suboptimal.

@coolzhao
Copy link

@martinfleis Yes, I would be happy to help on this and will try to do a PR later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants