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

Moritz Lennert mlennert at club.worldonline.be
Thu Jan 14 04:54:58 PST 2016


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

>> 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.

Moritz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: r_series_modifier.diff
Type: text/x-patch
Size: 1742 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20160114/a2b7f8ac/attachment.bin>


More information about the grass-dev mailing list