Solved! Go to Solution.
rastersCount = 360 counter = 0 dek = 1 while counter < rastersCount: for i in range(counter,(counter+10)): print i counter += 10 dek += 1
# Import system modules import arcpy, os, sys from arcpy import env from arcpy.sa import * # Set workspace env.workspace = "D:/dailyrainfall/subset" # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Create list of rasters rasters = arcpy.ListRasters("*", "tif") # Create Weekly rainfall raster try: index = 70 for index in rasters: count = 0 while count <=7: # Set local variables inRaster0 = rasters.Next() count += 1 inRaster1 = rasters.Next() count += 1 inRaster2 = rasters.Next() count += 1 inRaster3 = rasters.Next() count += 1 inRaster4 = rasters.Next() count += 1 inRaster5 = rasters.Next() count += 1 inRaster6 = rasters.Next() count += 1 index -= 1 # Execute CellStatistics outCellStatistics = CellStatistics([inRaster0, inRaster1, inRaster2, inRaster3, inRaster4, inRaster5, inRaster6], "SUM", "NODATA") output = outCellStatistics.name # Save the output outCellStatistics.save("D:/dailyrainfall/subset/result/" + output + ".tif") except: # If an error occurred while running a tool, then print the messages. print arcpy.GetMessages()
try: # Create list of rasters rasters = arcpy.ListRasters("*", "tif") rastersCount = len(rasters) counter = 0 weekNum = 1 while counter < rastersCount: #collect 7 consecutive rasters weekRasters = [] for i in range(counter,(counter+7)): weekRasters.append(rasters) # Execute CellStatistics (one can use list of rasters directly here) outCellStatistics = CellStatistics(weekRasters, "MEAN", "NODATA") # Save the output outRasterName = "week_"+ str(weekNum) outCellStatistics.save("C:/tmp/PrecipRasters/" + outRasterName ) counter += 7 weekNum += 1
Hi m.gasior,
I tried to implement the python script that you suggested but I get an error when I ran it in in PythonWin and in ArcGIS 10. I have 366 rasters in TIFF format and I want to calculate the mean values every 10 days. I tried to modify the script but get an error. This is the modified script that I am trying to use. Could you help me revise my script?
Thanks,
-Leoimport arcpy, os, sys from arcpy import env from arcpy.sa import * env.workspace = "E:\PCP_TRMM_1998-2013" rasters = arcpy.ListRasters("*", "tif") rastersCount = len(rasters) counter = 0 weekDek = 1 while counter < rastersCount: dekadRasters = [] for i in range(counter,(counter+10)): dekRasters.append(rasters) outCellStatistics = CellStatistics(dekRasters, "MEAN", "NODATA") outRasterName = "dekad_"+ str(weekDek) outCellStatistics.save("E:\PCP_TRMM_1998-2013\Dekads" + outRasterName ) counter += 10 weekDek += 1
if arcpy.CheckExtension("Spatial") == "Available": arcpy.CheckOutExtension("Spatial")