"""Results-first tables for the MACE paper: every traceable measured value is filled in; every other cell is marked. python -m mace10.paper writes /tables/t{1..4}_*.tex, /numbers_mace10.tex, mace10/out/table_cells.csv (cell -> status, n, source) and RESULTS_FIRST_DRAFT.md Cell status (rendered in the PDF): value measured on this protocol (source recorded per cell) NR NEEDS RUN (incremental calls and USD from the dry run listed in the caption and table_specs.yaml) NA NOT APPLICABLE pilot panel PILOT / DIFFERENT PROTOCOL (soybean, seed 0, runs 0-4, 5 images per disease and run); never merged into ten-crop rows Intervals: 95% bootstrap over unique query images, stratified by crop (2,000 resamples, seed 0); equal-crop means. """ from __future__ import annotations import json from pathlib import Path import numpy as np import pandas as pd HERE = Path(__file__).resolve().parent; OUT = HERE / "out"; LOCK = HERE / "locked" PAPER = HERE / "paper_src" # editable multi-file source; mace10/build_submission.py writes the single-file Overleaf paper PILOT = HERE.parent / "runs" NR = "\\nr{}"; NA = "\\na{}" cells: list[dict] = []; mac: dict[str, str] = {} RNG = np.random.default_rng(0); B = 2000 def cell(table, row, col, value=None, status="measured", n=None, source=""): cells.append({"table": table, "row": row, "col": col, "status": status, "value": value, "n": n, "source": source}) return value if status == "measured" else NR if status == "needs_run" else NA def eqcrop_ci(df, col): """Equal-crop mean accuracy (%) and stratified bootstrap 95% CI over unique images.""" groups = [g[col].to_numpy(float) for _, g in df.groupby("crop")] est = np.mean([g.mean() for g in groups]) * 100 bs = [np.mean([RNG.choice(g, len(g)).mean() for g in groups]) * 100 for _ in range(B)] return est, np.percentile(bs, 2.5), np.percentile(bs, 97.5) def fmt(e, lo=None, hi=None): return f"{e:.1f}" if lo is None else f"{e:.1f} {{\\tiny[{lo:.1f}, {hi:.1f}]}}" RES: dict = {} def minus(t): """True minus signs for negative numbers in generated text.""" import re return re.sub(r"(?