vivarium-public-health 2.3.2__py3-none-any.whl → 3.0.0__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.
- vivarium_public_health/_version.py +1 -1
- vivarium_public_health/disease/model.py +23 -21
- vivarium_public_health/disease/models.py +1 -0
- vivarium_public_health/disease/special_disease.py +40 -41
- vivarium_public_health/disease/state.py +42 -125
- vivarium_public_health/disease/transition.py +70 -27
- vivarium_public_health/mslt/delay.py +1 -0
- vivarium_public_health/mslt/disease.py +1 -0
- vivarium_public_health/mslt/intervention.py +1 -0
- vivarium_public_health/mslt/magic_wand_components.py +1 -0
- vivarium_public_health/mslt/observer.py +1 -0
- vivarium_public_health/mslt/population.py +1 -0
- vivarium_public_health/plugins/parser.py +61 -31
- vivarium_public_health/population/add_new_birth_cohorts.py +2 -3
- vivarium_public_health/population/base_population.py +2 -1
- vivarium_public_health/population/mortality.py +83 -80
- vivarium_public_health/{metrics → results}/__init__.py +2 -0
- vivarium_public_health/results/columns.py +22 -0
- vivarium_public_health/results/disability.py +187 -0
- vivarium_public_health/results/disease.py +222 -0
- vivarium_public_health/results/mortality.py +186 -0
- vivarium_public_health/results/observer.py +78 -0
- vivarium_public_health/results/risk.py +138 -0
- vivarium_public_health/results/simple_cause.py +18 -0
- vivarium_public_health/{metrics → results}/stratification.py +10 -8
- vivarium_public_health/risks/__init__.py +1 -2
- vivarium_public_health/risks/base_risk.py +134 -29
- vivarium_public_health/risks/data_transformations.py +65 -326
- vivarium_public_health/risks/distributions.py +315 -145
- vivarium_public_health/risks/effect.py +376 -75
- vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py +61 -89
- vivarium_public_health/treatment/magic_wand.py +1 -0
- vivarium_public_health/treatment/scale_up.py +1 -0
- vivarium_public_health/treatment/therapeutic_inertia.py +1 -0
- vivarium_public_health/utilities.py +17 -2
- {vivarium_public_health-2.3.2.dist-info → vivarium_public_health-3.0.0.dist-info}/METADATA +13 -3
- vivarium_public_health-3.0.0.dist-info/RECORD +49 -0
- {vivarium_public_health-2.3.2.dist-info → vivarium_public_health-3.0.0.dist-info}/WHEEL +1 -1
- vivarium_public_health/metrics/disability.py +0 -118
- vivarium_public_health/metrics/disease.py +0 -136
- vivarium_public_health/metrics/mortality.py +0 -144
- vivarium_public_health/metrics/risk.py +0 -110
- vivarium_public_health/testing/__init__.py +0 -0
- vivarium_public_health/testing/mock_artifact.py +0 -145
- vivarium_public_health/testing/utils.py +0 -71
- vivarium_public_health-2.3.2.dist-info/RECORD +0 -49
- {vivarium_public_health-2.3.2.dist-info → vivarium_public_health-3.0.0.dist-info}/LICENSE.txt +0 -0
- {vivarium_public_health-2.3.2.dist-info → vivarium_public_health-3.0.0.dist-info}/top_level.txt +0 -0
@@ -1,136 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
================
|
3
|
-
Disease Observer
|
4
|
-
================
|
5
|
-
|
6
|
-
This module contains tools for observing disease incidence and prevalence
|
7
|
-
in the simulation.
|
8
|
-
|
9
|
-
"""
|
10
|
-
from typing import Any, Dict, List, Optional
|
11
|
-
|
12
|
-
import pandas as pd
|
13
|
-
from vivarium import Component
|
14
|
-
from vivarium.framework.engine import Builder
|
15
|
-
from vivarium.framework.event import Event
|
16
|
-
from vivarium.framework.population import SimulantData
|
17
|
-
|
18
|
-
from vivarium_public_health.utilities import to_years
|
19
|
-
|
20
|
-
|
21
|
-
class DiseaseObserver(Component):
|
22
|
-
"""Observes disease counts and person time for a cause.
|
23
|
-
|
24
|
-
By default, this observer computes aggregate disease state person time and
|
25
|
-
counts of disease events over the full course of the simulation. It can be
|
26
|
-
configured to add or remove stratification groups to the default groups
|
27
|
-
defined by a ResultsStratifier.
|
28
|
-
|
29
|
-
In the model specification, your configuration for this component should
|
30
|
-
be specified as, e.g.:
|
31
|
-
|
32
|
-
.. code-block:: yaml
|
33
|
-
|
34
|
-
configuration:
|
35
|
-
stratification:
|
36
|
-
cause_name:
|
37
|
-
exclude:
|
38
|
-
- "sex"
|
39
|
-
include:
|
40
|
-
- "sample_stratification"
|
41
|
-
"""
|
42
|
-
|
43
|
-
CONFIGURATION_DEFAULTS = {
|
44
|
-
"stratification": {
|
45
|
-
"disease": {
|
46
|
-
"exclude": [],
|
47
|
-
"include": [],
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
##############
|
53
|
-
# Properties #
|
54
|
-
##############
|
55
|
-
|
56
|
-
@property
|
57
|
-
def configuration_defaults(self) -> Dict[str, Any]:
|
58
|
-
return {
|
59
|
-
"stratification": {
|
60
|
-
self.disease: self.CONFIGURATION_DEFAULTS["stratification"]["disease"]
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
@property
|
65
|
-
def columns_created(self) -> List[str]:
|
66
|
-
return [self.previous_state_column_name]
|
67
|
-
|
68
|
-
@property
|
69
|
-
def columns_required(self) -> Optional[List[str]]:
|
70
|
-
return [self.disease]
|
71
|
-
|
72
|
-
#####################
|
73
|
-
# Lifecycle methods #
|
74
|
-
#####################
|
75
|
-
|
76
|
-
def __init__(self, disease: str):
|
77
|
-
super().__init__()
|
78
|
-
self.disease = disease
|
79
|
-
self.current_state_column_name = self.disease
|
80
|
-
self.previous_state_column_name = f"previous_{self.disease}"
|
81
|
-
|
82
|
-
# noinspection PyAttributeOutsideInit
|
83
|
-
def setup(self, builder: Builder) -> None:
|
84
|
-
self.step_size = builder.time.step_size()
|
85
|
-
self.config = builder.configuration.stratification[self.disease]
|
86
|
-
|
87
|
-
disease_model = builder.components.get_component(f"disease_model.{self.disease}")
|
88
|
-
|
89
|
-
for state in disease_model.states:
|
90
|
-
builder.results.register_observation(
|
91
|
-
name=f"{state.state_id}_person_time",
|
92
|
-
pop_filter=f'alive == "alive" and {self.disease} == "{state.state_id}" and tracked==True',
|
93
|
-
aggregator=self.aggregate_state_person_time,
|
94
|
-
requires_columns=["alive", self.disease],
|
95
|
-
additional_stratifications=self.config.include,
|
96
|
-
excluded_stratifications=self.config.exclude,
|
97
|
-
when="time_step__prepare",
|
98
|
-
)
|
99
|
-
|
100
|
-
for transition in disease_model.transition_names:
|
101
|
-
filter_string = (
|
102
|
-
f'{self.previous_state_column_name} == "{transition.from_state}" '
|
103
|
-
f'and {self.disease} == "{transition.to_state}" '
|
104
|
-
f"and tracked==True "
|
105
|
-
f'and alive == "alive"'
|
106
|
-
)
|
107
|
-
builder.results.register_observation(
|
108
|
-
name=f"{transition}_event_count",
|
109
|
-
pop_filter=filter_string,
|
110
|
-
requires_columns=[self.previous_state_column_name, self.disease],
|
111
|
-
additional_stratifications=self.config.include,
|
112
|
-
excluded_stratifications=self.config.exclude,
|
113
|
-
when="collect_metrics",
|
114
|
-
)
|
115
|
-
|
116
|
-
########################
|
117
|
-
# Event-driven methods #
|
118
|
-
########################
|
119
|
-
|
120
|
-
def on_initialize_simulants(self, pop_data: SimulantData) -> None:
|
121
|
-
self.population_view.update(
|
122
|
-
pd.Series("", index=pop_data.index, name=self.previous_state_column_name)
|
123
|
-
)
|
124
|
-
|
125
|
-
def on_time_step_prepare(self, event: Event) -> None:
|
126
|
-
# This enables tracking of transitions between states
|
127
|
-
prior_state_pop = self.population_view.get(event.index)
|
128
|
-
prior_state_pop[self.previous_state_column_name] = prior_state_pop[self.disease]
|
129
|
-
self.population_view.update(prior_state_pop)
|
130
|
-
|
131
|
-
###############
|
132
|
-
# Aggregators #
|
133
|
-
###############
|
134
|
-
|
135
|
-
def aggregate_state_person_time(self, x: pd.DataFrame) -> float:
|
136
|
-
return len(x) * to_years(self.step_size())
|
@@ -1,144 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
==================
|
3
|
-
Mortality Observer
|
4
|
-
==================
|
5
|
-
|
6
|
-
This module contains tools for observing cause-specific and
|
7
|
-
excess mortality in the simulation, including "other causes".
|
8
|
-
|
9
|
-
"""
|
10
|
-
from typing import Callable, List, Optional
|
11
|
-
|
12
|
-
import pandas as pd
|
13
|
-
from vivarium import Component
|
14
|
-
from vivarium.framework.engine import Builder
|
15
|
-
|
16
|
-
from vivarium_public_health.disease import DiseaseState, RiskAttributableDisease
|
17
|
-
|
18
|
-
|
19
|
-
class MortalityObserver(Component):
|
20
|
-
"""An observer for cause-specific deaths and ylls (including "other causes").
|
21
|
-
|
22
|
-
By default, this counts cause-specific deaths and years of life lost over
|
23
|
-
the full course of the simulation. It can be configured to add or remove
|
24
|
-
stratification groups to the default groups defined by a
|
25
|
-
:class:ResultsStratifier. The aggregate configuration key can be set to
|
26
|
-
True to aggregate all deaths and ylls into a single observation and remove
|
27
|
-
the stratification by cause of death to improve runtime.
|
28
|
-
|
29
|
-
In the model specification, your configuration for this component should
|
30
|
-
be specified as, e.g.:
|
31
|
-
|
32
|
-
.. code-block:: yaml
|
33
|
-
|
34
|
-
configuration:
|
35
|
-
stratification:
|
36
|
-
mortality:
|
37
|
-
exclude:
|
38
|
-
- "sex"
|
39
|
-
include:
|
40
|
-
- "sample_stratification"
|
41
|
-
|
42
|
-
This observer needs to access the has_excess_mortality attribute of the causes
|
43
|
-
we're observing, but this attribute gets defined in the setup of the cause models.
|
44
|
-
As a result, the model specification should list this observer after causes.
|
45
|
-
"""
|
46
|
-
|
47
|
-
CONFIGURATION_DEFAULTS = {
|
48
|
-
"stratification": {
|
49
|
-
"mortality": {
|
50
|
-
"exclude": [],
|
51
|
-
"include": [],
|
52
|
-
"aggregate": False,
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
def __init__(self):
|
58
|
-
super().__init__()
|
59
|
-
self.causes_of_death = ["other_causes"]
|
60
|
-
self.required_death_columns = ["alive", "exit_time"]
|
61
|
-
self.required_yll_columns = [
|
62
|
-
"alive",
|
63
|
-
"cause_of_death",
|
64
|
-
"exit_time",
|
65
|
-
"years_of_life_lost",
|
66
|
-
]
|
67
|
-
|
68
|
-
##############
|
69
|
-
# Properties #
|
70
|
-
##############
|
71
|
-
|
72
|
-
@property
|
73
|
-
def columns_required(self) -> Optional[List[str]]:
|
74
|
-
return [
|
75
|
-
"alive",
|
76
|
-
"years_of_life_lost",
|
77
|
-
"cause_of_death",
|
78
|
-
"exit_time",
|
79
|
-
]
|
80
|
-
|
81
|
-
#####################
|
82
|
-
# Lifecycle methods #
|
83
|
-
#####################
|
84
|
-
|
85
|
-
# noinspection PyAttributeOutsideInit
|
86
|
-
def setup(self, builder: Builder) -> None:
|
87
|
-
self.clock = builder.time.clock()
|
88
|
-
self.config = builder.configuration.stratification.mortality
|
89
|
-
cause_components = builder.components.get_components_by_type(
|
90
|
-
(DiseaseState, RiskAttributableDisease)
|
91
|
-
)
|
92
|
-
self.causes_of_death += [
|
93
|
-
cause.state_id for cause in cause_components if cause.has_excess_mortality
|
94
|
-
]
|
95
|
-
if not self.config.aggregate:
|
96
|
-
for cause_of_death in self.causes_of_death:
|
97
|
-
self._register_mortality_observations(
|
98
|
-
builder, cause_of_death, f'cause_of_death == "{cause_of_death}"'
|
99
|
-
)
|
100
|
-
else:
|
101
|
-
self._register_mortality_observations(builder, "all_causes")
|
102
|
-
|
103
|
-
###################
|
104
|
-
# Private methods #
|
105
|
-
###################
|
106
|
-
|
107
|
-
def _register_mortality_observations(
|
108
|
-
self, builder: Builder, cause: str, additional_pop_filter: str = ""
|
109
|
-
) -> None:
|
110
|
-
pop_filter = (
|
111
|
-
'alive == "dead" and tracked == True'
|
112
|
-
if additional_pop_filter == ""
|
113
|
-
else f'alive == "dead" and tracked == True and {additional_pop_filter}'
|
114
|
-
)
|
115
|
-
builder.results.register_observation(
|
116
|
-
name=f"death_due_to_{cause}",
|
117
|
-
pop_filter=pop_filter,
|
118
|
-
aggregator=self.count_deaths,
|
119
|
-
requires_columns=self.required_death_columns,
|
120
|
-
additional_stratifications=self.config.include,
|
121
|
-
excluded_stratifications=self.config.exclude,
|
122
|
-
when="collect_metrics",
|
123
|
-
)
|
124
|
-
builder.results.register_observation(
|
125
|
-
name=f"ylls_due_to_{cause}",
|
126
|
-
pop_filter=pop_filter,
|
127
|
-
aggregator=self.calculate_ylls,
|
128
|
-
requires_columns=self.required_yll_columns,
|
129
|
-
additional_stratifications=self.config.include,
|
130
|
-
excluded_stratifications=self.config.exclude,
|
131
|
-
when="collect_metrics",
|
132
|
-
)
|
133
|
-
|
134
|
-
###############
|
135
|
-
# Aggregators #
|
136
|
-
###############
|
137
|
-
|
138
|
-
def count_deaths(self, x: pd.DataFrame) -> float:
|
139
|
-
died_of_cause = x["exit_time"] > self.clock()
|
140
|
-
return sum(died_of_cause)
|
141
|
-
|
142
|
-
def calculate_ylls(self, x: pd.DataFrame) -> float:
|
143
|
-
died_of_cause = x["exit_time"] > self.clock()
|
144
|
-
return x.loc[died_of_cause, "years_of_life_lost"].sum()
|
@@ -1,110 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
==============
|
3
|
-
Risk Observers
|
4
|
-
==============
|
5
|
-
|
6
|
-
This module contains tools for observing risk exposure during the simulation.
|
7
|
-
|
8
|
-
"""
|
9
|
-
from typing import Any, Dict, List, Optional
|
10
|
-
|
11
|
-
import pandas as pd
|
12
|
-
from vivarium import Component
|
13
|
-
from vivarium.framework.engine import Builder
|
14
|
-
|
15
|
-
from vivarium_public_health.utilities import to_years
|
16
|
-
|
17
|
-
|
18
|
-
class CategoricalRiskObserver(Component):
|
19
|
-
"""An observer for a categorical risk factor.
|
20
|
-
|
21
|
-
Observes category person time for a risk factor.
|
22
|
-
|
23
|
-
By default, this observer computes aggregate categorical person time
|
24
|
-
over the full course of the simulation. It can be configured to add or
|
25
|
-
remove stratification groups to the default groups defined by a
|
26
|
-
ResultsStratifier.
|
27
|
-
|
28
|
-
In the model specification, your configuration for this component should
|
29
|
-
be specified as, e.g.:
|
30
|
-
|
31
|
-
.. code-block:: yaml
|
32
|
-
|
33
|
-
configuration:
|
34
|
-
stratification:
|
35
|
-
risk_name:
|
36
|
-
exclude:
|
37
|
-
- "sex"
|
38
|
-
include:
|
39
|
-
- "sample_stratification"
|
40
|
-
"""
|
41
|
-
|
42
|
-
CONFIGURATION_DEFAULTS = {
|
43
|
-
"stratification": {
|
44
|
-
"risk": {
|
45
|
-
"exclude": [],
|
46
|
-
"include": [],
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
##############
|
52
|
-
# Properties #
|
53
|
-
##############
|
54
|
-
|
55
|
-
@property
|
56
|
-
def configuration_defaults(self) -> Dict[str, Any]:
|
57
|
-
"""
|
58
|
-
A dictionary containing the defaults for any configurations managed by
|
59
|
-
this component.
|
60
|
-
"""
|
61
|
-
return {
|
62
|
-
"stratification": {
|
63
|
-
f"{self.risk}": self.CONFIGURATION_DEFAULTS["stratification"]["risk"]
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
@property
|
68
|
-
def columns_required(self) -> Optional[List[str]]:
|
69
|
-
return ["alive"]
|
70
|
-
|
71
|
-
#####################
|
72
|
-
# Lifecycle methods #
|
73
|
-
#####################
|
74
|
-
|
75
|
-
def __init__(self, risk: str):
|
76
|
-
"""
|
77
|
-
Parameters
|
78
|
-
----------
|
79
|
-
risk :
|
80
|
-
name of a risk
|
81
|
-
|
82
|
-
"""
|
83
|
-
super().__init__()
|
84
|
-
self.risk = risk
|
85
|
-
self.exposure_pipeline_name = f"{self.risk}.exposure"
|
86
|
-
|
87
|
-
# noinspection PyAttributeOutsideInit
|
88
|
-
def setup(self, builder: Builder) -> None:
|
89
|
-
self.step_size = builder.time.step_size()
|
90
|
-
self.config = builder.configuration.stratification[self.risk]
|
91
|
-
self.categories = builder.data.load(f"risk_factor.{self.risk}.categories")
|
92
|
-
|
93
|
-
for category in self.categories:
|
94
|
-
builder.results.register_observation(
|
95
|
-
name=f"{self.risk}_{category}_person_time",
|
96
|
-
pop_filter=f'alive == "alive" and `{self.exposure_pipeline_name}`=="{category}" and tracked==True',
|
97
|
-
aggregator=self.aggregate_risk_category_person_time,
|
98
|
-
requires_columns=["alive"],
|
99
|
-
requires_values=[self.exposure_pipeline_name],
|
100
|
-
additional_stratifications=self.config.include,
|
101
|
-
excluded_stratifications=self.config.exclude,
|
102
|
-
when="time_step__prepare",
|
103
|
-
)
|
104
|
-
|
105
|
-
###############
|
106
|
-
# Aggregators #
|
107
|
-
###############
|
108
|
-
|
109
|
-
def aggregate_risk_category_person_time(self, x: pd.DataFrame) -> float:
|
110
|
-
return len(x) * to_years(self.step_size())
|
File without changes
|
@@ -1,145 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
==================
|
3
|
-
Mock Data Artifact
|
4
|
-
==================
|
5
|
-
|
6
|
-
This module contains a mock version of the artifact manager for use with
|
7
|
-
testing vivarium_public_health components.
|
8
|
-
|
9
|
-
"""
|
10
|
-
import pandas as pd
|
11
|
-
from vivarium.framework.artifact import ArtifactManager
|
12
|
-
from vivarium.testing_utilities import build_table
|
13
|
-
|
14
|
-
from vivarium_public_health.testing.utils import make_age_bins, make_uniform_pop_data
|
15
|
-
|
16
|
-
MOCKERS = {
|
17
|
-
"cause": {
|
18
|
-
"prevalence": 0,
|
19
|
-
"cause_specific_mortality_rate": 0,
|
20
|
-
"excess_mortality_rate": 0,
|
21
|
-
"remission_rate": 0,
|
22
|
-
"incidence_rate": 0.001,
|
23
|
-
"disability_weight": pd.DataFrame({"value": [0]}),
|
24
|
-
"restrictions": lambda *args, **kwargs: {"yld_only": False},
|
25
|
-
},
|
26
|
-
"risk_factor": {
|
27
|
-
"distribution": lambda *args, **kwargs: "ensemble",
|
28
|
-
"exposure": 120,
|
29
|
-
"exposure_standard_deviation": 15,
|
30
|
-
"relative_risk": build_table(
|
31
|
-
[1.5, "continuous", "test_cause", "incidence_rate"],
|
32
|
-
1990,
|
33
|
-
2017,
|
34
|
-
(
|
35
|
-
"age",
|
36
|
-
"sex",
|
37
|
-
"year",
|
38
|
-
"value",
|
39
|
-
"parameter",
|
40
|
-
"affected_entity",
|
41
|
-
"affected_measure",
|
42
|
-
),
|
43
|
-
),
|
44
|
-
"population_attributable_fraction": build_table(
|
45
|
-
[1, "test_cause_1", "incidence_rate"],
|
46
|
-
1990,
|
47
|
-
2017,
|
48
|
-
("age", "sex", "year", "value", "cause", "affected_measure"),
|
49
|
-
),
|
50
|
-
"tmred": lambda *args, **kwargs: {
|
51
|
-
"distribution": "uniform",
|
52
|
-
"min": 80,
|
53
|
-
"max": 100,
|
54
|
-
"inverted": False,
|
55
|
-
},
|
56
|
-
"exposure_parameters": lambda *args, **kwargs: {
|
57
|
-
"scale": 1,
|
58
|
-
"max_rr": 10,
|
59
|
-
"max_val": 200,
|
60
|
-
"min_val": 0,
|
61
|
-
},
|
62
|
-
"ensemble_weights": lambda *args, **kwargs: pd.DataFrame({"norm": 1}, index=[0]),
|
63
|
-
},
|
64
|
-
"sequela": {
|
65
|
-
"prevalence": 0,
|
66
|
-
"cause_specific_mortality_rate": 0,
|
67
|
-
"excess_mortality_rate": 0,
|
68
|
-
"remission_rate": 0,
|
69
|
-
"incidence_rate": 0.001,
|
70
|
-
"disability_weight": pd.DataFrame({"value": [0]}),
|
71
|
-
},
|
72
|
-
"etiology": {
|
73
|
-
"population_attributable_fraction": build_table(
|
74
|
-
[1, "incidence_rate"],
|
75
|
-
1990,
|
76
|
-
2017,
|
77
|
-
("age", "sex", "year", "value", "affected_measure"),
|
78
|
-
),
|
79
|
-
},
|
80
|
-
"healthcare_entity": {
|
81
|
-
"cost": build_table(
|
82
|
-
[0, "outpatient_visits"],
|
83
|
-
1990,
|
84
|
-
2017,
|
85
|
-
("age", "sex", "year", "value", "healthcare_entity"),
|
86
|
-
),
|
87
|
-
"utilization_rate": 0,
|
88
|
-
},
|
89
|
-
# FIXME: this is a hack to get the MockArtifact to use the correct value
|
90
|
-
"population.location": "Kenya",
|
91
|
-
"population": {
|
92
|
-
"age_bins": make_age_bins(),
|
93
|
-
"structure": make_uniform_pop_data(),
|
94
|
-
"theoretical_minimum_risk_life_expectancy": (
|
95
|
-
build_table(98.0, 1990, 1990)
|
96
|
-
.query('sex=="Female"')
|
97
|
-
.filter(["age_start", "age_end", "value"])
|
98
|
-
),
|
99
|
-
},
|
100
|
-
}
|
101
|
-
|
102
|
-
|
103
|
-
class MockArtifact:
|
104
|
-
def __init__(self):
|
105
|
-
self.mocks = MOCKERS.copy()
|
106
|
-
|
107
|
-
def load(self, entity_key):
|
108
|
-
if entity_key in self.mocks:
|
109
|
-
return self.mocks[entity_key]
|
110
|
-
|
111
|
-
entity_type, *_, entity_measure = entity_key.split(".")
|
112
|
-
assert entity_type in self.mocks
|
113
|
-
assert entity_measure in self.mocks[entity_type]
|
114
|
-
value = self.mocks[entity_type][entity_measure]
|
115
|
-
|
116
|
-
if callable(value):
|
117
|
-
value = value(entity_key)
|
118
|
-
elif not isinstance(value, (pd.DataFrame, pd.Series)):
|
119
|
-
value = build_table(value, 1990, 2018)
|
120
|
-
|
121
|
-
return value
|
122
|
-
|
123
|
-
def write(self, entity_key, data):
|
124
|
-
self.mocks[entity_key] = data
|
125
|
-
|
126
|
-
|
127
|
-
class MockArtifactManager(ArtifactManager):
|
128
|
-
def __init__(self):
|
129
|
-
self.artifact = self._load_artifact(None)
|
130
|
-
|
131
|
-
@property
|
132
|
-
def name(self):
|
133
|
-
return "mock_artifact_manager"
|
134
|
-
|
135
|
-
def setup(self, builder):
|
136
|
-
pass
|
137
|
-
|
138
|
-
def load(self, entity_key, *args, **kwargs):
|
139
|
-
return self.artifact.load(entity_key)
|
140
|
-
|
141
|
-
def write(self, entity_key, data):
|
142
|
-
self.artifact.write(entity_key, data)
|
143
|
-
|
144
|
-
def _load_artifact(self, _):
|
145
|
-
return MockArtifact()
|
@@ -1,71 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
=================
|
3
|
-
Testing Utilities
|
4
|
-
=================
|
5
|
-
|
6
|
-
This module contains data generation tools for testing vivarium_public_health
|
7
|
-
components.
|
8
|
-
|
9
|
-
"""
|
10
|
-
from itertools import product
|
11
|
-
|
12
|
-
import numpy as np
|
13
|
-
import pandas as pd
|
14
|
-
|
15
|
-
|
16
|
-
def make_uniform_pop_data(age_bin_midpoint=False):
|
17
|
-
age_bins = [(b.age_start, b.age_end) for b in make_age_bins().itertuples()]
|
18
|
-
sexes = ("Male", "Female")
|
19
|
-
years = zip(range(1990, 2018), range(1991, 2019))
|
20
|
-
locations = (1, 2)
|
21
|
-
|
22
|
-
age_bins, sexes, years, locations = zip(*product(age_bins, sexes, years, locations))
|
23
|
-
mins, maxes = zip(*age_bins)
|
24
|
-
year_starts, year_ends = zip(*years)
|
25
|
-
|
26
|
-
pop = pd.DataFrame(
|
27
|
-
{
|
28
|
-
"age_start": mins,
|
29
|
-
"age_end": maxes,
|
30
|
-
"sex": sexes,
|
31
|
-
"year_start": year_starts,
|
32
|
-
"year_end": year_ends,
|
33
|
-
"location": locations,
|
34
|
-
"value": 100 * (np.array(maxes) - np.array(mins)),
|
35
|
-
}
|
36
|
-
)
|
37
|
-
if age_bin_midpoint: # used for population tests
|
38
|
-
pop["age"] = pop.apply(lambda row: (row["age_start"] + row["age_end"]) / 2, axis=1)
|
39
|
-
return pop
|
40
|
-
|
41
|
-
|
42
|
-
def make_age_bins():
|
43
|
-
idx = pd.MultiIndex.from_tuples(
|
44
|
-
[
|
45
|
-
(0.0, 0.01917808, "Early Neonatal"),
|
46
|
-
(0.01917808, 0.07671233, "Late Neonatal"),
|
47
|
-
(0.07671233, 1.0, "Post Neonatal"),
|
48
|
-
(1.0, 5.0, "1 to 4"),
|
49
|
-
(5.0, 10.0, "5 to 9"),
|
50
|
-
(10.0, 15.0, "10 to 14"),
|
51
|
-
(15.0, 20.0, "15 to 19"),
|
52
|
-
(20.0, 25.0, "20 to 24"),
|
53
|
-
(25.0, 30.0, "25 to 29"),
|
54
|
-
(30.0, 35.0, "30 to 34"),
|
55
|
-
(35.0, 40.0, "35 to 39"),
|
56
|
-
(40.0, 45.0, "40 to 44"),
|
57
|
-
(45.0, 50.0, "45 to 49"),
|
58
|
-
(50.0, 55.0, "50 to 54"),
|
59
|
-
(55.0, 60.0, "55 to 59"),
|
60
|
-
(60.0, 65.0, "60 to 64"),
|
61
|
-
(65.0, 70.0, "65 to 69"),
|
62
|
-
(70.0, 75.0, "70 to 74"),
|
63
|
-
(75.0, 80.0, "75 to 79"),
|
64
|
-
(80.0, 85.0, "80 to 84"),
|
65
|
-
(85.0, 90.0, "85 to 89"),
|
66
|
-
(90.0, 95.0, "90 to 94"),
|
67
|
-
(95.0, 125.0, "95 plus"),
|
68
|
-
],
|
69
|
-
names=["age_start", "age_end", "age_group_name"],
|
70
|
-
)
|
71
|
-
return pd.DataFrame(index=idx).reset_index()
|
@@ -1,49 +0,0 @@
|
|
1
|
-
vivarium_public_health/__about__.py,sha256=RgWycPypKZS80TpSX7o41cREnG8PfguNHDHLuLyl820,487
|
2
|
-
vivarium_public_health/__init__.py,sha256=tomMOl3PI7O8GdxDWGBiBjT0Bwd31GpyQTYTzwIv108,361
|
3
|
-
vivarium_public_health/_version.py,sha256=J4CRnpR3v72FGOMp8gqSua_XWZpAfXuqgVWiQFB-gTY,22
|
4
|
-
vivarium_public_health/utilities.py,sha256=_X9sZQ7flsi2sVWQ9zrf8GJw8QwZsPZm3NUjx1gu7bM,2555
|
5
|
-
vivarium_public_health/disease/__init__.py,sha256=RuuiRcvAJfX9WQGt_WZZjxN7Cu3E5rMTmuaRS-UaFPM,419
|
6
|
-
vivarium_public_health/disease/model.py,sha256=9Ru3mg3UUp3h1W0y-1xkWjQBgxqSq-LXM0ByiEcNmGA,8332
|
7
|
-
vivarium_public_health/disease/models.py,sha256=uiB2qUlxBsPPPmHJ8Cgot_T1ItZ8RYSNVOBtxtn93Y0,3478
|
8
|
-
vivarium_public_health/disease/special_disease.py,sha256=gl8aK0z6afCxiCZxgJafLe4xmbR91zk3079hsi2pUAw,14751
|
9
|
-
vivarium_public_health/disease/state.py,sha256=wTSiWKXgJ4k9kr0p8oC3gAHil0-zQPOifNoBftHnTRw,24837
|
10
|
-
vivarium_public_health/disease/transition.py,sha256=Or5nucRzeGG-UuE_CGkPZ9qE35-Ed9I9LWHj4rjknCc,5334
|
11
|
-
vivarium_public_health/metrics/__init__.py,sha256=bWAvvdCm_7RPIazo12qFohA2x5-_EV6ceV8IhKS37sk,209
|
12
|
-
vivarium_public_health/metrics/disability.py,sha256=zm0vAG00wj44CHjYGdT2_pebgARa3XXIerrR06t80rc,3984
|
13
|
-
vivarium_public_health/metrics/disease.py,sha256=_WQYjd6FRrxRs1Oj8NR9ZmcbXVvsHqX_hods10hwHzU,4546
|
14
|
-
vivarium_public_health/metrics/mortality.py,sha256=B1AX-N4aO1Jd2NEJ_yMC1NHaDr4pEXmQxNm5kXoLz8w,4826
|
15
|
-
vivarium_public_health/metrics/risk.py,sha256=ANwgwpasX-5t0OHMQysV8p_cM86NL2bV6za1FM0JR88,3201
|
16
|
-
vivarium_public_health/metrics/stratification.py,sha256=_ChQy8yeP09wFKne4UPPiUEfCKDM6UGfHl4moKCjoNQ,4612
|
17
|
-
vivarium_public_health/mslt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
-
vivarium_public_health/mslt/delay.py,sha256=4JiSID5bt2xB1DQR1FX1f0NV947HKtwfk-D32C54kbg,22581
|
19
|
-
vivarium_public_health/mslt/disease.py,sha256=JWe_A6X5NyDcTXf-HIeSSUv0DCwj27aIwRXVWzjXCVQ,15683
|
20
|
-
vivarium_public_health/mslt/intervention.py,sha256=q6-ZHYFuV9o7WKlHMpiFAsEH2fYzwOayY120eDAOQ5U,10335
|
21
|
-
vivarium_public_health/mslt/magic_wand_components.py,sha256=7sy_7fa0R5pk5XPdt9-AfK005JV3em4Tvu4L4xeg4g0,3980
|
22
|
-
vivarium_public_health/mslt/observer.py,sha256=Z0aWLrlSjxLuYqzXarNunJ2Xqei4R9nX03dnE6uvr4o,13940
|
23
|
-
vivarium_public_health/mslt/population.py,sha256=R5Z7aBf63LDbasPVMMI0HTh41FIL_OAhYk0qQWf_-lU,7285
|
24
|
-
vivarium_public_health/plugins/__init__.py,sha256=oBW_zfgG_LbwfgTDjUe0btfy9FaDvAbtXho1zQFnz0Y,76
|
25
|
-
vivarium_public_health/plugins/parser.py,sha256=uhBw5t-Lmb8YDN2GvVG93l50ZuCIsg4VocSA5T_wz3w,31789
|
26
|
-
vivarium_public_health/population/__init__.py,sha256=17rtbcNVK5LtCCxAex7P7Q_vYpwbeTepyf3nazS90Yc,225
|
27
|
-
vivarium_public_health/population/add_new_birth_cohorts.py,sha256=qNsZjvaJ7Et8_Kw7JNyRshHHRA3pEQMM4TSqCp48Gr4,9092
|
28
|
-
vivarium_public_health/population/base_population.py,sha256=CeYrocZh5oEJ1HR3Zr_-erUQHElUeV8WtmL-1iVyHEo,17080
|
29
|
-
vivarium_public_health/population/data_transformations.py,sha256=PsvE1-S-Q_K4viBgF2Ss0DaaoH0WyhRX26ZJYwJ0O84,22322
|
30
|
-
vivarium_public_health/population/mortality.py,sha256=w1Oxb958LjUkNwxJ0vdA3TZndpeNiaH3d7RukLas_oQ,10085
|
31
|
-
vivarium_public_health/risks/__init__.py,sha256=XvX12RgD0iF5PBoc2StsOhxJmK1FP-RaAYrjIT9MfDs,232
|
32
|
-
vivarium_public_health/risks/base_risk.py,sha256=6D7YlxQOdQm-Kw5_vjpQmFqU7spF-lTy14WEEefRQlA,6494
|
33
|
-
vivarium_public_health/risks/data_transformations.py,sha256=-nEbytxaQEB1zaAacA46A3WATeKle2FvrnePx-NPCeg,19602
|
34
|
-
vivarium_public_health/risks/distributions.py,sha256=EYMjhOmci4O7orU2-qQ55uOzqplqByn4GokbKgcZgfQ,10800
|
35
|
-
vivarium_public_health/risks/effect.py,sha256=GH_n5j6RQY-DdV0hSH-_Qo10lXVZRdMyANh6wfrLtiI,7295
|
36
|
-
vivarium_public_health/risks/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
37
|
-
vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py,sha256=G8-KMklSwd2Sl29oMX8WFPKKv1tBtRUOqLuAmoxOos0,18027
|
38
|
-
vivarium_public_health/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
|
-
vivarium_public_health/testing/mock_artifact.py,sha256=T6Fw0rSEGfDr7Lqq-YxcJBmZtjhybDTE9w9-SeWYYco,4244
|
40
|
-
vivarium_public_health/testing/utils.py,sha256=bbAEGw5kRzVB_80uc5u5mp47NMj2xD6Nw7vlEsT_-Wg,2199
|
41
|
-
vivarium_public_health/treatment/__init__.py,sha256=wONElu9aJbBYwpYIovYPYaN_GYfVhPXtTeFWSdQMgA0,222
|
42
|
-
vivarium_public_health/treatment/magic_wand.py,sha256=iPKFN3VjfiMy_XvN94UqM-FUrGuI0ULwmOdAGdOepYQ,1979
|
43
|
-
vivarium_public_health/treatment/scale_up.py,sha256=EkuEAmKaW7AvPWDqDa9WJ2Iy_yiKFytsJu8HVli5Lrg,7078
|
44
|
-
vivarium_public_health/treatment/therapeutic_inertia.py,sha256=VwZ7t90zzfGoBusduIvcE4lDe5zTvzmHiUNB3u2I52Y,2339
|
45
|
-
vivarium_public_health-2.3.2.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
|
46
|
-
vivarium_public_health-2.3.2.dist-info/METADATA,sha256=UWxOYZMSTZHmUbO4DQhLZ4maatsr-kGX_1Paks8518Q,3590
|
47
|
-
vivarium_public_health-2.3.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
48
|
-
vivarium_public_health-2.3.2.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
|
49
|
-
vivarium_public_health-2.3.2.dist-info/RECORD,,
|
{vivarium_public_health-2.3.2.dist-info → vivarium_public_health-3.0.0.dist-info}/LICENSE.txt
RENAMED
File without changes
|
{vivarium_public_health-2.3.2.dist-info → vivarium_public_health-3.0.0.dist-info}/top_level.txt
RENAMED
File without changes
|