Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • SUNSET SUNSET
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 43
    • Issues 43
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Terraform modules
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Earth SciencesEarth Sciences
  • SUNSETSUNSET
  • Issues
  • #99
Closed
Open
Issue created Jan 19, 2024 by vagudets@vagudetsMaintainer

Units: Monthly precipitation unit transformation does not compute the number of days in a month correctly

Expected Behavior

The atomic function .days_in_month(), which is defined inside the transform_units_precipitation() file, is supposed to return the amount of days for each monthly time stamp, taking into account the month and whether it is a leap year.

Current Behavior

In R>4.2, the function fails:

In if (leap_year(x)) { :
  the condition has length > 1 and only the first element will be used

In R<4.2, the function does not fail but running the same code will produce a warning letting the user know the result is incorrect:

library(lubridate)
leap_year(2012)
# [1] TRUE
leap_year(c(2012, 2013))
# [1]  TRUE FALSE
if (leap_year(c(2012, 2013))) {
  print("hi")
}
# [1] "hi"
# Warning message:
# In if (leap_year(c(2012, 2013))) { :
#  the condition has length > 1 and only the first element will be used

Possible Solutions?

To be determined. @nperez I have some questions about the logic in the atomic function. Maybe we can take a look together and see if we can find a fix that works?

Steps To Reproduce

  • Recipe: Any recipe where monthly mean precipitation is loaded and requires unit transformation. For example: https://earth.bsc.es/gitlab/es/sunset/-/blob/194bbcaecf1d608fc75941818871b03bab565a49/recipes/atomic_recipes/recipe_system7c3s-prlr.yml

  • Script:

# The recipe can be found in the dev-fix_units_monthly_precip branch
source("modules/Loading/Loading.R")
source("modules/Units/Units.R")

recipe <- prepare_outputs("recipes/atomic_recipes/recipe_system7c3s-prlr.yml")

data <- Loading(recipe)
data <- Units(recipe, data)
  • Branch/SUNSET Version: master

  • Environment: Nord3v2 (R/4.1.2) and bsceshub (R/4.2.1)

Edited Feb 02, 2024 by vagudets
Assignee
Assign to
Time tracking