Commit 0f113aab authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v0.2.8.0 NEW: add as.data.frame.airGR function to coerce outputs of PrepGR,...

v0.2.8.0 NEW: add as.data.frame.airGR function to coerce outputs of PrepGR, CalGR and SimGR to a data.frame
parent 6243c881
Package: airGRteaching
Type: Package
Title: Teaching Hydrological Modelling with the GR Rainfall-Runoff Models ('Shiny' Interface Included)
Version: 0.2.7.7
Date: 2020-01-24
Version: 0.2.8.0
Date: 2020-02-05
Authors@R: c(
person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"),
person("Laurent", "Coron", role = c("aut"), comment = c(ORCID = "0000-0002-1503-6204")),
......
Modelling functions:
====================
======================
PrepGR Creation of the inputs required to the CalGR
and SimGR functions
CalGR Calibration algorithm optimises the error
criterion selected as objective function
SimGR Run GR hydrological models
Summarizing functions:
======================
as.data.frame Create a data.frame from outputs of PrepGR,
CalGR or SimGR
Plotting functions:
====================
======================
dyplot Interactive time series plotting of PrepGR, CalGR
and SimGR objects
......@@ -23,7 +30,7 @@ plot.SimGR Synthetic plotting of model outputs
Shiny interface:
====================
======================
ShinyGR Interactive Web applications to run the GR4J, GR5J
and GR6J hydrological models whith or without CemaNeige
......@@ -11,6 +11,7 @@ S3method("dyplot","default")
S3method("dyplot","PrepGR")
S3method("dyplot","CalGR")
S3method("dyplot","SimGR")
S3method("as.data.frame", "airGRt")
......@@ -29,6 +30,7 @@ export(dyplot.PrepGR)
export(dyplot.CalGR)
export(dyplot.SimGR)
export(ShinyGR)
export(as.data.frame.airGRt)
exportPattern(".DiagramGR")
exportPattern(".TypeModelGR")
......
......@@ -14,7 +14,13 @@ output:
### 0.2.7.7 Release Notes (2020-01-24)
### 0.2.8.0 Release Notes (2020-02-05)
#### New features
- Added <code>as.data.frame.airGRt()</code> method in order to create a <code>data.frame</code> from outputs of <code>PrepGR()</code>, <code>CalGR()</code> and <code>SimGR()</code> functions. This <code>data.frame</code> always presents the same structure and contains (observed flow, simulated flow, simulated solid precipitation fraction, etc.). Wwhen it doesn't make sense a columns contains <code>NA</code> values (e.g. Qims with the <code>PrepGR()</code> function)
#### User-visible changes
......
......@@ -76,7 +76,7 @@ CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
TypeModel = PrepGR$TypeModel, CalCrit = CalCrit,
PeriodModel = list(WarmUp = as.POSIXct(PrepGR$InputsModel$DatesR[range(MOD_opt$IndPeriod_WarmUp)], tz = "UTC"),
Run = CalPer))
class(CalGR) <- c("CalGR", "GR")
class(CalGR) <- c("CalGR", "GR", "airGRt")
return(CalGR)
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ PrepGR <- function(ObsDF = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Q
PrepGR <- list(InputsModel = MOD_obs, Qobs = ObsDF$Qobs, TypeModel = TypeModel)
class(PrepGR) <- c("PrepGR", "GR")
class(PrepGR) <- c("PrepGR", "GR", "airGRt")
return(PrepGR)
}
......@@ -81,7 +81,7 @@ SimGR <- function(PrepGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE",
CalCrit = CalGR$CalCrit, EffCrit = CRT,
PeriodModel = list(WarmUp = as.POSIXct(PrepGR$InputsModel$DatesR[range(MOD_opt$IndPeriod_WarmUp)], tz = "UTC"),
Run = SimPer))
class(SimGR) <- c("SimGR", "GR")
class(SimGR) <- c("SimGR", "GR", "airGRt")
return(SimGR)
}
\ No newline at end of file
as.data.frame.airGRt <- function(x, row.names = NULL, ...) {
if (!(inherits(x, "PrepGR") | inherits(x, "CalGR") | inherits(x, "SimGR"))) {
stop("'InputsCrit' must be of class 'PrepGR', 'CalGR', 'SimGR'")
}
TMGR <- .TypeModelGR(x)
myGR <- list()
myGR$PrecipSim <- NA
myGR$FracSolid <- NA
myGR$TempMean <- NA
if (inherits(x, "PrepGR")) {
if (TMGR$CemaNeige) {
PrecipSol <- rowMeans(as.data.frame(x$InputsModel$LayerPrecip) * as.data.frame(x$InputsModel$LayerFracSolidPrecip), na.rm = TRUE)
PrecipSim <- rowMeans(as.data.frame(x$InputsModel$LayerPrecip), na.rm = TRUE)
FracSolid <- PrecipSol / PrecipSim
FracSolid <- ifelse(is.na(FracSolid) & PrecipSol == 0 & PrecipSim == 0, 0, FracSolid)
myGR$PrecipSim <- PrecipSim
myGR$FracSolid <- FracSolid
TempMean <- rowMeans(as.data.frame(x$InputsModel$LayerTempMean), na.rm = TRUE)
myGR$TempMean <- TempMean
}
myGR$DatesR <- x$InputsModel$DatesR
myGR$PotEvap <- x$InputsModel$PotEvap
myGR$Precip <- x$InputsModel$Precip
myGR$Qobs <- x$Qobs
myGR$Qsim <- NA
}
if (inherits(x, "CalGR") | inherits(x, "SimGR")) {
if (TMGR$CemaNeige) {
PrecipSol <- rowMeans(sapply(x$OutputsModel$CemaNeigeLayers, "[[", "Psol"), na.rm = TRUE)
PrecipSim <- rowMeans(sapply(x$OutputsModel$CemaNeigeLayers, "[[", "Pliq"), na.rm = TRUE) + PrecipSol
FracSolid <- PrecipSol / PrecipSim
FracSolid <- ifelse(is.na(FracSolid) & PrecipSol == 0 & PrecipSim == 0, 0, FracSolid)
myGR$PrecipSim <- PrecipSim
myGR$FracSolid <- FracSolid
TempMean <- rowMeans(sapply(x$OutputsModel$CemaNeigeLayers, "[[", "Temp"), na.rm = TRUE)
myGR$TempMean <- TempMean
}
myGR$DatesR <- x$OutputsModel$DatesR
myGR$PotEvap <- x$OutputsModel$PotEvap
myGR$Precip <- x$OutputsModel$Precip
myGR$Qobs <- x$Qobs
myGR$Qsim <- x$OutputsModel$Qsim
}
TabSim <- data.frame(Dates = myGR$DatesR,
PotEvap = myGR$PotEvap,
PrecipObs = myGR$Precip,
PrecipSim_CemaNeige = myGR$PrecipSim,
PrecipFracSolid_CemaNeige = myGR$FracSolid,
TempMeanSim_CemaNeige = myGR$TempMean,
Qobs = myGR$Qobs,
Qsim = myGR$Qsim)
as.data.frame(x = TabSim, row.names = row.names, ...)
}
\encoding{UTF-8}
\name{as.data.frame}
\alias{as.data.frame.airGRt}
\alias{as.data.frame}
\title{Function to coerce the outputs of PrepGR, CalGR and SimGR to a data.frame.}
\usage{
\method{as.data.frame}{airGRt}(x, row.names = NULL, ...)
}
\arguments{
\item{x}{[object of class \emph{airGRt}] typically an object of class \code{\link{PrepGR}}, \code{\link{CalGR}} or \code{\link{SimGR}}}
\item{row.names}{\code{NULL} or a character vector giving the row names for the data frame. Missing values are not allowed}
\item{...}{additional arguments to be passed to or from methods}
}
\value{
[data.frame] containing:
\item{Dates}{[POSIXct] vector of dates}
\item{PotEvap}{[numeric] time series of potential evapotranspiration (catchment average) [mm/time step]}
\item{PrecipObs}{[numeric] time series of total precipitation (catchment average) [mm/time step]}
\item{PrecipSim_CemaNeige}{[numeric] time series of precipitation (layer average) [mm/time step],
defined CemaNeige is used}
\item{PrecipFracSolid_CemaNeige}{[numeric] time series of solid precipitation fraction (layer average) [-],
defined CemaNeige is used}
\item{TempMeanSim_CemaNeige}{[numeric] time series of mean air temperature (layer average) [°C],
defined CemaNeige is used}
\item{Qobs}{[numeric] time series of observed flow (for the same time steps than simulated) [mm/time step]}
\item{Qsim}{[numeric] time series of simulated flow (for the same time steps than simulated) [mm/time step] (only for objects of class \code{\link{CalGR}} or \code{\link{SimGR}})}
}
\seealso{
\code{\link{PrepGR}}, \code{\link{CalGR}}, \code{\link{SimGR}}
}
\description{Functions to coerce to a data.frame the outputs of PrepGR, CalGR and SimGR}
\author{Olivier Delaigue}
\examples{
library(airGRteaching)
## data.frame of observed data
data(L0123001, package = "airGR")
BasinObs2 <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
## Preparation of observed data for modelling
PREP <- PrepGR(ObsDF = BasinObs2, HydroModel = "GR4J", CemaNeige = FALSE)
head(as.data.frame(PREP))
## Calibration step
CAL <- CalGR(PrepGR = PREP, CalCrit = "KGE2",
WupPer = NULL, CalPer = c("1990-01-01", "1991-12-31"))
head(as.data.frame(CAL))
## Simulation step using the result of the automatic calibration method to set the model parameters
SIM <- SimGR(PrepGR = PREP, CalGR = CAL, EffCrit = "KGE2",
WupPer = NULL, SimPer = c("1992-01-01", "1992-12-31"))
head(as.data.frame(SIM))
}
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