[GRASS-user] GRASS 7.0.0 Issues with Object Based Image Analysis

Hey all,

So I’m back to pick your brains… this time with a few questions.

GRASS 7.0.0 on Windows 7

Basically, I am trying to copy the workflow outlined by Martin here (http://translate.google.com/translate?sl=cs&tl=en&js=n&prev=t&hl=en&ie=UTF-8&u=http%3A%2F%2Fgeo.fsv.cvut.cz%2Fgwiki%2F153ZODH%2F_15._cvi%25C4%258Den%25C3%25AD&act=url) but I am having a couple problems.

The first issue I ran into was trying to the python code (about halfway down the page, “for maps in MAPS”). I have changed the parameters so they suit GRASS 7.0 but I still receive this error:

Traceback (most recent call last):
File “C:\Users\Jacob\Desktop\Python\SEG_DB_MAN.py”, line 111, in
column_prefix=‘%s’ % bnum)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 375, in run_command
return handle_errors(returncode, returncode, args, kwargs)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 310, in handle_errors
returncode=returncode)
CalledModuleError: Module run None [‘v.rast.stats’, ‘-c’, ‘map=LE7_2001_SEG’, ‘column_prefix=B1’, ‘method=median’, ‘raster=LE7_ATCORR_2001_B1’] ended with error
Process ended with non-zero return code 1. See errors in the (error) output.

However, when I enter the variables in manually using the Command Console in the GUI (using the exact same inputs), the command runs perfectly. Does anyone know why this would happen?

This is the command line from the GUI

(Thu May 14 13:12:10 2015)
v.rast.stats -c map=LE7_2001_SEG column_prefix=B1 method=median raster=LE7_ATCORR_2001_B1
Processing data (4298 categories)…
Updating the database …
(Thu May 14 13:12:26 2015) Command finished (15 sec)

The second issue is trying to set up the training areas. When I open the vector file in the map display and change the mode to digitizer it crashes when I set the vector file I want to edit. Sometimes it doesn’t crash (per se) just goes totally unresponsive. I can move the windows around but nothing happens when I click any of the buttons up top (specifically Display attributes), and when I go to click back in the Layer Manager then GRASS crashes. Does anyone have experience with this?

It should also be noted that I had the digitizer tool working normally for about ten minutes before it crashed for the first time. I don’t see any error messages either, but maybe I am not looking in the right places?

Any ways, any advice would be welcome!

Thanks,

JDC

On Thu, May 14, 2015 at 2:00 PM, Jake Chila <jake.chila@gmail.com> wrote:

The first issue I ran into was trying to the python code (about halfway down the page, “for maps in MAPS”). I have changed the parameters so they suit GRASS 7.0 but I still receive this error:

Traceback (most recent call last):
File “C:\Users\Jacob\Desktop\Python\SEG_DB_MAN.py”, line 111, in
column_prefix=‘%s’ % bnum)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 375, in run_command
return handle_errors(returncode, returncode, args, kwargs)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 310, in handle_errors
returncode=returncode)
CalledModuleError: Module run None [‘v.rast.stats’, ‘-c’, ‘map=LE7_2001_SEG’, ‘column_prefix=B1’, ‘method=median’, ‘raster=LE7_ATCORR_2001_B1’] ended with error
Process ended with non-zero return code 1. See errors in the (error) output.

Hi, are there any other errors above or elsewhere the output? The actual error messages start with “ERROR:”. (I guess I should add this note to the error message.) Vaclav

HI all,

So I think I figured it out with help from Vaclav. When I launch the script from within the GUI the real errors are displayed in the Command Console. The issue I was having had to do with mislabelled column names; I was using numbers are the first character (my database management skills need some refinement apparently).

Now the script works when I launch it from within the GUI (no error messages in the command line), but when I launch the script from outside of Grass it is giving me grief.

Here is the code I am running:

MAPS = grass.read_command(‘i.group’,
group=‘LE7_SEG’,
flags=‘g’,
quiet=True).splitlines()

for maps in MAPS:

band=maps.split(‘@’,1)[0]

bnum=band[-2:]

grass.run_command(‘v.build’,
map=‘LE7_2001_SEG’,
option=‘build’)

grass.run_command(‘v.rast.stats’,
map=‘LE7_2001_SEG’,
flags=‘c’,
raster=band,
method=‘median’,
column_prefix=‘%s’ % bnum)

grass.run_command(‘v.db.update’,
map=‘LE7_2001_SEG’,
column=‘bright’,
qcolumn=‘bright+%s_median’ %bnum)

grass.run_command(‘v.db.dropcolumn’,
map=‘LE7_2001_SEG’,
column = ‘%s_median’ % bnum)

I have to include the v.build command because, for some reason, the polygon topology needs to be rebuilt every time I try to use it. The code also includes all the environment settings needed to access GRASS which I know work because the script gets past the v.build command and repeatedly fails on the v.rast.stats command.

Thanks,

JDC

···

On Thu, May 14, 2015 at 5:23 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Thu, May 14, 2015 at 2:00 PM, Jake Chila <jake.chila@gmail.com> wrote:

The first issue I ran into was trying to the python code (about halfway down the page, “for maps in MAPS”). I have changed the parameters so they suit GRASS 7.0 but I still receive this error:

Traceback (most recent call last):
File “C:\Users\Jacob\Desktop\Python\SEG_DB_MAN.py”, line 111, in
column_prefix=‘%s’ % bnum)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 375, in run_command
return handle_errors(returncode, returncode, args, kwargs)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 310, in handle_errors
returncode=returncode)
CalledModuleError: Module run None [‘v.rast.stats’, ‘-c’, ‘map=LE7_2001_SEG’, ‘column_prefix=B1’, ‘method=median’, ‘raster=LE7_ATCORR_2001_B1’] ended with error
Process ended with non-zero return code 1. See errors in the (error) output.

