This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlives_touched_lives_improved.py
202 lines (159 loc) · 9.32 KB
/
lives_touched_lives_improved.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 22 08:48:52 2019
Lives touched, lives improved model
@author: LaurencT
"""
import pandas as pd
import sys
# Import other modules written for LTLI
sys.path.append('C:/Users/laurenct/OneDrive - Wellcome Cloud/My Documents/python/lives_touched_lives_improved/scripts')
from argument_parser import ltli_argument_parser
from argument_parser import print_selected_arguments
import model_inputs
import input_check
from generate_deterministic_params import get_deterministic_params
from generate_probabilistic_params import get_probabilistic_params
from restructure_cov_pop_burden import get_relevant_burden
from restructure_cov_pop_burden import adjust_burden_dict
from restructure_cov_pop_burden import create_coverage_population_dict
from restructure_cov_pop_burden import adjust_cov_pop_for_trials
from restructure_cov_pop_burden import merge_cov_pop_and_burden
from adjust_for_intervention_factors import adjust_for_intervention_factors
import apply_exceptions
import calculate_ltli
import reshape_for_graphs
import exports
# Set up directories, file names and analysis type
DATA_DIR = 'C:/Users/laurenct/OneDrive - Wellcome Cloud/My Documents/python/lives_touched_lives_improved/data/'
GRAPH_DIR = 'C:/Users/laurenct/OneDrive - Wellcome Cloud/My Documents/python/lives_touched_lives_improved/graphs/'
OUTPUTS_DIR = 'C:/Users/laurenct/OneDrive - Wellcome Cloud/My Documents/python/lives_touched_lives_improved/outputs/'
BACKUP_DIR = 'C:/Users/laurenct/OneDrive - Wellcome Cloud/My Documents/python/lives_touched_lives_improved/data/backup/'
SLIDES_DIR = 'C:/Users/laurenct/Wellcome Cloud/Innovations - Lives touched, lives improved model results/'
PARAM_CSV_NAME = 'LTLI_parameters.csv'
ESTIMATES_CSV_NAME = 'LTLI_outputs_baseline.csv'
POPULATION_CSV_NAME = 'GBD_population_2016_reshaped.csv'
BURDEN_CSV_NAME = 'gbd_data_wide_2017.csv'
COVERAGE_XLS_NAME = 'intervention_coverage_assumptions.xlsm'
COVERAGE_SHEET_NAME = 'Penetration assumptions'
PPT_TEMPLATE_NAME = 'mm_template_impact.pptx'
ANALYSIS_TYPE = {'run_all' : False, # True if you just want to run all the models or False to run one model
'num_trials' : 1000, # 1000 as standard - could do fewer to speed up
'overwrite_estimates' : True # True or False - do you want to overwrite the estimates linked to Tableau
}
# Code run sequentially
if __name__ == "__main__":
# Argument parser
args = ltli_argument_parser(DATA_DIR, GRAPH_DIR, OUTPUTS_DIR, BACKUP_DIR, SLIDES_DIR,
PARAM_CSV_NAME, ESTIMATES_CSV_NAME, POPULATION_CSV_NAME,
BURDEN_CSV_NAME, COVERAGE_XLS_NAME, COVERAGE_SHEET_NAME,
PPT_TEMPLATE_NAME)
DATA_DIR = args.DATA_DIR
GRAPH_DIR = args.GRAPH_DIR
OUTPUTS_DIR = args.OUTPUTS_DIR
BACKUP_DIR = args.BACKUP_DIR
SLIDES_DIR = args.SLIDES_DIR
PARAM_CSV_NAME = args.PARAM_CSV_NAME
ESTIMATES_CSV_NAME = args.ESTIMATES_CSV_NAME
POPULATION_CSV_NAME = args.POPULATION_CSV_NAME
BURDEN_CSV_NAME = args.BURDEN_CSV_NAME
COVERAGE_XLS_NAME = args.COVERAGE_XLS_NAME
COVERAGE_SHEET_NAME = args.COVERAGE_SHEET_NAME
PPT_TEMPLATE_NAME = args.PPT_TEMPLATE_NAME
print_selected_arguments(DATA_DIR, GRAPH_DIR, OUTPUTS_DIR, BACKUP_DIR, SLIDES_DIR,
PARAM_CSV_NAME, ESTIMATES_CSV_NAME, POPULATION_CSV_NAME,
BURDEN_CSV_NAME, COVERAGE_XLS_NAME, COVERAGE_SHEET_NAME,
PPT_TEMPLATE_NAME)
# Loads the relevant model parameters
param_user_all = model_inputs.load_params(PARAM_CSV_NAME, DATA_DIR)
# Loads the latest estimates before this model run (csv is structured same as params)
estimates_output = model_inputs.load_params(ESTIMATES_CSV_NAME, DATA_DIR)
# Transforms the parameters to a dict for future transformation
param_user_dict = model_inputs.create_param_dict(param_user_all)
population = model_inputs.load_population_data(POPULATION_CSV_NAME, DATA_DIR)
burden_all = model_inputs.load_burden_data(BURDEN_CSV_NAME, DATA_DIR)
coverage = model_inputs.load_coverage_assumptions(COVERAGE_XLS_NAME,
COVERAGE_SHEET_NAME,
DATA_DIR)
# Write in a parameter checking function as the first function
input_check.check_inputs(ANALYSIS_TYPE,
param_user_all,
population,
coverage,
burden_all)
# Vary the parameter dict depending on whether you are running all the analysis
# or just a subset
param_user = input_check.check_run_all(ANALYSIS_TYPE,
param_user_dict)
# Create different versions of the parameters ready for sensitivity analyses
deterministic_dict = get_deterministic_params(ANALYSIS_TYPE, param_user)
probabilistic_dict = get_probabilistic_params(ANALYSIS_TYPE, param_user)
# Combine all parameters into one dict
param_dict = {k: pd.concat([deterministic_dict[k], probabilistic_dict[k]], sort = True)
for k in deterministic_dict.keys()}
print('All the parameters have been simulated')
# Get the disease burden data for each set of parameters
burden_dict_unadjusted = get_relevant_burden(param_dict, burden_all)
# Adjust burden so it is in a dictionary of relevant burden dfs for each set
# of parameters
burden_dict= adjust_burden_dict(burden_dict_unadjusted, param_dict)
# Create the cov_pop_dict based on coverage for that type of intervention an
# population
cov_pop_dict = create_coverage_population_dict(coverage,
population,
param_dict)
# Adjust cov_pop_dict so the values are now dicts where the keys are scenarios
# and the values are dfs customised to the scenarios
cov_pop_dict = adjust_cov_pop_for_trials(cov_pop_dict,
param_dict)
# Merge the burden and coverage / population dfs
cov_pop_burden_dict = merge_cov_pop_and_burden(burden_dict,
cov_pop_dict)
print('All the datasets have been simulated based on the parameters')
# Adjust the dfs in cov_pop_burden_dict for intervention factors such as the
# endemicity threshold, diagnostic inflation and intervention cut
cov_pop_burden_dict = adjust_for_intervention_factors(cov_pop_burden_dict,
param_dict)
# Clear any previous exception comments for projects that are being modelled
estimates_output = apply_exceptions.clear_exceptions(estimates_output, param_user)
# Apply various geographical exceptions see the updated
estimates_output, cov_pop_burden_dict = apply_exceptions.apply_geography_exceptions(cov_pop_burden_dict,
estimates_output)
# Calculate lives_touched and input them to
param_dict = calculate_ltli.update_lives_touched(cov_pop_burden_dict, param_dict)
param_dict = calculate_ltli.update_lives_improved(param_dict)
print('All the estimates have been completed')
# Separate param dict into seperate dicts for further analyis
param_dict_separated = reshape_for_graphs.separate_param_dict(param_dict, ANALYSIS_TYPE)
deterministic_dict = param_dict_separated['det']
probabilistic_dict = param_dict_separated['prob']
# Create base dicts for bridging diagram
base_cov_pop_burden_dict = {k: cov_pop_burden_dict[k]['base']
for k in cov_pop_burden_dict.keys()}
bridge_graph_dict = reshape_for_graphs.get_bridging_data(base_cov_pop_burden_dict,
burden_dict_unadjusted,
param_user_dict)
# Draws graphs and exports them to graphs_dir for all of the analyses
exports.draw_graphs_export(probabilistic_dict,
deterministic_dict,
bridge_graph_dict,
GRAPH_DIR)
# Turn the graphs into formatted slides
exports.create_all_slides(param_dict,
SLIDES_DIR,
DATA_DIR,
GRAPH_DIR,
PPT_TEMPLATE_NAME)
# Update param_user_all ready for export
estimates_output = exports.update_estimates_output(deterministic_dict,
probabilistic_dict,
estimates_output,
param_user,
param_user_all)
exports.export_estimates(estimates_output,
ANALYSIS_TYPE,
BACKUP_DIR,
OUTPUTS_DIR,
DATA_DIR,
ESTIMATES_CSV_NAME)
print('All the exports have been completed, the entire process is complete')