wntr.network.base module

The wntr.network.base module includes base classes for network elements and the network model.

Contents

AbstractModel Base class for water network models.
Subject() Base class for the subject in an observer design pattern.
Observer Base class for the observer in an observer design pattern.
Node(wn, name) Base class for nodes.
Link(wn, link_name, start_node_name, …) Base class for links.
Registry(wn) Base class for registries.
NodeType(val) Enum class for node types.
LinkType(val) Enum class for link types.
LinkStatus(val) Enum class for link statuses.
class wntr.network.base.AbstractModel[source]

Bases: object

Base class for water network models.

class wntr.network.base.Subject[source]

Bases: object

Base class for the subject in an observer design pattern.

Methods

notify  
subscribe  
unsubscribe  
class wntr.network.base.Observer[source]

Bases: object

Base class for the observer in an observer design pattern.

Methods

update  
class wntr.network.base.Node(wn, name)[source]

Bases: object

Base class for nodes.

For details about the different subclasses, see one of the following: Junction, Tank, and Reservoir

Parameters:
wn : WaterNetworkModel

WaterNetworkModel object

name : string

Name of the node (must be unique among nodes of all types)

Attributes:
coordinates

tuple: The node coordinates, (x,y)

demand

float: The current demand at the node

head

float: The current head at the node

initial_quality

float: The initial quality (concentration) at the node

leak_area

float: The leak area at the node

leak_demand

float: The current demand at the node

leak_discharge_coeff

float: The leak discharge coefficient

leak_status

bool: The current leak status at the node

name

str: The name of the node

node_type

str: The node type

tag

str: A tag or label for the node

Methods

todict() Dictionary representation of the node
head

float: The current head at the node

demand

float: The current demand at the node

leak_demand

float: The current demand at the node

leak_status

bool: The current leak status at the node

leak_area

float: The leak area at the node

leak_discharge_coeff

float: The leak discharge coefficient

node_type

str: The node type

name

str: The name of the node

tag

str: A tag or label for the node

initial_quality

float: The initial quality (concentration) at the node

coordinates

tuple: The node coordinates, (x,y)

todict()[source]

Dictionary representation of the node

Bases: object

Base class for links.

For details about the different subclasses, see one of the following: Pipe, Pump, and Valve

Parameters:
wn : WaterNetworkModel

WaterNetworkModel object

link_name : string

Name of the link

start_node_name : string

Name of the start node

end_node_name : string

Name of the end node

Attributes:
end_node

Node: The end node object.

end_node_name

str: The name of the end node (read only)

flow

float: Current flow through the link (read only)

initial_setting

float: The initial setting for the link (if Active)

initial_status

LinkStatus: The initial status (Opened, Closed, Active) of the Link

link_type

str: The link type

name

str: The link name (read-only)

setting

float: The current setting of the link

start_node

Node: The start node object.

start_node_name

str: The name of the start node (read only)

status

LinkStatus: Current status of the link

tag

str: A tag or label for this link

vertices

A list of curve points, in the direction of start node to end node.

Methods

todict() Dictionary representation of the link

str: The link type

initial_status

LinkStatus: The initial status (Opened, Closed, Active) of the Link

initial_setting

float: The initial setting for the link (if Active)

start_node

Node: The start node object.

end_node

Node: The end node object.

start_node_name

str: The name of the start node (read only)

end_node_name

str: The name of the end node (read only)

name

str: The link name (read-only)

flow

float: Current flow through the link (read only)

status

LinkStatus: Current status of the link

setting

float: The current setting of the link

tag

str: A tag or label for this link

vertices

A list of curve points, in the direction of start node to end node.

The vertices should be listed as a list of (x,y) tuples when setting.

todict()[source]

Dictionary representation of the link

class wntr.network.base.Registry(wn)[source]

Bases: _abcoll.MutableMapping

Base class for registries.

Parameters:
wn : WaterNetworkModel

WaterNetworkModel object

Methods

add_usage(key, *args) add args to usage[key]
clear()
clear_usage(key) if key in usage, clear usage[key]
get(k[,d])
get_usage(key) Get a set of items using an object by key.
items()
iteritems()
iterkeys()
itervalues()
keys()
orphaned() Get a list of orphaned usages.
pop(k[,d]) If key is not found, d is returned if given, otherwise KeyError is raised.
popitem() as a 2-tuple; but raise KeyError if D is empty.
remove_usage(key, *args) remove args from usage[key]
setdefault(k[,d])
todict() Dictionary representation of the registry
tolist() List representation of the registry
unused() Get a list of items which are unused by other objects in the model.
update([E, ]**F) If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
usage() Generator to get the usage for all objects in the registry
values()
__call__  
usage()[source]

Generator to get the usage for all objects in the registry

Yields:
key : str

The name of the object in the registry

value : tuple of (str, str)

Tuple of (name, typestr) of the external items using the object

get_usage(key)[source]

Get a set of items using an object by key.

Returns:
set of 2-tuples

Set of (name, typestr) of the external object using the item

orphaned()[source]

Get a list of orphaned usages.

If removed without appropriate checks, it is possible that a some other item will point to an object that has been deleted. (This is why the user should always use the “remove_*” methods). This method returns a list of names for objects that are referenced, but no longer exist.

Returns:
set

The names of any orphaned items

unused()[source]

Get a list of items which are unused by other objects in the model.

In most cases, this method will give little information. For nodes, however, this method could be important to identify a node which has become completely disconnected from the network. For patterns or curves, it may be used to find extra patterns or curves that are no longer necessary (or which the user forgot ot assign). It is not terribly useful for links.

Returns:
set

The names of any unused objects in the registry

clear_usage(key)[source]

if key in usage, clear usage[key]

add_usage(key, *args)[source]

add args to usage[key]

remove_usage(key, *args)[source]

remove args from usage[key]

todict()[source]

Dictionary representation of the registry

tolist()[source]

List representation of the registry

clear() → None. Remove all items from D.
get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → list of D's (key, value) pairs, as 2-tuples
iteritems() → an iterator over the (key, value) items of D
iterkeys() → an iterator over the keys of D
itervalues() → an iterator over the values of D
keys() → list of D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → list of D's values
class wntr.network.base.NodeType(val)[source]

Bases: enum.IntEnum

Enum class for node types.

Enum Members

Junction Node is a Junction
Reservoir Node is a Reservoir
Tank Node is a Tank
class wntr.network.base.LinkType(val)[source]

Bases: enum.IntEnum

Enum class for link types.

Enum Members

CV Pipe with check valve
Pipe Regular pipe
Pump Pump
Valve Any valve type (see following)
PRV Pressure reducing valve
PSV Pressure sustaining valve
PBV Pressure breaker valve
FCV Flow control valve
TCV Throttle control valve
GPV General purpose valve
class wntr.network.base.LinkStatus(val)[source]

Bases: enum.IntEnum

Enum class for link statuses.

Warning

This is NOT the class for determining output status from an EPANET binary file. The class for output status is wntr.epanet.util.LinkTankStatus.

Enum Members

Closed Pipe/valve/pump is closed.
Opened Pipe/valve/pump is open.
Open Alias to “Opened”
Active Valve is partially open.