vivarium-public-health 4.3.5__tar.gz → 4.3.7__tar.gz

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.
Files changed (157) hide show
  1. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/CHANGELOG.rst +8 -0
  2. {vivarium_public_health-4.3.5/src/vivarium_public_health.egg-info → vivarium_public_health-4.3.7}/PKG-INFO +1 -1
  3. vivarium_public_health-4.3.7/src/vivarium_public_health/_version.py +1 -0
  4. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/population/base_population.py +70 -7
  5. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7/src/vivarium_public_health.egg-info}/PKG-INFO +1 -1
  6. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/population/test_base_population.py +141 -1
  7. vivarium_public_health-4.3.5/src/vivarium_public_health/_version.py +0 -1
  8. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.bandit +0 -0
  9. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.flake8 +0 -0
  10. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.gitattributes +0 -0
  11. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.github/CODEOWNERS +0 -0
  12. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.github/pull_request_template.md +0 -0
  13. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.github/workflows/deploy.yml +0 -0
  14. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.gitignore +0 -0
  15. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.pylintrc +0 -0
  16. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.readthedocs.yml +0 -0
  17. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/.zenodo.json +0 -0
  18. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/CODE_OF_CONDUCT.rst +0 -0
  19. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/CONTRIBUTING.rst +0 -0
  20. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/Jenkinsfile +0 -0
  21. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/LICENSE.txt +0 -0
  22. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/MANIFEST.in +0 -0
  23. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/Makefile +0 -0
  24. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/README.rst +0 -0
  25. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/Makefile +0 -0
  26. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/nitpick-exceptions +0 -0
  27. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/_static/style.css +0 -0
  28. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/_templates/layout.html +0 -0
  29. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/disease/index.rst +0 -0
  30. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/disease/model.rst +0 -0
  31. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/disease/models.rst +0 -0
  32. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/disease/special_disease.rst +0 -0
  33. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/disease/state.rst +0 -0
  34. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/disease/transition.rst +0 -0
  35. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/index.rst +0 -0
  36. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/delay.rst +0 -0
  37. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/disease.rst +0 -0
  38. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/index.rst +0 -0
  39. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/intervention.rst +0 -0
  40. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/magic_wand_components.rst +0 -0
  41. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/observer.rst +0 -0
  42. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/mslt/population.rst +0 -0
  43. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/plugins/index.rst +0 -0
  44. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/plugins/parser.rst +0 -0
  45. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/population/add_new_birth_cohorts.rst +0 -0
  46. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/population/base_population.rst +0 -0
  47. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/population/data_transformations.rst +0 -0
  48. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/population/index.rst +0 -0
  49. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/population/mortality.rst +0 -0
  50. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/disability.rst +0 -0
  51. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/disease.rst +0 -0
  52. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/index.rst +0 -0
  53. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/mortality.rst +0 -0
  54. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/observer.rst +0 -0
  55. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/risk.rst +0 -0
  56. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/simple_cause.rst +0 -0
  57. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/results/stratification.rst +0 -0
  58. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/base_risk.rst +0 -0
  59. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/data_transformations.rst +0 -0
  60. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/distributions.rst +0 -0
  61. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/effect.rst +0 -0
  62. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/implementations/index.rst +0 -0
  63. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/implementations/low_birth_weight_and_short_gestation.rst +0 -0
  64. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/risks/index.rst +0 -0
  65. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/treatment/index.rst +0 -0
  66. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/treatment/magic_wand.rst +0 -0
  67. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/treatment/scale_up.rst +0 -0
  68. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/treatment/therapeutic_inertia.rst +0 -0
  69. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/api_reference/utilities.rst +0 -0
  70. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/conf.py +0 -0
  71. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/index.rst +0 -0
  72. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/tutorials/index.rst +0 -0
  73. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/docs/source/tutorials/risk_exposure.rst +0 -0
  74. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/pyproject.toml +0 -0
  75. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/python_versions.json +0 -0
  76. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/setup.cfg +0 -0
  77. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/setup.py +0 -0
  78. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/__about__.py +0 -0
  79. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/__init__.py +0 -0
  80. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/__init__.py +0 -0
  81. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/exceptions.py +0 -0
  82. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/model.py +0 -0
  83. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/models.py +0 -0
  84. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/special_disease.py +0 -0
  85. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/state.py +0 -0
  86. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/disease/transition.py +0 -0
  87. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/__init__.py +0 -0
  88. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/delay.py +0 -0
  89. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/disease.py +0 -0
  90. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/intervention.py +0 -0
  91. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/magic_wand_components.py +0 -0
  92. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/observer.py +0 -0
  93. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/mslt/population.py +0 -0
  94. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/plugins/__init__.py +0 -0
  95. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/plugins/parser.py +0 -0
  96. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/population/__init__.py +0 -0
  97. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/population/add_new_birth_cohorts.py +0 -0
  98. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/population/data_transformations.py +0 -0
  99. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/population/mortality.py +0 -0
  100. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/__init__.py +0 -0
  101. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/columns.py +0 -0
  102. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/disability.py +0 -0
  103. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/disease.py +0 -0
  104. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/mortality.py +0 -0
  105. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/observer.py +0 -0
  106. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/risk.py +0 -0
  107. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/simple_cause.py +0 -0
  108. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/results/stratification.py +0 -0
  109. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/__init__.py +0 -0
  110. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/base_risk.py +0 -0
  111. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/data_transformations.py +0 -0
  112. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/distributions.py +0 -0
  113. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/effect.py +0 -0
  114. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/implementations/__init__.py +0 -0
  115. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/risks/implementations/low_birth_weight_and_short_gestation.py +0 -0
  116. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/treatment/__init__.py +0 -0
  117. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/treatment/magic_wand.py +0 -0
  118. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/treatment/scale_up.py +0 -0
  119. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/treatment/therapeutic_inertia.py +0 -0
  120. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health/utilities.py +0 -0
  121. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health.egg-info/SOURCES.txt +0 -0
  122. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health.egg-info/dependency_links.txt +0 -0
  123. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health.egg-info/not-zip-safe +0 -0
  124. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health.egg-info/requires.txt +0 -0
  125. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/src/vivarium_public_health.egg-info/top_level.txt +0 -0
  126. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/__init__.py +0 -0
  127. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/conftest.py +0 -0
  128. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/data/rr_interpolator.csv +0 -0
  129. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/disease/__init__.py +0 -0
  130. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/disease/test_disease.py +0 -0
  131. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/disease/test_special_disease.py +0 -0
  132. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/mock_artifact.py +0 -0
  133. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/plugins/__init__.py +0 -0
  134. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/plugins/test_parser.py +0 -0
  135. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/population/__init__.py +0 -0
  136. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/population/conftest.py +0 -0
  137. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/population/test_add_new_birth_cohort.py +0 -0
  138. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/population/test_data_transformations.py +0 -0
  139. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/population/test_mortality.py +0 -0
  140. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/__init__.py +0 -0
  141. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/test_categorical_risk_observer.py +0 -0
  142. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/test_disability.py +0 -0
  143. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/test_disability_observer.py +0 -0
  144. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/test_disease_observer.py +0 -0
  145. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/test_mortality_observer.py +0 -0
  146. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/results/test_stratification.py +0 -0
  147. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/__init__.py +0 -0
  148. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/conftest.py +0 -0
  149. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/test_base_risk.py +0 -0
  150. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/test_data_transformations.py +0 -0
  151. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/test_distributions.py +0 -0
  152. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/test_effect.py +0 -0
  153. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/risks/test_low_birth_weight_and_short_gestation.py +0 -0
  154. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/test_utilities.py +0 -0
  155. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/treatment/__init__.py +0 -0
  156. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tests/treatment/test_scale_up.py +0 -0
  157. {vivarium_public_health-4.3.5 → vivarium_public_health-4.3.7}/tox.ini +0 -0
