Commit 2ead268e authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch '7-remove-gits-class-object-and-use-createinputsmodel-directly' into 'master'

Resolve "Remove Gits class object and use CreateInputsModel directly"

Closes #9, #10, and #7

See merge request in-wop/griwrm!3
Showing with 24 additions and 22 deletions
+24 -22
...@@ -28,7 +28,7 @@ Run `vignette("01_First_network", package = "griwrm")` before this one in order ...@@ -28,7 +28,7 @@ Run `vignette("01_First_network", package = "griwrm")` before this one in order
load("_cache/V01.RData") load("_cache/V01.RData")
``` ```
### Loading ### Loading
Data comes from calibration of ClimAware project with naturalised flows. Data comes from calibration of ClimAware project with naturalised flows.
...@@ -40,29 +40,31 @@ ClimAwareParams <- readr::read_csv( ...@@ -40,29 +40,31 @@ ClimAwareParams <- readr::read_csv(
ClimAwareParams ClimAwareParams
``` ```
The lag $\tau_0$ and route $K_0$ parameters of TGR are expressed as time delay in hours corresponding to the delay time between the farest upstream inlet and the outlet of the sub-basin. The lag $\tau_0$ and route $K_0$ parameters of TGR are expressed as time delay in hours corresponding to the delay time between the farest upstream inlet and the outlet of the sub-basin.
Almost all sub basin has only a lag parameter. The only exception is for La Marne à Noisiel (NOISI_17) that has a routing parameter which can be approximated to a single lag parameter equals to $\tau_0 + K_0$. Almost all sub basin has only a lag parameter. The only exception is for La Marne à Noisiel (NOISI_17) that has a routing parameter which can be approximated to a single lag parameter equals to $\tau_0 + K_0$.
This lag parameter has to be converted in a speed in m/s used in the airGR lag model: This lag parameter has to be converted in a speed in m/s used in the airGR lag model:
```{r} ```{r}
# Convert TGR routing parameter into speed # Convert TGR routing parameter into speed
params <- merge(ginet, ClimAwareParams, by.x = "id", by.y = "id_sgl") params <- merge(griwrm, ClimAwareParams, by.x = "id", by.y = "id_sgl")
for(id in girop$id) { ParamClimAware <- sapply(griwrm$id, function(id) {
# Maximum connection length with upstream nodes nodeParam <- ClimAwareParams[ClimAwareParams$id_sgl == id,]
UpstrNodes <- which(ginet$down == id & !is.na(ginet$down)) # Record hydrological model parameters
Param <- unlist(nodeParam[c("S", "IGF", "KR", "T")])
# Add lag model parameter if upstream nodes exist
UpstrNodes <- which(griwrm$down == id & !is.na(griwrm$down))
if(length(UpstrNodes) > 0) { if(length(UpstrNodes) > 0) {
maxLength <- max(ginet$length[UpstrNodes]) maxLength <- max(griwrm$length[UpstrNodes])
params$LAG <- maxLength * 1000 / ((params$Tau0 + params$K0) * 3600) Param <- c(
sLag <- "LAG" Param,
} else { maxLength / ((nodeParam$Tau0 + nodeParam$K0) * 3600)
sLag <- NULL )
} }
girop$params[girop$id == id] <- list(params[params$id == id, c("S", "IGF", "KR", "T", sLag)]) return(Param)
} })
dplyr::select(params, id, S, IGF, KR, T, LAG)
``` ```
## GriwmRunOptions object ## GriwmRunOptions object
...@@ -80,7 +82,7 @@ library(lubridate) ...@@ -80,7 +82,7 @@ library(lubridate)
IndPeriod_Run <- seq( IndPeriod_Run <- seq(
which(InputsModel[[1]]$DatesR == (InputsModel[[1]]$DatesR[1] + months(12))), # Set aside warm-up period 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 length(InputsModel[[1]]$DatesR) # Until the end of the time series
) )
``` ```
The warmup period could also be defined as is: The warmup period could also be defined as is:
...@@ -93,8 +95,8 @@ IndPeriod_WarmUp = seq(1,IndPeriod_Run[1]-1) ...@@ -93,8 +95,8 @@ IndPeriod_WarmUp = seq(1,IndPeriod_Run[1]-1)
```{r} ```{r}
RunOptions <- CreateRunOptions( RunOptions <- CreateRunOptions(
InputsModel = InputsModel, InputsModel = InputsModel,
IndPeriod_WarmUp = IndPeriod_WarmUp, IndPeriod_WarmUp = IndPeriod_WarmUp,
IndPeriod_Run = IndPeriod_Run IndPeriod_Run = IndPeriod_Run
) )
``` ```
...@@ -107,23 +109,23 @@ RunOptions <- CreateRunOptions( ...@@ -107,23 +109,23 @@ RunOptions <- CreateRunOptions(
OutputsModelsClimAware <- RunModel( OutputsModelsClimAware <- RunModel(
InputsModel = InputsModel, InputsModel = InputsModel,
RunOptions = RunOptions, RunOptions = RunOptions,
girop Param = ParamClimAware
) )
``` ```
## Save data for next vignettes ## Save data for next vignettes
```{r} ```{r}
save(RunOptions, file = "_cache/V02.RData") save(RunOptions, ParamClimAware, file = "_cache/V02.RData")
``` ```
## Plot the result for each basin ## Plot the result for each basin
```{r, fig.height = 5, fig.width = 8} ```{r, fig.height = 5, fig.width = 8}
htmltools::tagList(lapply( htmltools::tagList(lapply(
names(OutputsModelsClimAware), names(OutputsModelsClimAware),
function(x) { function(x) {
plot(OutputsModelsClimAware[[x]], Qobs = gits[[x]]$Qobs[IndPeriod_Run] , main = x) plot(OutputsModelsClimAware[[x]], Qobs = Qobs[IndPeriod_Run,x] , 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