Dear all,
I have 120 raster maps with the same name pattern: arc_01, arc_02, arc_03, arc_(…), and want to sum all of them in one. I can do it manually by introducing all the raster maps, but, does anyone know any way to do it automatically? Maybe with any expression based on the pattern?
Thanks for the attention.
Miguel,
Do you use Linux or something similar? I can’t test but maybe works on Windows as well with bash shell:
r.mapcalc expression=resultmap=g.list type=raster pattern=arc_0* separator='+'
bye
R
···
2016-09-08 19:13 GMT+02:00 Miguel Carrero <miguel.carrero.pazos@gmail.com>:
Dear all,
I have 120 raster maps with the same name pattern: arc_01, arc_02, arc_03, arc_(…), and want to sum all of them in one. I can do it manually by introducing all the raster maps, but, does anyone know any way to do it automatically? Maybe with any expression based on the pattern?
Thanks for the attention.
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
Hello,
You can use r.series for that and pass the list of maps that you get with g.list directly into r.series using back ticks, or you can also pass a file with all map names. Check the manual for more examples: https://grass.osgeo.org/grass73/manuals/r.series.html
Cheers,
Vero
···
El sept. 8, 2016 7:13 PM, “Miguel Carrero” <miguel.carrero.pazos@gmail.com> escribió:
Dear all,
I have 120 raster maps with the same name pattern: arc_01, arc_02, arc_03, arc_(…), and want to sum all of them in one. I can do it manually by introducing all the raster maps, but, does anyone know any way to do it automatically? Maybe with any expression based on the pattern?
Thanks for the attention.
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
On Thu, Sep 8, 2016 at 1:27 PM, Robert Kuszinger <kuszinger@giscom.hu>
wrote:
Do you use Linux or something similar? I can't test but maybe works on
Windows as well with bash shell:
r.mapcalc expression=resultmap=`g.list type=raster pattern=arc_0*
separator='+'`
Even on Linux, this can fail when the expression is too long (operating
system limits the length of a command), but that's what the file parameter
is for in r.mapcalc. You can save the g.list result to a file, in Bash:
g.list type=raster pattern="elev*" separator='+' >> expression.txt
add whatever else is needed in the expression and then use the file
parameter in r.mapcalc (same idea as what Veronica suggests for r.series):
r.mapcalc file=expression.txt
For simple cases, r.series is just simpler as Veronica suggests.
Vaclav
https://grass.osgeo.org/grass70/manuals/r.mapcalc.html
2016-09-08 12:32 GMT-05:00 Veronica Andreo <veroandreo@gmail.com>:
Hello,
You can use r.series for that and pass the list of maps that you get with
g.list directly into r.series using back ticks, or you can also pass a file
with all map names. Check the manual for more examples:
https://grass.osgeo.org/grass73/manuals/r.series.html
Hello,
Interesting, I always used mapcalc for this. Do you know what are the
advantages of using r.series instead of mapcalc for this type of job?
Laurent
On 09/09/16 17:09, Laurent C. wrote:
2016-09-08 12:32 GMT-05:00 Veronica Andreo <veroandreo@gmail.com>:
Hello,
You can use r.series for that and pass the list of maps that you get with
g.list directly into r.series using back ticks, or you can also pass a file
with all map names. Check the manual for more examples:
https://grass.osgeo.org/grass73/manuals/r.series.html
Hello,
Interesting, I always used mapcalc for this. Do you know what are the
advantages of using r.series instead of mapcalc for this type of job?
It provides a lot of aggregate statistics that would be more complicated in r.mapcalc (at least you would need two calls to r.mapcalc), such as standard deviation, median, etc.
Also, you don't have to construct the formula. Just put a list of map names in a file (this is really useful if you have many maps as otherwise you might go beyond the allowed command line length) and run r.series with the desired indicator.
Moritz
Hi all,
Thanks to everyone for the help. I’ve tried with g.list, and pass a file with all map names in r.mapcalp, but realised that there is a limit on space to sum a high number of maps at the same time. So, I’m going to have a look to r.series.
Cheers,
Miguel.
De: Laurent C.
Enviado: viernes, 9 de septiembre de 2016 16:09
Para: Veronica Andreo
CC: Miguel Carrero; grass-user
Asunto: Re: [GRASS-user] How to sum a hundred of raster maps using r.mapcalc
2016-09-08 12:32 GMT-05:00 Veronica Andreo veroandreo@gmail.com:
Hello,
You can use r.series for that and pass the list of maps that you get with
g.list directly into r.series using back ticks, or you can also pass a file
with all map names. Check the manual for more examples:
https://grass.osgeo.org/grass73/manuals/r.series.html
Hello,
Interesting, I always used mapcalc for this. Do you know what are the
advantages of using r.series instead of mapcalc for this type of job?
Laurent
On Fri, Sep 9, 2016 at 12:18 PM, Miguel Carrero <
miguel.carrero.pazos@gmail.com> wrote:
I’ve tried with g.list, and pass a file with all map names in r.mapcalp,
but realised that there is a limit on space to sum a high number of maps at
the same time.
If you are using the file input instead of the command line and still
hitting some limit, you can check if it is system open files limit [1]. On
Linux, you can check soft limit with [2]:
ulimit -a
which gives 1024 on my system. And check also the hard limit with:
ulimit -aH
which gives 65536 on my system. And then increase the soft limit with:
ulimit -n number
Also, try it with some smaller amount of maps (like 10) to check that the
issue is really in the open file limit (or command line length) not, for
example, in the syntax.
Vaclav
[1]
https://grasswiki.osgeo.org/wiki/Large_raster_data_processing#Number_of_open_files_limitation
[2] https://lists.osgeo.org/pipermail/grass-dev/2014-April/068368.html