@@ -1,3 +1,11 @@
1
+ **4.3.7 - 09/10/25**
2
+
3
+ - Bugfix: raise an error if simulation start year is earlier than population data.
4
+
5
+ **4.3.6 - 08/28/25**
6
+
7
+ - Feature: ScaledPopulation can handle multiple year data inputs.
8
+
1
9
  **4.3.5 - 08/01/25**
2
10
 
3
11
  - Use vivarium_dependencies for common setup constraints
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vivarium_public_health
3
- Version: 4.3.5
3
+ Version: 4.3.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
@@ -0,0 +1 @@
1
+ __version__ = "4.3.7"
@@ -166,7 +166,7 @@ class BasePopulation(Component):
166
166
  demographic_proportions, year: int
167
167
  ) -> pd.DataFrame:
168
168
  reference_years = sorted(set(demographic_proportions.year_start))
169
- ref_year_index = np.digitize(year, reference_years).item() - 1
169
+ ref_year_index = _find_bin_start_index(year, reference_years)
170
170
  return demographic_proportions[
171
171
  demographic_proportions.year_start == reference_years[ref_year_index]
172
172
  ]
@@ -235,15 +235,50 @@ class ScaledPopulation(BasePopulation):
235
235
  raise ValueError(
236
236
  f"Scaling factor must be a pandas DataFrame. Provided value: {scaling_factor}"
237
237
  )
