Skip to content

laser.measles.abm.utils

laser.measles.abm.utils

This module provides utility functions for the laser-measles project.

Functions:

Name Description
calc_distances

np.ndarray, longitudes: np.ndarray, verbose: bool = False) -> np.ndarray: Calculate the pairwise distances between points given their latitudes and longitudes.

calc_capacity

np.uint32, nticks: np.uint32, cbr: np.float32, verbose: bool = False) -> np.uint32: Calculate the population capacity after a given number of ticks based on a constant birth rate.

seed_infections_randomly

int = 100) -> None: Seed initial infections in random locations at the start of the simulation.

seed_infections_in_patch

int, ninfections: int = 100) -> None: Seed initial infections in a specific location at the start of the simulation.

set_initial_susceptibility_randomly

float = 1.0) -> None: Set the population susceptibility level at the start of the simulation.

set_initial_susceptibility_in_patch

int, susc_frac: float = 1.0) -> None: Set the population susceptibility level at the start of the simulation in a specific patch.

laser.measles.abm.utils.calc_capacity(population, nticks, cbr, verbose=False)

Calculate the population capacity after a given number of ticks based on a constant birth rate (CBR).

Args:

1
2
3
4
population (np.uint32): The initial population.
nticks (np.uint32): The number of ticks (time steps) to simulate.
cbr (np.float32): The constant birth rate per 1000 people per year.
verbose (bool, optional): If True, prints detailed population growth information. Defaults to False.

Returns:

1
np.uint32: The estimated population capacity after the given number of ticks.

laser.measles.abm.utils.calc_distances(latitudes, longitudes, verbose=False)

Calculate the pairwise distances between points given their latitudes and longitudes.

Parameters:

1
2
3
latitudes (np.ndarray): A 1-dimensional array of latitudes.
longitudes (np.ndarray): A 1-dimensional array of longitudes with the same shape as latitudes.
verbose (bool, optional): If True, prints the upper left corner of the distance matrix. Default is False.

Returns:

1
np.ndarray: A 2-dimensional array where the element at [i, j] represents the distance between the i-th and j-th points.

Raises:

1
AssertionError: If latitudes is not 1-dimensional or if latitudes and longitudes do not have the same shape.

laser.measles.abm.utils.seed_infections_in_patch(model, ipatch, ninfections=1)

Seed initial infections in a specific patch of the population at the start of the simulation. This function randomly selects individuals from the specified patch and sets their infection timer to the mean infection duration, effectively marking them as infected. The process continues until the desired number of initial infections is reached.

Args:

1
2
3
model: The simulation model containing the population and parameters.
ipatch (int): The identifier of the patch where infections should be seeded.
ninfections (int, optional): The number of initial infections to seed. Defaults to 100.

Returns:

1
None

laser.measles.abm.utils.seed_infections_randomly(model, ninfections=100)

Seed initial infections in random locations at the start of the simulation. This function randomly selects individuals from the population and seeds them with an infection, based on the specified number of initial infections.

Args:

1
2
3
model: The simulation model containing the population and parameters.
ninfections (int, optional): The number of initial infections to seed.
                             Defaults to 100.

Returns:

1
np.ndarray: The nodeids of the individuals seeded with an infection.

laser.measles.abm.utils.seed_infections_randomly_SI(model, ninfections=100)

Seed initial infections in random locations at the start of the simulation. This function randomly selects individuals from the population and seeds them with an infection, based on the specified number of initial infections.

Args:

1
2
3
model: The simulation model containing the population and parameters.
ninfections (int, optional): The number of initial infections to seed.
                             Defaults to 100.

Returns:

1
None

laser.measles.abm.utils.set_initial_susceptibility_in_patch(model, ipatch, susc_frac=1.0)

Set the population susceptibility level at the start of the simulation, in a specific patch. This function randomly selects individuals from the patch and changes their susceptibility to zero, according to the parameter susc_frac.

Args:

1
2
3
model: The simulation model containing the population and parameters.
ipatch: The patch to set susceptibility in
susc_frac (float, optional): The fraction of individuals to keep susceptible.

Returns:

1
None

laser.measles.abm.utils.set_initial_susceptibility_randomly(model, susc_frac=1.0)

Set the population susceptibility level at the start of the simulation. This function randomly selects individuals from the population and changes their susceptibility to zero, according to the parameter susc_frac.

Args:

1
2
model: The simulation model containing the population and parameters.
susc_frac (float, optional): The fraction of individuals to keep susceptible.

Returns:

1
None