Title: | R Interface for US EPA's SWMM |
---|---|
Description: | Functions to connect the widely used Storm Water Management Model (SWMM) of the United States Environmental Protection Agency (US EPA) <https://www.epa.gov/water-research/storm-water-management-model-swmm> to R with currently two main goals: (1) Run a SWMM simulation from R and (2) provide fast access to simulation results, i.e. SWMM's binary '.out'-files. High performance is achieved with help of Rcpp. Additionally, reading SWMM's '.inp' and '.rpt' files is supported to glance model structures and to get direct access to simulation summaries. |
Authors: | Dominik Leutnant [aut, cre] , Anneke Doering [aut], Malte Henrichs [ctb], Hauke Sonnenberg [ctb] |
Maintainer: | Dominik Leutnant <[email protected]> |
License: | GPL-3 |
Version: | 0.9.1.9000 |
Built: | 2024-11-01 06:11:08 UTC |
Source: | https://github.com/hsonne/swmmr |
This function reads an object of class 'inp'. All objects are
converted to simple feature geometries via inp_to_sf
and
finally passed to geom_sf
. It allows to quickly
visualize a model structure.
## S3 method for class 'inp' autoplot(x, ...)
## S3 method for class 'inp' autoplot(x, ...)
x |
An inp object |
... |
currently ignored |
Lifecycle: experimental
## Not run: inp <- read_inp("model.inp") autoplot(inp) ## End(Not run)
## Not run: inp <- read_inp("model.inp") autoplot(inp) ## End(Not run)
junctions_to_sf()
: converts junctions to simple features (required
sections: junctions
and coordinates
)
outfalls_to_sf()
: converts junctions to simple features (required
sections: outfalls
and coordinates
)
links_to_sf()
: converts links to simple features (required sections:
conduits
and coordinates
)
subcatchments_to_sf()
: converts subcatchments to simple features (required
sections: subcatchments
, subareas
, infiltration
and polygons
)
raingages_to_sf()
: converts raingages to simple features (required
sections: raingages
and symbols
)
storages_to_sf()
: converts storages to simple features (required sections:
storage
and coordinates
)
weirs_to_sf()
: converts weirs to simple features (required sections:
weirs
and coordinates
)
orifices_to_sf()
: converts orifices to simple features (required sections:
orifices
and coordinates
)
pumps_to_sf()
: converts pumps to simple features (required sections:
pumps
and coordinates
)
inp_to_sf()
: converts junctions, outfalls, links, storages, weirs,
orifices, pumps, subcatchments and raingages to a list of simple features
raingages_to_sf(x) junctions_to_sf(x) outfalls_to_sf(x) storages_to_sf(x) subcatchments_to_sf(x) links_to_sf(x) weirs_to_sf(x) orifices_to_sf(x) pumps_to_sf(x) weirs_to_sf(x) orifices_to_sf(x) pumps_to_sf(x) inp_to_sf(x, remove_invalid = TRUE)
raingages_to_sf(x) junctions_to_sf(x) outfalls_to_sf(x) storages_to_sf(x) subcatchments_to_sf(x) links_to_sf(x) weirs_to_sf(x) orifices_to_sf(x) pumps_to_sf(x) weirs_to_sf(x) orifices_to_sf(x) pumps_to_sf(x) inp_to_sf(x, remove_invalid = TRUE)
x |
An object of class 'inp', created by |
remove_invalid |
Should invalid sf geometries be removed? |
A simple feature or a list of simple features
This function opens an .out file and lists all available time series data. Currently, the list is returned 'as is' which might change in future. It belongs to a set of helper functions which aim to simplify the work with .out files. The lifecycle of this function is considered experimental.
get_out_content(file = "")
get_out_content(file = "")
file |
The file to be read. |
A list showing the available content.
## Not run: content <- get_out_content("model.out") ## End(Not run)
## Not run: content <- get_out_content("model.out") ## End(Not run)
This function opens an .out file and extract the swmm version the file was generated with. It belongs to a set of helper functions which aim to simplify the work with .out files. The lifecycle of this function is considered experimental.
get_out_version(file = "")
get_out_version(file = "")
file |
The file to be read. |
A vector of type integer
## Not run: version <- get_out_version("model.out") ## End(Not run)
## Not run: version <- get_out_version("model.out") ## End(Not run)
Convert SWMM's .inp to .shp and txt files
inp_to_files(x, name, path_out = getwd())
inp_to_files(x, name, path_out = getwd())
x |
An object of class inp. |
name |
Give a name for the current model, e.g. "Example1". |
path_out |
Writeable directory name where to save the converted files. Folders: dat, shp and txt will be created if not existent. Default is the current working directory of the R process. |
.dat, .shp and/or .txt files.
Reads a SWMM .inp file and creates a list with corresponding SWMM sections.
read_inp(x, rm.comment = TRUE, ...)
read_inp(x, rm.comment = TRUE, ...)
x |
Name (incl. path) to an input file. |
rm.comment |
Should lines with comments starting with a ";" be discarded? |
... |
optional arguments passed to |
An object of class inp
## Not run: list_of_inp_sections <- read_inp("model.inp") ## End(Not run)
## Not run: list_of_inp_sections <- read_inp("model.inp") ## End(Not run)
Reads a SWMM's LID Report File and returns a tibble
read_lid_rpt(x, return_xts = TRUE, ...)
read_lid_rpt(x, return_xts = TRUE, ...)
x |
Name (incl. path) to a LID report file. |
return_xts |
logical. Sets the return type. If set to TRUE, xts objects are returned, FALSE gives tibbles. |
... |
optional arguments passed to |
A tibble or xts object
## Not run: tbl_lid_rpt <- read_lid_rpt("lid_rpt.txt") ## End(Not run)
## Not run: tbl_lid_rpt <- read_lid_rpt("lid_rpt.txt") ## End(Not run)
Reads the binary output ('.out') generated by the stormwater management model 'SWMM' and creates a list of xts-objects.
read_out(file = "", iType = NULL, object_name = NULL, vIndex = NULL)
read_out(file = "", iType = NULL, object_name = NULL, vIndex = NULL)
file |
The file to be read. |
iType |
Sets the result type: 0 for Subcatchments, 1 for nodes, 2 for links, 3 for system variables. Leave empty for retrieving elements available. |
object_name |
Sets the objects of which time series data is returned. Leave empty for retrieving elements available. |
vIndex |
Sets the variables to be read (s. Details). Leave empty for retrieving elements available. |
vIndex depends on the result type. Choices are...
for each subcatchment variable:
0 for rainfall rate (in/hr or mm/hr),
1 for snow depth (inches or millimeters),
2 for evaporation loss (in/day or mm/day),
3 for infiltration loss (in/hr or mm/hr),
4 for runoff flow (flow units),
5 for groundwater flow into the drainage network (flow units),
6 for groundwater elevation (ft or m),
7 for soil moisture in the unsaturated groundwater zone (volume fraction),
7 + N for washoff concentration of each pollutant (mass/liter).
for each node variable:
0 for water depth (ft or m above the node invert elevation),
1 for hydraulic head (ft or m, absolute elevation per vertical datum),
2 for stored water volume (including ponded water, ft3 or m3),
3 for lateral inflow (runoff + all other external inflows, in flow units),
4 for total inflow (lateral inflow + upstream inflows, in flow units),
5 for surface flooding (excess overflow when the node is at full depth, in flow units),
5 + N for concentration of each pollutant after any treatment (mass/liter),
for each link variable:
0 for flow rate (flow units),
1 for average water depth (ft or m),
2 for flow velocity (ft/s or m/s),
3 for volume of water (ft3 or m3),
4 for capacity (fraction of full area filled by flow for conduits; control setting for pumps and regulators),
4 + N for concentration of each pollutant (mass/liter),
for each system-wide variable:
0 for air temperature (deg. F or deg. C),
1 for total rainfall (in/hr or mm/hr),
2 for total snow depth (inches or millimeters),
3 for average losses (in/hr or mm/hr),
4 for total runoff (flow units),
5 for total dry weather inflow (flow units),
6 for total groundwater inflow (flow units),
7 for total RDII inflow (flow units),
8 for total external inflow (flow units),
9 for total direct inflow (flow units),
10 for total external flooding (flow units),
11 for total outflow from outfalls (flow units),
12 for total nodal storage volume ( ft3 or m3),
13 for potential evaporation (in/day or mm/day),
14 for actual evaporation (in/day or mm/day).
A list of xts-objects.
xts
.
## Not run: xts_list_of_results <- read_out("model.out") ## End(Not run)
## Not run: xts_list_of_results <- read_out("model.out") ## End(Not run)
Reads a SWMM .rpt file and creates a list with corresponding results sections.
read_rpt(x, ...)
read_rpt(x, ...)
x |
Name (incl. path) to an report file. |
... |
optional arguments passed to |
An object of class rpt
## Not run: list_of_rpt_results <- read_rpt("model.rpt") ## End(Not run)
## Not run: list_of_rpt_results <- read_rpt("model.rpt") ## End(Not run)
This function runs a swmm inp file. If rpt and out files are not specified files are automatically created in the same directory of the inp file.
run_swmm(inp, rpt = NULL, out = NULL, exec = NULL, stdout = "", wait = TRUE)
run_swmm(inp, rpt = NULL, out = NULL, exec = NULL, stdout = "", wait = TRUE)
inp |
Name and path to an input file. |
rpt |
Name and path to a report file. |
out |
Name and path to an out file. |
exec |
Name and path to swmm5 executable. If not manually set, the following paths are looked up when package gets loaded: windows: "C:/Program Files (x86)/EPA SWMM 5.X.XXX/swmm5.exe" not windows: "/usr/local/bin/swmm5" , "/usr/bin/swmm5" |
stdout |
where output to ‘stdout’ or
‘stderr’ should be sent. Possible values are |
wait |
a logical (not |
The path to a swmm5 executable is read by calling 'getOption("swmmr.exec")'.
## Not run: result <- run_swmm("model.inp") ## End(Not run)
## Not run: result <- run_swmm("model.inp") ## End(Not run)
Reads *.shp files and other information needed for SWMM's *.inp file and returns a list of class inp. If paths are not specified default values are taken.
shp_to_inp( path_options = NULL, path_polygon = NULL, subcatchment_typologies = NULL, path_point = NULL, junction_parameters = NULL, path_outfall = NULL, path_line = NULL, conduit_material = NULL, path_timeseries = NULL, infiltration = NULL, path_pumps = NULL, path_pump_curve = NULL, path_weirs = NULL, path_storage = NULL, path_storage_curve = NULL )
shp_to_inp( path_options = NULL, path_polygon = NULL, subcatchment_typologies = NULL, path_point = NULL, junction_parameters = NULL, path_outfall = NULL, path_line = NULL, conduit_material = NULL, path_timeseries = NULL, infiltration = NULL, path_pumps = NULL, path_pump_curve = NULL, path_weirs = NULL, path_storage = NULL, path_storage_curve = NULL )
path_options |
Name (incl. path) to a .txt file with SWMM sections. Write section name in lower case and in squared brackets. The following sections are allowed: options, report, raingages, evaporation, pollutant, landuse, buildup, washoff, coverages. |
path_polygon |
Name (incl. path) to a .shp file with polygons features. At least the following subcatchment related columns must be specified: Name, Outlet, Area, RouteTo. |
subcatchment_typologies |
R data.frame or tibble with further subcatchment related parameters. If subcatchment_typologies is given, polygon feature has to include a column named Type. Parameters defined in subcatchment_typologies parameters are merged to subcatchments by Type. |
path_point |
Name (incl. path) to a .shp file with point features. At least the following junction related columns must be specified: Name, Bottom and Top or Ymax. |
junction_parameters |
R data.frame or tibble with further junction related parameters (e.g. Surcharge depth). |
path_outfall |
Name (incl. path) to a .shp file with point features. At least the following outfall related columns must be specified: Name, Bottom, Type, Gated. |
path_line |
Name (incl. path) to a .shp file with line features. At least the following conduit related coulumns must be specified: Name, Length, Type, FromNode, ToNode, OutOffset, Geom1. |
conduit_material |
R data.frame or tibble with further conduit related parameters (e.g. roughness). If conduit_material is given, line feature has to include a column named Material. Parameters defined in conduit_material parameters are merged to conduits by Material. |
path_timeseries |
Name (incl. path) to a .dat file with a timeseries in SWMM format. |
infiltration |
R data.frame or tibble with infiltration parameters related to soil properties. If infiltration is given, polygon feature has to include a column named soil. Infiltration parameters are merged to subcatchments by soil name. |
path_pumps |
Name (incl. path) to a .shp file with line features. All parameters must be given: Name, FromNode, ToNode, Pcurve, status, Startup, Shutoff. |
path_pump_curve |
Name (incl. path) to a .txt file with pump curve information. Having the following structure: "Name of pump" "PUMP1-4" "x" "y", without header. |
path_weirs |
Name (incl. path) to a .shp file with line features. All parameters must be given: Name, FromNode, ToNode, Type, CrestHt, Cd, Gated, EC, Cd2, Sur. |
path_storage |
Name (incl. path) to a .txt file with storage curve information. Having the following structure: "Name of storage" "Storage" "x" "y", without header. |
path_storage_curve |
Name (incl. path) to a .txt file with storage curve information. Having the following structure: "Name of storage unit" "Storage" "x" "y", without header. |
A list of class inp.
Show summary of a swmm model structure
## S3 method for class 'inp' summary(object, ...)
## S3 method for class 'inp' summary(object, ...)
object |
An object of class 'inp', created by |
... |
Additional parameters (currently ignored). |
The input is returned invisibly.
## Not run: x <- read_inp("model.inp") summary(x) ## End(Not run)
## Not run: x <- read_inp("model.inp") summary(x) ## End(Not run)
Writes an inp
object to disk which can be read and run by SWMM.
write_inp(x, file)
write_inp(x, file)
x |
An object of class 'inp', created by |
file |
either a character string naming a file or a connection
open for writing. |
## Not run: write_inp(inp, "~/model.inp") ## End(Not run)
## Not run: write_inp(inp, "~/model.inp") ## End(Not run)