-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_covid19.jl
350 lines (299 loc) · 15.4 KB
/
map_covid19.jl
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#module map_covid19
using Dates, DataFrames, ColorSchemes, PlotlyJS, FileIO
#import PlotlySave.savefig
#include("COVID19.jl")
#include("load_covid19_data.jl")
reasonable_resolution() = (1000, 800)
# time index
#for ti = 8:length(covid19us[1].confirmed)
#ti = 200
ti = length(covid19us[1].confirmed)
cconfirmed = [covid19us[i].confirmed[ti] for i in 1:length(covid19us)];
dcconfirmed = [mean(covid19us[i].confirmed[ti-7+1:ti] - covid19us[i].confirmed[ti-8+1:ti-1]) for i in 1:length(covid19us)];
dcconfirmedinst = [mean(covid19us[i].confirmed[ti] - covid19us[i].confirmed[ti-1]) for i in 1:length(covid19us)];
cdeath = [covid19us[i].death[ti] for i in 1:length(covid19us)];
dcdeath = [mean(covid19us[i].death[ti-7+1:ti] - covid19us[i].death[ti-8+1:ti-1]) for i in 1:length(covid19us)];
dcdeathinst = [mean(covid19us[i].death[ti] - covid19us[i].death[ti-1]) for i in 1:length(covid19us)];
# extracting county indices with land area and population
cind = findall((countyarea .> 0) .& (cpop .> 0));
tind = 1:length(covid19us[1].confirmed);
t = covid19us[1].time[tind];
# plot a map of confirmed cases
#cval = cconfirmed[cind] ./ (countyarea[cind] .* cpop[cind]);
cval = cconfirmed[cind] ./ cpop[cind];
log10cval = log10.(cval);
#sval = countyarea[cind] .* cpop[cind];
sval = cpop[cind];
log10sval = log10.(sval);
# daily confirmed cases per 100k averaged over 7 days
dCONFIRMEDpc = dcconfirmed[cind] ./ cpop[cind] .* 1e5;
bind = findall(dCONFIRMEDpc .<= 0);
dCONFIRMEDpc[bind] .= NaN;
# daily instant confirmed cases per 100k
dCONFIRMEDpcinst = dcconfirmedinst[cind] ./ cpop[cind] .* 1e5;
bind = findall(dCONFIRMEDpcinst .<= 0);
dCONFIRMEDpcinst[bind] .= NaN;
# daily death per 100k averaged over 7 days
dDEATHpc = dcdeath[cind] ./ cpop[cind] .* 1e5;
bind = findall(dDEATHpc .<= 0);
dDEATHpc[bind] .= NaN;
# daily instant death per 100k
dDEATHpcinst = dcdeathinst[cind] ./ cpop[cind] .* 1e5;
bind = findall(dDEATHpcinst .<= 0);
dDEATHpcinst[bind] .= NaN;
df = DataFrame(LON = clon[cind],
LAT = clat[cind],
POPULATION = cpop[cind],
log10POPULATION = log10.(cpop[cind]),
logPOPULATION = log.(cpop[cind]),
nrootPOPULATION = (cpop[cind]) .^ (1.0/2.85)/5,
CONFIRMEDpc = cconfirmed[cind] ./ cpop[cind] .* 1e5,
CONFIRMED = cconfirmed[cind],
log10CONFIRMEDpc = log10.(cconfirmed[cind] ./ cpop[cind] .* 1e5),
dCONFIRMEDpc = dCONFIRMEDpc,
dCONFIRMED = dcconfirmed[cind],
log10dCONFIRMEDpc = log10.(dCONFIRMEDpc),
dCONFIRMEDpcinst = dCONFIRMEDpcinst,
dCONFIRMEDinst = dcconfirmedinst[cind],
log10dCONFIRMEDpcinst = log10.(dCONFIRMEDpcinst),
DEATHpc = cdeath[cind] ./ cpop[cind] .* 1e5,
DEATH = cdeath[cind],
log10DEATHpc = log10.(cdeath[cind] ./ cpop[cind] .* 1e5),
dDEATHpc = dDEATHpc,
dDEATH = dcdeath[cind],
log10dDEATHpc = log10.(dDEATHpc),
dDEATHpcinst = dDEATHpcinst,
dDEATHinst = dcdeathinst[cind],
log10dDEATHpcinst = log10.(dDEATHpcinst),
);
function pmapconfirmed()
pmapsg = PlotlyJS.scattergeo(; locationmode="USA-states",
lat = df[!, :LAT],
lon = df[!, :LON],
marker_size=df[!, :nrootPOPULATION],
marker_color=df[!, :log10CONFIRMEDpc],
marker_colorscale="Jet",
marker_showscale = true,
marker_cmin = 3.5,
marker_cmax = 4.5,
hoverinfo="text",
hovertext=
"County: " .* county[cind] .* ", " .* state[cind] .* "<br>" .*
"Population: " .* string.(df[!, :POPULATION]) .* "<br>" .*
"Confirmed Cases (actual): " .* string.(df[!, :CONFIRMED]) .* "<br>" .*
"Confirmed Cases per 100k: " .* string.(round.(df[!, :CONFIRMEDpc], digits=2)) .* "<br>" .*
"Cumulative Deaths (actual): " .* string.(df[!, :DEATH]) .* "<br>" .*
"Cumulative Deaths per 100k: " .* string.(round.(df[!, :DEATHpc], digits=2)) .* "<br>" .*
"% infected with COVID19: " .* string.(round.(df[!, :CONFIRMED] ./ df[!, :POPULATION] .* 100, digits=2)) .* "<br>" .*
"% death rate: " .* string.(round.(df[!, :DEATH] ./ df[!, :CONFIRMED] .*100, digits=2))
);
geo = attr(scope="usa",
projection_type="ablbers usa",
showland=true,
landcolor="rgb(220, 220, 220)",
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255,255,255)",
countrycolor="rgb(255,255,255)",
);
title = attr(text = "Cumulative Confirmed Cases per 100k " * string(t[ti])[1:10] * " (log10) <br><sub><a href=\"https://truedichotomy.github.io/covid19_public/\">https://truedichotomy.github.io/covid19_public/</a></sub></br>", yref = "paper", y=1.0)
layout = Layout(; title=title, showlegend=false, geo=geo)
PlotlyJS.plot(pmapsg, layout)
end
function pmapdconfirmed()
pmapsg = PlotlyJS.scattergeo(; locationmode="USA-states",
lat = df[!, :LAT],
lon = df[!, :LON],
#marker_size=df[!, :logPOPULATION]/1.3,
marker_size=df[!, :nrootPOPULATION],
marker_color=df[!, :log10dCONFIRMEDpc],
marker_colorscale="Jet",
marker_showscale = true,
marker_cmin = -0.5,
marker_cmax = 2.7,
hoverinfo="text",
#hovertext=string.(df[!, :dCONFIRMED]) .* " " .* county[cind],
hovertext=
"County: " .* county[cind] .* ", " .* state[cind] .* "<br>" .*
"Population: " .* string.(df[!, :POPULATION]) .* "<br>" .*
"Confirmed Cases (actual): " .* string.(df[!, :CONFIRMED]) .* "<br>" .*
"Confirmed Cases per 100k: " .* string.(round.(df[!, :CONFIRMEDpc], digits=2)) .* "<br>" .*
"Daily New Cases (actual): " .* string.(round.(df[!, :dCONFIRMED], digits=2)) .* "<br>" .*
"Daily New Cases per 100k: " .* string.(round.(df[!, :dCONFIRMEDpc], digits=2)) .* "<br>" .*
"% infected with COVID19: " .* string.(round.(df[!, :CONFIRMED] ./ df[!, :POPULATION] .* 100, digits=2)) .* "<br>" .*
"% death rate: " .* string.(round.(df[!, :DEATH] ./ df[!, :CONFIRMED] .*100, digits=2))
);
geo = attr(scope="usa",
projection_type="ablbers usa",
showland=true,
landcolor="rgb(220, 220, 220)",
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255,255,255)",
countrycolor="rgb(255,255,255)",
);
title = attr(text = "Daily New Cases per 100k " * string(t[ti])[1:10] * " (log10, 7 day avg.) <br><sub><a href=\"https://truedichotomy.github.io/covid19_public/\">https://truedichotomy.github.io/covid19_public/</a></sub></br>", yref = "paper", y=1.0)
layout = Layout(; title=title, showlegend=false, geo=geo)
PlotlyJS.plot(pmapsg, layout)
end
function pmapdconfirmedinst()
pmapsg = PlotlyJS.scattergeo(; locationmode="USA-states",
lat = df[!, :LAT],
lon = df[!, :LON],
marker_size=df[!, :nrootPOPULATION],
#marker_size=df[!, :logPOPULATION]/1.3,
marker_color=df[!, :log10dCONFIRMEDpcinst],
marker_colorscale="Jet",
marker_showscale = true,
marker_cmin = -0.5,
marker_cmax = 2.5,
hoverinfo="text",
#hovertext=string.(df[!, :dCONFIRMED]) .* " " .* county[cind],
hovertext=
"County: " .* county[cind] .* ", " .* state[cind] .* "<br>" .*
"Population: " .* string.(df[!, :POPULATION]) .* "<br>" .*
"Confirmed Cases (actual): " .* string.(df[!, :CONFIRMED]) .* "<br>" .*
"Confirmed Cases per 100k: " .* string.(round.(df[!, :CONFIRMEDpc], digits=2)) .* "<br>" .*
"Daily New Cases (actual): " .* string.(df[!, :dCONFIRMEDinst]) .* "<br>" .*
"Daily New Cases per 100k: " .* string.(round.(df[!, :dCONFIRMEDpcinst], digits=2)) .* "<br>" .*
"% infected with COVID19: " .* string.(round.(df[!, :CONFIRMED] ./ df[!, :POPULATION] .* 100, digits=2)) .* "<br>" .*
"% death rate: " .* string.(round.(df[!, :DEATH] ./ df[!, :CONFIRMED] .*100, digits=2))
);
geo = attr(scope="usa",
projection_type="ablbers usa",
showland=true,
landcolor="rgb(220, 220, 220)",
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255,255,255)",
countrycolor="rgb(255,255,255)",
);
title = attr(text = "Daily New Cases per 100k " * string(t[ti])[1:10] * " (log10) <br><sub><a href=\"https://truedichotomy.github.io/covid19_public/\">https://truedichotomy.github.io/covid19_public/</a></sub></br>", yref = "paper", y=1.0)
layout = Layout(; title=title, showlegend=false, geo=geo)
PlotlyJS.plot(pmapsg, layout)
end
function pmapdeath()
pmapsg = PlotlyJS.scattergeo(; locationmode="USA-states",
lat = df[!, :LAT],
lon = df[!, :LON],
marker_size=df[!, :nrootPOPULATION],
#marker_size=df[!, :logPOPULATION]/1.3,
marker_color=df[!, :log10DEATHpc],
marker_colorscale="Jet",
marker_showscale = true,
marker_cmin = 0,
marker_cmax = 2.7,
hoverinfo="text",
#hovertext=string.(df[!, :DEATH]) .* " " .* county[cind],
hovertext=
"County: " .* county[cind] .* ", " .* state[cind] .* "<br>" .*
"Population: " .* string.(df[!, :POPULATION]) .* "<br>" .*
"Confirmed Cases (actual): " .* string.(df[!, :CONFIRMED]) .* "<br>" .*
"Confirmed Cases per 100k: " .* string.(round.(df[!, :CONFIRMEDpc], digits=2)) .* "<br>" .*
"Cumulative Deaths (actual): " .* string.(df[!, :DEATH]) .* "<br>" .*
"Cumulative Deaths per 100k: " .* string.(round.(df[!, :DEATHpc], digits=2)) .* "<br>" .*
"% infected with COVID19: " .* string.(round.(df[!, :CONFIRMED] ./ df[!, :POPULATION] .* 100, digits=2)) .* "<br>" .*
"% death rate: " .* string.(round.(df[!, :DEATH] ./ df[!, :CONFIRMED] .*100, digits=2))
);
geo = attr(scope="usa",
projection_type="ablbers usa",
showland=true,
landcolor="rgb(220, 220, 220)",
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255,255,255)",
countrycolor="rgb(255,255,255)",
);
title = attr(text = "Cumulative Death per 100k " * string(t[ti])[1:10] * " (log10) <br><sub><a href=\"https://truedichotomy.github.io/covid19_public/\">https://truedichotomy.github.io/covid19_public/</a></sub></br>", yref = "paper", y=1.0)
layout = Layout(; title=title, showlegend=false, geo=geo)
PlotlyJS.plot(pmapsg, layout)
end
function pmapddeath()
pmapsg = PlotlyJS.scattergeo(; locationmode="USA-states",
lat = df[!, :LAT],
lon = df[!, :LON],
#marker_size=df[!, :logPOPULATION]/1.3,
marker_size=df[!, :nrootPOPULATION],
marker_color=df[!, :log10dDEATHpc],
marker_colorscale="Jet",
marker_showscale = true,
marker_cmin = -1.5,
marker_cmax = 1,
hoverinfo="text",
#hovertext=string.(df[!, :dDEATH]) .* " " .* county[cind],
hovertext=
"County: " .* county[cind] .* ", " .* state[cind] .* "<br>" .*
"Population: " .* string.(df[!, :POPULATION]) .* "<br>" .*
"Total Deaths (actual): " .* string.(df[!, :DEATH]) .* "<br>" .*
"Total Deaths per 100k: " .* string.(round.(df[!, :DEATHpc], digits=2)) .* "<br>" .*
"Daily New Deaths (actual): " .* string.(round.(df[!, :dDEATH], digits=2)) .* "<br>" .*
"Daily New Deaths per 100k: " .* string.(round.(df[!, :dDEATHpc], digits=2)) .* "<br>" .*
"% infected with COVID19: " .* string.(round.(df[!, :CONFIRMED] ./ df[!, :POPULATION] .* 100, digits=2)) .* "<br>" .*
"% death rate: " .* string.(round.(df[!, :DEATH] ./ df[!, :CONFIRMED] .*100, digits=2))
);
geo = attr(scope="usa",
projection_type="ablbers usa",
showland=true,
landcolor="rgb(220, 220, 220)",
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255,255,255)",
countrycolor="rgb(255,255,255)",
);
title = attr(text = "Daily New Deaths per 100k " * string(t[ti])[1:10] * " (log10, 7 day avg.) <br><sub><a href=\"https://truedichotomy.github.io/covid19_public/\">https://truedichotomy.github.io/covid19_public/</a></sub></br>", yref = "paper", y=1.0)
layout = Layout(; title=title, showlegend=false, geo=geo)
PlotlyJS.plot(pmapsg, layout)
end
function pmapddeathinst()
pmapsg = PlotlyJS.scattergeo(; locationmode="USA-states",
lat = df[!, :LAT],
lon = df[!, :LON],
#marker_size=df[!, :logPOPULATION]/1.3,
marker_size=df[!, :nrootPOPULATION],
marker_color=df[!, :log10dDEATHpcinst],
marker_colorscale="Jet",
marker_showscale = true,
marker_cmin = -1.5,
marker_cmax = 1,
hoverinfo="text",
#hovertext=string.(df[!, :dDEATH]) .* " " .* county[cind],
hovertext=
"County: " .* county[cind] .* ", " .* state[cind] .* "<br>" .*
"Population: " .* string.(df[!, :POPULATION]) .* "<br>" .*
"Total Deaths (actual): " .* string.(df[!, :DEATH]) .* "<br>" .*
"Total Deaths per 100k: " .* string.(round.(df[!, :DEATHpc], digits=2)) .* "<br>" .*
"Daily New Deaths (actual): " .* string.(df[!, :dDEATHinst]) .* "<br>" .*
"Daily New Deaths per 100k: " .* string.(round.(df[!, :dDEATHpcinst], digits=2)) .* "<br>" .*
"% infected with COVID19: " .* string.(round.(df[!, :CONFIRMED] ./ df[!, :POPULATION] .* 100, digits=2)) .* "<br>" .*
"% death rate: " .* string.(round.(df[!, :DEATH] ./ df[!, :CONFIRMED] .*100, digits=2))
);
geo = attr(scope="usa",
projection_type="ablbers usa",
showland=true,
landcolor="rgb(220, 220, 220)",
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255,255,255)",
countrycolor="rgb(255,255,255)",
);
title = attr(text = "Daily New Deaths per 100k " * string(t[ti])[1:10] * " (log10) <br><sub><a href=\"https://truedichotomy.github.io/covid19_public/\">https://truedichotomy.github.io/covid19_public/</a></sub></br>", yref = "paper", y=1.0)
layout = Layout(; title=title, showlegend=false, geo=geo)
PlotlyJS.plot(pmapsg, layout)
end
#figoutdir = "/Volumes/GoogleDrive/My Drive/COVID19/";
figoutdir = "../covid19_public/maps/";
#PlotlyJS._js_path = "https://cdn.plot.ly/plotly-latest.min.js";
#save(pmapconfirmed(), figoutdir * "covid19map_confirmed.html", format="html");
PlotlyJS.savefig(pmapconfirmed(), figoutdir * "covid19map_confirmed.html", format="html");
PlotlyJS.savefig(pmapdconfirmed(), figoutdir * "covid19map_delta_confirmed_7days.html", format="html");
PlotlyJS.savefig(pmapdconfirmedinst(), figoutdir * "covid19map_delta_confirmed_latest.html", format="html");
PlotlyJS.savefig(pmapdeath(), figoutdir * "covid19map_death.html", format="html");
PlotlyJS.savefig(pmapddeath(), figoutdir * "covid19map_delta_death_7days.html", format="html");
PlotlyJS.savefig(pmapddeathinst(), figoutdir * "covid19map_delta_death_latest.html", format="html");
#PlotlyJS.savehtml(pmapconfirmed(), figoutdir * "covid19map_confirmed.html", :remote);
#PlotlyJS.savehtml(pmapdconfirmed(), figoutdir * "covid19map_delta_confirmed_7days.html", :remote);
#PlotlyJS.savehtml(pmapdconfirmedinst(), figoutdir * "covid19map_delta_confirmed_latest.html", :remote);
#PlotlyJS.savehtml(pmapdeath(), figoutdir * "covid19map_death.html", :remote);
#PlotlyJS.savehtml(pmapddeath(), figoutdir * "covid19map_delta_death_7days.html", :remote);
#PlotlyJS.savehtml(pmapddeathinst(), figoutdir * "covid19map_delta_death_latest.html", :remote);
#end