swmm5 module#

Python extensions for the SWMM5 Programmers toolkit.

exception SWMMException(error_code, error_message)[source]#

Bases: Exception

Custom exception class for SWMM errors.

exception PYSWMMException(error_message)[source]#

Bases: Exception

Custom exception class for PySWMM errors.

class PySWMM(inpfile='', rptfile=None, binfile=None, swmm_lib_path=None)[source]#

Bases: object

Wrapper class to lead SWMM DLL object.

This allow performing operations on the SWMM object that is created when the file is being loaded.

PySWMM can be run in two different modes:

Mode 1: Execute simulation without any intervention

  • Open the Input file using swmm_open()

  • Execute the simlation without intervening swmmExec()

  • then close calling swmm_close()

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmmExec()
>>> swmm_model.swmm_close()

—or—

Mode 2: Step through the entire simulation manually by (This mode allows the user to invervene and stream simulation data as well as set parameters and use outside controls approaches)

  • swmm_open()

  • swmm_start()

  • swmm_step() or swmm_stride() until it returns 0

  • swmm_end()

  • swmm_report()

  • swmm_close()

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step() # or swmm_stride()
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()

Initialize the PySWMM object class.

User can specified SWMM library path. Uses default lib if not provided.

Parameters:
  • inpfile (str) – Name of SWMM input file (default ‘’)

  • rptfile (str) – Report file to generate (default None)

  • binfile (str) – Optional binary output file (default None)

  • swmm_lib_path (str) – SWMM library path (default None).

swmmExec(inpfile=None, rptfile=None, binfile=None)[source]#

Open an input file, run SWMM, then close the file.

Parameters:
  • inpfile (str) – Name of SWMM input file

  • rptfile (str) – Report file to generate

  • binfile (str) – Optional binary output file

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmmExec()
>>> swmm_model.swmm_close()
swmm_run(inpfile=None, rptfile=None, binfile=None)[source]#

# TODO:.

swmm_open(inpfile=None, rptfile=None, binfile=None)[source]#

Opens SWMM input file & reads in network data.

Parameters:
  • inpfile (str) – Name of SWMM input file

  • rptfile (str) – Report file to generate

  • binfile (str) – Optional binary output file

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_close()
swmm_start(SaveOut2rpt=False)[source]#

Prepares to Start SWMM Simulation.

Parameters:

SaveOut2rpt (bool) – Save timeseries results to rpt file (default is False).

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
swmm_end()[source]#

Ends SWMM Simulation.

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
swmm_step()[source]#

Advances SWMM Simulation by a single routing step.

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
swmm_stride(advanceSeconds)[source]#

This function allows for user defined stride length to advance the model simulation by a defined time. This is useful when control rules are managed externally by PySWMM. Instead of evaluating rules every routing step, instead the simulation can be advanced further in time before the PySWMM can intervene. When a 0 is returned, the simulation period has reached the end.

Parameters:

advanceSeconds (int) – Number seconds to advance the simulation forward.

Returns:

Current simulation time after a stride in decimal days (float)

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_stride(600)
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
swmm_report()[source]#

Copies Time Series results from .out to .rpt file.

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
swmm_close()[source]#

Closes model and supporting files and cleans up memory.

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     if (time <= 0.0): break
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
swmm_save_hotstart(hotstart_filename)[source]#

Save the current state of the model to a hotstart file.

This can be run at any point during the simultion.

Parameters:

hotstart_filename (str) – Name of hotstart file to save to.

swmm_use_hotstart(hotstart_filename)[source]#

Use a hotstart file to initialize the model.

This must be run before swmm_start() and after swmm_open().

Parameters:

hotstart_filename (str) – Name of hotstart file to load from.

swmm_getVersion()[source]#

Retrieves version number of current SWMM engine.

The format used is xyzzz where x = major version number, y = minor version number, and zzz = build number.

Returns:

version number of the DLL source code

Return type:

int

swmm_getMassBalErr()[source]#

Get Mass Balance Errors.

Returns:

Runoff Error, Flow Routing Error, Quality Error

Return type:

tuple

getSimulationDateTime(timeType)[source]#

Get Simulation Time Data (Based on SimulationTime options).

Parameters:

timeType (int) – (toolkitapi.SimulationTime member variable)

Returns:

datetime

Return type:

