[GRASS-dev] eval option in r.mapcalc in a python script

Paulo van Breugel p.vanbreugel at gmail.com
Thu Jan 14 15:20:29 PST 2016


On 14-01-16 13:54, Moritz Lennert wrote:
> On 14/01/16 13:05, Paulo van Breugel wrote:
>>>> grass.mapcalc("$out = 0", out=out)
>>>> for i in xrange(len(IN)):
>>>>      grass.mapcalc("$out = $out + log($in)", out=out, in=in[i]),
>>>> overwrite=True
>>>>
>>>
>>> ISTR that modifying the contents of a map in-place might be possible,
>>> but not recommended.
>> I think your solution below is perfectly fine, but out of curiosity, and
>> to get a better grasp of the possible pitfalls, what is the reason the
>> above in-place modification is not recommended?
>
> See Glynn's comment (to you ;-) ) here 
> http://lists.osgeo.org/pipermail/grass-dev/2015-December/077600.html

OK, that is embarrassing (and sorry Glynn, I do try to pay attention). I 
did remember having been point out to this before, but forgot the 
details. But yes, I should have know better than to fall into the same 
pitfall.

>
>>> Maybe one option, as I could image others to have this kind of issue,
>>> would be to add a "modifier" (or similar name) parameter to r.series
>>> which would allow to calculate the statistic defined by "method" on a
>>> modified version of the maps (e.g. squared, square root, log, sin,
>>> cos, etc.).
>>
>> The log in the example above was for illustrative purposes, the real
>> expression is a bit more complex. Nevertheless, I think it would be very
>> useful to have such a modifier, really good idea!
>
> Try the attached patch, which is just a brute-force, proof-of-concept. 
> It would be nicer to solve this with function pointers, but I'm not at 
> ease with that, so I'll leave that to others.
>
> If you would like to see this implemented, I suggest filing an 
> enhancement ticket. You can attach this patch if you want to.
Just create a ticket, many thanks for the patch and helping out on this
>
> Moritz



More information about the grass-dev mailing list