wntr.network.model module

The wntr.network.model module includes methods to build a water network model.

Contents

WaterNetworkModel([inp_file_name]) Water network model class.
PatternRegistry(wn)

Attributes

CurveRegistry(model)

Attributes

SourceRegistry(wn) A registry for sources
NodeRegistry(model) The registry containing the model’s nodes
LinkRegistry(model)

Attributes

class wntr.network.model.WaterNetworkModel(inp_file_name=None)[source]

Bases: wntr.network.base.AbstractModel

Water network model class.

Parameters:

inp_file_name: string (optional)

Directory and filename of EPANET inp file to load into the WaterNetworkModel object.

Attributes

control_name_list Get a list of control/rule names
curve_name_list Get a list of curve names
curves The curve registry (as property) or a generator for iteration (as function call)
fcvs Iterator over all flow control valves (FCVs)
gpvs Iterator over all general purpose valves (GPVs)
head_pumps Iterator over all head-based pumps
junction_name_list Get a list of junction names
junctions Iterator over all junctions
link_name_list Get a list of link names
links The link registry (as property) or a generator for iteration (as function call)
node_name_list Get a list of node names
nodes The node registry (as property) or a generator for iteration (as function call)
num_controls The number of controls
num_curves The number of curves
num_junctions The number of junctions
num_links The number of links
num_nodes The number of nodes
num_patterns The number of patterns
num_pipes The number of pipes
num_pumps The number of pumps
num_reservoirs The number of reservoirs
num_sources The number of sources
num_tanks The number of tanks
num_valves The number of valves
options The model’s options object
pattern_name_list Get a list of pattern names
patterns The pattern registry (as property) or a generator for iteration (as function call)
pbvs Iterator over all pressure breaker valves (PBVs)
pipe_name_list Get a list of pipe names
pipes Iterator over all pipes
power_pumps Iterator over all power pumps
prvs Iterator over all pressure reducing valves (PRVs)
psvs Iterator over all pressure sustaining valves (PSVs)
pump_name_list Get a list of pump names (both types included)
pumps Iterator over all pumps
reservoir_name_list Get a list of reservoir names
reservoirs Iterator over all reservoirs
source_name_list Get a list of source names
tank_name_list Get a list of tanks names
tanks Iterator over all tanks
tcvs Iterator over all throttle control valves (TCVs)
valve_name_list Get a list of valve names (all types included)
valves Iterator over all valves

Methods

add_control(name, control_object) Adds a control to the water network model
add_curve(name, curve_type, xy_tuples_list) Adds a curve to the water network model
add_junction(name[, base_demand, …]) Adds a junction to the water network model
add_pattern(name[, pattern]) Adds a pattern to the water network model
add_pipe(name, start_node_name, end_node_name) Adds a pipe to the water network model
add_pump(name, start_node_name, end_node_name) Adds a pump to the water network model
add_reservoir(name[, base_head, …]) Adds a reservoir to the water network model
add_source(name, node_name, source_type, quality) Adds a source to the water network model
add_tank(name[, elevation, init_level, …]) Adds a tank to the water network model
add_valve(name, start_node_name, end_node_name) Adds a valve to the water network model
assign_demand(demand[, pattern_prefix]) Assign demands using values in a DataFrame.
controls() Returns a generator to iterate over all controls
get_control(name) Get a specific control
get_curve(name) Get a specific curve
get_graph() Returns a networkx graph of the water network model
get_link(name) Get a specific link
get_links_for_node(node_name[, flag]) Returns a list of links connected to a node
get_node(name) Get a specific node
get_pattern(name) Get a specific pattern
get_source(name) Get a specific source
query_link_attribute(attribute[, operation, …]) Query link attributes, for example get all pipe diameters > threshold
query_node_attribute(attribute[, operation, …]) Query node attributes, for example get all nodes with elevation <= threshold
read_inpfile(filename) Defines water network model components from an EPANET INP file
remove_control(name) Removes a control from the water network model
remove_curve(name) Removes a curve from the water network model
remove_link(name[, with_control]) Removes a link from the water network model
remove_node(name[, with_control]) Removes a node from the water network model
remove_pattern(name) Removes a pattern from the water network model
remove_source(name) Removes a source from the water network model
reset_initial_values() Resets all initial values in the network
scale_node_coordinates(scale) Scales node coordinates, using 1:scale (scale should be in meters)
sources() Returns a generator to iterate over all sources
split_pipe(pipe_name_to_split, …[, …]) Splits a pipe by adding a junction and one new pipe segment
todict() Dictionary representation of the water network model
write_inpfile(filename[, units]) Writes the current water network model to an EPANET INP file
options

