Skip to content

laser.measles.biweekly

laser.measles.biweekly

laser.measles.biweekly.BaseScenario = BaseBiweeklyScenario module-attribute

Base class for scenario data wrappers.

Provides a wrapper around polars DataFrames with additional validation and convenience methods.

Example:

1
2
3
4
5
6
```python
from laser.measles.scenarios.synthetic import single_patch_scenario

scenario = single_patch_scenario(population=100_000, mcv1_coverage=0.85)
# scenario is a Polars DataFrame with columns: id, pop, lat, lon, mcv1
```

laser.measles.biweekly.BiweeklyModel(scenario, params, name='biweekly')

Bases: BaseLaserModel

Population-level measles model with 14-day (biweekly) timesteps.

Tracks SEIR compartment counts per patch without individual agents, making it significantly faster than ABMModel for large-scale parameter sweeps and multi-country analyses. Choose this model when individual-level detail is not required and computational speed is a priority. For daily timesteps with explicit SEIR compartment dynamics, see CompartmentalModel.

This is the first object created in the build model stage of the researcher workflow. After construction, attach components with add_component or by setting the components property, then call model.run().

Parameters:

Name Type Description Default
scenario DataFrame | BaseBiweeklyScenario

Metapopulation patch data. Required columns: id (str), pop (int), lat (Float64), lon (Float64), mcv1 (Float64). A plain polars.DataFrame is automatically wrapped.

required
params BiweeklyParams

Simulation parameters including num_ticks, seed, and start_time.

required
name str

Display name for log messages. Defaults to "biweekly".

'biweekly'

Example:

1
2
3
4
5
6
7
8
```python
from laser.measles.biweekly import BiweeklyModel, BiweeklyParams

params = BiweeklyParams(num_ticks=26, seed=42, start_time="2000-01")
model = BiweeklyModel(scenario=df, params=params)
model.components = [InfectionSeedingProcess, InfectionProcess]
model.run()
```

laser.measles.biweekly.BiweeklyModel.__call__(model, tick)

Updates the model for the next tick.

Args:

1
2
model: The model containing the patches and their populations.
tick (int): The current time step or tick.

Returns:

1
None

laser.measles.biweekly.BiweeklyModel.infect(indices, num_infected)

Infects the given nodes with the given number of infected individuals.

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 to infect.

required

laser.measles.biweekly.BiweeklyModel.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.biweekly.BiweeklyParams

Bases: BaseModelParams

Parameters for the biweekly compartmental measles model (14-day timesteps).

Inherits all fields from BaseModelParams. Each tick represents 14 days, and the model tracks three SIR states (no explicit Exposed compartment).

Parameters:

Name Type Description Default
num_ticks int

Number of biweekly simulation steps (e.g., 26 ≈ 1 year, 130 ≈ 5 years).

required
seed int

Random seed for reproducibility. Default: 20250314.

required
start_time str

Simulation start in "YYYY-MM" format. Default: "2000-01".

required
verbose bool

Print detailed logging. Default: False.

required

Example:

1
2
3
```python
params = BiweeklyParams(num_ticks=26, seed=42, start_time="2000-01")
```

laser.measles.biweekly.BiweeklyParams.states property

SIR state names: ["S", "I", "R"].

laser.measles.biweekly.BiweeklyParams.time_step_days property

Duration of one tick in days (always 14 for the biweekly model).

laser.measles.biweekly.create_component(component_class, params=None)

Wrap a component class and its parameters into a single callable.

Use this at set parameters time when a component requires a custom Pydantic parameter object. The returned factory is callable with the same (model, verbose) signature that BaseLaserModel.components expects, so it can be placed directly in the component list.

Parameters:

Name Type Description Default
component_class type[T]

The component class to instantiate.

required
params type[B] | None

A Pydantic parameter object (or None for defaults).

None

Returns:

Type Description
Callable[[Any, Any], T]

A callable that creates the component when invoked by the model.

Example:

1
2
3
4
5
6
7
8
```python
from laser.measles import create_component
from laser.measles.compartmental.components import InfectionProcess, InfectionParams

model.components = [
    create_component(InfectionProcess, InfectionParams(beta=0.8)),
]
```