vivarium-public-health 3.0.4__py3-none-any.whl → 3.0.6__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.0.4"
1
+ __version__ = "3.0.6"
@@ -1,7 +1,7 @@
1
1
  """
2
- ===================
3
- Disability Observer
4
- ===================
2
+ ====================
3
+ Disability Observers
4
+ ====================
5
5
 
6
6
  This module contains tools for observing years lived with disability (YLDs)
7
7
  in the simulation.
@@ -102,7 +102,7 @@ class DisabilityObserver(PublicHealthObserver):
102
102
  )
103
103
  # Convert to SimpleCause instances and add on all_causes
104
104
  causes_of_disability = [
105
- SimpleCause.create_from_disease_state(cause) for cause in causes_of_disability
105
+ SimpleCause.create_from_specific_cause(cause) for cause in causes_of_disability
106
106
  ] + [SimpleCause("all_causes", "all_causes", "cause")]
107
107
 
108
108
  excluded_causes = (
@@ -1,7 +1,7 @@
1
1
  """
2
- ================
3
- Disease Observer
4
- ================
2
+ =================
3
+ Disease Observers
4
+ =================
5
5
 
6
6
  This module contains tools for observing disease incidence and prevalence
7
7
  in the simulation.
@@ -1,7 +1,7 @@
1
1
  """
2
- ==================
3
- Mortality Observer
4
- ==================
2
+ ===================
3
+ Mortality Observers
4
+ ===================
5
5
 
6
6
  This module contains tools for observing cause-specific and
7
7
  excess mortality in the simulation, including "other causes".
@@ -130,7 +130,7 @@ class MortalityObserver(PublicHealthObserver):
130
130
 
131
131
  # Convert to SimpleCauses and add on other_causes and not_dead
132
132
  self.causes_of_death = [
133
- SimpleCause.create_from_disease_state(cause) for cause in causes_of_death
133
+ SimpleCause.create_from_specific_cause(cause) for cause in causes_of_death
134
134
  ] + [
135
135
  SimpleCause("not_dead", "not_dead", "cause"),
136
136
  SimpleCause("other_causes", "other_causes", "cause"),
@@ -1,3 +1,13 @@
1
+ """
2
+ ===============
3
+ Basic Observers
4
+ ===============
5
+
6
+ This module contains convenience classes for building concrete observers in
7
+ public health models.
8
+
9
+ """
10
+
1
11
  from typing import Callable, List, Optional, Union
2
12
 
3
13
  import pandas as pd
@@ -1,12 +1,21 @@
1
+ """
2
+ ============
3
+ Simple Cause
4
+ ============
5
+
6
+ This module contains tools for creating a minimal representation of a cause
7
+ as required by observers.
8
+
9
+ """
10
+
1
11
  from dataclasses import dataclass
2
12
 
3
13
 
4
14
  @dataclass
5
15
  class SimpleCause:
6
- """A simple dataclass to represent the bare minimum information needed
7
- for observers, e.g. 'all_causes' as a cause of disability.
16
+ """A simple dataclass to represent the bare minimum information needed by observers.
8
17
 
9
- It also includes a class method to convert a provided disease state into a
18
+ It also includes a class method to convert a provided cause into a
10
19
  ``SimpleCause`` instance.
11
20
 
12
21
  """
@@ -19,6 +28,16 @@ class SimpleCause:
19
28
  """The cause type of the cause."""
20
29
 
21
30
  @classmethod
