Wednesday, May 9, 2012

HEC-HMS Report Style Sheets

Whew!  I feel like I'm the first person to crack this HEC-HMS XSL Style Sheet nut.  In any case I'm the first one to share it on the web.


First of all, before diving into how to get a report using a Style Sheet, you should realize that a sort of basin model report from HEC-HMS is available as a readable text file in the .basin file.  But beyond that, for the purposes and in the hope that we users would develop tabular reports, the HEC also provided a report definition language (that they didn't document very well) for reports we can get from the Tools, Reports menu.

I was able to create an SCS Basin Summary style sheet by using the "tags" in the .basin file, making them lower case and removing spaces from them.  Here's an example of how I added the Curve Number to my report:

1.  The sample Snyder report provided by the HEC includes this snippet

  
  <table border="2" width="100%">
    <tr>
      <th>Subbasin</th>
      <th>Snyder Tp</th>
      <th>Snyder Cp</th>
    </tr>
    <xsl:for-each select="/HMS:basin/HMS:subbasin">
    <tr>
      <xsl:apply-templates select="."/>
      <xsl:apply-templates select="./HMS:transform/HMS:snydertp"/>
      <xsl:apply-templates select="child::HMS:transform/HMS:snydercp"/>
    </tr>
    </xsl:for-each>
  </table>

2. My .basin file includes this snippet
  
Subbasin: STSTP2
     Description: Sub-basin from Tailings model
     Canvas X: 1046.2
     Canvas Y: 1208.0
     Area: 0.1345
     Downstream: RTSTP

     Canopy: None

     Surface: None

     LossRate: SCS
     Percent Impervious Area: 0.0
     Curve Number: 87

     Transform: SCS
     Lag: 28.800
     Unitgraph Type: STANDARD

     Baseflow: None
End:


3. I turned "Curve Number" from step 2 into curvenumber below.  I continued that way to use the example of the .basin file and correct (with some oddities) the table HTML to create an SCS Basin table as shown below:
  
  <table border="2" width="100%">
    <tr>
      <th></th>
      <th>Subbasin</th>
      <th>Area</th>
      <th>SCS CN</th>
      <th>SCS Lag</th>
    </tr>
    <xsl:for-each select="/HMS:basin/HMS:subbasin">
    <tr>
      <td><xsl:apply-templates select="."/></td>
      <td><xsl:apply-templates select="./HMS:area"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:curvenumber"/></td>
      <td><xsl:apply-templates select="child::HMS:transform/HMS:lag"/></td>
    </tr>
    </xsl:for-each>
  </table>

And here is the complete file I saved as SCSBasinSummary.xsl
  
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:HMS="http://www.hec.usace.army.mil/software/hec-hms" >

<xsl:template match="/HMS:basin">
  <p><b>Basin Model "<xsl:value-of select="/HMS:basin/@name"/>"</b></p>
  <table border="2" width="100%">
    <tr>
      <th></th>
      <th>Subbasin</th>
      <th>Area</th>
      <th>SCS CN</th>
      <th>SCS Lag</th>
    </tr>
    <xsl:for-each select="/HMS:basin/HMS:subbasin">
    <tr>
      <td><xsl:apply-templates select="."/></td>
      <td><xsl:apply-templates select="./HMS:area"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:curvenumber"/></td>
      <td><xsl:apply-templates select="child::HMS:transform/HMS:lag"/></td>
    </tr>
    </xsl:for-each>
  </table>
  <p>Current as of <xsl:value-of select="/HMS:basin/HMS:header/HMS:lastmodifieddate"/> at <xsl:value-of select="/HMS:basin/HMS:header/HMS:lastmodifiedtime"/> </p>
</xsl:template>

<xsl:template match="HMS:subbasin">
  <td><xsl:value-of select="@name"/></td>
</xsl:template>

<xsl:template match="HMS:snydertp">
  <td><xsl:value-of select="."/></td>
</xsl:template>

<xsl:template match="HMS:snydercp">
  <td><xsl:value-of select="."/></td>
</xsl:template>

</xsl:stylesheet>

And here is the resulting report :-) :

