How to apply the user choices
[ ]:
from pywatemsedem import choices
from pathlib import Path
This notebook gives some examples on how to use the new module choices.py. This module creates objects that store all user choices needed for a model run with pywatemsedem.
Let start with an example.
First we initialise our WSOptions object. In this objec the basic choices of a model run must be made.
[ ]:
ws_options = choices.Options()
Let’s have a look at the L model option
[ ]:
ws_options.l_model
We see that the Value of the L model is None, as the user has not set this value yet. There are several ways to add the value of the user choice. We will show these possibilities below.
The first, and most simple way, is to manually give a value to this user choice.
[ ]:
ws_options.l_model = "Renders_and_Gobeyn_2024"
As shown above, you cannot add just a random value when the “allowed_values” property of the choices object is given. “Renders_and_Gobeyn_2024” is not an allowed value for the L model, so we have to give a valid one.
[ ]:
ws_options.l_model = "Desmet1996_Vanoost2003"
[ ]:
ws_options.l_model
A second way to add the value to a user choice, is to read it from an ini-file. We will show this for the S model.
[ ]:
ws_options.s_model
[ ]:
ini_file = Path("../../tests/data/default_values.ini")
ws_options.read_values_from_ini(ini_file)
[ ]:
ws_options.only_routing
A third method is to assign the default value to the value. We will illustrate this for the tc model.
[ ]:
ws_options.tc_model.apply_default_value()
[ ]:
ws_options.tc_model
Now, let’s set the parameters object.
[ ]:
ws_parameters = choices.Parameters()
Let us assing the r_factor value
[ ]:
ws_parameters.r_factor = 1250
Oh no, we have given the wrong dtype for the R factor parameter. It should be a float, not an int. Let’s correct it.
[ ]:
ws_parameters.r_factor = 1250.0
If you think you have assigned all parameter values, there is a function available to check if all required/mandatory user choices have a value. Let’s check if this is true for ws_parameters.
[ ]:
ws_parameters.check_mandatory_values()
ok, the parcel connectivity cropland is not given. We will assign this value, togheter with all other missing parameters (see documentation which parameters are mandatory to give)
[ ]:
ws_parameters.parcel_connectivity_cropland.read_value_from_ini(ini_file)
ws_parameters.parcel_connectivity_grasstrips.read_value_from_ini(ini_file)
ws_parameters.parcel_connectivity_forest.read_value_from_ini(ini_file)
ws_parameters.parcel_trapping_eff_cropland.read_value_from_ini(ini_file)
ws_parameters.parcel_trapping_eff_pasture.read_value_from_ini(ini_file)
ws_parameters.parcel_trapping_eff_forest.read_value_from_ini(ini_file)
ws_parameters.bulk_density.read_value_from_ini(ini_file)
[ ]:
ws_parameters.check_mandatory_values()
If we want to use an extension, we can enable this extension via
[ ]:
ws_extensions = choices.Extensions()
[ ]:
ws_extensions.create_ktc_map = True
ws_extensions.curve_number = True
Now, we need to set the extension parameters. Note that this class is dependent on the conent of the WSExtensions class.
[ ]:
ws_extensions_parameters = choices.ExtensionsParameters(ws_extensions)
We have read in the documentation that the parameters ‘ktc_low’ and ‘ktc_high’ are needed when the extension ‘create_ktc_map’ is enabled.
[ ]:
ws_extensions_parameters.ktc_high = 36.0
ws_extensions_parameters.ktc_low = 10.5
[ ]:
ws_extensions_parameters.endtime_model = 2.0
[ ]:
ws_extensions_parameters.check_mandatory_values()
[ ]:
ws_extensions_parameters.ktc_limit = 0.1
Now, we only need to decide on the outputs of the model.
[ ]:
ws_output = choices.Output()
We will use all the defaults given.
[ ]:
ini = Path("../../tests/data/default_values.ini")
[ ]:
ws_output.read_values_from_ini(ini)