4

Why is my ArcPy script in ArcGIS 10.1 failing to set null cell values below three standard deviations beyond the mean?

import arcpy, sys, os

#Accept input and output raster
inRas = sys.argv[1]
outRas = sys.argv[2]

#Pull mean and standard deviation from input raster
meanie = arcpy.GetRasterProperties_management(inRas, "MEAN")
meanres = meanie.getOutput(0)
meanfloat = float(meanres)

stdev = arcpy.GetRasterProperties_management(inRas, "STD")
stdres = stdev.getOutput(0)
stdfloat = float(stdres)

#Calculate threshold value
threshold = meanfloat + (3 * stdfloat)
threstring = str(threshold)

#Create where clause
whereClause = "VALUE < " + threstring

#Test output
arcpy.AddMessage (whereClause)

#Run SetNull
outRas = arcpy.SetNull(inRas, inRas, whereClause)

This results in the following error:

Traceback (most recent call last):
File       "Z:<directory-redacted>\Nullify.py", line 27, in <module>
outRas = arcpy.SetNull(inRas, inRas, whereClause)
AttributeError: 'module' object has no attribute 'SetNull'

Failed to execute (Nullifiy).
5

arcpy.SetNull does not exist. You are wanting arpy.sa.SetNull.

Here's the SetNull page for 10.1. If you notice in some of the examples there is:

from arcpy.sa import *

and you see that SetNull is used, but the import * from arcpy.sa drops the arcpy.sa from arcpy.sa.SetNull. And be sure to check out the spatial analyst license

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.