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.
<SPAN class="keyword token">import</SPAN> arcpy
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Spatial"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Define input workspace and create list of rasters</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\dzelmanfahm\Desktop\DEM_Trials'</SPAN>
rasters <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*2009*"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>rasters<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Run cell statistics</SPAN>
calc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa<SPAN class="punctuation token">.</SPAN>CellStatistics<SPAN class="punctuation token">(</SPAN>rasters<SPAN class="punctuation token">,</SPAN> statistics_type <SPAN class="operator token">=</SPAN> <SPAN class="string token">"MEAN"</SPAN><SPAN class="punctuation token">)</SPAN>
calc<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'C:\Users\dzelmanfahm\Desktop\OUTPUT_DEM_TRIALS\Raster.tif'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>