vivarium-public-health 3.1.2__py3-none-any.whl → 3.1.3__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- __version__ = "3.1.2"
1
+ __version__ = "3.1.3"
@@ -17,6 +17,7 @@ import scipy
17
17
  from layered_config_tree import ConfigurationError
18
18
  from vivarium import Component
19
19
  from vivarium.framework.engine import Builder
20
+ from vivarium.framework.values import Pipeline
20
21
 
21
22
  from vivarium_public_health.risks import Risk
22
23
  from vivarium_public_health.risks.data_transformations import (
@@ -112,7 +113,8 @@ class RiskEffect(Component):
112
113
  def setup(self, builder: Builder) -> None:
113
114
  self.exposure = self.get_risk_exposure(builder)
114
115
 
115
- self.target_modifier = self.get_target_modifier(builder)
116
+ self._relative_risk_source = self.get_relative_risk_source(builder)
117
+ self.relative_risk = self.get_relative_risk(builder)
116
118
 
117
119
  self.register_target_modifier(builder)
118
120
  self.register_paf_modifier(builder)
@@ -124,7 +126,7 @@ class RiskEffect(Component):
124
126
  def build_all_lookup_tables(self, builder: Builder) -> None:
125
127
  self._exposure_distribution_type = self.get_distribution_type(builder)
126
128
 
127
- rr_data = self.get_relative_risk_data(builder)
129
+ rr_data = self.load_relative_risk(builder)
128
130
  rr_value_cols = None
129
131
  if self.is_exposure_categorical:
130
132
  rr_data, rr_value_cols = self.process_categorical_data(builder, rr_data)
@@ -146,7 +148,7 @@ class RiskEffect(Component):
146
148
  return risk_exposure_component.distribution_type
147
149
  return risk_exposure_component.get_distribution_type(builder)
148
150
 
149
- def get_relative_risk_data(
151
+ def load_relative_risk(
150
152
  self,
151
153
  builder: Builder,
152
154
  configuration=None,
@@ -260,24 +262,27 @@ class RiskEffect(Component):
260
262
  def get_risk_exposure(self, builder: Builder) -> Callable[[pd.Index], pd.Series]:
261
263
  return builder.value.get_value(self.exposure_pipeline_name)
262
264
 
263
- def get_target_modifier(
264
- self, builder: Builder
265
- ) -> Callable[[pd.Index, pd.Series], pd.Series]:
265
+ def adjust_target(self, index: pd.Index, target: pd.Series) -> pd.Series:
266
+ relative_risk = self.relative_risk(index)
267
+ return target * relative_risk
268
+
269
+ def get_relative_risk_source(self, builder: Builder) -> Callable[[pd.Index], pd.Series]:
270
+
266
271
  if not self.is_exposure_categorical:
267
272
  tmred = builder.data.load(f"{self.risk}.tmred")
268
273
  tmrel = 0.5 * (tmred["min"] + tmred["max"])
269
274
  scale = builder.data.load(f"{self.risk}.relative_risk_scalar")
270
275
 
271
- def adjust_target(index: pd.Index, target: pd.Series) -> pd.Series:
276
+ def generate_relative_risk(index: pd.Index) -> pd.Series:
272
277
  rr = self.lookup_tables["relative_risk"](index)
273
278
  exposure = self.exposure(index)
274
279
  relative_risk = np.maximum(rr.values ** ((exposure - tmrel) / scale), 1)
275
- return target * relative_risk
280
+ return relative_risk
276
281
 
277
282
  else:
278
283
  index_columns = ["index", self.risk.name]
279
284
 
280
- def adjust_target(index: pd.Index, target: pd.Series) -> pd.Series:
285
+ def generate_relative_risk(index: pd.Index) -> pd.Series:
281
286
  rr = self.lookup_tables["relative_risk"](index)
282
287
  exposure = self.exposure(index).reset_index()
283
288
  exposure.columns = index_columns
@@ -288,16 +293,24 @@ class RiskEffect(Component):
288
293
  relative_risk = relative_risk.set_index(index_columns)
289
294
 
290
295
  effect = relative_risk.loc[exposure.index, "value"].droplevel(self.risk.name)
291
- affected_rates = target * effect
292
- return affected_rates
296
+ return effect
293
297
 
294
- return adjust_target
298
+ return generate_relative_risk
299
+
300
+ def get_relative_risk(self, builder: Builder) -> Pipeline:
301
+ return builder.value.register_value_producer(
302
+ f"{self.risk.name}_on_{self.target.name}.relative_risk",
303
+ self._relative_risk_source,
304
+ component=self,
305
+ required_resources=[self.exposure],
306
+ )
295
307
 
296
308
  def register_target_modifier(self, builder: Builder) -> None:
297
309
  builder.value.register_value_modifier(
298
310
  self.target_pipeline_name,
299
- modifier=self.target_modifier,
300
- requires_values=[f"{self.risk.name}.exposure"],
311
+ modifier=self.adjust_target,
312
+ component=self,
313
+ required_resources=[self.relative_risk],
301
314
  )
302
315
 
303
316
  def register_paf_modifier(self, builder: Builder) -> None:
@@ -307,7 +320,8 @@ class RiskEffect(Component):
307
320
  builder.value.register_value_modifier(
308
321
  self.target_paf_pipeline_name,
309
322
  modifier=self.lookup_tables["population_attributable_fraction"],
310
- requires_columns=required_columns,
323
+ component=self,
324
+ required_resources=required_columns,
311
325
  )
312
326
 
313
327
  ##################
@@ -371,7 +385,7 @@ class NonLogLinearRiskEffect(RiskEffect):
371
385
  return f"non_log_linear_risk_effect.{risk.name}_on_{target}"
372
386
 
373
387
  def build_all_lookup_tables(self, builder: Builder) -> None:
374
- rr_data = self.get_relative_risk_data(builder)
388
+ rr_data = self.load_relative_risk(builder)
375
389
  self.validate_rr_data(rr_data)
376
390
 
377
391
  def define_rr_intervals(df: pd.DataFrame) -> pd.DataFrame:
@@ -415,7 +429,7 @@ class NonLogLinearRiskEffect(RiskEffect):
415
429
  builder, paf_data
416
430
  )
417
431
 
418
- def get_relative_risk_data(
432
+ def load_relative_risk(
419
433
  self,
420
434
  builder: Builder,
421
435
  configuration=None,
@@ -472,10 +486,8 @@ class NonLogLinearRiskEffect(RiskEffect):
472
486
 
473
487
  return rr_data
474
488
 
475
- def get_target_modifier(
476
- self, builder: Builder
477
- ) -> Callable[[pd.Index, pd.Series], pd.Series]:
478
- def adjust_target(index: pd.Index, target: pd.Series) -> pd.Series:
489
+ def get_relative_risk_source(self, builder: Builder) -> Callable[[pd.Index], pd.Series]:
490
+ def generate_relative_risk(index: pd.Index) -> pd.Series:
479
491
  rr_intervals = self.lookup_tables["relative_risk"](index)
480
492
  exposure = self.population_view.get(index)[f"{self.risk.name}_exposure"]
481
493
  x1, x2 = (
@@ -486,9 +498,9 @@ class NonLogLinearRiskEffect(RiskEffect):
486
498
  m = (y2 - y1) / (x2 - x1)
487
499
  b = y1 - m * x1
488
500
  relative_risk = b + m * exposure
489
- return target * relative_risk
501
+ return relative_risk
490
502
 
491
- return adjust_target
503
+ return generate_relative_risk
492
504
 
493
505
  ##############
494
506
  # Validators #
@@ -336,7 +336,6 @@ class LBWSGRiskEffect(RiskEffect):
336
336
 
337
337
  super().setup(builder)
338
338
  self.interpolator = self.get_interpolator(builder)
339
- self.relative_risk = self.get_relative_risk_pipeline(builder)
340
339
 
341
340
  #################
342
341
  # Setup methods #
@@ -393,10 +392,10 @@ class LBWSGRiskEffect(RiskEffect):
393
392
  for age_start in exposed_age_group_starts
394
393
  }
395
394
 
396
- def get_relative_risk_pipeline(self, builder: Builder) -> Pipeline:
395
+ def get_relative_risk(self, builder: Builder) -> Pipeline:
397
396
  return builder.value.register_value_producer(
398
397
  self.relative_risk_pipeline_name,
399
- source=self.get_relative_risk,
398
+ source=self.get_relative_risk_source,
400
399
  requires_columns=["age"] + self.rr_column_names,
401
400
  )
402
401
 
@@ -470,7 +469,7 @@ class LBWSGRiskEffect(RiskEffect):
470
469
  # Pipeline sources and modifiers #
471
470
  ##################################
472
471
 
473
- def get_relative_risk(self, index: pd.Index) -> pd.Series:
472
+ def get_relative_risk_source(self, index: pd.Index) -> pd.Series:
474
473
  pop = self.population_view.get(index)
475
474
  relative_risk = pd.Series(1.0, index=index, name=self.relative_risk_pipeline_name)
476
475
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vivarium_public_health
3
- Version: 3.1.2
3
+ Version: 3.1.3
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
@@ -26,44 +26,44 @@ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
26
26
  Classifier: Topic :: Scientific/Engineering :: Physics
27
27
  Classifier: Topic :: Software Development :: Libraries
28
28
  License-File: LICENSE.txt
29
- Requires-Dist: vivarium >=3.2.0
30
- Requires-Dist: layered-config-tree >=1.0.1
29
+ Requires-Dist: vivarium>=3.2.0
30
+ Requires-Dist: layered_config_tree>=1.0.1
31
31
  Requires-Dist: loguru
32
- Requires-Dist: numpy <2.0.0
32
+ Requires-Dist: numpy<2.0.0
33
33
  Requires-Dist: pandas
34
34
  Requires-Dist: scipy
35
35
  Requires-Dist: tables
36
- Requires-Dist: risk-distributions >=2.0.11
36
+ Requires-Dist: risk_distributions>=2.0.11
37
37
  Requires-Dist: pyarrow
38
- Provides-Extra: dev
39
- Requires-Dist: sphinx <7.0 ; extra == 'dev'
40
- Requires-Dist: sphinx-rtd-theme ; extra == 'dev'
41
- Requires-Dist: sphinx-click ; extra == 'dev'
42
- Requires-Dist: sphinx-autodoc-typehints ; extra == 'dev'
43
- Requires-Dist: IPython ; extra == 'dev'
44
- Requires-Dist: matplotlib ; extra == 'dev'
45
- Requires-Dist: vivarium-testing-utils ; extra == 'dev'
46
- Requires-Dist: pytest ; extra == 'dev'
47
- Requires-Dist: pytest-cov ; extra == 'dev'
48
- Requires-Dist: pytest-mock ; extra == 'dev'
49
- Requires-Dist: hypothesis ; extra == 'dev'
50
- Requires-Dist: pyyaml ; extra == 'dev'
51
- Requires-Dist: black ==22.3.0 ; extra == 'dev'
52
- Requires-Dist: isort ; extra == 'dev'
53
38
  Provides-Extra: docs
54
- Requires-Dist: sphinx <7.0 ; extra == 'docs'
55
- Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
56
- Requires-Dist: sphinx-click ; extra == 'docs'
57
- Requires-Dist: sphinx-autodoc-typehints ; extra == 'docs'
58
- Requires-Dist: IPython ; extra == 'docs'
59
- Requires-Dist: matplotlib ; extra == 'docs'
39
+ Requires-Dist: sphinx<7.0; extra == "docs"
40
+ Requires-Dist: sphinx-rtd-theme; extra == "docs"
41
+ Requires-Dist: sphinx-click; extra == "docs"
42
+ Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
43
+ Requires-Dist: IPython; extra == "docs"
44
+ Requires-Dist: matplotlib; extra == "docs"
60
45
  Provides-Extra: test
61
- Requires-Dist: vivarium-testing-utils ; extra == 'test'
62
- Requires-Dist: pytest ; extra == 'test'
63
- Requires-Dist: pytest-cov ; extra == 'test'
64
- Requires-Dist: pytest-mock ; extra == 'test'
65
- Requires-Dist: hypothesis ; extra == 'test'
66
- Requires-Dist: pyyaml ; extra == 'test'
46
+ Requires-Dist: vivarium_testing_utils; extra == "test"
47
+ Requires-Dist: pytest; extra == "test"
48
+ Requires-Dist: pytest-cov; extra == "test"
49
+ Requires-Dist: pytest-mock; extra == "test"
50
+ Requires-Dist: hypothesis; extra == "test"
51
+ Requires-Dist: pyyaml; extra == "test"
52
+ Provides-Extra: dev
53
+ Requires-Dist: sphinx<7.0; extra == "dev"
54
+ Requires-Dist: sphinx-rtd-theme; extra == "dev"
55
+ Requires-Dist: sphinx-click; extra == "dev"
56
+ Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
57
+ Requires-Dist: IPython; extra == "dev"
58
+ Requires-Dist: matplotlib; extra == "dev"
59
+ Requires-Dist: vivarium_testing_utils; extra == "dev"
60
+ Requires-Dist: pytest; extra == "dev"
61
+ Requires-Dist: pytest-cov; extra == "dev"
62
+ Requires-Dist: pytest-mock; extra == "dev"
63
+ Requires-Dist: hypothesis; extra == "dev"
64
+ Requires-Dist: pyyaml; extra == "dev"
65
+ Requires-Dist: black==22.3.0; extra == "dev"
66
+ Requires-Dist: isort; extra == "dev"
67
67
 
68
68
  Vivarium Public Health
69
69
  ======================
@@ -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=EkxTxShULe9D7KtZB_iICEO13IyzloAxfYgXHGwpMhQ,22
3
+ vivarium_public_health/_version.py,sha256=xoSqNkNOCK0xzFXnsO80epHc1vbiRC8Nbn4Cy-2wBX4,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/model.py,sha256=ZwhhQCc8jj_QeJZO2zLtp_yWzqRxvLjuzW7iDUmmBGA,8852
@@ -35,15 +35,15 @@ vivarium_public_health/risks/__init__.py,sha256=z8DcnZGxqNVAyFZm2WAV-IVNGvrSS4iz
35
35
  vivarium_public_health/risks/base_risk.py,sha256=XQ_7rYJS5gh0coEKDqcc_zYdjPDBZlj6-THsIQxL3zs,10888
36
36
  vivarium_public_health/risks/data_transformations.py,sha256=SgdPKc95BBqgMNUdlAQM8k6iaXcpxnjk5B2ySTES1Yg,9269
37
37
  vivarium_public_health/risks/distributions.py,sha256=a63-ihg2itxqgowDZbUix8soErxs_y8TRwsdtTCIUU4,18121
38
- vivarium_public_health/risks/effect.py,sha256=BN7XzmCutG5yCIcw9uxl_yKBTtqrL_Y4trrj5wND62w,20735
38
+ vivarium_public_health/risks/effect.py,sha256=2DaBKxncS94cm8Ih-TQtbV1mGsEZhx6fEnB5V_ocIZM,21241
39
39
  vivarium_public_health/risks/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
- vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py,sha256=8L-19voqV0URpkbJlgIfdGSJAwEu-y-J9_KGJUJUYgY,17931
40
+ vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py,sha256=Iw5e7sCrWplEu6dic1Wu6q9e0rdeem_6gQ_-N52G54E,17866
41
41
  vivarium_public_health/treatment/__init__.py,sha256=wONElu9aJbBYwpYIovYPYaN_GYfVhPXtTeFWSdQMgA0,222
42
42
  vivarium_public_health/treatment/magic_wand.py,sha256=zGIhrNgB9q6JD7fHlvbDQb3H5e_N_QsROO4Y0kl_JQM,1955
43
43
  vivarium_public_health/treatment/scale_up.py,sha256=hVz0ELXDqlpcExI31rKdepxqcW_hy2hZSa6qCzv6udU,7020
44
44
  vivarium_public_health/treatment/therapeutic_inertia.py,sha256=8Z97s7GfcpfLu1U1ESJSqeEk4L__a3M0GbBV21MFg2s,2346
45
- vivarium_public_health-3.1.2.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
- vivarium_public_health-3.1.2.dist-info/METADATA,sha256=m30cn1jwJksbLgxSqetpor3zYnZZdHQ6BqDBQ3l2hnA,4061
47
- vivarium_public_health-3.1.2.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
48
- vivarium_public_health-3.1.2.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
- vivarium_public_health-3.1.2.dist-info/RECORD,,
45
+ vivarium_public_health-3.1.3.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
+ vivarium_public_health-3.1.3.dist-info/METADATA,sha256=csuhuXUl84A5QlA7S10sjMvafQXonRvAlwm2XSj-ck4,4028
47
+ vivarium_public_health-3.1.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
48
+ vivarium_public_health-3.1.3.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
+ vivarium_public_health-3.1.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.5.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5