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

nodata_value for zonal_stats doesn't appear to work #597

Closed
petersedivec opened this issue Dec 15, 2021 · 5 comments
Closed

nodata_value for zonal_stats doesn't appear to work #597

petersedivec opened this issue Dec 15, 2021 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@petersedivec
Copy link

Describe the bug
Running zonal_stats and passing in the argument nodata_values = -99999 results in a
ValueError: All arrays must be of the same length
stack trace with method and line number
zonal.py line 519
zonal.py 335
python3.7/site-packages/pandas/core/frame.py 614
python3.7/site-packages/pandas/core/internals/construction.py 465

When i run zonal_stats without the nodata_values argument it runs fine and computes

nodata_values = -99999 or nodata_values = -99999.0

Expected behavior
Would expect the method zonal_stats to return statistics computed ignoring pixels with nodata_values

Screenshots
Unable to provide screenshots, running this in a classified environment

Desktop (please complete the following information):
Running this in Databricks 7.3LTS with Python 3.7.5, xarray-spatial 0.3.0

@petersedivec petersedivec added the bug Something isn't working label Dec 15, 2021
@thuydotm
Copy link
Contributor

Thanks for reaching out. I guess the error happened because, in the values raster, there is some zone filled with nodata_values. This bug has already been fixed with PR #581, and we plan to add this to the next release in early January.

In the meanwhile, can you try to replace all nodata_values pixels in values raster by np.nan and run the analysis as a temporary workaround? This should work because all NaNs will be excluded from calculations.

@petersedivec
Copy link
Author

thanks, yep, from looking through the code we noticed that. We also ran with a positive value of 99999 and that worked fine so something with negative sign is causing a bug

@thuydotm
Copy link
Contributor

Did the 2 datasets you run are exactly the same except for the nodata value? It could happen that the dataset with a positive value of 99999 does not have a zone that only filled by nodata. If this is not the case, can you please add a minimal reproducible example where positive works and negative doesn't? Off the top of my head, I don't find any reason that it behaves differently with negative sign.

@petersedivec
Copy link
Author

petersedivec commented Dec 16, 2021 via email

@thuydotm
Copy link
Contributor

thuydotm commented Nov 28, 2022

Fixed in #581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants