From 74da7caaf4de6b21787fb3c487dbbc1c300680d0 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Wed, 18 Jul 2018 16:47:54 +0200 Subject: [PATCH] v1.0.11.0 new argument in LatUnit PEdaily_Oudin to chose the unit of the latitude + LatRad --> Lat + code cleaned --- DESCRIPTION | 4 +- NEWS.rmd | 28 ++++++++++++-- R/PEdaily_Oudin.R | 95 +++++++++++++++++++++++++++++++---------------- 3 files changed, 89 insertions(+), 38 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ef8705bd..e10e064f 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.0.10.11 -Date: 2018-06-29 +Version: 1.0.11.0 +Date: 2018-07-18 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl")), person("Charles", "Perrin", role = c("aut", "ths")), diff --git a/NEWS.rmd b/NEWS.rmd index fda8b9fc..a984602f 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -14,19 +14,39 @@ output: +### 1.0.11.0 Release Notes (2018-07-18) + + +#### Deprectated and defunct + +- The <code>LatRad</code> argument is now deprecated in <code>PEdaily_Oudin()</code> and replaced by the <code>Lat</code> argument. + + +#### Major user-visible changes + +- <code>PEdaily_Oudin()</code> now presents a <code>LatUnit</code> argument which allows to chose the unit of the latitude between radians and degrees. + + +#### Minor user-visible changes + +- Several functions of the package were cleant or slightly modified, with no effect on their outputs. + +____________________________________________________________________________________ + + ### 1.0.10.11 Release Notes (2018-06-29) #### Bug fixes -- Fixed bug in <code>RunModel_GR2M</code>. The function now returns the total precipitation (P) instead of the net rainfall (P1). +- Fixed bug in <code>RunModel_GR2M()</code>. The function now returns the total precipitation (P) instead of the net rainfall (P1). #### Major user-visible changes -- <code>RunModel_GR2M</code> now returns more explicit precipitation outputs names. +- <code>RunModel_GR2M()</code> now returns more explicit precipitation outputs names. -- <code>CreateInputsCrit</code> now returns a warning message when the KGE (or KGE') is used with a log transformation on flows. +- <code>CreateInputsCrit()</code> now returns a warning message when the KGE (or KGE') is used with a log transformation on flows. - The article reference is corrected. @@ -102,7 +122,7 @@ ________________________________________________________________________________ #### New features -- <code>DataAltiExtrapolation_Valery()</code> and <code>CreateInputsModel()</code> now present a PrecipScale argument which allows rescaling precipitation when it is interpolated on the elevation layers when CemaNeige is used. +- <code>DataAltiExtrapolation_Valery()</code> and <code>CreateInputsModel()</code> now present a <code>PrecipScale</code> argument which allows rescaling precipitation when it is interpolated on the elevation layers when CemaNeige is used. #### Bug fixes diff --git a/R/PEdaily_Oudin.R b/R/PEdaily_Oudin.R index 10861685..a896a0f7 100644 --- a/R/PEdaily_Oudin.R +++ b/R/PEdaily_Oudin.R @@ -1,35 +1,66 @@ -PEdaily_Oudin <- function(JD,Temp,LatRad){ - - PE_Oudin_D <- rep(NA,length(Temp)); - for(k in 1:length(Temp)){ - - FI <- LatRad ### latitude in rad - ### FI <- LatDeg/(180/pi) ### conversion from deg to rad - COSFI <- cos(FI) - AFI <- abs(LatRad/42.) - - TETA <- 0.4093*sin(JD[k]/58.1-1.405) - COSTETA <- cos(TETA) - COSGZ <- max(0.001,cos(FI-TETA)) - GZ <- acos(COSGZ) - COSGZ2 <- COSGZ*COSGZ - if(COSGZ2 >= 1){ SINGZ <- 0. } else { SINGZ <- sqrt(1.-COSGZ2) } - COSOM <- 1.-COSGZ/COSFI/COSTETA - if(COSOM < -1.){ COSOM <- -1. } - if(COSOM > 1.){ COSOM <- 1. } - COSOM2 <- COSOM*COSOM - if(COSOM2 >= 1.){ SINOM <- 0. } else { SINOM <- sqrt(1.-COSOM2) } - OM <- acos(COSOM) - COSPZ <- COSGZ+COSFI*COSTETA*(SINOM/OM-1.) - if(COSPZ < 0.001){ COSPZ <- 0.001 } - ETA <- 1.+cos(JD[k]/58.1)/30. - GE <- 446.*OM*COSPZ*ETA - - if(Temp[k] >= -5.0) { PE_Oudin_D[k] <- GE*(Temp[k]+5.)/100./28.5 } else { PE_Oudin_D[k] <- 0 } - +PEdaily_Oudin <- function(JD, Temp, LatRad, Lat, LatUnit = c("rad", "deg")) { + + if (!missing(LatRad)) { + warning("Deprecated \"LatRad\" argument. Please, use \"Lat\" instead.") + if (missing(Lat)) { + Lat <- LatRad } - - return(PE_Oudin_D); - + } + + PE_Oudin_D <- rep(NA, length(Temp)) + + if (LatUnit[1L] == "rad") { + FI <- Lat + } + if (LatUnit[1L] == "deg") { + FI <- Lat / (180 / pi) + } + + COSFI <- cos(FI) + AFI <- abs(FI / 42) + + for (k in seq_along(Temp)) { + + TETA <- 0.4093 * sin(JD[k] / 58.1 - 1.405) + COSTETA <- cos(TETA) + COSGZ <- max(0.001, cos(FI - TETA)) + GZ <- acos(COSGZ) + COSOM <- 1 - COSGZ / COSFI / COSTETA + + if (COSOM < -1) { + COSOM <- -1 + } + if (COSOM > 1) { + COSOM <- 1 + } + + COSOM2 <- COSOM * COSOM + + if (COSOM2 >= 1) { + SINOM <- 0 + } else { + SINOM <- sqrt(1 - COSOM2) + } + + OM <- acos(COSOM) + COSPZ <- COSGZ + COSFI * COSTETA * (SINOM/OM - 1) + + if (COSPZ < 0.001) { + COSPZ <- 0.001 + } + + ETA <- 1 + cos(JD[k] / 58.1) / 30 + GE <- 446 * OM * COSPZ * ETA + + if (Temp[k] >= -5.0) { + PE_Oudin_D[k] <- GE * (Temp[k] + 5) / 100 / 28.5 + } else { + PE_Oudin_D[k] <- 0 + } + + } + + return(PE_Oudin_D) + } -- GitLab