Basin Model "Bisbee Tailing 071609"
Subbasin Area SCS CN SCS Lag
SCTSA Top Basin 0.2149 87 17.7
SCTSA Top Pond 1 0.1548 87 24.1
SCTSA Top Pond 2 0.1345 87 28.8
SCTSA Top Pond 3 0.0877 87 24.7
SCTSA TOE-1 0.0895 87 9.4
W Natural Ground 1 0.0831 87 11.7
SCTSA Main 2 WS 0.01259 87 11.0
SCTSA-W3 0.0079 87 3.2
SCTSA-W1 0.0073 87 3.2
SCTSA Main 3 WS 0.0327 87 8.7
HR 1 0.0168 87 1.5
SCTSA-S3 0.0135 87 4.3
SCTSA-S4 0.0125 87 4.1
SCTSA-S2 0.0058 87 2.6
SCTSA-S1 0.0053 87 2.3
SCTSA-S5 0.0166 87 4.8
SCTSA-S6 0.0132 87 3.2
SCTSA-S7 0.0168 87 6.1
HP-1 0.047 87 6.3
SCTSA-S8 0.0217 87 5.3
Upstream Natuural 0.6291 87 15.3
NCTSA Top 0.2581 87 18
NCTSA-E3 0.0289 87 5.3
NCTSA-E5 0.0083 87 3.6
NCTSA-E2 0.0050 87 3.8
NCTSA-E1 0.0033 87 2.2
NCTSA-E4 0.0022 87 2.9
SCTSA-E3 0.0108 87 6.5
NCTSA Main 4 WS 0.0055 87 2.5
NCTSA Main 5 WS 0.0162 87 2.9
SCTSA-E2 0.0123 87 5.7
NCTSA Main 6 WS 0.0097 87 4.2
SCTSA-E1 0.0060 87 4.5
NCTSA Main 7 WS 0.0075 87 2
SCTSA-E0 0.0022 87 2.9
NCTSA Main 8 WS 0.0057 87 1.9
HR-2 0.0097 87 1.5
HP-2 0.0475 87 3.9
SCTSA-E4 0.0070 87 1.6
Current as of 8 May 2012 at 18:00:28

Here's another one that reports both SCS and Green-Ampt and Clark:

  <table border="2" width="100%">
    <tr>
      <th></th>
      <th>Subbasin</th>
      <th>Area</th>
      <th>SCS CN</th>
      <th>SCS Lag</th>
      <th>GA IC</th>
      <th>GA SC</th>
      <th>GA Suction</th>
      <th>GA Conduct.</th>
      <th>GA %Imp.</th>
      <th>Clark TC</th>
      <th>Clark R</th>
    </tr>
    <xsl:for-each select="/HMS:basin/HMS:subbasin">
    <tr>
      <td><xsl:apply-templates select="."/></td>
      <td><xsl:apply-templates select="./HMS:area"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:curvenumber"/></td>
      <td><xsl:apply-templates select="./HMS:transform/HMS:lag"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:initialcontent"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:saturatedcontent"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:wettingfrontsuction"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:hydraulicconductivity"/></td>
      <td><xsl:apply-templates select="./HMS:lossrate/HMS:percentimpervious area"/></td>
      <td><xsl:apply-templates select="./HMS:transform/HMS:timeofconcentration"/></td>
      <td><xsl:apply-templates select="./HMS:transform/HMS:storagecoefficient"/></td>
    </tr>
    </xsl:for-each>
  </table>

3 comments:

adi said...

Works wonderfully. Do you have report template for all the elements of the model(incl. met, basin and comtrol)? Thanks.

Thomas Gail Haws said...

Nah. I haven't spent that much time with it. Just enough to figure it out and then share. You should be able to pretty much follow the same procedure for any table, though. If you have any uncertainty or trouble, feel free to holler.

Anonymous said...

Works straight out of the box. Many thanks.