Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat March 21 2020
@author: nolte
"""
import numpy as np
from scipy import integrate
from matplotlib import pyplot as plt
plt.close('all')
print(' ')
print('SIR.py')
def solve_flow(param,max_time=1000.0):
def flow_deriv(x_y,tspan,mu,betap):
x, y = x_y
return [-mu*x + betap*x*y,-betap*x*y]
x0 = [del1, del2]
# Solve for the trajectories
t = np.linspace(0, int(tlim), int(250*tlim))
x_t = integrate.odeint(flow_deriv, x0, t, param)
return t, x_t
r = 0.0002 # 0.00015
k = 50 # connections 50
dill = 14 # days ill
dpq = 14 # days shelter in place
fnq = 0.6 # fraction NOT sheltering in place
mr0 = 0.01 # mortality rate
mr1 = 0.03 # extra mortality rate if exceeding hospital capacity
P = 330 # population of US in Millions
HC = 0.003 # hospital capacity
dinf = fnq*dill + (1-fnq)*np.exp(-dpq/dill)*dill;
betap = r*k*dinf;
mu = 1/dill;
print('beta = ',betap)
print('dinf = ',dinf)
print('betap/mu = ',betap/mu)
del1 = .001 # infected
del2 = 1-del1 # susceptible
tlim = np.log(P*1e6/del1)/betap + 50/betap
param = (mu, betap) # flow parameters
t, y = solve_flow(param)
I = y[:,0]
S = y[:,1]
R = 1 - I - S
plt.figure(1)
lines = plt.semilogy(t,I,t,S,t,R)
plt.ylim([0.001,1])
plt.xlim([0,tlim])
plt.legend(('Infected','Susceptible','Removed'))
plt.setp(lines, linewidth=0.5)
plt.xlabel('Days')
plt.ylabel('Fraction of Population')
plt.title('Population Dynamics for COVID-19 in US')
plt.show()
mr = mr0 + mr1*(0.2*np.max(I)-HC)*np.heaviside(0.2*np.max(I),HC)
Dead = mr*P*R[R.size-1]
print('Dead = ',Dead)
D = np.zeros(shape=(100,))
x = np.zeros(shape=(100,))
for kloop in range(0,5):
for floop in range(0,100):
fnq = floop/100
dinf = fnq*dill + (1-fnq)*np.exp(-dpq/dill)*dill;
k = 20 + kloop*10
betap = r*k*dinf
tlim = np.log(P*1e6/del1)/betap + 50/betap
param = (mu, betap) # flow parameters
t, y = solve_flow(param)
I = y[:,0]
S = y[:,1]
R = 1 - I - S
mr = mr0 + mr1*(0.2*np.max(I)-HC)*np.heaviside(0.2*np.max(I),HC)
D[floop] = mr*P*R[R.size-1]
x[floop] = fnq
plt.figure(2)
lines2 = plt.plot(x,D)
plt.setp(lines2, linewidth=0.5)
plt.ylabel('US Million Deaths')
plt.xlabel('Fraction NOT Quarantining')
plt.title('Quarantine and Distancing')
plt.legend(('20','30','40','50','60','70'))
plt.show()
label = np.zeros(shape=(9,))
for floop in range(0,8):
fq = floop/10.0
dinf = (1-fq)*dill + fq*np.exp(-dpq/dill)*dill;
k = 50
betap = r*k*dinf
tlim = np.log(P*1e6/del1)/betap + 50/betap
param = (mu, betap) # flow parameters
t, y = solve_flow(param)
I = y[:,0]
S = y[:,1]
R = 1 - I - S
plt.figure(3)
lines2 = plt.plot(t,I*P)
plt.setp(lines2, linewidth=0.5)
label[floop]=fq
plt.legend(label)
plt.ylabel('US Millions Infected')
plt.xlabel('Days')
plt.title('Flattening the Curve')