laser.measles.compartmental
laser.measles.compartmental
laser.measles.compartmental.BaseScenario = BaseCompartmentalScenario
module-attribute
Base class for scenario data wrappers.
Provides a wrapper around polars DataFrames with additional validation and convenience methods.
laser.measles.compartmental.CompartmentalModel(scenario, params, name='compartmental')
Bases: BaseLaserModel
A class to represent the compartmental model with daily timesteps.
Args:
1 2 3 | |
Notes:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Initialize the disease model with the given scenario and parameters.
Args:
1 2 3 | |
Returns:
1 | |
laser.measles.compartmental.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.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
|
required |
params
|
CompartmentalParams
|
|
required |
components
|
list | None
|
Ordered list of component classes — same as the
original model, minus |
None
|
verbose
|
bool
|
Print a loading summary. |
True
|
Returns:
| Type | Description |
|---|---|
CompartmentalModel
|
A configured
|
Example:
1 2 3 4 5 6 7 8 9 10 | |
laser.measles.compartmental.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.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 |
laser.measles.compartmental.CompartmentalParams
Bases: BaseModelParams
Parameters for the compartmental SEIR model with daily timesteps.
All fields are inherited from :class:BaseModelParams. Key fields:
Attributes:
| Name | Type | Description |
|---|---|---|
num_ticks |
int
|
Number of daily simulation steps (e.g., 365 = 1 year). |
seed |
int
|
Random seed for reproducibility. Default: 20250314. |
start_time |
str
|
Simulation start in |
verbose |
bool
|
Print detailed logging. Default: False. |
Example::
1 2 | |
laser.measles.compartmental.create_component(component_class, params=None)
Helper function to create a component instance with parameters.
This function creates a callable object that will instantiate the component with the given parameters when called by the model.
Parameters
component_class : Type[BaseComponent] The component class to instantiate **kwargs Parameters to pass to the component constructor
Returns
Callable[[Any, Any], BaseComponent] A function that creates the component instance when called by the model
Examples
model.components = [ ... create_component(MyComponent, params=MyComponentParams), ... AnotherComponent, ... ]
laser.measles.compartmental.load_snapshot(path, params, components=None, verbose=True)
Load a compartmental model from an HDF5 snapshot file and return it ready to run.
Restores the patch SEIR state, scenario, and metadata saved by
save_snapshot.
Set params.start_time to the snapshot date printed by
save_snapshot. Do not include InfectionSeedingProcess in the
components list — infections are already encoded in the restored
patch states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the HDF5 snapshot file written by
|
required |
params
|
CompartmentalParams
|
|
required |
components
|
list | None
|
Ordered list of component classes to attach — same list
as used when building the original model, minus
|
None
|
verbose
|
bool
|
Print a loading summary. |
True
|
Returns:
| Type | Description |
|---|---|
CompartmentalModel
|
A configured
|
Example:
1 2 3 4 5 6 7 8 9 10 11 | |
laser.measles.compartmental.save_snapshot(model, path, verbose=True)
Save compartmental model patch state to an HDF5 snapshot file.
Call this after
CompartmentalModel.run()
to persist the full patch SEIR state. The resulting HDF5 file can be
resumed with
load_snapshot to
continue the simulation from exactly where it left off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CompartmentalModel
|
A fully-run (or mid-run)
|
required |
path
|
str | Path
|
Destination HDF5 file path (created or overwritten). |
required |
verbose
|
bool
|
Print a progress summary. |
True
|
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |