AnsweredAssumed Answered

Loop through multiple folder and Calculate mean of raster of Same folder

Question asked by india123 on Mar 24, 2017
Latest reply on Apr 3, 2017 by xander_bakker

Hi All, 


I am writing a script to loop through multiple folders and calculate mean of the raster of each folder's data sets and save it in same folder. Below script i am working, but its not producing the mean rasters for each year folder, after running the script its generating only name of "mean" raster in main folder, and overlapping it .

Below images showing the name of the raster in one folder, another folder the raster name is same, only year value is changed in different year.
here how to take the year value in name of mean raster (E.g. for 2001 folder, output mean raster name would be Mean_Temp_2001.tif, E.g. for 2002 folder, output mean raster name would be Mean_Temp_2002.tif)

Below i have attached data sets also (Test_data folder)v which i am working on. 





import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput = True
env.workspace = r"D:\Test"
outraster = env.workspace

walk = arcpy.da.Walk(env.workspace, topdown=True, datatype="RasterDataset")
for dirpath, dirnames, filenames in walk:
    print dirpath
    rasterList = []
    for file in filenames:
        raster = os.path.join(dirpath, file)
        rasMean =,"MEAN"),"mean.tif"))
        print rasMean