The model’s options object

Returns:WaterNetworkOptions
nodes

The node registry (as property) or a generator for iteration (as function call)

Returns:NodeRegistry

The link registry (as property) or a generator for iteration (as function call)

Returns:LinkRegistry
patterns

The pattern registry (as property) or a generator for iteration (as function call)

Returns:PatternRegistry
curves

The curve registry (as property) or a generator for iteration (as function call)

Returns:CurveRegistry
sources()[source]

Returns a generator to iterate over all sources

Returns:A generator in the format (name, object).
controls()[source]

Returns a generator to iterate over all controls

Returns:A generator in the format (name, object).
junctions

Iterator over all junctions

tanks

Iterator over all tanks

reservoirs

Iterator over all reservoirs

pipes

Iterator over all pipes

pumps

Iterator over all pumps

valves

Iterator over all valves

head_pumps

Iterator over all head-based pumps

power_pumps

Iterator over all power pumps

prvs

Iterator over all pressure reducing valves (PRVs)

psvs

Iterator over all pressure sustaining valves (PSVs)

pbvs

Iterator over all pressure breaker valves (PBVs)

tcvs

Iterator over all throttle control valves (TCVs)

fcvs

Iterator over all flow control valves (FCVs)

gpvs

Iterator over all general purpose valves (GPVs)

add_junction(name, base_demand=0.0, demand_pattern=None, elevation=0.0, coordinates=None, demand_category=None)[source]

Adds a junction to the water network model

Parameters:

name : string

Name of the junction.

base_demand : float

Base demand at the junction.

demand_pattern : string or Pattern

Name of the demand pattern or the actual Pattern object

elevation : float

Elevation of the junction.

coordinates : tuple of floats

X-Y coordinates of the node location.

demand_category : string

Name of the demand category

add_tank(name, elevation=0.0, init_level=3.048, min_level=0.0, max_level=6.096, diameter=15.24, min_vol=None, vol_curve=None, coordinates=None)[source]

Adds a tank to the water network model

Parameters:

name : string

Name of the tank.

elevation : float

Elevation at the Tank.

init_level : float

Initial tank level.

min_level : float

Minimum tank level.

max_level : float

Maximum tank level.

diameter : float

Tank diameter.

min_vol : float

Minimum tank volume.

vol_curve : str

Name of a volume curve (optional)

coordinates : tuple of floats

X-Y coordinates of the node location.

Raises:

ValueError

If init_level greater than max_level or less than min_level

add_reservoir(name, base_head=0.0, head_pattern=None, coordinates=None)[source]

Adds a reservoir to the water network model

Parameters:

name : string

Name of the reservoir.

base_head : float, optional

Base head at the reservoir.

head_pattern : string

Name of the head pattern (optional)

coordinates : tuple of floats, optional

X-Y coordinates of the node location.

add_pipe(name, start_node_name, end_node_name, length=304.8, diameter=0.3048, roughness=100, minor_loss=0.0, status='OPEN', check_valve_flag=False)[source]

Adds a pipe to the water network model

Parameters:

name : string

Name of the pipe.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

length : float, optional

Length of the pipe.

diameter : float, optional

Diameter of the pipe.

roughness : float, optional

Pipe roughness coefficient.

minor_loss : float, optional

Pipe minor loss coefficient.

status : string, optional

Pipe status. Options are ‘Open’ or ‘Closed’.

