vivarium-public-health 4.3.6__py3-none-any.whl → 4.3.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__ = "4.3.6"
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
  ]
@@ -257,22 +257,22 @@ class ScaledPopulation(BasePopulation):
257
257
  if "year_start" not in scaling_factor.index.names:
258
258
  return population_structure, scaling_factor
259
259
 
260
- # Subset to start year of simulation or closest year
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.
261
263
  pop_reference_years = sorted(
262
264
  set(population_structure.index.get_level_values("year_start"))
263
265
  )
264
- pop_year_index = np.digitize(year, pop_reference_years).item() - 1
265
- scale_reference_years = sorted(
266
- set(scaling_factor.index.get_level_values("year_start"))
267
- )
268
- scale_year_index = np.digitize(year, scale_reference_years).item() - 1
269
- # Subset to start year of simulation or earliest year. E.g. if start year = 2021 and pop
270
- # structure has 2021, we will subset to 2021. If pop structure minimum year is 2025, we
271
- # will subset to 2025.
266
+ pop_year_index = _find_bin_start_index(year, pop_reference_years)
272
267
  population_structure = population_structure.loc[
273
268
  population_structure.index.get_level_values("year_start")
274
269
  == pop_reference_years[pop_year_index]
275
270
  ]
271
+
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
276
  scaling_factor = scaling_factor.loc[
277
277
  scaling_factor.index.get_level_values("year_start")
278
278
  == scale_reference_years[scale_year_index]
@@ -527,3 +527,31 @@ def _assign_demography_with_age_bounds(
527
527
  )
528
528
  register_simulants(simulants[list(key_columns)])
529
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.6
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,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=bXuOm7EMaj1zGwMTlGgJNLOisp5gk6scG4bpGO0RNd8,22
3
+ vivarium_public_health/_version.py,sha256=jiLY_6kRRuH71R8uwkvkgOzPZ0hPgjpzzaC6-JM7Fyk,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/exceptions.py,sha256=vb30IIV82OiDf2cNZCs_E2rF6mdDDHbnZSND60no5CU,97
@@ -20,7 +20,7 @@ vivarium_public_health/plugins/__init__.py,sha256=oBW_zfgG_LbwfgTDjUe0btfy9FaDvA
20
20
  vivarium_public_health/plugins/parser.py,sha256=WoUisq0d-PfJtSzKYZ6C-s-fYdQpNiRBE14vKaYE27Y,32921
21
21
  vivarium_public_health/population/__init__.py,sha256=x_9rB93q64Krw-kbBDI1-_U_JsPO1_QrL03AwiFlwXI,243
22
22
  vivarium_public_health/population/add_new_birth_cohorts.py,sha256=x6A60GE_F3I8AgLABNJ-2ziiUj52lAd66uX5yc2vIDI,9038
23
- vivarium_public_health/population/base_population.py,sha256=XwfIfJRIcJsxphK62nVPZbrcAw0_7dhxGVuPEnGw3R0,20550
23
+ vivarium_public_health/population/base_population.py,sha256=IqQFVZiw-bSDX1MHjwn6pmQYoJksKNwi0OQo_uHZyDM,21399
24
24
  vivarium_public_health/population/data_transformations.py,sha256=YHbwfb40EPbXsPW-Rk1s5d61rP8fqgDtMELB7OJG3mo,22662
25
25
  vivarium_public_health/population/mortality.py,sha256=Mtv45FENNY0GlPIoVd3d3pRq01aEh4cjzNXIgEe6hMo,10364
26
26
  vivarium_public_health/results/__init__.py,sha256=rKUZGlRXJgEyFY4a_WJeg3XnC0l34S5guYZ0N9JJS4E,319
@@ -43,8 +43,8 @@ vivarium_public_health/treatment/__init__.py,sha256=wONElu9aJbBYwpYIovYPYaN_GYfV
43
43
  vivarium_public_health/treatment/magic_wand.py,sha256=zg4I48G-l9fC6-qjvApbM1zNACJimZlX9ZZ9fdHKwvc,1985
44
44
  vivarium_public_health/treatment/scale_up.py,sha256=_bsf9c_yVc7-q_-yBcXimISTUfYzPps1auH0uEf7sfQ,7048
45
45
  vivarium_public_health/treatment/therapeutic_inertia.py,sha256=ZIHnpuszZwA_BkS53JbSLvpcnX_bqG2knwCUyUgkA9M,2362
46
- vivarium_public_health-4.3.6.dist-info/licenses/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
47
- vivarium_public_health-4.3.6.dist-info/METADATA,sha256=YdB1JSLxInm6y2_uIOnjiG8tqavEJQiOBsQaxn9tqgA,3877
48
- vivarium_public_health-4.3.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
- vivarium_public_health-4.3.6.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
50
- vivarium_public_health-4.3.6.dist-info/RECORD,,
46
+ vivarium_public_health-4.3.7.dist-info/licenses/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
47
+ vivarium_public_health-4.3.7.dist-info/METADATA,sha256=M7KR6H7eH4yPNByDLXOPWBLjKrdytboajMaN28u9MxU,3877
48
+ vivarium_public_health-4.3.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
+ vivarium_public_health-4.3.7.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
50
+ vivarium_public_health-4.3.7.dist-info/RECORD,,