First of all, we will keep the time series corresponding to the measured data and to the results of the original model set up in a list. This variable will be used later on to compare them quickly with each other.

Create a list containing the already known time series
# Save measurements and initial model results in a list of time series to compare 

timeSeriesToCompare = [measuredTimeSeries, waterlevelResults]

The model calibration will be done by changing the less reliable parameters from the loaded model. Let’s assume that these factors are the flow boundary condition at the node Boxbergen, and the roughness of the main tributaries leading to Zwolle:

The boundary conditions are not known yet in the scripting environment as variables. The complete name of the flow boundary condition at Boxbergen is, as shown in the previous figure, composed by the name of the location and the current value (Boxbergen - Q:25.064 m^3/s). However, the function GetBoundaryDataByName   defined in the API library SobekWaterFlowFunctions already takes this into account, so you don't have to worry about it. Assign the boundary condition data object corresponding to Boxbergen to the variable bcCalibration. We will suppose that this parameter could have a value of 8, 10 or 12 m3/s. Create therefore a list containing the cases in that range of variation:

First parameter used in the calibration: B.C. at Boxbergen
# Selection of parameters used for calibration and their range of variation
bcCalibration = GetBoundaryDataByName(flowModel, "Boxbergen")
rangeBC = [8, 10, 12]

The other parameter that will be used to calibrate the model is the roughness at the main tributaries.  First of all, this object should be available in the scripting environment. The object to edit is the corresponding network coverage. We will assume that the roughness (type Strickler) coefficient ks can change from 24 to 34 m1/3 s-1 in steps of 2, so a total of 6 different cases.

Second parameter used in the calibration: roughness
roughnessMain = GetItemByName(flowModel.RoughnessSections, "Main").RoughnessNetworkCoverage
rangeRoughness = [24, 26, 28, 30, 32, 34]

In summary, for the calibration, we will study all the possible combinations ( 6 x 3 = 18) of the above mentioned parameters.

Before starting the calibration procedure, we want to calculate and keep in a variable the goodness of the current settings of the flow model. So, first of all, we will assign the current values of the calibration parameters to a couple of variables.

The results of a model during the first time steps are extremely dependent on the initial conditions. So if the latter are not good ones, then not so meaningful results, and even in some cases, numerical oscillations can be found during the first time steps. This unreliable period, sometimes called warm-up period of a simulation, can be skipped by using the function GetAverageDeviation , as defined in the library SOBEKTutorialLibrary. Let's neglect the results of the first 20 output time steps. We can then calculate the goodness of the initial model settings and save those values in the variable listCalibration for later use.

Calculate goodness of current model settings
# Deviation of current model results with respect to measurements
roughnessInitialValue = roughnessMain.DefaultValue
bcInitialValue = bcCalibration.Flow
warmUpTimeSteps = 20
dev = GetAverageDeviation(measuredTimeSeries, waterlevelResults , startAt = warmUpTimeSteps)
listCalibration = [[bcInitialValue, roughnessInitialValue, dev]]

If you have followed the workflow directly importing the SOBEK 2.1x model, then the function GetAverageDeviation will not be know yet in the scripting environment, and you will have received an error message in the log, indicating the the function is not known. In fact, you don't have all the functions or classes defined within a python library, only the ones you need. This can be done by specifying the as a comma separated list after the import statement. So if you have followed the workflow directly importing a SOBEK 2.1x mode, then import the GetAverageDeviation function, with the code indicated below, and then, run again the code above which uses it.

Selective import from a library
from Libraries.SOBEKTutorialLibrary import GetAverageDeviation 

 

Note: The icon  indicates functions that you might find interesting to see how they have been built. You can do this by opening the corresponding library (another normal script python file on its own) in the toolbox and checking the code which defines the function or method you are interested in.


 

  • No labels