The R package RAStestR provides a library of functions for reading, manipulating and visualizing HEC-RAS output data. Specifically, it accesses the HDF5 data file associated with an HEC-RAS "plan". This vignette provides a brief introduction to the basic functionality of RAStestR.
Outputs from a simple quasi-unsteady sediment transport simulation are included with
RAStestR. Basic information about the plan can be displayed with
list_plan_info
.
library(RAStestR) ras.file = system.file("sample-data/SampleQuasiUnsteady.hdf", package = "RAStestR") list_plan_info(ras.file)
RAStestR provides functions for accessing data on model geometry and simulation outputs.
Simulation outputs are read into R via two basic functions: read_standard()
and
read_sediment()
. Most hydraulic data such as flow, water surface elevation, shear stress,
etc. are contained in single tables which are read in using read_standard()
. Some outputs
from sediment transport models reported by grain class in individual tables; these tables
can be read in and automatically grouped using read_sediment()
. In the example below, the
standard table "Shear Stress" and the sediment table "Mass Bed Change Cum" are read into R.
shear.stress = read_standard(ras.file, "Shear Stress") vol.change.cum = read_sediment(ras.file, "Vol Bed Change Cum")
You can also choose to extract data for only a subset of output times, river stations, or grain classes. RAStestR provides listing functions to retrieve possible values.
list_output_times(ras.file) list_stations(ras.file) list_grain_classes(ras.file)
read_standard
and read_sediment
return wide-format tables which match the row-column
structure of the HDF file. extracting subsets of the data is more convenient with wide
tables as rows correspond to output times and columns correspond to river stations.
However, many operations in R are more convenient to use with
long-format tables. The to_longtable
function collapses the cross-section columns in
a wide table automatically. The to_widetable()
function can convert a long table back
into the original wide format. The R package dplyr provides a rich environment for
manipulating long-format tables.
# wide table format (first five columns) head(shear.stress[1:5]) # long table format shear.stress.long = to_longtable(shear.stress, "ShearStress") head(shear.stress.long) # convert from long-format to wide-format #to_widetable(shear.stress.long, "Station", "ShearStress")
read_standard
, read_sediment
and to_longtable
read the river stations, time stamps
and grain classes as characters. This is inconvenient for e.g. plotting results over time
or along a reach. The function reformat_fields()
will convert the time stamps
to POSIXct
datetime format, and river stations to numeric
format.
shear.stress.long.fmt = reformat_fields(shear.stress.long)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.