laser.measles.abm.utils
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. |
add_at(A, indices, B)
Accumulate rows of B into A at the given indices (scatter-add).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Destination array that is updated in-place. |
required |
indices
|
ndarray
|
Index into A for each row of B. |
required |
B
|
ndarray
|
Source values to accumulate. |
required |
calc_capacity(population, nticks, cbr, verbose=False)
Calculate the population capacity after a given number of ticks based on a constant birth rate (CBR).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
uint32
|
The initial population. |
required |
nticks
|
uint32
|
The number of ticks (time steps) to simulate. |
required |
cbr
|
float32
|
The constant birth rate per 1000 people per year. |
required |
verbose
|
bool
|
If True, prints detailed population growth information. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
uint32
|
np.uint32: The estimated population capacity after the given number of ticks. |
calc_distances(latitudes, longitudes, verbose=False)
Calculate the pairwise distances between points given their latitudes and longitudes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitudes
|
ndarray
|
A 1-dimensional array of latitudes. |
required |
longitudes
|
ndarray
|
A 1-dimensional array of longitudes with the same shape as latitudes. |
required |
verbose
|
bool
|
If True, prints the upper left corner of the distance matrix. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A 2-dimensional array where the element at [i, j] represents the distance between the i-th and j-th points. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If latitudes is not 1-dimensional or if latitudes and longitudes do not have the same shape. |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The simulation model containing the population and parameters. |
required | |
ipatch
|
int
|
The identifier of the patch where infections should be seeded. |
required |
ninfections
|
int
|
The number of initial infections to seed. Defaults to 100. |
1
|
Returns:
| Type | Description |
|---|---|
None
|
None |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The simulation model containing the population and parameters. |
required | |
ninfections
|
int
|
The number of initial infections to seed. Defaults to 100. |
100
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The nodeids of the individuals seeded with an infection. |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The simulation model containing the population and parameters. |
required | |
ninfections
|
int
|
The number of initial infections to seed. Defaults to 100. |
100
|
Returns:
| Type | Description |
|---|---|
None
|
None |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The simulation model containing the population and parameters. |
required | |
ipatch
|
int
|
The patch to set susceptibility in |
required |
susc_frac
|
float
|
The fraction of individuals to keep susceptible. |
1.0
|
Returns:
| Type | Description |
|---|---|
None
|
None |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
The simulation model containing the population and parameters. |
required | |
susc_frac
|
float
|
The fraction of individuals to keep susceptible. |
1.0
|
Returns:
| Type | Description |
|---|---|
None
|
None |