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

set output data type in zonal_stats #76

Closed
benmcdermott opened this issue Aug 19, 2024 · 5 comments · Fixed by #77
Closed

set output data type in zonal_stats #76

benmcdermott opened this issue Aug 19, 2024 · 5 comments · Fixed by #77

Comments

@benmcdermott
Copy link

benmcdermott commented Aug 19, 2024

Hi there, I've been testing zonal_stats on a large raster containing decimal values. zonal_stats wants to allocate a large array with type float64 - which is unnecessary as my input raster is float32. Would it be possible to set this dtype throughout the calculation as to avoid overuse of memory?

@martinfleis
Copy link
Member

Which method for zonal stats are you using? The default?

@benmcdermott
Copy link
Author

Yes the default: raster.xvec.zonal_stats(...)

@martinfleis
Copy link
Member

It has actually nothing to do with the input dtype, that is preserved to the aggregated array. We need to create a rasterised version of geometries and that array is, due to masking of empty areas, being generated as float64. In #77 I am switching to float32, which should help a bit. If the memory is a concern, method="iterate" is significantly less demanding but slower.

@benmcdermott
Copy link
Author

I guess the reason I am testing your package rather than using rasterio or rasterstats is the vectorized method hoping for performance improvement. So would switching to the slower iterate version would be similar to packages I already use?

@martinfleis
Copy link
Member

So would switching to the slower iterate version would be similar to packages I already use?

Performance-wise, the method="iterate" it is likely to be similar to rasterstats, tough I haven't compared that directly.

Try using the dev version of xvec installed from main, that may solve the issues you're having. But it is to be noted that the performance here comes certainly at a memory cost.

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

Successfully merging a pull request may close this issue.

2 participants