datetime

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getSimulationDateTime(SimulationTime.StartDateTime)
2015-11-01 14:00:00
>>> swmm_model.getSimulationDateTime(SimulationTime.EndDateTime)
2015-11-04 00:00:00
>>> swmm_model.getSimulationDateTime(SimulationTime.ReportStart)
2015-11-01 14:00:00
>>>
>>> swmm_model.swmm_close()
setSimulationDateTime(timeType, newDateTime)[source]#

Set Simulation Time Data (Based on SimulationTime options).

Parameters:

timeType (int) – (toolkitapi.SimulationTime member variable)

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setSimulationDateTime(SimulationTime.StartDateTime,
                                     datetime(2009, 10, 1, 12,30))
>>>
getSimUnit(unit_type)[source]#

Get Simulation Units.

Parameters:

unittype (int) – Simulation Unit Type

Returns:

Simulation Unit Type

Return type:

str

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getSimUnit(SimulationUnits.FlowUnits)
CFS
>>> swmm_model.swmm_close()
getSimOptionSetting(setting_type)[source]#

Get Simulation Option Settings.

Parameters:

settingtype (int) – Analysis Option Setting

Returns:

Simulation Analysis option setting

Return type:

bool

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getSimAnalysisSetting(SimAnalysisSettings.AllowPonding)
False
>>> swmm_model.swmm_close()
getSimAnalysisSetting(param_type)[source]#

Get Simulation Configuration Parameter.

Parameters:

paramtype (int) – Simulation Parameter Type

Returns:

Simulation Analysis Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getSimAnalysisSetting(SimulationParameters.RouteStep)
300
>>> swmm_model.swmm_close()
getProjectSize(object_type)[source]#

Get Project Size: Number of Objects.

Parameters:

objecttype (int) – (member variable)

Returns:

Object Count

Return type:

int

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getProjectSize(ObjectType.NODE)
10
>>> swmm_model.swmm_close()
getObjectId(objecttype, index)[source]#

Get Object ID name.

Parameters:
  • objecttype (int) – (member variable)

  • index – ID Index

Returns:

Object ID

Return type:

string

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getObjectId(ObjectType.NODE,35)
"example_id_name"
>>>
>>> swmm_model.swmm_close()
getObjectIDList(objecttype)[source]#

Get Object ID list.

Parameters:

objecttype (int) – (member variable)

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getObjectIDList(ObjectType.LINK)
['C1:C2', 'C2', 'C3']
>>>
>>> swmm_model.swmm_close()
>>>
getObjectIDIndex(objecttype, ID)[source]#

Get Object ID Index. Mostly used as an internal function.

ObjectIDexist(objecttype, ID)[source]#

Check if Object ID Exists. Mostly used as an internal function.

getNodeType(ID)[source]#

Get Node Type (e.g. Junction, Outfall, Storage, Divider).

Parameters:

index (str) – ID

Returns:

Object ID

Return type:

int

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getNodeType('J1')
0
>>>
>>> swmm_model.getNodeType('J1') is NodeType.junction
True
>>>
>>> swmm_model.swmm_close()
getLinkType(ID)[source]#

Get Link Type (e.g. Conduit, Pump, Orifice, Weir, Outlet).

Parameters:

index (str) – ID

Returns:

Object ID

Return type:

int

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLinkType('C1')
3
>>>
>>> swmm_model.getLinkType('C1') is LinkType.weir
True
>>>
>>> swmm_model.swmm_close()
getLinkConnections(ID)[source]#

Get Link Connections (Upstream and Downstream Nodes).

Interestingly, if the dynamic wave solver is used, when the input file is parsed and added to the SWMM5 data model, any negatively sloped conduits are reversed automatically. The swmm_getLinkConnections function always calls the _swmm_getLinkDirection function to ensure the user-assigned upstream ID and downstream IDs are in the correct order. This way, the function provides support for directed graphs automatically.

Parameters:

index (str) – ID

Returns:

(Upstream Node Index, Downstream Node Index)

Return type:

tuple

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLinkConnections('C1')
('NodeUSID','NodeDSID')
>>>
>>> swmm_model.swmm_close()
getNodeParam(ID, parameter)[source]#

Get Node Parameter.

