stratification

This module presents classes which are used to define stratifications, which can be applied to the model.

class summer2.stratification.AgeStratification(name: str, strata: List[str], compartments: List[str])

Bases: Stratification

A stratification that represents a set of age groups with ageing dynamics.

Parameters
  • name – The name of the stratification.

  • strata – The new strata that will be created.

  • compartments – The compartments which will be stratified.

Strata must be a list of strings or integers that represent all ages. For example, the strata [0, 10, 20, 30] will be interpreted as the age groups 0-9, 10-19, 20-29, 30+ respectively.

Using this stratification will automatically add a set of ageing flows to the model, where the exit rate is proportional to the age group’s time span. For example, in the 0-9 strata, there will be a flow created where 10% of occupants “age up” into the 10-19 strata each year. Critically, this feature assumes that each of the model’s time steps represents a year.

class summer2.stratification.StrainStratification(name: str, strata: List[str], compartments: List[str])

Bases: Stratification

A stratification that represents a set of disease strains.

Parameters
  • name – The name of the stratification.

  • strata – The new strata that will be created.

  • compartments – The compartments which will be stratified.

Each requested stratum will be interpreted as a different strain of the disease being modelled. This will mean that the force of infection calculations will consider each strain separately.

Strain stratifications cannot use a mixing matrix

class summer2.stratification.Stratification(name: str, strata: List[str], compartments: List[str])

Bases: object

A generic stratification applied to the compartmental model.

Parameters
  • name – The name of the stratification.

  • strata – The new strata that will be created.

  • compartments – The compartments which will be stratified.

add_infectiousness_adjustments(compartment_name: str, adjustments: Dict[str, Union[Multiply, Overwrite]])

Add an adjustment of a compartment’s infectiousness to the stratification. You cannot currently use time-varying functions for infectiousness adjustments. All strata in this stratification must be specified as keys in the adjustments argument, if no adjustment required for a stratum, specify None as the value to the request for that stratum.

Parameters
  • compartment_name – The name of the compartment to adjust.

  • adjustments – An dict of adjustments to apply to the compartment.

Example

Create an adjustment for the ‘I’ compartment based on location:

strat = Stratification(
    name="location",
    strata=["urban", "rural", "alpine"],
    compartments=["S", "I", "R"]
)
strat.add_infectiousness_adjustments("I", {
    "urban": adjust.Multiply(1.5),
    "rural": adjust.Multiply(0.8),
    "alpine": None, # No adjustment
})
get_flow_adjustment(flow) dict

Note that the loop structure implies that if the user has requested multiple adjustments that apply to a single combination of strata (across multiple stratifications), then only the last one that is applicable will be used - because the last request will over-write the earlier ones in the loop. Therefore, the most recently added flow adjustment that matches a given flow will be returned.

is_ageing() bool

Returns True if this stratification represents a set of age groups with ageing dynamics

is_strain() bool

Returns True if this stratification represents a set of disease strains

set_flow_adjustments(flow_name: str, adjustments: Dict[str, Union[Multiply, Overwrite]], source_strata: Optional[Dict[str, str]] = None, dest_strata: Optional[Dict[str, str]] = None)

Set an adjustment of a flow to the stratification. Adjustments from previous stratifications will be applied before this. You can use time-varying functions for infectiousness adjustments.

It is possible to specify multiple flow adjustments for the same flow in a given Stratification. In this case, only the last-created applicable adjustment will be applied.

Parameters
  • flow_name – The name of the flow to adjust.

  • adjustments – A dict of adjustments to apply to the flow.

  • source_strata (optional) – A whitelist of strata to filter the target flow’s

  • compartments. (destination) –

  • dest_strata (optional) – A whitelist of strata to filter the target flow’s

  • compartments.

Example

Create an adjustment for the ‘recovery’ flow based on location:

strat = Stratification(
    name="location",
    strata=["urban", "rural", "alpine"],
    compartments=["S", "I", "R"]
)
strat.set_flow_adjustments("recovery", {
    "urban": Multiply(1.5),
    "rural": Multiply(0.8),
    "alpine": None, # No adjustment
})
set_mixing_matrix(mixing_matrix: Union[ndarray, Callable[[float], ndarray]])

Sets the mixing matrix for the model. Note that this must apply to all compartments, although this is checked at runtime rather than here.

set_population_split(proportions: Dict[str, float])

Sets how the stratification will split the population between the strata.

Parameters

proportions – A map of proportions to be assigned to each strata.

The supplied proportions must:

  • Specify all strata

  • All be positive

  • Sum to 1 +/- error defined above

validate_population_split(proportions: dict)