Hello! I have 750+ rasters with precipitation data. The folder contains a raster for each month for the years 1945-2009. I need to find the mean of each year in a new raster. However, I am getting caught up on how to parse all the rasters with the specific years in their name. I am only able to run the calcs on one year at a time. The rasters are named like Oct2009.tif, Nov2009.tif, Nov2008.tif, etc.
import arcpy
arcpy.CheckOutExtension("Spatial")
# Define input workspace and create list of rasters
arcpy.env.workspace = r'C:\Users\dzelmanfahm\Desktop\DEM_Trials'
rasters = arcpy.ListRasters("*2009*")
print(rasters)
# Run cell statistics
calc = arcpy.sa.CellStatistics(rasters, statistics_type = "MEAN")
calc.save(r'C:\Users\dzelmanfahm\Desktop\OUTPUT_DEM_TRIALS\Raster.tif')
You can probably use something like this (untested code):
It consists of creating a list of all the rasters and simply loop through the years and create a list of the rasters for a single year and use that for the calculation and output naming