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
Showing with 11 additions and 5 deletions
+11 -5
...@@ -41,11 +41,10 @@ PE_Oudin <- function(JD, Temp, ...@@ -41,11 +41,10 @@ PE_Oudin <- function(JD, Temp,
TimeStepIn <- match.arg(TimeStepIn , choices = TimeStep) TimeStepIn <- match.arg(TimeStepIn , choices = TimeStep)
TimeStepOut <- match.arg(TimeStepOut, choices = TimeStep) TimeStepOut <- match.arg(TimeStepOut, choices = TimeStep)
rleJD <- rle(JD) 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)) { 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") warning(msgDaliy)
}
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")
} }
...@@ -54,7 +53,14 @@ PE_Oudin <- function(JD, Temp, ...@@ -54,7 +53,14 @@ PE_Oudin <- function(JD, Temp,
if (TimeStepIn == "hourly") { if (TimeStepIn == "hourly") {
JD <- rleJD$values JD <- rleJD$values
idJD <- rep(seq_along(JD), each = rleJD$lengths[1L]) 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)
} }
......
Supports Markdown
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