compartment

This module contains a class used to represent compartments.

class summer2.compartment.Compartment(name: str, strata: Optional[Dict[str, str]] = None, idx: Optional[int] = None, tags: Optional[list] = None)

Bases: object

A single compartment in the compartmental model. Each compartment is defined by its name and stratum/strata if stratified. A compartment does not store the number of occupants - this data is tracked elsewhere in CompartmentalModel.

Parameters
  • name – The compartment’s name

  • strata – A mapping which defines this compartment’s strata for each stratification.

Example

Create a Compartment with no stratifications:

comp = Compartment("susceptible")

Create a Compartment with age and location stratifications:

comp = Compartment(
    name="susceptible"
    strata={
        "age": "young",
        "location": "rural",
    }
)
static deserialize(s: str)

Converts a string into a Compartment

has_name(comp) bool

Returns True if this compartment has the same root name as another.

has_name_in_list(comps: list) bool

Returns True if this compartment has the same root name as any compartment in the provided list.

has_strata(strata: dict) bool
has_stratum(stratification: str, stratum: str) bool
is_match(name: str, strata: dict) bool

Determines whether this compartment matches the supplied name and strata. A partial strata match, where this compartment has more strata than are supplied returns True.

serialize() str

Returns a string representation of the compartment

stratify(stratification_name: str, stratum_name: str)

Returns a copy of the Compartment with a new stratification applied to it.

Parameters
  • stratification_name – The name (or purpose) of the new stratification.

  • stratum_name – The stratum to be assigned to the new Compartment.

Returns

The new, stratified compartment.

Return type

Compartment