Skip to content

laser.measles.compartmental.model

laser.measles.compartmental.model

This module defines the CompartmentalModel class for SEIR simulation with daily timesteps

Classes:

Name Description
CompartmentalModel

A class to represent the compartmental SEIR model.

Imports:

Model Class

Methods: init(self, scenario: BaseScenario, parameters: CompartmentalParams, name: str = "compartmental") -> None: Initializes the model with the given scenario and parameters.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
components(self) -> list:
    Gets the list of components in the model.

components(self, components: list) -> None:
    Sets the list of components in the model and initializes instances and phases.

__call__(self, model, tick: int) -> None:
    Updates the model for a given tick.

run(self) -> None:
    Runs the model for the specified number of ticks.

visualize(self, pdf: bool = True) -> None:
    Generates visualizations of the model's results, either displaying them or saving to a PDF.

plot(self, fig: Figure = None):
    Generates plots for the scenario patches and populations, distribution of day of birth, and update phase times.

laser.measles.compartmental.model.CompartmentalModel(scenario, params, name='compartmental')

Bases: BaseLaserModel

A class to represent the compartmental model with daily timesteps.

Args:

1
2
3
scenario (BaseScenario): A scenario containing the scenario data, including population, latitude, and longitude.
params (CompartmentalParams): A set of parameters for the model.
name (str, optional): The name of the model. Defaults to "compartmental".

Notes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
This class initializes the model with the given scenario and parameters. The scenario must include the following columns:

    - `id` (string): The name of the patch or location.
    - `pop` (integer): The population count for the patch.
    - `lat` (float degrees): The latitude of the patches (e.g., from geographic or population centroid).
    - `lon` (float degrees): The longitude of the patches (e.g., from geographic or population centroid).
    - `mcv1` (float): The MCV1 coverage for the patches.

The default model uses SEIR compartments:
    - S: Susceptible individuals
    - E: Exposed individuals (infected but not yet infectious)
    - I: Infectious individuals
    - R: Recovered/immune individuals

Initialize the disease model with the given scenario and parameters.

Args:

1
2
3
scenario (BaseScenario): A scenario containing the scenario data, including population, latitude, and longitude.
params (CompartmentalParams): A set of parameters for the model, including seed, num_ticks, beta, sigma, gamma, and other SEIR parameters.
name (str, optional): The name of the model. Defaults to "compartmental".

Returns:

1
None

laser.measles.compartmental.model.CompartmentalModel.expose(indices, num_exposed)

Exposes the given nodes with the given number of exposed individuals. Moves individuals from Susceptible to Exposed compartment.

Parameters:

Name Type Description Default
indices int | ndarray

The indices of the nodes to expose.

required
num_exposed int | ndarray

The number of exposed individuals.

required

laser.measles.compartmental.model.CompartmentalModel.from_snapshot(path, params, components=None, verbose=True) classmethod

Load a CompartmentalModel from an HDF5 snapshot.

Convenience wrapper around load_snapshot. Use this to resume a simulation from a checkpoint saved with save_snapshot.

Parameters:

Name Type Description Default
path str | Path

Path to the HDF5 file written by save_snapshot.

required
params CompartmentalParams

CompartmentalParams for the resumed segment.

required
components list | None

Ordered list of component classes — same as the original model, minus InfectionSeedingProcess.

None
verbose bool

Print a loading summary.

True

Returns:

Type Description
CompartmentalModel

A configured CompartmentalModel ready for model.run().

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
```python
import laser.measles as lm
from laser.measles.compartmental.components import InfectionProcess

params2 = lm.CompartmentalParams(num_ticks=365, seed=42, start_time="2001-01")
model2 = lm.CompartmentalModel.from_snapshot(
    "checkpoint.h5", params2, components=[InfectionProcess]
)
model2.run()
```

laser.measles.compartmental.model.CompartmentalModel.infect(indices, num_infected)

Infects the given nodes with the given number of infected individuals. Moves individuals from Exposed to Infected compartment.

Parameters:

Name Type Description Default
indices int | ndarray

The indices of the nodes to infect.

required
num_infected int | ndarray

The number of infected individuals.

required

laser.measles.compartmental.model.CompartmentalModel.recover(indices, num_recovered)

Recovers the given nodes with the given number of recovered individuals. Moves individuals from Infected to Recovered compartment.

Parameters:

Name Type Description Default
indices int | ndarray

The indices of the nodes to recover.

required
num_recovered int | ndarray

The number of recovered individuals.

required