Note: If you wish to replicate the R code below, then you will need to copy and paste the following commands in R first (to make sure you have all the packages and their dependencies).

You will also need to download both files (http://www.ecoccs.com/R_Examples/Third_Creek_Water_Distribution_Project.inp and http://www.ecoccs.com/R_Examples/Third_Creek_Water_Distribution_Project.rpt) to the working directory on your computer.


install.packages("install.load")
# install the install.load package

install.load::install_load("epanetReader", "htmlTable")
# install and/or load the packages and their dependencies


This example was created with rmarkdown 1.2 using the following:



The following document uses the .inp and .map file created in March 2004 for EPANET analysis of the Third Creek Water Distribution system in Knoxville, Tennessee. The analysis that follows is based on “Read .rpt file” and “Read .inp file” examples from epanetReader R package.



install.load::load_package("epanetReader", "htmlTable")
# load needed packages using the load_package function from the install.load
# package (it is assumed that you have already installed these packages)


# inp is the .inp file name
inp <- "Third_Creek_Water_Distribution_Project.inp"


# read the network file into R
n1s <- read.inp(inp)

# Network summary
summary(n1s)
## $Title
## [1] "EPANET Third Creek Water Distribution Project - Irucka Embry (March 2004)"
## 
## $entryCounts
##             Number
## Junctions      117
## Tanks            2
## Reservoirs       1
## Pipes          162
## Pumps            3
## Coordinates    120
## 
## attr(,"class")
## [1] "summary.epanet.inp"
# Names of the elements of the R object n1s
names(n1s)
##  [1] "Title"       "Junctions"   "Tanks"       "Reservoirs"  "Pipes"      
##  [6] "Pumps"       "Valves"      "Demands"     "Patterns"    "Curves"     
## [11] "Controls"    "Rules"       "Energy"      "Status"      "Emitters"   
## [16] "Quality"     "Sources"     "Reactions"   "Mixing"      "Times"      
## [21] "Report"      "Options"     "Coordinates" "Vertices"    "Labels"     
## [26] "Backdrop"    "Tags"
# Network summary of the junctions
summary(n1s$Junctions)
##       ID              Elevation        Demand        Pattern       
##  Length:117         Min.   : 935   Min.   :   0.00   Mode:logical  
##  Class :character   1st Qu.:1020   1st Qu.:   8.91   NA's:117      
##  Mode  :character   Median :1060   Median :  15.10                 
##                     Mean   :1067   Mean   :  51.74                 
##                     3rd Qu.:1100   3rd Qu.:  29.49                 
##                     Max.   :1260   Max.   :3500.00
# Network summary of the pipes
summary(n1s$Pipes)
##       ID                Node1            Node2            Length      
##  Length:162         Min.   :  8.00   Min.   :  8.00   Min.   :  42.5  
##  Class :character   1st Qu.: 41.00   1st Qu.: 35.25   1st Qu.:1075.8  
##  Mode  :character   Median : 72.50   Median : 75.50   Median :1735.2  
##                     Mean   : 77.89   Mean   : 76.01   Mean   :2067.2  
##                     3rd Qu.:105.00   3rd Qu.:106.00   3rd Qu.:2823.0  
##                     Max.   :209.00   Max.   :207.00   Max.   :7760.0  
##     Diameter        Roughness     MinorLoss  Status   
##  Min.   : 2.000   Min.   :100   Min.   :0   Open:162  
##  1st Qu.: 6.000   1st Qu.:100   1st Qu.:0             
##  Median : 8.000   Median :100   Median :0             
##  Mean   : 8.247   Mean   :100   Mean   :0             
##  3rd Qu.:12.000   3rd Qu.:100   3rd Qu.:0             
##  Max.   :16.000   Max.   :100   Max.   :0
# Network plot
plot(n1s, legend.locn = "topleft")

# read the network report file into R
rpt <- "Third_Creek_Water_Distribution_Project.rpt"

# 
n1r <- read.rpt(rpt)

# 
summary(n1r)
## Contains node results for  25 time steps 
## 
## Summary of Junction Results: 
##      Demand           Pressure         Quality 
##  Min.   :   0.00   Min.   :  4.54   Min.   :0  
##  1st Qu.:   8.91   1st Qu.: 78.06   1st Qu.:0  
##  Median :  15.10   Median : 96.08   Median :0  
##  Mean   :  51.74   Mean   : 97.48   Mean   :0  
##  3rd Qu.:  29.49   3rd Qu.:115.03   3rd Qu.:0  
##  Max.   :3500.00   Max.   :170.20   Max.   :0  
## 
## Summary of Tank Results:
##      Demand          Pressure        Quality 
##  Min.   :-484.1   Min.   :0.000   Min.   :0  
##  1st Qu.:-197.3   1st Qu.:0.000   1st Qu.:0  
##  Median :-108.6   Median :0.740   Median :0  
##  Mean   :-129.5   Mean   :1.970   Mean   :0  
##  3rd Qu.:   0.0   3rd Qu.:3.855   3rd Qu.:0  
##  Max.   :   0.0   Max.   :7.060   Max.   :0  
## 
## Contains link results for  25 time steps 
## 
## Summary of Pipe Results:
##       Flow             Velocity        Headloss    
##  Min.   :-897.100   Min.   :0.000   Min.   : 0.00  
##  1st Qu.:  -4.827   1st Qu.:0.130   1st Qu.: 0.02  
##  Median :  22.190   Median :0.390   Median : 0.14  
##  Mean   :  66.619   Mean   :0.707   Mean   : 1.35  
##  3rd Qu.: 107.060   3rd Qu.:1.110   3rd Qu.: 1.21  
##  Max.   :1869.230   Max.   :5.010   Max.   :21.96
# 
names(n1r)
## [1] "nodeResults" "linkResults"
# Results for a chosen time period can be retrieved using the subset
# function
htmlTable(head(subset(n1r$nodeResults, Timestamp == "19:00")), rnames = FALSE, 
    align = "l", align.header = "l", css.cell = "padding-left: 0.5em; padding-right: 5em;")
ID Demand Head Pressure Quality note Timestamp timeInSeconds nodeType
8 26.73 1313.26 163.9 0 19:00 68400 Junction
9 5.44 1310.97 152.07 0 19:00 68400 Junction
10 10.89 1310.16 156.06 0 19:00 68400 Junction
11 40.77 1309.52 155.78 0 19:00 68400 Junction
12 26.09 1298.61 146.72 0 19:00 68400 Junction
13 29.67 1307.49 89.91 0 19:00 68400 Junction
# time series plot for a nodal value
plot(Pressure ~ timeInSeconds, data = subset(n1r$nodeResults, ID == "22"))

# Plotting the epanet.rpt object itself gives a map
plot(n1r, n1s, Timestep = "19:00", legend1.locn = "bottomright")