I was able to run the below script from @EmilBrundage.

However, the raster to be calculated were not paired correctly.

I am trying to loop files from 2 folders and perform raster calculation afterwards. The sequence of calculation must be:

(1st) out-0225*out-0225 [from clip qx folder] + out-0225*out-0225 [from clip qy folder]

(2nd) out-0226*out-0226 [from clip qx folder] + out-0226*out-0226 [from clip qy folder]

(3rd) out-0227*out-0227 [from clip qx folder] + out-0227*out-0227 [from clip qy folder]

and so on.

But then the script calculates like the image below.

File pairing

The script used is the ff:

import arcpy, os, math

ws1 = r"E:\clip_qx"
ws2 = r"E:\clip_qy"
outws = r"E:\ras_calc_qxy"

arcpy.env.workspace = ws1

rasterlist  = arcpy.ListRasters()

for r in rasterlist:
    r1 = arcpy.sa.Raster(r)
    r2 = arcpy.sa.Raster(os.path.join(ws2,r1))
    result =  (r1*r1) + (r2*r2)
    result.save(os.path.join(outws, r))
  • 1
    What do you mean by "not paired correctly"? Do they not line up or something? I am confused. Aug 3, 2017 at 15:13
  • @jbchurchill, i edited the question. Kindly check it out. Thanks again
    – F Viray
    Aug 4, 2017 at 0:22

1 Answer 1


In line

r2 = arcpy.sa.Raster(os.path.join(ws2,r1))

you write r1 at the end of the bracket.

I think this should be just r.


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.