Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # Mini 2 Mand D
  2. import numpy as np
  3. from epidemics import *
  4. import matplotlib.patches as mpatches
  5. import matplotlib.pyplot as plt
  6. from matplotlib import cm
  7.  
  8. # Settings
  9. T = 500 #number of weeks
  10. alpha = 0.30    # high alpha value: easy to infect
  11. beta = 0.05 # high beta-value: easy recovering
  12.  
  13. # Initialize the grid
  14. grid = np.loadtxt('worldmap.dat', dtype=int, delimiter=',')
  15. grid[30:35, 265:270] = INFECTED # Start in Asia
  16. grid[30:35, 50:55] = INFECTED # Start in Northa America
  17.  
  18. grids = []
  19. grids.append(grid)
  20. S = [np.sum(grid == SUSCEPTIBLE)]              
  21. I = [np.sum(grid == INFECTED)]                  
  22. R = [np.sum(grid == RECOVERED)]
  23.  
  24. # Run the simulation
  25. for n in range(T):
  26.     grid = time_step(grid, alpha, beta)
  27.     grids.append(grid)
  28.     S.append(np.sum(grid == SUSCEPTIBLE))
  29.     I.append(np.sum(grid == INFECTED))
  30.     R.append(np.sum(grid == RECOVERED))
  31.  
  32. # Plot the results
  33. [plot2D_SIR(grids[t], f'Week {t}') for t in np.arange(0,T+1,T//5)]
  34.  
  35. #plot evolution
  36. fig, ax = plt.subplots()
  37. people = [S, I, R]
  38. lab = ['Susceptible', 'Infectious', 'Recovered']
  39. col = ['indianred', 'darkslategrey', 'darkorange']
  40. for i in range(len(people)):
  41.     ax.plot(range(T+1), people[i], color=col[i], label=lab[i])
  42. ax.legend()
  43. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement