I have a directory folder of precipitation data; within this folder are subfolders for years 1901-2014. In each of these subfolders are 12 .asc grid files; each file represents a month of the year (i.e. Jan through Dec).
I am trying to create a model that will iterate through each of these subfolders and perform a calculation on the 12 grid files (for example: calculate total annual precipitation). I may want to perform other calculations, but for now would like to just have the model working.
I have tried the Iterate Workspace function with the Raster Calculator, and the Iterate Rasters function with the Raster Calculator, but could not get either to work how I wanted.
I also tried Iterate Rasters with Collect Values, and Cell Statistics – but that is also not working.
Below are the models I have tried:
Best Answer
When faced with a problem like this I use
os.walk()
which returns all files and then see if the files match what I want by extension, here's an example for shapefiles:Change
fExt.upper() == ".SHP":
tofExt.upper() == ".ASC":
and then operate as normal withfc
being the full path to the dataset.The other option is to put all the rasters in manually... or semi manually:
Open a command prompt in your base folder and type:
Which gives a list of all the ASCII files in all subfolders... if there's too many to select then try piping to a text file:
Then select all, copy, and paste into the tool.