Select to view content in your preferred language

Model Builder/Python: batch raster calculation

5196
11
03-28-2016 01:38 AM
TomHawkins
Deactivated User

I wish to carry out a raster calculation on a batch of rasters.
I want to add rasters by month, as identified by their file name.

I.e. all rasters within the month of January should add together and output a single jan.png/raster file. Then all the rasters within Feb should add together and produce a single FEB.png.

Rather than manually write a new rast calc expression for each month, I would prefer to automate it via either python or modelbuilder.

My plan outline is as follows:

Input Files. 36 Weekly raster files

5jan15-11jan15.png

12jan15-18jan15.png

19jan15-25jan15.png

26jan15-31jan15.png

01feb15-07feb15.png....

Raster operation.

(raster1+raster2+raster3+raster4)/(raster1+raster2+raster3+raster4) = month.png

output. 12 rasters for each month.

jan.png

feb.png

march.png

is it possible to write a python expression or create a modelbuilder which will add rasters by month using their filename?


Current Attempts

I have built a model, however this only runs on the rasters I provide it, requiring me to write a new expression each time. In other words it's the same as manually running raster calculator and writing a new expression for each month, I wish to automate this via modelbuilder.

0 Kudos
11 Replies
curtvprice
MVP Alum

Darren, the Cell Statistics tool would be a lot easier - it has an option to ignore NoData in the calculation, saving you all that work with Con!

CellStatistics(rasters, "SUM", "DATA")

TomHawkins
Deactivated User

Adding to your notes, what I would try to achieve is this

  1. This is a list of month names. 
  2. For each month name, loop through rasters. 
  3. If the raster name contains the month name, add it and save it.
    • output: JAN = (janweek1, janweek2, janweek3, janweek4), FEB = (febweek1,febweek2,febweek3,febweek4)...

  4. For each month, run the set of rasters through the following expression

    • (week1+week2+week3+week4)/(week1+week2+week3+week4) = month.png
    • result: jan.png, feb.png, march.png...
0 Kudos