metawards.Nodes¶
-
class
metawards.
Nodes
(N: int = 0)[source]¶ This is a container class for Nodes. This uses Numpy arrays to store a list of Node objects as a “struct of arrays”. This should improve speed of loading and access.
Methods
__init__
(N)Create a container for up to “N” nodes assert_not_null
()Assert that this collection of nodes is not null assert_valid_index
(i)Assert that the passed index ‘i’ is valid for this collection. copy
()Return a copy of this network, using deep copies for things which are variable, but shallow copies for things which should stay the same (e.g. get_index
(i)Return the mapped index for the ith node. is_null
()population
()Return the total population of the nodes resize
(N)Resize this container to hold ‘N’ nodes. scale_susceptibles
(ratio, work_ratio, play_ratio)Scale the number of susceptibles in these Nodes by the passed scale ratios. -
__getitem__
(i: int)[source]¶ Return the node at index ‘i’. Note that this is a deep copy of the node. Changing the node will not change the data in this container. To update the data in this container you need to use __setitem__, e.g. via the index operator (see __setitem__)
-
__init__
(N: int = 0)[source] Create a container for up to “N” nodes
-
__setitem__
(i: int, value: metawards._node.Node)[source]¶ Set the item as index ‘i’ equal to ‘value’. This deep-copies ‘value’ into this container
-
assert_valid_index
(i)[source]¶ Assert that the passed index ‘i’ is valid for this collection. This will return the index with Python reverse indexing, so that “-1” refers to the last node in the collection
-
copy
()[source]¶ Return a copy of this network, using deep copies for things which are variable, but shallow copies for things which should stay the same (e.g. x and y). This copy assumes that you are not changing the actual links between nodes, e.g. it shallow-copies label, begin_to, end_to, self_w, begin_p, end_p and self_p. If you are changing the links then you will need to recreate these arrays.
-
get_index
(i)[source]¶ Return the mapped index for the ith node. This will raise an IndexError if this is an invalid index. If not, it will map a negative index into a canonical positive index
-
population
() → int[source]¶ Return the total population of the nodes
Returns: Total population Return type: int
-
resize
(N: int)[source]¶ Resize this container to hold ‘N’ nodes. This will expand the container if ‘N’ is greater than len(self), or will contract the container (deleting excess nodes) if ‘N’ is less than len(self). This function is called typically when you pre-allocate a large Nodes container, and then want to reduce the size to fit the number of loaded nodes
-
scale_susceptibles
(ratio: any = None, work_ratio: any = None, play_ratio: any = None)[source]¶ Scale the number of susceptibles in these Nodes by the passed scale ratios. These can be values, e.g. ratio = 2.0 will scale the total number of susceptibles in each ward by 2.0. They can also be lists of values, where ward[i] will be scaled by ratio[i]. They can also be dictionaries, e.g. ward[i] scaled by ratio[i]
Parameters: - ratio (None, float, list or dict) – The amount by which to scale the total population of susceptibles - evenly scales the work and play populations
- work_ratio (None, float, list or dict) – Scale only the work population of susceptibles
- play_ratio (None, float, list or dict) – Scale only the play population of susceptibles
Returns: Return type: None
-