page_5_sd_model.Rmd 9.83 KB
Newer Older
1
---
2
title: "Simulated vs observed upstream flows in calibration of semi-distributed GR4J model"
3
4
5
6
7
8
9
10
11
12
13
14
15
16
author: "David Dorchies"
bibliography: ref/airgr_web_ref.bib
output: 
  html_document:
    toc: true
    toc_float: true
    depth: 3  # upto three depths of headings (specified by #, ## and ###)
    number_sections: true  ## if you want number sections at each table header
    theme: united  # many options for theme, this one is my favorite.
    highlight: tango  # specifies the syntax highlighting style
---



17
18
19
20
21
22
23
24
25
```{r include=FALSE}
formatGR <- '<strong><font color="#00a3a6">%s</font></strong>'
GR            <- sprintf(formatGR, "GR")
airGR         <- sprintf(formatGR, "airGR")
airGRdatassim <- "[airGRdatassim](https://gitlab.irstea.fr/HYCAR-Hydro/airgrdatassim/-/tree/dev)"
airGRteaching <- "[airGR](https://hydrogr.github.io/airGRteaching/)"
```


26
27
28
29
30
31
32
33
34
```{r, include=FALSE, fig.keep='none', results='hide'}
library(airGR)
options(digits = 3)
```

# Introduction

## Scope

35
The `r airGR` package implements semi-distributed model capabilities using a lag model between subcatchments. It allows to chain together several lumped models as well as integrating anthropogenic influence such as reservoirs or withdrawals.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

`RunModel_Lag` documentation gives an example of simulating the influence of a reservoir in a lumped model. Try `example(RunModel_Lag)` to get it.

In this vignette, we show how to calibrate 2 sub-catchments in series with a semi-distributed model consisting of 2 GR4J models. For doing this we compare two strategies for calibrating the downstream subcatchment:

- using upstream observed flows
- using upstream simulated flows

We finally compare these calibrations with a theoretical set of parameters.

## Model description


```{r, warning=FALSE, include=FALSE}
library(airGR)
options(digits = 3)
```

We use an example data set from the package that unfortunately contains data for only one catchment.

```{r, warning=FALSE}
## loading catchment data
data(L0123001)
```

Let's imagine that this catchment of 360 km² is divided into 2 subcatchments:

- An upstream subcatchment of 180 km²
- 100 km downstream another subcatchment of 180 km²

We consider that meteorological data are homogeneous on the whole catchment, so we use the same pluviometry `BasinObs$P` and the same evapotranspiration `BasinObs$E` for the 2 subcatchments.

For the observed flow at the downstream outlet, we generate it with the assumption that the upstream flow arrives at downstream with a constant delay of 2 days.

```{r}
QObsDown <- (BasinObs$Qmm + c(0, 0, BasinObs$Qmm[1:(length(BasinObs$Qmm)-2)])) / 2
72
options(digits = 5)
73
summary(cbind(QObsUp = BasinObs$Qmm, QObsDown))
74
options(digits = 3)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
```

# Calibration of the upstream subcatchment

The operations are exactly the same as the ones for a GR4J lumped model. So we do exactly the same operations as in the [Get Started](V01_get_started.html) vignette.

```{r}
InputsModelUp <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR,
                                   Precip = BasinObs$P, PotEvap = BasinObs$E)
Ind_Run <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1990-01-01"),
               which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1999-12-31"))
RunOptionsUp <- CreateRunOptions(FUN_MOD = RunModel_GR4J,
                                 InputsModel = InputsModelUp,
                                 IndPeriod_WarmUp = NULL, IndPeriod_Run = Ind_Run,
                                 IniStates = NULL, IniResLevels = NULL)
InputsCritUp <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModelUp,
                                 RunOptions = RunOptionsUp,
                                 VarObs = "Q", Obs = BasinObs$Qmm[Ind_Run])
CalibOptionsUp <- CreateCalibOptions(FUN_MOD = RunModel_GR4J, FUN_CALIB = Calibration_Michel)
OutputsCalibUp <- Calibration_Michel(InputsModel = InputsModelUp, RunOptions = RunOptionsUp,
                                     InputsCrit = InputsCritUp, CalibOptions = CalibOptionsUp,
                                     FUN_MOD = RunModel_GR4J)
```

And see the result of the simulation:

```{r}
OutputsModelUp <- RunModel_GR4J(InputsModel = InputsModelUp, RunOptions = RunOptionsUp,
                                Param = OutputsCalibUp$ParamFinalR)
```


# Calibration of the downstream subcatchment with upstream flow observations

we need to create the `InputsModel` object completed with upstream information:

```{r}
InputsModelDown1 <- CreateInputsModel(
  FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR,
  Precip = BasinObs$P, PotEvap = BasinObs$E,
115
116
  Qupstream = matrix(BasinObs$Qmm, ncol = 1), # upstream observed flow
  LengthHydro = 100, # distance between upstream catchment outlet & the downstream one [km]
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  BasinAreas = c(180, 180) # upstream and downstream areas [km²]
)
```

