from arcpy import *


#pathway to all rasters in workspace directory
rasters = arcpy.ListRasters('*.tif')

# Local variables:
Output_raster = "test_script.tif"

# Local variables:
aa = "flam_length_new.tif"
bb = "burn_prob.tif"
cc = "us_drought_prob.tif"
dd = "100m_fire_prec.tif"

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("(\"flam_length_new.tif")*(Lookup(\"burn_prob.tif\",'Probabilit')*0.6)+(Lookup(\"us_drought_prob.tif\",'Ptobabilit')*0.2)+(Lookup(\"us_fire_1000m_proba.tif\",'prob')*0.3)", Output_raster)

The error is:

Warning (from warnings module): File "", line 1 SyntaxWarning: import * only allowed at module level

Traceback (most recent call last): File "D:\work\scripts\risk_score.py", line 30, in arcpy.gp.RasterCalculator_sa("(\"flam_length_new.tif\")*(Lookup(\"burn_prob.tif\",'Probabilit')*0.6)+(Lookup(\"us_drought_prob.tif\",'Ptobabilit')*0.2)+(Lookup(\"us_fire_1000m_proba.tif\",'prob')*0.3)", Output_raster) File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\geoprocessing_base.py", line 510, in return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 000539: Error running expression: rcexec() Traceback (most recent call last): File "", line 1, in File "", line 8, in rcexec RuntimeError: ERROR 999998: Unexpected Error.

Failed to execute (RasterCalculator).


2 Answers 2


Raster calculator as such is not recognized as a tool in Python script. You can have more info on this issue on the link below.


In your case, you could create a new model where you split your process 1) creating intermediate raster with the lookup tool, 2) making the weighted sum of your raster with the math tool (with Plus and Times).

A more simple Python process is to directly use the arcpy map algebra


this should be something like this

import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = r'D:\work\USA'
# Set local variables
# Local variables:
aa = Raster("flam_length_new.tif")
bb = "burn_prob.tif"
cc = "us_drought_prob.tif"
dd = "100m_fire_prec.tif"

# Check out the ArcGIS Spatial Analyst extension license

# Execute Look ups
lu_bb = Lookup(bb,'Probabilit')
lu_cc = Lookup(cc,'Probabilit')
lu_dd = Lookup(dd,'Probabilit')

#make weighted sum
outraster = Raster(aa) + lu_bb*0.6 + lu_cc*0.2 + lu_dd*0.3

# Save the output

First thing you have to do is import your modules correctly. Please just write import arcpy.

Second thing that i see is so complicated this command:

arcpy.gp.RasterCalculator_sa("(\"flam_length_new.tif")*(Lookup(\"burn_prob.tif\",'Probabilit')*0.6)+(Lookup(\"us_drought_prob.tif\",'Ptobabilit')*0.2)+(Lookup(\"us_fire_1000m_proba.tif\",'prob')*0.3)", Output_raster)

Did you test this expression on arcmap manual? And why are you using arcpy.gp.rastercalculator; it's only useful on modelbuilder. You need to use arcpy map algebra. By the way i don't believe that you can collect your result when you type gp rastercalculator then immediately execute for lookup.. I think you need to do those step by step.

  • I am multiplying some factor in Three different Rasters, because of that i am using gp.rastercalculator, arcpy map algebra is througing some errors
    – Robot
    Jun 1, 2018 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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