vivarium-public-health 4.3.2__py3-none-any.whl → 4.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,139 +0,0 @@
1
- """
2
- ======================
3
- Intervention Observers
4
- ======================
5
-
6
- This module contains tools for observing risk exposure during the simulation.
7
-
8
- """
9
-
10
- import pandas as pd
11
- from vivarium.framework.engine import Builder
12
-
13
- from vivarium_public_health.results.columns import COLUMNS
14
- from vivarium_public_health.results.observer import PublicHealthObserver
15
- from vivarium_public_health.utilities import to_years
16
-
17
-
18
- class CategoricalInterventionObserver(PublicHealthObserver):
19
- """
20
- A class for observering interventions. This class has the same implementation as
21
- the 'CategoricalRiskObserver' class.
22
-
23
- """
24
-
25
- @property
26
- def columns_required(self) -> list[str] | None:
27
- """The columns required by this observer."""
28
- return ["alive"]
29
-
30
- #####################
31
- # Lifecycle methods #
32
- #####################
33
-
34
- def __init__(self, intervention: str) -> None:
35
- """Constructor for this observer.
36
-
37
- Parameters
38
- ----------
39
- intervention
40
- The name of the intervention being observed
41
- """
42
- super().__init__()
43
- self.intervention = intervention
44
- self.coverage_pipeline_name = f"{self.intervention}.coverage"
45
-
46
- #################
47
- # Setup methods #
48
- #################
49
-
50
- def setup(self, builder: Builder) -> None:
51
- """Set up the observer."""
52
- self.step_size = builder.time.step_size()
53
- self.categories = builder.data.load(f"intervention.{self.intervention}.categories")
54
-
55
- def get_configuration_name(self) -> str:
56
- return self.intervention
57
-
58
- def register_observations(self, builder: Builder) -> None:
59
- """Register a stratification and observation.
60
-
61
- Notes
62
- -----
63
- While it's typical for all stratification registrations to be encapsulated
64
- in a single class (i.e. the
65
- :class:ResultsStratifier <vivarium_public_health.results.stratification.ResultsStratifier),
66
- this observer registers an additional one. While it could be registered
67
- in the ``ResultsStratifier`` as well, it is specific to this observer and
68
- so it is registered here while we have easy access to the required categories
69
- and value names.
70
- """
71
- builder.results.register_stratification(
72
- f"{self.intervention}",
73
- list(self.categories.keys()),
74
- requires_values=[self.coverage_pipeline_name],
75
- )
76
- self.register_adding_observation(
77
- builder=builder,
78
- name=f"person_time_{self.intervention}",
79
- pop_filter=f'alive == "alive" and tracked==True',
80
- when="time_step__prepare",
81
- requires_columns=["alive"],
82
- requires_values=[self.coverage_pipeline_name],
83
- additional_stratifications=self.configuration.include + [self.intervention],
84
- excluded_stratifications=self.configuration.exclude,
85
- aggregator=self.aggregate_intervention_category_person_time,
86
- )
87
-
88
- ###############
89
- # Aggregators #
90
- ###############
91
-
92
- def aggregate_intervention_category_person_time(self, x: pd.DataFrame) -> float:
93
- """Aggregate the person time for this time step."""
94
- return len(x) * to_years(self.step_size())
95
-
96
- ##############################
97
- # Results formatting methods #
98
- ##############################
99
-
100
- def format(self, measure: str, results: pd.DataFrame) -> pd.DataFrame:
101
- """Rename the appropriate column to 'sub_entity'.
102
-
103
- The primary thing this method does is rename the risk column
104
- to 'sub_entity'. We do this here instead of the 'get_sub_entity_column'
105
- method simply because we do not want the risk column at all. If we keep
106
- it here and then return it as the sub-entity column later, the final
107
- results would have both.
108
-
109
- Parameters
110
- ----------
111
- measure
112
- The measure.
113
- results
114
- The results to format.
115
-
116
- Returns
117
- -------
118
- The formatted results.
119
- """
120
- results = results.reset_index()
121
- results.rename(columns={self.intervention: COLUMNS.SUB_ENTITY}, inplace=True)
122
- return results
123
-
124
- def get_measure_column(self, measure: str, results: pd.DataFrame) -> pd.Series:
125
- """Get the 'measure' column values."""
126
- return pd.Series("person_time", index=results.index)
127
-
128
- def get_entity_type_column(self, measure: str, results: pd.DataFrame) -> pd.Series:
129
- """Get the 'entity_type' column values."""
130
- return pd.Series("rei", index=results.index)
131
-
132
- def get_entity_column(self, measure: str, results: pd.DataFrame) -> pd.Series:
133
- """Get the 'entity' column values."""
134
- return pd.Series(self.intervention, index=results.index)
135
-
136
- def get_sub_entity_column(self, measure: str, results: pd.DataFrame) -> pd.Series:
137
- """Get the 'sub_entity' column values."""
138
- # The sub-entity col was created in the 'format' method
139
- return results[COLUMNS.SUB_ENTITY]
@@ -1,85 +0,0 @@
1
- from typing import NamedTuple
2
-
3
- from vivarium_public_health.exposure import Exposure
4
- from vivarium_public_health.exposure.effect import ExposureEffect
5
- from vivarium_public_health.utilities import EntityString, TargetString
6
-
7
-
8
- class Intervention(Exposure):
9
- """A model for an intervention defined by coverage (access to intervention).
10
-
11
- This component models access to an intervention as a dichotomous exposure where
12
- simulants are either covered or uncovered by the intervention.
13
-
14
- For example,
15
-
16
- #. vaccination coverage where simulants are either vaccinated (covered) or
17
- unvaccinated (uncovered).
18
- #. treatment access where simulants either have access to treatment (covered)
19
- or do not have access (uncovered).
20
-
21
- This component can source data either from a key in an Artifact
22
- ("intervention.intervention_name.coverage") or from parameters
23
- supplied in the configuration. If data is derived from the configuration, it
24
- must be an integer or float expressing the desired coverage level or a
25
- covariate name that is intended to be used as a proxy. For example, for an
26
- intervention named "intervention", the configuration could look like this:
27
-
28
- .. code-block:: yaml
29
-
30
- configuration:
31
- intervention.intervention_name:
32
- coverage: 0.8
33
-
34
- Interventions should be configured with names in the format of
35
- "intervention.intervention_name".
36
-
37
- """
38
-
39
- @property
40
- def exposure_type(self) -> str:
41
- """The measure of the intervention access."""
42
- return "coverage"
43
-
44
- @property
45
- def dichotomous_exposure_category_names(self) -> NamedTuple:
46
- """The name of the covered and uncovered categories for this intervention."""
47
-
48
- class __Categories(NamedTuple):
49
- exposed: str = "covered"
50
- unexposed: str = "uncovered"
51
-
52
- categories = __Categories()
53
- return categories
54
-
55
-
56
- class InterventionEffect(ExposureEffect):
57
- """A component to model the effect of an intervention on an affected entity's target rate.
58
-
59
- This component models how intervention coverage affects the rate of some target
60
- entity (e.g., disease incidence, mortality, disability). The effect is typically
61
- protective, reducing the target rate for covered simulants compared to uncovered
62
- simulants.
63
-
64
- This component can source data either from builder.data or from parameters
65
- supplied in the configuration. The data should specify the relative risk or
66
- rate ratio associated with intervention coverage.
67
-
68
- For example, an intervention effect might model how vaccination coverage affects
69
- disease incidence, where vaccinated individuals have a lower risk of disease
70
- compared to unvaccinated individuals.
71
-
72
- For an exposure named 'exposure_name' that affects 'affected_entity' and 'affected_cause',
73
- the configuration would look like:
74
-
75
- .. code-block:: yaml
76
-
77
- configuration:
78
- intervention_effect.exposure_name_on_affected_target:
79
- exposure_parameters: 2
80
- incidence_rate: 10
81
-
82
- """
83
-
84
- def get_name(self, intervention: EntityString, target: TargetString) -> str:
85
- return f"intervention_effect.{intervention.name}_on_{target}"