thym is hydrological modelling platform designed to analyse hydrological processes in tropical basins using aggregate rainfall-runoff conceptual models. So far, the platforms includes three different well known models:
- GR4J
- HBV
- HYMOD
These models run at daily time steps and are able to estimate daily runoff at the basin outlet.
thym is programmed in C language, and the pre- and postprocessing of model information is performed in python.
The main directory /thym is composed by the following directories and files:
/bin: Has themakefileand the model executables after compilation./inc: Has all the headers*.hfiles./src: Has all the source code*.cfiles./test_[model], : Application of a model (e.g.GR4J,HBVorHYMOD) to test case. For instance,test_gr4jcontain the input files needed to apply theGR4Jmodel. This directory contains the input files:/tools: Haspythonscripts for model result postprocessing. Theplot_in_out.pyscript plots simulated and observed time series and the variables inmeteo.ininput file.
This is the control or steering file for thym. This file has the following structure:
| ROW | MEANING |
|---|---|
| row 1 | Watershed name and hydrometric station |
| row 2 | Outlet latitude [dec] |
| row 3 | Outlet longitude [dec] |
| row 4 | Outlet altitude in [m.a.s.l] |
| row 5 | Watershed area in [km^2] |
| row 6 | Starting time (yyyy mm dd hr[0 23] min[0 59] sec[0 59]) |
| row 7 | End time (yyyy mm dd hr[0 23] min[0 59] sec[0 59]) |
| row 8 | Time step (s) |
| row 9 | |
| row 10 | PET method ['obs', 'hamon0', 'hamon1', 'pen-mon'] |
| row 11 | [Albedo] [wind speeed altitute (usually 10 m overgr.)] |
| row 12 | |
| row 13 | Model's name ['gr4j' 'hbv' 'hymod'] |
| row 14 | Model's parameters |
Note that:
-
In row 10: The user can chose the method to estimated the daily potential evapotranspiration among the following options: obs [observed precomputed values introduced through the
meteo.infile], hamon0 [Hamon method version 0], hamon1 [Hamon method version 1 (more standard)] and pen-mon [Penman-Monteith method]. -
In row 14: This row contains the parameters corresponding to the model in row 15. According to the model, the parameters are as follow:
| COL | PARAMETER | MEANING | RANGE |
|---|---|---|---|
| col 1 | x1 | Maximum capacity of the production store [mm] | 100; 1200 |
| col 2 | x2 | Groundwater recharge coefficient | -5; 3 |
| col 3 | x3 | One-day ahead maximun capacity of the routing store [mm] | 20; 300 |
| col 4 | x4 | Time base of unit hydrograph UH1 | 1.1; 2.9 |
| col 5 | pa | % of effective precipitation routed by UH1 | 0.9 |
| col 6 | pb | % of effective precipitation routed by UH2 | 0.1 |
| col 7 | trs | Air temperature above which the precipitation is all rainfall [oC] | - |
| col 8 | tmlt | The base temperature above which snow melt is allowed [oC] | - |
| col 9 | sno50 | The depth of snow when the basin is 50% covered by snow [mm] | - |
| col 10 | sno100 | The shreshold depth of snow, above which there is 100% cover [mm] | - |
| col 11 | ls | Snow temperature lag factor | - |
| col 12 | bmlt6 | Melt factor on June 21 [mm H2O/day-oC] | - |
| col 13 | bmlt12 | Melt factor on December 21 [mm H2O/day-oC] | - |
Note that the parameters x1, x2, x3 and x4 are often subjected to calibration. The parameters pa and pb take constant values. The others parameters belong to the snow model and are not relevant in tropical basins modelling.
| COL | PARAMETER | MEANING | RANGE |
|---|---|---|---|
| col 1 | k2 | Withdrawal rate from deep layer [days] | 10; 20000 |
| col 2 | k1 | Withdrawal rate for shallow layer overflow [days] | 1; 100 |
| col 3 | k0 | Withdrawal rate from shallow layer (interflow) [days] | 0.5; 20 |
| col 4 | degd | Degree day factor (snowmelt rate) [mm/day oC] | 0; 20 |
| col 5 | degw | Base temperature above which melt occur [oC] | -3; 3 |
| col 6 | ttlim | Temperature threshold below which freezing occurs [oC] | -3; 3 |
| col 7 | perc | Percolation rate into deep layer [mm/day] | 0; 100 |
| col 8 | beta | Distribution of soil stores [-] | 0; 7 |
| col 9 | lp | Limiting soil moisture at which PET takes place [-] | 0.3; 1 |
| col 10 | fcap | Maximum soil moisture storage [mm] | 10; 2000 |
| col 11 | hl1 | Maximum shallow layer storage [mm] | 0; 100 |
| col 12 | maxbas | Length of hydrograph routing transformation [hour] | 24; 120 |
| COL | PARAMETER | MEANING | RANGE |
|---|---|---|---|
| col 1 | ks | Slowflow routing tank's rate parameter | 0; 1 |
| col 2 | kq | Quickflow routing tanks' rate parameter | 0; 1 |
| col 3 | ddf | Degree day factor | 0; 2 |
| col 4 | tb | Base temperature to calculate melt | -5; 5 |
| col 5 | tth | Temperature threshold | -5; 5 |
| col 6 | alpha | Quick/slow split parameter | 0; 1 |
| col 7 | b | Scaled distribution function shape parameter | 0; 2 |
| col 8 | huz | Maximum height of soil moisture accounting tank | 0; Inf |
| col 9 | nq | Number of quickflow routing tanks | 1; Inf (typically < 3) |
| col 10 | kv | Vegetation adjustment to PE | 0; 2 |
This file contains the meterological data recorded within the catchment. This file has the following columns:
| datetime | tave_oC | tmin_oC | tmax_oC | precip_mm | windv_m/s | evapt_mm | runoff_mm |
|---|---|---|---|---|---|---|---|
| 1981-01-01 00:00:00 | -3.5 | 0.0 | 0.0 | 7.21 | 0.0 | 0.0 | 1.0502 |
| ... | ... | ... | ... | ... | ... | ... | ... |
where:
- datetime: Date time following the format: YYYY-MM-DD HH:MM:SS
- tave_oC: Daily average air temperature [$^oC$].
- tmin_oC: Daily minimum air temperature [$^oC$].
- tmax_oC: Daily maximum air temperature [$^oC$].
- precip_mm: Daily precipitation [$mm$].
- windv_m/s: Daily daily wind speed [$mm$]. Used to estimate potential evapotranspiration using, for instance, Penman-Monteith method. Note that the altitude at which windv is measured is indicated at row 11 in
ctrl.infile. Set this column to 0.0 is not needed by the evapotranspiration method. - evapt_mm: Daily observed potential evapotranspiration [$mm$]. Optionally, this can be calculated within the model (see
ctrl.infile) using different methods. If the evapotranspiration is calculated within the model, this column can be equal to 0. - runoff_mm: Daily runoff at the outlet of the basin [$mm$].
and the output file:
This file is composed by columns that records the values of state variables and flux variables for each simulated day. The variables (columns) are different for each model. Note that the most relevant variable, the total catchment runoff is called q_mm for any model and is given in mm.
This file contains some statistics to assess the model performance based on the simulated (q_mm in results.out) and the observed runoff (runoff_mm in meteo.in). The file has the following structure: ,. Below are the estimated STATs:
- NSE: Nash-Sutcliffe efficiency
- LNSE: Log Nash-Sutcliffe efficiency
- RMSE: Root-mean-squared error
- PBIAS: Percentage bias
- ABSER: Average absolute error
- ABSMAXER: Maximum absolute error
- PDIFF: Peak difference
- ERCOR: Correlation of error
- NSC: Number of sign changes
- Go to '/bin'.
- Type
make cleanthis will remove*.ofiles and the executable (optional). - Within
makefilechange the variableMODEL. So if:MODEL=1compilation is performed for GR4J modelMODEL=2compilation is performed for HBV modelMODEL=3compilation is performed for HYMOD model
- Type
make. This will execute themakefileand createthym_[model](e.gthym_gr4j) (model executable) and a symboly link to the executable within the main dir/thym.
- Go to the root dir
/thym. - Type
./thym_[model] testcase, so for instancethym_gr4j test_gr4j. This will run GR4J model for the test_gr4j study case. If the model execution is succesfull, the model will log results in the fileresults.outsaved within testcase directory (e.g./test_gr4j).
- Go to
/tools - Type
./plot_in_out.py ../testcase, so for instance./plot_in_out.py ../test_gr4j.plot_in_out.pywill plot time series of simulated (q_mm variable in theresults.outoutput file) and observed (runoff_mm variable in themeteo.ininput file) runoff in mm. The script will plot also all the variables inmeteo.infile.
Note that compilation, execution and plotting can be performed all at once using the run.sh in /thym root dir typing ./run.sh testcase valgrind (e.g. ./run.sh test_gr4j yes). Every step is performed as long as: COMP=true EXEC=true PLOT=true. Note that valgrind can be yes or something else. valgrind=yes the model is ran and memory leaks are checked. The option yes must be chosen when new developments are added to the model and memory leaks need to be checked.
-
Perform calibration and optimization of environmental models. Ideally, models must:
- use a text-based input/output file format. However, Ostrich can work with models that use MS Acces or NetCDF file formats if the Ostrich is configured accordingly (see
Type Conversions), - run without prompting for user intervention,
- produce outputs that can be reliably parsed.
- use a text-based input/output file format. However, Ostrich can work with models that use MS Acces or NetCDF file formats if the Ostrich is configured accordingly (see
-
Implement multiple deterministic, heuristic and smaplers algorithms (see table 1 in the user's manual). For instance, while the Levenberg-Marquardt algorithm is tailored to non-linear calibration problems, the Pareto Archive Dynamically Dimensioned Search and the Simple Multi-Objective Optimization Test Heuristic are suitable for multi-objective optimization or multi-criteria calibration. Additionaly, sampling-based algorithm such as Generalized Likelihood Uncertainty Estimation, Rejection Sampling and Metropolis-Hastings Markov Chain Monte Carlo are based for uncertainty-based calibration.
-
Estimate multiple regression statistics and diagnostics when used for model calibration via a weighted sum of squared errors approach (see table 2 in the user's manual).
Ostrich requires to set up the ostIn.txt input file and to create template model input files.
The following briefly explain the groups that form the input file. Note that with few exceptions, the format for a line of input in the file is <variable> <value>.
- basic configuration group: Some of the configuration variables are mandatory and is the only one group that does not need a
Begin...andEnd...group tags. This means that this group variables can be placed anywhere within the file. The configuration variables are:
ProgramType: Indicate the algorithm to be used to perform calibration or optimization.ModelExecutable: Indicate the name and path of model executable.ModelSubdir: When running in parallel, a working subdirectory must be especified to prevent parallel runs from clobbering each other's input and output files.ObjectiveFunction: Objective function to be optimized, eitherWSSE(Weighted Sum of Square Errors) calibration orGCOP(General-purpose Constrained Optimization Platform).PreserveBestModel: A user supply script that is run by Ostrich every time a new best parameter set is discovered.PreserveModelOutput: Ifyes, Ostrich will make copies of files associated with each model run and preserved files will be stored in directories namedrunNNNwhenNNNis a counter that increases after each model run. Alternatively, users can provide the name of a script that will run to preserve certain model run information. Ostrich will pass some argument to the user-defined script (see section 2.3 of user's manual).OstrichWarmStart: If set toyes, Ostrich will read the contents of any previously createdOstModeloutput files and use the entries therein to restart the optimization or calibration exercise.NumDigitsOfPrecision: Specifies the precision of values written by Ostrich output files.TelescopingStrategy: If selected (see listing 3 in user's manual) Ostrich will cause parameter bounds to become increasingly smaller as an optimization or calibration proceeds.RandomSeed: Used to control the random seed when generating random numbers.OnObsError: Used to control how Ostrich behaves when a model fails to generate all of the expected output for aWSSEcalibration. If equal toquit, Ostrich will abort if it ever fails to parse an observation from user-specified output files. If set to a value, Ostrich will use the value as a placeholder observation value.CheckSensitivities: If it is set toyes, Ostrich will perform a pre-calibration step to calculate parameter sensitivies.SuperMUSE: If it is set toyes, Ostrich will interface with EPA SuperMUSE tasker-client approach to parallel computing.OstrichCatching: If it is set toyes, Ostrich will examineOstModeloutput files prior to running a model configuration to see if the parameter set has already been evaluated.-BoxCoxTransformation: If set to a value other than1, Ostrich will apply a Box-Cox power transformation on each calibration residual. The value is used as the exponent for the transformation.ModelOutputRedirectionFile: This variable allows users to override the default name (i.e.OstExeOut.txt) of the file where Ostrich will redirect model output that would normally be displayed on a console screen.
-
file pairs group: A file pair consist of a template file and a corresponding input file. The contents of the template file should be identical to the paired model input file except that values of optimization (or calibration) parameters are placed placed with unique parameter names defined in the Parameter section. During Ostrich execution, this will use the template files to create syntactically correct model input files in preparation of running model at different parameter values.
BeginFilePairsandEndFilePairsare parsing tags to define this group. Pairs are introduced as<template1><sep><inputfile1>. -
extra files group: Extra files are model input files not used by Ostrich, but required for proper execution of the model.
BeginExtraFilesandEndExtraFilesare parsing tags to define this group. Files are introduced as<otherinputfile1>. -
extra directories group: Extra directories are directories containing model input files not used by Ostric, but required for proper execution of the mode.
BeginExtraDirsandEndExtraDirsare parsing tags to define this group. Directories are introduced as<inputdir1>. -
real-value parameters group: This configuration group describes the parameters to be calibrated or optimized.
BeginParamsandEndParamsare parsing tags to define this group. Parameters are introduced as<parameter_name1> <initial_value1> <lower_bound1> <upper_bound1> <input_transf1> <ostrich_transf1> <output_transf1> <format1>. Transformation can take the following values:none,log10andln. The format value is used to write into model input file following an specific format required by model. -
integer-value parameters group: This configuration group describes the parameters to be calibrated or optimized that can take only integer values.
BeginIntegerParamsandEndIntegerParamsare parsing tags to define this group. Parameters are introduced as<parameter_name1> <initial_value1> <lower_bound1> <upper_bound1>. -
combinatorial parameters group: This configuration group describes the parameters to be calibrated or optimized that can take on a discrete set of real, integer or string values.
BeginCombinatorialParamsandEndCombinatorialParamsare parsing tags to define this group. Parameters are introduced as<parameter_name1> <type1> <initial_value1> <value1> <value2> ... <valuen>.typecan be eitherreal,integerorstring. -
tied parameters group: This configuration group describes the parameters which are computed as a function of integer, real of combinatorial parameter values. They may also be functions of other tied parameters.
BeginTiedParamsandEndTiedParamsare parsing tags to define this group. Parameters are introduced as<parameter_name1> <number_of_param1> <pname1> <pname2> ... <pnamen> <type1> <type2> ... <type_data>.typeis the type of functional relationship and can be eitherlinear,exp,log,dist,wsum,ratioorconstant.type_datadepends of the functiontypeand on thenumber_of_param. -
special parameters (pre-emption) group: This configuration group describes the special parameters that are cost and constrain thresholds that are tracked by selected algorithms.
BeginSpecialParamsandEndSpecialParamsare parsing tags to define this group. Parameters are introduced as<parameter_name1> <initial_value1> <type1> <con_type1> <con_name1>.typeis the type of pre-emption parameter:BestCostorBestConstraint.con_typecan beupperorloweriftypeisBestConstraint.con_nameis the name of the constraint which are defined in the constraints group. -
initial parameters group: This configuration group describes initial parameter set that allow to introduce prior information (such as previous optimization results) improving the process.
BeginInitParamsandEndInitParamsare parsing tags to define this group. Parameters are introduced as<p1,1> <p2,1> ... <pn,1<. Inpi,jj is the j-initial value of the parameter i. Note that this set up must follow the order in the parameters group. -
parameters correction group: This configuration group allow users to interface Ostrich with an external program or script that makes adjustments to a candidate parameter set that has been calculated by Ostrich but not yet evaluated.
BeginParameterCorrectionandEndParameterCorrectionare parsing tags to define this group.BeginCorrectionsandEndCorrectionsare tags to define the parameter corrections. -
observations group: This configuration group allow users to list the observations names, values and weights, along with parsing instructions to reading simulated equivalent observations from model output files.
BeginObservationsandEndObservationsare parsing tags to define this group. This file is set up as<name1> <value1> <wgt1> <file1> <sep1> <key1> <line1> <col1> <tok1> <aug1> <grp1>. -
response variables group: This configuration group allow users to define the response variables when performing optimization. Ostrich will read the response variable from model output files prior to evaluating costs and constraints.
BeginResponseVarsandEndResponseVarsare parsing tags to define this group. -
tied-response variables group: This configuration group allow users to define tied-response variables which are variables whose values are computed by Ostrich as function of one or more response variables and/or parameters.
BeginTiedResVarsandEndTiedResVarsare parsing tags to define this group. -
type conversion group: Models that generate input or output files in MS Access or netcdf format can be interfaced with Ostrich via specification of a corresponding
TypeConversiongroup. Outputs specified in theTypeConversiongroup are extracted into text-based files that can then be processed into observations (see Observation group) or Response Variables (see Response Variables group).BeginTypeConversionandEndTypeConversionare parsing tags to define this group. -
search algorithms group: Each algorithm (see table 1 in user's manual) has its own configuration group, wherein the users can specify the values for various algorithm control variables. Additional optional configuration variables and groups such as warm start, pre-emption, parameter correction, list of initial parameters, math and stats and line search, may also be available for a given algorithm.
-
uncertainty-based search algorithms group: Several of the search algorithms implemented in Ostrich are designed to enumerate parameter probability distributions or behavioral parameter sets. Such algorithms are referred to as being uncertainty-based since they are not just concerned with identifying a single globally optimal parameter set. Each algorithm (see table 1 in user's manual) has its own configuration group.
-
multi-objective search algorithms group: These algorithms seek to identify non-dominated solutions representing the trade-off curve (i.e. pareto front) among conflicting objectives. These objectives can reflect a multi-criteria calibration exercise or a multi-objective optimization problem.
-
math and stats group: These group describes the finite difference method employed by algorithms (see table 1 in user's manual). If calibration is performed, additional variables in this group are used to request various statistical and diagnostic output.
BeginMathAndStatsandEndMathAndStatsare parsing tags to define this group. -
line search group: This group is used for configuration of the one-dimensional search algorithm that underlines unconstrained numerical optimization procedure (see table no. 1 in user's manual).
Begin1dSearchandEnd1dSearchare parsing tags to define this group. -
general-purpose constrained optimization platform (GCOP) group: In this group users can specify the response variable (or variables if performing multiobjective optimization or multi-criteria calibration) that will serve as the cost function (or functions) for general constrained optimization platform. Each cost function identifies a single response variable or tied response variable that represents a system cost to be minimized by the optimizer. The overall GCOP objective is a combination of the system cost and a penalty function, which accounts for the cost of all constraint violations.
Begin1dSearchandEnd1dSearchare parsing tags to define this group. -
constraints group: In this group the user supplies information about various constraints that are to be placed on a general constrained optimization problem. Any number and combination of constraints are supported.
BeginConstraintsandEndConstraintsare parsing tags to define this group.
Ostrich can run in serial or parallel mode. The Ostrich executable, Ostrich in Linux, must be in a directory along with ostIn.txt, model template files and the extra model input files. Remember that Ostrich uses the model template files to create model input files. The fundamental setup of ostIn.txt for:
-
Weighted Sum of Squared Errors (WSSE) Calibration: Several groups and variables must be setup in the
ostIn.txtincludingObjectiveFunction(set toWSSE),ProgramType,ModelExecutable,FilePairs,Parameters,ObservationsandMathAndStats. -
General Constrained Optimization Platform (GCOP): Several groups and variables must be setup in the
ostIn.txtincludingObjectiveFunction(set toGCOP),ProgramType,ModelExecutable,FilePairs,Parameters,ResponseVariables,GCOPandConstraints.
To run in serial mode in Linux:
`<path>/Ostrich`
To run in multi-core parallel model in Linux:
`mpirun -n 12 <path>/Ostrich`
where mpirun is a launcher provided by MPI libraries and -n 12 is an mpirun argument that indicates the number of processors (12) used to run Ostrich. If Ostrich want to be run across multiple nodes (like in a HPC infrastructure), other arguments like -hostfile and -rankfile might be needed.
Ostrich execution can be aborted after creating the file OstQuit.txt.
Certain search Ostrich algorithms allow an warm start and can be restarted from previous runs upon the variable OstrichWarmStart is set to yes in OstIn.txt.
Upon completion, Ostrich will generated several files. If executed in parallel mode, each processor will create its own set of output files, where N indicate the processor id. In serial mode, N=0, the id of the master core. The files created are:
OstOutputN.txt: The main output file, it contains an optimization (or regression) record along with statistical output.OstErrorsN.txt: Any errors or warning encountered by processorsN.OstModelN.txt: A sequential record of every model run evaluated by processorN.OstExeOut.txt: The standard output and errors of the model runs are directed to this file.OstStatusN.txt: This file is periodically updated with the current progress of the selected search algorithm.OstGcopOut: This file keeps track of the cost and constraint information for each model evaluation when theGCOPis used.OstNonDomSolutions: When a multi-objective search is performed, this file is periodically updated with the current list of non-dominated solutions that have been discovered by the selected search algorithm.
The following are some simple steps to use Ostrich for model calibration.
-
Download and compile Ostrich.
-
In
/thymcreate atestcase_ostr(e.g.test_gr4j_ostr) directory. This directory serve to implement Ostrich. -
Copy Ostrich executables within
testcase_ostro create a symboly link of the executable withintestcase_ostrdirectory.
Ostrichis the Linux executable for serial implementation.OstrichMPIis the Linux executable for parallel implementation. You need to have MPI libraries installed.
-
Create a
modeldirectory. This directory must contains the model executable (e.g.thym_gr4j) and model input files (e.gtest_gr4j/ctrl.in). Model output files are saved withinmodelfollowing the model functioning. You can copy the model executable or create a symboly link to the executable in themodeldirectory. -
Set up the template control model file. In this case, this file is
ctrl.in.tpl. In this file, one needs to show which are the parameters aim to be calibrated, this is done by replacing parameter values for parameter names (e.gpar_x1). Note that this parameter names are listed in the Ostrich control fileostIn.txtbetweenBeginParamsandEndParams. -
Set up the script to execute the model (e.g
ost_thym_gr4j.sh). The script name is included inostIn.txt(seeModelExecutable). Note that Ostrich will launch it to run the model every time the parameter set changes. -
(optional) Set up an script to save the best simulation, (e.g.
save_best.sh).The script name is included inostIn.txt(seePreserveBestModel). This script will create abestdirectory withinModelSubdir(seeostIn.txt). This script will save the best model output files and model diagnostics. -
Edit
ostIn_Serial.txtorostIn_Parallel.txteithe you want to run in serial or parallel mode. This is Ostrich control file, it isostIn.txt, actually. It is important to read Ostrich user's manual to understand the structure of the file. -
Run Ostrich using
run_ost.sh. This script will:- Clean up the current directory of Ostrich output files from previous runs.
- Create the
modeldir if not exist and create the model input dir in it including a link to model executable. - Copy
ostIn_Serial.txtintoostIn.txtorostIn_Parallel.txtintoostIn.txt - Run Ostrich in serial or parallel mode. Note that in each iteration Ostrich will use the template
ctrl.in.tplfile to change thectrl.infile.