Observers

This module contains tools for recording various outputs of interest in multi-state lifetable simulations.

vivarium_public_health.mslt.observer.output_file(config, suffix, sep='_', ext='csv')[source]

Determine the output file name for an observer, based on the prefix defined in config.observer.output_prefix and the (optional) config.input_data.input_draw_number.

Parameters:
  • config – The builder configuration object.

  • suffix – The observer-specific suffix.

  • sep – The separator between prefix, suffix, and draw number.

  • ext – The output file extension.

class vivarium_public_health.mslt.observer.MorbidityMortality(output_suffix='mm')[source]

This class records the all-cause morbidity and mortality rates for each cohort at each year of the simulation.

Parameters:

output_suffix (str) – The suffix for the CSV file in which to record the morbidity and mortality data.

property columns_required: List[str] | None

Provides names of columns required by the component.

Returns:

Names of required columns not created by this component. An empty list means all available columns are needed. None means no additional columns are necessary.

Return type:

Optional[List[str]]

setup(builder)[source]

Defines custom actions this component needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the component. By default, it does nothing.

Parameters:

builder (Builder) – The builder object used to set up the component.

Return type:

None

on_collect_metrics(event)[source]

Method that vivarium will run during the collect_metrics event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the collect_metrics event.

Parameters:

event (Event) – The event object associated with the collect_metrics event.

Return type:

None

on_simulation_end(event)[source]

Method that vivarium will run during the simulation_end event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the simulation_end event.

Parameters:

event (Event) – The event object associated with the simulation_end event.

Return type:

None

calculate_LE(table, py_col, denom_col)[source]

Calculate the life expectancy for each cohort at each time-step.

Parameters:
  • table – The population life table.

  • py_col – The name of the person-years column.

  • denom_col – The name of the population denominator column.

Returns:

  • The life expectancy for each table row, represented as a

  • pandas.Series object.

class vivarium_public_health.mslt.observer.Disease(disease, output_suffix=None)[source]

This class records the disease incidence rate and disease prevalence for each cohort at each year of the simulation.

Parameters:
  • disease (str) – The name of the chronic disease.

  • output_suffix (str | None) – The suffix for the CSV file in which to record the disease data.

property columns_required: List[str] | None

Provides names of columns required by the component.

Returns:

Names of required columns not created by this component. An empty list means all available columns are needed. None means no additional columns are necessary.

Return type:

Optional[List[str]]

setup(builder)[source]

Defines custom actions this component needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the component. By default, it does nothing.

Parameters:

builder (Builder) – The builder object used to set up the component.

Return type:

None

on_collect_metrics(event)[source]

Method that vivarium will run during the collect_metrics event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the collect_metrics event.

Parameters:

event (Event) – The event object associated with the collect_metrics event.

Return type:

None

on_simulation_end(event)[source]

Method that vivarium will run during the simulation_end event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the simulation_end event.

Parameters:

event (Event) – The event object associated with the simulation_end event.

Return type:

None

class vivarium_public_health.mslt.observer.TobaccoPrevalence(output_suffix='tobacco')[source]

This class records the prevalence of tobacco use in the population.

Parameters:

output_suffix (str) – The suffix for the CSV file in which to record the prevalence data.

property columns_required: List[str] | None

Provides names of columns required by the component.

Returns:

Names of required columns not created by this component. An empty list means all available columns are needed. None means no additional columns are necessary.

Return type:

Optional[List[str]]

setup(builder)[source]

Defines custom actions this component needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the component. By default, it does nothing.

Parameters:

builder (Builder) – The builder object used to set up the component.

Return type:

None

get_bin_names()[source]

Return the bin names for both the BAU and the intervention scenario.

These names take the following forms:

"name.no"

The number of people who have never been exposed.

"name.yes"

The number of people currently exposed.

"name.N"

The number of people N years post-exposure.

The final bin is the number of people \(\ge N\) years post-exposure.

The intervention bin names take the form "name_intervention.X".

on_collect_metrics(event)[source]

Method that vivarium will run during the collect_metrics event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the collect_metrics event.

Parameters:

event (Event) – The event object associated with the collect_metrics event.

Return type:

None

on_simulation_end(event)[source]

Method that vivarium will run during the simulation_end event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the simulation_end event.

Parameters:

event (Event) – The event object associated with the simulation_end event.

Return type:

None