Skip to content

Commit

Permalink
update korona
Browse files Browse the repository at this point in the history
  • Loading branch information
zaplotnik committed Apr 6, 2020
1 parent b049451 commit ca7cdd4
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 44 deletions.
48 changes: 35 additions & 13 deletions code/korona_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,28 @@
status_hospitalized_severe[hosp_p_severe] = 1


# now remove people from home recovery
inc_home = np.where(home_recovery_period < 0.5)[0]
status_home[inc_home] = 0
status_active[inc_home] = 0

# now remove living/deceased from hospitals
inc_hosp_dead = np.where(hospitalization_period_dead < 0.5)[0]
status_hospitalized_dead[inc_hosp_dead] = 0
status_dead[inc_hosp_dead] = 1
status_active[inc_hosp_dead] = 0

inc_hosp_critical = np.where(hospitalization_period_critical < 0.5)[0]
status_hospitalized_critical[inc_hosp_critical] = 0
status_immune[inc_hosp_critical] = 1
status_active[inc_hosp_critical] = 0

inc_hosp_severe = np.where(hospitalization_period_severe < 0.5)[0]
status_hospitalized_severe[inc_hosp_severe] = 0
status_immune[inc_hosp_severe] = 1
status_active[inc_hosp_severe] = 0


Nactive = np.sum(status_active)
Nincubation = np.sum(status_incubation)
Ninfectious = np.sum(status_infectious)
Expand Down Expand Up @@ -642,11 +664,11 @@

# ukrepi 16. marca
if day == 4:
rands = rands/np.random.uniform(3.0,4.5) # /8.
rands = rands/np.random.uniform(3.5,4.5) # /8.

# ukrepi 18.marca
# ukrepi 20.marca
if day == 8:
rands = rands/np.random.uniform(1.2,3.) # /2.
rands = rands/np.random.uniform(1.5,3.) # /2.

random_sample = np.random.random(N)
rands_input = (rands - rands.astype(np.int32)>random_sample) + rands.astype(np.int32)
Expand All @@ -665,16 +687,16 @@
print ""
print "Saving fields"
# save fields
np.savetxt("./2020_03_29/tab_days_{:03d}.txt".format(run),tab_days,fmt='%8d')
np.savetxt("./2020_03_29/tab_active_{:03d}.txt".format(run),tab_active,fmt='%8d')
np.savetxt("./2020_03_29/tab_infectious_{:03d}.txt".format(run),tab_infectious,fmt='%8d')
np.savetxt("./2020_03_29/tab_incubation_{:03d}.txt".format(run),tab_incubation,fmt='%8d')
np.savetxt("./2020_03_29/tab_symptoms_{:03d}.txt".format(run),tab_symptoms,fmt='%8d')
np.savetxt("./2020_03_29/tab_hospitalized_{:03d}.txt".format(run),tab_hospitalized,fmt='%8d')
np.savetxt("./2020_03_29/tab_icu_{:03d}.txt".format(run), tab_icu,fmt='%8d')
np.savetxt("./2020_03_29/tab_dead_{:03d}.txt".format(run), tab_dead,fmt='%8d')
np.savetxt("./2020_03_29/tab_immune_{:03d}.txt".format(run), tab_immune,fmt='%8d')
np.savetxt("./2020_03_29/tab_susceptible_{:03d}.txt".format(run), tab_susceptible,fmt='%8d')
np.savetxt("./2020_04_03/tab_days_{:03d}.txt".format(run),tab_days,fmt='%8d')
np.savetxt("./2020_04_03/tab_active_{:03d}.txt".format(run),tab_active,fmt='%8d')
np.savetxt("./2020_04_03/tab_infectious_{:03d}.txt".format(run),tab_infectious,fmt='%8d')
np.savetxt("./2020_04_03/tab_incubation_{:03d}.txt".format(run),tab_incubation,fmt='%8d')
np.savetxt("./2020_04_03/tab_symptoms_{:03d}.txt".format(run),tab_symptoms,fmt='%8d')
np.savetxt("./2020_04_03/tab_hospitalized_{:03d}.txt".format(run),tab_hospitalized,fmt='%8d')
np.savetxt("./2020_04_03/tab_icu_{:03d}.txt".format(run), tab_icu,fmt='%8d')
np.savetxt("./2020_04_03/tab_dead_{:03d}.txt".format(run), tab_dead,fmt='%8d')
np.savetxt("./2020_04_03/tab_immune_{:03d}.txt".format(run), tab_immune,fmt='%8d')
np.savetxt("./2020_04_03/tab_susceptible_{:03d}.txt".format(run), tab_susceptible,fmt='%8d')

