Registry#

module wntr.network.base

class Registry[source]#

Bases: MutableMapping

Base class for registries.

Parameters:

wn (WaterNetworkModel) – WaterNetworkModel object


__init__(wn)[source]#
add_usage(key, *args)[source]#

add args to usage[key]

clear() None.  Remove all items from D.#
clear_usage(key)[source]#

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)[source]#

Get a set of items using an object by key.

Returns:

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

Return type:

set of 2-tuples

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()[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:

The names of any orphaned items

Return type:

set

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)[source]#

remove args from usage[key]

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
to_dict()[source]#

Dictionary representation of the registry

to_list()[source]#

List representation of the registry

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:

The names of any unused objects in the registry

Return type:

set

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

values() an object providing a view on D's values#