And then calibrate the combination of Lag model for upstream flow transfer and GR4J model for the runoff of the downstream subcatchment:

```{r}
RunOptionsDown <- CreateRunOptions(FUN_MOD = RunModel_GR4J,
                                   InputsModel = InputsModelDown1,
                                   IndPeriod_WarmUp = NULL, IndPeriod_Run = Ind_Run,
                                   IniStates = NULL, IniResLevels = NULL)
InputsCritDown <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModelDown1,
                                   RunOptions = RunOptionsDown,
                                   VarObs = "Q", Obs = QObsDown[Ind_Run])
CalibOptionsDown <- CreateCalibOptions(FUN_MOD = RunModel_GR4J,
                                       FUN_CALIB = Calibration_Michel,
                                       IsSD = TRUE) # specify that it's a SD model
OutputsCalibDown1 <- Calibration_Michel(InputsModel = InputsModelDown1,
                                        RunOptions = RunOptionsDown,
                                        InputsCrit = InputsCritDown,
                                        CalibOptions = CalibOptionsDown,
                                        FUN_MOD = RunModel_GR4J)
```

To run the complete model, we should substitute the observed upstream flow by the simulated one:

```{r}
InputsModelDown2 <- InputsModelDown1
InputsModelDown2$Qupstream[Ind_Run] <- OutputsModelUp$Qsim
```

`RunModel` is run in order to automatically combine GR4J and Lag models.

```{r}
OutputsModelDown1 <- RunModel(InputsModel = InputsModelDown2,
                              RunOptions = RunOptionsDown,
                              Param = OutputsCalibDown1$ParamFinalR,
                              FUN_MOD = RunModel_GR4J)
```

Performance of the model validation is then:

```{r}
CritDown1 <- ErrorCrit_NSE(InputsCritDown, OutputsModelDown1)
```


# Calibration of the downstream subcatchment with upstream simulated flow

We calibrate the model with the `InputsModel` object previously created for substituting the observed upstream flow with the simulated one:

```{r}
OutputsCalibDown2 <- Calibration_Michel(InputsModel = InputsModelDown2,
                                        RunOptions = RunOptionsDown,
                                        InputsCrit = InputsCritDown,
                                        CalibOptions = CalibOptionsDown,
                                        FUN_MOD = RunModel_GR4J)
ParamDown2 <- OutputsCalibDown2$ParamFinalR
```


# Discussion

180
## Identification of Velocity parameter
181

182
The theoretical Velocity parameter should be equal to:
183
184

```{r}
185
186
Velocity <- InputsModelDown1$LengthHydro * 1e3 / (2 * 86400)
paste(format(Velocity), "m/s")
187
188
189
190
191
```

Both calibrations overestimate this parameter:

```{r}
192
193
194
195
196
197
198
199
200
mVelocity <- matrix(c(Velocity,
                      OutputsCalibDown1$ParamFinalR[1],
                      OutputsCalibDown2$ParamFinalR[1]),
                    ncol = 1,
                    dimnames = list(c("theoretical",
                                      "calibrated with observed upstream flow",
                                      "calibrated with simulated  upstream flow"),
                                    c("Velocity parameter")))
knitr::kable(mVelocity)
201
202
203
204
205
206
207
```

## Value of the performance criteria with theoretical calibration

Theoretically, the parameters of the downstream GR4J model should be the same as the upstream one and we know the lag time. So this set of parameter should give a better performance criteria:

```{r}
208
ParamDownTheo <- c(Velocity, OutputsCalibUp$ParamFinalR)
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
OutputsModelDownTheo <- RunModel(InputsModel = InputsModelDown2,
                                 RunOptions = RunOptionsDown,
                                 Param = ParamDownTheo,
                                 FUN_MOD = RunModel_GR4J)
CritDownTheo <- ErrorCrit_NSE(InputsCritDown, OutputsModelDownTheo)
```



## Parameters and performance of each subcatchment for all calibrations

```{r}
comp <- matrix(c(0, OutputsCalibUp$ParamFinalR,
                 rep(OutputsCalibDown1$ParamFinalR, 2),
                 OutputsCalibDown2$ParamFinalR,
                 ParamDownTheo),
               ncol = 5, byrow = TRUE)
comp <- cbind(comp, c(OutputsCalibUp$CritFinal,
                      OutputsCalibDown1$CritFinal,
                      CritDown1$CritValue,
                      OutputsCalibDown2$CritFinal,
                      CritDownTheo$CritValue))
231
colnames(comp) <- c("Velocity", paste0("X", 1:4), "NSE")
232
233
234
235
236
237
238
239
240
rownames(comp) <- c("Calibration of the upstream subcatchment",
                    "Calibration 1 with observed upstream flow",
                    "Validation 1 with simulated upstream flow",
                    "Calibration 2 with simulated upstream flow",
                    "Validation theoretical set of parameters")
knitr::kable(comp)
```

Even if calibration with observed upstream flows gives an improved performance criteria, in validation using simulated upstream flows the result is quite similar as the performance obtained with the calibration with upstream simulated flows. The theoretical set of parameters give also an equivalent performance but still underperforming the calibration 2 one.