Parameters:
  • ID (str) – Node ID

  • parameter (int) – Parameter (toolkitapi.NodeParams member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getNodeParam('J2',NodeParams.invertElev )
13.392
>>>
>>> swmm_model.swmm_close()
setNodeParam(ID, parameter, value)[source]#

Set Node Parameter.

Parameters:
  • ID (str) – Node ID

  • Parameter (int) – Parameter (toolkitapi.NodeParams member variable)

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getNodeParam('J2',NodeParams.invertElev, 19 )
>>>
>>> swmm_model.swmm_close()
getLinkParam(ID, parameter)[source]#

Get Link Parameter.

Parameters:
  • ID (str) – Link ID

  • Parameter (int) – Parameter (toolkitapi.NodeParams member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLinkParam('C1:C2',LinkParams.offset1 )
0.0
>>>
>>> swmm_model.swmm_close()
setLinkParam(ID, parameter, value)[source]#

Set Link Parameter.

Parameters:
  • ID (str) – Link ID

  • Parameter (int) – Parameter (toolkitapi.NodeParams member variable)

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setLinkParam('C1:C2',LinkParams.offset1, 2 )
>>>
>>> swmm_model.swmm_close()
getLidCOverflow(ID)[source]#

Get Lid Control Parameter.

Parameters:

ID (str) – Lid Control ID

Return type:

Bool

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLidCOverflow('J2')
True
>>>
>>> swmm_model.swmm_close()
getLidCParam(ID, layer, parameter)[source]#

Get LidControl Parameter.

Parameters:
  • ID (str) – Lid Control ID

  • layer (int) – Layer (toolkitapi.LidLayers member variable)

  • parameter (int) – Parameter (toolkitapi.LidLayersProperty member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLidCParam('J2', LidLayer.surface, LidLayersProperty.thickness)
>>>
>>> swmm_model.swmm_close()
setLidCParam(ID, layer, parameter, value)[source]#

Set Lid Control Parameter Before/During Model Simulation.

Parameters:
  • ID (str) – Lid Control ID

  • layer (int) – Layer (toolkitapi.LidLayers member variable)

  • parameter (int) – Parameter (toolkitapi.LidLayersProperty member variable)

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setLidCParam('J2', LidLayer.surface, LidLayersProperty.thickness, 110)
>>>
>>> swmm_model.swmm_close()
getLidUCount(ID)[source]#

Get Number of Lid Units Defined for Subcatchment.

Parameters:

ID (str) – Subcatchment ID

Return type:

int

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLidUCount('J2')
2
>>>
>>> swmm_model.swmm_close()
getLidUParam(subcatchID, lid_index, parameter)[source]#

Get LidUnit Parameter

Parameters:
  • subcatchID (str) – Subcatchment ID

  • lid_index (int) – Lid unit index

  • parameter (int) – Paramter (toolkitapi.LidUParams member variable)

Returns:

paramater Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLidUParam('S2', 0, LidUParams.unitarea)
1000
>>>
>>> swmm_model.swmm_close()
setLidUParam(subcatchID, lid_index, parameter, value)[source]#

Set LidUnit Parameter

Parameters:
  • subcatchID (str) – Subcatchment ID

  • lid_index (int) – Lid unit index

  • parameter (int) – parameter (toolkitapi.LidUParams member variable)

  • value (double) – value set to parameter

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setLidUParam('S2', 0, LidUParams.unitarea, 10)
>>>
>>> swmm_model.swmm_close()
getLidUOption(subcatchID, lid_index, parameter)[source]#

Get LidUnit Option

Parameters:
  • subcatchID (str) – Subcatchment ID

  • lid_index (int) – Lid unit Index

  • parameter (int) – paramter (toolkitapi.LidUParams member variable)

Returns:

paramater Value

Return type:

int

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLidUOption('S2', 0, LidUParams.index)
1000
>>>
>>> swmm_model.swmm_close()
setLidUOption(subcatchID, lid_index, parameter, value)[source]#

Set LidUnit Option

Parameters:
  • subcatchID (str) – Subcatchment ID

  • lid_index (int) – Lid unit index

  • parameter (int) – paramter (toolkitapi.LidUParams member variable)

  • value (double) – value set to parameter

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setLidUOption('S2', 0, LidUParams.index, 0)
>>>
>>> swmm_model.swmm_close()
getSubcatchParam(ID, parameter)[source]#

Get Subcatchment Parameter

Parameters:
  • ID (str) – Subcatchment ID

  • Parameter (int) – Parameter (toolkitapi.SubcParams member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getLinkParam('S2',SubcParams.area )
43561.596096880996
>>>
>>> swmm_model.swmm_close()
setSubcatchParam(ID, parameter, value)[source]#

Set Subcatchment Parameter.

Parameters:
  • ID (str) – Subcatchment ID

  • parameter (int) – paramter (toolkitapi.SubcParams member variable)

  • value (double) – value set to parameter

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setLinkParam('S2',SubcParams.area, 100 )
>>>
>>> swmm_model.swmm_close()
getSubcatchOutConnection(ID)[source]#

Get Subcatchment Outlet Connection.

This function return the type of loading surface and the ID. The two load to objects are nodes and other subcatchments.

Nodes are ObjectType.NODE Subcatchments are ObjectType.SUBCATCH

Parameters:
  • ID (str) – Subcatchment ID

  • Parameter (int) – Parameter (toolkitapi.SubcParams member variable)

Returns:

(Loading Surface Type, ID)

Return type:

tuple

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getSubcatchOutConnection('S2',SubcParams.area )
(2, 'J2')
>>>
>>> subout = swmm_model.getSubcatchOutConnection('S2',SubcParams.area )
>>> subout[0]  == ObjectType.NODE
True
>>>
>>> swmm_model.swmm_close()
getGagePrecip(ID, parameter)[source]#

Get precipitation from gage

This function returns the rainfall, show and total precipitation associated with the gage

Parameters:
  • ID (str) – Gage ID

  • parameter (int) – paramter (toolkitapi.RainGageResults member variable)

Returns:

value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.getGagePrecip('Gage1', )
0.0
>>> swmm_model.swmm_close()
getCurrentSimulationTime()[source]#

Get Current Simulation DateTime in Python Format.

Returns:

Python Datetime

Return type:

datetime

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getCurrentSimualationTime())
...     if (time <= 0.0): break
2015-11-03 10:10:12
2015-11-03 10:20:12
2015-11-03 10:30:12
2015-11-03 10:40:12
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getLidUFluxRates(subcatchID, lidIndex, layerIndex)[source]#

Get Lid Unit Layer Flux Rates Result.

Parameters:
  • subcatchID (str) – Subcatchment ID

  • lidIndex (int) – Lid unit Index

  • layerIndex (int) – Parameter (toolkitapi.LidLayers member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getLidUFluxRates('J1', 0, LidLayers.surface))
...     if (time <= 0.0): break
1.2
1.5
1.9
1.2
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getLidUResult(subcatchID, lidIndex, resultType)[source]#

Get Lid Result.

Parameters:
  • subcatchID (str) – Subcatchment ID

  • lidIndex (int) – Lid unit Index

  • resultType (int) – Parameter (toolkitapi.LidUResults member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getLidUResult('J1', 0, LidUResults.inflow))
...     if (time <= 0.0): break
1.2
1.5
1.9
1.2
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getLidGResult(subcatchID, resultType)[source]#

Get Lid Group Result.

Parameters:
  • subcatchID (str) – Subcatchment ID

  • resultType (int) – Parameter (toolkitapi.LidUResults member variable)

Returns:

Parameter Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getLidGResult('J1', LidUResults.flowToPerv))
...     if (time <= 0.0): break
1.2
1.5
1.9
1.2
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getNodeResult(ID, result_type)[source]#

Get Node Result.

Parameters:
  • ID (str) – Node ID

  • result_type (int) – parameter (toolkitapi.NodeResults member variable)

Returns:

value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getNodeResult('J1', NodeResults.newDepth))
...     if (time <= 0.0): break
1.2
1.5
1.9
1.2
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getNodePollut(ID, result_type)[source]#

Get water quality results from a Node.

Parameters:
  • ID (str) – Node ID

  • result_type (int) – parameter (toolkitapi.NodePollut member value)

Return type:

list

getLinkResult(ID, result_type)[source]#

Get Link Result.

Parameters:
  • ID (str) – Link ID

  • result_type (int) – parameter (toolkitapi.LinkResults member variable)

Returns:

parameter value

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getLinkResult('J1', LinkResults.newFlow))
...     if (time <= 0.0): break
1.2
1.5
1.9
1.2
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getLinkPollut(ID, result_type)[source]#

