forked from luca-rosa/rd-model
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmulti_plate.py
85 lines (64 loc) · 2.85 KB
/
multi_plate.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
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
from scipy.integrate import solve_ivp
class Multiplate:
def __init__(self, size):
self.size = size
self.plates = []
def get_size(self):
return self.size
def get_num_plates(self):
return len(self.plates)
def get_all_plates(self):
return self.plates
def add_plate(self, new_plate):
self.plates.append(new_plate)
def set_plates(self, plates):
self.plates = plates
def model(self, t, y, params):
U = y.reshape(self.get_all_species_U().shape)
dU = np.zeros(U.shape)
species_dict = {}
behaviour_dict = {}
for idx, s in enumerate(self.species):
species_dict[s.get_name()] = U[idx]
behaviour_dict[s.get_name()] = s.behaviour
for idx, s in enumerate(self.species):
dU[idx] = behaviour_dict[s.get_name()](species_dict, params)
return dU.flatten()
def run_plates(self, t_final, dt, params):
t = np.arange(0, t_final, dt)
U_init = self.get_all_species_U().flatten()
sim_ivp = solve_ivp(self.model, [0, t_final], U_init,
t_eval=t, args=(params,))
sim_ivp = sim_ivp.y.reshape(self.get_num_species(),
self.size[0], self.size[1],
int(t_final / dt))
return sim_ivp
def plot_simulation(self, sim, timepoints):
for tp in timepoints:
fig, axs = plt.subplots(int(np.ceil(len(self.species) / 3)), 3, sharex='all', sharey='all')
for idx, (ax, s) in enumerate(zip(axs.flatten(), self.species)):
# for idx, s in enumerate(self.species):
im = ax.imshow(sim[idx, :, :, tp*600], interpolation="none",
cmap=cm.viridis, vmin=0,
vmax=np.max(sim[idx, :, :, :]))
ax.set_title(s.get_name() + ' hour: ' + str(tp))
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
fig.colorbar(im, cax=cax, shrink=0.8)
fig.savefig('fig_hour_' + str(tp) +'.pdf')
fig.show()
def plot_plate(self):
print("plotting plate")
fig, axs = plt.subplots(int(np.ceil(len(self.species) / 3)), 3, sharex='all', sharey='all')
for idx, s in enumerate(self.species):
im = axs[idx].imshow(s.get_U(), interpolation="none", cmap=cm.viridis, vmin=0)
axs[idx].set_title(s.get_name())
divider = make_axes_locatable(axs[idx])
cax = divider.append_axes("right", size="5%", pad=0.05)
fig.colorbar(im, cax=cax, shrink=0.8)
fig.savefig('fig.pdf')
fig.show()