# np.savetxt("./save/day_infected_{:03d}.txt".format(run),day_infected)
# np.savetxt("./save/rands_input_{:03d}.txt".format(run),rands)
20 changes: 10 additions & 10 deletions code/korona_final_spike.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,16 @@
print ""
print "Saving fields"
# save fields
np.savetxt("./2020_03_29/tab_days_{:03d}.txt".format(run),tab_days,fmt='%8d')
np.savetxt("./2020_03_29/tab_active_{:03d}.txt".format(run),tab_active,fmt='%8d')
np.savetxt("./2020_03_29/tab_infectious_{:03d}.txt".format(run),tab_infectious,fmt='%8d')
np.savetxt("./2020_03_29/tab_incubation_{:03d}.txt".format(run),tab_incubation,fmt='%8d')
np.savetxt("./2020_03_29/tab_symptoms_{:03d}.txt".format(run),tab_symptoms,fmt='%8d')
np.savetxt("./2020_03_29/tab_hospitalized_{:03d}.txt".format(run),tab_hospitalized,fmt='%8d')
np.savetxt("./2020_03_29/tab_icu_{:03d}.txt".format(run), tab_icu,fmt='%8d')
np.savetxt("./2020_03_29/tab_dead_{:03d}.txt".format(run), tab_dead,fmt='%8d')
np.savetxt("./2020_03_29/tab_immune_{:03d}.txt".format(run), tab_immune,fmt='%8d')
np.savetxt("./2020_03_29/tab_susceptible_{:03d}.txt".format(run), tab_susceptible,fmt='%8d')
np.savetxt("./save_spike/tab_days_{:03d}.txt".format(run),tab_days,fmt='%8d')
np.savetxt("./save_spike/tab_active_{:03d}.txt".format(run),tab_active,fmt='%8d')
np.savetxt("./save_spike/tab_infectious_{:03d}.txt".format(run),tab_infectious,fmt='%8d')
np.savetxt("./save_spike/tab_incubation_{:03d}.txt".format(run),tab_incubation,fmt='%8d')
np.savetxt("./save_spike/tab_symptoms_{:03d}.txt".format(run),tab_symptoms,fmt='%8d')
np.savetxt("./save_spike/tab_hospitalized_{:03d}.txt".format(run),tab_hospitalized,fmt='%8d')
np.savetxt("./save_spike/tab_icu_{:03d}.txt".format(run), tab_icu,fmt='%8d')
np.savetxt("./save_spike/tab_dead_{:03d}.txt".format(run), tab_dead,fmt='%8d')
np.savetxt("./save_spike/tab_immune_{:03d}.txt".format(run), tab_immune,fmt='%8d')
np.savetxt("./save_spike/tab_susceptible_{:03d}.txt".format(run), tab_susceptible,fmt='%8d')

# np.savetxt("./save/day_infected_{:03d}.txt".format(run),day_infected)
# np.savetxt("./save/rands_input_{:03d}.txt".format(run),rands)
22 changes: 22 additions & 0 deletions code/korona_final_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@
status_hospitalized_severe[hosp_p_severe] = 1


# now remove people from home recovery
inc_home = np.where(home_recovery_period < 0.5)[0]
status_home[inc_home] = 0
status_active[inc_home] = 0

# now remove living/deceased from hospitals
inc_hosp_dead = np.where(hospitalization_period_dead < 0.5)[0]
status_hospitalized_dead[inc_hosp_dead] = 0
status_dead[inc_hosp_dead] = 1
status_active[inc_hosp_dead] = 0

inc_hosp_critical = np.where(hospitalization_period_critical < 0.5)[0]
status_hospitalized_critical[inc_hosp_critical] = 0
status_immune[inc_hosp_critical] = 1
status_active[inc_hosp_critical] = 0

inc_hosp_severe = np.where(hospitalization_period_severe < 0.5)[0]
status_hospitalized_severe[inc_hosp_severe] = 0
status_immune[inc_hosp_severe] = 1
status_active[inc_hosp_severe] = 0


Nactive = np.sum(status_active)
Nincubation = np.sum(status_incubation)
Ninfectious = np.sum(status_infectious)
Expand Down
61 changes: 46 additions & 15 deletions code/plot_data_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import datetime

run = 15
run = 17

save_data = False
#%% READ REAL DATA
Expand All @@ -26,10 +26,13 @@
data_icu = data_stats["state.icu"][17:]
data_cases = data_stats["tests.positive.todate"][17:]
data_dead = data_stats["state.deceased.todate"][17:]
#data_cases_new = data_stats["tests.positive"][17:]
data_days = np.arange(0,data_hospitalised.shape[0])
Ndata = len(data_dead)


#%% READ SIMULATED DATA
days = np.loadtxt("./2020_03_29/tab_days_4453.txt")
days = np.loadtxt("./2020_04_03/tab_days_002.txt")
Nt =days.shape[0]

