arcpy, Spatial Analyst, and Exp

Discussion created by jencarta on Mar 6, 2014
Latest reply on Mar 9, 2014 by xander_bakker

I am trying to convert some 9.3 python scripts that use the geoprocessor object gp to use arcpy instead. I am struggling with the conversion of Single Output Map Algebra (SOMA) that uses exp. Also, the script first calculated IDW on a set of points and that alone was quite a struggle to figure out since the 10.2 help for Spatial Analyst IDW does not show the correct input parameters! Add to the confusion the decision of when to use arcpy.Raster and when not to.

Anyway, I am very close, but for some reason when I run arcpy.Exp_sa on my raster as such:

ExpOut = arcpy.Exp_sa(IDWOut)

another raster is automatically output by Exp with the same name as IDWOut, but with Exp_ at the beginning and _1 at the end. For example, if IDWOut is "IDW_PAH_filtered", then a raster called "Exp_IDW_PAH_filtered_1" is automatically created. According to the help page the output should be saved to ExpOut, but when I look at the values of that raster, I can see that they have not had the exponential applied.

So confused!!

Here are the actual code snippets:

geoDB = sys.argv[1]
COCLayer = sys.argv[2]
COCField = sys.argv[3]
PerfLog = sys.argv[4]
IDWCellSize = sys.argv[5]
IDWPower = sys.argv[6]
IDWRadius = sys.argv[7]
IDWMask = sys.argv[8]
IDWBarrier = sys.argv[9


IDWOut = geoDB + "\\IDW_" + COCLayer
arcpy.Idw_sa(geoDB + "\\temp_data", COCField, IDWOut, IDWCellSize, IDWPower, IDWRadius, IDWBarrier)
ExpOut = arcpy.Exp_sa(IDWOut)
IDWOut = arcpy.Raster(ExpOut) / 1000

And the temp_data is a temporary point shapefile that is created correctly by the script. I started wondering if Exp has the wrong input parameters on the help page just like Idw and maybe needs an output raster as one of the parameters, like:
arcpy.Exp_sa(IDWOut, ExpOut)
but when I tried that, I got an error saying "name 'ExpOut' is not defined".

If anyone has any insights, I will welcome them. Yes, I know I can still use the old gp method, but I really want to avoid that. By the way, here is what it used to look like:

IDWOut = geoDB + "\\IDW_temp"
outRaster = geoDB + "\\IDW_" + COCLayer

gp.Idw_sa(geoDB + "\\temp_data", COCField, IDWOut, IDWCellSize, IDWPower, IDWRadius, IDWBarrier)       
inExpress = "( exp (" + IDWOut + ") ) / 1000"
gp.SingleOutputMapAlgebra_sa(inExpress, outRaster)

The inputs sys.argv[] were the same. In that case, IDWOut was a temporary raster that was deleted later and the final output was outRaster, but doing something similar with arcpy was creating even more problems.