Commit deb106d7 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

refactor(PE_Oudin): add an error message when TimeStepIn = "hourly" and...

refactor(PE_Oudin): add an error message when TimeStepIn = "hourly" and length(Temp) != length(idJD)
Refs #134
parent 488e9a40
Pipeline #26049 canceled with stage
......@@ -41,11 +41,10 @@ PE_Oudin <- function(JD, Temp,
TimeStepIn <- match.arg(TimeStepIn , choices = TimeStep)
TimeStepOut <- match.arg(TimeStepOut, choices = TimeStep)
rleJD <- rle(JD)
msgDaliy <- "each day should have only one identical value of julian days. The time series is not sorted, or contains duplicate or missing dates"
msgHourly <- "each day must have 24 identical values of julian days (one for each hour). The time series is not sorted, or contains duplicate or missing dates"
if (TimeStepIn == "daily" & any(rleJD$lengths != 1)) {
warning("each day should have only one identical value of julian days. The time series is not sorted, or contains duplicate or missing dates")
}
if (TimeStepIn == "hourly" & any(rleJD$lengths != 24)) {
warning("each day must have 24 identical values of julian days (one for each hour). The time series is not sorted, or contains duplicate or missing dates")
warning(msgDaliy)
}
......@@ -54,7 +53,14 @@ PE_Oudin <- function(JD, Temp,
if (TimeStepIn == "hourly") {
JD <- rleJD$values
idJD <- rep(seq_along(JD), each = rleJD$lengths[1L])
Temp <- as.vector(tapply(X = Temp, INDEX = idJD, FUN = mean))
if (length(Temp) != length(idJD)) {
stop(msgHourly)
} else {
Temp <- as.vector(tapply(X = Temp, INDEX = idJD, FUN = mean))
}
}
if (TimeStepIn == "hourly" & any(rleJD$lengths != 24)) {
warning(msgHourly)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment