There are a couple of problems that need to be addressed. I put in some comments to help explain.
Code:
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Input data source
arcpy.env.workspace = "S:/Work/Risa/Trial_and_Error/input" # don't use spaces or special characters in path names
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = "S:/Work/Risa/Trial_and_Error/output/"
# Loop through a list of files in the workspace
rasterFiles = arcpy.ListRasters()
# The loop does nothing else but build the list
inRasters = [] # you need to do this outside of the loop
for filename in rasterFiles:
print("Processing: " + filename)
if filename.endswith("14.tif"):
inRasters.append(filename)
# Now we have a list of the files we want to average, but you only need to calculate the average once,
# which means this part should not be in the loop, so we remove indentation
outRaster = CellStatistics(inRasters, "MEAN", "DATA")
# Save the output
outRaster.save("S:/Work/Risa/Trial_and_Error/output/AvgPrecip01.tif")
print "Average Calculated!!!"
Looping through files one of the most useful and common tasks in GIS. Once you get this mastered you'll be set!
Bookmarks