AnsweredAssumed Answered

raster calculator attribute error 'str' object has no attribute 'save'

Question asked by whittier on Aug 2, 2012
Latest reply on Aug 7, 2012 by whittier
I am multiplying several .tif files by set values and adding the results together using raster calculator in arcgis 10.1.  If I manually load the files into raster calculator, the calculation completes.  Unfortunately I need to do this several hundred times so I would like to automate the process.  I created a model in model builder (and it worked) and then exported the code to python to see the format. 

Here is that coding
# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
RT_v4_2027_0_albers_tif = "RT_v4_2027_0_albers.tif"
RT_v4_2027_1_albers_tif = "RT_v4_2027_1_albers.tif"
RT_v4_2027_2_albers_tif = "RT_v4_2027_2_albers.tif"

rt_sum_2027_100_tif = "Y:\\RT_annual\\rt_sum_2027_100.tif"

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("((\"%RT_v4_2027_0_albers.tif%\" * 31) + (\"%RT_v4_2027_1_albers.tif%\" * 28) + (\"%RT_v4_2027_2_albers.tif%\" * 31)) * 100", rt_sum_2027_100_tif)

As a first step toward automating I then tried to calculate the above for the next set of files using this code:
# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
RT_v4_2028_0_albers_tif = "Y:\\RT_albers\\RT_v4_2028_0_albers.tif"
RT_v4_2028_1_albers_tif = "Y:\\RT_albers\\RT_v4_2028_1_albers.tif"
RT_v4_2028_2_albers_tif = "Y:\\RT_albers\\RT_v4_2028_2_albers.tif"
rt_sum_2028_100_tif = "Y:\\RT_annual\\rt_sum_2028_100.tif"

arcpy.gp.RasterCalculator_sa("((\"%RT_v4_2028_0_albers_tif%\" * 31) + (\"%RT_v4_2028_1_albers_tif%\" * 28) + (\"%RT_v4_2028_2_albers_tif%\" * 31)) * 100", rt_sum_2028_100_tif)

I get the following error whether I run the script in the ArcGIS python window or in IDLE:

Runtime error  Traceback (most recent call last):   File "<string>", line 24, in <module>   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>     return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 000539: Error running expression: rcexec()  Traceback (most recent call last):   File "<expression>", line 1, in <module>   File "<string>", line 8, in rcexec AttributeError: 'str' object has no attribute 'save'  Failed to execute (RasterCalculator).

Why does this script seem to be looking for an attribute called 'save'?  Any suggestions would be greatly appreciated.

Outcomes