pywr icon indicating copy to clipboard operation
pywr copied to clipboard

Additional documentation on model-state dependent parameters

Open jjsoper opened this issue 7 years ago • 3 comments

It would be helpful to include information on how to incorporate user-defined functions within parameters that rely on current states of the model (such as the volume of a storage unit evaluated at each timestep). This feature was briefly mentioned in the README.

jjsoper avatar Aug 29 '18 12:08 jjsoper

Apologies that this is currently lacking. There is some WIP documentation in #652.

The InterpolatedVolumeParameter is an example of a fairly simple parameter that uses current volume to compute a value. It inherits from a shared parent class, but gives the idea.

https://github.com/pywr/pywr/blob/e0cb9cce7e451fd919569654a702482ce949ea21/pywr/parameters/parameters.py#L102

Otherwise please have a look at the ControlCurveInterpolatedParameter. This is slightly complex because it is written in Cython, but its .value() method utilises the current storage of the associated storage node. A similar custom parameter could be written directly in Pyhon.

https://github.com/pywr/pywr/blob/e0cb9cce7e451fd919569654a702482ce949ea21/pywr/parameters/_control_curves.pyx#L168

jetuk avatar Aug 29 '18 12:08 jetuk

Thank you for this!

jjsoper avatar Aug 29 '18 13:08 jjsoper

If you get stuck and can paste code here please do and I can help debug it.

Otherwise come chat in our Gitter channel: https://gitter.im/pywr/pywr

Thanks for the feedback!

jetuk avatar Aug 29 '18 13:08 jetuk