Run the Plot Script

  1. Ensure the script is active by double-clicking the Stage+Flow script from in the Script Editor tree pane.
    1. The File: field above the Editor Pane should show Stage+Flow.py. If it shows CAVI3_Utils.py you need to make sure you double-click Stage+Flow in the tree to the left of the window.
      Script Editor
  2. Click the Save/Run button.
  3. You should see an error message. When you select OK, another window will open.
    Script Error

Troubleshoot the Plot Script

  1. Examine the line where the error occurred. It prints the contents of a variable named datasetList. Notice that the previous line defines that variable, but it is commented out.
  2. Edit line 29 to uncomment the variable assignment.
    1. Delete just the # character (or a shortcut is to use Ctrl + /, this shortcut can toggle the comment for multiple lines of selected code).
    2. Don't delete the space to the left of the # character. If you accidentally do so, restore it using the tab key and NOT the space bar.
    3. The character before datasetList should be a tab character, and it should line up vertically with the next line as shown in the screenshot below.
      Stage+Flow Script
  3. Try to run the script Save/Run and see what happens.
  4. There should now be a different error message.
    Script Error
  5. This error is saying that a function called Plot is trying to be utilized, but it has not been defined. This usually means an import was skipped.
  6. If you look at the top lines of the script, there is an import utilizing a wildcard import (the asterisk). This is no longer supported in CWMS (many older scripts utilized this syntax).
  7. To fix this issue, search the JavaDocs to try to determine exactly what import we need.
    1. The JavaDocs can be found within the CWMS folder (not the Watershed folder, but the folder where the CAVI application is running from - CAVI/javaDocs/index.html).
  8. Go to the INDEX option and select the P to go down the the section start with P, and find Plot.
  9. Then use the find function (crtl+f in windows) to locate Plot. You should see the same as below.
    JavaDocs
  10. Looking back at the top of the script, you should see there is an import hec.script trying to use the asterisk. Lets see if there is an import using that method.
  11. If we look at the end of each line, it tells what method or constructor is for the function.
  12. Notice that there is an instance of hec.script that a plot is located with (hec.script.Plot). So lets try to remove the asterisk and enter Plot in its place.

Add the Plot Script to the Modeling Tab

  1. Select the Scripts tab at the bottom of the Modeling tab.
  2. Right-click in the Scripts area and select Edit from the context menu.
  3. The Select Scripts dialog will open.
  4. Either double-click on the Stage+Flow entry in the Available column, or select that entry and click the Add button. Either action will move the Stage+Flow entry to the Selected column.
    Select Scripts Window
  5. Click OK from the Select Scripts dialog to close the window.
  6. The script should now appear in the Scripts area.
    Script Area of Forecast
  7. Click the Stage+Flow button in the Scripts area to run the script. You should see the following plot.
    Calpella Gage

Edit the Plot Script

Now, you will edit the script to change a few of the plot settings.

  1. As shown below, change the line from vp2.addCurve(“Y1”, flowData) to vp1.addCurve(“Y2”, flowData)
  2. Delete the line vp2 = layout.addViewport()
    Plot ScriptPlot Script
  3. This change will cause the script to plot both curves within the same viewport.
  4. Save and Run the script. You should see the following plot.
    Updated Calpella Gage Plot
  5. Add the following lines below line 70. Be sure to insert a tab character at the start of each line. These edits will change the line styles for the plot.

    stageCurve = plot.getCurve(stageData)
    flowCurve = plot.getCurve(flowData)
    stageCurve.setLineColor("red")
    stageCurve.setLineStyle("solid")
    flowCurve.setLineColor("blue")
    flowCurve.setLineStyle("solid")
    CODE

    Make sure that the indention level is the same as above. You might have to tab some lines.

  6. Save and Run.
  7. You should see a plot like the one below.
    Calpella Gage Plot