check_valve_flag : bool, optional

True if the pipe has a check valve. False if the pipe does not have a check valve.

add_pump(name, start_node_name, end_node_name, pump_type='POWER', pump_parameter=50.0, speed=1.0, pattern=None)[source]

Adds a pump to the water network model

Parameters:

name : string

Name of the pump.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

pump_type : string, optional

Type of information provided for a pump. Options are ‘POWER’ or ‘HEAD’.

pump_parameter : float or str object

Float value of power in KW. Head curve name.

speed: float

Relative speed setting (1.0 is normal speed)

pattern: str

ID of pattern for speed setting

add_valve(name, start_node_name, end_node_name, diameter=0.3048, valve_type='PRV', minor_loss=0.0, setting=0.0)[source]

Adds a valve to the water network model

Parameters:

name : string

Name of the valve.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

diameter : float, optional

Diameter of the valve.

valve_type : string, optional

Type of valve. Options are ‘PRV’, etc.

minor_loss : float, optional

Pipe minor loss coefficient.

setting : float or string, optional

pressure setting for PRV, PSV, or PBV, flow setting for FCV, loss coefficient for TCV, name of headloss curve for GPV.

add_pattern(name, pattern=None)[source]

Adds a pattern to the water network model

The pattern can be either a list of values (list, numpy array, etc.) or a Pattern object. The Pattern class has options to automatically create certain types of patterns, such as a single, on/off pattern (previously created using the start_time and stop_time arguments to this function) – see the class documentation for examples.

Warning

Patterns must be added to the model prior to adding any model element that uses the pattern, such as junction demands, sources, etc. Patterns are linked by reference, so changes to a pattern affects all elements using that pattern.

Warning

Patterns always use the global water network model options.time values. Patterns will not be resampled to match these values, it is assumed that patterns created using Pattern(…) or Pattern.binary_pattern(…) object used the same pattern timestep value as the global value, and they will be treated accordingly.

Parameters:

name : string

Name of the pattern.

pattern : list of floats or Pattern

A list of floats that make up the pattern, or a Pattern object.

Raises:

ValueError

If adding a pattern with name that already exists.

add_curve(name, curve_type, xy_tuples_list)[source]

Adds a curve to the water network model

Parameters:

name : string

Name of the curve.

curve_type : string

Type of curve. Options are HEAD, EFFICIENCY, VOLUME, HEADLOSS.

xy_tuples_list : list of (x, y) tuples

List of X-Y coordinate tuples on the curve.

add_source(name, node_name, source_type, quality, pattern=None)[source]

Adds a source to the water network model

Parameters:

name : string

Name of the source

node_name: string

Injection node.

source_type: string

Source type, options = CONCEN, MASS, FLOWPACED, or SETPOINT

quality: float

Source strength in Mass/Time for MASS and Mass/Volume for CONCEN, FLOWPACED, or SETPOINT

pattern: string or Pattern object

Pattern name or object

add_control(name, control_object)[source]

Adds a control to the water network model

Parameters:

name : string

control object name.

control_object : Control object

Control object.

remove_node(name, with_control=False)[source]

Removes a node from the water network model

Removes a link from the water network model

remove_pattern(name)[source]

Removes a pattern from the water network model

remove_curve(name)[source]

Removes a curve from the water network model

remove_source(name)[source]

Removes a source from the water network model

Parameters:

name : string

The name of the source object to be removed

remove_control(name)[source]

Removes a control from the water network model

get_node(name)[source]

Get a specific node

Parameters:

name : str

The node name

Returns:

Junction, Tank, or Reservoir

Get a specific link

Parameters:

name : str

The link name

Returns:

Pipe, Pump, or Valve

get_pattern(name)[source]

Get a specific pattern

Parameters:

name : str

The pattern name

Returns:

Pattern

get_curve(name)[source]

Get a specific curve

Parameters:

name : str

The curve name

Returns:

Curve

get_source(name)[source]

Get a specific source

Parameters:

name : str

The source name

