PatternRegistry#

module wntr.network.model

class PatternRegistry[source]#

Bases: Registry

A registry for patterns.


class DefaultPattern[source]#

Bases: object

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

__init__(options)[source]#
property name#

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

__init__(wn)#
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.

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

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)#

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:

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

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#
property default_pattern#

A new default pattern object