N = 5000
Expand All @@ -43,27 +46,54 @@
immune = np.zeros((N,days.shape[0]))
susceptible = np.zeros((N,days.shape[0]))

inc_dead_data = data_dead.values>0
inc_icu_data = data_icu.values>0

blah = np.zeros((2,N))

j = 0
for i in range(N):
print(i)
if os.path.exists("./2020_03_29/tab_active_{:03d}.txt".format(i)):
if os.path.exists("./2020_04_03/tab_active_{:03d}.txt".format(i)):

active[j,:] = np.loadtxt("./2020_04_03/tab_active_{:03d}.txt".format(i))
infectious[j,:] = np.loadtxt("./2020_04_03/tab_infectious_{:03d}.txt".format(i))
incubation[j,:] = np.loadtxt("./2020_04_03/tab_incubation_{:03d}.txt".format(i))
symptoms[j,:] = np.loadtxt("./2020_04_03/tab_symptoms_{:03d}.txt".format(i))
hospitalized[j,:] = np.loadtxt("./2020_04_03/tab_hospitalized_{:03d}.txt".format(i))
icu[j,:] = np.loadtxt("./2020_04_03/tab_icu_{:03d}.txt".format(i))
dead[j,:] = np.loadtxt("./2020_04_03/tab_dead_{:03d}.txt".format(i))
immune[j,:] = np.loadtxt("./2020_04_03/tab_immune_{:03d}.txt".format(i))
susceptible[j,:] = np.loadtxt("./2020_04_03/tab_susceptible_{:03d}.txt".format(i))

active[j,:] = np.loadtxt("./2020_03_29/tab_active_{:03d}.txt".format(i))
infectious[j,:] = np.loadtxt("./2020_03_29/tab_infectious_{:03d}.txt".format(i))
incubation[j,:] = np.loadtxt("./2020_03_29/tab_incubation_{:03d}.txt".format(i))
symptoms[j,:] = np.loadtxt("./2020_03_29/tab_symptoms_{:03d}.txt".format(i))
hospitalized[j,:] = np.loadtxt("./2020_03_29/tab_hospitalized_{:03d}.txt".format(i))
icu[j,:] = np.loadtxt("./2020_03_29/tab_icu_{:03d}.txt".format(i))
dead[j,:] = np.loadtxt("./2020_03_29/tab_dead_{:03d}.txt".format(i))
immune[j,:] = np.loadtxt("./2020_03_29/tab_immune_{:03d}.txt".format(i))
susceptible[j,:] = np.loadtxt("./2020_03_29/tab_susceptible_{:03d}.txt".format(i))

dead_model = dead[j,:Ndata] > 0
icu_model = icu[j,:Ndata] > 0

inc_dead_all = inc_dead_data & dead_model
inc_icu_all = inc_icu_data & icu_model

#print dead[j,:Ndata][inc_dead_all]
#print (data_dead.values)[inc_dead_all]

#print icu[j,:Ndata][inc_icu_all]
#print (data_icu.values)[inc_icu_all]

sum1 = ((np.log((data_dead.values)[inc_dead_all]) - np.log(dead[j,:Ndata][inc_dead_all]))**2).sum()
sum2 = (((np.log(data_icu.values)[inc_icu_all]) - np.log(icu[j,:Ndata][inc_icu_all]))**2).sum()
#print sum1, sum2
#print ""
blah[0,j] = i
blah[1,j] = sum1 + sum2
j += 1
else:
continue
print(j)

print blah[1,:j]
print np.percentile(blah[1,:j],15)




#%% COMPUTE PARAMETERS
active_median = np.median(active[:j],axis=0)
Expand Down Expand Up @@ -200,8 +230,8 @@

# simulated values
# plt.fill_between(days,active_01,active_99,color="blue",alpha=0.1)
#plt.fill_between(days,active_05,active_95,color="blue",alpha=0.2)
#plt.plot(days,active_median,label="Active",color="blue",lw=3)
plt.fill_between(days,active_25,active_75,color="blue",alpha=0.2)
plt.plot(days,active_median,label="Active",color="blue",lw=3)

# plt.fill_between(days,symptoms_01,symptoms_99,color="green",alpha=0.1)
plt.fill_between(days,symptoms_25,symptoms_75,color="green",alpha=0.2)
Expand Down Expand Up @@ -246,6 +276,7 @@
plt.grid(b=True, which='major', color='grey', linestyle='-')
plt.grid(b=True, which='minor', color='grey', linestyle='--')
plt.ylim([1,10**5])
plt.xlim([-3,Nt+3])
plt.legend()
fig.savefig("potek_pandemije{:02d}.png".format(run),dpi=250)

Loading

0 comments on commit ca7cdd4

Please sign in to comment.