Skip to content

Commit 18046f4

Browse files
author
sm2511
committed
get heatmaps for all scenarios
1 parent 2558e5f commit 18046f4

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

src/scripts/consumables_analyses/analysis_impact_of_consumable_scenarios.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -751,40 +751,47 @@ def get_capacity_used_by_cadre_and_level(_df):
751751
programs = pd.read_csv(resourcefilepath / 'healthsystem'/ 'consumables' / "ResourceFile_Consumables_availability_and_usage.csv")[['category', 'item_code', 'module_name']]
752752
programs = programs.drop_duplicates('item_code')
753753
tlo_availability_df = tlo_availability_df.merge(programs, on = ['item_code'], how = 'left')
754-
755-
# Generate a heatmap
756-
# Pivot the DataFrame
757-
aggregated_df = tlo_availability_df.groupby(['category', 'Facility_Level'])['available_prop'].mean().reset_index()
758-
aggregated_df = aggregated_df[aggregated_df.Facility_Level.isin(['1a', '1b'])]
759-
aggregated_df.loc[aggregated_df.Facility_Level == '1a','Facility_Level'] = 'Health centres'
760-
aggregated_df.loc[aggregated_df.Facility_Level == '1b','Facility_Level'] = 'Hospitals'
761-
heatmap_data = aggregated_df.pivot("category", "Facility_Level", "available_prop")
762-
763-
# Calculate the aggregate row and column
764-
aggregate_col= aggregated_df.groupby('Facility_Level')['available_prop'].mean()
765-
aggregate_row = aggregated_df.groupby('category')['available_prop'].mean()
766-
overall_aggregate = aggregated_df['available_prop'].mean()
767-
768-
# Add aggregate row and column
769-
heatmap_data['Average'] = aggregate_row
770-
aggregate_col['Average'] = overall_aggregate
771-
heatmap_data.loc['Average'] = aggregate_col
772-
773-
# Generate the heatmap
774-
sns.set(font_scale=1.5)
775-
plt.figure(figsize=(10, 8))
776-
sns.heatmap(heatmap_data, annot=True, cmap='RdYlGn', cbar_kws={'label': 'Proportion of days on which consumable is available'})
777-
778-
# Customize the plot
779-
#plt.title('Consumable availability by Facility Level and Category')
780-
plt.xlabel('Facility Level')
781-
plt.ylabel(f'Disease/Public health \n program')
782-
plt.xticks(rotation=45)
783-
plt.yticks(rotation=0)
784-
785-
plt.savefig(figurespath /'consumable_availability_heatmap_1a_2.png', dpi=300, bbox_inches='tight')
786-
plt.show()
787-
plt.close()
754+
availability_scenarios = ['available_prop',
755+
'available_prop_scenario1', 'available_prop_scenario2',
756+
'available_prop_scenario3', 'available_prop_scenario4',
757+
'available_prop_scenario5', 'available_prop_scenario6',
758+
'available_prop_scenario7', 'available_prop_scenario8']
759+
i = 0
760+
for avail_scenario in availability_scenarios:
761+
# Generate a heatmap
762+
# Pivot the DataFrame
763+
aggregated_df = tlo_availability_df.groupby(['category', 'Facility_Level'])[avail_scenario].mean().reset_index()
764+
aggregated_df = aggregated_df[aggregated_df.Facility_Level.isin(['1a', '1b'])]
765+
aggregated_df.loc[aggregated_df.Facility_Level == '1a','Facility_Level'] = 'Health centres'
766+
aggregated_df.loc[aggregated_df.Facility_Level == '1b','Facility_Level'] = 'Hospitals'
767+
heatmap_data = aggregated_df.pivot("category", "Facility_Level", avail_scenario)
768+
769+
# Calculate the aggregate row and column
770+
aggregate_col= aggregated_df.groupby('Facility_Level')[avail_scenario].mean()
771+
aggregate_row = aggregated_df.groupby('category')[avail_scenario].mean()
772+
overall_aggregate = aggregated_df[avail_scenario].mean()
773+
774+
# Add aggregate row and column
775+
heatmap_data['Average'] = aggregate_row
776+
aggregate_col['Average'] = overall_aggregate
777+
heatmap_data.loc['Average'] = aggregate_col
778+
779+
# Generate the heatmap
780+
sns.set(font_scale=1.5)
781+
plt.figure(figsize=(10, 8))
782+
sns.heatmap(heatmap_data, annot=True, cmap='RdYlGn', cbar_kws={'label': 'Proportion of days on which consumable is available'})
783+
784+
# Customize the plot
785+
plt.title(scenarios[i])
786+
plt.xlabel('Facility Level')
787+
plt.ylabel(f'Disease/Public health \n program')
788+
plt.xticks(rotation=45)
789+
plt.yticks(rotation=0)
790+
791+
plt.savefig(figurespath /f'consumable_availability_heatmap_1a_2_{avail_scenario}.png', dpi=300, bbox_inches='tight')
792+
plt.show()
793+
plt.close()
794+
i = i + 1
788795

789796
# TODO Justify the focus on levels 1a and 1b - where do HSIs occur?; at what level is there most misallocation within districts
790797
# TODO get graphs of percentage of successful HSIs under different scenarios for levels 1a and 1b

0 commit comments

Comments
 (0)