AnsweredAssumed Answered

Perform Raster Calculation from Multiple Sub-folder Using ArcPy

Question asked by india123 on Oct 7, 2016
Latest reply on Oct 11, 2016 by Dan_Patterson
Branched to a new discussion

I have five subfolders with Rasters name with the same parameter. I am trying to figure out a way to Loop average of all  raster and save output raster in outfolder . For instance 

Subfolder1   Subfolder2   Subfolder3   Subfolder4    Subfolder5   Outfolder
r001_NPP.tif r001_npp.tif r001_NPP.tif r_001_NPP.tif r001_NPP.tif r001_MEAN_NPP.tif

I have tried to write code for this, Below i post my code what i have so far

import arcpy, os, glob

ws1 = glob.glob(r'D:\subfolder1\*.tif')
ws2 = glob.glob(r'D:\subfolder2\*.tif')
ws3 = glob.glob(r'D:\subfolder3\*.tif')
ws4 = glob.glob(r'D:\subfolder4\*.tif')
ws5 = glob.glob(r'D:\subfolder5\*.tif')
outws = r'D:\outfolder'

for r in ws1, ws2, ws3, ws4:
    basename = os.path.basename(r).split("_")[0]
    r1 =, basename + "r_NPP.tif"))
    r2 =, basename + "r_NPP.tif"))
    r3 =, basename + "r_NPP.tif"))
    r4 =, basename + "r_NPP.tif"))
    r5 =, basename + "r_NPP.tif"))

    result = (r1 + r2 + r3 + r4 + r5) / 5
    outname = basename + "r_Mean_NPP.tif", outname))