vivarium-public-health 4.1.1__py3-none-any.whl → 4.2.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/risks/implementations/low_birth_weight_and_short_gestation.py +88 -10
- {vivarium_public_health-4.1.1.dist-info → vivarium_public_health-4.2.0.dist-info}/METADATA +1 -1
- {vivarium_public_health-4.1.1.dist-info → vivarium_public_health-4.2.0.dist-info}/RECORD +7 -7
- {vivarium_public_health-4.1.1.dist-info → vivarium_public_health-4.2.0.dist-info}/WHEEL +1 -1
- {vivarium_public_health-4.1.1.dist-info → vivarium_public_health-4.2.0.dist-info}/licenses/LICENSE.txt +0 -0
- {vivarium_public_health-4.1.1.dist-info → vivarium_public_health-4.2.0.dist-info}/top_level.txt +0 -0
@@ -1 +1 @@
|
|
1
|
-
__version__ = "4.
|
1
|
+
__version__ = "4.2.0"
|
@@ -14,6 +14,8 @@ from typing import Any
|
|
14
14
|
|
15
15
|
import numpy as np
|
16
16
|
import pandas as pd
|
17
|
+
from layered_config_tree import ConfigurationError
|
18
|
+
from loguru import logger
|
17
19
|
from vivarium.framework.engine import Builder
|
18
20
|
from vivarium.framework.lifecycle import LifeCycleError
|
19
21
|
from vivarium.framework.population import SimulantData
|
@@ -21,9 +23,12 @@ from vivarium.framework.resource import Resource
|
|
21
23
|
from vivarium.framework.values import Pipeline
|
22
24
|
|
23
25
|
from vivarium_public_health.risks import Risk, RiskEffect
|
24
|
-
from vivarium_public_health.risks.data_transformations import
|
26
|
+
from vivarium_public_health.risks.data_transformations import (
|
27
|
+
get_exposure_post_processor,
|
28
|
+
pivot_categorical,
|
29
|
+
)
|
25
30
|
from vivarium_public_health.risks.distributions import PolytomousDistribution
|
26
|
-
from vivarium_public_health.utilities import get_lookup_columns, to_snake_case
|
31
|
+
from vivarium_public_health.utilities import EntityString, get_lookup_columns, to_snake_case
|
27
32
|
|
28
33
|
CATEGORICAL = "categorical"
|
29
34
|
BIRTH_WEIGHT = "birth_weight"
|
@@ -31,16 +36,76 @@ GESTATIONAL_AGE = "gestational_age"
|
|
31
36
|
|
32
37
|
|
33
38
|
class LBWSGDistribution(PolytomousDistribution):
|
39
|
+
@property
|
40
|
+
def categories(self) -> list[str]:
|
41
|
+
# These need to be sorted so the cumulative sum is in the correct order of categories
|
42
|
+
# and results are therefore reproducible and correct
|
43
|
+
return sorted(self.lookup_tables[self.exposure_key].value_columns)
|
34
44
|
|
35
45
|
#################
|
36
46
|
# Setup methods #
|
37
47
|
#################
|
38
48
|
|
49
|
+
def __init__(
|
50
|
+
self,
|
51
|
+
risk: EntityString,
|
52
|
+
distribution_type: str,
|
53
|
+
exposure_data: int | float | pd.DataFrame | None = None,
|
54
|
+
) -> None:
|
55
|
+
super().__init__(risk, distribution_type, exposure_data)
|
56
|
+
self.exposure_key = "birth_exposure"
|
57
|
+
|
39
58
|
# noinspection PyAttributeOutsideInit
|
40
59
|
def setup(self, builder: Builder) -> None:
|
41
60
|
super().setup(builder)
|
42
61
|
self.category_intervals = self.get_category_intervals(builder)
|
43
62
|
|
63
|
+
def build_all_lookup_tables(self, builder: Builder) -> None:
|
64
|
+
try:
|
65
|
+
birth_exposure_data = self.get_data(
|
66
|
+
builder, self.configuration["data_sources"]["birth_exposure"]
|
67
|
+
)
|
68
|
+
birth_exposure_value_columns = self.get_exposure_value_columns(
|
69
|
+
birth_exposure_data
|
70
|
+
)
|
71
|
+
|
72
|
+
if isinstance(birth_exposure_data, pd.DataFrame):
|
73
|
+
birth_exposure_data = pivot_categorical(
|
74
|
+
builder, self.risk, birth_exposure_data, "parameter"
|
75
|
+
)
|
76
|
+
|
77
|
+
self.lookup_tables["birth_exposure"] = self.build_lookup_table(
|
78
|
+
builder, birth_exposure_data, birth_exposure_value_columns
|
79
|
+
)
|
80
|
+
except ConfigurationError:
|
81
|
+
logger.warning("Birth exposure data for LBWSG is missing from the simulation")
|
82
|
+
try:
|
83
|
+
super().build_all_lookup_tables(builder)
|
84
|
+
except ConfigurationError:
|
85
|
+
logger.warning("The data for LBWSG exposure is missing from the simulation.")
|
86
|
+
|
87
|
+
if (
|
88
|
+
"birth_exposure" not in self.lookup_tables
|
89
|
+
and "exposure" not in self.lookup_tables
|
90
|
+
):
|
91
|
+
raise ConfigurationError(
|
92
|
+
"The LBWSG distribution requires either 'birth_exposure' or 'exposure' data to be "
|
93
|
+
"available in the simulation."
|
94
|
+
)
|
95
|
+
|
96
|
+
def get_exposure_parameter_pipeline(self, builder: Builder) -> Pipeline:
|
97
|
+
lookup_columns = []
|
98
|
+
if "exposure" in self.lookup_tables:
|
99
|
+
lookup_columns.extend(get_lookup_columns([self.lookup_tables["exposure"]]))
|
100
|
+
if "birth_exposure" in self.lookup_tables:
|
101
|
+
lookup_columns.extend(get_lookup_columns([self.lookup_tables["birth_exposure"]]))
|
102
|
+
return builder.value.register_value_producer(
|
103
|
+
self.parameters_pipeline_name,
|
104
|
+
source=lambda index: self.lookup_tables[self.exposure_key](index),
|
105
|
+
component=self,
|
106
|
+
required_resources=list(set(lookup_columns)),
|
107
|
+
)
|
108
|
+
|
44
109
|
def get_category_intervals(self, builder: Builder) -> dict[str, dict[str, pd.Interval]]:
|
45
110
|
"""Gets the intervals for each category.
|
46
111
|
|
@@ -203,8 +268,9 @@ class LBWSGRisk(Risk):
|
|
203
268
|
@property
|
204
269
|
def configuration_defaults(self) -> dict[str, Any]:
|
205
270
|
configuration_defaults = super().configuration_defaults
|
271
|
+
# Add birth exposure data source
|
206
272
|
configuration_defaults[self.name]["data_sources"][
|
207
|
-
"
|
273
|
+
"birth_exposure"
|
208
274
|
] = f"{self.risk}.birth_exposure"
|
209
275
|
configuration_defaults[self.name]["distribution_type"] = "lbwsg"
|
210
276
|
return configuration_defaults
|
@@ -224,6 +290,7 @@ class LBWSGRisk(Risk):
|
|
224
290
|
def setup(self, builder: Builder) -> None:
|
225
291
|
super().setup(builder)
|
226
292
|
self.birth_exposures = self.get_birth_exposure_pipelines(builder)
|
293
|
+
self.configuration_age_end = builder.configuration.population.initialization_age_max
|
227
294
|
|
228
295
|
#################
|
229
296
|
# Setup methods #
|
@@ -242,7 +309,7 @@ class LBWSGRisk(Risk):
|
|
242
309
|
self.exposure_distribution.lookup_tables.values()
|
243
310
|
)
|
244
311
|
|
245
|
-
def get_pipeline(axis_: str):
|
312
|
+
def get_pipeline(axis_: str) -> Pipeline:
|
246
313
|
return builder.value.register_value_producer(
|
247
314
|
self.birth_exposure_pipeline_name(axis_),
|
248
315
|
source=lambda index: self.get_birth_exposure(axis_, index),
|
@@ -260,12 +327,23 @@ class LBWSGRisk(Risk):
|
|
260
327
|
########################
|
261
328
|
|
262
329
|
def on_initialize_simulants(self, pop_data: SimulantData) -> None:
|
263
|
-
|
264
|
-
self.
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
330
|
+
if pop_data.user_data.get("age_end", self.configuration_age_end) == 0:
|
331
|
+
self.exposure_distribution.exposure_key = "birth_exposure"
|
332
|
+
else:
|
333
|
+
self.exposure_distribution.exposure_key = "exposure"
|
334
|
+
|
335
|
+
try:
|
336
|
+
birth_exposures = {
|
337
|
+
self.get_exposure_column_name(axis): self.birth_exposures[
|
338
|
+
self.birth_exposure_pipeline_name(axis)
|
339
|
+
](pop_data.index)
|
340
|
+
for axis in self.AXES
|
341
|
+
}
|
342
|
+
except KeyError:
|
343
|
+
raise ConfigurationError(
|
344
|
+
f"{self.exposure_distribution.exposure_key} data for {self.name} is missing from the "
|
345
|
+
"simulation. Simulants cannot be initialized."
|
346
|
+
)
|
269
347
|
self.population_view.update(pd.DataFrame(birth_exposures))
|
270
348
|
|
271
349
|
##################################
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: vivarium_public_health
|
3
|
-
Version: 4.
|
3
|
+
Version: 4.2.0
|
4
4
|
Summary: Components for modelling diseases, risks, and interventions with ``vivarium``
|
5
5
|
Home-page: https://github.com/ihmeuw/vivarium_public_health
|
6
6
|
Author: The vivarium developers
|
@@ -1,6 +1,6 @@
|
|
1
1
|
vivarium_public_health/__about__.py,sha256=RgWycPypKZS80TpSX7o41cREnG8PfguNHDHLuLyl820,487
|
2
2
|
vivarium_public_health/__init__.py,sha256=GDeeP-7OlCBwPuv_xQoB1wNmvCaFsqfTB7qnnYApm0w,1343
|
3
|
-
vivarium_public_health/_version.py,sha256=
|
3
|
+
vivarium_public_health/_version.py,sha256=pU56ZDjCDnUbINe39hYuKXHy9UI9Tf4xjWgnxBlxEDk,22
|
4
4
|
vivarium_public_health/utilities.py,sha256=QNXQ6fhAr1HcV-GwKw7wQLz6QyuNxqNvMA-XujKjTgs,3035
|
5
5
|
vivarium_public_health/disease/__init__.py,sha256=VUJHDLlE6ngo2qHNQUtZ8OWH5H_T7_ao-xsYKDkRmHw,443
|
6
6
|
vivarium_public_health/disease/exceptions.py,sha256=vb30IIV82OiDf2cNZCs_E2rF6mdDDHbnZSND60no5CU,97
|
@@ -38,13 +38,13 @@ vivarium_public_health/risks/data_transformations.py,sha256=SgdPKc95BBqgMNUdlAQM
|
|
38
38
|
vivarium_public_health/risks/distributions.py,sha256=5gkurGTPqZczIKum5NgJ-DbJ2bxA1tRbLe7jKgCqkQg,18203
|
39
39
|
vivarium_public_health/risks/effect.py,sha256=Cw-V1rMPaAPZsirbUElPzksvNuXLQc8TIIk0hgaFzvA,21259
|
40
40
|
vivarium_public_health/risks/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
41
|
-
vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py,sha256=
|
41
|
+
vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py,sha256=wKVGHhdIas9WOrgA5wpwkSSDrZwBtaCqkZXfQH6jrkY,21159
|
42
42
|
vivarium_public_health/treatment/__init__.py,sha256=wONElu9aJbBYwpYIovYPYaN_GYfVhPXtTeFWSdQMgA0,222
|
43
43
|
vivarium_public_health/treatment/magic_wand.py,sha256=zg4I48G-l9fC6-qjvApbM1zNACJimZlX9ZZ9fdHKwvc,1985
|
44
44
|
vivarium_public_health/treatment/scale_up.py,sha256=_bsf9c_yVc7-q_-yBcXimISTUfYzPps1auH0uEf7sfQ,7048
|
45
45
|
vivarium_public_health/treatment/therapeutic_inertia.py,sha256=ZIHnpuszZwA_BkS53JbSLvpcnX_bqG2knwCUyUgkA9M,2362
|
46
|
-
vivarium_public_health-4.
|
47
|
-
vivarium_public_health-4.
|
48
|
-
vivarium_public_health-4.
|
49
|
-
vivarium_public_health-4.
|
50
|
-
vivarium_public_health-4.
|
46
|
+
vivarium_public_health-4.2.0.dist-info/licenses/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
|
47
|
+
vivarium_public_health-4.2.0.dist-info/METADATA,sha256=o3j3So0A5hNLBNevTQG955g_nKQE5AaH3dXh67tzkUo,4237
|
48
|
+
vivarium_public_health-4.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
49
|
+
vivarium_public_health-4.2.0.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
|
50
|
+
vivarium_public_health-4.2.0.dist-info/RECORD,,
|
File without changes
|
{vivarium_public_health-4.1.1.dist-info → vivarium_public_health-4.2.0.dist-info}/top_level.txt
RENAMED
File without changes
|