AnsweredAssumed Answered

Problem in Calculate percent difference between two rasters

Question asked by dljayasekera on Sep 8, 2017
Latest reply on Sep 11, 2017 by dkwiens

Hi,

 

 I need to calculate the percent difference between two rasters. Below is my code and I am getting the following error. Can somebody help me to correct my code? 

 

Thanks in advance.

 

Error:

Traceback (most recent call last):
  File "C:\Users\jayaskeradl\Desktop\Arkansas Flood\My_Phyton_Scripts\Normal_Difference.py", line 73, in <module>
    outcalc2 = Minus(normal, fmaskrasters)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 4247, in Minus
    in_raster_or_constant2)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Utils.py", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 4244, in Wrapper
    ["Minus", in_raster_or_constant1, in_raster_or_constant2])
TypeError: expected a raster or layer name
months = [10]
weeks = [1]
year = [2010]

arcpy.env.workspace = r'H:\PRISM_800m_weekly_sum\Crawford\All'
out = r'H:\PRISM_800m_weekly_sum\Crawford\All\output'

for month in months:
     for week in weeks:
     arcpy.env.workspace = r'H:\PRISM_800m_weekly_sum\Crawford\All'
     fmaskrasters = arcpy.ListRasters("Week_" + str(week) + "_Sum" + str(year) + "_" + str(month) + "*","*")

    arcpy.env.workspace = r'H:\PRISM_800m_weekly_sum\Crawford\All\output'
    normal = arcpy.ListRasters("Crawford_Normal_Week_" + str(week) + "_*_" + str(month) + "*")
    outcalc2 = Minus(normal, fmaskrasters)
    Final = (outcalc2/normal)*100
    finras1 = out + "\\" + "Crawford_Normal_Week_" + str(week) + "_Difference" + "_" + str(month) + ".tif"
    arcpy.CopyRaster_management(Final,finras1 + "_Normal_Difference_Crawford.tif","","","","","")

Outcomes