Returns:

Source

get_control(name)[source]

Get a specific control

Parameters:

name : str

The control name

Returns:

Control

node_name_list

Get a list of node names

Returns:list of strings
junction_name_list

Get a list of junction names

Returns:list of strings
tank_name_list

Get a list of tanks names

Returns:list of strings
reservoir_name_list

Get a list of reservoir names

Returns:list of strings

Get a list of link names

Returns:list of strings
pipe_name_list

Get a list of pipe names

Returns:list of strings
pump_name_list

Get a list of pump names (both types included)

Returns:list of strings
valve_name_list

Get a list of valve names (all types included)

Returns:list of strings
pattern_name_list

Get a list of pattern names

Returns:list of strings
curve_name_list

Get a list of curve names

Returns:list of strings
source_name_list

Get a list of source names

Returns:list of strings
control_name_list

Get a list of control/rule names

Returns:list of strings
num_nodes

The number of nodes

num_junctions

The number of junctions

num_tanks

The number of tanks

num_reservoirs

The number of reservoirs

The number of links

num_pipes

The number of pipes

num_pumps

The number of pumps

num_valves

The number of valves

num_patterns

The number of patterns

num_curves

The number of curves

num_sources

The number of sources

num_controls

The number of controls

todict()[source]

Dictionary representation of the water network model

get_graph()[source]

Returns a networkx graph of the water network model

Returns:WaterNetworkModel networkx graph.
assign_demand(demand, pattern_prefix='ResetDemand')[source]

Assign demands using values in a DataFrame.

New demands are specified in a pandas DataFrame indexed by simulation time (in seconds) and one column for each node. The method resets node demands by creating a new demand pattern for each node and resetting the base demand to 1. The demand pattern is resampled to match the water network model pattern timestep. This method can be used to reset demands in a water network model to demands from a pressure dependent demand simulation.

Parameters:

demand : pandas DataFrame

A pandas DataFrame containing demands (index = time, columns = node names)

pattern_prefix: string

Pattern prefix, default = ‘ResetDemand’

Returns a list of links connected to a node

Parameters:

node_name : string

Name of the node.

flag : string

Options are ‘ALL’, ‘INLET’, ‘OUTLET’. ‘ALL’ returns all links connected to the node. ‘INLET’ returns links that have the specified node as an end node. ‘OUTLET’ returns links that have the specified node as a start node.

Returns:

A list of link names connected to the node

query_node_attribute(attribute, operation=None, value=None, node_type=None)[source]

Query node attributes, for example get all nodes with elevation <= threshold

Parameters:

attribute: string

Node attribute.

operation: numpy operator

Numpy operator, options include np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal.

value: float or int

Threshold

node_type: Node type

Node type, options include wntr.network.model.Node, wntr.network.model.Junction, wntr.network.model.Reservoir, wntr.network.model.Tank, or None. Default = None. Note None and wntr.network.model.Node produce the same results.

Returns:

A dictionary of node names to attribute where node_type satisfies the

operation threshold.

Notes

If operation and value are both None, the dictionary will contain the attributes for all nodes with the specified attribute.

Query link attributes, for example get all pipe diameters > threshold

Parameters:

attribute: string

Link attribute

operation: numpy operator

Numpy operator, options include np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal.

value: float or int

Threshold

link_type: Link type

Link type, options include wntr.network.model.Link, wntr.network.model.Pipe, wntr.network.model.Pump, wntr.network.model.Valve, or None. Default = None. Note None and wntr.network.model.Link produce the same results.

Returns:

A dictionary of link names to attributes where link_type satisfies the

operation threshold.

Notes

If operation and value are both None, the dictionary will contain the attributes for all links with the specified attribute.

reset_initial_values()[source]

Resets all initial values in the network

read_inpfile(filename)[source]

Defines water network model components from an EPANET INP file

Parameters:

filename : string

Name of the INP file.

write_inpfile(filename, units=None)[source]

Writes the current water network model to an EPANET INP file

Parameters:

filename : string

Name of the inp file.

