Select to view content in your preferred language

Major bug in Zonal Stats?

5459
10
Jump to solution
08-11-2015 11:52 AM
GüntherGrill
Occasional Contributor

I am using ArcGIS 10.2.2 to determine zonal statistics for a number of zones. If there is any NoData in the value raster, I want the zone results to be "NoData", precisely as advertised by the tools description. This tool description states:

"

DATA — Within any particular zone, only cells that have a value in the input Value raster will be used in determining the output value for that zone. NoData cells in the Value raster will be ignored in the statistic calculation.

NODATA — Within any particular zone, if any NoData cells exist in the Value raster, it is deemed that there is insufficient information to perform statistical calculations for all the cells in that zone; therefore, the entire zone will receive the NoData value on the output raster.

"

Please have a look at my setup in this picture:

Zonal.png

I am using the NODATA option with a value raster that has one NoData pixel, and therefore expect the resulting zone value (zone 61154) to be 'NoData'. Instead, I get a value of 12.74 (rounded to 13 in the image), which confuses me on two levels: First, I expected 'NoData', and second, the resulting value of 12.74 is mathematically impossible, because the mean cannot be larger than the maximum value in the value raster, which is 10 in this case.

If I am using the DATA option, I get a value of about 9.1, which makes sense. We tested this on different datasets, computers, and ArcGIS versions.

The 'Count' attribute is also wrong for that particular zone. There are indeed 421 cells in that zone, but the tool only counted 297. Calculating 421 minus 297 results in 124 - oddly enough, this is the "position" where the NoData pixel is located, if one counts the pixels from upper left to lower right in the zone. The tool might be getting the cell count wrong (too low), which might explain the increase of the average.

see also: Major bug in ArcGIS Zonal statistics? - Geographic Information Systems Stack Exchange where someone already confirmed the issue

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
GüntherGrill
Occasional Contributor

An ESRI employee pointed me to an existing bug report:

BUG-000084883 - The 'Ignore NoData in calculations' option in Zona..

Case closed.

View solution in original post

10 Replies
GüntherGrill
Occasional Contributor

btw, zone and value are both raster data sets with the same resolution (despite the visual appearance)

0 Kudos
DanPatterson_Retired
MVP Emeritus

If it is as you said on the other site and You followed Bill's suggestion, then you should forward this as a bug.  In the interim to confirm that everything is fine, you could try the following procedure

  • export both grids to Esri grids (not tiffs, jpegs etc) using
    • the same cell size
    • the same extent
    • make sure that they are snapped so that the cell bounds of both are coincident

confirm the total cell count for both and that one and/or both have nodata values

rerun the analysis to confirm

If all the above is fine,

  • upgrade to 10.3.1 and check for new patches .... barring that
  • zip and ship your data and report as a bug.

Then report back here.

0 Kudos
GüntherGrill
Occasional Contributor

Thanks Dan, I don't have ArcGIS10.3.1. Care to test it using my data?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Here you go...for your viewing pleasure

ZonalStats_on_off.pngOk

GüntherGrill
Occasional Contributor

OK, thanks for doing this, this confirms the erroneous behavior of the tool. I wonder why you didn't get 12.7 as the mean like I do, but the cell count and the fact that it should produce NODATA still points to a major error in the code, does it not?

0 Kudos
GüntherGrill
Occasional Contributor

Dan, I found out why the mean value for that zone is different in your case. You used "ALL" statistics as in

arcpy.gp.ZonalStatisticsAsTable_sa(zones,"Value",val_grid, out,"NODATA","ALL")

N")

If you used only the "MEAN" instead as in

arcpy.gp.ZonalStatisticsAsTable_sa(zones,"Value",value_grid, out,"NODATA","MEAN")

I predict you would get something around 12.74 .... as well.

Bizarre!

0 Kudos
DanPatterson_Retired
MVP Emeritus

I will check later...I just used the tool in ArcToolbox...haven't tried the python-arcpy approach...which I will just in case there are differences in behaviour between the tool and arcpy

0 Kudos
GüntherGrill
Occasional Contributor

Thanks again! I used the code for illustration purposes only (export as python snippet) and also use the Toolbox. But you are right in the sense, that Toolbox and Python code sometimes produce different results too.

0 Kudos
GüntherGrill
Occasional Contributor

An ESRI employee pointed me to an existing bug report:

BUG-000084883 - The 'Ignore NoData in calculations' option in Zona..

Case closed.