From 8a533d60f6fb978dd0a46b0c19bc95029a1e72d1 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Mon, 18 Mar 2019 11:53:12 +0100 Subject: [PATCH] v1.2.9.9 UPDATE: new checks added in PEdaily_Oudin --- DESCRIPTION | 4 ++-- NEWS.rmd | 4 +++- R/PEdaily_Oudin.R | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b0f49d47..56720f75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.2.9.8 -Date: 2019-03-13 +Version: 1.2.9.9 +Date: 2019-03-18 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")), diff --git a/NEWS.rmd b/NEWS.rmd index 32e638f5..67b74e68 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -13,7 +13,7 @@ output: -### 1.2.9.8 Release Notes (2019-03-13) +### 1.2.9.9 Release Notes (2019-03-18) @@ -60,6 +60,8 @@ output: - It is now possible to be redirected on the documantation about <code>plot.OutputsModel()</code> with <code>?plot</code>. +- <code>plot.OutputsModel()</code> does not return a warning message anymore when <code>Qobs = NULL</code>. + - It is now possible to use a character vector the function name (in addition to function objects) in all <code>FUN_*</code> arguments of the following functions: <code>Calibration()</code>, <code>Calibration_Michel()</code>, <code>CreateCalibOptions()</code>, <code>CreateIniStates()</code>, <code>CreateIniStates()</code>, <code>CreateInputsCrit()</code>, <code>CreateInputsModel()</code>, <code>CreateRunOptions()</code>, <code>ErrorCrit()</code>, <code>RunModel()</code> and <code>TransfoParam()</code>. diff --git a/R/PEdaily_Oudin.R b/R/PEdaily_Oudin.R index 38f6d258..dd42174a 100644 --- a/R/PEdaily_Oudin.R +++ b/R/PEdaily_Oudin.R @@ -9,10 +9,10 @@ PEdaily_Oudin <- function(JD, Temp, LatRad, Lat, LatUnit = c("rad", "deg")) { Lat <- LatRad } } - if (!inherits(JD, "numeric")) { + if (!(inherits(JD, "numeric") | inherits(JD, "integer"))) { stop("'JD' must be of class 'numeric'") } - if (!inherits(Temp, "numeric")) { + if (!(inherits(Temp, "numeric") | inherits(Temp, "integer"))) { stop("'Temp' must be of class 'numeric'") } if (length(JD) != length(Temp)) { @@ -24,12 +24,21 @@ PEdaily_Oudin <- function(JD, Temp, LatRad, Lat, LatUnit = c("rad", "deg")) { if (!inherits(Lat, "numeric") | length(Lat) != 1) { stop("'Lat' must be a 'numeric' of length one") } + if (LatUnit[1L] == "rad" & ((Lat >= pi/2) | (Lat <= -pi/2))) { + stop("'Lat' must be comprised between -pi/2 and +pi/2 degrees") + } + if (LatUnit[1L] == "deg" & ((Lat >= 90) | (Lat <= -90))) { + stop("'Lat' must be comprised between -90 and +90 degrees") + } if (LatUnit[1L] == "rad") { FI <- Lat } if (LatUnit[1L] == "deg") { FI <- Lat / (180 / pi) } + if (any(JD < 0) | any(JD > 366)) { + stop("'JD' must only contain integers from 1 to 366") + } ## ---------- Oudin's formula @@ -71,14 +80,29 @@ PEdaily_Oudin <- function(JD, Temp, LatRad, Lat, LatUnit = c("rad", "deg")) { ETA <- 1 + cos(JD[k] / 58.1) / 30 GE <- 446 * OM * COSPZ * ETA + if (is.na(Temp[k])) { + PE_Oudin_D[k] <- NA + } else { if (Temp[k] >= -5.0) { PE_Oudin_D[k] <- GE * (Temp[k] + 5) / 100 / 28.5 } else { PE_Oudin_D[k] <- 0 } + } } + if (any(is.na(Temp))) { + if (any(is.na(PE_Oudin_D))) { + warning("'Temp' time series, and therefore the returned 'PE' time series, contain missing value(s)") + } else { + warning("'Temp' time series contains missing value(s)") + } + } + if (!any(is.na(Temp)) & any(is.na(PE_Oudin_D))) { + warning("returned 'PE' time series contains missing value(s)") + } + return(PE_Oudin_D) } -- GitLab