#!/usr/bin/env python3 """Read bar heights off the charts of Mannino, Caldo and Maffei (2026), J. Plant Physiol. 326, 154872, by pixels. We don't host the paper's PDF or its images: run this on your own copy of the PDF (CC BY 4.0, from the publisher). The script checks the PDF's SHA-256 against the copy we used, takes the two embedded chart images out of it (Fig. 3, 1895 x 1003 pixels, and Fig. 5, 1659 x 2110), finds each panel's y-axis and tick marks, and reads each blue (control, GMF) and orange (coil, hMF) bar's top and error-bar cap. The two lowest ticks give the scale. Readings are good to a few pixels; an error bar the scan can't find is reported as 0. Colours follow the figure's legend. Nothing in the PDF is executed. Needs Pillow. Run: python3 -I read_bars.py """ import hashlib import io import json import re import sys from PIL import Image OUR_PDF_SHA256 = "dd247d6a28e40176271cf02711b1cfeabfc1edc47955d4a0113206129f295507" FIGURES = {"Fig. 3": (1895, 1003), "Fig. 5": (1659, 2110)} # panel: figure, crop box (x0, y0, x1, y1) in image pixels, values of the lowest and highest ticks, bar labels in order PANELS = [ ("Fig. 3A total protein, mg BSAE per g dry weight", "Fig. 3", (60, 20, 480, 380), 0, 120, ["protein"]), ("Fig. 3B total phenolics, mg GAE per g dry weight", "Fig. 3", (520, 20, 940, 380), 0, 300, ["phenolics"]), ("Fig. 3C total flavonoids, per g dry weight", "Fig. 3", (990, 20, 1420, 380), 0, 140, ["flavonoids"]), ("Fig. 3D H2O2, per g dry weight", "Fig. 3", (1460, 20, 1895, 380), 0, 2.0, ["H2O2"]), ("Fig. 5F effective quantum yield of PSII", "Fig. 5", (975, 1040, 1659, 1400), 0, 1.0, ["QY max", "1000", "500", "300", "100", "50", "20", "10"]), ("Fig. 5H non-photochemical quenching", "Fig. 5", (880, 1560, 1659, 2000), 0, 1.2, ["L1", "L2", "L3", "L4", "Lss", "D1", "D2", "D3"]), ] def images(pdf): """Embedded JPEG images, by size.""" found = {} for m in re.finditer(rb"/Subtype\s*/Image", pdf): start = pdf.rfind(b"obj", 0, m.start()) s = pdf.find(b"stream", m.start()) head = pdf[start:s] if b"/DCTDecode" not in head: continue j = s + 6 j += 2 if pdf[j:j + 2] == b"\r\n" else 1 e = pdf.find(b"endstream", j) try: im = Image.open(io.BytesIO(pdf[j:e])).convert("RGB") except Exception: continue found.setdefault(im.size, im) return found def dark(p): return sum(p) < 200 def blue(p): r, g, b = p return b > 90 and r < 80 and g < 130 and b - r > 50 def orange(p): r, g, b = p return r > 190 and 80 < g < 160 and b < 110 def read_panel(im, box, v_low, v_high, labels): px = im.load() x0, y0, x1, y1 = box best = (0, None) for x in range(x0, x0 + (x1 - x0) // 3): run = longest = 0 for y in range(y0, y1): run = run + 1 if dark(px[x, y]) else 0 longest = max(longest, run) if longest > best[0]: best = (longest, x) ax = best[1] ticks = [] for y in range(y0, y1): if all(dark(px[ax - k, y]) for k in (3, 5, 7)) or all(dark(px[ax + k, y]) for k in (3, 5, 7)): if ticks and y - ticks[-1][-1] <= 1: ticks[-1].append(y) else: ticks.append([y]) rows = [sum(t) / len(t) for t in ticks] y_low, y_high = rows[-1], rows[0] def value(y): return v_low + (y_low - y) * (v_high - v_low) / (y_low - y_high) row = int(y_low) - 6 bars, x = [], ax + 3 while x < x1: kind = "GMF" if blue(px[x, row]) else "hMF" if orange(px[x, row]) else None if kind: test = blue if kind == "GMF" else orange a = x while x < x1 and test(px[x, row]): x += 1 if x - a >= 6: bars.append((kind, a, x - 1)) x += 1 out = [] for kind, a, b in bars: test = blue if kind == "GMF" else orange cx = (a + b) // 2 y = row while y > y0 and test(px[cx, y]): y -= 1 top = y + 1 yy, cap, gap = top - 1, top, 0 while yy > y0 and gap <= 2: if any(dark(px[cx + k, yy]) for k in range(-3, 4)): cap, gap = yy, 0 else: gap += 1 yy -= 1 out.append({"group": kind, "x": [a, b], "top_px": top, "value": round(value(top), 4), "cap_px": cap, "sd": round(value(cap) - value(top), 4)}) pairs = [] for i, lab in enumerate(labels): g = [o for o in out[2 * i:2 * i + 2]] if len(g) == 2 and g[0]["group"] == "GMF" and g[1]["group"] == "hMF": change = (g[1]["value"] - g[0]["value"]) / g[0]["value"] * 100 if g[0]["value"] else None pairs.append({"label": lab, "GMF": g[0]["value"], "hMF": g[1]["value"], "change_percent": round(change, 1) if change is not None else None}) return {"axis_x": ax, "tick_rows": [round(r, 1) for r in rows], "bars": out, "pairs": pairs} def main(): pdf = open(sys.argv[1], "rb").read() sha = hashlib.sha256(pdf).hexdigest() res = {"pdf_sha256": sha, "same_as_our_copy": sha == OUR_PDF_SHA256, "panels": {}} if sha != OUR_PDF_SHA256: print("Note: this PDF differs from the copy we used; readings may differ.", file=sys.stderr) found = images(pdf) for title, fig, box, lo, hi, labels in PANELS: im = found.get(FIGURES[fig]) if im is None: res["panels"][title] = "image not found" continue res["panels"][title] = read_panel(im, box, lo, hi, labels) text = json.dumps(res, indent=1) + "\n" with open(sys.argv[2], "w", encoding="utf-8", newline="\n") as fh: fh.write(text) sys.stdout.reconfigure(encoding="utf-8") for title, p in res["panels"].items(): print(title, [(q["label"], q["GMF"], q["hMF"], q["change_percent"]) for q in p["pairs"]] if isinstance(p, dict) else p) if __name__ == "__main__": main()