Python – Resolving Inaccuracy in Spatial Analyst Cell Statistics Tool

arcgis-10.0arcpyspatial-analyst

My question is similar to the Cell Statistics gives Wrong Answer question. In Python, I'm using the MINIMUM parameter to execute the cell statistics tool on several reclassified rasters ('0's and '1's) and I'm not getting accurate results. However, when I use the tool in ArcMap I get what I'm looking for. It seems as if it's only using two rasters (don't know which ones). Here's the code I'm using.

arcpy.env.workspace = ("F:\\hdf\\hdf_test\\reclass")
outh10v03 = ("F:\\hdf\\hdf_test\\h10v03\\")

h10v03 = arcpy.ListRasters("*2000*h10v03*", "tif")

for reclass in h10v03:
    print reclass

arcpy.gp.CellStatistics_sa(h10v03, outh10v03 + "h10v03_2000" + ".tif", "MINIMUM", "DATA")

Any ideas as to why it's not using all rasters (I believe that's the case)?

Best Answer

I'm not certain if the problem is due to indentation in your code, or whether it is due to formatting on the site:

for reclass in h10v03:
    print reclass

arcpy.gp.CellStatistics_sa(reclass, outh10v03 + "h10v03_2000" + ".tif", "MINIMUM", "DATA") 
# only the last line is run once

In this case it should loop through all of the tifs in the folder:

for reclass in h10v03:
    print reclass    
    arcpy.gp.CellStatistics_sa(reclass, outh10v03 + "h10v03_2000" + ".tif", "MINIMUM", "DATA")
    # here the line arcpy.gp.CellStatistics_sa ... is run for every raster in h10v03
Related Question