metawards.Nodes

class metawards.Nodes(N: int = 0)[source]

This is a container class for Nodes. This uses Python arrays to store a list of Node objects as a “struct of arrays”. This should improve speed of loading and access.

__init__(N: int = 0)[source]

Create a container for up to “N” nodes

Methods

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getitem__(i)

Return the node at index ‘i’.

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init__([N])

Create a container for up to “N” nodes

__init_subclass__

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__len__()

Return the number of nodes in this container

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

Create and return a new object.

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__setitem__(i, value)

Set the item as index ‘i’ equal to ‘value’.

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

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_custom(key[, default])

Return the array of custom parameters for the key called ‘key’.

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, …])

Scale the number of susceptibles in these Nodes by the passed scale ratios.

set_custom(key, value[, index])

Set the custom parameters for the key called ‘key’ to ‘value’.

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

__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

__len__()[source]

Return the number of nodes in this container

__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_not_null()[source]

Assert that this collection of nodes is not null

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

begin_p

The start index for play links

begin_to

The start index for work links

bg_foi

per-ward bg_foi value - this the starting FOI for the ward in the FOI calculation. This defaults to 0.0, but can be set to larger values if you want the ward to have a background FOI that drives infections

coordinates

Coordinate system used (x/y for X,Y in km, lat/long for latitude and longitude)

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.

cutoff

per-ward cutoff value - default to a large number that is greater than any distance between points on Earth (distance in k)

day_foi

Dayime force of infection for each ward

day_inf_prob

Daytime infection probability for each ward

denominator_d

Day time work denominator for each ward

denominator_n

Night time work denominator for each ward

denominator_p

Night time play denominator for each ward

denominator_pd

Day time play denominator for each ward

end_p

The end index for play links

end_to

The end index for work links

get_custom(key: str, default: float = 0.0) → array[float][source]

Return the array of custom parameters for the key called ‘key’. If these don’t exist then create them with the specified default value. Note that this returns a shallow copy of the array, meaning that you can modify this directly and it will change the value of the nodes. This is identical to the behaviour of the other arrays in this Nodes object (it is optimised for speed, not safety)

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

label

ID number for each node. This should equal the node index

night_foi

Nighttime force of infection for each ward

night_inf_prob

Nighttime infection probability for each ward

play_suscept

Number of susceptible players in each ward

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

save_play_suscept

Saved value of the number of susceptible players

scale_susceptibles(ratio: Optional[any] = None, work_ratio: Optional[any] = None, play_ratio: Optional[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

scale_uv

per-ward UV scaling parameter

self_p

The index of the home player play link

self_w

The index of the home commuter work link

set_custom(key: str, value: _Union[float, array[float]], index: int = None) → None[source]

Set the custom parameters for the key called ‘key’ to ‘value’. If the index is set then this just sets the value for that index. You pass in either an array of floats (thus setting all node parameters, or a single float, which is for the single ward, or will set all wards to have that value.

Note that custom parameters can only be floats!

x

X-coordinate of the center of each ward

y

Y-coordinate of the center of each ward