Appendix - Example Scripts
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 Type | ScriptName | Description |
---|---|---|
math | AddTenTsc.py | Add 10 to each value using TimeSeriesContainer (tsc), no accesst o DSSVue features is required. |
math | Add 10 to each value using HecMath.add(10.). HecMath functions are easier to use than manipulating the data directly in a DataContainer | |
math | Newton.py | Demonstrates using Newtons method to find a solution to an equation. |
dates/calendar | holidays.py | Script that lists the federal holidays for any given year. Example run: T:\>holidays 2021 |
data entry | DataEntry.py | Both 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 export | FolsomToShef.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 import | ImportShef.py | Importing SHEF data is easy; you essentially call the function importShef(String fileName), passing in the name of the file to import. |
Excel export | FolsomExcel.py | The export to Excel function uses code from HecDataTable; writing to Excel is similar to creating a table. |
Exporting to specific Excel filename. | FolsomSaveExcel.py | uses table.createExcelFile(..) method to specify the Excel filename |
custom import | WriteDss.py | If 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 example | OakvilleSimple.py | A simple plot script that illustrates: ![]() 1) Retrieve the data; |
Complex plotting example | Folsom.py | A more complex plot using three viewports ![]() |
Creating a table from a script | FolsomTable.py | The same data shown in plots is easily displayed in tabular form |
Coyote Valley Dam Reservoir Plot | Coyote.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 | and | 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 | A script to convert all HEC-DSS v6 files in a directory tree to HEC-DSS v7. |