diff --git a/DESCRIPTION b/DESCRIPTION index be8edbd28cde1c3eced7384be9d73a1b600963d0..0507aac19d3ec9c21b7c817a10147dce13b9a961 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,5 +37,5 @@ VignetteBuilder: Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.0 Language: en-US diff --git a/R/CreateGRiwrm.R b/R/CreateGRiwrm.R index e55754b5f16cd8644fa0f8d9a53f98831b8a6a23..f5f9fe3980ab6ee70a317efb876dd83eb76ed2ba 100644 --- a/R/CreateGRiwrm.R +++ b/R/CreateGRiwrm.R @@ -1,23 +1,36 @@ -#' Generation of a network description containing all hydraulic nodes and the description -#' of their connections +#' Generation of a network description containing all hydraulic nodes and the +#' description of their connections #' #' @details `db` is a [data.frame] which at least contains in its columns: #' #' * a node identifier (column `id`), -#' * the identifier and the hydraulic distance to the downstream node ([character] columns `down` and [numeric] columns `length` in km). The last downstream node should have fields `down` and `length` set to `NA`, +#' * the identifier and the hydraulic distance to the downstream node +#' ([character] columns `down` and [numeric] columns `length` in km). The +#' last downstream node should have fields `down` and `length` set to `NA`, #' * the area of the basin ([numeric] column `area` in km2) -#' * the hydrological model to use if necessary ([character] column `model`) ([NA] for using observed flow instead of a runoff model output) +#' * the hydrological model to use or [NA] for using observed flow instead of a +#' runoff model output ([character] column `model`) #' #' @param db [data.frame] description of the network (See details) -#' @param cols [list] or [vector] columns of `db`. By default, mandatory column names are: `id`, `down`, `length`. Other names can be handled with a named list or vector containing items defined as `"required name" = "column name in db"` -#' @param keep_all [logical] indicating if all columns of `db` should be kept or if only columns defined in `cols` should be kept +#' @param cols [list] or [vector] columns of `db`. By default, mandatory column +#' names are: `id`, `down`, `length`, `area` and `model`. Other names can be +#' handled with a named list or vector containing items defined as `"required +#' name" = "column name in db"` (See details) +#' @param keep_all [logical] indicating if all columns of `db` should be kept +#' or if only columns defined in `cols` should be kept #' -#' @return [data.frame] of class `GRiwrm` describing the airGR semi-distributed model network, with each line corresponding to a location on the river network and with the following columns: +#' @return [data.frame] of class `GRiwrm` describing the airGR semi-distributed +#' model network, with each line corresponding to a location on the river +#' network and with the following columns: #' * `id` ([character]): node identifier -#' * `down` ([character]): identifier of the node downstream of the current node ([NA] for the most downstream node) -#' * `length` ([numeric]): hydraulic distance to the downstream node in km ([NA] for the most downstream node) -#' * `area` ([numeric]): total area of the basin starting from the current node location in km2 -#' * `model` ([character]): hydrological model to use if necessary ([NA] for using observed flow instead of a runoff model output) +#' * `down` ([character]): identifier of the node downstream of the current +#' node ([NA] for the most downstream node) +#' * `length` ([numeric]): hydraulic distance to the downstream node in km +#' ([NA] for the most downstream node) +#' * `area` ([numeric]): total area of the basin starting from the current +#' node location in km2 +#' * `model` ([character]): hydrological model to use ([NA] for using observed +#' flow instead of a runoff model output) #' #' @aliases GRiwrm #' @export @@ -61,7 +74,8 @@ CreateGRiwrm <- function(db, #' Check of the column types of a [data.frame] #' #' @param df [data.frame] to check -#' @param coltypes named [list] with the name of the columns to check as key and the required type as value +#' @param coltypes named [list] with the name of the columns to check as key and +#' the required type as value #' @param keep_all [logical] if `df` contains extra columns #' #' @return [NULL] or error message if a wrong type is detected @@ -100,7 +114,7 @@ getNodeRanking <- function(griwrm) { if (!inherits(griwrm, "GRiwrm")) { stop("getNodeRanking: griwrm argument should be of class GRiwrm") } - # Remove nodes without model (direct flow connections treated as upstream flows only) + # Remove upstream nodes without model (direct flow connections) griwrm <- griwrm[!is.na(griwrm$model),] # Rank 1 rank <- setdiff(griwrm$id, griwrm$down) @@ -112,6 +126,9 @@ getNodeRanking <- function(griwrm) { } ranking <- unique(ranking, fromLast = TRUE) ranking <- ranking[-length(ranking)] + # Remove intermediate nodes without model (direct flow connections) + ranking <- ranking[ranking %in% griwrm$id] + return(ranking) } checkNetworkConsistency <- function(db) { diff --git a/man/CreateGRiwrm.Rd b/man/CreateGRiwrm.Rd index ab1ad3510b16b6db0441e4eccd6591f0dceb0e6b..012eb41bf2db3c1464698d0f7126425eb954591f 100644 --- a/man/CreateGRiwrm.Rd +++ b/man/CreateGRiwrm.Rd @@ -3,8 +3,8 @@ \name{CreateGRiwrm} \alias{CreateGRiwrm} \alias{GRiwrm} -\title{Generation of a network description containing all hydraulic nodes and the description -of their connections} +\title{Generation of a network description containing all hydraulic nodes and the +description of their connections} \usage{ CreateGRiwrm( db, @@ -16,31 +16,43 @@ CreateGRiwrm( \arguments{ \item{db}{\link{data.frame} description of the network (See details)} -\item{cols}{\link{list} or \link{vector} columns of \code{db}. By default, mandatory column names are: \code{id}, \code{down}, \code{length}. Other names can be handled with a named list or vector containing items defined as \code{"required name" = "column name in db"}} +\item{cols}{\link{list} or \link{vector} columns of \code{db}. By default, mandatory column +names are: \code{id}, \code{down}, \code{length}, \code{area} and \code{model}. Other names can be +handled with a named list or vector containing items defined as \code{"required name" = "column name in db"} (See details)} -\item{keep_all}{\link{logical} indicating if all columns of \code{db} should be kept or if only columns defined in \code{cols} should be kept} +\item{keep_all}{\link{logical} indicating if all columns of \code{db} should be kept +or if only columns defined in \code{cols} should be kept} } \value{ -\link{data.frame} of class \code{GRiwrm} describing the airGR semi-distributed model network, with each line corresponding to a location on the river network and with the following columns: +\link{data.frame} of class \code{GRiwrm} describing the airGR semi-distributed +model network, with each line corresponding to a location on the river +network and with the following columns: \itemize{ \item \code{id} (\link{character}): node identifier -\item \code{down} (\link{character}): identifier of the node downstream of the current node (\link{NA} for the most downstream node) -\item \code{length} (\link{numeric}): hydraulic distance to the downstream node in km (\link{NA} for the most downstream node) -\item \code{area} (\link{numeric}): total area of the basin starting from the current node location in km2 -\item \code{model} (\link{character}): hydrological model to use if necessary (\link{NA} for using observed flow instead of a runoff model output) +\item \code{down} (\link{character}): identifier of the node downstream of the current +node (\link{NA} for the most downstream node) +\item \code{length} (\link{numeric}): hydraulic distance to the downstream node in km +(\link{NA} for the most downstream node) +\item \code{area} (\link{numeric}): total area of the basin starting from the current +node location in km2 +\item \code{model} (\link{character}): hydrological model to use (\link{NA} for using observed +flow instead of a runoff model output) } } \description{ -Generation of a network description containing all hydraulic nodes and the description -of their connections +Generation of a network description containing all hydraulic nodes and the +description of their connections } \details{ \code{db} is a \link{data.frame} which at least contains in its columns: \itemize{ \item a node identifier (column \code{id}), -\item the identifier and the hydraulic distance to the downstream node (\link{character} columns \code{down} and \link{numeric} columns \code{length} in km). The last downstream node should have fields \code{down} and \code{length} set to \code{NA}, +\item the identifier and the hydraulic distance to the downstream node +(\link{character} columns \code{down} and \link{numeric} columns \code{length} in km). The +last downstream node should have fields \code{down} and \code{length} set to \code{NA}, \item the area of the basin (\link{numeric} column \code{area} in km2) -\item the hydrological model to use if necessary (\link{character} column \code{model}) (\link{NA} for using observed flow instead of a runoff model output) +\item the hydrological model to use or \link{NA} for using observed flow instead of a +runoff model output (\link{character} column \code{model}) } } \examples{ diff --git a/vignettes/V03_Open-loop_influenced_flow.Rmd b/vignettes/V03_Open-loop_influenced_flow.Rmd index 148c8309e6ea21dd1b27e221e3fd82f1c6fa871a..a68b78faacac587911e25e5669b47cd23b9dba23 100644 --- a/vignettes/V03_Open-loop_influenced_flow.Rmd +++ b/vignettes/V03_Open-loop_influenced_flow.Rmd @@ -26,9 +26,21 @@ library(airGRiwrm) ## Presentation of the study case -The calibration results shown in vignette 'V02_Calibration_SD_model' for the flows simulated on the Avon at Evesham (Gauging station '54002') and on the Severn at Buildwas (Gauging station '54095') are not fully satisfactory, especially regarding low flows. These upper basins are actually heavily influenced by impoundments and inter-basin transfers [@higgsHydrologicalChangesRiver1988]. +The calibration results shown in vignette 'V02_Calibration_SD_model' for the +flows simulated on the Avon at Evesham (Gauging station '54002') and on the +Severn at Buildwas (Gauging station '54095') are not fully satisfactory, +especially regarding low flows. These upper basins are actually heavily +influenced by impoundments and inter-basin transfers [@higgsHydrologicalChangesRiver1988]. -To cope with these influences, in this vignette, we will not try to simulate the basin functioning with an hydrological model but we will rather directly inject in the model the observed flows at these nodes. +So, to cope with these influences, in this vignette, we use direct injection of +observed influenced flows instead of modelling natural flow with an hydrological model. + +We use observation on the Avon at Evesham (Gauging station '54002') and we +choose to do the same on the Severn at Bewdley (Gauging station '54001') as if +the observed flow at these locations would be the observed release of a dam. + +Please note that the flow on the Severn at Buildwas (Gauging station '54095') is +still simulated but its flows is no longer routed to downstream. ## Conversion of a gauging station into a release spot @@ -49,7 +61,7 @@ To notify the SD model that the provided flows on a node should be directly used ```{r} griwrmV03 <- griwrm griwrmV03$model[griwrm$id == "54002"] <- NA -griwrmV03$model[griwrm$id == "54095"] <- NA +griwrmV03$model[griwrm$id == "54001"] <- NA griwrmV03 ``` @@ -82,7 +94,7 @@ Qobs <- cbind(sapply(BasinsObs, function(x) {x$discharge_spec})) This time, we need to provide observed flows as inputs for the nodes '54002' and '54095': ```{r} -QobsInputs <- Qobs[, c("54002", "54095")] +QobsInputs <- Qobs[, c("54001", "54002")] ``` Then, the `GRiwrmInputsModel` object can be generated taking into account the new `GRiwrm` object: @@ -110,7 +122,7 @@ RunOptions <- CreateRunOptions(IM_OL, InputsCrit <- CreateInputsCrit(IM_OL, FUN_CRIT = ErrorCrit_KGE2, RunOptions = RunOptions, Obs = Qobs[IndPeriod_Run,], - AprioriIds = c("54057" = "54032", "54032" = "54001"), + AprioriIds = c("54057" = "54032", "54032" = "54029"), transfo = "sqrt", k = 0.15 ) CalibOptions <- CreateCalibOptions(IM_OL) diff --git a/vignettes/seinebasin/V04_Open-loop_influenced_flow.Rmd b/vignettes/seinebasin/V04_Open-loop_influenced_flow.Rmd index fc0dbe1285a8ebb5cccd99ba6bcc3f6127ab33e1..b91cd76292c0e480a1c9be52afa2baa4246b59df 100644 --- a/vignettes/seinebasin/V04_Open-loop_influenced_flow.Rmd +++ b/vignettes/seinebasin/V04_Open-loop_influenced_flow.Rmd @@ -23,11 +23,15 @@ library(airGRiwrm) ## Integration of the reservoir connections into the model -The aim of this vignette is to add reservoir connections to the Seine River model previously set up. A complete description of the reservoir system of the Seine River can be found in @dehayEtudeImpactChangement2012 +The aim of this vignette is to add reservoir connections to the Seine River model +previously set up. A complete description of the reservoir system of the Seine +River can be found in @dehayEtudeImpactChangement2012 ### Add connections to the reservoirs in the gauging station network -Because of the **airGR** SD model structure, the topology of the network will differ between the physical one and the modeled one. In the following, we provide details for each of the 4 lakes, and then we present the complete SD network. +Because of the **airGR** SD model structure, the topology of the network will +differ between the physical one and the modeled one. In the following, we provide +details for each of the 4 lakes, and then we present the complete SD network. First, the physical topology of the Aube lake is represented below: @@ -52,7 +56,9 @@ style AUBE fill:#ccf ", width = "100%") ``` -In the SD model, we do not simulate intermediate flows as well as the reservoir in the catchment. As a result, an equivalent topology compatible with **airGR** will be the one below: +In the SD model, we do not simulate intermediate flows as well as the reservoir +in the catchment. As a result, an equivalent topology compatible with **airGR** +will be the one below: ```{r mmd_aube_model, echo = FALSE} mmd(" @@ -65,7 +71,8 @@ style AUBE_R3 fill:#fcc ", width = "100%") ``` -`AUBE_P2` will propagate negative flows downstream (reservoir inflows) while `AUBE_R3` will propagate positive flows downstream (reservoir releases). +`AUBE_P2` will propagate negative flows downstream (reservoir inflows) while +`AUBE_R3` will propagate positive flows downstream (reservoir releases). The configuration on the lake Seine is similar: @@ -108,21 +115,19 @@ style P fill:#ccf ", width = "100%") ``` -It can be modeled as: +We can keep the same structure to model it. `PANNEC_R` corresponds to the flow +released by the Pannecière lake, it is acting as an upstream node which means +that the flow simulated at `CHAUM_07` is no longer routed to downstream. ```{r mmd_pannec_model, echo = FALSE} mmd(" graph LR -CHAUM_07 --> |153km| GURGY_02 -PANNEC_P --> |153km| GURGY_02 +CHAUM_07 --> |0km| PANNEC_R PANNEC_R --> |153km| GURGY_02 -style PANNEC_P fill:#fcc style PANNEC_R fill:#fcc ", width = "100%") ``` -With $Q_{PANNEC\_P} = - Q_{CHAUM\_07}$ as all the upstream flows fill the reservoir. - The Marne lake can be mapped as: ```{r mmd_marne_true, echo = FALSE} @@ -177,13 +182,17 @@ reservoir_connections$model <- NA reservoir_connections$area <- NA load("_cache/V01.RData") griwrm2 <- rbind(griwrm, reservoir_connections[, names(griwrm)]) +# Insert PANNEC_R between CHAUM_07 and GURGY_02 +griwrm2$down[griwrm2$id == "CHAUM_07"] <- "PANNEC_R" +griwrm2$length[griwrm2$id == "CHAUM_07"] <- 0 plot(griwrm2) ``` ## Loading reservoir observation time series -Description of the files, the columns and the type of connection (inlet / outlet) are defined in the list below: +Description of the files, the columns and the type of connection (inlet / outlet) +are defined in the list below: ```{r lCfgReservoirs} lCfgReservoirs <- jsonlite::read_json(system.file("seine_data", "config_reservoirs.json", package = "seinebasin")) @@ -198,24 +207,6 @@ data(QNAT) data(Qreservoirs) ``` -## How to handle an inline reservoir? The Pannecière lake case. - -There are two possibilities: - -- truncate the system and only simulate the release of the reservoir if we only care about downstream flows -- add a fictive inlet to the reservoir that will store all upstream discharge into the reservoir - -If we know in advance the flows released by the reservoir, upstream flow informations is not useful for the simulation. However, reservoir management simulation would require upstream flow informations for simulating the reservoir state during simulation. The second alternative will therefore be useful for the next phases. - -```{r Qnat} -Qreservoirs <- cbind( - Qreservoirs, - -Qnat[, "CHAUM_07"] * griwrm2$area[griwrm2$id == "CHAUM_07"] * 1e3 -) -colnames(Qreservoirs)[ncol(Qreservoirs)] <- "PANNEC_P" -``` - - ## Create the InputsModel object ```{r CreateInputsModel} @@ -236,7 +227,8 @@ load("_cache/V03.RData") ### How to handle former upstream sub-basins with upstream flows ? -A lag parameter is now mandatory for these sub-basins. As no calibration is possible at that stage an arbitrary one will be used (1 m/s). +A lag parameter is now mandatory for these sub-basins. As no calibration is +possible at that stage an arbitrary one will be used (1 m/s). ```{r ParamMichel} ParamMichel$STDIZ_04 <- c(1, ParamMichel$STDIZ_04)