vivarium-public-health 3.0.5__py3-none-any.whl → 3.0.7__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 +1 @@
1
- __version__ = "3.0.5"
1
+ __version__ = "3.0.7"
@@ -7,7 +7,7 @@ This module contains tools to model transitions between disease states.
7
7
 
8
8
  """
9
9
 
10
- from typing import TYPE_CHECKING, Any, Callable, Dict, Union
10
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
11
11
 
12
12
  import pandas as pd
13
13
  from vivarium.framework.engine import Builder
@@ -48,6 +48,10 @@ class RateTransition(Transition):
48
48
  },
49
49
  }
50
50
 
51
+ @property
52
+ def columns_required(self) -> Optional[List[str]]:
53
+ return ["alive"]
54
+
51
55
  @property
52
56
  def transition_rate_pipeline_name(self) -> str:
53
57
  if "incidence_rate" in self._get_data_functions:
@@ -100,8 +104,6 @@ class RateTransition(Transition):
100
104
  preferred_post_processor=union_post_processor,
101
105
  )
102
106
 
103
- self.population_view = builder.population.get_view(["alive"])
104
-
105
107
  #################
106
108
  # Setup methods #
107
109
  #################
@@ -123,7 +123,10 @@ class Risk(Component):
123
123
 
124
124
  @property
125
125
  def columns_created(self) -> List[str]:
126
- return [self.propensity_column_name, self.exposure_column_name]
126
+ columns_to_create = [self.propensity_column_name]
127
+ if self.create_exposure_column:
128
+ columns_to_create.append(self.exposure_column_name)
129
+ return columns_to_create
127
130
 
128
131
  @property
129
132
  def initialization_requirements(self) -> Dict[str, List[str]]:
@@ -172,6 +175,16 @@ class Risk(Component):
172
175
  self.propensity = self.get_propensity_pipeline(builder)
173
176
  self.exposure = self.get_exposure_pipeline(builder)
174
177
 
178
+ # We want to set this to True iff there is a non-loglinear risk effect
179
+ # on this risk instance
180
+ self.create_exposure_column = bool(
181
+ [
182
+ component
183
+ for component in builder.components.list_components()
184
+ if component.startswith(f"non_log_linear_risk_effect.{self.risk.name}_on_")
185
+ ]
186
+ )
187
+
175
188
  def get_distribution_type(self, builder: Builder) -> str:
176
189
  """Get the distribution type for the risk from the configuration.
177
190
 
@@ -270,19 +283,19 @@ class Risk(Component):
270
283
  ########################
271
284
 
272
285
  def on_initialize_simulants(self, pop_data: SimulantData) -> None:
