[GRASS-user] help with r.series

Glynn Clements glynn at gclements.plus.com
Thu Sep 4 13:41:39 PDT 2014


Rajat Nayak wrote:

> I have created a few list using g.mlist command in grass7. Each list has a
> few raster layers. For example; FILE2000 has lists of all monthly layers
> for the year 2000, FILE2001 has layers for 2001...so on.
> Now I want to create one layer each  for each of these lists (each year). I
> can use "r.series" command with method="average", to get a layer with
> averaged values across all the months for a particular year. Now I have 14
> such lists corresponding to 14 years and do not want to repeat the process
> for each year. Is there a way to automate this process using grass prompt?
> I don't want to move to R, would like to complete all the work in GRASS.

bash:
	for file in FILE20?? ; do
	    r.series file=$file output=output${file#file} method=average
	done

Python:
	import os
	import grass.script as grass
	for file in os.listdir('.'):
	    if not file.startswith('FILE20'):
	        continue
	    output = 'output' + file[4:]
	    grass.run_command('r.series', file=file, output=output,
	                      method='average')

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list