Skip to content

Standardise using keyword arguments for setting parameter values. #86

@tyralla

Description

@tyralla

This issue came up when working on issue #85, which introduced the parameters NmbSegments and Coefficients. One can set the values of both parameters via the optional keyword arguments lag for NmbSegments and damp or k and x for Coefficients. This model-specific approach allows to apply the new application model musk_classic both in the style of HBV96 and the original Muskingum method. However, unfortunately, it makes applying some standard calibration tools of HydPy impossible.

To apply standardised calibration tools to keyword arguments of parameters, we must standardise how we define and use these keyword arguments. As a first step, we added the KEYWORDS dictionary to class Parameter and made some efforts to let the calibration tools defined in module calibtools, itemtools, and xmltools use it. But so far, only the two mentioned parameters use this way of "officially" defining keywords, and even for them, we might encounter some cases where things do not run smoothly. We will use this issue to collect potential drawbacks in discuss further improvements.

The first two general problems I am aware of:

  • For subclasses of ZipParameter, the time-dependency of the keyword arguments depends on the time-dependency of the parameter values. So far, we have no way to express this.
  • In some cases, the success of letting a standard calibration tool target a keyword might depend on how the values of the parameter have been defined previously.

The following two examples explain the second problem (taken from the current documentation).

hp, pub, TestIO = prepare_full_example_2()
from hydpy import Add

coefficients = hp.elements.stream_lahn_1_lahn_2.model.parameters.control.coefficients
coefficients(damp=1.0)
rule = Add(
    name="damp",
    parameter="coefficients",
    value=1.0,
    keyword="damp",
    model="musk_classic",
    parameterstep="2d",
)
rule.apply_value()
print(coefficients)
from hydpy.examples import prepare_full_example_2

hp, pub, TestIO = prepare_full_example_2()
from hydpy import Add

coefficients = hp.elements.stream_lahn_1_lahn_2.model.parameters.control.coefficients
coefficients(k=1.0, x=0.2)
rule = Add(
    name="damp",
    parameter="coefficients",
    value=1.0,
    keyword="damp",
    model="musk_classic",
    parameterstep="2d",
)
rule.apply_value()
print(coefficients)

The first example correctly prints coefficients(damp=2.0). The second fails with the following error: KeyError: "While trying to initialise the Add rule object damp, the following error occurred: 'The current KeywordArguments object does not handle an argument under the keyword damp.'"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions