question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nodata_value for zonal_stats doesn't appear to work

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
petersediveccommented, Dec 16, 2021

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: @.***>

0reactions
thuydotmcommented, Nov 28, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

rasterstats zonal statistics does not ignore nodata
Solved! I realized that I was changing only the meta property not the actual nodata value. I still don't understand why the masked...
Read more >
Solved: Major bug in Zonal Stats? - Esri Community
I am using the NODATA option with a value raster that has one NoData pixel, and therefore expect the resulting zone value (zone...
Read more >
rasterstats 0.10.3 documentation - PythonHosted.org
If raster is a GDAL source, this value overrides any NODATA value specified in the file's metadata. If None , the file's metadata's...
Read more >
Zonal Statistics—Help | ArcGIS for Desktop
ArcGIS geoprocessing tool that calculates statistics on values of a raster within the zones of another dataset.
Read more >
Calculating Zonal Statistics of a Raster using Python - YouTube
This tutorial explains the basics of calculating the zonal statistics such as average, max, min values corresponding to a defined spatial ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found