Skip to content

Commit 2155c05

Browse files
committed
rework time-series plotting; plot results for multiple diffusion constants
1 parent e22453c commit 2155c05

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

cr_bayesian_optim/fractal_dim.py

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,45 +123,73 @@ def produce_options():
123123
def fractal_dim_over_time():
124124
options = produce_options()
125125

126-
cells, _ = load_or_compute_full(options)
127-
128-
iterations = sorted(cells.keys())[::4]
129-
colony_diam = []
130-
dims_mean = []
131-
dims_std = []
132-
for i in tqdm(iterations, desc="Calculating dim(t)"):
133-
pos = np.array([c[0].mechanics.pos for c in cells[i].values()])
134-
135-
# Calculate Diameter of colony with convex hull
136-
hull = sp.spatial.ConvexHull(pos)
137-
hull_points = pos[hull.vertices]
138-
139-
diam = 0
140-
n_points = int(np.ceil(len(hull_points) / 2))
141-
for p in hull_points[:n_points]:
142-
d = np.linalg.norm(hull_points - p, axis=1)
143-
diam = max(diam, np.max(d))
144-
colony_diam.append(diam)
145-
146-
_, _, popt, pcov = calculate_fractal_dim_for_pos(pos, options, None)
147-
dims_mean.append(-popt[0])
148-
dims_std.append(pcov[0, 0] ** 0.5)
149-
150-
t = np.array(iterations) * options.time.dt / 60
151-
y1 = np.array(dims_mean)
152-
y1_err = np.array(dims_std)
153-
y2 = np.array(colony_diam) / 1000
126+
t = []
127+
y1 = []
128+
y1_err = []
129+
y2 = []
130+
131+
diffusion_constants = [80, 5, 0.5]
132+
for diffusion_constant in diffusion_constants:
133+
options.domain.diffusion_constant = diffusion_constant
134+
cells, _ = load_or_compute_full(options)
135+
136+
iterations = sorted(cells.keys())[::4]
137+
colony_diam = []
138+
dims_mean = []
139+
dims_std = []
140+
for i in tqdm(iterations, desc="Calculating dim(t)"):
141+
pos = np.array([c[0].mechanics.pos for c in cells[i].values()])
142+
143+
# Calculate Diameter of colony with convex hull
144+
hull = sp.spatial.ConvexHull(pos)
145+
hull_points = pos[hull.vertices]
146+
147+
diam = 0
148+
n_points = int(np.ceil(len(hull_points) / 2))
149+
for p in hull_points[:n_points]:
150+
d = np.linalg.norm(hull_points - p, axis=1)
151+
diam = max(diam, np.max(d))
152+
colony_diam.append(diam)
153+
154+
_, _, popt, pcov = calculate_fractal_dim_for_pos(pos, options, None)
155+
dims_mean.append(-popt[0])
156+
dims_std.append(pcov[0, 0] ** 0.5)
157+
158+
t.append(np.array(iterations) * options.time.dt / 60)
159+
y1.append(np.array(dims_mean))
160+
y1_err.append(np.array(dims_std))
161+
y2.append(np.array(colony_diam) / 1000)
154162

155163
fig, ax = plt.subplots(figsize=(8, 8))
156164

157165
# Introduce new y-axis for colony size
158166
ax2 = ax.twinx()
159167
ax2.set_ylabel("Diameter [mm]")
160-
ax2.plot(t, y2, label="Colony Size", linestyle="--", color=COLOR5)
168+
ax2.set_yscale("log")
169+
for i in range(len(t)):
170+
ax2.plot(
171+
t[i], y2[i], label="Colony Size", linestyle="--", color=COLOR5, linewidth=2
172+
)
161173

162174
# Plot Fractal Dimension
163-
ax.plot(t, y1, label="dim", color=COLOR1)
164-
ax.fill_between(t, y1 - y1_err, y1 + y1_err, color=COLOR3, alpha=0.3)
175+
for i in range(len(t)):
176+
ax.plot(t[i], y1[i], label="dim", color=COLOR1)
177+
ax.fill_between(
178+
t[i], y1[i] - y1_err[i], y1[i] + y1_err[i], color=COLOR3, alpha=0.3
179+
)
180+
ind = int(np.round(0.2 * len(t[i])))
181+
angle = (
182+
360
183+
/ (2 * np.pi)
184+
* np.atan(
185+
(y1[i][ind + 1] - y1[i][ind])
186+
/ (np.max(y1) - np.min(y1))
187+
/ (t[i][ind + 1] - t[i][ind])
188+
* (np.max(t) - np.min(t))
189+
)
190+
)
191+
y = y1[i][ind] + 0.1 * (np.max(y1[i]) - np.min(y1[i]))
192+
ax.text(t[i][ind], y, f"D={diffusion_constants[i]}", rotation=angle)
165193
ax.set_ylabel("Fractal Dimension")
166194
ax.set_xlabel("Time [min]")
167195

0 commit comments

Comments
 (0)