vivarium-public-health 4.3.5__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.5"
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,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=NYrliYxjsS6KdKfQAwEvUhfqJXk87BHG-YA6Q3DTUIY,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=Wu797AL13KRLhXkYni_XocJBLfhfvCVgGeas08U3tCM,18898
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.5.dist-info/licenses/LICENSE.txt,sha256=mN4bNLUQNcN9njYRc_3jCZkfPySVpmM6MRps104FxA4,1548
47
- vivarium_public_health-4.3.5.dist-info/METADATA,sha256=AqoR7HJE8HzNFk3525wVzzu_SHktWYfVa6GO0leCXs4,3877
48
- vivarium_public_health-4.3.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
49
- vivarium_public_health-4.3.5.dist-info/top_level.txt,sha256=VVInlpzCFD0UNNhjOq_j-a29odzjwUwYFTGfvqbi4dY,23
50
- vivarium_public_health-4.3.5.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,,