import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r105';rows=json.loads((O/'results.json').read_text())['records'];total=sum(r['references'] for r in rows);methods=('whole','uniform','variance');tables=[]
for t in ('0.5','0.75'):
 for n in ('10','30','60','all'):
  vals=[sum(r['scores'][k]['ranked'][n][t]['matched'] for r in rows) for k in methods];tables.append(f'<tr><td>{t}</td><td>{n}</td>'+''.join(f'<td>{v}/{total}</td>' for v in vals)+'</tr>')
cards=[]
for r in rows:
 vals=[r['scores'][k]['ranked']['10']['0.5']['matched'] for k in methods];cards.append(f'<section><h2>Source field {r["index"]:02d}</h2><p>Top 10 matches: whole / uniform tiles / variance tiles = {" / ".join(map(str,vals))} of {r["references"]}. Tile points on padding: {r["stats"]["uniform"]["in_padding"]} / {r["stats"]["variance"]["in_padding"]}.</p><a href="{r["panel"]}"><img loading="lazy" src="{r["panel"]}" alt="Source reference polygons and whole-image, uniform-tile, and variance-tile masks"></a><p><a href="/{html.escape(r["source"])}">Original public RGB</a> · <a href="{r["archive"]}">Raw tile masks and point coordinates</a> · <a href="/{html.escape(r["reference_archive"])}">Published polygon references and R87 candidates</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>R105 real-field tile points</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/l89/">Synthetic tile study</a> · <a href="/results/r98/">Source audit</a><h1>R105: Tile-point strategies on real public fields</h1><p class="warn">Development check on 13 previously viewed fields from an archive also used for some training. Sample, slide and base-model training independence are unknown. Source annotations do not establish severe overlap; they may omit organisms. This does not establish real-overlap, species or human-level accuracy.</p><p>Use the 13 R98-retained Khanom fields and 24 source polygons, preserving the earlier quarantine of three similar fields. Run the frozen L88 uniform and L89 image-variance point rules on identical 16 overlapping 256-pixel crops. Each method uses 256 queries and 16 image encodings per field when run alone; this paired run shares each encoding and uses 512 queries. An earlier 256-query whole-image point grid is a cached comparison with one encoding, different point locations and context. All strategies use the same score, area and NMS thresholds.</p><table><tr><th>Mask IoU ≥</th><th>Mask budget per field</th><th>Whole-image grid</th><th>Uniform tiles</th><th>Variance tiles</th></tr>'''+''.join(tables)+'''</table><p>Cells are one-to-one matches to 24 available source polygons. At top 10 and IoU ≥0.5, variance tiles match 13/24 versus 5/24 for uniform tiles; the earlier whole-image grid matches 17/24 with different geometry and compute. At top 30 the respective totals are 24/24, 22/24 and 24/24. These nonrandom, previously studied fields cannot establish generalization.</p><p>Reference-conditioned after inference, 182 of 3,328 uniform tile queries and 927 of 3,328 variance queries land on a source polygon. The same source location may be queried multiple times in overlapping tiles; a point on a polygon is not necessarily a correct mask. The images are 4:3 content padded with black rows; 416 uniform and 335 variance queries land in padding. Padding was not filtered, so its influence on ranking remains a testable factor rather than an established cause of the observed difference.</p><p>Uniform and variance streams retain 836 and 712 masks after NMS; 591 and 485 of those touch a crop boundary. Source labels can be incomplete, so candidate counts do not establish false positives. The display budget counts masks, not measured review time. Both raw streams, suppression aliases, native RGB links and crop coordinates are retained.</p><p>Source/archive hashes, reused reference masks, point-selection and crop geometry, candidate filtering, shared NMS and matching scores were reconstructed. Eight selected individual queries reproduced their saved batch masks; verification shares the point selector and matcher and does not repeat all inference. Source images: <a href="https://zenodo.org/records/21295927">Khanom, Images of diatoms for CNN model training</a>, CC BY 4.0; model/software terms are separate.</p><p><a href="protocol.json">Protocol</a> · <a href="results.json">Scores, ranks and point counts</a> · <a href="verify.log">Verification</a> · <a href="sample-replay.json">Sample replay</a> · <a href="/research/R105.md">Research note</a></p>'''+''.join(cards)+'</html>')
