[GRASS-user] r.neighbors - annulus (torus) neighbor

Hi all!

while I need annulus (or torus) neighbor to some of my work I added easily it to neighbors (grass 65 delev) module. Because I do not won't to create a fork of that module I put it on that url:

http://www.staff.amu.edu.pl/~jarekj/r.neighbors2.tar.gz

Annulus neighbor is a circular neighbor but with exuding nearest neighborhood defined by inner radius.

Maybe someones will find this useful.

regards
Jarek

Hi Jarek and r.neighbor maintenators,

I suggest put a flag on r.neighbor for annulus (torus), so in future versions the module will be always update.
Just a suggestion.

Jarek, congrats.

cheers

milton

2010/11/15 Jasiewicz Jarosław <jarekj@amu.edu.pl>

Hi all!

while I need annulus (or torus) neighbor to some of my work I added easily it to neighbors (grass 65 delev) module. Because I do not won’t to create a fork of that module I put it on that url:

http://www.staff.amu.edu.pl/~jarekj/r.neighbors2.tar.gz

Annulus neighbor is a circular neighbor but with exuding nearest neighborhood defined by inner radius.

Maybe someones will find this useful.

regards
Jarek


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Jasiewicz Jarosław wrote:

while I need annulus (or torus) neighbor to some of my work I added
easily it to neighbors (grass 65 delev) module. Because I do not won't
to create a fork of that module I put it on that url:

If you need neighbourhood shape other than a square or circle, use the
weights= option.

Masks can be created using NumPy; e.g.

  from numpy import *
  r = 7 # outer radius
  r0 = 3 # inner radius
  d = sqrt(fromfunction(lambda x, y: (x-r)**2 + (y-r)**2, (2*r+1, 2*r+1)))
  m = logical_and(d >= r0, d <= r)
  savetxt('weights', m, fmt = '%d')

Or for smooth edges:

  from numpy import *
  r = 7 # outer radius
  r0 = 3 # inner radius
  d = sqrt(fromfunction(lambda x, y: (x-r)**2 + (y-r)**2, (2*r+1, 2*r+1)))
  m = minimum(1, maximum(0, (r-r0)/2 - abs(d - (r+r0)/2)))
  savetxt('weights', m, fmt = '% .3f')

If you only need a mask (weights of 0 or 1), you can use anything
which can outupt PGM files (use the P2 "text" format and cut off the
header).

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

Glynn Clements pisze:

Jasiewicz Jaros³aw wrote:

while I need annulus (or torus) neighbor to some of my work I added easily it to neighbors (grass 65 delev) module. Because I do not won't to create a fork of that module I put it on that url:
    
If you need neighbourhood shape other than a square or circle, use the
weights= option.

Masks can be created using NumPy; e.g.

  from numpy import *
  r = 7 # outer radius
  r0 = 3 # inner radius
  d = sqrt(fromfunction(lambda x, y: (x-r)**2 + (y-r)**2, (2*r+1, 2*r+1)))
  m = logical_and(d >= r0, d <= r)
  savetxt('weights', m, fmt = '%d')

Or for smooth edges:

  from numpy import *
  r = 7 # outer radius
  r0 = 3 # inner radius
  d = sqrt(fromfunction(lambda x, y: (x-r)**2 + (y-r)**2, (2*r+1, 2*r+1)))
  m = minimum(1, maximum(0, (r-r0)/2 - abs(d - (r+r0)/2)))
  savetxt('weights', m, fmt = '% .3f')

If you only need a mask (weights of 0 or 1), you can use anything
which can outupt PGM files (use the P2 "text" format and cut off the
header).

yes, but for me modification of C code was little simpler than this.
cheers
Jarek

Milton Cezar Ribeiro wrote:

I suggest put a flag on r.neighbor for annulus (torus), so in future
versions the module will be always update.

A flag alone isn't sufficient; it would also need an option for the
inner radius.

In general, we try to avoid adding options for features which can be
accomplished by a separate program. The selection= option was only
added because the alternative (applying the mask afterwards) could be
significantly slower.

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