How to access units programmatically for PySWMM

Question:

I’m looking for more references and to better understand the node and overall simulation data units for a PySWMM Model. I receive models that are developed in different units and I am looking to develop some standard interpretation / comparison tools for personal use. For example, the following example gives me node depth, but it does not come with units.

from pyswmm import Simulation, Nodes

with Simulation("./Example1.inp") as sim:
    node1 = Nodes(sim)["1"]

    for step in sim:
        print(node1.depth)
Asked By: Evidlo

||

Answers:

The units are defined inside the SWMM INP file in the [OPTIONS] section:

[OPTIONS]
;;Option             Value
FLOW_UNITS           CFS

PySWMM uses the same unit system as SWMM. However, I understand how this can be a bit unclear since this is not surfaced directly in PySWMM. PySWMM users can fetch out the units for the Simulation using the following command:

from pyswmm import Simulation

with Simulation("./Example1.inp") as sim:
    print(sim.flow_units)
    print(sim.system_units) # returns "SI" or "US"

Depending on the flow unit selection specified in the INP file, SWMM will determine whether or not you are in US or SI. The following table was pulled from the USEPA SWMM Users Manual.

Unit Table from USEPA SWMM Users Manual

For example, if the INP specifies a flow rate of CFS (or cubic feet per second), SWMM will decide that this is in US units. The code in your example would be in depth units of feet.

from pyswmm import Simulation, Nodes

with Simulation("./Example1.inp") as sim:
    node1 = Nodes(sim)["1"]

    for step in sim:
        print(node1.depth)
Answered By: bemcdonnell
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.