Skip to main content

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​

TableContent
nodesJunctions, outfalls, storage units and dividers
edgesConduits, pumps, orifices, weirs and outlets
subcatchmentsSubcatchments with subarea and infiltration data
raingagesRain gauges
timeseriesTime series values in long form
options[OPTIONS], [TITLE] and [MAP] entries
unparsedLines 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.

ColumnType
idUtf8
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, pondedAreaFloat64
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.

ColumnType
id, sourceId, targetIdUtf8
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, outletOffsetFloat64
shape (from [XSECTIONS])Utf8
geom1, geom2, geom3, geom4Float64
barrelsInt32
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 StructFields
junctionNo fields
outfalloutfallType, tideCurve (TIDAL), stageSeries (TIMESERIES), routeTo (Utf8); fixedStage (FIXED; Float64); gated (Bool)
storagestorageShape, curveId (TABULAR) (Utf8); parameter1, parameter2, parameter3 (other shapes), evaporationFraction, suction, conductivity, initialDeficit (Float64)
dividerdivertedLink, dividerType, curveId (TABULAR) (Utf8); minFlow (CUTOFF and WEIR), weirHeight, dischargeCoefficient (WEIR) (Float64)
conduitinitialFlow, maxFlow (Float64)
pumppumpCurve, initialStatus (Utf8); startupDepth, shutoffDepth (Float64)
orificeorificeType (Utf8); dischargeCoefficient, closeTime (Float64); gated (Bool)
weirweirType, roadSurface, coefficientCurve (Utf8); dischargeCoefficient, endCoefficient, roadWidth (Float64); endContractions (Int32); gated, surcharge (Bool)
outletoutletType, 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​

ColumnType
id, rainGage, outletIdUtf8
area, imperviousPercent, width, slopeFloat64
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​

TableColumns
raingagesid, format, interval, source (Utf8); snowCatch (Float64)
timeseriesname, date, time (Utf8); value (Float64)
optionssection, key, value (Utf8)
unparsedsection, 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:

  1. Opening record: the magic number 516114522, the SWMM version, the flow-unit code and the counts of subcatchments, nodes, links and pollutants.
  2. Object IDs: each ID is an int32 byte length and the bytes.
  3. Pollutant concentration-unit codes.
  4. Input properties: subcatchment area; node type, invert and maximum depth; link type, offsets, maximum depth and length.
  5. Counts and codes of the reporting variables for subcatchments, nodes, links and the system.
  6. The report start date (float64 days since 1899-12-30) and the report step (int32 seconds).
  7. One block per reporting period: the float64 date, then the float32 values of all subcatchments, nodes, links and the system.
  8. 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​

TableContent
metadataOne row with the run settings
timesOne row per reporting period
subcatchmentResultsOne row per subcatchment
nodeResultsOne row per node
linkResultsOne row per link
systemResultsOne 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.

TableVariables
subcatchmentResultsrainfall, snowDepth, evaporation, infiltration, runoff, groundwaterFlow, groundwaterElevation, soilMoisture, then pollutant:<name> per pollutant
nodeResultsdepth, head, volume, lateralInflow, totalInflow, flooding, then pollutant:<name> per pollutant
linkResultsflow, depth, velocity, volume, capacity, then pollutant:<name> per pollutant
systemResultsairTemperature, rainfall, snowDepth, infiltration, runoff, dryWeatherInflow, groundwaterInflow, rdiiInflow, directInflow, totalLateralInflow, flooding, outflow, storage, evaporation, potentialEvaporation
TableColumns
metadataversion, reportStepSeconds, periodCount, errorCode (Int32); flowUnits (CFS, GPM, MGD, CMS, LPS, MLD; Utf8); startDate (Timestamp, ms, UTC)
timestime (Timestamp, ms, UTC)

Join results to the input tables​

  • Period t of each list is row t of the times table. The times table and each list have periodCount entries. metadata.periodCount gives the count. Row t of times is the end of period t: the report start date plus t + 1 report steps.
  • The id column holds the SWMM object name. Join it to the id column of the subcatchments, nodes or edges table of the .inp file. Join by id, 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> and FixedSizeList[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.