# HYPE Model Documentation

### Wiki editing/maintenance

start:hype_tutorials:assimilation_intro

# Data assimilation with HYPE

## Introduction

The hydrological simulation system used to run the hydrological model HYPE can be used for data assimilation with the ensemble Kalman filter method. The ordinary HYPE executable does not contain this functionality, but compiled with a flag for assimilation you get an executable that can be used for data assimilation with HYPE. The base for the data assimilation is a propagation of an ensemble of models forward in time, one step at the time. Forcing data is perturbed (a little and differently) for the ensemble members by a special routine in the assimilation to give the ensemble a little variance. The perturbations are spatially correlated with a certain correlation length.

After a time step has been simulated for the whole ensemble, and if there are some observations that are to be assimilated for that time step, a so called “analysis” is made. The analysis will use the deviations between observations and corresponding modelled predictor to adjust (or update) the states of the model. For the analysis HYPE uses the ensemble Kalman filter (enKf) method.

The base of the method is the Kalman filter:

where X is the model’s state variables and Y is its observation variables. The matrix K, the Kalman gain, is calculated as a function of the covariance between error in the model predictors and model states.

Thus, the Kalman filter can adjust all model states with a selected set of observations (including observations that are not of the model states) as long as the observation variable can be predicted from the model states. The function that predict the observation variable is called an observation operator. For instance, discharge (COUT), which is not a model state but a result of other model states (primary the water stored in soil, rivers and lakes) is the predictor of observed discharge (ROUT).

For simple models the covariance between error in a model predictor and the model states can be theoretically derived, but for more complex models like HYPE that is difficult. This is where the ensemble of the “ensemble” Kalman filter comes into play. Instead of calculating the covariance matrices needed for the analysis, they are estimated from the ensemble of models. The model errors of the predictors and the model states are sampled from the ensemble and the covariances are calculated for the samples.

To come later

## Input and output files

There is actually only one additional input file used for data assimilation. That is the AssimInfo.txt file which holds all information needed. Here you give the settings of the data assimilation. A few settings are given in the ordinary information file. First, assimilation need to be turned on in the info.txt file (`assimilation on`). In addition, it is possible to restart an assimilation from a saved ensemble of states (`indaensstate`) and to save ensemble states for later restart (`outdaensdate`).

The assimilation may give additional output files besides the ordinary files you get as output when asked for in info.txt. In the ordinary files, the assimilation routine will write the mean or median result of the ensemble. Whether you get the mean or median is set in AssimInfo.txt. In addition, you can get duplicated files for minimum and maximum value of the ensemble, standard deviation or each ensemble member. The extra files are separated by a suffix (number) on the ordinary output file name. For example timeCOUT_002.txt could hold the ensemble minimum values.

An assimilation simulation may temporary save the ensemble states in binary files instead of keeping them in memory. This function can be used to restart an assimilation simulation at previously saved states, but can also be used for large model setups to save memory during the simulation. The files are either one for each ensemble (nnnnnn.bin) or one for each of the three variable types; state ensemble, forcing ensemble and auxiliary ensemble (ensXstates.bin, ensFstates.bin, ensAstates.bin).