22
- def create_from_disease_state(cls, disease_state: type) -> "SimpleCause":
23
- """Create a SimpleCause instance from a"""
24
- return cls(disease_state.state_id, disease_state.model, disease_state.cause_type)
31
+ def create_from_specific_cause(cls, cause: type) -> "SimpleCause":
32
+ """Create a SimpleCause instance from a more specific cause.
33
+
34
+ Parameters
35
+ ----------
36
+ cause
37
+ The cause to be converted into a SimpleCause instance.
38
+
39
+ Returns
40
+ -------
41
+ A SimpleCause instance.
42
+ """
43
+ return cls(cause.state_id, cause.model, cause.cause_type)
@@ -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.4
3
+ Version: 3.0.6
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=tomMOl3PI7O8GdxDWGBiBjT0Bwd31GpyQTYTzwIv108,361
3
- vivarium_public_health/_version.py,sha256=gNoy6uoSQO4ZzowTZAJz3hphzq1F_Y-3X9YrQdb7ppc,22
3
+ vivarium_public_health/_version.py,sha256=uC8HeJcsNKDMSm12PYMv69I4zC6ciz4KILeBXWW_c8g,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
@@ -24,26 +24,26 @@ vivarium_public_health/population/data_transformations.py,sha256=QVh_63Wwg9BUkaQ
24
24
  vivarium_public_health/population/mortality.py,sha256=w7b_TUssHjRcnULdXu7MXKfZBjCrlYWbB94oO3JWogI,10264
25
25
  vivarium_public_health/results/__init__.py,sha256=XKuX9HTXUur1kpHM7zuMSnkJxlg-W7eMAPmh8LP9Xp4,281
26
26
  vivarium_public_health/results/columns.py,sha256=V-L3JgTcsk51Zx9PcUwSgaE1iZjuGyfZ8aShPjynadU,495
27
- vivarium_public_health/results/disability.py,sha256=DqSNI1CEdhNXy-mhTtuTXom22e6XGrvFoaeQwyBdlig,9872
28
- vivarium_public_health/results/disease.py,sha256=q5-g495tPbcs1zfApwoCTfkionAwQbCeXn3JigBUOIk,12526
29
- vivarium_public_health/results/mortality.py,sha256=Bo8l8CYcBmI6BsXl8l_7mPieGLzyUp3XeFBm497mThE,9652
30
- vivarium_public_health/results/observer.py,sha256=-VoOYOaT-vmxVNi0bxm3It0ZFdLIq8D9Ng28xO1JuLw,7143
27
+ vivarium_public_health/results/disability.py,sha256=JQm3Q7CoGCT2AgxaoH6MKkvnq4xF83wfFmEvEOvTmvA,9876
28
+ vivarium_public_health/results/disease.py,sha256=OwxhPrfDsCnCZSaw8Yiq2AnibWikoqI-gM7xDdhFLcM,12529
29
+ vivarium_public_health/results/mortality.py,sha256=imH5OGze_rb0i60hmFs-JUjE6XXoH8Gt9wWeut0sk_M,9656
30
+ vivarium_public_health/results/observer.py,sha256=SQmKL1OCs2gDS8clIuJvZ3WiuspMkGEVDhnuNMJAvHc,7300
31
31
  vivarium_public_health/results/risk.py,sha256=GS4qJVjW3MqsDeRDDac2etFQlqIluxOxIZFMy1Ytmp8,6622
32
- vivarium_public_health/results/simple_cause.py,sha256=jlrllbSiEIOrf69gQvrJww29uMrR8xzK_5TApu1Mxqg,724
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.4.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
- vivarium_public_health-3.0.4.dist-info/METADATA,sha256=mVOUpc6PRXAW7lnKkJ3BRJPKHT3erLyQuS60qlMFUzU,4061
47
- vivarium_public_health-3.0.4.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
48
- vivarium_public_health-3.0.4.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
- vivarium_public_health-3.0.4.dist-info/RECORD,,
45
+ vivarium_public_health-3.0.6.dist-info/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
46
+ vivarium_public_health-3.0.6.dist-info/METADATA,sha256=9R6AnfAPIZppi65fLRkAEMGemyS-yognH2oN1U9zS_g,4061
47
+ vivarium_public_health-3.0.6.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
48
+ vivarium_public_health-3.0.6.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
49
+ vivarium_public_health-3.0.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (74.1.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5