2.0.0b10
catchment modelling framework
|
Here all data files needed for the tutorial can be downloaded: -
In a former tutorial we learned how we can use CMF to build a simple lumped model. There, we also learned that calibration by hand is quite difficult. As we are not the first persons who discover this, smart people have devised solutions for this problem. One of those solutions is Spotpy. Spotpy allows the automated calibration of models with many different algorithms and objective functions. This tutorial here is meant to show you how to use CMF with Spotpy. For this we will be using classes (object oriented programming). So if you do not yet know what classes are, it might be helpful to take a look. Though, for our purposes it is enough when you understand classes are just a fancy way to organize the structure of you code. Obviously you need to have SPOTPY and CMF installed on your computer to make this work. To run the model we will also need data. For the tutorial semi randomly generated data can be downloaded here: discharge, temperature and precipitation.
Spotpy makes some assumptions about your model. So to make your model compatible to Spotpy, you need some additional methods which work as an interface to Spotpy. To make them easier recycable it can be handy to shift them to an additional class. You do not neccesary have to fully grasp what those methods do, if you simply want a quick calibration done.
The first method calls your model and makes it run with the parameters Spotpy provides and returns the results the model calculated.
The second method is needed by Spotpy to generate the data with which the model is evaluated. In our case this is the measured discharge.
The third method calls Spotpy's own method for parameter generation. This means the values for the parameters we need in our model are generated here.
The final method of the interface is used to define the objective function. This means on what criteria the model should be judged. In our case we are using the Nash-Sutcliffe Efficieny, which focusses on peak flows.
The structure of the model is the same as the one we used in the first lumped tutorial. Therefore it should already be a bit familiar. The main difference is that the model code is now structured in a class, instead of writing one line under the next one. For this a class is used. To make use of the Interface we created, we let our model class inherit the methods from the SpotpyInterface class.
The first method of the model class initializes all things we need for the model, meaning the project, the cell, the layer, an outlet and out date.
This method is also used to define our parameters and their range. For this we need to import a distribution from spotpy. For our case Uniform is sufficient.
Finally the method the method loads in the forcing data and initializes the rainfall and the meteo station by calling another method (described below).
The method to load in the weather data works the same way as in the model without spotpy.
Same goes for the method to create the stations.
One significant difference to the model without Spotpy is the method to set the values for the parameters. We need this method as we cannot simply hardcode the values as we did in the model without Spotpy. Instead the parameters must be flexibly be filled with the values Spotpy provides. Therefore, we need to create this method to be able to do this.
Finally, we need a method which lets the model run and creates an array of the output. Here we also create the CMF solver, which solves the differential equations.
Now the model is ready to be used with Spotpy. The handling is rather straightforward. We simply have to create an instance of our model and forward it to Spotpy. Spotpy additionally needs to know what output format we want and what our file should be called. Here we can also define how often the model should run.
We you know start this model you should get a Nash-Sutcliffe Efficieny of about ~ 0.3. You can play around with other objective functions and add additional storages and connections, to test wether you can improve the model. The output you get should be similar to this:
Spotpy tells you what algorithm it is using and how much it as progressed in calculating all the runs we asked it for. When its done, Spotpy informs us about the beste run (In this case NS = 0.57) and what parameter set was used for this best run (In our case 64.4,..., 3.44, 0.66. The order in this parameter set is the one we have defined in the model.
In case someone is missing the old tutorial, it can still be found here: http://fb09-pasig.umwelt.uni-giessen.de/cmf/wiki/Cmflumped