Opened 9 years ago

Last modified 5 years ago

#2665 new defect

d.* modules not working from python or bash scripts (GRASS 7.0, Linux / Windows7)

Reported by: santipardo Owned by: grass-dev@…
Priority: minor Milestone: 7.6.2
Component: Display Version: 7.0.0
Keywords: d.mon, d.vect, d.rast, python, script, bash Cc:
CPU: x86-64 Platform: All

Description

(I copy here this question from GIS.stackexhange, related to a possible bug when calling d.* modules from a script)

Do d.* commands from GRASS GIS 7.0 run from a python script? I'm trying with this code:

import grass.script as grass

grass.run_command('d.mon', start="wx3", resolution = '1')
grass.run_command('d.mon', select="wx3")
grass.run_command('d.rast', map="M01relief")
grass.run_command('d.mon', select="wx3")
grass.run_command('d.vect', map="M03PTEtramos", color="black",  width='2')

When executing the complete script, the wx3 monitor starts, but remains empty. However, if I paste the commands one by one in GRASS Python Command-line, I get the layers drawn in the monitor. And using Cairo driver, I also get the layers drawn in a PNG file (directly from the script).

In the aforementioned Python code, the monitor seems not to apply the code, because if I check for the monitor commands, I get no info:

grass.run_command('d.mon', flags="c")
[Empty output]

(The monitor wx3 opens and remains empty)

Using a Bash script, the monitor is again empty:

d.mon start=wx3 resolution=1
d.rast map=M01relief
d.vect map=M03PTEtramos color=black width=2
d.redraw

But if I ask then for the list of commands I get results:

d.mon -c
Enlistar comandos para el monitor <wx3>:
d.rast map="M01relief" bgcolor="white"
d.vect map="M03PTEtramos" layer="1" display="shape" type="point,line,boundary,area,face" color="black" fill_color="200:200:200" width=2 width_scale=1 icon="basic/x" size=5 label_layer="1" label_color="red" label_bgcolor="none" label_bcolor="none" label_size=8 xref="left" yref="center"

Actually, doing d.redraw from command line (not from the script), shows the map.

The problem happens both in Linux Mint 64 bits and Windows7 64 bits (the second running in a VirtualBox machine)

Change History (11)

comment:1 by santipardo, 9 years ago

This is weird. The commands are written to the cmd file of the monitor (e.g.: .tmp/24518.0.cmd):

d.rast map="M01relief" bgcolor="white"
d.vect map="M03PTEtramos" layer="1" display="shape" type="point,line,boundary,area,face" color="black" fill_color="200:200:200" width=2 width_scale=1 icon="basic/x" size=5 label_layer="1" label_color="red" label_bgcolor="none" label_bcolor="none" label_size=8 xref="left" yref="center"

But I do not get the layers shown until I manually open the file (in a text editor) and save it. Using some python code to open, edit and save the trick doesn't work:

with open(rutamon, 'a') as comandos:
        comandos.write('d.redraw')
        comandos.close()

Here I open the file in append mode, and add a line for 'd.redraw'. But it doesn't work, I have to open and save manually the file...

comment:2 by santipardo, 9 years ago

PROVISIONAL WORKAROUND: I have found that if I open a second monitor after the first, the layers are shown:

grass.run_command('d.mon', start="wx3", resolution = '2')
grass.run_command('d.rast', map="M01relief",  overwrite="true")
grass.run_command('d.mon', start="wx0", resolution = '1')
grass.run_command('d.rast', map="M01relief",  overwrite="true")
grass.run_command('d.mon', select="wx3")
grass.run_command('d.redraw', verbose="true")

With this code, I get an empty "wx0" monitor, and a "wx3" monitor showing my layers. But I need that second 'ghost' monitor, which is not very elegant... Any help with this is welcome.

comment:3 by santipardo, 9 years ago

Priority: normalminor

comment:4 by neteler, 9 years ago

Milestone: 7.0.17.0.2

Ticket retargeted after 7.0.1 milestone closed

comment:5 by neteler, 8 years ago

Milestone: 7.0.27.0.3

Ticket retargeted after milestone closed

comment:6 by neteler, 8 years ago

Milestone: 7.0.3

Ticket retargeted after milestone closed

comment:7 by neteler, 8 years ago

Milestone: 7.0.4

Ticket retargeted after 7.0.3 milestone closed

comment:8 by martinl, 8 years ago

Milestone: 7.0.47.0.5

comment:9 by neteler, 7 years ago

Milestone: 7.0.57.0.6

comment:10 by neteler, 6 years ago

Milestone: 7.0.67.0.7

comment:11 by martinl, 5 years ago

Milestone: 7.0.77.6.2
Note: See TracTickets for help on using tickets.