Commit 8aa60df2 authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch '12-diagram-of-calibrated-model' into 'dev'

Resolve "Diagram of calibrated model"

Closes #12

See merge request !16
parents 5c5fc75a 74cc374f
Pipeline #23479 passed with stages
in 15 minutes and 38 seconds
......@@ -10,3 +10,4 @@
^_pkgdown\.yml$
^pkgdown
^docs
^vignettes/seinebasin$
......@@ -18,6 +18,7 @@ S3method(RunModel,GRiwrmInputsModel)
S3method(RunModel,InputsModel)
S3method(RunModel,SD)
S3method(RunModel,Supervisor)
S3method(plot,GRiwrm)
S3method(plot,GRiwrmOutputsModel)
S3method(plot,Qm3s)
export(Calibration)
......@@ -29,7 +30,6 @@ export(CreateInputsCrit)
export(CreateInputsModel)
export(CreateRunOptions)
export(CreateSupervisor)
export(DiagramGRiwrm)
export(GRiwrm)
export(RunModel)
export(createControl)
......
#' Display a diagram representing the network structure of a GRiwrm object
#'
#' @param griwrm the GRiwrm object to display.
#' @param display if `TRUE` displays the diagram with `DiagrammeR::mermaid`, return the mermaid code otherwise.
#' @param orientation Orientation of the graph. "LR" by default.
#' @param x a GRiwrm object to display (See [GRiwrm])
#' @param display if `TRUE` displays the diagram with [DiagrammeR::mermaid], return the mermaid code otherwise
#' @param orientation a [character] describing the orientation of the graph. Possible values are "LR" (left-right), "RL" (right-left), "TB" (top-bottom), or "BT" (bottom-top). "LR" by default
#' @param width The width of the resulting graphic in pixels (See [DiagrammeR::mermaid])
#' @param height The height of the resulting graphic in pixels (See [DiagrammeR::mermaid])
#' @param ... Other arguments and parameters you would like to send to JavaScript (See [DiagrammeR::mermaid])
#'
#' @details This function only works inside RStudio because the HTMLwidget produced by DiagrammeR
#' is not handled on some platforms
......@@ -14,19 +17,19 @@
#' @examples
#' \dontrun{
#' # Display diagram
#' DiagramGRiwrm(griwrm)
#' plot.GRiwrm(griwrm)
#' # Is the same as
#' DiagrammeR::mermaid(DiagramGRiwrm(griwrm, display = FALSE), width = "100%", height = "100%")
#' DiagrammeR::mermaid(plot.GRiwrm(griwrm, display = FALSE), width = "100%", height = "100%")
#' }
#'
DiagramGRiwrm <- function(griwrm, display = TRUE, orientation = "LR") {
plot.GRiwrm <- function(x, display = TRUE, orientation = "LR", width = "100%", height = "100%", ...) {
if(Sys.getenv("RSTUDIO") != "1") {
return()
}
if(!"DiagrammeR" %in% rownames(utils::installed.packages())) {
stop("The 'DiagrammeR' package should be installed. Type: install.packages('DiagrammeR')")
}
g2 <- griwrm[!is.na(griwrm$down),]
g2 <- x[!is.na(x$down),]
nodes <- paste(
g2$id,
"-->|",
......@@ -38,7 +41,7 @@ DiagramGRiwrm <- function(griwrm, display = TRUE, orientation = "LR") {
styleDF <- paste("style", unique(g2$id[is.na(g2$model)]), "fill:#fcc")
diagram <- paste(c(paste("graph", orientation), nodes, styleSD, styleDF), collapse = "\n")
if(display) {
DiagrammeR::mermaid(diagram, width = "100%", height = "100%")
DiagrammeR::mermaid(diagram = diagram, width, height, ...)
} else {
return(diagram)
}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/DiagramGRiwrm.R
\name{DiagramGRiwrm}
\alias{DiagramGRiwrm}
% Please edit documentation in R/plot.GRiwrm.R
\name{plot.GRiwrm}
\alias{plot.GRiwrm}
\title{Display a diagram representing the network structure of a GRiwrm object}
\usage{
DiagramGRiwrm(griwrm, display = TRUE, orientation = "LR")
\method{plot}{GRiwrm}(
x,
display = TRUE,
orientation = "LR",
width = "100\%",
height = "100\%",
...
)
}
\arguments{
\item{griwrm}{the GRiwrm object to display.}
\item{x}{a GRiwrm object to display (See \link{GRiwrm})}
\item{display}{if \code{TRUE} displays the diagram with \code{DiagrammeR::mermaid}, return the mermaid code otherwise.}
\item{display}{if \code{TRUE} displays the diagram with \link[DiagrammeR:mermaid]{DiagrammeR::mermaid}, return the mermaid code otherwise}
\item{orientation}{Orientation of the graph. "LR" by default.}
\item{orientation}{a \link{character} describing the orientation of the graph. Possible values are "LR" (left-right), "RL" (right-left), "TB" (top-bottom), or "BT" (bottom-top). "LR" by default}
\item{width}{The width of the resulting graphic in pixels (See \link[DiagrammeR:mermaid]{DiagrammeR::mermaid})}
\item{height}{The height of the resulting graphic in pixels (See \link[DiagrammeR:mermaid]{DiagrammeR::mermaid})}
\item{...}{Other arguments and parameters you would like to send to JavaScript (See \link[DiagrammeR:mermaid]{DiagrammeR::mermaid})}
}
\value{
Mermaid code of the diagram id display is \code{FALSE}.
......@@ -26,9 +39,9 @@ is not handled on some platforms
\examples{
\dontrun{
# Display diagram
DiagramGRiwrm(griwrm)
plot.GRiwrm(griwrm)
# Is the same as
DiagrammeR::mermaid(DiagramGRiwrm(griwrm, display = FALSE), width = "100\%", height = "100\%")
DiagrammeR::mermaid(plot.GRiwrm(griwrm, display = FALSE), width = "100\%", height = "100\%")
}
}
......@@ -66,7 +66,7 @@ griwrm
The diagram of the network structure is represented below with in blue the upstream nodes with a GR4J model and in green the intermediate nodes with an SD (GR4J + LAG) model.
```{r diagram}
DiagramGRiwrm(griwrm)
plot(griwrm)
```
......
......@@ -58,7 +58,7 @@ The diagram of the network structure is represented below with:
* in red the node with direct flow injection (no hydrological model)
```{r diagram}
DiagramGRiwrm(griwrmV03)
plot(griwrmV03)
```
### Generate the GRiwrmInputsModel object
......
......@@ -60,7 +60,7 @@ griwrmV04 <- rbind(
area = NA
)
)
DiagramGRiwrm(griwrmV04)
plot(griwrmV04)
```
Nodes in red color are direct injection points (positive or negative flow) in the model, green nodes simulate either sub-basin rainfall-runoff and routing of upstream node flows and grey nodes simulate sub-basin rainfall-runoff flows only.
......
......@@ -53,15 +53,15 @@ griwrm
The diagram of the network structure is represented below with in blue the upstream nodes with a GR4J model and in green the intermediate nodes with an SD (GR4J + LAG) model.
```{r DiagramGRiwrm, fig.height = 7, fig.width = 8}
DiagramGRiwrm(griwrm)
```{r plot, fig.height = 7, fig.width = 8}
plot(griwrm)
```
## Observation time series
The daily mean precipitation and potential evaporation at the scale of the intermediate sub-basins are extracted from the SAFRAN reanalysis [@vidal50yearHighresolutionAtmospheric2010].
The daily mean precipitation and potential evaporation at the scale of the intermediate sub-basins are extracted from the SAFRAN reanalysis [@vidal50yearHighresolutionAtmospheric2010].
The daily naturalised flow is provided by @hydratecActualisationBaseDonnees2011a.
......
......@@ -176,7 +176,7 @@ reservoir_connections$model <- NA
reservoir_connections$area <- NA
load("_cache/V01.RData")
griwrm2 <- rbind(griwrm, reservoir_connections[, names(griwrm)])
DiagramGRiwrm(griwrm2)
plot(griwrm2)
```
......
......@@ -37,7 +37,7 @@ Remove extra items from global configuration
selectedNodes <- c("MARNE_P23", "STDIZ_04", "LOUVE_19", "VITRY_25", "MARNE_P28", "MARNE_R25", "CHALO_21", "MONTR_18", "NOISI_17")
griwrm3 <- griwrm2[griwrm2$id %in% selectedNodes,]
griwrm3[griwrm3$id == "NOISI_17", c("down", "length")] = NA # Downstream station instead of PARIS_05
DiagramGRiwrm(griwrm3)
plot(griwrm3)
```
Generate `GRiwrmInputsModel` object
......
......@@ -38,7 +38,7 @@ selectedNodes <- c("MARNE_P23", "STDIZ_04", "LOUVE_19", "VITRY_25", "MARNE_P28",
griwrm3 <- griwrm2[griwrm2$id %in% selectedNodes,]
griwrm3$model[!is.na(griwrm3$model)] <- "RunModel_GR6J"
griwrm3[griwrm3$id == "NOISI_17", c("down", "length")] = NA # Downstream station instead of PARIS_05
DiagramGRiwrm(griwrm3)
plot(griwrm3)
```
Generate `GRiwrmInputsModel` object
......
......@@ -22,7 +22,7 @@ library(seinebasin)
This vignette is an example of flow naturalisation by modelling [@terrierStreamflowNaturalizationMethods2020].
By using the model calibrated with influenced flow on the Marne River, it's now possible to model naturalised flows by dropping the connections to the Marne reservoir from the model.
By using the model calibrated with influenced flow on the Marne River, it's now possible to model naturalised flows by dropping the connections to the Marne reservoir from the model.
## Set the data
......@@ -49,7 +49,7 @@ Remove extra items from global configuration
selectedNodes <- c("STDIZ_04", "LOUVE_19", "VITRY_25", "CHALO_21", "MONTR_18", "NOISI_17")
griwrm4 <- griwrm[griwrm$id %in% selectedNodes,]
griwrm4[griwrm4$id == "NOISI_17", c("down", "length")] = NA # Downstream station instead of PARIS_05
DiagramGRiwrm(griwrm4)
plot(griwrm4)
```
Generate `GRiwrmInputsModel` object
......
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