Hello colleagues
I am trying to use a formula in python. It is a raster dataset and I am trying to calculate a field based on an equation.
Here is the code
====================
inTable = "C:/Data/A3_Large_projects/Fuelloadmodels/Data/GDB/Yr2021.gdb/combo"
fieldName = "Bark_load"
expression = "t_RF(!Bark_r!, !Bark_k!, !Bark_c!, !since_fire!)"
codeblock = """
def t_RF(Bark_r, Bark_k, Bark_c, since_fire):
if since_fire >= 0:
return 7.437 /(1+937.8 * Exp ( -1.905 *( Bark_r *(1 - Exp ( - Bark_k * since_fire ) )+ Bark_c )))
else:
return 999 """
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON_9.3", codeblock)
====================
End code
Error message starts
====================
Traceback (most recent call last):
File "C:\Data\A3_Large_projects\Fuelloadmodels\Python_script\Fuelhazard.py", line 126, in <module>
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON_9.3", codeblock)
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 3661, in CalculateField
raise e
ExecuteError: ERROR 000539: Error running expression: t_RF(2.5, 0.2, 0.7, 1)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 4, in t_RF
NameError: global name 'Exp' is not defined
Failed to execute (CalculateField).
====================
End error message
I am relatively new in python. Trying to understand the error message. Will appreciate any help.
Thanks