[GRASS-user] r.neighborhoodmatrix error message

Moritz Lennert mlennert at club.worldonline.be
Tue Mar 7 08:55:03 PST 2017


Hi Michele !

On 07/03/17 17:27, Michele Zurlo wrote:
> Hi I'm Michele and this is my first e-mail in this mailing list and I
> hope to find a little help :-)
> I'm working to classify some UAV images and I would like to follow the
> method proposed by Grippa et al. 2016
> <http://proceedings.utwente.nl/367/1/Grippa-An%20Open-Source%20Semi-Automated%20Processing%20Chain%20For%20Urban%20OBIA%20Classification-28.pdf>
> working with i.segment.uspo
> <https://grass.osgeo.org/grass72/manuals/addons/i.segment.uspo.html>.
> So I downloaded and installed the OSGEO Live 9.5 and from GRASS shell I
> installed i.segment.uspo
> <https://grass.osgeo.org/grass72/manuals/addons/i.segment.uspo.html> and
> the required r.neighborhoodmatrix
> <https://grass.osgeo.org/grass72/manuals/addons/r.neighborhoodmatrix.html>.
> Everything went right but when I try to use i.segment.uspo
> <https://grass.osgeo.org/grass72/manuals/addons/i.segment.uspo.html> I
> get an error message because there is something wrong with
> r.neighborhoodmatrix
> <https://grass.osgeo.org/grass72/manuals/addons/r.neighborhoodmatrix.html>.
> This is the error message retrieved trying to use r.neighborhoodmatrix
> <https://grass.osgeo.org/grass72/manuals/addons/r.neighborhoodmatrix.html>:
>
> #############################
> Traceback (most recent call last):
>   File
> "/home/user/.grass7/addons/scripts/r.neighborhoodmatrix",
> line 137, in <module>
>     main()
>   File
> "/home/user/.grass7/addons/scripts/r.neighborhoodmatrix",
> line 123, in main
>     unique_neighbors_sorted =
> gscript.natural_sort(unique_neighbors)
> AttributeError: 'module' object has no attribute
> 'natural_sort'
> #############################
>
> I tried to re-install the module but I retrieved the same message.
> Someone can help me?

This sounds like OSGeo Live 9.5 contains a version of GRASS GIS that did 
not have this natural_sort in the GRASS Python scripting library, yet.

Is using OSGeo Live 10 an option for you ? This contains GRASS 7.0.4 
which is the first version that contains natural_sort as a utility function.

Otherwise, it is quite easy to introduce it manually in the script. Copy 
the following into 
/home/user/.grass7/addons/scripts/r.neighborhoodmatrix, just before the 
"def cleanup():" line:

def natural_sort(l):
     """Returns sorted strings using natural sort
     """
     convert = lambda text: int(text) if text.isdigit() else text.lower()
     alphanum_key = lambda key: [convert(c) for c in 
re.split('([0-9]+)', key)]
     return sorted(l, key=alphanum_key)

Moritz


More information about the grass-user mailing list