Opened 7 years ago

Closed 6 years ago

## #2121 closed enhancement (fixed)

# v.rast.stats: allow choice of statistics

Reported by: | mlennert | Owned by: | |
---|---|---|---|

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_suma 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 Changed 7 years ago by

### comment:2 follow-ups: 3 4 Changed 6 years ago by

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?

### comment:3 Changed 6 years ago by

Replying to lucadelu:

I added a

methodoption to choose the methods to save in the attribute table in r58726.I would like also to remove

-eflag and add the methods calculated by extended statistics to themethod's options, what do you think?

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

### comment:4 follow-up: 5 Changed 6 years ago by

Replying to lucadelu:

I added a

methodoption 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

-eflag and add the methods calculated by extended statistics to themethod's options, what do you think?

Sounds reasonable to me.

Moritz

### comment:5 follow-up: 6 Changed 6 years ago by

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

### comment:6 follow-up: 9 Changed 6 years ago by

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

### comment:7 follow-ups: 8 10 Changed 6 years ago by

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

### comment:8 Changed 6 years ago by

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

### comment:9 follow-ups: 12 13 Changed 6 years ago by

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

### comment:10 follow-up: 11 Changed 6 years ago by

### comment:11 Changed 6 years ago by

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.

### comment:12 Changed 6 years ago by

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

### comment:13 Changed 6 years ago by

### comment:14 Changed 6 years ago by

Resolution: | → fixed |
---|---|

Status: | new → closed |

Ticket completed, closing it.

Please reopen if needed

**Note:**See TracTickets for help on using tickets.

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