Before including a script in a forecast run, you must add specific code to ensure the script executes correctly and triggers the next program in the sequence.

This guide walks you through the required steps to prepare your script for execution within an HEC-RTS forecast.

Step 1: Create A Script

If you already have a script, you can skip this step. 

You can write your script using the Script Editor in HEC-RTS or any preferred Integrated Development Environment (IDE), such as Eclipse or IntelliJ.

Step 2: Define the computeAlternative function

Your script must include a function named computeAlternative. This function is required for the forecast to execute successfully.

  1. Define a function with the name computeAlternative
    1. It takes two parameters (currentAlternative and computeOptions) and return True or False: 
      1. True or 1: Script ran successfully, and the forecast continues.
      2. False or 0: Script failed, and the forecast is aborted.

See below for an example of how to define the computeAlternative function.

Example Script

def computeAlternative(currentAlternative, computeOptions):
    """
    A script to run in an RTS Forecast that simply prints out the 
    available information
    """
    co = computeOptions
    print("program name               = {}".format(co.getProgramName()))
    print("user                       = {}".format(co.getUser()))
    print("model position             = {}".format(co.getModelPosition()))
    print("input position             = {}".format(co.getInputPosition()))
    print("name multiplier            = {}".format(co.getNameMultiplier()))
    print("i/o time step              = {}".format(co.getIoTimeStep())
    print("i/o time increment         = {}".format(co.getIoTimeIncrement()))
    print("time zone offset           = {}".format(co.getTimeZoneOffset()))
    print("f parts                    = {}".format(list(co.getFParts()))
    print("full f part                = {}".format(co.getFullFPart()))
    is_ensemble = co.isEnsembleCompute())
    print("is ensemble compute        = ()".format(is_ensemble))
    if is_ensemble:
        print("ensemble member number     = {}".format(co.getEnsembleMemberNumber()))
        print("ensemble collection string = {}".format(co.getEnsembleCollectionString())
        
    return True # success
PYTHON

Step 3: (Optional) Define Additional Functions 

You may define additional functions and call them within computeAlternative as needed.

currentAlternative

  • The object passed to the currentAlternative parameter is the object that executes the script.
  • Currently, it does not provide any useful fields or methods for scripting purposes.

computeOptions

This object provides several useful methods:

  • getEnsembleCollectionString() -> str
  • getEnsembleMemberNumber() -> int
  • getFParts() -> java.lang.String[] # use "list(computeOptions.getFParts())" to cast to python list
  • getFullFPart() -> str
  • getInputPosition() -> int
  • getIoTimeIncrement() -> int
  • getIoTimeStep() -> int
  • getModelPosition() -> int
  • getNameMultiplier() -> int
  • getProgramName() -> str
  • getTimeZoneOffset() -> int
  • getUser() -> str
  • isEnsembleCompute() -> bool
  • toString() -> str

Final Steps

After completing these steps, follow this guide to learn how to insert a script into your forecast run. Compute the forecast to verify that your script executes as expected and the forecast completes without errors.