[GRASS-dev] Re: [GRASS-user] i.spectral.py in WinGrass

Daniel Victoria wrote:

You are right Glynn, I just checked i.spectral.py and it has the
d.linegraph feature but, i.spectral is greyed out in wxpython gui

That's a bug in the wxGUI. All scripts will be greyed out on Windows.

[For grass-dev]

The bug is in GetGRASSCmds in globalvar.py. It checks whether the last
4 characters of the filename are '.exe' or '.py'. As '.py' is only 3
characters, it will never match. The code should be using
os.path.splitext().

and,
when I try to run it from the command line (using Msys wingrass7svn),
if I input a raster group I get the error:

The output format for "i.group -l ..." was changed in r34815, which
breaks the script. I'll change it to use "i.group -g ..." instead.

If I try to run it using the raster options I don't get any errors but
nothing is displayed to the screen.

That's to be expected. 7.0 doesn't support display monitors. All d.*
commands generate an image in the file specified by $GRASS_PNGFILE, or
map.png if that variable isn't set. Check whether a file named map.png
was created.

You can have the output displayed within the wx GUI by adding a
command layer for the i.spectral command.

Alternatively, you can try the wxpyimgview script (not tested on
Windows, assumes that you're using bash as the shell):

  export GRASS_PNGFILE=map.bmp
  export GRASS_PNG_MAPPED=TRUE
  d.erase
  wxpyimgview map.bmp &

Running from the command console in wxgui I get:

ImportError: No module named collections

It looks as though I don't have the collections module?

That seems to be a common issue with Python on Windows. FWIW, the
stock Python 2.6.4 installer for Windows does include this module.

But fixing that probably won't let you run i.spectral from the GUI's
command prompt. The last time I checked, "display" commands were
handled by checking that the program name begins with "d.", so it
won't work with i.spectral. Renaming the installed script to
d.spectral.py may work (once the bug mentioned above is fixed).

But ideally, the command prompt should set GRASS_PNGFILE to a
temporary filename then check whether the file was created. That will
handle all display commands, regardless of how they're named.

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

Hi,

2010/12/8 Glynn Clements <glynn@gclements.plus.com>:

The bug is in GetGRASSCmds in globalvar.py. It checks whether the last
4 characters of the filename are '.exe' or '.py'. As '.py' is only 3
characters, it will never match. The code should be using
os.path.splitext().

fixed in r44691.

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Hi,

2010/12/8 Glynn Clements <glynn@gclements.plus.com>:

ImportError: No module named collections

It looks as though I don't have the collections module?

That seems to be a common issue with Python on Windows. FWIW, the
stock Python 2.6.4 installer for Windows does include this module.

the problem has been report on trac [1], closed without any clue.

Martin

[1] http://trac.osgeo.org/osgeo4w/ticket/182

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

2010/12/23 Martin Landa <landa.martin@gmail.com>:

[...]

the problem has been report on trac [1], closed without any clue.

hm, it seems to be bug in GRASS windows installer, sorry for noise.

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Hi,

2010/12/23 Martin Landa <landa.martin@gmail.com>:

2010/12/23 Martin Landa <landa.martin@gmail.com>:

[...]

the problem has been report on trac [1], closed without any clue.

hm, it seems to be bug in GRASS windows installer, sorry for noise.

seems to be really mismatch of python versions. The test script
(below) is run by

C:\Program Files (x86)\GRASS-70-SVN\extrabin\python.exe (GRASS_PYTHON)

g.parser runs menuform.py - also by GRASS_PYTHON

them `r.test.py --interface-description` (called from menuform.py) is
run by another version of Python

C:\Python26\ArcGIS10.0\python.exe

...no clue why.

Martin

===

#!/usr/bin/env python

#%Module
#% description: Creates a raster map showing buffer zones surrounding
cells that contain non-NULL category values.
#%End
#%Option
#% key: input
#% type: string
#% required: yes
#% multiple: no
#% key_desc: name
#% description: Name of input raster map
#% gisprompt: old,cell,raster
#%End

import sys

print >> sys.stderr, sys.executable

import grass.script as grass

grass.parser()

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Martin Landa wrote:

>> the problem has been report on trac [1], closed without any clue.
>
> hm, it seems to be bug in GRASS windows installer, sorry for noise.

seems to be really mismatch of python versions. The test script
(below) is run by

C:\Program Files (x86)\GRASS-70-SVN\extrabin\python.exe (GRASS_PYTHON)

g.parser runs menuform.py - also by GRASS_PYTHON

them `r.test.py --interface-description` (called from menuform.py) is
run by another version of Python

C:\Python26\ArcGIS10.0\python.exe

...no clue why.

Executing a Python script will use whichever program is associated
with the .py extension.

When the GUI runs a command with the --interface-description flag, or
when it runs it for real, it doesn't care whether it's a binary
executable, a Python script or whatever, it just executes it.

It shouldn't matter that scripts don't use the same version of Python
as the GUI. All that matters is that the system has Python installed
correctly. However: if the command is being run with e.g. PYTHONHOME
or PYTHONPATH referring to the "bundled" version, you're likely to run
into problems.

As 7.0 includes Python *scripts* (as opposed to the wx GUI), any
packaging of 7.0 shouldn't attempt to "bundle" Python; that cannot be
made to work. Executing a Python script (via system, _spawn(),
CreateProcess() etc) will use the file associations from the registry,
and the GRASS installer must not change those as that would interfere
with any other use of Python on the system.

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

Hi all,

Maybe this could be a Xmas whish...

Is there a way to have i.spectral work like the "query raster value"
comand from the display window? I mean, whenever I click on any place
on the raster, i.spectral would draw the spectral profile of a raster
group?

Cheers and a great new year to all grass users

Daniel

On Thu, Dec 23, 2010 at 8:56 PM, Martin Landa <landa.martin@gmail.com> wrote:

2010/12/23 Martin Landa <landa.martin@gmail.com>:

[...]

the problem has been report on trac [1], closed without any clue.

hm, it seems to be bug in GRASS windows installer, sorry for noise.

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa