-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_covid19_data.jl
76 lines (64 loc) · 3.03 KB
/
load_covid19_data.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
#using Pkg
#Pkg.activate(ENV["HOME"] * "/.julia/environments/" * "covid19")
if Sys.iswindows() == false
covid19dir = ENV["HOME"] * "/GitHub/covid19"
else
covid19dir = ENV["HOMEDRIVE"] * ENV["HOMEPATH"] * "\\GitHub\\covid19"
end
if (covid19dir in LOAD_PATH) == false
push!(LOAD_PATH, pwd());
end
#Pkg.update()
#ENV["PYTHON"] = ENV["CONDA_PYTHON_EXE"]
#]add CSV HTTP GitHub DataFrames PyCall PyPlot Plots Dates Statistics TimeSeries MLJ XGBoost Measurements LsqFit NCDatasets Glob JSON3 Tables Pandas FileIO CSVFiles Missings JLD2 OnlineStats CUDAnative CuArrays
#Pkg.build("PyCall")
using Dates, Statistics, Shapefile, DataFrames, Glob
## Load CENSUS TIGER/Line Shapefile Data
function load_county_data(countyshppath = "./tl_2019_us_county.shp")
#countyshpdownloadurl = "https://liviandonglai.box.com/s/pv1zdejyy0ntsjikeiljqlfmoxiz8gba"
#countyshpboxlocation = "/Users/gong/Box/Data/CENSUS/tl_2019_us_county/tl_2019_us_county.shp"
return countytable = Shapefile.Table(countyshppath);
end
## Load COVID-19 Data
#import COVID19
(covid19g, covid19us, covid19nyt_state, covid19nyt_county) = COVID19.load_data("./");
country = [covid19us[i].country for i in 1:length(covid19us)];
fips = [covid19us[i].fips for i in 1:length(covid19us)];
county = [covid19us[i].county for i in 1:length(covid19us)];
state = [covid19us[i].province_state for i in 1:length(covid19us)];
clat = [covid19us[i].lat for i in 1:length(covid19us)];
clon = [covid19us[i].lon for i in 1:length(covid19us)];
cpop = [covid19us[i].population for i in 1:length(covid19us)];
cconfirmed = [covid19us[i].confirmed[end] for i in 1:length(covid19us)];
dcconfirmed = [mean(covid19us[i].confirmed[end-7:end] - covid19us[i].confirmed[end-8:end-1]) for i in 1:length(covid19us)];
dcconfirmedinst = [mean(covid19us[i].confirmed[end] - covid19us[i].confirmed[end-1]) for i in 1:length(covid19us)];
cdeath = [covid19us[i].death[end] for i in 1:length(covid19us)];
dcdeath = [mean(covid19us[i].death[end-7:end] - covid19us[i].death[end-8:end-1]) for i in 1:length(covid19us)];
dcdeathinst = [mean(covid19us[i].death[end] - covid19us[i].death[end-1]) for i in 1:length(covid19us)];
ustate = unique(state);
mfips = deepcopy(fips);
strfips = string.(fips);
terrind = findall(0 .<= mfips .< 100);
mfips[terrind] = mfips[terrind] .* 1000;
gind = findall(mfips .>= 0);
mfips[gind] = mfips[gind] .+ 100000;
strfips = [string(mfips[i])[2:end] for i in 1:length(mfips)];
statefips = [strfips[i][1:2] for i in 1:length(strfips)];
countytable = load_county_data();
ctcensusfips = countytable.STATEFP .* countytable.COUNTYFP;
ctaland = countytable.ALAND;
ctawater = countytable.AWATER;
ctname = countytable.NAME;
countyarea = Array{Float64}(undef,(length(strfips)));
countyarea .= NaN;
for i = 1:length(strfips)
if parse(Int,strfips[i][1:2]) <= 59
local fipsind = findall(strfips[i] .== ctcensusfips);
if isempty(fipsind) == false
countyarea[i] = ctaland[fipsind[1]];
end
end
end
## Calculating Cases per population/area
#strfips[1:end-110] .* state[1:end-110]
#sort(censusfips)[1:end-90]