EPA SWMM format
The EPA Storm Water Management Model (SWMM) describes a drainage network in a text input file.
The file has the extension .inp. A simulation run writes the computed results to a binary output file.
That file has the extension .out. EPA SWMM is public domain software.
SWMMLoader parses the file into a tables collection of Apache Arrow tables.
Each section header of the file, for example [JUNCTIONS], starts a block of data lines.
Comments that start with ; are ignored.
Output tables
| Table | Content |
|---|---|
nodes | Junctions, outfalls, storage units and dividers |
edges | Conduits, pumps, orifices, weirs and outlets |
subcatchments | Subcatchments with subarea and infiltration data |
raingages | Rain gauges |
timeseries | Time series values in long form |
options | [OPTIONS], [TITLE] and [MAP] entries |
unparsed | Lines from sections that the loader does not parse |
References to undeclared objects are kept. The parser does not throw for them.
nodes
The first three columns are the node columns of the other graph loaders, in the same order and with the same types.
| Column | Type |
|---|---|
id | Utf8 |
label (always null) | Utf8 |
attributes (see Typed attributes) | Struct with one child Struct per node kind |
kind (junction, outfall, storage, divider) | Utf8 |
invertElevation, maxDepth, initialDepth, surchargeDepth, pondedArea | Float64 |
x, y (from [COORDINATES]) | Float64 |
edges
The first six columns are the edge columns of the other graph loaders, in the same order and with the same types.
A SWMM link goes from its inlet node (sourceId) to its outlet node (targetId), so directed is always true.
| Column | Type |
|---|---|
id, sourceId, targetId | Utf8 |
directed (always true) | Bool |
label (always null) | Utf8 |
attributes (see Typed attributes) | Struct with one child Struct per link kind |
kind (conduit, pump, orifice, weir, outlet) | Utf8 |
length, roughness, inletOffset, outletOffset | Float64 |
shape (from [XSECTIONS]) | Utf8 |
geom1, geom2, geom3, geom4 | Float64 |
barrels | Int32 |
vertices (from [VERTICES]) | List of FixedSizeList(2) of Float64 |
Typed attributes
The attributes column holds the fields that are specific to one object kind.
It has one child Struct per kind. In each row, the child Struct of the row kind has the values.
The child Structs of the other kinds are null. A field that the line does not supply is null.
A token that does not convert to the field type is null, for example a gate flag that is not YES or NO.
The schema is the same for every file, also when the file has no object of a kind.
| Child Struct | Fields |
|---|---|
junction | No fields |
outfall | outfallType, tideCurve (TIDAL), stageSeries (TIMESERIES), routeTo (Utf8); fixedStage (FIXED; Float64); gated (Bool) |
storage | storageShape, curveId (TABULAR) (Utf8); parameter1, parameter2, parameter3 (other shapes), evaporationFraction, suction, conductivity, initialDeficit (Float64) |
divider | divertedLink, dividerType, curveId (TABULAR) (Utf8); minFlow (CUTOFF and WEIR), weirHeight, dischargeCoefficient (WEIR) (Float64) |
conduit | initialFlow, maxFlow (Float64) |
pump | pumpCurve, initialStatus (Utf8); startupDepth, shutoffDepth (Float64) |
orifice | orificeType (Utf8); dischargeCoefficient, closeTime (Float64); gated (Bool) |
weir | weirType, roadSurface, coefficientCurve (Utf8); dischargeCoefficient, endCoefficient, roadWidth (Float64); endContractions (Int32); gated, surcharge (Bool) |
outlet | outletType, curveId (TABULAR) (Utf8); coefficient, exponent (FUNCTIONAL) (Float64); gated (Bool) |
const attributes = edges.getChild("attributes");
const weirs = attributes?.getChild("weir");
const isGated = weirs?.getChild("gated")?.get(row); // true, false or null
subcatchments
| Column | Type |
|---|---|
id, rainGage, outletId | Utf8 |
area, imperviousPercent, width, slope | Float64 |
nImperv, nPerv, sImperv, sPerv, percentZero (from [SUBAREAS]) | Float64 |
infiltration (JSON text from [INFILTRATION]) | Utf8 |
polygon (from [Polygons]) | List of FixedSizeList(2) of Float64 |
raingages, timeseries, options and unparsed
| Table | Columns |
|---|---|
raingages | id, format, interval, source (Utf8); snowCatch (Float64) |
timeseries | name, date, time (Utf8); value (Float64) |
options | section, key, value (Utf8) |
unparsed | section, line (Utf8) |
Coordinate reference system
The format has no CRS field. Set the swmm.crs option to store the CRS as swmm:crs
in the schema metadata of the nodes, edges and subcatchments tables.
Usage
import { load } from "@loaders.gl/core";
import { SWMMLoader } from "@loaders.gl/graphs/swmm";
const model = await load("Example1.inp", SWMMLoader);
const edges = model.tables.find((entry) => entry.name === "edges")?.table;
console.log(edges?.getChild("kind")?.get(0));
See SWMMLoader for the options.
Binary output file
SWMMOutputLoader parses a SWMM 5 binary output file (.out) into a tables collection of Apache Arrow tables.
The file is little-endian. It has these sections, in this order:
- Opening record: the magic number
516114522, the SWMM version, the flow-unit code and the counts of subcatchments, nodes, links and pollutants. - Object IDs: each ID is an int32 byte length and the bytes.
- Pollutant concentration-unit codes.
- Input properties: subcatchment area; node type, invert and maximum depth; link type, offsets, maximum depth and length.
- Counts and codes of the reporting variables for subcatchments, nodes, links and the system.
- The report start date (float64 days since 1899-12-30) and the report step (int32 seconds).
- One block per reporting period: the float64 date, then the float32 values of all subcatchments, nodes, links and the system.
- Closing record: the byte positions of the IDs, the input properties and the results, the period count, the error code and the magic number.
The times table gives the real time of each period.
Output tables
| Table | Content |
|---|---|
metadata | One row with the run settings |
times | One row per reporting period |
subcatchmentResults | One row per subcatchment |
nodeResults | One row per node |
linkResults | One row per link |
systemResults | One row with the system-wide results |
Each result table has an id column (Utf8), except systemResults.
Each variable is a FixedSizeList<Float32> column with one value per period.
The value of row row at period t is table.getChild(variable).get(row).get(t).
get(row) returns an Arrow Vector, so get(row)[t] is undefined. Use get(row).toArray() for a Float32Array of all periods.
| Table | Variables |
|---|---|
subcatchmentResults | rainfall, snowDepth, evaporation, infiltration, runoff, groundwaterFlow, groundwaterElevation, soilMoisture, then pollutant:<name> per pollutant |
nodeResults | depth, head, volume, lateralInflow, totalInflow, flooding, then pollutant:<name> per pollutant |
linkResults | flow, depth, velocity, volume, capacity, then pollutant:<name> per pollutant |
systemResults | airTemperature, rainfall, snowDepth, infiltration, runoff, dryWeatherInflow, groundwaterInflow, rdiiInflow, directInflow, totalLateralInflow, flooding, outflow, storage, evaporation, potentialEvaporation |
| Table | Columns |
|---|---|
metadata | version, reportStepSeconds, periodCount, errorCode (Int32); flowUnits (CFS, GPM, MGD, CMS, LPS, MLD; Utf8); startDate (Timestamp, ms, UTC) |
times | time (Timestamp, ms, UTC) |
Join results to the input tables
- Period
tof each list is rowtof thetimestable. Thetimestable and each list haveperiodCountentries.metadata.periodCountgives the count. Rowtoftimesis the end of periodt: the report start date plust + 1report steps. - The
idcolumn holds the SWMM object name. Join it to theidcolumn of thesubcatchments,nodesoredgestable of the.inpfile. Join byid, not by row. The output file can have fewer objects than the input file. - The list size is the period count of the run. Tables from two runs with different period counts have different Arrow types,
for example
FixedSizeList[24]<Float32>andFixedSizeList[48]<Float32>. Do not concatenate them without a conversion.
The units of the values follow the flow units of the run, for example cubic feet per second and feet for CFS.
The output file has values only for the objects that the [REPORT] section selects.
See SWMMOutputLoader for the options.