The wflow_fit module¶
Introduction¶
The wflow_fit module provides simple automated least square fitting for the wflow models. It uses the scipy.optimize function to perform the fitting.
The program works mu multipling the fit parameter with a factor and optimise this factor. To get the new optimised parameters for your model you have to multiply your original parameters with the optimised factor. You can specify measured and simulated Q pairs to use and which area of the model you wan to adjust for each Simulated/Measured pair
In order to use the fit module you must have a:
A working wflow model
a tss file with measured discharge
an [fit] section in the ini file
The ini file¶
To be able to use the fit module you must add a [fit] section to the .ini file of the wflow model you want to fit.
[fit]
# The parameters are name parameter_0 to parameter_n
parameter_0 = M
parameter_1 = RootingDepth
# Q specifies the tss file with measure discharge data
# the path is relative to the case directory
Q = testing.tss
# The columns in the measured Q you want to fit to
ColMeas = [1,5]
# The columns in the measured Q you want to fit
ColSim = [1,5]
# Number of warup timesteps. This are not used in fitting
WarmUpSteps = 1
# The map defining the areas you want to adjust
areamap=staticmaps/wflow_catchment.map
# The areas you want to adjust for each Qmeas/Qsim combination
areacode=[1,5]
Fitting results¶
Results are saved in the wflow_fit.res file in the case/runid directory. In addition, the program saves a graph of modelled and observed data in the file fit.png and maps of the original and fitted parameters are also saved.
If you specify the -U option the resulting maps are saved in the staticmaps directory after each steps. As such, next steps (if you calibrate multiple subcatchments/areas) also include the results of the previous steps. Note that this will overwrite your maps if you already have those!
How to fit¶
Although wflow_sbm has a fairly large number of parameters most should not be fitted automatically. The parameters that are most suited for fitting are:
M
FirstZoneKsatVer
RunoffGeneratingGWPerc (if this is switched on. It is usually best to first setup the model without this parameter!)
RootingDepth
It is recommended to only fit one or two parameters at one time.
The wflow_rhine_sbm example can be used to test the fitting procedure.
wflow_fit.py -M wflow\_sbm -T 300 -C wflow\rhine\_sbm
Description of the python module¶
Fit a wflow_ hydrological model using scipy.leastsq.
usage
wflow_fit -M ModelName [-h][-F runinfofile][-C casename]
[-c configfile][-T last_step][-S first_step][-s seconds]
-M: model to fit (e.g. wflow_sbm, wflow_hbv, wflow_cqf)
-T: Set last timestep
-S: Set the start timestep (default = 1)
-C: set the name of the case (directory) to run
-R: set the name runId within the current case
-U: save the map after each step ti the input (staticmaps) dir so
that next steps (colums) use the previous results
-c: name of wflow the configuration file (default: Casename/wflow_sbm.ini).
-h: print usage information
For this program to work you must add a [fit] section to the ini file of the program to fit (e.g. the wflow_hbv program)
$Author: schelle $ $Id: wflow_sbm.py 669 2013-05-16 05:25:48Z schelle $ $Rev: 669 $
- wflow_fit.configget(config, section, var, default)¶
gets parameter from config file and returns a default value if the parameter is not found
- class wflow_fit.wfmodel_fit_API(startTime, stopTime, casename, runId='_fitrun', modeltofit='wflow_sbm', config='wflow_sbm.ini', clonemap='wflow_subcatch.map')¶
Class that initializes and runs a wflow model
- multVarWithPar(pars)¶
Multiply a parameter in the model with the fit parameters. Use a map to limit the area to adjust
- run(pars)¶
Run the model for the number of timesteps.
- savemaps(pars, savetoinput=False)¶
Ssave the adjusted (and original) parameter maps
- shutdown(pars)¶
Shutdown the model