rpatarasuk

Finding an Average Rainfall Data

Discussion created by rpatarasuk on May 2, 2012
Latest reply on May 11, 2012 by rpatarasuk
Hi All,

I have about 350 files of PRISM rainfall data to process. I have e.g. precip from 1970 - 2010. and each year has 13 files.

ppt_1970.01.tif
ppt_1970.02.tif
ppt_1970.03.tif
ppt_1970.04.tif
ppt_1970.05.tif
ppt_1970.06.tif
ppt_1970.07.tif
ppt_1970.08.tif
ppt_1970.09.tif
ppt_1970.10.tif
ppt_1970.11.tif
ppt_1970.12.tif
ppt_1970.14.tif
.
.
.
ppt_2010.11.tif
ppt_2010.12.tif
ppt_2010.14.tif

I try to write a python code to calculate a long term average. Here is the code that I have so far. I have only tried to play around with 5-10 files and the program only returns values for the last file (i.e. it doesn't add up the values of previous file and find the average). Also, I would like to exclude "*.14" from the calculation.

# 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 & Error/input"
arcpy.env.overwriteOutput = True

# Set output folder
OutputFolder = "S:/Work/Risa/Trial & Error/output/"

# Loop through a list of files in the workspace
rasterFiles = arcpy.ListRasters()

# Local variables:
for filename in rasterFiles:
    print("Processing: " + filename)
    inRaster = arcpy.env.workspace + "/" + filename
    outRaster = OutputFolder + "/" + "AvgPrecip.tif"
   
    #***need to process from all of the files except the ones that have "*.14"

    # Process: Cell Statistics
    arcpy.gp.CellStatistics_sa(inRaster, outRaster, "MEAN", "DATA")

   
                                  
print "***DONE!!!"


Any help would be very appreciated. Thank you very much.

Risa

Outcomes