forked from InstituteforDiseaseModeling/covasim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_interventions_testing.py
246 lines (197 loc) · 8.13 KB
/
test_interventions_testing.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
'''
Testing the effect of testing interventions in Covasim
'''
#%% Imports and settings
import sciris as sc
import covasim as cv
do_plot = 1
do_show = 1
do_save = 0
debug = 1
keep_sims = 0
fig_paths = [f'results/testing_scen_{i}.png' for i in range(3)]
def test_interventions(do_plot=False, do_show=True, do_save=False, fig_path=None):
sc.heading('Test of testing interventions')
sc.heading('Setting up...')
sc.tic()
n_runs = 3
verbose = 1
base_pars = {
'pop_size': 1000,
'use_layers': True,
}
base_sim = cv.Sim(base_pars) # create sim object
n_people = base_sim['pop_size']
npts = base_sim.npts
# Define overall testing assumptions
# As the most optimistic case, we assume countries could get to South Korea's testing levels. S Korea has tested
# an average of 10000 people/day over March, or 270,000 in total. This is ~200 people per million every day (0.02%).
max_optimistic_testing = 0.0002
optimistic_daily_tests = [max_optimistic_testing*n_people]*npts # Very best-case scenario for asymptomatic testing
# Define the scenarios
scenarios = {
'baseline': {
'name':'Status quo, no testing',
'pars': {
'interventions': None,
}
},
'test_skorea': {
'name':'Assuming South Korea testing levels of 0.02% daily (untargeted); isolate positives',
'pars': {
'interventions': cv.test_num(daily_tests=optimistic_daily_tests)
}
},
'tracing': {
'name':'Assuming South Korea testing levels of 0.02% daily (with contact tracing); isolate positives',
'pars': {
'interventions': [cv.test_num(daily_tests=optimistic_daily_tests),
cv.dynamic_pars({'quar_trans_factor':{'days':20, 'vals':0.1}})] # This means that people who've been in contact with known positives isolate with 90% effectiveness
}
},
'floating': {
'name': 'Test with constant probability based on symptoms',
'pars': {
'interventions': cv.test_prob(symptomatic_prob=max_optimistic_testing, asymptomatic_prob=0.0)
}
},
'historical': {
'name': 'Test a known number of positive cases',
'pars': {
'interventions': cv.test_historical(n_tests=[100]*npts, n_positive = [1]*npts)
}
},
'sequence': {
'name': 'Historical switching to probability',
'pars': {
'interventions': cv.sequence(days=[10, 51], interventions=[
cv.test_historical(n_tests=[100] * npts, n_positive=[1] * npts),
cv.test_prob(symptomatic_prob=0.2, asymptomatic_prob=0.002),
])
}
},
}
metapars = {'n_runs': n_runs}
scens = cv.Scenarios(sim=base_sim, metapars=metapars, scenarios=scenarios)
scens.run(verbose=verbose, debug=debug)
if do_plot:
scens.plot(do_save=do_save, do_show=do_show, fig_path=fig_path)
return scens
def test_turnaround(do_plot=False, do_show=True, do_save=False, fig_path=None):
sc.heading('Test impact of reducing delay time for getting test results')
sc.heading('Setting up...')
sc.tic()
n_runs = 3
verbose = 1
base_pars = {
'pop_size': 5000,
'use_layers': True,
}
base_sim = cv.Sim(base_pars) # create sim object
n_people = base_sim['pop_size']
npts = base_sim.npts
# Define overall testing assumptions
testing_prop = 0.1 # Assumes we could test 10% of the population daily (!!)
daily_tests = [testing_prop*n_people]*npts # Number of daily tests
# Define the scenarios
scenarios = {
f'{d}dayturnaround': {
'name':f'Symptomatic testing with {d} days to get results',
'pars': {
'interventions': cv.test_num(daily_tests=daily_tests, test_delay=d)
}
} for d in range(1, 7+1, 2)
}
metapars = {'n_runs': n_runs}
scens = cv.Scenarios(sim=base_sim, metapars=metapars, scenarios=scenarios)
scens.run(verbose=verbose, debug=debug)
if do_plot:
scens.plot(do_save=do_save, do_show=do_show, fig_path=fig_path)
return scens
def test_tracedelay(do_plot=False, do_show=True, do_save=False, fig_path=None):
sc.heading('Test impact of reducing delay time for finding contacts of positives')
sc.heading('Setting up...')
sc.tic()
n_runs = 3
verbose = 1
base_pars = {
'pop_size': 5000,
'use_layers': True,
}
base_sim = cv.Sim(base_pars) # create sim object
base_sim['n_days'] = 50
base_sim['beta'] = 0.03 # Increase beta
n_people = base_sim['pop_size']
npts = base_sim.npts
# Define overall testing assumptions
testing_prop = 0.1 # Assumes we could test 10% of the population daily (way too optimistic!!)
daily_tests = [testing_prop*n_people]*npts # Number of daily tests
# Define the scenarios
scenarios = {
'lowtrace': {
'name': '10% daily testing; poor contact tracing; 7d quarantine; 50% acquision reduction',
'pars': {
'quar_trans_factor': {'h': 1, 's': 0.5, 'w': 0.5, 'c': 0.25},
'quar_acq_factor': 0.5,
'quar_period': 7,
'interventions': [cv.test_num(daily_tests=daily_tests),
cv.contact_tracing(trace_probs = {'h': 0, 's': 0, 'w': 0, 'c': 0},
trace_time = {'h': 1, 's': 7, 'w': 7, 'c': 7})]
}
},
'modtrace': {
'name': '10% daily testing; moderate contact tracing; 10d quarantine; 75% acquision reduction',
'pars': {
'quar_trans_factor': {'h': 1, 's': 0.25, 'w': 0.25, 'c': 0.1},
'quar_acq_factor': 0.75,
'quar_period': 10,
'interventions': [cv.test_num(daily_tests=daily_tests),
cv.contact_tracing(trace_probs = {'h': 1, 's': 0.8, 'w': 0.5, 'c': 0.1},
trace_time = {'h': 0, 's': 3, 'w': 3, 'c': 8})]
}
},
'hightrace': {
'name': '10% daily testing; fast contact tracing; 14d quarantine; 90% acquision reduction',
'pars': {
'quar_trans_factor': {'h': 0.5, 's': 0.1, 'w': 0.1, 'c': 0.1},
'quar_acq_factor': 0.9,
'quar_period': 14,
'interventions': [cv.test_num(daily_tests=daily_tests),
cv.contact_tracing(trace_probs = {'h': 1, 's': 0.8, 'w': 0.8, 'c': 0.2},
trace_time = {'h': 0, 's': 1, 'w': 1, 'c': 5})]
}
},
'alltrace': {
'name': '10% daily testing; same-day contact tracing; 21d quarantine; 100% acquision reduction',
'pars': {
'quar_trans_factor': {'h': 0.0, 's': 0.0, 'w': 0.0, 'c': 0.0},
'quar_acq_factor': 0,
'quar_period': 21,
'interventions': [cv.test_num(daily_tests=daily_tests),
cv.contact_tracing(trace_probs = {'h': 1, 's': 1, 'w': 1, 'c': 1},
trace_time = {'h': 0, 's': 1, 'w': 1, 'c': 2})]
}
},
}
metapars = {'n_runs': n_runs}
scens = cv.Scenarios(sim=base_sim, metapars=metapars, scenarios=scenarios)
scens.run(verbose=verbose, debug=debug)
if do_plot:
to_plot = [
'cum_infections',
'cum_recoveries',
'new_infections',
'n_quarantined',
'new_quarantined'
]
fig_args = dict(figsize=(24,16))
scens.plot(do_save=do_save, do_show=do_show, to_plot=to_plot, fig_path=fig_path, n_cols=2, fig_args=fig_args)
return scens
#%% Run as a script
if __name__ == '__main__':
sc.tic()
#scens1 = test_interventions(do_plot=do_plot, do_save=do_save, do_show=do_show, fig_path=fig_paths[0])
# scens2 = test_turnaround(do_plot=do_plot, do_save=do_save, do_show=do_show, fig_path=fig_paths[1])
scens3 = test_tracedelay(do_plot=do_plot, do_save=do_save, do_show=do_show, fig_path=fig_paths[2])
sc.toc()
print('Done.')