Build Status Coverage Status CRAN RStudio mirror downloads CRAN version

epanetReader

epanetReader is an R package for reading water network simulation data in Epanet's .inp and .rpt formats into R. Some basic summary information and plots are also provided.

Epanet is a highly popular tool for water network simulation. But, it can be difficult to access network information for subsequent analysis and visualization. This is a real strength of R however, and there many tools already existing in R to support analysis and visualization.

In addition to this README page, information about epanetReader is available from Environmental Modelling & Software (pdf) and ASCE Conference Proceedings (pdf).

Installation

Getting Started

Network files

Read network information from an .inp file with a similar syntax as the popular read.table or read.csv functions. Note that the example network one that ships with Epanet causes a warning. The warning is just a reminder of how R deals with integer IDs.

library(epanetReader)
n1 <- read.inp("Net1.inp") 

Retrieve summary information about the network.

summary(n1)

A basic network plot is also available

plot(n1)

Net 1 plot

The read.inp function returns an object with structure similar to the .inp file itself. A section in the .inp file corresponds to a named entry in the list. These entries are accessed using the \$ syntax of R.

names(n1)

Sections of the .inp file are stored as a data.frame or character vector. For example, the junction table is stored as a data.frame and retrieved as follows. In this case patterns were not specified in the junction table and so are marked NA.

n1$Junctions

A summary of the junction table shows that Net1.inp has nine junctions with elevations ranging from 690 to 710 and demands ranging from 0 to 200. Note that the node ID is stored as a character rather than an integer or factor.

summary(n1$Junctions)

Epanet Simulation Results

Results of the network simulation specified in Net.inp may be stored in Net1.rpt by running Epanet from the command line. Note that the report section of the .inp file should contain the following lines in order to generate output readable by this package.

[REPORT]
Page 0
Links All
Nodes All

On windows, calling the epanet executable epanet2d runs the simulation.

>epanet2d Net1.inp Net1.rpt 

... EPANET Version 2.0

  o Retrieving network data
  o Computing hydraulics 
  o Computing water quality
  o Writing output report to Net1.rpt

... EPANET completed.

The .rpt file generated by Epanet may be read into R using read.rpt(). The simulation is summarized over junctions, tanks and pipes.

n1r <- read.rpt("Net1.rpt") 
summary(n1r)

The default plot of simulation results is a map for time period 00:00:00. Note that the object created from the .inp file is a required argument to make the plot.

plot( n1r, n1)

Net 1 plot

In contrast to the treatment of .inp files described above, data from .rpt files is stored using a slightly different structure than the .rpt file. The function returns an object (list) with a data.frame for node results and data.frame for link results. These two data frames contain results from all the time periods. This storage choice was made to facilitate time series plots.

Entries in the epanet.rpt object (list) created by read.rpt() are found using the names() function.

names(n1r)

Results for a chosen time period can be retrieved using the subset function.

subset(n1r$nodeResults, Timestamp == "0:00:00")

A comparison with the corresponding entry of the .rpt file, shown below for reference, shows that four columns have been added to the table. These pieces of extra info make visualizing the results easier.

  Node Results at 0:00:00 hrs:
  --------------------------------------------------------
                     Demand      Head  Pressure  Chlorine
  Node                  gpm        ft       psi      mg/L
  --------------------------------------------------------
  10                   0.00   1004.35    127.54      0.50
  11                 150.00    985.23    119.26      0.50
  12                 150.00    970.07    117.02      0.50
  13                 100.00    968.87    118.67      0.50
  21                 150.00    971.55    117.66      0.50
  22                 200.00    969.08    118.76      0.50
  23                 150.00    968.65    120.74      0.50
  31                 100.00    967.39    115.86      0.50
  32                 100.00    965.69    110.79      0.50
  9                -1866.18    800.00      0.00      1.00  Reservoir
  2                  766.18    970.00     52.00      1.00  Tank

Epanet-msx simulation results

Results of a multi-species simulation by Epanet-msx can be read as well.

The read.msxrpt() function creates an s3 object of class epanetmsx.rpt. Similar to the approach above, there is a data frame for node results and link results.

Usage with other packages

ggplot2

The ggplot2 package makes it easy to create complex graphics by allowing users to describe the plot in terms of the data. Continuing the Net1 example Here we plot chlorine concentration over time at each node in the network.

library(ggplot2)
qplot( data= n1r$nodeResults,  
       x = timeInSeconds/3600, y = Chlorine, 
       facets = ~ID, xlab = "Hour")  

Net 1 Cl plot

Animation

The animation package is useful for creating a video from successive plots.

# example with animation package 
library(animation)

#unique time stamps
ts <- unique((n1r$nodeResults$Timestamp))
imax <- length(ts)

# generate animation of plots at each time step
saveHTML(
  for( i in 1:imax){
    plot(n1r, n1, Timestep = ts[i]) 
  }
)

References

Rossman, L. A. (2000) Epanet 2 users manual. US EPA, Cincinnati, Ohio.



bradleyjeck/epanetReader documentation built on May 13, 2019, 2:28 a.m.