273
- propensity_values = self.randomness.get_draw(pop_data.index)
274
- df = pd.DataFrame(
275
- {
276
- self.propensity_column_name: self.randomness.get_draw(pop_data.index),
277
- self.exposure_column_name: self.exposure_distribution.ppf(propensity_values),
278
- }
286
+ propensity = pd.Series(
287
+ self.randomness.get_draw(pop_data.index), name=self.propensity_column_name
279
288
  )
280
- self.population_view.update(df)
289
+ self.population_view.update(propensity)
290
+ self.update_exposure_column(pop_data.index)
281
291
 
282
292
  def on_time_step_prepare(self, event: Event) -> None:
283
- exposure_values = self.exposure(event.index)
284
- exposure_col = pd.Series(exposure_values, name=self.exposure_column_name)
285
- self.population_view.update(exposure_col)
293
+ self.update_exposure_column(event.index)
294
+
295
+ def update_exposure_column(self, index: pd.Index) -> None:
296
+ if self.create_exposure_column:
297
+ exposure = pd.Series(self.exposure(index), name=self.exposure_column_name)
298
+ self.population_view.update(exposure)
286
299
 
287
300
  ##################################
288
301
  # Pipeline sources and modifiers #
@@ -157,16 +157,19 @@ class RiskEffect(Component):
157
157
  rr_source = configuration.data_sources.relative_risk
158
158
  rr_dist_parameters = configuration.data_source_parameters.relative_risk.to_dict()
159
159
 
160
- try:
161
- distribution = getattr(import_module("scipy.stats"), rr_source)
162
- rng = np.random.default_rng(builder.randomness.get_seed(self.name))
163
- rr_data = distribution(**rr_dist_parameters).ppf(rng.random())
164
- except AttributeError:
160
+ if isinstance(rr_source, str):
161
+ try:
162
+ distribution = getattr(import_module("scipy.stats"), rr_source)
163
+ rng = np.random.default_rng(builder.randomness.get_seed(self.name))
164
+ rr_data = distribution(**rr_dist_parameters).ppf(rng.random())
165
+ except AttributeError:
166
+ rr_data = self.get_filtered_data(builder, rr_source)
167
+ except TypeError:
168
+ raise ConfigurationError(
169
+ f"Parameters {rr_dist_parameters} are not valid for distribution {rr_source}."
170
+ )
171
+ else:
165
172
  rr_data = self.get_filtered_data(builder, rr_source)
166
- except TypeError:
167
- raise ConfigurationError(
168
- f"Parameters {rr_dist_parameters} are not valid for distribution {rr_source}."
169
- )
170
173
  return rr_data
171
174
 
172
175
  def get_filtered_data(
@@ -198,6 +201,8 @@ class RiskEffect(Component):
198
201
  cat2["parameter"] = "cat2"
199
202
  cat2["value"] = 1
200
203
  rr_data = pd.concat([cat1, cat2], ignore_index=True)
204
+ if "parameter" in rr_data.index.names:
205
+ rr_data = rr_data.reset_index("parameter")
201
206
 
202
207
  rr_value_cols = list(rr_data["parameter"].unique())
203
208
  rr_data = pivot_categorical(builder, self.risk, rr_data, "parameter")
@@ -361,6 +366,10 @@ class NonLogLinearRiskEffect(RiskEffect):
361
366
  # Setup methods #
362
367
  #################
363
368
 
369
+ @staticmethod
370
+ def get_name(risk: EntityString, target: TargetString) -> str:
371
+ return f"non_log_linear_risk_effect.{risk.name}_on_{target}"
372
+
364
373
  def build_all_lookup_tables(self, builder: Builder) -> None:
365
374
  rr_data = self.get_relative_risk_data(builder)
366
375
  self.validate_rr_data(rr_data)
@@ -191,7 +191,7 @@ class LBWSGRisk(Risk):
191
191
  return f"{axis}.birth_exposure"
192
192
 
193
193
  @staticmethod
194
- def exposure_column_name(axis: str) -> str:
194
+ def get_exposure_column_name(axis: str) -> str:
195
195
  return f"{axis}_exposure"
196
196
 
197
197
  ##############
@@ -206,7 +206,7 @@ class LBWSGRisk(Risk):
206
206
 
207
207
  @property
208
208
  def columns_created(self) -> List[str]:
209
- return [self.exposure_column_name(axis) for axis in self.AXES]
209
+ return [self.get_exposure_column_name(axis) for axis in self.AXES]
210
210
 
211
211
  #####################
212
212
  # Lifecycle methods #
@@ -256,7 +256,7 @@ class LBWSGRisk(Risk):
256
256
 
257
257
  def on_initialize_simulants(self, pop_data: SimulantData) -> None:
258
258
  birth_exposures = {
259
- self.exposure_column_name(axis): self.birth_exposures[
259
+ self.get_exposure_column_name(axis): self.birth_exposures[
260
260
  self.birth_exposure_pipeline_name(axis)
261
261
  ](pop_data.index)
262
262
  for axis in self.AXES
@@ -318,7 +318,7 @@ class LBWSGRiskEffect(RiskEffect):
318
318
  super().__init__("risk_factor.low_birth_weight_and_short_gestation", target)
319
319
 
320
320
  self.lbwsg_exposure_column_names = [
321
- LBWSGRisk.exposure_column_name(axis) for axis in LBWSGRisk.AXES
321
+ LBWSGRisk.get_exposure_column_name(axis) for axis in LBWSGRisk.AXES
322
322
  ]
323
323
  self.relative_risk_pipeline_name = (
324
324
  f"effect_of_{self.risk.name}_on_{self.target.name}.relative_risk"
@@ -433,8 +433,8 @@ class LBWSGRiskEffect(RiskEffect):
433
433
  pop = self.population_view.subview(["sex"] + self.lbwsg_exposure_column_names).get(
434
434
  pop_data.index
435
435
  )
436
- birth_weight = pop[LBWSGRisk.exposure_column_name(BIRTH_WEIGHT)]
437
- gestational_age = pop[LBWSGRisk.exposure_column_name(GESTATIONAL_AGE)]
436
+ birth_weight = pop[LBWSGRisk.get_exposure_column_name(BIRTH_WEIGHT)]
437
+ gestational_age = pop[LBWSGRisk.get_exposure_column_name(GESTATIONAL_AGE)]
438
438
 
439
439
  is_male = pop["sex"] == "Male"
440
440
  is_tmrel = (self.TMREL_GESTATIONAL_AGE_INTERVAL.left <= gestational_age) & (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vivarium_public_health
3
- Version: 3.0.5
3
+ Version: 3.0.7
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,13 +1,13 @@
1
1
  vivarium_public_health/__about__.py,sha256=RgWycPypKZS80TpSX7o41cREnG8PfguNHDHLuLyl820,487
2
2
  vivarium_public_health/__init__.py,sha256=tomMOl3PI7O8GdxDWGBiBjT0Bwd31GpyQTYTzwIv108,361
3
- vivarium_public_health/_version.py,sha256=3kxZhPRWwAKER8BleEtUBQTUGwcBGPmrbjLu-HEi-hI,22
3
+ vivarium_public_health/_version.py,sha256=tP42eveLWP9Mgm4I435dKZC463zDP4G3Rq_XJ9XMJAg,22
4
4
  vivarium_public_health/utilities.py,sha256=5cl9jjVkOQ1UeXT4DjDMAhaBNNjAsDo-SVJwpv6FDw0,3071
5
5
  vivarium_public_health/disease/__init__.py,sha256=RuuiRcvAJfX9WQGt_WZZjxN7Cu3E5rMTmuaRS-UaFPM,419
6
6
  vivarium_public_health/disease/model.py,sha256=0WIYDEx-hwlUJp6Zl8m8bUMoWxuVkOWsJvh_YlZiOPs,8234
7
7
  vivarium_public_health/disease/models.py,sha256=01UK7yB2zGPFzmlIpvhd-XnGe6vSCMDza3QTidgY7Nc,3479
8
8
  vivarium_public_health/disease/special_disease.py,sha256=3vS1WsO__IwOK0Oe_CUmh3aaKrXIf2CANtmiqlS3pjc,14614
9
9
  vivarium_public_health/disease/state.py,sha256=PUSDE1UlvoCPT6jPEyCTQO1bXjjYxqzdIa6-Bxpd-7I,22370
10
- vivarium_public_health/disease/transition.py,sha256=ZxYXZBo2EEXzuQCbaj2pHTyj61hYkdqBH1ce2Htdnb4,6412
10
+ vivarium_public_health/disease/transition.py,sha256=fgeVMy86GLrNpZ3J9E4AC0iA5z3aVdP0ZQ0AWa_odTY,6452
11
11
  vivarium_public_health/mslt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  vivarium_public_health/mslt/delay.py,sha256=aOYjMpMSHEVlJs0FuC2gdq3uj6_vKmkhDjoBtC4i9G0,22812
13
13
  vivarium_public_health/mslt/disease.py,sha256=TBqa7yj6k1oUbgkAe0rIgLpbdMLMFs4DiZ1Igi2BQBg,16663
@@ -32,18 +32,18 @@ vivarium_public_health/results/risk.py,sha256=GS4qJVjW3MqsDeRDDac2etFQlqIluxOxIZ
32
32
  vivarium_public_health/results/simple_cause.py,sha256=ibdE6KwhDfQWntCVkOEooBcmUydEoupmd3_poHSHyu8,1007
33
33
  vivarium_public_health/results/stratification.py,sha256=4I3YGHVabNAZENE7YboOtWsWU4X-8LUBJ9iwYMbpl6E,5387
34
34
  vivarium_public_health/risks/__init__.py,sha256=z8DcnZGxqNVAyFZm2WAV-IVNGvrSS4izju_0DNe2Ghw,212
35
- vivarium_public_health/risks/base_risk.py,sha256=WhvB0RRYIsGsPQvJEWckcBlOVSh4Rx-B-VGZDSWWb7s,10416
35
+ vivarium_public_health/risks/base_risk.py,sha256=fNQZIgGHYnWFWdLA9qmtTA66ujCGq2jgA5S1-MadWT8,10900
36
36
  vivarium_public_health/risks/data_transformations.py,sha256=SgdPKc95BBqgMNUdlAQM8k6iaXcpxnjk5B2ySTES1Yg,9269
37
37
  vivarium_public_health/risks/distributions.py,sha256=7xCI2zSpnKUEWow4ywRirVbvbpeJaxo6g9us0-Lh0kE,18197
38
- vivarium_public_health/risks/effect.py,sha256=Oc_3A0fbMDUBAJAMJ9aeDRDqdgW_aF75B3SbGv9QELw,20351
38
+ vivarium_public_health/risks/effect.py,sha256=fc_MrhmJLQcpaiZk12klric2c5-BY1gZaWMbsEjBUlY,20766
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=o3Uo6_AQoUHJeGo4HpB0PlouNqKst9NFmm3PRiTr5bg,17924
40
+ vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py,sha256=kxuJwkpJzGF8CqwNEemEA7CrohcxKQJtvUXLJtD1xm0,17948
41
41
  vivarium_public_health/treatment/__init__.py,sha256=wONElu9aJbBYwpYIovYPYaN_GYfVhPXtTeFWSdQMgA0,222
42
42
  vivarium_public_health/treatment/magic_wand.py,sha256=i9N57-MEuQv5B6dQ5iVMTAdOPghYcgiRRz-dTzigf1s,1980
43
43
  vivarium_public_health/treatment/scale_up.py,sha256=aKJmZ2G6N80n7oPkJM8IpqZOhftUBkAMBn4hR4EZzhE,7015
44
44
  vivarium_public_health/treatment/therapeutic_inertia.py,sha256=8Z97s7GfcpfLu1U1ESJSqeEk4L__a3M0GbBV21MFg2s,2346
45
- vivarium_public_health-3.0.5.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
- vivarium_public_health-3.0.5.dist-info/METADATA,sha256=FX6CeaoApBMGJFO3USOMhAIsMpl7srL1gQIkUV8Ay54,4061
47
- vivarium_public_health-3.0.5.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
48
- vivarium_public_health-3.0.5.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
- vivarium_public_health-3.0.5.dist-info/RECORD,,
45
+ vivarium_public_health-3.0.7.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
+ vivarium_public_health-3.0.7.dist-info/METADATA,sha256=yrIrajFSQQDZMMSZMwVgi8dW3iHFLhEDnmKnyspCDiY,4061
47
+ vivarium_public_health-3.0.7.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
48
+ vivarium_public_health-3.0.7.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
+ vivarium_public_health-3.0.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5