"""Publish all newly sampled development background sites."""
import html,json
from pathlib import Path
from PIL import Image,ImageDraw
R=Path(__file__).resolve().parents[1];O=R/'results/r112/academy-backgrounds-v2';d=json.loads((O/'manifest.json').read_text());cards=[]
for i,r in enumerate(d['records']):
 pane=Image.new('L',(768,280),255);draw=ImageDraw.Draw(pane)
 for j,x in enumerate(r['images']):
  draw.text((j*256+4,4),'Z index '+str(x['z_index']),fill=30);im=Image.open(O/x['path']).convert('L').resize((250,250));pane.paste(im,(j*256+3,25))
 name=f'field-{i:03d}-triplet.jpg';pane.save(O/name,quality=88);cards.append('<article><h3>Site '+str(i+1)+' · '+html.escape(r['slide'])+'</h3><p>XY origin '+html.escape(str(r['origin_xy']))+'; scale '+html.escape(str(r['um_per_pixel_xy']))+' µm/pixel. Focus positions are plane indices, not confirmed physical Z positions.</p><a href="'+name+'"><img loading="lazy" src="'+name+'" alt="Three indexed focus planes from one unlabelled location"></a><p>'+ ' · '.join('<a href="'+html.escape(x['path'])+'">plane '+str(x['z_index'])+'</a>' for x in r['images'])+'</p></article>')
page='''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Academy development backgrounds</title><style>body{font:16px/1.55 system-ui;background:#f4f6f0;color:#193b37;margin:0}main{max-width:1050px;margin:auto;padding:24px}a{color:#096c58}.notice,article{background:white;border:1px solid #cddbd2;padding:16px;margin:14px 0}.notice{border-left:5px solid #bc851b}img{max-width:100%;height:auto}</style><main><nav><a href="/results/r112/">Synthetic training</a></nav><h1>Additional Academy development fields</h1><p class="notice"><strong>Unlabeled real fields, not empty background.</strong> Any field may contain diatoms, overlapping organisms, fragments or debris. No pixel is confirmed negative, and no organism has been identified or segmented here.</p><p>64 locations were selected from eight slides already used for development, with three nearby plane indices at each location. Coordinates were chosen from metadata before viewing image content. The images are single-channel native-resolution crops. Different locations, focus planes and slide names do not prove independent biological samples or an unbiased representation of the collection. Other Academy slides were not sampled for this pool.</p><p>Within each site, images have the same XY location; similar plane indices do not establish measured Z distances or proper focus. The TIFF reader, file length and saved field hashes were verified, but the entire multi-gigabyte scan was not hashed.</p><p><a href="protocol.json">Selection protocol</a> · <a href="manifest.json">Coordinates, scale and file hashes</a> · <a href="verify.json">Re-extraction checks</a></p>'''+''.join(cards)+'''</main></html>''';(O/'index.html').write_text(page);print('published',len(cards),'triplets')
