This appendix provides several example jython scripts to illustrate the use of scripting with HEC-DSSVue.  The intent of this appendix is to show variations in scripts and how to implement them.


Usually it is easiest to write a script by taking an example and modifying it to meet your needs. The scripts in this appendix are provided on Github https://github.com/HydrologicEngineeringCenter/DSSVue-Example-Scripts . The data for the scripts is provided in the attached sample.dss file. Most scripts access this file in the "C:\temp" directory. To execute the scripts, you will need to copy sample.dss to the C:\temp directory, and the sample scripts to "HecDssVue\Scripts" directory, or you may import them with the Script Editor.

This section covers math scripts, export/import scripts, simple graphics, "headless" operation (graphics in a background mode), complex graphics and calling scripts from scripts.


Math scripts use the HecMath package, so no direct access to HEC-DSSVue or ListSelection is needed. You can also get a DataContainer and access the data directly. The two approaches are shown in the following two scripts, which both add the number "10" to each value.


Script TypeScriptNameDescription
mathAddTenTsc.pyAdd 10 to each value using TimeSeriesContainer  (tsc), no accesst o DSSVue features is required.
math

AddTenHecMath.py

Add 10 to each value using HecMath.add(10.).  HecMath functions are easier to use than manipulating the data directly in a DataContainer
mathNewton.pyDemonstrates using Newtons method to find a solution to an equation.
dates/calendarholidays.py

Script that lists the federal holidays for any given year.  Example run:

T:\>holidays 2021
Federal holidays in 2021
        Fri, 01 Jan 2021 : New Year's Day
        Mon, 18 Jan 2021 : Birthday of Martin Luther King, Jr.
        Mon, 15 Feb 2021 : Washington's Birthday
        Mon, 31 May 2021 : Memorial Day
        Mon, 05 Jul 2021 : Independence Day
        Mon, 06 Sep 2021 : Labor Day
        Mon, 11 Oct 2021 : Columbus Day
        Thu, 11 Nov 2021 : Veterans Day
        Thu, 25 Nov 2021 : Thanksgiving Day
        Fri, 24 Dec 2021 : Christmas Day
        Fri, 31 Dec 2021 : New Year's Day

data entryDataEntry.pyBoth the manual time series data entry screen and paired data entry screen can be brought up from a script. They both can be passed a pathname to preset the dialog, and the time series dialog can be given a start time. This  example displays an initialized time series data entry screen.
SHEF exportFolsomToShef.py

If the SHEF parameter files are setup, a simple script can be written to import or export SHEF data. Essentially, the same steps are followed in the script as would be done interactively through the ListSelection class.    This script creates the file FolsomShefData.shef    To setup the parameter files unzip SHEFPARM.zip to   %APPDATA%\HEC\HEC-DSS\  directory.  On some computers that directory would be:  C:\Users\<user>\AppData\Roaming\HEC\HEC-DSSVue .   where <user> is your windows login username.

SHEF importImportShef.py

Importing SHEF data is easy; you essentially call the function importShef(String fileName), passing in the name of the file to import.

Excel exportFolsomExcel.pyThe export to Excel function uses code from HecDataTable; writing to Excel is similar to creating a table.
Exporting to specific Excel filename.FolsomSaveExcel.pyuses table.createExcelFile(..) method to specify the Excel filename
custom importWriteDss.pyIf you can parse a format, you can write a script to enter your data into HEC-DSS by using a DataContainer. DataContainers are generic database independent classes that hold data used by the various functions in HEC-DSSVue.  The following example, WriteDss.py, shows the use of a TimeSeriesContainer. In this example, HecTime is used to generate the times needed and the TimeSeriesContainer is imported from hec.io:
Simple plotting exampleOakvilleSimple.py

A simple plot script that illustrates:


1) Retrieve the data; 
2) Initialize the plot; 
3) Bring the plot into existence with showPlot(); 
4) Change the plot; and 
5) Save the plot to file and close.

Complex plotting exampleFolsom.py

A more complex plot using three viewports

Creating a table from a scriptFolsomTable.py

The same data shown in plots is easily displayed in tabular form

Coyote Valley Dam Reservoir PlotCoyote.py

This is a plot showing reservoir data for the month of March. The plot shows precipitation, storage, top of conservation, inflow, outflow and downstream flows.

Scripts with Arguments

RunGages.py

and

GagePlot.py

Often you will want to setup a plot or other function and apply it to different locations, variables or times. Instead of duplicating the script for each instance, which leads to maintenance and manageability issues, it is usually advantageous to write one script and pass in arguments that may vary.

Application with User Interface 

DssConverter.py

A script to convert all HEC-DSS v6 files in a directory tree to HEC-DSS v7.



sample.dss