import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/l90';rows=json.loads((O/'results.json').read_text())['records'];nref=sum(x['references'] for x in rows);methods=('original','defer_padding','valid_first');table=[]
for stream in ('uniform','variance'):
 for t in ('0.5','0.75'):
  for n in ('10','30','60','all'):
   vals=[sum(x['methods'][stream]['scores'][k][n][t]['matched'] for x in rows) for k in methods];table.append(f'<tr><td>{stream}</td><td>{t}</td><td>{n}</td>'+''.join(f'<td>{v}/{nref}</td>' for v in vals)+'</tr>')
cards=[]
for r in rows:
 for stream in ('uniform','variance'):
  x=r['methods'][stream];vals=[x['scores'][k]['10']['0.5']['matched'] for k in methods];counts=[x['stats'][k]['10']['padding_points'] for k in methods];cards.append(f'<section><h2>Field {r["index"]:02d}: {stream}</h2><p>Top-10 matches original / deferred / valid-first: {" / ".join(map(str,vals))} of {r["references"]}; prompt-in-padding masks shown: {" / ".join(map(str,counts))}. These are pre-existing masks; padding-touching masks with in-image prompts are not automatically discarded.</p><a href="{x["panel"]}"><img loading="lazy" src="{x["panel"]}" alt="Source polygons and three candidate ranking overlays"></a><p><a href="/{html.escape(r["source"])}">Original public RGB</a> · <a href="/results/r105/{r["archive"]}">All original model outputs</a></p></section>')
(O/'index.html').write_text('''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>L90 padding-aware rankings</title><style>body{font:16px/1.5 system-ui;color:#18342f;max-width:1200px;margin:2em auto;padding:0 1em}a{color:#006b59}img{width:100%}table{border-collapse:collapse}td,th{border:1px solid #bbc;padding:.4em}.warn{background:#fff2d6;padding:1em}section{border-top:1px solid #ccd}</style><a href="/results/board.html">Research board</a> · <a href="/results/r105/">Underlying real-field replay</a><h1>L90: What if padding prompts are shown later?</h1><p class="warn">Retrospective development analysis after R105's padding counts were seen. These 13 fields were repeatedly viewed and come from an archive used in earlier work; there is no demonstrated sample independence or severe real overlap. This is not validation on another microscope or proof of human-level segmentation.</p><p>R105 maps 4:3 source images into a 512×512 frame with black rows above and below the actual image. Compare the original NMS-kept score ranking; the same ranking stably reordered to put prompts inside source image content first; and a valid-first ranking that recomputes 0.8 NMS on only in-image prompts before appending suppressed in-image alternatives and then every padding-prompt candidate. All original raw masks remain saved. A prompt in padding can still produce a mask over real image content, so deferral is reversible and is not a biological identity decision.</p><table><tr><th>Tile point policy</th><th>Mask IoU ≥</th><th>Budget</th><th>Original</th><th>Padding deferred</th><th>Valid-first NMS</th></tr>'''+''.join(table)+'''</table><p>Values are one-to-one matches to 24 source polygons across 13 fields. At top 10 and IoU ≥0.5, variance-guided masks improve from 13/24 to 21/24 with either padding-aware ordering; uniform masks improve from 5/24 to 10/24. The original first-ten lists contained 61 and 54 padding-prompt masks, respectively, across 13 fields; padding-aware first-ten lists contain none. These are development-set findings after observing the issue, not a frozen independent benchmark or a measured user-review-time improvement.</p><p>Both alternatives preserve the original 256 prompts and 16 crop encodings per method per field; the study reuses saved outputs, so it does not measure any inference savings. Deferral retains the exact NMS-kept set; valid-first redoes NMS on in-image candidates and appends all other eligible alternatives, so its full candidate set is larger. A target at the actual image edge may still need a partial mask; point location alone does not label the mask or target as invalid.</p><p>Source archive hashes, point partitions, valid-first NMS links, retained-candidate uniqueness, score totals and display budgets were independently reconstructed using the shared NMS and matching helpers. No model inference was rerun. Candidate volume is not a validated false-positive count; all native source imagery, crop coordinates and masks are preserved.</p><p><a href="protocol.json">Protocol</a> · <a href="results.json">All rankings and scores</a> · <a href="verify.log">Verification</a> · <a href="/research/L90.md">Research note</a> · <a href="/research/R106.md">Frozen follow-up plan</a></p>'''+''.join(cards)+'</html>')