Hi, are there any other errors above or elsewhere the output? The actual error messages start with “ERROR:”. (I guess I should add this note to the error message.) Vaclav

Actually, scratch that. The script ran once, but now when I run it from the GUI it doesn’t actually update the table, it just runs through without doing anything.

JDC

···

On Fri, May 15, 2015 at 10:56 AM, Jake Chila <jake.chila@gmail.com> wrote:

HI all,

So I think I figured it out with help from Vaclav. When I launch the script from within the GUI the real errors are displayed in the Command Console. The issue I was having had to do with mislabelled column names; I was using numbers are the first character (my database management skills need some refinement apparently).

Now the script works when I launch it from within the GUI (no error messages in the command line), but when I launch the script from outside of Grass it is giving me grief.

Here is the code I am running:

MAPS = grass.read_command(‘i.group’,
group=‘LE7_SEG’,
flags=‘g’,
quiet=True).splitlines()

for maps in MAPS:

band=maps.split(‘@’,1)[0]

bnum=band[-2:]

grass.run_command(‘v.build’,
map=‘LE7_2001_SEG’,
option=‘build’)

grass.run_command(‘v.rast.stats’,
map=‘LE7_2001_SEG’,
flags=‘c’,
raster=band,
method=‘median’,
column_prefix=‘%s’ % bnum)

grass.run_command(‘v.db.update’,
map=‘LE7_2001_SEG’,
column=‘bright’,
qcolumn=‘bright+%s_median’ %bnum)

grass.run_command(‘v.db.dropcolumn’,
map=‘LE7_2001_SEG’,
column = ‘%s_median’ % bnum)

I have to include the v.build command because, for some reason, the polygon topology needs to be rebuilt every time I try to use it. The code also includes all the environment settings needed to access GRASS which I know work because the script gets past the v.build command and repeatedly fails on the v.rast.stats command.

Thanks,

JDC

On Thu, May 14, 2015 at 5:23 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Thu, May 14, 2015 at 2:00 PM, Jake Chila <jake.chila@gmail.com> wrote:

The first issue I ran into was trying to the python code (about halfway down the page, “for maps in MAPS”). I have changed the parameters so they suit GRASS 7.0 but I still receive this error:

Traceback (most recent call last):
File “C:\Users\Jacob\Desktop\Python\SEG_DB_MAN.py”, line 111, in
column_prefix=‘%s’ % bnum)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 375, in run_command
return handle_errors(returncode, returncode, args, kwargs)
File “C:\Program Files (x86)\GRASS GIS 7.0.0\etc\python\grass\script\core.py”, line 310, in handle_errors
returncode=returncode)
CalledModuleError: Module run None [‘v.rast.stats’, ‘-c’, ‘map=LE7_2001_SEG’, ‘column_prefix=B1’, ‘method=median’, ‘raster=LE7_ATCORR_2001_B1’] ended with error
Process ended with non-zero return code 1. See errors in the (error) output.

Hi, are there any other errors above or elsewhere the output? The actual error messages start with “ERROR:”. (I guess I should add this note to the error message.) Vaclav

Just a python comment. (I’m not sure it will make any difference, but it makes the “run_command” cleaner)
See below:

Set variables for the column names " (from above) " (from above)

···

On 05/15/2015 05:02 PM, Jake Chila wrote:

Actually, scratch that. The script ran once, but now when I run it from the GUI it doesn’t actually update the table, it just runs through without doing anything.

JDC

On Fri, May 15, 2015 at 10:56 AM, Jake Chila <jake.chila@gmail.com> wrote:

HI all,

Here is the code I am running:

MAPS = grass.read_command(‘i.group’,
group=‘LE7_SEG’,
flags=‘g’,
quiet=True).splitlines()

for maps in MAPS:

band=maps.split(‘@’,1)[0]

bnum=band[-2:]

col = bnum+“_median”
qcol = “bright”+col

grass.run_command(‘v.build’,
map=‘LE7_2001_SEG’,
option=‘build’)

grass.run_command(‘v.rast.stats’,
map=‘LE7_2001_SEG’,
flags=‘c’,
raster=band,
method=‘median’,
column_prefix=‘%s’ % bnum)

It seems to me that the ‘%s’ is unnecessary here. bnum should already be a string variable so “column_prefix = bnum” should be fine.

grass.run_command(‘v.db.update’,
map=‘LE7_2001_SEG’,
column=‘bright’,
qcolumn=‘bright+%s_median’ %bnum)

Here just use: "qcolumm = qcol

grass.run_command(‘v.db.dropcolumn’,
map=‘LE7_2001_SEG’,
column = ‘%s_median’ % bnum)

And here "column = col

Thanks,

JDC

On 15/05/15 16:02, Jake Chila wrote:

Actually, scratch that. The script ran once, but now when I run it from
the GUI it doesn't actually update the table, it just runs through
without doing anything.

Before going any further with this, try the new addon: i.segment.stats [1] which does the calculations for you without having to define the loop and dropping excess columns.

Moritz

[1] http://grass.osgeo.org/grass70/manuals/addons/i.segment.stats.html

Hey thanks Moritz!

I will try the i.segment.stats moving forward. Thanks for the ‘heads-up’!

JDC

···

On Mon, May 18, 2015 at 8:20 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 15/05/15 16:02, Jake Chila wrote:

Actually, scratch that. The script ran once, but now when I run it from
the GUI it doesn’t actually update the table, it just runs through
without doing anything.

Before going any further with this, try the new addon: i.segment.stats [1] which does the calculations for you without having to define the loop and dropping excess columns.

Moritz

[1] http://grass.osgeo.org/grass70/manuals/addons/i.segment.stats.html