[GRASS-user] mapcalc problem in python script!!

Hello again,

just to give you some more information on my problem:
I am running exactly following script:

---------------------------------------------------------------
import sys
import os
import atexit

import grass.script as grass
import grass.script.setup as gsetup

# set mapset/location/dbase/gisbase
gisbase = os.environ['GISBASE'] = "C:/Program Files (x86)/GRASS 6.5"

sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))

gisrc = gsetup.init('C:/Program Files (x86)/GRASS 6.5', 'C:\Users\XY\Documents\Grass GIS', 'Treene_Location', 'Treene')

def cleanup():
    pass

def main():
    grass.mapcalc("$upstream_shreve = ${upstream_part}+${shreve}",
                  upstream_shreve = options['upstream_shreve'],
                  upstream_part = options['upstream_part'],
                  shreve = options['shreve'])
    return 0

if __name__ == "__main__":
    options, flags = grass.parser()
    atexit.register(cleanup)
    sys.exit(main())
-------------------------------------------------------------

and I get following error back from python:
-------------------------------------------------------------
Traceback (most recent call last):
  File "C:/Users/Johannes Radinger/Documents/Pyhton Scripts/test3.py", line 40, in <module>
    sys.exit(main())
  File "C:/Users/Johannes Radinger/Documents/Pyhton Scripts/test3.py", line 32, in main
    upstream_shreve = options['upstream_shreve'],
KeyError: 'upstream_shreve'
------------------------------------------------------------

hopefully you can help me why there is an error...

cheers
Johannes

On 02/01/2011 03:28 PM, Johannes Radinger wrote:
> Hello,
>
> I am running GRASS GIS 6.5 and want to run a python script
> including a mapcaluculator-expression of a simple formula:
>
> A=if(B,C)
>
> grass.mapcalc("$upstream_shreve = if(${upstream_part},${shreve})",
> upstream_shreve = options['upstream_shreve'],
> upstream_part = options['upstream_part'],
> shreve = options['shreve'])
>
> but that isn't working... I don't know whats excaclty the problem....

I don't know anything about python, but I had a similar problem under R,
where the problem was escaping of the formula - the formula needed to be
enclosed in " in grass.
To diagnose: can you see the command executed under GRASS? Does it work
if you paste this into GRASS?

Cheers,

Rainer

hello,

I still don't know whats the exact problem. And it is not directly possible to paste it into GRASS as the options command is processed by
the g.parser module in the end of my script. That's sofar as I understand...

I am not sure if something is wrong with ' and " or with the options-commands. According to the manual (http://grass.osgeo.org/wiki/GRASS_and_Python#Example_for_embedding_r.mapcalc_.28map_algebra.29)
it should work that way...

hopefully someone can help me...

cheers
johannes

>
> hopefully you can help me
>
> thanks
> Johannes

- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel: +33 - (0)9 53 10 27 44
Cell: +27 - (0)8 39 47 90 42
Fax (SA): +27 - (0)8 65 16 27 82
Fax (D) : +49 - (0)3 21 21 25 22 44
Fax (FR): +33 - (0)9 58 10 27 44
email: Rainer@krugs.de

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

Johannes Radinger wrote:

Somehow I didn't your answer via email, I just found it at
http://permalink.gmane.org/gmane.comp.gis.grass.user/38530

For whatever reason, GMX doesn't like my IP address, and bounces my
emails. The problem is compounded by a "feature" of the mailing list
software which (by default) doesn't send messages to any subscriber
whose email address appears in the To or CC fields (on the assumption
that they'll already get a copy). You can (and probably should)
disable this feature in your preferences (via the link at the bottom
of the email).

just to give you some more information on my problem:
I am running exactly following script:

def main():
    grass.mapcalc("$upstream_shreve = ${upstream_part}+${shreve}",
                  upstream_shreve = options['upstream_shreve'],
                  upstream_part = options['upstream_part'],
                  shreve = options['shreve'])
    return 0

if __name__ == "__main__":
    options, flags = grass.parser()

grass.parser() needs to know the valid options for the script. These
are specified by comments beginning with "#%". See any existing script
for reference.

Then, you need to run the script with the appropriate command line
options. I'm assuming that isn't happening, because you should get an
error if you provide an unrecognised option (and there are no
recognised options).

--
Glynn Clements <glynn@gclements.plus.com>

Dear all

Does anyone have a tutorial or an example of how to create heatmaps or
hotspots based on point density in GRASS.

I tried to use v.kernel but not sure what some of the parameters mean?
v.neighbor is straight forward but the output map is very coarse.

Cheers
Sab

On Friday, February 04, 2011, razmjooeis@faunalia.co.uk wrote:

Dear all

Does anyone have a tutorial or an example of how to create heatmaps or
hotspots based on point density in GRASS.

I tried to use v.kernel but not sure what some of the parameters mean?
v.neighbor is straight forward but the output map is very coarse.

Hi,

v.kernel is the way to go, however its output will depend on a couple things:

1. region settings
2. the size of the kernel (in terms of standard deviation)
3. obviously, the point density

tinker around with those, starting with the region settings (e.g. the
resolution), then tinker with the standard deviation (in map units) option.

Cheers,
Dylan

Glynn Clements wrote:

> Somehow I didn't your answer via email, I just found it at
> http://permalink.gmane.org/gmane.comp.gis.grass.user/38530

For whatever reason, GMX doesn't like my IP address, and bounces my
emails.

... so there's not much point in emailing me off-list, as I cannot
reply to your mails.

--
Glynn Clements <glynn@gclements.plus.com>