WeightedMean: wrong dlon calculation
This issue is identified by @bsolaraj . WeightedMean() takes the size of each grid into consideration when calculateing the weight, so the distance between each lon/lat point (dlon
and dlat
) are calculated (dlon <- abs(c(abs(lon[2 : nblon]) - abs(lon[1 : nblon - 1]))) * pi / 180
, line 128.)
In the following example, the problem happens at lon = -0.5 and lon = 0.5. abs() makes dlon = 0
but the distance should be 1.
lon <- seq(-179.5,179.5,by=1)
nblon <- length(lon)
lon[lon > 180] = lon[lon > 180] - 360
dlon <- abs(c(abs(lon[2 : nblon]) - abs(lon[1 : nblon - 1]))) * pi / 180
dlon[180]
[1] 0 #SHOULD BE 1
lon[180:181]
[1] -0.5 0.5
The dlon
calculation can be done by diff(lon)
simply. @nperez do you see any potential problem if we make this change?
Cheers,
An-Chi