# Water Level Simulation in River Network by Data Assimilation Using Ensemble Kalman Filter
## 4 Application of Ensemble Kalman Filter  
In this study we established a new scheme based on EnKF and applied it to a river network hydrodynamic system. A three-stage joint solution method was used to solve the hydrodynamic model of the river network, and the water level was selected as the state variable of the nonlinear dynamic system of the river network. Before the start of the filtering treatment, the Box-Muller transform method was used to generate an initial sample ensemble of nodal water level randomly. The data followed the normal distribution \(N(\mu,\sigma^{2})\). To ensure the diversity of the sampling data, with reasonable dispersion, the average value \(\mu\) was determined based on the simulated water level at the start of filtering, and the standard deviation was also set as a certain proportion of the nodal water depth at the start of filtering. The initial sample ensemble of the nodal water level was generated by means of the Box-Muller transform method. Its average value \(\overline{\mathbf{X}}\) is shown as:  
\[\overline{\mathbf{X}}=\frac{1}{m}\underset{i=1}{\overset{m}{\sum}}\mathbf{X}_{ i}, \tag{19}\]  
where \(m\) represents the number of samples, i.e., the size of the ensemble. The sample values obey a normal distribution and have a standard deviation of \(\sigma\). The disturbance term \(\Delta\mathbf{X}_{i}\) for the \(i\)th ensemble member is  
\[\Delta\mathbf{X}_{i}=\mathbf{X}_{i}-\overline{\mathbf{X}}, \tag{20}\]  
and \(\Delta\mathbf{X}\) is defined as the ensemble of disturbance terms:  
\[\Delta\mathbf{X}=(\Delta\mathbf{X}_{1},\Delta\mathbf{X}_{2},\cdots,\Delta \mathbf{X}_{m}). \tag{21}\]  
Then, the error variance matrix can be expressed as follows:  
\[\mathbf{P}=\frac{1}{m-1}\Delta\mathbf{X}(\Delta\mathbf{X})^{T}, \tag{22}\]  
The data assimilation process for river networks using the EnKF algorithm is shown in Figure 1. The details of the algorithm's development are shown below. When filtering, the first step is to calculate the state simulation values of each sample set, that is, the prediction values \(\mathbf{\hat{X}}_{k/k-1}\):  
\[\mathbf{\hat{X}}_{k/k-1}=\mathbf{\Phi}_{k}(\mathbf{\hat{X}}_{k-1}) \tag{23}\]Then, the prediction error variance matrix and gain matrix are calculated as in Equations (24) and (25), respectively. Calculating the gain matrix requires the introduction of the observation noise level, that is, the observation error. The Box-Muller method is also used to discretize the observation data to obtain the observation set, which is fed into the ensemble Kalman filtering algorithm, together with the forecast water level set for assimilation, to obtain a set of assimilated water levels, whose mean value is the optimal solution for data assimilation. \[\mathbf{P}_{k/k-1}=\frac{1}{m-1}\Delta\mathbf{\hat{X}}_{k/k-1}(\Delta\mathbf{\hat{X}}_{k/k- 1})^{T}, \tag{24}\]  
\[\mathbf{K}_{k}=\mathbf{P}_{k/k-1}\mathbf{H}_{k}^{T}(\mathbf{H}_{k}\mathbf{P}_{k/k-1}\mathbf{H}_{k}^{T}+ \mathbf{R}_{k})^{-1}, \tag{25}\]  
where \(\mathbf{R}_{k}\) is the observation error covariance; \(\mathbf{P}_{k/k-1}\mathbf{H}_{k}^{T}\) and \(\mathbf{H}_{k}\mathbf{P}_{k/k-1}\mathbf{H}_{k}^{T}\) are calculated according to the following equations:  
\[\mathbf{P}_{k/k-1}\mathbf{H}_{k}^{T}=\frac{1}{m-1}\sum_{i=1}^{m} \begin{array}{c}[ \mathbf{\hat{X}}_{i}^{k/k-1}-\overline{\mathbf{\hat{X}}_{k/k-1}}]\times\\ [\mathbf{H}_{k}(\mathbf{\hat{X}}_{i}^{k/k-1})-\overline{\mathbf{H}_{k}(\mathbf{\hat{X}}_{k/k-1 })}]^{T}\end{array} , \tag{26}\]  
\[\mathbf{H}_{k}\mathbf{P}_{k/k-1}\mathbf{H}_{k}^{T}=\frac{1}{m-1}\sum_{i=1}^{m} \begin{array} []{c}[\mathbf{H}_{k}(\mathbf{\hat{X}}_{i}^{k/k-1})-\overline{\mathbf{H}_{k}(\mathbf{\hat{X}}_ {k/k-1})}]\times\\ [\mathbf{H}_{k}(\mathbf{\hat{X}}_{i}^{k/k-1})-\overline{\mathbf{H}_{k}(\mathbf{\hat{X}}_{k/k-1 })}]^{T}\end{array}