[GRASS-dev] [GRASS GIS] #2121: v.rast.stats: allow choice of statistics

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------
It would be convenient if v.rast.stats allowed a choice of statistics that
one wants to upload to the attribute table. Currently, it creates 9
columns:

{{{
INTEGER|B5_n
DOUBLE PRECISION|B5_min
DOUBLE PRECISION|B5_max
DOUBLE PRECISION|B5_range
DOUBLE PRECISION|B5_mean
DOUBLE PRECISION|B5_stddev
DOUBLE PRECISION|B5_varianc
DOUBLE PRECISION|B5_cf_var
DOUBLE PRECISION|B5_sum
}}}

a series of which can actually be derived from others (mean, range, sttdev
|| variance, coefficient of variation), meaning that only 5 are really
needed (n, min, max, variance || stddev, sum).

So, at least we could limit the uploaded statistics to those 5, or even
allow choice of statistics through a parameter.

Moritz

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by mlennert):

Trac didn't like my use of the pipe character as OR operator, so "variance
stddev" should read "variance OR stddev".

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by lucadelu):

I added a ''method'' option to choose the methods to save in the attribute
table in r58726.

I would like also to remove ''-e'' flag and add the methods calculated by
extended statistics to the ''method'' 's options, what do you think?

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by lucadelu):

Replying to [comment:2 lucadelu]:
> I added a ''method'' option to choose the methods to save in the
attribute table in r58726.
>
> I would like also to remove ''-e'' flag and add the methods calculated
by extended statistics to the ''method'' 's options, what do you think?

Please try r58727, in previous version there was a small bug.

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by mlennert):

Replying to [comment:2 lucadelu]:
> I added a ''method'' option to choose the methods to save in the
attribute table in r58726.

This is great, thanks ! Just one problem: it fails at lines 255-256 with
the dbf driver as colnames get truncated, but your variable names are
full, and so

{{{
variable = colname.replace("%s_" % colprefix, '')
i = variables[variable]
}}}

leads to a key error since 'variable' does not exist in 'variables'. A
solution might be to use a dictionary linking variable names to colnames ?

> I would like also to remove ''-e'' flag and add the methods calculated
by extended statistics to the ''method'' 's options, what do you think?

Sounds reasonable to me.

Moritz

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by lucadelu):

Replying to [comment:4 mlennert]:

>
> This is great, thanks ! Just one problem: it fails at lines 255-256 with
the dbf driver as colnames get truncated, but your variable names are
full, and so
>
>
> {{{
> variable = colname.replace("%s_" % colprefix, '')
> i = variables[variable]
> }}}
>
> leads to a key error since 'variable' does not exist in 'variables'. A
solution might be to use a dictionary linking variable names to colnames ?
>

Yes I fixed it using dictionary, try r58728 (it also solve another problem
with DBF driver).

>
> Sounds reasonable to me.
>

I wait other dev's comments before make these changes

> Moritz

Luca

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by mlennert):

Replying to [comment:5 lucadelu]:
> Replying to [comment:4 mlennert]:
>
> >
> > This is great, thanks ! Just one problem: it fails at lines 255-256
with the dbf driver as colnames get truncated, but your variable names are
full, and so
> >
> >
> > {{{
> > variable = colname.replace("%s_" % colprefix, '')
> > i = variables[variable]
> > }}}
> >
> > leads to a key error since 'variable' does not exist in 'variables'. A
solution might be to use a dictionary linking variable names to colnames ?
> >
>
> Yes I fixed it using dictionary, try r58728

Yup, works great now.

> (it also solve another problem with DBF driver).

Great, I had just stumbled upon that while testing !

Now, one more issue: since recently (r57999), there is the possibility to
abbreviate option values, but this does not seem to work here:

{{{
v.rast.stats blks raster=elevation column=elev
method=mini,maxi,mean,stddev -c
Processing data (2535 categories)...
Traceback (most recent call last):
   File "/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-unknown-
linux-gnu/scripts/v.rast.stats", line 295, in <module>
     main()
   File "/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-unknown-
linux-gnu/scripts/v.rast.stats", line 261, in main
     i = variables[variable]
KeyError: 'mini'
}}}

I don't know exactly what's needed to make this work, but it would be nice
if it did.