238
- scaling_factor = scaling_factor.set_index(
239
- [col for col in scaling_factor.columns if col != "value"]
238
+ start_year = builder.configuration.time.start.year
239
+ population_structure, scaling_factor = self._format_data_inputs(
240
+ population_structure, scaling_factor, start_year
240
241
  )
241
- population_structure = population_structure.set_index(
242
- [col for col in population_structure.columns if col != "value"]
242
+
243
+ return (population_structure * scaling_factor).reset_index()
244
+
245
+ def _format_data_inputs(
246
+ self, pop_structure: pd.DataFrame, scalar_data: pd.DataFrame, year: int
247
+ ) -> tuple[pd.DataFrame, pd.DataFrame]:
248
+ """Data cleaning function to check whether scalar_data and population structure are compatible for scaling
249
+ the population structure of a simulation."""
250
+
251
+ scaling_factor = scalar_data.set_index(
252
+ [col for col in scalar_data.columns if col != "value"]
243
253
  )
244
- scaled_population_structure = (population_structure * scaling_factor).reset_index()
254
+ population_structure = pop_structure.set_index(
255
+ [col for col in pop_structure.columns if col != "value"]
256
+ )
257
+ if "year_start" not in scaling_factor.index.names:
258
+ return population_structure, scaling_factor
259
+
260
+ # Subset the population structure and scaling factors to the simulation
261
+ # start year. If the data does not contain the exact simulation start
262
+ # year, subset to the closest year less than the simulation start year.
263
+ pop_reference_years = sorted(
264
+ set(population_structure.index.get_level_values("year_start"))
265
+ )
266
+ pop_year_index = _find_bin_start_index(year, pop_reference_years)
267
+ population_structure = population_structure.loc[
268
+ population_structure.index.get_level_values("year_start")
269
+ == pop_reference_years[pop_year_index]
270
+ ]
245
271
 
246
- return scaled_population_structure
272
+ scale_reference_years = sorted(
273
+ set(scaling_factor.index.get_level_values("year_start"))
274
+ )
275
+ scale_year_index = _find_bin_start_index(year, scale_reference_years)
276
+ scaling_factor = scaling_factor.loc[
277
+ scaling_factor.index.get_level_values("year_start")
278
+ == scale_reference_years[scale_year_index]
279
+ ]
280
+
281
+ return population_structure, scaling_factor
247
282
 
248
283
 
249
284
  class AgeOutSimulants(Component):
@@ -492,3 +527,31 @@ def _assign_demography_with_age_bounds(
492
527
  )
493
528
  register_simulants(simulants[list(key_columns)])
494
529
  return simulants
530
+
531
+
532
+ def _find_bin_start_index(value: int, sorted_reference_values: list[int]) -> int:
533
+ """Finds the index of the closest reference value less than or equal to the provided value.
534
+
535
+ Parameters
536
+ ----------
537
+ value
538
+ The value for which to find the closest reference value.
539
+ sorted_reference_values
540
+ A sorted list of reference values.
541
+
542
+ Returns
543
+ -------
544
+ The index of the closest reference value less than or equal to the provided value.
545
+
546
+ Raises
547
+ ------
548
+ ValueError
549
+ If the provided value is less than the minimum reference value.
550
+ """
551
+ ref_value_index = np.digitize(value, sorted_reference_values).item() - 1
552
+ if ref_value_index < 0:
553
+ raise ValueError(
554
+ f"The provided value {value} is less than the minimum reference value "
555
+ f"{min(sorted_reference_values)}."
556
+ )
557
+ return ref_value_index
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vivarium_public_health
3
- Version: 4.3.5
3
+ Version: 4.3.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,4 +1,5 @@
1
1
  import math
2
+ from itertools import product
2
3
 
3
4
  import numpy as np
4
5
  import pandas as pd
@@ -294,7 +295,11 @@ def test_scaled_population(
294
295
  "population_size": 1_000_000,
295
296
  "include_sex": "Both",
296
297
  },
297
- "time": {"step_size": 1},
298
+ "time": {
299
+ "step_size": 1,
300
+ # Update the start year to fall within the population structure data.
301
+ "start": {"year": 2021},
302
+ },
298
303
  },
299
304
  layer="override",
300
305
  )
