Hi All,
I have rainfall rasters for each day of the decade 2000 - 2009. Each file is named with the format rYYYYMMDD (eg r20001224 is the rainfall raster for Dec 24th 2000).
I would like to create 'monthly average rainfall' rasters for each month in this decade (10 years x 12 months = 120 rasters).
Rather than manually selecting each daily raster in a month, is there a way to get ArcGIS to select rasters with a common prefix as the input to Raster Calculator? i.e. generate a new raster by averaging all rasters named 'r200001__' (from January 2000).
Ideally, I would like to iterate this process in Model Builder using the Raster Calculator. I'm inexperienced with python coding, but I'm happy to learn if it's the only/best way.
Any advice is appreciated!
Look at using ListRasters and feeding the result into CellStatistics
This has been covered if you want to use scripting which may be easier
https://community.esri.com/message/766189-cell-statistics-with-list-rasters
Scripting will probably be the easiest way to implement this using ListRasters—Help | ArcGIS Desktop and Cell Statistics—Help | ArcGIS Desktop as Steve Lynch already mentioned before.
To give you a head start with some of the code that will be needed, have a look at the snippet below:
lst_ras = ['r20000125', 'r20000126', 'r20000127', 'r20000128',
'r20000129', 'r20000130', 'r20000131', 'r20000201',
'r20000202', 'r20000203', 'r20000204', 'r20000205']
lst_months = list(set([ras[:7] for ras in lst_ras]))
print(lst_months)
for month in lst_months:
ras_names_month = [ras for ras in lst_ras if ras.startswith(month)]
print("month: {} rasters: {}".format(month, ras_names_month))
You will use ListRasters to get a list of raster names. In my example I created a small list manually (see lines 1 to 3). On line 5 I create a list of the month prefixes and print it on line 6. This will yield:
['r200002', 'r200001']
For each month prefix (line 😎 you can get a list of all the day rasters, which is done on line 9. This list is what you will use with the Cell Statistics as first parameter. The result of line 9 is printed on line 10 as yields:
month: r200002 rasters: ['r20000201', 'r20000202', 'r20000203', 'r20000204', 'r20000205']
month: r200001 rasters: ['r20000125', 'r20000126', 'r20000127', 'r20000128', 'r20000129', 'r20000130', 'r20000131']