[apologies for taking the liberty to re-sort previous posts]

Milton Cezar Ribeiro:

> > I have a set of 7 raster maps.
> > I am able to calculate several stats with these mapas using r.series.
> > Now I need to calculate the mean of the tree highest values of my 7 maps.
> > Any idea of how can I do that?

José Miguel Barrios wrote:
> A possible approach could be, for example, to do the following with each
> map:

> r.stats -1 input=map1 outputÎllvaluesmap1

> It will create a file containing the cell values for each map.  Then you
> can read this file into R and average the three highest values.  Something
> like:

> values.map1<-read.table("cellvaluesmap1")
> threehighest<-values.map1$V1[order(values.map1,decreasingúLSE)][1:3]
> mean3highest<-mean(threehighest)

If in Linux, there are several ways to do this.  One (very) nice approach as
shown in <http://stackoverflow.com/a/3096575/1172302>, could be:

# get the numbers
r.stats -1 input=map1 output=Values1

# sort and keep first 3
sort -rn Values1  |  head -3 > Values1.sorted

# sum and divide by 3
echo "( $( paste -sd+ Values1.sorted ) ) / 3" | bc

# or a one-liner!
sort -rn numbers | head -3  | echo "( $( paste -sd+ ) ) / 3" | bc

Other options would be "awk" or "python". Also, note that  r.stats  has also
the "-x" and "-g" flags.  You could grab them as well and, if doing the math
"externally", know where to place the results each time?

However, it seems like a very "resources" hungry approach, if your maps are
many and large.  There must be a "smart"(er) way to do this directly using
r.mapcalc...

Best, Nikos

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to