vivarium-public-health 3.0.10__py3-none-any.whl → 3.1.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,7 @@ from vivarium_public_health.population import (
30
30
  FertilityCrudeBirthRate,
31
31
  FertilityDeterministic,
32
32
  Mortality,
33
+ ScaledPopulation,
33
34
  )
34
35
  from vivarium_public_health.results import (
35
36
  CategoricalRiskObserver,
@@ -1 +1 @@
1
- __version__ = "3.0.10"
1
+ __version__ = "3.1.0"
@@ -3,5 +3,5 @@ from .add_new_birth_cohorts import (
3
3
  FertilityCrudeBirthRate,
4
4
  FertilityDeterministic,
5
5
  )
6
- from .base_population import BasePopulation, generate_population
6
+ from .base_population import BasePopulation, ScaledPopulation, generate_population
7
7
  from .mortality import Mortality
@@ -8,6 +8,8 @@ characteristics to simulants.
8
8
 
9
9
  """
10
10
 
11
+ from __future__ import annotations
12
+
11
13
  from typing import Callable, Dict, Iterable, List
12
14
 
13
15
  import numpy as np
@@ -76,12 +78,11 @@ class BasePopulation(Component):
76
78
  # Validate configuration for deprecated keys
77
79
  self._validate_config_for_deprecated_keys()
78
80
 
79
- source_population_structure = load_population_structure(builder)
81
+ source_population_structure = self._load_population_structure(builder)
80
82
  self.demographic_proportions = assign_demographic_proportions(
81
83
  source_population_structure,
82
84
  include_sex=self.config.include_sex,
83
85
  )
84
-
85
86
  self.randomness = self.get_randomness_streams(builder)
86
87
  self.register_simulants = builder.randomness.register_simulants
87
88
 
@@ -138,7 +139,6 @@ class BasePopulation(Component):
138
139
  demographic_proportions = self.get_demographic_proportions_for_creation_time(
139
140
  self.demographic_proportions, pop_data.creation_time.year
140
141
  )
141
-
142
142
  self.population_view.update(
143
143
  generate_population(
144
144
  simulant_ids=pop_data.index,
@@ -202,6 +202,50 @@ class BasePopulation(Component):
202
202
  f"Public Health. Use the new key '{mapper[key]}' instead."
203
203
  )
204
204
 
205
+ def _load_population_structure(self, builder: Builder) -> pd.DataFrame:
206
+ return load_population_structure(builder)
207
+
208
+
209
+ class ScaledPopulation(BasePopulation):
210
+ """This component is to be used in place of BasePopulation when all simulants are
211
+ a subset of the total population and need to be rescaled. The base population
212
+ structure is multiplied by a provided scaling factor. This scaling factor
213
+ can be a dataframe passed in or a string that corresponds to an artifact key.
214
+ If providing an artifact key, users can specify that in the configuration file.
215
+ For example:
216
+
217
+ .. code-block:: yaml
218
+
219
+ components:
220
+ vivarium_public_health:
221
+ population:
222
+ - ScaledPopulation("some.artifact.key")
223
+
224
+
225
+ """
226
+
227
+ def __init__(self, scaling_factor: str | pd.DataFrame):
228
+ super().__init__()
229
+ self.scaling_factor = scaling_factor
230
+ """Set a multiplicative scaling factor for the population structure."""
231
+
232
+ def _load_population_structure(self, builder: Builder) -> pd.DataFrame:
233
+ scaling_factor = self.get_data(builder, self.scaling_factor)
234
+ population_structure = load_population_structure(builder)
235
+ if not isinstance(scaling_factor, pd.DataFrame):
236
+ raise ValueError(
237
+ f"Scaling factor must be a pandas DataFrame. Provided value: {scaling_factor}"
238
+ )
239
+ scaling_factor = scaling_factor.set_index(
240
+ [col for col in scaling_factor.columns if col != "value"]
241
+ )
242
+ population_structure = population_structure.set_index(
243
+ [col for col in population_structure.columns if col != "value"]
244
+ )
245
+ scaled_population_structure = (population_structure * scaling_factor).reset_index()
246
+
247
+ return scaled_population_structure
248
+
205
249
 
206
250
  class AgeOutSimulants(Component):
207
251
  """Component for handling aged-out simulants"""
@@ -13,6 +13,7 @@ from typing import Tuple, Union
13
13
 
14
14
  import numpy as np
15
15
  import pandas as pd
16
+ from vivarium.framework.engine import Builder
16
17
  from vivarium.framework.randomness import RandomnessStream
17
18
 
18
19
  _SORT_ORDER = ["location", "year_start", "sex", "age_start"]
@@ -493,11 +494,12 @@ def get_cause_deleted_mortality_rate(all_cause_mortality_rate, list_of_csmrs):
493
494
  )
494
495
 
495
496
 
496
- def load_population_structure(builder):
497
+ def load_population_structure(builder: Builder) -> pd.DataFrame:
497
498
  data = builder.data.load("population.structure")
498
499
  # create an age column which is the midpoint of the age group
499
500
  data["age"] = data.apply(lambda row: (row["age_start"] + row["age_end"]) / 2, axis=1)
500
501
  data["location"] = builder.data.load("population.location")
502
+
501
503
  return data
502
504
 
503
505
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vivarium_public_health
3
- Version: 3.0.10
3
+ Version: 3.1.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
- vivarium_public_health/__init__.py,sha256=jYSQDGc86QMEW4iZ7wO1JCSP189n1zScIn6QKG470Kw,1321
3
- vivarium_public_health/_version.py,sha256=xS-MdV9u-8rYsWMV1VgxiWeHHmEWb63Js1BsRGmz0xo,23
2
+ vivarium_public_health/__init__.py,sha256=GDeeP-7OlCBwPuv_xQoB1wNmvCaFsqfTB7qnnYApm0w,1343
3
+ vivarium_public_health/_version.py,sha256=YVoF76lT0p3dIsqphNnDWuqSia3gZP1S1eQYXZ9FbSE,22
4
4
  vivarium_public_health/utilities.py,sha256=5cl9jjVkOQ1UeXT4DjDMAhaBNNjAsDo-SVJwpv6FDw0,3071
5
5
  vivarium_public_health/disease/__init__.py,sha256=VUJHDLlE6ngo2qHNQUtZ8OWH5H_T7_ao-xsYKDkRmHw,443
6
6
  vivarium_public_health/disease/model.py,sha256=0WIYDEx-hwlUJp6Zl8m8bUMoWxuVkOWsJvh_YlZiOPs,8234
@@ -17,10 +17,10 @@ vivarium_public_health/mslt/observer.py,sha256=O4rysQzAGE5oDkdXb0E-qjD9TPFphQHTn
17
17
  vivarium_public_health/mslt/population.py,sha256=v_p5VkjndAVJMuXaJQc3lAdzUWHlWCEQWH4A-c4phPA,7255
18
18
  vivarium_public_health/plugins/__init__.py,sha256=oBW_zfgG_LbwfgTDjUe0btfy9FaDvAbtXho1zQFnz0Y,76
19
19
  vivarium_public_health/plugins/parser.py,sha256=v78mj8awpdrB-oqK8udPI_7MZBChoKJOQN_e17fNEj8,31841
20
- vivarium_public_health/population/__init__.py,sha256=17rtbcNVK5LtCCxAex7P7Q_vYpwbeTepyf3nazS90Yc,225
20
+ vivarium_public_health/population/__init__.py,sha256=x_9rB93q64Krw-kbBDI1-_U_JsPO1_QrL03AwiFlwXI,243
21
21
  vivarium_public_health/population/add_new_birth_cohorts.py,sha256=k65Li0LYWl-JFHBUvLjJxkRv12EJw_FVxrOYgbd44q8,9078
22
- vivarium_public_health/population/base_population.py,sha256=4lUc8EZwzj5Ba36lSmW9yyxcRuBSMLqi_8Fy69ssq5E,17026
23
- vivarium_public_health/population/data_transformations.py,sha256=QVh_63Wwg9BUkaQm1pMSvBb-wsYrsgyADKIERAiEOVg,22188
22
+ vivarium_public_health/population/base_population.py,sha256=jJMVWv_EO0ckUZHhh01dRbsRgL491Eg3thRxPwNiAeg,18866
23
+ vivarium_public_health/population/data_transformations.py,sha256=YmqyrlrIBtHGp1nFyhesqlNryvB7Vr33eVu4fU4HWsA,22260
24
24
  vivarium_public_health/population/mortality.py,sha256=w7b_TUssHjRcnULdXu7MXKfZBjCrlYWbB94oO3JWogI,10264
25
25
  vivarium_public_health/results/__init__.py,sha256=rKUZGlRXJgEyFY4a_WJeg3XnC0l34S5guYZ0N9JJS4E,319
26
26
  vivarium_public_health/results/columns.py,sha256=V-L3JgTcsk51Zx9PcUwSgaE1iZjuGyfZ8aShPjynadU,495
@@ -42,8 +42,8 @@ vivarium_public_health/treatment/__init__.py,sha256=wONElu9aJbBYwpYIovYPYaN_GYfV
42
42
  vivarium_public_health/treatment/magic_wand.py,sha256=i9N57-MEuQv5B6dQ5iVMTAdOPghYcgiRRz-dTzigf1s,1980
43
43
  vivarium_public_health/treatment/scale_up.py,sha256=9Cl3_MaCNPtUPPKXf3hWYepIwMCFlFY24jt2jeyFQO4,7006
44
44
  vivarium_public_health/treatment/therapeutic_inertia.py,sha256=8Z97s7GfcpfLu1U1ESJSqeEk4L__a3M0GbBV21MFg2s,2346
45
- vivarium_public_health-3.0.10.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
- vivarium_public_health-3.0.10.dist-info/METADATA,sha256=pPeIbY7zeBd-vNNaZMJQL51VeEZ1GanLuxYpDs24ZtU,4062
47
- vivarium_public_health-3.0.10.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
48
- vivarium_public_health-3.0.10.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
- vivarium_public_health-3.0.10.dist-info/RECORD,,
45
+ vivarium_public_health-3.1.0.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
+ vivarium_public_health-3.1.0.dist-info/METADATA,sha256=YGem2GjFv7jkEz7_3VkJMsJjMtHolbwiFgBgL0LF4Mk,4061
47
+ vivarium_public_health-3.1.0.dist-info/WHEEL,sha256=a7TGlA-5DaHMRrarXjVbQagU3Man_dCnGIWMJr5kRWo,91
48
+ vivarium_public_health-3.1.0.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
+ vivarium_public_health-3.1.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.4.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5