Skip to content

Commit ff41fa1

Browse files
Update Level 1b consumable availability to reflect 1b-2 merge (#1743)
* update availability of consumables at level 1b to reflect the weighted average of availability at levels 1b and 2 * allow for different weights when calculating average * revert original resource file * add new resource files with different ways of handling level 1b availability * merge in xpert update from master * apply weighted average of level 1b and 2 facilities to level 1b probability across alternative consumable scenarios - set up so that `consumable_availability_estimation.py` produces the final RF using functions from `generate_consumable_availability_scenarios_for_impact_analysis.py` * remove test ResourceFiles applying different level 1b-2 weights. * update logical check for changes in consumables availabiltity in routine `update_consumables_availability_to_represent_merging_of_levels_1b_and_2` * Add note * linting * introduce switch to allow use of the original consumables dataset * correct filename * check both consumables data files * update old scripts to point to original consumbales file to preserve consistency. * linting --------- Co-authored-by: Tim Hallett <39991060+tbhallett@users.noreply.github.com>
1 parent eafccb9 commit ff41fa1

9 files changed

Lines changed: 1266 additions & 1198 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ff3be5d065013bc7c5cffd982f04fa3b37a923ebd3f37e5dbb39542703dd2310
3-
size 914
2+
oid sha256:b96e35b518fb33fe0c89b9e47d6b623ec9eb30d454b404554312787a5937404e
3+
size 967
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:3bc044868ad9f1c618fc9b3fd6fc0ed23f32b153c8438f52fd4b72e40d8f503f
3-
size 55831644
2+
oid sha256:2ab824924a4c0e798eeec6c2514c50577ba83185120ec257d5065c583fe1dfa6
3+
size 57341233
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3bc044868ad9f1c618fc9b3fd6fc0ed23f32b153c8438f52fd4b72e40d8f503f
3+
size 55831644

src/scripts/contraception/Items_InclAvailabilityData.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
last_line_interv_pkg_name = 'Female Condom'
2828
name_containing = 'sutur'
2929
what_to_check = 'lines' # 'lines' or 'item_name'
30-
avail_data_filename = 'ResourceFile_Consumables_availability_small.csv'
30+
avail_data_filename = 'ResourceFile_Consumables_availability_small_original.csv'
3131
#####
3232

3333
avail_data = pd.read_csv(Path(

src/scripts/data_file_processing/healthsystem/consumables/consumable_resource_analyses_with_lmis/consumables_availability_estimation.py

Lines changed: 516 additions & 242 deletions
Large diffs are not rendered by default.

src/scripts/data_file_processing/healthsystem/consumables/generating_consumable_scenarios/generate_consumable_availability_scenarios_for_impact_analysis.py

Lines changed: 711 additions & 943 deletions
Large diffs are not rendered by default.

src/scripts/malaria/malaria_cons_availability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# get consumables spreadsheet
1717
cons_availability = pd.read_csv(
18-
resourcefilepath / "healthsystem/consumables/ResourceFile_Consumables_availability_small.csv")
18+
resourcefilepath / "healthsystem/consumables/ResourceFile_Consumables_availability_small_original.csv")
1919
items_list = pd.read_csv(
2020
resourcefilepath / "healthsystem/consumables/ResourceFile_Consumables_Items_and_Packages.csv")
2121

src/tlo/methods/healthsystem.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
# those of '2' and have more overall capacity, so
5353
# probably account for the majority of the
5454
# interactions.
55-
55+
# Note that, as of PR #1743, this should not be changed, as the availability of consumables at level 1b is now
56+
# encoded to reflect a (weighted) average of the availability of levels '1b' and '2'.
5657

5758
def pool_capabilities_at_levels_1b_and_2(df_original: pd.DataFrame) -> pd.DataFrame:
5859
"""Return a modified version of the imported capabilities DataFrame to reflect that the capabilities of level 1b
@@ -200,6 +201,12 @@ class HealthSystem(Module):
200201
Types.DATA_FRAME,
201202
"Look-up table for the designations of consumables (whether diagnostic, medicine, or other",
202203
),
204+
"data_source_for_cons_availability_estimates": Parameter(
205+
Types.STRING, "Source of data on consumable availability. Options are: `original` or `updated`."
206+
"The original source was used in the calibration and presented in the overview paper. The "
207+
"updated source introduced in PR #1743 and better reflects the average availability of "
208+
"consumables in the merged 1b/2 facility level."
209+
),
203210
"availability_estimates": Parameter(
204211
Types.DATA_FRAME, "Estimated availability of consumables in the LMIS dataset."
205212
),
@@ -655,10 +662,20 @@ def read_parameters(self, resourcefilepath: Optional[Path] = None):
655662
path_to_resourcefiles_for_healthsystem / "consumables" / "ResourceFile_Consumables_Item_Designations.csv",
656663
dtype={"Item_Code": int, "is_diagnostic": bool, "is_medicine": bool, "is_other": bool},
657664
).set_index("Item_Code")
665+
666+
# Choose to read-in the updated availabilty estimates or the legacy availability estimates
667+
if self.parameters["data_source_for_cons_availability_estimates"] == 'original':
668+
filename_for_cons_availability_estimates = "ResourceFile_Consumables_availability_small_original.csv"
669+
elif self.parameters["data_source_for_cons_availability_estimates"] == 'updated':
670+
filename_for_cons_availability_estimates = "ResourceFile_Consumables_availability_small.csv"
671+
else:
672+
raise ValueError("data_source_for_cons_availability_estimates should be either 'original' or 'updated'")
673+
658674
self.parameters["availability_estimates"] = pd.read_csv(
659-
path_to_resourcefiles_for_healthsystem / "consumables" / "ResourceFile_Consumables_availability_small.csv"
675+
path_to_resourcefiles_for_healthsystem / "consumables" / filename_for_cons_availability_estimates
660676
)
661677

678+
662679
# Data on the number of beds available of each type by facility_id
663680
self.parameters["BedCapacity"] = pd.read_csv(
664681
path_to_resourcefiles_for_healthsystem / "infrastructure_and_equipment" / "ResourceFile_Bed_Capacity.csv"
@@ -1330,7 +1347,7 @@ def update_consumables_availability_to_represent_merging_of_levels_1b_and_2(self
13301347
assert (df_updated.columns == df_original.columns).all()
13311348
assert (df_updated.dtypes == df_original.dtypes).all()
13321349

1333-
# check values the same for everything apart from the facility level '2' facilities
1350+
# check values the same for everything apart from the facility level 'LABEL_FOR_MERGED_FACILITY_LEVELS_1B_AND_2'
13341351
facilities_with_any_differences = set(
13351352
df_updated.loc[
13361353
~(
@@ -1339,8 +1356,10 @@ def update_consumables_availability_to_represent_merging_of_levels_1b_and_2(self
13391356
"Facility_ID",
13401357
]
13411358
)
1342-
level2_facilities = set(mfl.loc[mfl["Facility_Level"] == "2", "Facility_ID"])
1343-
assert facilities_with_any_differences.issubset(level2_facilities)
1359+
updated_facilities = set(
1360+
mfl.loc[mfl['Facility_Level'] == LABEL_FOR_MERGED_FACILITY_LEVELS_1B_AND_2, 'Facility_ID']
1361+
)
1362+
assert facilities_with_any_differences.issubset(updated_facilities)
13441363

13451364
return df_updated
13461365

tests/test_consumables.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,13 @@ def schedule_hsi_that_will_request_consumables(sim):
531531

532532
def test_check_format_of_consumables_file():
533533
"""Run the check on the file used by default for the Consumables data"""
534+
path_to_file = resourcefilepath / 'healthsystem' / 'consumables'
534535
check_format_of_consumables_file(
535-
pd.read_csv(
536-
resourcefilepath / 'healthsystem' / 'consumables' / 'ResourceFile_Consumables_availability_small.csv'),
536+
pd.read_csv(path_to_file / 'ResourceFile_Consumables_availability_small.csv'),
537+
fac_ids=fac_ids
538+
)
539+
check_format_of_consumables_file(
540+
pd.read_csv(path_to_file / 'ResourceFile_Consumables_availability_small_original.csv'),
537541
fac_ids=fac_ids
538542
)
539543

0 commit comments

Comments
 (0)