[GRASS-user] help with r.series
Pietro
peter.zamb at gmail.com
Thu Sep 4 05:35:42 PDT 2014
Hi Rajat,
On Thu, Sep 4, 2014 at 1:51 PM, Rajat Nayak <rajat27404 at gmail.com> 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.
Yes you can do it, using BASH or python, personally I prefer/use python.
A possible solution for grass6/7 could be something like:
{{{
from grass import script
# define the pattern to select the maps that will be aggregate
PATTERNS = ('rast2001*', 'rast2002*', 'rast2003*') # etc.
# define the name of the output names
OUTPUTS = ('out2001', 'out2002', 'out2003')
# start a cycle for each pattern and for each output
for pattern, output in zip(PATTERNS, OUTPUTS):
# get the list of input maps
inputs = script.mlist_strings('rast', pattern=pattern)
# run your command
script.run_command('r.series', input=inputs, output=output,
method='average')
}}}
More information about the grass-user
mailing list