Get water quality results from a Link.

Parameters:
  • ID (str) – Link ID

  • result_type (int) – parameter (toolkitapi.LinkPollut member value)

Returns:

Pollutant Value

Return type:

list

getSubcatchResult(ID, result_type)[source]#

Get Subcatchment Result

Parameters:
  • ID (str) – Subcatchment ID

  • result_type (int) – paramter (toolkitapi.LinkResults member variable)

Returns:

paramater Value

Return type:

float

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> while(True):
...     time = swmm_model.swmm_step()
...     print(swmm_model.getSubcatchResult('S3', SubcResults.newRunoff))
...     if (time <= 0.0): break
0.01
0.05
0.09
0.08
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
getSubcatchPollut(ID, result_type)[source]#

Get pollutant results from a Subcatchment.

Parameters:
  • ID (str) – Subcatchment ID

  • result_type (int) – parameter (toolkitapi.SubcPollut member variable)

Returns:

Pollutant Values

Return type:

list

node_statistics(ID)[source]#

Get stats for a Node.

Parameters:

ID (str) – Node ID

Returns:

Group Stats

Return type:

dict

node_inflow(ID)[source]#

Get total inflow volume for a Node.

Parameters:

ID (str) – Node ID

Returns:

Total Volume

Return type:

float

storage_statistics(ID)[source]#

