[GRASS-user] usage of r.mapcalc in python script

Hi All,

please any python programmer could explain me the correct use of r.mapcalc in this case.
In my python script I have a formula like this:

n = 0.016 * (resolution ** 0.46)

(resolution is the cellsize of the input map).
and I have to calculate a map with:

grass.mapcalc(“mti = log((exp($rast1 , n)) / $rast2)”, rast1 = ‘r_accumulation’, rast2 = ‘r_slope’)

but since n is not a map, i get the error:

Invalid map
Parse error
ERROR: An error occurred while running r.mapcalc

How can I use the ‘n’ in r.mapcalc?

Thank you in advance,

Margherita

Margherita Di Leo wrote:

Hi All,

please any python programmer could explain me the correct use of r.mapcalc
in this case.
In my python script I have a formula like this:

n = 0.016 * (resolution ** 0.46)

(resolution is the cellsize of the input map).
and I have to calculate a map with:

grass.mapcalc("mti = log((exp($rast1 , n)) / $rast2)", rast1 =
'r_accumulation', rast2 = 'r_slope')

Try
grass.mapcalc("mti = log((exp($rast1 , $n)) / $rast2)", rast1 =
'r_accumulation', rast2 = 'r_slope', n = n)

Markus M

but since n is not a map, i get the error:

Invalid map <n>
Parse error
ERROR: An error occurred while running r.mapcalc

How can I use the 'n' in r.mapcalc?

Thank you in advance,

Margherita

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

It works! Thanks a lot.

Margherita

Try

grass.mapcalc(“mti = log((exp($rast1 , $n)) / $rast2)”, rast1 =

‘r_accumulation’, rast2 = ‘r_slope’, n = n)

Markus M