units : str, int or FlowUnits

Name of the units being written to the inp file.

scale_node_coordinates(scale)[source]

Scales node coordinates, using 1:scale (scale should be in meters)

Parameters:

scale : float

Coordinate scale multiplier.

split_pipe(pipe_name_to_split, new_pipe_name, new_junction_name, add_pipe_at_node='end', split_at_point=0.5)[source]

Splits a pipe by adding a junction and one new pipe segment

This method is convenient when adding leaks to a pipe. It provides an initially zero-demand node at some point along the pipe and then reconnects the original pipe to this node and adds a new pipe to the other side. Hydraulic paths are maintained. The new junction can then have a leak added to it.

It is important to note that check valves are not added to the new pipe. By allowing the new pipe to be connected at either the start or the end of the old pipe, this allows the split to occur before or after the check valve. Additionally, no controls will be added to the new pipe; the old pipe will keep any controls. Again, this allows the split to occur before or after a “valve” that is controlled by opening or closing a pipe.

This method keeps ‘pipe_name_to_split’, resizes it, and adds a new pipe to keep total length equal. The pipe will be split at a new junction placed at a point ‘split_at_point’ of the way between the start and end (in that direction). The new pipe can be added to ‘add_pipe_at_node’ of either start or end. For example, if add_pipe_at_node='start', then the original pipe will go from the new junction to the original end node, and the new pipe will go from the original start node to the new junction.

The new pipe will have the same diameter, roughness, minor loss, and base status of the original pipe. The new junction will have a base demand of 0, an elevation equal to the ‘split_at_point’ x 100% of the elevation between the original start and end nodes, coordinates at ‘split_at_point’ between the original start and end nodes, and will use the default demand pattern.

Parameters:

pipe_name_to_split: string

The name of the pipe to split.

new_pipe_name: string

The name of the new pipe to be added as the split part of the pipe.

new_junction_name: string

The name of the new junction to be added.

add_pipe_at_node: string

Either ‘start’ or ‘end’, ‘end’ is default. The new pipe goes between this original node and the new junction.

split_at_point: float

Between 0 and 1, the position along the original pipe where the new junction will be located.

Returns:

tuple

returns (original_pipe, new_junction, new_pipe) objects

Raises:

ValueError

The link is not a pipe, split_at_point is out of bounds, add_pipe_at_node is invalid.

RuntimeError

The new_junction_name or new_pipe_name is already in use.

class wntr.network.model.PatternRegistry(wn)[source]

Bases: wntr.network.base.Registry

Attributes

default_pattern A new default pattern object

Methods

DefaultPattern(options) An object that always points to the current default pattern for a model
__call__(…) <==> x(…)
add_pattern(name[, pattern]) Adds a pattern to the water network model.
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]
usage() Generator to get the usage for all objects in the registry
values()
class DefaultPattern(options)[source]

Bases: object

An object that always points to the current default pattern for a model

Attributes

name The name of the default pattern, or None if no pattern is assigned
name

The name of the default pattern, or None if no pattern is assigned

add_pattern(name, pattern=None)[source]

Adds a pattern to the water network model.

The pattern can be either a list of values (list, numpy array, etc.) or a Pattern object. The Pattern class has options to automatically create certain types of patterns, such as a single, on/off pattern

Warning

Patterns must be added to the model prior to adding any model element that uses the pattern, such as junction demands, sources, etc. Patterns are linked by reference, so changes to a pattern affects all elements using that pattern.

Warning

Patterns always use the global water network model options.time values. Patterns will not be resampled to match these values, it is assumed that patterns created using Pattern(…) or Pattern.binary_pattern(…) object used the same pattern timestep value as the global value, and they will be treated accordingly.

Parameters:

name : string

Name of the pattern.

pattern : list of floats or Pattern

A list of floats that make up the pattern, or a Pattern object.

Raises:

ValueError

If adding a pattern with name that already exists.

default_pattern

A new default pattern object

add_usage(key, *args)

add args to usage[key]

