197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 | def write_graphs(
results: list[dict],
df: pd.DataFrame,
assets_dir: Path,
) -> list[dict[str, str]]:
"""Write PNG graphs to assets_dir. Returns list of {title, image} dicts."""
assets_dir.mkdir(parents=True, exist_ok=True)
sections: list[dict[str, str]] = []
graph_specs = [
(
"01_colony_expansion.png",
"Colony expansion",
lambda ax: _plot_lines(
ax, df,
[("area", "Area (mm²)", "#4f46e5"), ("diameter", "Diameter (mm)", "#059669")],
"Colony expansion over time", "Time (days)", "Size (mm² / mm)",
),
),
(
"02_growth_roughness.png",
"Relative growth and edge roughness",
lambda ax: _plot_lines(
ax, df,
[
("relative_growth_rate", "Relative growth rate (1/day)", "#ea580c"),
("edge_roughness", "Edge roughness", "#b45309"),
],
"Relative growth and edge roughness", "Time (days)", "Growth / roughness",
),
),
(
"03_crack_burden.png",
"Crack burden",
lambda ax: _plot_lines(
ax, df,
[
("crack_coverage", "Crack coverage (%)", "#f59e0b"),
("crack_count", "Crack count", "#7c2d12"),
],
"Crack burden over time", "Time (days)", "Coverage / count",
),
),
(
"04_texture.png",
"Texture organisation",
lambda ax: _plot_lines(
ax, df,
[
("entropy", "Texture entropy (bits)", "#0f766e"),
("center_edge_delta", "Center-to-edge intensity", "#14b8a6"),
],
"Texture organisation", "Time (days)", "Texture signal",
),
),
("05_area_circularity.png", "Area vs circularity", lambda ax: _plot_scatter(ax, df)),
("06_feature_correlation.png", "Feature correlation heatmap", lambda ax: _plot_heatmap(ax, df)),
]
for filename, title, renderer in graph_specs:
fig, ax = plt.subplots(figsize=(8.5, 4.5))
renderer(ax)
path = assets_dir / filename
_save_figure(fig, path)
sections.append({"title": title, "image": path.name})
# Area distribution
fig, ax = plt.subplots(figsize=(8.5, 4.5))
if not df.empty:
bins = min(8, max(3, len(df)))
ax.hist(df["area"], bins=bins, color="#6366f1", alpha=0.85, edgecolor="white")
ax.grid(alpha=0.2)
else:
ax.text(0.5, 0.5, "No data", ha="center", va="center")
ax.set_title("Area distribution")
ax.set_xlabel("Area (mm²)")
ax.set_ylabel("Image count")
path = assets_dir / "07_area_distribution.png"
_save_figure(fig, path)
sections.append({"title": "Area distribution", "image": path.name})
# Summary tables
_save_table_figure(
assets_dir / "08_table_morphology.png",
"Per-image morphology and QC",
df,
["filename", "day", "area", "diameter", "perimeter", "eccentricity", "qc_status"],
)
_save_table_figure(
assets_dir / "09_table_texture.png",
"Per-image texture metrics",
df,
["filename", "entropy", "center_edge_delta", "density_index"],
)
_save_table_figure(
assets_dir / "10_table_growth.png",
"Per-image crack and growth metrics",
df,
["filename", "crack_coverage", "relative_growth_rate", "area_growth_rate"],
)
return sections
|