Friday, April 29, 2016

Python Dictionary Example for Determining a Flow Value based on a Pool Elevation

HEC-ResSim uses the programming language, Jython, for its scripted rules.  Scripted rules are sometimes necessary in HEC-ResSim when the built-in rules can not adequately address a unique operating condition.

Before developing a scripted rule in HEC-ResSim, I test the Python logic in an outside editor.  In this post, I show the testing of Python logic for determining a flow value based on a pool elevation.  Once I know that the Python logic is functioning correctly, I then add the code to HEC-ResSim and modify it for use in HEC-ResSim.

In a follow-up post, I will show the addition of this code to HEC-ResSim along with an examination of the results.

The code shown below is documented with the # symbol.  The # is only for documentation and does not impact the results of the code.



In the code, a value of 65 was entered for the hardcoded pool elevation.  Based on the values for the release, a pool elevation value of 65 should give a release value of 1300.

The result of running this code is as follows:


I also tested it with a pool elevation value of 80.  This result should return a release of 1600.


Since the testing of the program was successful, the next step is to incorporate it into HEC-ResSim.  This will be shown in a follow-up post.