wntr.network.model module¶
The wntr.network.model module includes methods to build a water network model.
Contents
|
Water network model class. |
|
A registry for patterns. |
|
A registry for curves. |
|
A registry for sources. |
|
A registry for nodes. |
|
A registry for links. |
- class wntr.network.model.WaterNetworkModel(inp_file_name=None)[source]¶
Bases:
AbstractModel
Water network model class.
- Parameters
inp_file_name (string (optional)) – Directory and filename of EPANET inp file to load into the WaterNetworkModel object.
- property options¶
The model’s options object
- Returns
Options
- property nodes¶
The node registry (as property) or a generator for iteration (as function call)
- Returns
NodeRegistry
- property links¶
The link registry (as property) or a generator for iteration (as function call)
- Returns
LinkRegistry
- property patterns¶
The pattern registry (as property) or a generator for iteration (as function call)
- Returns
PatternRegistry
- property 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).
- property junctions¶
Iterator over all junctions
- property tanks¶
Iterator over all tanks
- property reservoirs¶
Iterator over all reservoirs
- property pipes¶
Iterator over all pipes
- property pumps¶
Iterator over all pumps
- property valves¶
Iterator over all valves
- property head_pumps¶
Iterator over all head-based pumps
- property power_pumps¶
Iterator over all power pumps
- property prvs¶
Iterator over all pressure reducing valves (PRVs)
- property psvs¶
Iterator over all pressure sustaining valves (PSVs)
- property pbvs¶
Iterator over all pressure breaker valves (PBVs)
- property tcvs¶
Iterator over all throttle control valves (TCVs)
- property fcvs¶
Iterator over all flow control valves (FCVs)
- property 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 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=0.0, vol_curve=None, overflow=False, 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, optional) – Name of a volume curve
overflow (bool) – Overflow indicator (Always False for the WNTRSimulator)
coordinates (tuple of floats, optional) – X-Y coordinates of the node location.
- 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, optional) – Name of the head pattern.
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, initial_status='OPEN', check_valve=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.
initial_status (string or LinkStatus, optional) – Pipe initial status. Options are ‘OPEN’ or ‘CLOSED’.
check_valve (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, initial_status='OPEN')[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 string) – For a POWER pump, the pump power. For a HEAD pump, the head curve name.
speed (float) – Relative speed setting (1.0 is normal speed)
pattern (string) – Name of the speed pattern
initial_status (string or LinkStatus) – Pump initial status. Options are ‘OPEN’ or ‘CLOSED’.
- add_valve(name, start_node_name, end_node_name, diameter=0.3048, valve_type='PRV', minor_loss=0.0, initial_setting=0.0, initial_status='ACTIVE')[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’, ‘PSV’, ‘PBV’, ‘FCV’, ‘TCV’, and ‘GPV’
minor_loss (float, optional) – Pipe minor loss coefficient.
initial_setting (float or string, optional) – Valve initial setting. Pressure setting for PRV, PSV, or PBV. Flow setting for FCV. Loss coefficient for TCV. Name of headloss curve for GPV.
initial_status (string or LinkStatus) – Valve initial status. Options are ‘OPEN’, ‘CLOSED’, or ‘ACTIVE’.
- 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.
- 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
- remove_node(name, with_control=False, force=False)[source]¶
Removes a node from the water network model
- remove_link(name, with_control=False, force=False)[source]¶
Removes a link 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
- get_node(name)[source]¶
Get a specific node
- Parameters
name (str) – The node name
- Returns
Junction, Tank, or Reservoir
- get_link(name)[source]¶
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_source(name)[source]¶
Get a specific source
- Parameters
name (str) – The source name
- Returns
Source
- get_control(name)[source]¶
Get a specific control or rule
- Parameters
name (str) – The control name
- Returns
ctrl (Control or Rule)
- property node_name_list¶
Get a list of node names
- Returns
list of strings
- property junction_name_list¶
Get a list of junction names
- Returns
list of strings
- property tank_name_list¶
Get a list of tanks names
- Returns
list of strings
- property reservoir_name_list¶
Get a list of reservoir names
- Returns
list of strings
- property link_name_list¶
Get a list of link names
- Returns
list of strings
- property pipe_name_list¶
Get a list of pipe names
- Returns
list of strings
- property pump_name_list¶
Get a list of pump names (both types included)
- Returns
list of strings
- property head_pump_name_list¶
Get a list of head pump names
- Returns
list of strings
- property power_pump_name_list¶
Get a list of power pump names
- Returns
list of strings
- property valve_name_list¶
Get a list of valve names (all types included)
- Returns
list of strings
- property prv_name_list¶
Get a list of prv names
- Returns
list of strings
- property psv_name_list¶
Get a list of psv names
- Returns
list of strings
- property pbv_name_list¶
Get a list of pbv names
- Returns
list of strings
- property tcv_name_list¶
Get a list of tcv names
- Returns
list of strings
- property fcv_name_list¶
Get a list of fcv names
- Returns
list of strings
- property gpv_name_list¶
Get a list of gpv names
- Returns
list of strings
- property pattern_name_list¶
Get a list of pattern names
- Returns
list of strings
- property curve_name_list¶
Get a list of curve names
- Returns
list of strings
- property source_name_list¶
Get a list of source names
- Returns
list of strings
- property control_name_list¶
Get a list of control/rule names
- Returns
list of strings
- property num_nodes¶
The number of nodes
- property num_junctions¶
The number of junctions
- property num_tanks¶
The number of tanks
- property num_reservoirs¶
The number of reservoirs
- property num_links¶
The number of links
- property num_pipes¶
The number of pipes
- property num_pumps¶
The number of pumps
- property num_valves¶
The number of valves
- property num_patterns¶
The number of patterns
- property num_curves¶
The number of curves
- property num_sources¶
The number of sources
- property num_controls¶
The number of controls
- describe(level=0)[source]¶
Describe number of components in the network model
- Parameters
level (int (0, 1, or 2)) –
Level 0 returns the number of Nodes, Links, Patterns, Curves, Sources, and Controls.
Level 1 includes information from Level 0 but divides Nodes into Junctions, Tanks, and Reservoirs, divides Links into Pipes, Pumps, and Valves, and divides Curves into Pump, Efficiency, Headloss, and Volume.
Level 2 includes information from Level 1 but divides Pumps into Head and Power, and divides Valves into PRV, PSV, PBV, TCV, FCV, and GPV.
- Returns
A dictionary with component counts
- from_dict(d: dict)[source]¶
Append the model with elements from a dictionary.
- Parameters
d (dict) – Dictionary representation of the WaterNetworkModel
- to_gis(crs=None, pumps_as_points=False, valves_as_points=False)[source]¶
Convert a WaterNetworkModel into GeoDataFrames
- Parameters
crs (str, optional) – Coordinate reference system, by default None
pumps_as_points (bool, optional) – Represent pumps as points (True) or lines (False), by default False
valves_as_points (bool, optional) – Represent valves as points (True) or lines (False), by default False
- Returns
WaterNetworkGIS object that contains junctions, tanks, reservoirs, pipes,
pumps, and valves GeoDataFrames
- from_gis(gis_data)[source]¶
Append the model with elements from GeoDataFrames
- Parameters
gis_data (WaterNetworkGIS or dictionary of GeoDataFrames) – GeoDataFrames containing water network attributes. If gis_data is a dictionary, then the keys are junctions, tanks, reservoirs, pipes, pumps, and valves. If the pumps or valves are Points, they will be converted to Lines with the same start and end node location.
- Returns
WaterNetworkModel
- to_graph(node_weight=None, link_weight=None, modify_direction=False)[source]¶
Convert a WaterNetworkModel into a networkx MultiDiGraph
- Parameters
node_weight (dict or pandas Series (optional)) – Node weights
link_weight (dict or pandas Series (optional)) – Link weights.
modify_direction (bool (optional)) – If True, than if the link weight is negative, the link start and end node are switched and the abs(weight) is assigned to the link (this is useful when weighting graphs by flowrate). If False, link direction and weight are not changed.
- Returns
networkx MultiDiGraph
- get_graph(node_weight=None, link_weight=None, modify_direction=False)[source]¶
Convert a WaterNetworkModel into a networkx MultiDiGraph
Deprecated since version 0.5.0.
Use
to_graph()
instead- Parameters
node_weight (dict or pandas Series (optional)) – Node weights
link_weight (dict or pandas Series (optional)) – Link weights.
modify_direction (bool (optional)) – If True, than if the link weight is negative, the link start and end node are switched and the abs(weight) is assigned to the link (this is useful when weighting graphs by flowrate). If False, link direction and weight are not changed.
- Returns
networkx MultiDiGraph
- assign_demand(demand, pattern_prefix='ResetDemand')[source]¶
Assign demands using values in a DataFrame.
New demands are specified in a pandas DataFrame indexed by time (in seconds). The method resets junction demands by creating a new demand pattern and using a base demand of 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 = junction names)
pattern_prefix (string) – Pattern name prefix, default = ‘ResetDemand’. The junction name is appended to the prefix to create a new pattern name. If the pattern name already exists, an error is thrown and the user should use a different pattern prefix name.
- get_links_for_node(node_name, flag='ALL')[source]¶
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 pandas Series that contains the attribute that satisfies the
operation threshold for a given node_type.
Notes
If operation and value are both None, the Series will contain the attributes for all nodes with the specified attribute.
- query_link_attribute(attribute, operation=None, value=None, link_type=None)[source]¶
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 pandas Series that contains the attribute that satisfies the
operation threshold for a given link_type.
Notes
If operation and value are both None, the Series will contain the attributes for all links with the specified attribute.
- class wntr.network.model.PatternRegistry(wn)[source]¶
Bases:
Registry
A registry for patterns.
- class DefaultPattern(options)[source]¶
Bases:
object
An object that always points to the current default pattern for a model
- property 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 patternWarning
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.
- property 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() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on 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 ¶
- to_dict()¶
Dictionary representation of the registry
- to_list()¶
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() an object providing a view on D's values ¶
- class wntr.network.model.CurveRegistry(model)[source]¶
Bases:
Registry
A registry for curves.
- set_curve_type(key, curve_type)[source]¶
Sets curve type.
WARNING – this 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
- 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
- property 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
- property 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
- property 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
- property 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
- property 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() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on 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 ¶
- to_dict()¶
Dictionary representation of the registry
- to_list()¶
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() an object providing a view on D's values ¶
- class wntr.network.model.SourceRegistry(wn)[source]¶
Bases:
Registry
A registry for sources.
- 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() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on 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 ¶
- to_dict()¶
Dictionary representation of the registry
- to_list()¶
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() an object providing a view on D's values ¶
- class wntr.network.model.NodeRegistry(model)[source]¶
Bases:
Registry
A registry for nodes.
- add_junction(name, base_demand=0.0, demand_pattern=None, elevation=0.0, coordinates=None, demand_category=None, emitter_coeff=None, initial_quality=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 Pattern object
elevation (float) – Elevation of the junction.
coordinates (tuple of floats, optional) – X-Y coordinates of the node location.
demand_category (str, optional) – Category to the base demand
emitter_coeff (float, optional) – Emitter coefficient
initial_quality (float, optional) – Initial quality at this junction
- add_tank(name, elevation=0.0, init_level=3.048, min_level=0.0, max_level=6.096, diameter=15.24, min_vol=0.0, vol_curve=None, overflow=False, 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 of a cylindrical tank (only used when the volume curve is None)
min_vol (float) – Minimum tank volume (only used when the volume curve is None)
vol_curve (string, optional) – Name of a volume curve. The volume curve overrides the tank diameter and minimum volume.
overflow (bool, optional) – Overflow indicator (Always False for the WNTRSimulator)
coordinates (tuple of floats, optional) – X-Y coordinates of the node location.
- 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, optional) – Name of the head pattern.
coordinates (tuple of floats, optional) – X-Y coordinates of the node location.
- property junction_names¶
List of names of all junctions
- property tank_names¶
List of names of all junctions
- property 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() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on 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 ¶
- to_dict()¶
Dictionary representation of the registry
- to_list()¶
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() an object providing a view on D's values ¶
- class wntr.network.model.LinkRegistry(model)[source]¶
Bases:
Registry
A registry for links.
- add_pipe(name, start_node_name, end_node_name, length=304.8, diameter=0.3048, roughness=100, minor_loss=0.0, initial_status='OPEN', check_valve=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.
initial_status (string, optional) – Pipe initial status. Options are ‘OPEN’ or ‘CLOSED’.
check_valve (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, initial_status='OPEN')[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 string) – For a POWER pump, the pump power (float). For a HEAD pump, the head curve name (string).
speed (float) – Relative speed setting (1.0 is normal speed)
pattern (string) – Name of the speed pattern
initial_status (str or LinkStatus) – Pump initial status. Options are ‘OPEN’ or ‘CLOSED’.
- add_valve(name, start_node_name, end_node_name, diameter=0.3048, valve_type='PRV', minor_loss=0.0, initial_setting=0.0, initial_status='ACTIVE')[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’, ‘PSV’, ‘PBV’, ‘FCV’, ‘TCV’, and ‘GPV’
minor_loss (float, optional) – Pipe minor loss coefficient.
initial_setting (float or string, optional) – Valve initial setting. Pressure setting for PRV, PSV, or PBV. Flow setting for FCV. Loss coefficient for TCV. Name of headloss curve for GPV.
initial_status (string or LinkStatus) – Valve initial status. Options are ‘OPEN’, ‘CLOSED’, or ‘ACTIVE’
- check_valves()[source]¶
Generator to get all pipes with check valves
- Yields
name (str) – The name of the pipe
link (Pipe) – The pipe object
- property pipe_names¶
A list of all pipe names
- property valve_names¶
A list of all valve names
- property pump_names¶
A list of all pump names
- property head_pump_names¶
A list of all head pump names
- property power_pump_names¶
A list of all power pump names
- property prv_names¶
A list of all prv names
- property psv_names¶
A list of all psv names
- property pbv_names¶
A list of all pbv names
- property tcv_names¶
A list of all tcv names
- property fcv_names¶
A list of all fcv names
- property gpv_names¶
A list of all gpv 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() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on 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 ¶
- to_dict()¶
Dictionary representation of the registry
- to_list()¶
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() an object providing a view on D's values ¶