ZonalStatisticsAsTable misses 245 zones out of 3108! - ArcPy , ArcGIS Pro 2.8.2.

2654
12
Jump to solution
08-30-2021 12:05 PM
BabakJfard
New Contributor III

I have many .ncf files that I read as raster layers and then do zonal statistics to have mean and sd values over each of 3108 CONUS counties. But the final standalone table is missing 245 counties. This is how the raster layer and the counties look together. You see that the raster covers all the polygons

feature layer on top of the raster layerfeature layer on top of the raster layer

And the picture below shows missing counties  from the resulted zonal statistics in red color.Red counties are missed from the final tableRed counties are missed from the final table

This is my code that loops over different files with same rasters only different values in cells and the same shape file for zonal boundaries.

 

 

# Set the analysis environments
env.workspace = r"C:\ArcGIS_projects\PM25"

rasrtersFolder = r"C:\ArcGIS_projects\PM25\V4NA03\\"
zonalOutFolder = r"C:ArcGIS_projects\PM25\zonal_stats\\"

variable = "PM25"
XDimension = "LON"
YDimension = "LAT"
outRasterLayer = "PM25"
bandDimmension = ""
dimensionValues = ""
valueSelectionMethod = ""
cellRegistration = ""

# for zonal statistics
inZoneData = 'CONUS_counties_2016_WGS1984'
zoneField = 'GEOID'
inValueRaster = 'PM25'

for fileName in files:
    # Reading netcdf file into raster layer
    inNetCDFFile = rasrtersFolder + fileName

    # Execute MakeNetCDFRasterLayer
    arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, variable, XDimension, YDimension,
                               outRasterLayer, bandDimmension, dimensionValues, 
                               valueSelectionMethod, cellRegistration)

    # Now doing zonal statistics
    outName = fileName.split('.')[0]
    outTable = zonalOutFolder + outName+'.dbf'

    outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster,
                                  outTable, "DATA", "MEAN_STD")

    # Set local variables
    inTable = outName
    outLocation = r"C:\Users\babak.jfard\ArcGIS_projects\PM25\zonal_stats_csv"
    outTable = outName.split('-')[0] + ".csv"

    # Execute TableToTable
    arcpy.TableToTable_conversion(inTable, outLocation, outTable)
    
    arcpy.management.Delete('PM25')
    arcpy.management.Delete(outName)
    arcpy.management.Delete(outTable)

 

 

the files to reproduce can be found here: (All projection are set to WGS1984 to align with the ncd files)

Is it possible to be related to my updated ArcGIS pro (2.8.2)? two weeks ago I did the very same with an older version of ArcGIS pro and worked perfectly. Last night I updated my ArcGIS pro, and the very same raster and feature have missing zones in the results

0 Kudos
12 Replies
SarmisthaChatterjee
Esri Contributor

Thanks, can you please also share the shapefile 

0 Kudos
BabakJfard
New Contributor III

Sure. I just corrected its link in the original question. Now everyone clicking it can get access to the file.

SarmisthaChatterjee
Esri Contributor
Thank you for sharing the data and for reporting this issue BabakJfard.
It seems like the ZonalStatisticsAsTable tool has some issue in ArcGIS Pro 2.8.2 with the MakeNetCDFRasterLayer tool output as a value raster input. We will take a closer look and will address it in the upcoming release.

For a workaround, please use the new MakeMultidimensionalRasterLayer tool to add the PM25 layer to your analysis in Pro. This tool creates a raster layer from a netCDF file with specified variables and dimensions: Try, arcpy.md.MakeMultidimensionalRasterLayer(r"C:\data\V4NA03_PM25_NA_200007_200007-RH35.nc", "PM25_MMRL", "PM25")

Then use the raster layer in your Zonal tool, as you have done above. Your new output should contain the same number of zones, as in your CONUS counties dataset.


Hope that helps!
Thanks,
Sarmistha
0 Kudos