@@ -349,6 +354,141 @@ def test_scaled_population(
349
354
  )
350
355
 
351
356
 
357
+ @pytest.mark.parametrize("test_case", ["pop_structure", "both"])
358
+ @pytest.mark.parametrize("year", [2021, 2025])
359
+ def test_scaled_population__format_data_inputs(
360
+ test_case: str,
361
+ year: int,
362
+ ) -> None:
363
+ """Test ScaledPopulation with multi-year data in population structure and/or scaling factor.
364
+
365
+ Cases:
366
+ 1. pop_structure: Population structure has multiple years, scaling factor does not
367
+ 2. both: Both population structure and scaling factor have multiple years
368
+ """
369
+
370
+ # Create multi-year population structure (2021-2024)
371
+ age_idx = pd.MultiIndex.from_tuples(
372
+ [
373
+ (0.0, 25.0, "Young People"),
374
+ (25.0, 50.0, "Old People"),
375
+ (50.0, 75.0, "Ancient People"),
376
+ (75.0, 100.0, "People Who Beat the Odds"),
377
+ ],
378
+ names=["age_start", "age_end", "age_group_name"],
379
+ )
380
+ age_df = pd.DataFrame(index=age_idx).reset_index()
381
+ age_bins = [(group.age_start, group.age_end) for group in age_df.itertuples()]
382
+ sexes = ("Male", "Female")
383
+ location = ["Kenya"]
384
+ years = [(2021, 2022), (2022, 2023), (2023, 2024)] # Multiple years
385
+
386
+ age_bins, sexes, years, location = zip(*product(age_bins, sexes, years, location))
387
+ mins, maxes = zip(*age_bins)
388
+ year_starts, year_ends = zip(*years)
389
+
390
+ pop_structure = pd.DataFrame(
391
+ {
392
+ "location": location,
393
+ "sex": sexes,
394
+ "age_start": mins,
395
+ "age_end": maxes,
396
+ "year_start": year_starts,
397
+ "year_end": year_ends,
398
+ # Base values for each demographic group
399
+ "value": [1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0] * 3, # Repeated for 3 years
400
+ }
401
+ )
402
+
403
+ # Create scaling factor data based on test case
404
+ if test_case == "pop_structure":
405
+ # Scaling factor single year
406
+ scalar_data = pd.DataFrame(
407
+ {
408
+ "sex": ["Male", "Female"] * 4,
409
+ "age_start": [0.0, 0.0, 25.0, 25.0, 50.0, 50.0, 75.0, 75.0],
410
+ "age_end": [25.0, 25.0, 50.0, 50.0, 75.0, 75.0, 100.0, 100.0],
411
+ "year_start": [2021] * 8,
412
+ "year_end": [2022] * 8,
413
+ "value": [1.5, 1.2, 2.1, 1.8, 0.9, 1.1, 1.3, 1.4],
414
+ }
415
+ )
416
+ # Remove year_start and year end since scalar data only has one year
417
+ formatted_scalar_data = scalar_data.set_index(
418
+ ["sex", "age_start", "age_end"], drop=True
419
+ )[["value"]]
420
+ elif test_case == "both":
421
+ # Both have multiple years - should be able to multiply together directly
422
+ scalar_data = pd.DataFrame(
423
+ {
424
+ "age_start": [0.0, 0.0, 25.0, 25.0, 50.0, 50.0, 75.0, 75.0] * 3,
425
+ "age_end": [25.0, 25.0, 50.0, 50.0, 75.0, 75.0, 100.0, 100.0] * 3,
426
+ "sex": ["Male", "Female"] * 12,
427
+ "year_start": [2021] * 8 + [2022] * 8 + [2023] * 8,
428
+ "year_end": [2022] * 8 + [2023] * 8 + [2024] * 8,
429
+ "value": [
430
+ 1.0,
431
+ 1.0,
432
+ 1.0,
433
+ 1.0,
434
+ 1.0,
435
+ 1.0,
436
+ 1.0,
437
+ 1.0,
438
+ 1.5,
439
+ 1.2,
440
+ 2.1,
441
+ 1.8,
442
+ 0.9,
443
+ 1.1,
444
+ 1.3,
445
+ 1.4,
446
+ 1.8,
447
+ 1.4,
448
+ 2.3,
449
+ 2.0,
450
+ 1.2,
451
+ 1.6,
452
+ 1.7,
453
+ 1.9,
454
+ ],
455
+ }
456
+ )
457
+
458
+ # Subset to 2021 or subset to 2023 since that is latest year start to verify
459
+ # we are subsetting to correct year in _format_data_inputs
460
+ query_year = 2021 if year == 2021 else 2023
461
+ formatted_pop_structure = pop_structure.loc[pop_structure["year_start"] == query_year]
462
+ formatted_scalar_data = scalar_data.loc[scalar_data["year_start"] == query_year]
463
+ formatted_scalar_data = formatted_scalar_data.set_index(
464
+ ["sex", "age_start", "age_end", "year_start", "year_end"], drop=True
465
+ )
466
+ formatted_pop_structure = formatted_pop_structure.set_index(
467
+ ["location", "sex", "age_start", "age_end", "year_start", "year_end"]
468
+ )
469
+ scaled_pop = bp.ScaledPopulation("placeholder")
470
+ formatted = scaled_pop._format_data_inputs(pop_structure, scalar_data, year)
471
+ expected = (formatted[0] * formatted[1]).reset_index()
472
+ data = (formatted_pop_structure * formatted_scalar_data).reset_index()
473
+ pd.testing.assert_frame_equal(data, expected)
474
+
475
+
476
+ def test__find_bin_start_index():
477
+ sorted_values = [10, 20, 30]
478
+ assert bp._find_bin_start_index(10, sorted_values) == 0
479
+ assert bp._find_bin_start_index(19, sorted_values) == 0
480
+ assert bp._find_bin_start_index(20, sorted_values) == 1
481
+ assert bp._find_bin_start_index(29, sorted_values) == 1
482
+ assert bp._find_bin_start_index(30, sorted_values) == 2
483
+ assert bp._find_bin_start_index(99999, sorted_values) == 2
484
+
485
+ # Edge case
486
+ with pytest.raises(
487
+ ValueError, match="The provided value 9 is less than the minimum reference value 10."
488
+ ):
489
+ bp._find_bin_start_index(9, sorted_values)
490
+
491
+
352
492
  def _check_population(simulants, initial_age, step_size, include_sex):
353
493
  assert len(simulants) == len(simulants.age.unique())
354
494
  assert simulants.age.min() > initial_age
@@ -1 +0,0 @@
1
- __version__ = "4.3.5"