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)