Commit ed52b904 authored by Dorchies David's avatar Dorchies David
Browse files

doc: Add influenced flow calibration case

Refs #11
Showing with 146 additions and 7 deletions
+146 -7
Package: griwrm
Title: GR based Integrated Water Resource Management
Version: 0.3.0
Version: 0.3.1
Authors@R:
person(given = "David",
family = "Dorchies",
......
......@@ -78,7 +78,6 @@ The user must at least define the following arguments:
```{r}
library(lubridate)
IndPeriod_Run <- seq(
which(InputsModel[[1]]$DatesR == (InputsModel[[1]]$DatesR[1] + months(12))), # Set aside warm-up period
length(InputsModel[[1]]$DatesR) # Until the end of the time series
......
---
title: "03_First_Calibration"
title: "First calibration of the model"
author: "David Dorchies"
vignette: >
%\VignetteIndexEntry{Calibration of naturalised semi-distributive model}
......
---
title: "Running open-loop influenced semi-distributed flow model"
author: "David Dorchies"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Running open-loop influenced semi-distributed flow model}
......@@ -182,9 +183,17 @@ DiagramGriwrm(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:
```{r}
lCfgReservoirs <- jsonlite::read_json(system.file("seine_data", "config_reservoirs.json", package = "griwrm"))
str(lCfgReservoirs)
```
Then, we load observation data for each reservoir and each connection:
```{r}
for(reservoir_id in names(lCfgReservoirs)) {
df <- readr::read_delim(
......@@ -297,14 +306,13 @@ for(id in ids) {
ts$Q <- ts$Q * 86.4 / griwrm$area[griwrm$id == id] / 1000
# Setting data gaps to NA
ts$Q[ts$Q <= 0] <- NA
# Qnat column is merged into Qobs dataframe
# Column is merged into Qobs dataframe
Qobs2 <- MergeTS(Qobs2, id, ts[,c("Date", "Q")])
}
```
### Comparison with simulated flows
```{r, fig.height = 5, fig.width = 8}
## Save data for next vignettes
```{r}
ReduceOutputsModel <- function(OutputsModels, IndPeriod) {
items <- names(OutputsModels)
OutputsModelsOut <- sapply(items, function(x) {OutputsModels[[x]] <- OutputsModels[[x]][IndPeriod]})
......@@ -313,6 +321,13 @@ ReduceOutputsModel <- function(OutputsModels, IndPeriod) {
return(OutputsModelsOut)
}
QobsReservoirs <- Qobs[Qobs$DatesR < "2008-08-01",c("DatesR", reservoir_connections$id)]
save(QobsReservoirs, Qobs2, griwrm2, ReduceOutputsModel, file = "_cache/V04.RData")
```
### Comparison with simulated flows
```{r, fig.height = 5, fig.width = 8}
htmltools::tagList(lapply(
ids,
function(x) {
......@@ -325,3 +340,4 @@ htmltools::tagList(lapply(
```
---
title: "Calibration of an open-loop influenced flow model"
author: "David Dorchies"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Calibration of an open-loop influenced flow model}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(griwrm)
```
This vignette proposes an example of calibration of influenced flow with the Marne reservoir. It will used influenced observation flows directly measured at gauging stations and flows recorded at reservoir inlets and outlet.
## Set the data
Loading naturalised data and influenced flow configuration:
```{r}
load("_cache/V01b.RData")
load("_cache/V04.RData")
```
Remove extra items from global configuration
```{r}
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)
```
Generate `GriwrmInputsModel` object
```{r}
Qobs3 <- cbind(Qobs2, QobsReservoirs)
iEnd <-which(DatesR == lubridate::ymd("2008-07-31"))
InputsModel3 <- CreateInputsModel(griwrm3, DatesR[1:iEnd], Precip[1:iEnd,], PotEvap[1:iEnd,], Qobs3)
```
## GriwmRunOptions object
```{r}
IndPeriod_Run <- seq(
which(InputsModel3[[1]]$DatesR == (InputsModel3[[1]]$DatesR[1] + months(12))), # Set aside warm-up period
length(InputsModel3[[1]]$DatesR) # Until the end of the time series
)
```
The warmup period could also be defined as is:
```{r}
IndPeriod_WarmUp = seq(1,IndPeriod_Run[1]-1)
```
```{r}
RunOptions <- CreateRunOptions(
InputsModel = InputsModel3,
IndPeriod_WarmUp = IndPeriod_WarmUp,
IndPeriod_Run = IndPeriod_Run
)
```
## InputsCrit object
```{r}
InputsCrit <- CreateInputsCrit(
InputsModel = InputsModel3,
FUN_CRIT = airGR::ErrorCrit_KGE2,
RunOptions = RunOptions, Qobs = Qobs3
)
```
## GriwrmCalibOptions object
```{r}
CalibOptions <- CreateCalibOptions(InputsModel3)
str(CalibOptions)
```
## Calibration
```{r warning = FALSE}
OutputsCalib <- Calibration(InputsModel3, RunOptions, InputsCrit, CalibOptions)
```
## Run model with Michel calibration
```{r}
ParamMichel <- sapply(griwrm3$id, function(x) {OutputsCalib[[x]]$Param})
OutputsModels3 <- RunModel(
InputsModel = InputsModel3,
RunOptions = RunOptions,
Param = ParamMichel
)
```
### Comparison with simulated flows
```{r, fig.height = 5, fig.width = 8}
htmltools::tagList(lapply(
griwrm3$id[!is.na(griwrm3$model)],
function(x) {
Q3 <- Qobs3[RunOptions[[1]]$IndPeriod_Run,x]
iQ3 <- which(!is.na(Q3))
IndPeriod_Obs <- iQ3[1]:tail(iQ3,1)
OutputsModels <- ReduceOutputsModel(OutputsModels3[[x]], IndPeriod_Obs)
plot(OutputsModels, Qobs = Q3[IndPeriod_Obs] , main = x)
}
))
```
Supports Markdown
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