[GRASS-dev] [GRASS GIS] #2400: r.reclass.area: add option to use -d flag

#2400: r.reclass.area: add option to use -d flag
-------------------------+--------------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Python | Version: svn-trunk
Keywords: | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
See above

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use -d flag
----------------------------+-----------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Python | Version: svn-trunk
Keywords: r.reclass.area | Platform: Unspecified
      Cpu: Unspecified |
----------------------------+-----------------------------------------------
Changes (by hamish):

  * keywords: => r.reclass.area

Comment:

what would this -d flag do?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2400#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
----------------------------+-----------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Python | Version: svn-trunk
Keywords: r.reclass.area | Platform: Unspecified
      Cpu: Unspecified |
----------------------------+-----------------------------------------------

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2400#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
----------------------------+-----------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Keywords: r.reclass.area | Platform: All
      Cpu: Unspecified |
----------------------------+-----------------------------------------------
Changes (by neteler):

  * platform: Unspecified => All
  * milestone: => 7.0.0

Comment:

In r.clump it is:

{{{
-d
     Clump also diagonal cells
     Clumps are also traced along diagonal neighboring cells
}}}

At time there is in r.reclass.area

{{{
-c
     Input map is clumped
}}}

How would you describe the potential -d flag here (and perhaps modify
the -c description)?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2400#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
----------------------------+-----------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Keywords: r.reclass.area | Platform: All
      Cpu: Unspecified |
----------------------------+-----------------------------------------------

Comment(by peifer):

Maybe I am just plain stupid, but my simple idea was that r.reclass.area
should have an option to use r.clump's rather recently introduced -d flag.
Only in cases where the map is NOT pre-clumped, of course. Updated
descriptions could be:

-c
     Input map is already clumped. Flags -c and -d are mutually exclusive.

-d
     Area size of generated clumps includes diagonally neighboring cells.
Flags -d and -c are mutually exclusive.

The above enhancement would avoid that one has to pre-clump separately, in
case one is interested in diagonal neighbors.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2400#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
----------------------------+-----------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Keywords: r.reclass.area | Platform: All
      Cpu: Unspecified |
----------------------------+-----------------------------------------------

Comment(by neteler):

Your idea is pretty clear! We just need to find the least confusing flag
descriptions, that's all...

The part of "Flags -c and -d are mutually exclusive" will go into the
Python script itself.

{{{
-c Input map is already clumped

-d Area size of generated clumps includes diagonally neighboring cells
}}}

I am not sure if the difference between -c and -d is already obvious.
And I thought that the proposed -d should correspond to that of r.clump in
its behaviour?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2400#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
----------------------------+-----------------------------------------------
Reporter: peifer | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Keywords: r.reclass.area | Platform: All
      Cpu: Unspecified |
----------------------------+-----------------------------------------------

Comment(by peifer):

Replying to [comment:5 neteler]:
> I am not sure if the difference between -c and -d is already obvious.
> And I thought that the proposed -d should correspond to that of r.clump
in
> its behaviour?

Of course. My wording was bad. My thought was that people using
r.reclass.area focus more on the size limit. For them, the clumping is
only and intermediate step towards applying an area size filter. Why not
blindly copying the text from r.clump (which is a bit repetitive in
itself, though):

{{{
-d Clump also diagonal cells
     Clumps are also traced along diagonal neighboring cells
}}}

PS, and somewhat beyond the enhancement request in this ticket:
What would be really neat for experimenting with different area sizes:
r.clump would write the area size in px into the category labels and
r.reclass would be able to use the size values from there. One would clump
once only and could check the effects of various rules (by reclassifying
unwanted size classes to NULL).

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2400#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: worksforme | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by peifer):

  * status: new => closed
  * resolution: => worksforme

Comment:

I'm no Python programmer or anything, but dared to do the below changes in
the current source code. My local r.reclass.area now works as expected, so
I will close this ticket.

{{{
--- r.reclass.area.org 2014-09-07 14:56:32.000000000 +0200
+++ r.reclass.area 2014-09-07 15:06:12.000000000 +0200
@@ -54,6 +54,11 @@
  #% description: Input map is clumped
  #%end

+#%flag
+#% key: d
+#% description: Clumps include diagonal neighbors
+#%end
+
  import sys
  import os
  import atexit
@@ -68,6 +73,7 @@
      greater = options['greater']
      outfile = options['output']
      clumped = flags['c']
+ diagonal = flags['d']

      s = grass.read_command("g.region", flags='p')
      kv = grass.parse_key_val(s, sep=':')
@@ -88,6 +94,9 @@
      if not grass.find_file(infile)['name']:
          grass.fatal(_("Raster map <%s> not found") % infile)

+ if clumped and diagonal:
+ grass.fatal(_("flags c and d are mutually exclusive"))
+
      if clumped:
          clumpfile = infile
      else:
@@ -98,9 +107,14 @@
              if grass.find_file(clumpfile)['name']:
                  grass.fatal(_("Temporary raster map <%s> exists") %
clumpfile)

- grass.message(_("Generating a clumped raster file ..."))
- grass.run_command('r.clump', input=infile, output=clumpfile)

+ if diagonal:
+ grass.message(_("Generating a clumped raster file including
diagonal neighbors..."))
+ grass.run_command('r.clump', flags='d', input=infile,
output=clumpfile)
+ else:
+ grass.message(_("Generating a clumped raster file ..."))
+ grass.run_command('r.clump', input=infile, output=clumpfile)
+
      if lesser:
          grass.message(_("Generating a reclass map with area size less
than " \
                          "or equal to %f hectares...") % limit)
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: reopened
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by neteler):

  * status: closed => reopened
  * resolution: worksforme =>

Comment:

Please add the diff as attachment to the ticket. It may then remain open
unless it was
updated in SVN.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: reopened
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by peifer):

Here you are.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: reopened
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by annakrat):

Replying to [comment:9 peifer]:
> Here you are.

I committed it in r61829. Needs testing of course.

I was wondering, should the example on r.reclass.area man page include the
-c flag? The zipcodes are already clumped, or?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: reopened
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by neteler):

Replying to [comment:10 annakrat]:
> I was wondering, should the example on r.reclass.area man page include
the -c flag? The zipcodes are already clumped, or?

The codes should be (the associated names not necessarily).

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: reopened
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by peifer):

Replying to [comment:10 annakrat]:
> The zipcodes are already clumped, or?

It doesn't look like: zipcodes has 13 distinct cat values. r.clump
generates 16 clumps and r.clump -d generates 14 clumps.

Maybe zipcodes isn't a good example map for r.reclass.area in the first
place, because when following the man page: some area of zip code 27606 is
lost during the clumping (without the innocent user being aware of this
risk, I would assume).
{{{
|27606|RALEIGH. . . . . . . . . .| 6626.420| # Size in ha in original
zipcodes map
|27606|RALEIGH. . . . . . . . . .| 6626.410| # 1 px = 100m2 = 0.01 ha
lost in zipcodes_larger2000ha
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:12&gt;
GRASS GIS <http://grass.osgeo.org>

#2400: r.reclass.area: add option to use r.clump's -d flag
--------------------------+-------------------------------------------------
  Reporter: peifer | Owner: grass-dev@…
      Type: enhancement | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-trunk
Resolution: fixed | Keywords: r.reclass.area
  Platform: All | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by peifer):

  * status: reopened => closed
  * resolution: => fixed

Comment:

Works as expected in trunk. I will close the ticket.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2400#comment:13&gt;
GRASS GIS <http://grass.osgeo.org>