[GRASS-user] use of g.list inside r.mapcalc expression

Veronica Andreo veroandreo at gmail.com
Wed Jun 15 07:17:20 PDT 2016


Cool!
Thanks my friend!

A slightly modified version did the trick! My previous attempt included a
bunch of nested for loops that took forever :-/

map=`g.list rast pat=MOD13Q1*_NDVI`
for m in ${map}; do
    i=`echo $m | cut -c 1-23`
    echo $m $i
    r.mapcalc --o \
    expression="${m} = if("${i}"_pixel_reliability == 0, ${m}, null())"
done

Cheers!
Vero

2016-06-15 10:36 GMT-03:00 Sajid Pareeth <spareeth at gmail.com>:

> Hi Vero
>
> If I got you right, may be this could be a better approach,
> #Assuming you are using MOD13Q1 product, and for example maps from
> MOD13Q1.A2015353.h18v05.006.2016007180711.hdf;
>
> map=`g.list rast pat=MOD13*_EVI`
> for tile in ${map}; do
>     ## Put the common part (In this case - MOD13Q1.A2015353.h18v05) of the
> map name into a variable.
>     i=`echo $map|cut -c1-23`
>     r.mapcalc --o expression="${map} = if(${i}_pixel_reliability` == 0,
> ${map}, null())"
> done
>
>
> Sajid
>
>
> On Wed, Jun 15, 2016 at 2:58 PM, Veronica Andreo <veroandreo at gmail.com>
> wrote:
>
>> Hello everybody,
>>
>> Is it possible to use r.mapcalc with `g.list` as part of the
>> expression??? Something like:
>>
>> tiles=(h11v11 h12v11 h12v12)
>> for tile in ${tiles[*]}
>> do
>> r.mapcalc --o expression="`g.list rast pat=MOD13*$tile_EVI` =
>> if(`g.list rast pat=MOD13*$tile_pixel_reliability` == 0, `g.list rast
>> pat=MOD13*$tile_EVI`, null())"
>> done
>>
>> it worked only once in a test case with one image per tile... when I
>> tried to run it again for the whole set, i get parse error:
>>
>> syntax error, unexpected ';', expecting '('
>> syntax error, unexpected ';', expecting ')'
>> Parse error
>> ERROR: parse error
>>
>> Which would be best practice in this case? Is this use even possible?
>>
>> I know I can register maps in temporal framework and use
>> t.rast.mapcalc, but I want to keep year and doy in mapnames and
>> neither t.rast.mapcalc nor t.rast.algebra have granularity suffix
>> option yet (only numerical suffix).
>>
>> Ah, I use grass trunk (7.3) freshly updated to r68692.
>>
>> thanks much in advance!
>>
>> Vero
>> _______________________________________________
>> grass-user mailing list
>> grass-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-user
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20160615/06a58072/attachment.html>


More information about the grass-user mailing list