clear() → None. Remove all items from D.
clear_usage(key)

if key in usage, clear usage[key]

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_usage(key)

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

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
orphaned()

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

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.

remove_usage(key, *args)

remove args from usage[key]

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in 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.

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

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

usage()

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

values() → list of D's values
class wntr.network.model.CurveRegistry(model)[source]

Bases: wntr.network.base.Registry

Attributes

efficiency_curve_names List of names of all efficiency curves
headloss_curve_names List of names of all headloss curves
pump_curve_names List of names of all pump curves
untyped_curve_names List of names of all curves without types
volume_curve_names List of names of all volume curves

Methods

__call__(…) <==> x(…)
add_curve(name, curve_type, xy_tuples_list) Adds a curve to the water network model.
add_usage(key, *args) add args to usage[key]
clear()
clear_usage(key) if key in usage, clear usage[key]
efficiency_curves() Generator to get all efficiency curves
get(k[,d])
get_usage(key) Get a set of items using an object by key.
headloss_curves() Generator to get all headloss curves
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.
pump_curves() Generator to get all pump curves
remove_usage(key, *args) remove args from usage[key]
set_curve_type(key, curve_type) WARNING – does not check to make sure key is typed before assigning it - you could end up
setdefault(k[,d])
todict() Dictionary representation of the registry
tolist() List representation of the registry
untyped_curves() Generator to get all curves without type
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]
usage() Generator to get the usage for all objects in the registry
values()
volume_curves() Generator to get all volume curves
set_curve_type(key, curve_type)[source]

WARNING – does not check to make sure key is typed before assigning it - you could end up with a curve that is used for more than one type, which would be really weird

add_curve(name, curve_type, xy_tuples_list)[source]

Adds a curve to the water network model.

Parameters:

name : string

Name of the curve.

curve_type : string

Type of curve. Options are HEAD, EFFICIENCY, VOLUME, HEADLOSS.

xy_tuples_list : list of (x, y) tuples

List of X-Y coordinate tuples on the curve.

untyped_curves()[source]

Generator to get all curves without type

Yields:

name : str

The name of the curve

curve : Curve

The untyped curve object

untyped_curve_names

List of names of all curves without types

pump_curves()[source]

Generator to get all pump curves

Yields:

name : str

The name of the curve

curve : Curve

The pump curve object

pump_curve_names

List of names of all pump curves

efficiency_curves()[source]

Generator to get all efficiency curves

Yields:

name : str

The name of the curve

curve : Curve

The efficiency curve object

efficiency_curve_names

List of names of all efficiency curves

headloss_curves()[source]

Generator to get all headloss curves

Yields:

name : str

The name of the curve

curve : Curve

The headloss curve object

headloss_curve_names

List of names of all headloss curves

volume_curves()[source]

Generator to get all volume curves

Yields:

name : str

The name of the curve

curve : Curve

The volume curve object

volume_curve_names

List of names of all volume curves

add_usage(key, *args)

add args to usage[key]

clear() → None. Remove all items from D.
clear_usage(key)

if key in usage, clear usage[key]

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_usage(key)

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

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
orphaned()

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

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.

remove_usage(key, *args)

remove args from usage[key]

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in 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.

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

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

usage()

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

values() → list of D's values
class wntr.network.model.SourceRegistry(wn)[source]

Bases: wntr.network.base.Registry

A registry for sources

Methods

__call__(…) <==> x(…)
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]
usage() Generator to get the usage for all objects in the registry
values()
add_usage(key, *args)

add args to usage[key]

clear() → None. Remove all items from D.
clear_usage(key)

if key in usage, clear usage[key]

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_usage(key)

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

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
orphaned()

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

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.

remove_usage(key, *args)

remove args from usage[key]

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in 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.

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

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

usage()

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

values() → list of D's values
class wntr.network.model.NodeRegistry(model)[source]

Bases: wntr.network.base.Registry

The registry containing the model’s nodes

Attributes

junction_names List of names of all junctions
reservoir_names List of names of all junctions
tank_names List of names of all junctions