Get stats for a Storage Node.

Parameters:

ID (str) – Node ID

Returns:

Group Stats

Return type:

dict

outfall_statistics(ID)[source]#

Get stats for a Outfall Node.

Parameters:

ID (str) – Node ID

Returns:

Group Stats

Return type:

dict

conduit_statistics(ID)[source]#

Get stats for a Conduits.

Parameters:

ID (str) – Conduit ID

Returns:

Group Stats

Return type:

dict

pump_statistics(ID)[source]#

Get stats for a Pump.

Parameters:

ID (str) – Pump ID

Returns:

Group Stats

Return type:

dict

subcatch_statistics(ID)[source]#

Get stats for a Subcatchment.

Parameters:

ID (str) – Subcatchment ID

Returns:

Group Stats

Return type:

dict

flow_routing_stats()[source]#

Get Flow Routing System stats.

Returns:

Dictionary of Flow Routing Stats.

Return type:

dict

runoff_routing_stats()[source]#

Get Runoff Routing System stats.

Returns:

Dictionary of Runoff Routing Stats.

Return type:

dict

setLinkSetting(ID, target_setting)[source]#

Set Link Setting (Pumps, Orifices, Weirs).

Parameters:
  • ID (str) – Link ID

  • target_setting (float) – New target setting which will be applied

at the start of the next routing step.

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> i = 0
>>> while(True):
...     time = swmm_model.swmm_step()
...     i+=1
...     if i == 80:
...         swmm_model.setLinkSetting('C3',0.5)
...     if (time <= 0.0): break
...
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
setNodeInflow(ID, flow_rate)[source]#

Set Node Inflow rate.

The flow rate should be in the user defined units. The value is held constant in the model until it is redefined by the toolkit API.

Parameters:
  • ID (str) – Node ID

  • flow_rate (float) – New flow rate in the user-defined flow units

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> i = 0
>>> while(True):
...     if i == 80:
...         swmm_model.setNodeInflow('J1',4)
...     time = swmm_model.swmm_step()
...     i+=1
...     if (time <= 0.0): break
...
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
setOutfallStage(ID, stage)[source]#

Set Outfall Stage (head).

The level should be in the user defined units. The value is held constant in the model until it is redefined by the toolkit API.

Parameters:
  • ID (str) – Node ID

  • stage (float) – New flow rate in the user-defined flow units

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.swmm_start(True)
>>> i = 0
>>> while(True):
...     if i == 80:
...         swmm_model.setOutfallStage('J1',4)
...     time = swmm_model.swmm_step()
...     i+=1
...     if (time <= 0.0): break
...
>>>
>>> swmm_model.swmm_end()
>>> swmm_model.swmm_report()
>>> swmm_model.swmm_close()
setGagePrecip(ID, value)[source]#

Set precipitation to gage

This function sets the rainfall intensity to the gage

Parameters:
  • ID (str) – Gage ID

  • valve (float) – rainfall intensity

Returns:

errcode

Examples:

>>> swmm_model = PySWMM(r'\.inp',r'\.rpt',r'\.out')
>>> swmm_model.swmm_open()
>>> swmm_model.setGagePrecip('Gage1', 10.0)
>>> swmm_model.swmm_close()
setNodePollut(ID, pollutant_ID, pollutant_value)[source]#

Set water quality results in a Node.

Parameters:

ID (str) – Node ID

:param str pollutant_ID :param float pollutant_value: pollutant value to set

setLinkPollut(ID, pollutant_ID, pollutant_value)[source]#

Set water quality results in a Link.

Parameters:
  • ID (str) – Link ID

  • ID – Pollutant ID

  • pollutant_value (float) – pollutant value to set