Opened 11 years ago

Closed 11 years ago

#2121 closed enhancement (fixed)

v.rast.stats: allow choice of statistics

Reported by: mlennert Owned by: grass-dev@…
Priority: normal Milestone: 7.0.0
Component: Vector Version: svn-trunk
Keywords: v.rast.stats Cc:
CPU: Unspecified Platform: Unspecified

Description

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

Change History (14)

comment:1 by mlennert, 11 years ago

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

comment:2 by lucadelu, 11 years ago

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?

in reply to:  2 comment:3 by lucadelu, 11 years ago

Replying to 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.

in reply to:  2 ; comment:4 by mlennert, 11 years ago

Replying to 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

in reply to:  4 ; comment:5 by lucadelu, 11 years ago

Replying to 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

in reply to:  5 ; comment:6 by mlennert, 11 years ago

Replying to lucadelu:

Replying to 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

in reply to:  description ; comment:7 by matmar, 11 years ago

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

in reply to:  7 comment:8 by neteler, 11 years ago

Replying to 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

in reply to:  6 ; comment:9 by lucadelu, 11 years ago

Replying to 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

in reply to:  7 ; comment:10 by lucadelu, 11 years ago

Replying to 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

in reply to:  10 comment:11 by mlennert, 11 years ago

Replying to lucadelu:

Replying to 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' 1.

in reply to:  9 comment:12 by mlennert, 11 years ago

Replying to lucadelu:

Replying to 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

in reply to:  9 comment:13 by lucadelu, 11 years ago

Replying to 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

comment:14 by lucadelu, 11 years ago

Resolution: fixed
Status: newclosed

Ticket completed, closing it.

Please reopen if needed

Note: See TracTickets for help on using tickets.