Methods

__call__([node_type]) Returns a generator to iterate over all nodes of a specific node type.
add_junction(name[, base_demand, …]) Adds a junction to the water network model.
add_reservoir(name[, base_head, …]) Adds a reservoir to the water network model.
add_tank(name[, elevation, init_level, …]) Adds a tank to the water network model.
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()
junctions() Generator to get all junctions
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]
reservoirs() Generator to get all reservoirs
setdefault(k[,d])
tanks() Generator to get all tanks
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]
usage() Generator to get the usage for all objects in the registry
values()
add_junction(name, base_demand=0.0, demand_pattern=None, elevation=0.0, coordinates=None, demand_category=None)[source]

Adds a junction to the water network model.

Parameters:

name : string

Name of the junction.

base_demand : float

Base demand at the junction.

demand_pattern : string or Pattern

Name of the demand pattern or the actual Pattern object

elevation : float

Elevation of the junction.

coordinates : tuple of floats

X-Y coordinates of the node location.

add_tank(name, elevation=0.0, init_level=3.048, min_level=0.0, max_level=6.096, diameter=15.24, min_vol=None, vol_curve=None, coordinates=None)[source]

Adds a tank to the water network model.

Parameters:

name : string

Name of the tank.

elevation : float

Elevation at the Tank.

init_level : float

Initial tank level.

min_level : float

Minimum tank level.

max_level : float

Maximum tank level.

diameter : float

Tank diameter.

min_vol : float

Minimum tank volume.

vol_curve : str

Name of a volume curve (optional)

coordinates : tuple of floats

X-Y coordinates of the node location.

Raises:

ValueError

If init_level greater than max_level or less than min_level

add_reservoir(name, base_head=0.0, head_pattern=None, coordinates=None)[source]

Adds a reservoir to the water network model.

Parameters:

name : string

Name of the reservoir.

base_head : float, optional

Base head at the reservoir.

head_pattern : string

Name of the head pattern (optional)

coordinates : tuple of floats, optional

X-Y coordinates of the node location.

junction_names

List of names of all junctions

tank_names

List of names of all junctions

reservoir_names

List of names of all junctions

junctions()[source]

Generator to get all junctions

Yields:

name : str

The name of the junction

node : Junction

The junction object

tanks()[source]

Generator to get all tanks

Yields:

name : str

The name of the tank

node : Tank

The tank object

reservoirs()[source]

Generator to get all reservoirs

Yields:

name : str

The name of the reservoir

node : Reservoir

The reservoir object

add_usage(key, *args)

add args to usage[key]

clear() → None. Remove all items from D.
clear_usage(key)

if key in usage, clear usage[key]

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_usage(key)

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

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
orphaned()

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

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.

remove_usage(key, *args)

remove args from usage[key]

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in 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.

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

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

usage()

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

values() → list of D's values
class wntr.network.model.LinkRegistry(model)[source]

Bases: wntr.network.base.Registry

Attributes

pipe_names A list of all pipe names
pump_names A list of all pump names
valve_names A list of all valve names

Methods

__call__([link_type]) Returns a generator to iterate over all nodes of a specific node type.
add_pipe(name, start_node_name, end_node_name) Adds a pipe to the water network model.
add_pump(name, start_node_name, end_node_name) Adds a pump to the water network model.
add_usage(key, *args) add args to usage[key]
add_valve(name, start_node_name, end_node_name) Adds a valve to the water network model.
check_valves() Generator to get all pipes with check valves
clear()
clear_usage(key) if key in usage, clear usage[key]
fcvs() Generator to get all FCVs
get(k[,d])
get_usage(key) Get a set of items using an object by key.
gpvs() Generator to get all GPVs
head_pumps() Generator to get all head pumps
items()
iteritems()
iterkeys()
itervalues()
keys()
orphaned() Get a list of orphaned usages.
pbvs() Generator to get all PBVs
pipes() Generator to get all pipes
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.
power_pumps() Generator to get all power pumps
prvs() Generator to get all PRVs
psvs() Generator to get all PSVs
pumps() Generator to get all pumps
remove_usage(key, *args) remove args from usage[key]
setdefault(k[,d])
tcvs() Generator to get all TCVs
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]
usage() Generator to get the usage for all objects in the registry
values()
valves() Generator to get all valves
add_pipe(name, start_node_name, end_node_name, length=304.8, diameter=0.3048, roughness=100, minor_loss=0.0, status='OPEN', check_valve_flag=False)[source]

