Reading HEC-RAS HDF5 Results with R


Multiple packages read HDF5 data into R. The sample code below uses the Bioconducter package, available at: www.bioconductor.org.

Reading Results Matrix

The easiest way to deal with HEC-RAS results in R involves reading a time-space result matrix directly into an R dataframe and then interacting with the dataframe. The simplest data call involves defining a path to the HDF output file and an HDF path to the result.
For example, the following arguments import all of the water surface elevations, for all cells into a dataframe:

























FilePath<-"C:\\Users\\q0hecsag\\Documents\\Projects
2D Sediment
TestFile.p02.hdf"
dfWSE<-h5read(FilePath,"/Results/Unsteady/Output/Output Blocks/Base Output/Unsteady Time Series/2D Flow Areas/Chippewa/Water Surface")
To plot stage hydrograph at a specific cell (e.g. to compare with observed data):
vTime<-h5read(DynamicPath,"/Results/Unsteady/Output/Output Blocks/Base Output/Unsteady Time Series/Time")
vWSE<-dfWSE[Cell,]
plot (vTime,vWSE)

(Note: vTime is just the relative time from the beginning of the simulation. The next section describes how to format HEC-RAS formatted date-time data)

























Formatting HEC-RAS Date-Time Data in R

The HDF5 Data in HEC-RAS include two time results that match the rows of the result matrix.

Time is the relative, elapsed, time since the beginning of the simulation. This is a simple approach. R can interpret Time as a numerical vector and can plot any column (Cell or XS) of any of the results against it without further formatting.

However, plotting against absolute time is often better, particularly when comparing to observed data with their own time reference. R will import the Time Date Stamp as a string vector. You must define the date format to convert this to a date.

One way to convert the HEC-RAS date format is:

vDateTime.dt<-strptime(vDateTime(),"%d%b%Y %H:%M:%S")

where vDateTime() is the Time Date Stamp vector extracted from the HDF file.

Then you can plot against these absolute dates, for example:
plot (vDateTime.dt,vWSE)

Reading HEC-RAS HDF5 Results with Python

Dysarz (2018)Dysarz, T. (2018) Application of Python Scripting Techniques for Control and Automation of HEC-RAS Simulations, Water, 10(10):1382, doi: 10.3390/w10101382. includes sample code that accessed sediment HDF5 data from Python.

Example Code

Examples of third-party scripts that users developed to interact with HEC-RAS results are included below.