-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvisualize_feature_per_testing.py
139 lines (114 loc) · 3.88 KB
/
visualize_feature_per_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
# Santiago Nunez-Corrales and Eric Jakobsson
# Illinois Informatics and Molecular and Cell Biology
# University of Illinois at Urbana-Champaign
# {nunezco,jake}@illinois.edu
# A simple tunable model for COVID-19 response
import matplotlib.pyplot as plt
import scipy.stats as sps
import seaborn as sns
import pandas as pd
import numpy as np
from scipy.ndimage import gaussian_filter1d
from covidmodel import CovidModel
import sys
feature = sys.argv[1]
start = float(sys.argv[2])
top = float(sys.argv[3])
bottom = float(sys.argv[4])
in_file = {}
in_file["25"] = sys.argv[5]
in_file["50"] = sys.argv[6]
in_file["75"] = sys.argv[7]
in_file["cf"] = sys.argv[8]
out_file = sys.argv[9]
cases = ["25", "50", "75", "cf"]
plt.figure(figsize = (11.7, 8.27))
plt.ticklabel_format(style='plain', axis='y')
df0 = {}
for scn in cases:
df0[scn] = pd.read_csv(in_file[scn])
df0[scn]["Step"] = df0[scn]["Step"]/96
df = {}
# Used when there is
df_temp = {}
xmaxl = {}
for scn in cases:
df[scn] = pd.DataFrame()
if feature == "Rt":
for iteration in df0[scn]["Iteration"].unique():
df_temp[scn] = pd.DataFrame()
df_temp[scn]["Step"] = (df0[scn]["Step"].unique())
df_temp[scn]["Rt"] = gaussian_filter1d(df0[scn]["Rt"][df0[scn]["Iteration"] == iteration], 96)
df[scn] = df[scn].append(df_temp[scn])
else:
df[scn]["Step"] = df0[scn]["Step"]
df[scn][feature] = df0[scn][feature]
xmaxl[scn] = df[scn]["Step"].max()
#xmin = min(list(xminl.values()))
xmin = start
xmax = max(list(xmaxl.values()))
ymin = bottom
ymax = top
avg = {}
low_ci_95 = {}
high_ci_95 = {}
low_ci_99 = {}
high_ci_99 = {}
df_stats = {}
for scn in cases:
print(f"Processing case {scn}")
avg[scn] = []
low_ci_95[scn] = []
high_ci_95[scn] = []
low_ci_99[scn] = []
high_ci_99[scn] = []
for step in df[scn]["Step"].unique():
values = df[scn][feature][df[scn]["Step"] == step]
f_mean = values.mean()
lci95, hci95 = sps.t.interval(0.95, len(values), loc=f_mean, scale=sps.sem(values))
lci99, hci99 = sps.t.interval(0.99, len(values), loc=f_mean, scale=sps.sem(values))
avg[scn].append(f_mean)
low_ci_95[scn].append(lci95)
high_ci_95[scn].append(hci95)
low_ci_99[scn].append(lci99)
high_ci_99[scn].append(hci99)
df_stats[scn] = pd.DataFrame()
df_stats[scn]["Step"] = df[scn]["Step"].unique()
df_stats[scn]["mean"] = avg[scn]
df_stats[scn]["lci95"] = low_ci_95[scn]
df_stats[scn]["hci95"] = high_ci_95[scn]
df_stats[scn]["lci99"] = low_ci_99[scn]
df_stats[scn]["hci99"] = high_ci_99[scn]
colpertyp = {}
colpertyp["25"] = "darkred"
colpertyp["50"] = "teal"
colpertyp["75"] = "darkblue"
colpertyp["cf"] = "purple"
labpertyp = {}
labpertyp["25"] = "25%"
labpertyp["50"] = "50%"
labpertyp["75"] = "75%"
labpertyp["cf"] = "CF"
for scn in cases:
plt.plot(df_stats[scn]["Step"], df_stats[scn]["mean"], color=colpertyp[scn], linewidth=1, label=labpertyp[scn])
plt.fill_between(df_stats[scn]["Step"], df_stats[scn]["lci95"], df_stats[scn]["hci95"], color=colpertyp[scn], alpha=.1)
plt.vlines(116, 0, ymax, colors='gray', linestyle=":")
plt.vlines(130, 0, ymax, colors='gray', linestyle="-.")
plt.vlines(136, 0, ymax, colors='gray', linestyle="--")
plt.xlim([xmin, xmax])
plt.ylim([ymin, ymax])
plt.xlabel("Days since April 15, 2020", fontsize=18)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.legend(fontsize=16, title="Scenario", title_fontsize=18)
if (feature == "SymptQuarantined") or (feature == "Asymptomatic") or (feature == "Severe"):
plt.ylabel("Population Fraction", fontsize=18)
elif feature == "CumulPublValue":
plt.ylabel("Public Value", fontsize=18)
elif feature == "CumulPrivValue":
plt.ylabel("Private Value", fontsize=18)
elif feature == "Rt":
plt.ylabel("$R(T)$", fontsize=18)
else:
plt.ylabel("variable", fontsize=18)
plt.savefig(out_file, dpi=300)