Scripting
Reading DSS pathnames in Jython Scripts
In CWMS 3.4.1, some legacy methods such as getPathnameList() return uppercase paths only and return E-PARTs that are only DSS 6 compatible. For DSS 7 compatibility, please use HecDssCatalog.getCatalog() or HecDss.getCondensedCatalog() when reading DSS pathnames in Jython scripts.
// Jython example to get pathnames from a DSS file.
from hec.heclib.dss import HecDssCatalog
catalog = HecDssCatalog("c:/tmp/sample7.dss")
sorted = True
paths = catalog.getCatalog(sorted)
for p in paths:
print(p)
For more scripting examples on cataloging DSS record pathnames, please refer to using-hecdsscatalog-to-see-dss-pathnames.
DSS7 Case-Insensitive Text Comparison in Jython Scripts
Switching to HEC-DSS 7 means that the assumption that pathnames and all of their parts are in uppercase is no longer valid. This means that any scripts that make that assumption when testing or comparing pathnames/parts need to perform case-insensitive tests or comparisons. Fortunately, this is an easy modification to most scripts.
The various ways to test or compare pathnames/parts are shown below. In these examples, variables s1 and s2 indicate string (text) variables.
Normal Test/Comparison | Case Insensitive Test/Comparison |
---|---|
s1 == "TEXT" | s1.upper() == "TEXT" |
s1 == s2 | s1.upper() == s2.upper() |
s1.startswith("TEXT") | s1.upper().startswith("TEXT") |
s1.startswith(s2) | s1.upper().startswith(s2.upper()) |
s1.endswith("TEXT") | s1.upper().endswith("TEXT") |
s1.endswith(s2) | s1.upper().sendswith(s2.upper()) |
s1.find("TEXT") | s1.upper.find("TEXT") |
s1.find(s2) | s1.upper().find(s2.upper()) |
s1.index("TEXT") | s1.upper().index("TEXT") |
s1.index(s2) | s1.upper().index(s2.upper()) |
DSS7 New E-Part Conventions
HEC-DSS 7 changed the time series E-part conventions for n-Minute and n-Month records. In HEC-DSS 6 and prior, n-Minute data E-pathnames parts were nMIN (e.g., 15MIN) and n-Month parts were nMON (e.g., 1MON). HEC-DSS 7 changed these to nMinute (e.g., 15Minute) and nMonth (e.g., 1Month), respectively.
DSS7_EPARTS = [ "1Year", "1Month", "Semi-Month", "Tri-Month",
"1Week", "1Day", "12Hour", "8Hour",
"6Hour", "4Hour", "3Hour", "2Hour",
"1Hour", "30Minute", "20Minute", "15Minute",
"12Minute", "10Minute", "6Minute", "5Minute",
"4Minute", "3Minute", "2Minute", "1Minute",
"30Second", "20Second", "15Second", "10Second",
"6Second", "5Second", "4Second", "3Second",
"2Second", "1Second",
"IR-Century", "IR-Decade", "IR-Year", "IR-Month", "IR-Day"]
DSS6_EPARTS = [ "1YEAR", "1MON", "SEMI-MONTH", "TRI-MONTH",
"1WEEK", "1DAY", "12HOUR", "8HOUR",
"6HOUR", "4HOUR", "3HOUR", "2HOUR",
"1HOUR", "30MIN", "20MIN", "15MIN",
"12MIN", "10MIN", "6MIN", "5MIN",
"4MIN", "3MIN", "2MIN", "1MIN",
"IR-CENTURY", "IR-DECADE", "IR-YEAR", "IR-MONTH", "IR-DAY"]
To prevent users from having to manually make these changes to their extract lists, the DssConverter Tool that is used to convert watershed HEC-DSS files from 6 to 7 also has the capability to automatically make these changes for all extract lists in the watershed. If you did not have it make the changes when you originally ran the DssConverter Tool, you can simply run it again to make the changes - it will not affect any HEC-DSS 7 files or any extract lists that have already had the changes made.
To (re)run the DssConverter tool, simply follow the published directions, paying special attention to step 13.
Record Type Error
You may need to edit your Jython scripts if you get an error such as this:
What happened? Starting in CWMS 3.4, all data for a forecast is being stored in DSS 7 instead of DSS 6. DSS 7 doesn't allow you to mix double precision and single precision within the same time-series record.
To get around this error, you will need to get all the data in the same record type. Since HEC-ResSim defaults to a record type of 105 (regular time series, double precision)/115 (irregular time series, double precision), it is suggested to ensure all time series data is in one of these two record types. An example script to convert existing time series data to a record type of 105 or 115 can be found on the following GitHub link: https://github.com/HydrologicEngineeringCenter/DSSVue-Example-Scripts/blob/master/src/DataType.py
Within your script that is saving data to a forecast.dss file, you will also need to add a quick call to make sure it is being pushed as a record type of 105 or 115.
Tsc.storedAsdoubles = True #This stores "Tsc" as a double (record type 105 or 115)
Once the data has been converted to double (using the script in GitHub) and you verify that data being stored is as a double (above code block), you should not have issues with this issue in transitioning to HEC-DSS 7 from HEC-DSS 6.