-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathca-hostpathogen.py
59 lines (47 loc) · 1.53 KB
/
ca-hostpathogen.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
import pycxsimulator
from pylab import *
width = 50
height = 50
initProb = 0.01
infectionRate = 0.85
regrowthRate = 0.15
def initialize():
global time, config, nextConfig
time = 0
config = zeros([height, width])
for x in range(width):
for y in range(height):
if random() < initProb:
state = 2
else:
state = 1
config[y, x] = state
nextConfig = zeros([height, width])
def observe():
cla()
imshow(config, vmin = 0, vmax = 2, cmap = cm.jet)
axis('image')
title('t = ' + str(time))
def update():
global time, config, nextConfig
time += 1
for x in range(width):
for y in range(height):
state = config[y, x]
if state == 0:
for dx in range(-1, 2):
for dy in range(-1, 2):
if config[(y+dy)%height, (x+dx)%width] == 1:
if random() < regrowthRate:
state = 1
elif state == 1:
for dx in range(-1, 2):
for dy in range(-1, 2):
if config[(y+dy)%height, (x+dx)%width] == 2:
if random() < infectionRate:
state = 2
else:
state = 0
nextConfig[y, x] = state
config, nextConfig = nextConfig, config
pycxsimulator.GUI().start(func=[initialize, observe, update])