# [GRASS-dev] [GRASS GIS] #2969: r.series: wrong usage of weights

GRASS GIS trac at osgeo.org
Wed Mar 23 07:27:20 PDT 2016

```#2969: r.series: wrong usage of weights
-------------------------------+-------------------------
Reporter:  mmetz              |      Owner:  grass-dev@…
Type:  defect             |     Status:  new
Priority:  normal             |  Milestone:  7.0.4
Component:  Raster             |    Version:  7.0.3
Keywords:  r.series, weights  |        CPU:  Unspecified
Platform:  All                |
-------------------------------+-------------------------
A weighted average is calculated with

{{{
avg = sum(w[i] * x[i]) / sum(w[i])
}}}

r.series calculates weighted averages with
{{{
avg = sum(w[i] * x[i]) / count
}}}

r.series should instead behave like r.neighbors and use the corresponding
weighing functions from libstats if available.

Test commands:
{{{
# set the region
g.region -p n=10 s=0 w=0 e=10 res=1
# create identical input maps
r.mapcalc "input1 = 1"
r.mapcalc "input2 = 1"
r.mapcalc "input3 = 1"
r.mapcalc "input4 = 1"
r.mapcalc "input5 = 1"

# average
r.series in=input1,input2,input3,input4,input5 method=average out=avg
# weighted average
r.series in=input1,input2,input3,input4,input5 method=average out=avg_w
weights=0.1,0.2,0.3,0.2,0.1
}}}

Without weights the result is 1, with weights the result is 0.18 instead
of 1. Weights have been added to r.series in r49946. I am going to change
r.series in trunk and relbr70.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2969>
GRASS GIS <https://grass.osgeo.org>

```