Skip to content

SWATProblemMultimodel

Advanced Users Only

This feature requires special expertise

SWATProblemMultimodel

Bases: Problem

__init__(params: Dict[str, Tuple[str, List[Tuple[str, str, float, float]]]], function_to_evaluate: Callable, param_arg_name: str, n_workers: int = 1, parallelization: str = 'threads', ub_prior: Optional[List[int]] = None, lb_prior: Optional[List[int]] = None, function_to_evaluate_prior: Optional[Callable] = None, args_function_to_evaluate_prior: Optional[Dict[str, Any]] = None, param_arg_name_to_modificate_by_prior_function: Optional[str] = None, debug: bool = False, **kwargs: Dict[str, Any]) -> None

This class serves the same purpose as SWATProblem, with the added capability of running another model before executing SWAT+. This enables running a prior model in the same calibration process, wherein the parameters are calibrated simultaneously. For example, the prior model can modify an input file of SWAT+ before initiating SWAT+ (according to the parameters of the calibration).

  • params Dict[str, Tuple[str, List[Tuple[str, str, int, int]]]]): A dictionary containing the range of values to optimize. Format: {filename: (id_col, [(id, col, upper_bound, lower_bound)])}
  • function_to_evaluate (Callable): An objective function to minimize. This function, which has to be created entirely by the user, should be responsible for adjusting the necessary values based on the calibration iteration, running SWAT, reading the results, comparing them with observations, and calculating an error measure. The function can accept any user-defined arguments, but it must receive at least one argument (named as indicated by param_arg_name), which takes a dictionary in the format {filename: (id_col, [(id, col, value)])}, representing the current calibration values. Format: function_to_evaluate(Dict[Any, Any]) -> Tuple[int, Dict[str, str]] where the first element is the error produced in the observations and the second element is a dictionary containing a user-desired identifier as the key and the location where the simulation has been saved as the value.
  • param_arg_name (str): The name of the argument within function_to_evaluate function where the current calibration parameters are expected to be passed. This parameter must be included in **kwargs
  • n_workers (int, optional): The number of parallel workers to use (default is 1).
  • parallelization (str, optional): The parallelization method to use ('threads' or 'processes') (default is 'threads').
  • ub_prior (List[int], optional): Upper bounds list of calibrated parameters of the prior model. Default is None.
  • lb_prior (List[int], optional): Lower bounds list of calibrated parameters of the prior model. Default is None.
  • function_to_evaluate_prior (Callable, optional): Prior function to be used for modifying parameters before SWAT+ simulation. Must take the name indicated by args_function_to_evaluate_prior as a mandatory argument, and must be a np.ndarray, so in the source code the following is done: function_to_evaluate_prior(args_function_to_evaluate_prior = np.ndarray, ...). Must return a value that will be used to modify a parameter in the kwargs dictionary. Default is None.
  • args_function_to_evaluate_prior (Dict[str, Any], optional): Additional arguments for function_to_evaluate_prior. args_function_to_evaluate_prior does not have to be included here. This dictionary will be unpacked and passed as keyword arguments of args_function_to_evaluate_prior.
  • param_arg_name_to_modificate_by_prior_function (str, optional): Parameter modified in kwargs by the return of function_to_evaluate_prior, so in the source code the following is done: kwargs[param_arg_name_to_modificate_by_prior_function] = function_to_evaluate_prior(...)
  • debug (bool, optional): If True, print debug output during optimization (default is False).
  • **kwargs: Additional keyword arguments, that will be passed to function_to_evaluate.

Returns: None