functions#

swmmio.utils.functions.check_if_url_and_download(url)[source]#

Check if a given string is a URL and download the file to a temporary directory if it is.

Parameters:
urlstr

string that may be a URL

Returns:
str

path to the downloaded file in the temporary directory or the original string if it is not a URL

swmmio.utils.functions.find_network_trace(model, start_node, end_node, include_nodes=None, include_links=None)[source]#

This function searches for a path between two nodes. In addition, since SWMM allows multiple links (edges) between nodes, the user can specify a list of both nodes, and links to include in the path. It will return a single path selection.

Parameters:
  • model – swmmio.Model object

  • start_node – string of Node Name

  • end_node – string of Node Name

  • include_nodes – list of node name strings

  • include_links – list of link name strings

Returns:

Network Path Trace Tuple

swmmio.utils.functions.format_inp_section_header(string)[source]#

Ensure a string is in the inp section header format: [UPPERCASE], except in the case of the [Polygons] section with is capitalized case :param string: :return: string

swmmio.utils.functions.merge_dicts(*dict_args)[source]#

Given any number of dicts, shallow copy and merge into a new dict, precedence goes to key value pairs in latter dicts.

swmmio.utils.functions.model_to_networkx(model, drop_cycles=True)[source]#

Networkx MultiDiGraph representation of the model

swmmio.utils.functions.random_alphanumeric(n=6)[source]#
swmmio.utils.functions.remove_braces(string)[source]#
swmmio.utils.functions.rotate_model(m, rads=0.5, origin=None)[source]#

Rotate a model’s coordinates by a specified angle around a given origin.

Parameters:
mswmmio.Model

The model whose coordinates are to be rotated.

radsfloat, optional

The angle in radians by which to rotate the model. Default is 0.5 radians.

origintuple of float, optional

The (x, y) coordinates of the point around which to rotate the model. If not provided, the origin defaults to (0, 0).

Returns:
swmmio.Model

The model with its coordinates rotated.

Examples

>>> from swmmio.tests.data import MODEL_FULL_FEATURES_XY_B
>>> import swmmio
>>> mb = swmmio.Model(MODEL_FULL_FEATURES_XY_B)
>>> mc = rotate_model(mb, rads=0.75, origin=(2748515.571, 1117763.466))
>>> mc.inp.coordinates
swmmio.utils.functions.summarize_model(model) dict[source]#

Summarize a SWMM model by calculating various statistics and counts of elements.

Parameters:
modelswmmio.core.Model

An instance of a SWMM model containing input data (inp) and nodes.

Returns:
dict

A dictionary containing the summary of the model with the following keys:

  • ‘num_subcatchments’: int, number of subcatchments in the model.

  • ‘num_conduits’: int, number of conduits in the model.

  • ‘num_junctions’: int, number of junctions in the model.

  • ‘num_outfalls’: int, number of outfalls in the model.

  • ‘num_raingages’: int, number of raingages in the model.

  • ‘catchment_area’: float, total area of subcatchments (if subcatchments exist).

  • ‘mean_subcatchment_slope’: float, mean slope of subcatchments weighted by area (if subcatchments exist).

  • ‘total_conduit_length’: float, total length of conduits (if conduits exist).

  • ‘invert_range’: float, range of invert elevations of nodes (if nodes exist).

swmmio.utils.functions.trace_from_node(conduits, startnode, mode='up', stopnode=None)[source]#

trace up and down a SWMM model given a start node and optionally a stop node.

swmmio.utils.functions.trim_section_to_nodes(inp, node_ids=None, node_type='junctions', drop=True)[source]#