# Looping through Raster to compute Mean in Cell Statistics

Discussion created by kah7 on May 23, 2013
Latest reply on May 29, 2013 by kah7
I am attempting to loop through a set of MODIS data to compute averages by period.  Since 2000 is missing periods 1 - 3 I am just computing the averages of periods 1 -3 for 2001 through 2012.  I am then computing the averages for periods 4 - 23 with data from 2000 through 2012.  I have written a script to do this, but keep getting an error 000732 about my data not existing or not being supported.  I opened one of the grids in Arc and it was fine.  I am not sure why I am getting this error and have included the code below.

```# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "S:\\MODIS\\DATA_v05\\modis016_0250_ndvi\\us\\"

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Path names for input and output data
path = "S:\\MODIS\\DATA_v05\\modis016_0250_ndvi\\us\\or"
output_path = "B:\\MODIS_NDVI\\Avg_per_period\\avg"

for period in range (1,3):
#MODIS does not have data for the first three periods of 2000.  This will calculate an average for the first three periods ignoring the year 2000.  It will also place a 0 in front of the single digit to match the file name.
if period <= 3:
period = ("0"+str(period))
grids01 = Raster('"' + path + "01" + period + "ndvius" + '"')
grids02 = Raster('"' + path + "02" + period + "ndvius" + '"')
grids03 = Raster('"' + path + "03" + period + "ndvius" + '"')
grids04 = Raster('"' + path + "04" + period + "ndvius" + '"')
grids05 = Raster('"' + path + "05" + period + "ndvius" + '"')
grids06 = Raster('"' + path + "06" + period + "ndvius" + '"')
grids07 = Raster('"' + path + "07" + period + "ndvius" + '"')
grids08 = Raster('"' + path + "08" + period + "ndvius" + '"')
grids09 = Raster('"' + path + "09" + period + "ndvius" + '"')
grids10 = Raster('"' + path + "10" + period + "ndvius" + '"')
grids11 = Raster('"' + path + "11" + period + "ndvius" + '"')
grids12 = Raster('"' + path + "12" + period + "ndvius" + '"')
#grids = grids01 + ";" + grids02 + ";" + grids03 + ";" + grids04 + ";" + grids05 + ";" + grids06 + ";" + grids07 + ";" + grids08 + ";" + grids09 + ";" + grids10 + ";" + grids11 + ";" + grids12
avg_temp = ('"' + output_path + period + "temp" + '"')
avg = (output_path + period)
outCellStatistics = CellStatistics([grids01, grids02, grids03, grids04, grids05, grids06, grids07, grids08, grids09, grids10, grids11, grids12], "MEAN", "DATA")
outCellStatistics.save(avg_temp)
#This is will place a 0 in front of the single digit to match the file name.
elif period < 10:
period = ("0"+str(period))
grids00 = ('"' + path + "00" + period + "ndvius" + '"')
grids01 = ('"' + path + "01" + period + "ndvius" + '"')
grids02 = ('"' + path + "02" + period + "ndvius" + '"')
grids03 = ('"' + path + "03" + period + "ndvius" + '"')
grids04 = ('"' + path + "04" + period + "ndvius" + '"')
grids05 = ('"' + path + "05" + period + "ndvius" + '"')
grids06 = ('"' + path + "06" + period + "ndvius" + '"')
grids07 = ('"' + path + "07" + period + "ndvius" + '"')
grids08 = ('"' + path + "08" + period + "ndvius" + '"')
grids09 = ('"' + path + "09" + period + "ndvius" + '"')
grids10 = ('"' + path + "10" + period + "ndvius" + '"')
grids11 = ('"' + path + "11" + period + "ndvius" + '"')
grids12 = ('"' + path + "12" + period + "ndvius" + '"')
grids = "[" + grids00 + "," + grids01 + "," + grids02 + "," + grids03 + "," + grids04 + "," + grids05 + "," + grids06 + "," + grids07 + "," + grids08 + "," + grids09 + "," + grids10 + "," + grids11 + "," + grids12 + "]"
avg_temp = (output_path + period + "temp")
avg = (output_path + period)
arcpy.gp.CellStatistics_sa(grids,avg_temp,"MEAN", "DATA")
#These are double digit periods and will match the file name without correction.
else:
period = (str(period))
grids00 = ('"' + path + "00" + period + "ndvius" + '"')
grids01 = ('"' + path + "01" + period + "ndvius" + '"')
grids02 = ('"' + path + "02" + period + "ndvius" + '"')
grids03 = ('"' + path + "03" + period + "ndvius" + '"')
grids04 = ('"' + path + "04" + period + "ndvius" + '"')
grids05 = ('"' + path + "05" + period + "ndvius" + '"')
grids06 = ('"' + path + "06" + period + "ndvius" + '"')
grids07 = ('"' + path + "07" + period + "ndvius" + '"')
grids08 = ('"' + path + "08" + period + "ndvius" + '"')
grids09 = ('"' + path + "09" + period + "ndvius" + '"')
grids10 = ('"' + path + "10" + period + "ndvius" + '"')
grids11 = ('"' + path + "11" + period + "ndvius" + '"')
grids12 = ('"' + path + "12" + period + "ndvius" + '"')
grids = "[" + grids00 + "," + grids01 + "," + grids02 + "," + grids03 + "," + grids04 + "," + grids05 + "," + grids06 + "," + grids07 + "," + grids08 + "," + grids09 + "," + grids10 + "," + grids11 + "," + grids12 + "]"
avg_temp = (output_path + period + "temp")
avg = (output_path + period)
arcpy.gp.CellStatistics_sa(grids,avg_temp,"MEAN", "DATA")```