[GRASS-user] problems with r.neighborhoodmatrix

Moritz Lennert mlennert at club.worldonline.be
Thu Feb 22 02:34:13 PST 2018

Hello Gra,

On 21/02/18 16:49, Gra wrote:
> I have this error with r.neighborhoodmatrix
> could you help?
> thanks
> Traceback (most recent call last):
>    File
> "/home/zuliagr/.grass7/addons/scripts/r.neighborhoodmatrix",
> line 190, in <module>
>      main()
>    File
> "/home/zuliagr/.grass7/addons/scripts/r.neighborhoodmatrix",
> line 150, in main
>      for line in heapq.merge(*[decorated_file(f, keyfunc) for
> f in files]):
>    File "/usr/lib/python2.7/heapq.py", line 376, in merge
>      h_append([next(), itnum, next])
>    File
> "/home/zuliagr/.grass7/addons/scripts/r.neighborhoodmatrix",
> line 96, in decorated_file
>      yield (key(line), line)
>    File
> "/home/zuliagr/.grass7/addons/scripts/r.neighborhoodmatrix",
> line 92, in keyfunc
>      return [int(x) for x in s.split(separator)[:2]]
> ValueError: invalid literal for int() with base 10:
> '0-0.003922'

The value 0-0.003922 seems to indicate that you are not using an integer 
map. Calculating a neighborhood matrix only makes sense for clearly 
defined objects and this implies an identification with integer ids 
(such as the ones coming out of r.clump or i.segment).

To make sure this is the problem, please send us the r.info output on 
your input map.

I just committed a revised version of the addon which checks the map 
type and gives a fatal error if it is not the expected integer type. 
Reinstall the extension and tell us what you get.

BTW, you sent me a private mail [please don't do that: mails should 
always go to the list] concerning an error in r.object.spatialautocor 
where you also have an error in r.neighborhoodmatrix, using the 
following command:

> r.object.spatialautocor ob=maskAT001L2_50 var=RPnAT001L2 at in_data method=moran   
> maskAT001L2_50 = raster map value 1
> RPnAT001L2 = my variable

I suspect the reason for the error is similar, but to make sure, please 
send the output of

r.info maskAT001L2_50


More information about the grass-user mailing list