I am a Python novice trying to figure out how to perform calculations on temporary rasters with variable names.
My attempt at a minimum working example is below, but I would eventually like to do this with thousands of larger grids, so I expect that I will need to keep everything temporary until the very end to increase efficiency.
The code below fails on the last line. The error message is:
RuntimeError: ERROR 000732: Input Raster: Dataset bin2 does not exist or is not supported.
If I replace the last line with the permanent filenames:
tmpout = Minus("D:/tmp/tmp" + `year`,"D:/tmp/tmp" + `yearold`)
then it runs fine. I am running IDLE in ArcGIS 10.0 with Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32.
import arcgisscripting
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.extent = arcpy.Extent(0,0,2,2)
arcpy.CreateRandomRaster_management("D:/tmp/","tmp1","","",1)
arcpy.CreateRandomRaster_management("D:/tmp/","tmp2","","",1)
bin1 = arcpy.Raster("D:/tmp/tmp1")
bin2 = arcpy.Raster("D:/tmp/tmp2")
for year in range(2, 3, 1) :
yearold = year - 1
binyear = "bin" + `year`
binyearold = "bin" + `yearold`
print "fails in next line"
tmpout = Minus(binyear,binyearold)
I think the problem is that bin1 and bin2 are being interpreted as strings as opposed to pointer to temporary rasters, but I can't figure out how to make my intent understood. Replacing binyear with Raster(binyear), for example, did not help.
whatever_STRINGin my context asyear, I get the same error message. – Adam Aug 17 '14 at 10:37