Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • ClimProjDiags ClimProjDiags
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 1
    • Issues 1
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Earth SciencesEarth Sciences
  • ClimProjDiagsClimProjDiags
  • Issues
  • #2
Closed
Open
Issue created Nov 21, 2019 by Roberto Bilbao@rfernandDeveloper

Bug in WeightedMean function

Hi @nperez,

I have found a bug in the WeightedMean function. I have been using this function to calculate area weighted means of data with latitudes and longitudes with regular grids, for example the global mean. I have realised that the output of this function gives different results depending on the order of the longitudes, for example, if the data goes from 0 to 360 vs is the data is from 180 to 360 and then from 1 to 180. There shouldn't be any effect from this, and in fact, the longitude in regular grids should always have equal weights.

I believe the problem may be in lines 123-125:

dlon <- abs(c(lon[2 : nblon] - lon[1 : nblon - 1])) * pi / 180
dlon <- c(dlon, dlon[1])
dlon <- array(dlon, dim = c(nblon, nblat))

If there is a discontinuity in the latitudes, as in the case of the lons going from 180 to 360 and then from 1 to 180 then the weight dlon calculated when the lon goes from 360 to 1 is wrongly given a large weight. I also don't see why the longitude should be weighted like the latitudes, even though it doesn't have an effect.

This could be solved by giving the longitudes equal weights all the time, which typically is the case in regular grids.

@swild @dverfail in case you use this function.

Assignee
Assign to
Time tracking