Moritz

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by matmar):

Hi Moritz,

> So, at least we could limit the uploaded statistics to those 5, or even
allow choice of statistics through a parameter.
>
> Moritz

I would preserve the (singol) choice of all the 9 statistics without
dropping the extended ones.
Furthermore, just a suggestion: the "average" statistic is called
"average" in r.series and "mean" in v.rast.stats. It would be great if
someone could manage to unify the terminology...

Matteo

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by neteler):

Replying to [comment:7 matmar]:
...
> Furthermore, just a suggestion: the "average" statistic is
> called "average" in r.series and "mean" in v.rast.stats.
> It would be great if someone could manage to unify the terminology...

Right. For a discussion on this, see this email and following:

http://lists.osgeo.org/pipermail/grass-dev/2013-October/thread.html#65948

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by lucadelu):

Replying to [comment:6 mlennert]:

>
> Now, one more issue: since recently (r57999), there is the possibility
to abbreviate option values, but this does not seem to work here:
>
>
> {{{
> v.rast.stats blks raster=elevation column=elev
method=mini,maxi,mean,stddev -c
> Processing data (2535 categories)...
> Traceback (most recent call last):
> File "/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-unknown-
linux-gnu/scripts/v.rast.stats", line 295, in <module>
> main()
> File "/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-unknown-
linux-gnu/scripts/v.rast.stats", line 261, in main
> i = variables[variable]
> KeyError: 'mini'
> }}}
>
> I don't know exactly what's needed to make this work, but it would be
nice if it did.
>

fixed in r58731, I just check the long name and set it instead the
abbreviate one.

No objections were done for remove the ''e'' flag and add the methods to
''method'' option, so I start to implement it

> Moritz

Luca

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by lucadelu):

Replying to [comment:7 matmar]:

>
> Furthermore, just a suggestion: the "average" statistic is called
"average" in r.series and "mean" in v.rast.stats. It would be great if
someone could manage to unify the terminology...
>

fixed in r58731.

> Matteo

Luca

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by mlennert):

Replying to [comment:10 lucadelu]:
> Replying to [comment:7 matmar]:
>
> >
> > Furthermore, just a suggestion: the "average" statistic is called
"average" in r.series and "mean" in v.rast.stats. It would be great if
someone could manage to unify the terminology...
> >
>
> fixed in r58731.

Actually AFAIK, there was no agreement, yet, on what was preferred. Vaclav
actually argued for 'mean' instead of 'average'
[http://lists.osgeo.org/pipermail/grass-dev/2013-October/065977.html 1].

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by mlennert):

Replying to [comment:9 lucadelu]:
> Replying to [comment:6 mlennert]:
>
> >
> > Now, one more issue: since recently (r57999), there is the possibility
to abbreviate option values, but this does not seem to work here:
> >
> >
> > {{{
> > v.rast.stats blks raster=elevation column=elev
method=mini,maxi,mean,stddev -c
> > Processing data (2535 categories)...
> > Traceback (most recent call last):
> > File "/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-unknown-
linux-gnu/scripts/v.rast.stats", line 295, in <module>
> > main()
> > File "/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-unknown-
linux-gnu/scripts/v.rast.stats", line 261, in main
> > i = variables[variable]
> > KeyError: 'mini'
> > }}}
> >
> > I don't know exactly what's needed to make this work, but it would be
nice if it did.
> >
>
> fixed in r58731, I just check the long name and set it instead the
abbreviate one.

Seems to work nicely, thanks !

Moritz

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Keywords: v.rast.stats | Platform: Unspecified
      Cpu: Unspecified |
--------------------------+-------------------------------------------------

Comment(by lucadelu):

Replying to [comment:9 lucadelu]:

>
> No objections were done for remove the ''e'' flag and add the methods to
''method'' option, so I start to implement it
>

Please try r58735, it remove 'e' flag and add the extended methods to the
new 'method' option.

Luca

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

#2121: v.rast.stats: allow choice of statistics
--------------------------+-------------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: enhancement | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: Vector | Version: svn-trunk
Resolution: fixed | Keywords: v.rast.stats
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by lucadelu):

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

Comment:

Ticket completed, closing it.

Please reopen if needed

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