import arcview,arcpy,math
from arcpy.sa import *
def erf(x):
''' Error function modified for rasters from the pure python implementation
posted on StackExchange [1] of the algorithm from the
Handbook of Mathematical Functions [2]
[1] http://stackoverflow.com/a/457805/737471
[2] http://people.math.sfu.ca/~cbm/aands/frameindex.htm
'''
# save the sign of x
#sign = 1 if x >= 0 else -1 # This doesn't work with a Raster object
# ValueError: The truth value of a raster is ambiguous.
# Invalid use of raster with Boolean operator or function.
sign = (x>=0) + ((x<0)*-1)
x = Abs(x)
# constants
a1 = 0.254829592
a2 = -0.284496736
a3 = 1.421413741
a4 = -1.453152027
a5 = 1.061405429
p = 0.3275911
# A&S formula 7.1.26
t = 1.0/(1.0 + p*x)
y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*Exp(-x*x)
return sign*y
if __name__=='__main__':
input_raster='path/to/input/raster'
output_raster='path/to/output/raster'
arcpy.CheckOutExtension('spatial')
inras=Raster(input_raster)
outras = 0.5*(1+erf((inras)/math.sqrt(2*2*2)))
outras.save(output_raster)
math.sqrt(2*2*2)