[GRASS-user] Re: Trying python scripts.

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Thu May 27 14:29:09 EDT 2010


Marcello Gorini wrote:
[...]
> >>> ... I am trying to run the first examples found in 
> >>> http://grass.osgeo.org/wiki/GRASS_and_Python.

--%<---
a script was here - look first post !
--->%--

> >>> It seems to run OK and “100%” is displayed in the GRASS prompt, but
> >>> when I tried to display the map, I found out that it wasn't created at
> >>> all.

Nikos Alexandris:
> >> If there are no errors and the script ran fine, maybe you just need to
> >> check the region settings?

> >>> Just for you to know, to run the script I simply create it (say
> >>> "myscript.py"), give permissions and run it in a GRASS session with the
> >>> necessary options:
> >>> > ./myscript.py output=outmap raster1=map1 raster2=map2

> >>> I am using Ubuntu 9.04 64bits and GRASS 6.4.ORC5.

> >> For example:
> >> # check region extent, etc.
> >> g.region -p
> >> 
> >> # set region extent and resolution to the map of your interest
> >> g.region rast=outmap -pa
> >> 
> >> # give color
> >> r.colors rast=outmap color=rainbow
> >> 
> >> # try to display
> >> d.mon x0 && d.rast outmap
> >> 
> >> # is it there?

Marcello Gorini: 
> >> No, it is not there. To make sure I set the region to the input map:
> >> 
> >> g.region rast=map1 -pa
> >> d.mon x0 && d.rast map1

> >> OK, it is there. Then I ran the script:
> >> ./myscript.py output=outmap raster1=map1 raster2=map2

> >> After processing, I tried:
> >> d.rast outmap

> >> But then:
> >> ERROR: Raster map <outmap> not found

> >> What could be wrong?

Marcello, not sure why it does not work for you. I (copied over the script 
from the 1st post in this thread as test_mapcalc.py, added +x to make it 
executable) and it works fine for me:

# test run
python test_mapcalc.py raster1=mod_b2 raster2=mod_b2_new 
output=testing_mapcalc_python_script

# r.info on inputs and the output

# mod_b2
r.info -r mod_b2

min=0
max=5504

# mod_b2_new
r.info -r mod_b2_new

min=0
max=0.5504

# output
r.info -r testing_mapcalc_python_script

min=0
max=5504.5504


> >> P.S.: By the way, is this the right way to quote answers?

Like (almost) always, it depends whom you are asking ;-). There are so many 
ways and opinions and habits and... (you can scan the archive or other mailing 
lists and you'll find that people even argue seriously about the "correct" way 
to reply).

Personally I got stuck with _clean_ in-line bottom posting because I find it 
so useful when I read older threads and understand what has been discussed and 
get to the point right away.

I prefer to invest time and clean-out un-necessary stuff (taking though 
sometimes the risk to reject parts that are important?) and give a logical 
flow to the discussion (first the question, then the answer) in order to make 
it easier for any (next) reader.

Regards, Nikos


More information about the grass-user mailing list