Adds a pipe to the water network model.

Parameters:

name : string

Name of the pipe.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

length : float, optional

Length of the pipe.

diameter : float, optional

Diameter of the pipe.

roughness : float, optional

Pipe roughness coefficient.

minor_loss : float, optional

Pipe minor loss coefficient.

status : string, optional

Pipe status. Options are ‘Open’ or ‘Closed’.

check_valve_flag : bool, optional

True if the pipe has a check valve. False if the pipe does not have a check valve.

add_pump(name, start_node_name, end_node_name, pump_type='POWER', pump_parameter=50.0, speed=1.0, pattern=None)[source]

Adds a pump to the water network model.

Parameters:

name : string

Name of the pump.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

pump_type : string, optional

Type of information provided for a pump. Options are ‘POWER’ or ‘HEAD’.

pump_parameter : float or str object

Float value of power in KW. Head curve name.

speed: float

Relative speed setting (1.0 is normal speed)

pattern: str

ID of pattern for speed setting

add_valve(name, start_node_name, end_node_name, diameter=0.3048, valve_type='PRV', minor_loss=0.0, setting=0.0)[source]

Adds a valve to the water network model.

Parameters:

name : string

Name of the valve.

start_node_name : string

Name of the start node.

end_node_name : string

Name of the end node.

diameter : float, optional

Diameter of the valve.

valve_type : string, optional

Type of valve. Options are ‘PRV’, etc.

minor_loss : float, optional

Pipe minor loss coefficient.

setting : float or string, optional

pressure setting for PRV, PSV, or PBV, flow setting for FCV, loss coefficient for TCV, name of headloss curve for GPV.

check_valves()[source]

Generator to get all pipes with check valves

Yields:

name : str

The name of the pipe

link : Pipe

The pipe object

pipe_names

A list of all pipe names

valve_names

A list of all valve names

pump_names

A list of all pump names

pipes()[source]

Generator to get all pipes

Yields:

name : str

The name of the pipe

link : Pipe

The pipe object

pumps()[source]

Generator to get all pumps

Yields:

name : str

The name of the pump

link : Pump

The pump object

valves()[source]

Generator to get all valves

Yields:

name : str

The name of the valve

link : Valve

The valve object

head_pumps()[source]

Generator to get all head pumps

Yields:

name : str

The name of the pump

link : HeadPump

The pump object

power_pumps()[source]

Generator to get all power pumps

Yields:

name : str

The name of the pump

link : PowerPump

The pump object

prvs()[source]

Generator to get all PRVs

Yields:

name : str

The name of the valve

link : PRValve

The valve object

psvs()[source]

Generator to get all PSVs

Yields:

name : str

The name of the valve

link : PSValve

The valve object

pbvs()[source]

Generator to get all PBVs

Yields:

name : str

The name of the valve

link : PBValve

The valve object

tcvs()[source]

Generator to get all TCVs

Yields:

name : str

The name of the valve

link : TCValve

The valve object

fcvs()[source]

Generator to get all FCVs

Yields:

name : str

The name of the valve

link : FCValve

The valve object

gpvs()[source]

Generator to get all GPVs

Yields:

name : str

The name of the valve

link : GPValve

The valve object

add_usage(key, *args)

add args to usage[key]

clear() → None. Remove all items from D.
clear_usage(key)

if key in usage, clear usage[key]

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_usage(key)

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

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
orphaned()

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

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.

remove_usage(key, *args)

remove args from usage[key]

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in 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.

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

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

usage()

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

values() → list of D's values