nodata_value for zonal_stats doesn't appear to work
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
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 https://github.com/makepath/xarray-spatial/pull/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.
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
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.
Good point, I don't think there were any positive values in the array with 99999 so maybe that's why the case worked. I haven't had a chance to swap out for Nan but I will test both cases when I'm back from the holidays.
On Thu, Dec 16, 2021, 09:24 thuydotm @.***> wrote:
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.
— Reply to this email directly, view it on GitHub https://github.com/makepath/xarray-spatial/issues/597#issuecomment-996023876, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSPPNFMWGM5GVCEK6QM2MTURIODDANCNFSM5KDCMMEA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
Fixed in https://github.com/makepath/xarray-spatial/pull/581