[GRASS-user] Calculate average of 3 highest values for a set of raster maps

Paulo van Breugel p.vanbreugel at gmail.com
Fri Mar 15 02:08:37 PDT 2013


Sorry, some typo's (but the given code should be ok): set all values < 
4/7 quantile to null(), not 0, and you want to calculate the average, 
not the sum

On Fri 15 Mar 2013 10:05:51 AM CET, Paulo van Breugel wrote:
> Hi Miltinho
>
> I assume you want the mean of the three highest values for each raster
> cell? If so, you can do this using another step with r.series
>
> 1) If your 7 maps are a1 .. a7:
>
> mapcalc "a1 = 1"; r.mapcalc "a2 = 2"; r.mapcalc "a3 = 3"; r.mapcalc
> "a4 = 4"; r.mapcalc "a5 = 5"; r.mapcalc "a6 = 6"; r.mapcalc "a7 = 7"
>
> 2) calculate the 4/7 quantile. Actually, it should be a little bit
> smaller to make sure you include your 3rd largest layer. In this
> example below, 0.57 as approximation is fine
>
> r.series --overwrite input=a1,a2,a3,a4,a5,a6,a7 quantile=0.57
> output=res1 method=quantile
>
> 2) Next, for all 7 layers, set all values < 4/7 quantile to 0
>
> r.mapcalc "b1 = if(a1>res1,a1,null())"
> r.mapcalc "b2 = if(a2>res1,a2,null())"
> r.mapcalc "b3 = if(a3>res1,a3,null())"
> r.mapcalc "b4 = if(a4>res1,a4,null())"
> r.mapcalc "b5 = if(a5>res1,a5,null())"
> r.mapcalc "b6 = if(a6>res1,a6,null())"
> r.mapcalc "b7 = if(a7>res1,a7,null())"
>
> 3) Now, calculate the sum of the 7 new layers
>
> r.series input=b1,b2,b3,b4,b5,b6,b7 method=average output=res2
> --overwrite
>
> Your output res2 should have a value 6 for all raster cells.
>
> Cheers,
>
> Paulo
>
>
>
>
>
>
> On Fri 15 Mar 2013 03:57:35 AM CET, Milton Cezar Ribeiro wrote:
>> 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?
>>
>> cheers


More information about the grass-user mailing list