Utilities

Utility provides various methods that don’t act on a population directly.

Overview:

class pyEpiabm.utility.AntibodyMultiplier(max_41: float, half_life_41: float, change_in_max_10: float, change_in_half_life_10: float, days_positive_pcr_to_max_igg: int)[source]

Class which calculates a multiplier for the susceptibility in the force of infection (to be used in personal_foi.py) based on the current IgG antibody count.

__call__(time_since_infection: float, age_group: int) float[source]

Calculates the multiplier to be used in the force of infection. Takes the form 1 - A * 2^(-bt) where A and b are factors dependent on age_group. If we are not using ages, then we use values for age = 41.

This will be a decaying exponential from the time of peak IgG titre, which occurs a fixed period of time after first being infected. Before the peak a person cannot be re-infected, so their force of infection will be zero.

Parameters:
  • time_since_infection (float) – Time (in days) since the Person first became infected

  • age_group (int) – Age group of the Person

Returns:

An IgG multiplier for the force of infection

Return type:

float

class pyEpiabm.utility.DistanceFunctions[source]

Class which contains multiple distance functions for use when considering spatial infections, either inter-place or inter-cell.

static dist(loc1: Tuple[float, float], loc2: Tuple[float, float] = (0.0, 0.0)) float[source]

Calculate distance based on currently configured distance metric

Parameters:
  • loc1 (Tuple[float, float]) – (x,y) coordinates of the first place

  • loc2 (Tuple[float, float]) – (x,y) coordinates of the second place

Returns:

Distance between the two locations

Return type:

float

static dist_euclid(loc1: Tuple[float, float], loc2: Tuple[float, float] = (0.0, 0.0))[source]

Calculates distance based on the standard L2, Euclidean norm. This assumes the space is approximately planar, and so is a good approximation for smaller areas where the curvature of the Earth is not significant. Passing a single location argument will return the norm of this tuple.

Parameters:
  • loc1 (Tuple[float, float]) – (x,y) coordinates of the first place

  • loc2 (Tuple[float, float]) – (x,y) coordinates of the second place

Returns:

Euclidean distance between the two locations

Return type:

float

static dist_periodic(loc1: Tuple[int, int], stride: int, scales: Tuple[float, float], loc2: Tuple[int, int] = (0, 0))[source]

One of the function for calculating distances implemented in CovidSim. Locations are integer points on a grid, which can be mapped to the whole globe. Periodic conditions at the boundary mean this only applies to a global grid. Scales should be (Earth perimeter, vertical range)

Parameters:
  • loc1 (Tuple[int, int]) – Index location of the first place

  • stride (int) – Number of indices in a row

  • scales (Tuple[float, float]) – Conversion to global coordinates

  • loc2 (Tuple[int, int]) – Index location of the second place

Returns:

Periodic distance between the two locations

Return type:

float

minimum_between_cells(cell2)[source]

Function to find the minimum distance between microcells in two cells. Covidsim uses this to weight the spatial kernel.

Parameters:
  • cell1 (Cell) – First cell to find the minimum distance between

  • cell2 (Cell) – Second cell to find the minimum distance between

Returns:

Minimum distance between the two cells

Return type:

float

class pyEpiabm.utility.InverseCdf(mean, icdf_array)[source]

Class of inverse cumulative distribution functions (icdf) and their associated methods, in a style similar to CovidSim.

icdf_choose_exp() float[source]

Samples a value from the inverse cumulative distribution function, following what is done in CovidSim (with negative exponentiation), and returns the value as a float.

Returns:

Mean scaled relative to given icdf

Return type:

float

icdf_choose_noexp() float[source]

Samples a value from the inverse cumulative distribution function, following what is done in CovidSim (without exponentiation), and returns the value as a float.

Returns:

Mean scaled relative to given icdf

Return type:

float

class pyEpiabm.utility.RandomMethods[source]

Class to calculate methods in a style similar to CovidSim.

covid_sim_rand()[source]

Reproduction of the ranf_mt method in the Rand.cpp from CovidSim. In covid-sim, they would use the thread number to generate the output.

Returns:

Returns random number between 0 and 1

Return type:

float

class pyEpiabm.utility.RateMultiplier(p_1: float, p_2: float, t_1: float = 90.0, t_2: float = 180.0)[source]

Class which produces a decaying exponential curve parameterised by time given two data points (default of 90 and 180 days). Note that p(t) = 0 represents immunity having a maximal effect on the StateTransitionMatrix probabilities, and p(t) = 1 represents immunity having no effect. So p -> 1 as t -> inf. p will take the form p(t) = 1 - be^(-at) for some constants a and b (determined by the two data points).

__call__(t: float) float[source]

Given a value t (representing days since a Person last recovered from the disease), calculates the rate multiplier for a waning individual moving to a specific compartment, using a decaying exponential

Parameters:

t (float) – Days since a Person last recovered from the disease

Returns:

The rate multiplier for the probability of them moving to a certain compartment in the StateTransitionMatrix

Return type:

float

class pyEpiabm.utility.SpatialKernel[source]

Class to create the gravity kernel used throughout CovidSim in the spatial weighting.

static weighting(distance: float, scale: float = 1, shape: float = 1.0)[source]

Returns the weighting given by the Covidsim distance weighting. The formula is given by

\[\frac{1}{(1+\frac{\text{distance}}{\text{scale}})^\text{shape}}\]

and is further detailed in the wiki: https://github.com/SABS-R3-Epidemiology/epiabm/wiki/Comparison-to-Ferguson-Model

Parameters:
  • distance (float) – Distance input as the main argument

  • scale (float) – Parameter to scale the kernel function

  • shape (float) – Parameter to change the shape of the kernel function

Returns:

weight – Float of the weight function

Return type:

float

pyEpiabm.utility.log_exceptions(message: str = '')[source]

Provides a try/except clause around the function it is applied to. Logs the type of error, and name of the function, if an error occurs, with an optional message appended on the end.

Parameters:

message (str) – Optional message to append to default log text