"""Trace shared conservative source locations into the prior synthetic comparison."""
import hashlib,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r112/ude-sampling-metadata';C=O/'site-components.json';M=R/'results/r112/grouped-synthetic/manifest.json';sha=lambda p:hashlib.sha256(Path(p).read_bytes()).hexdigest();c=json.loads(C.read_text());m=json.loads(M.read_text());shared=c['shared_components_in_existing_local_split'];q={i for group in shared for i in group['validation_ids']};train={i for group in shared for i in group['train_ids']};val=[i for scene in m['records'] if scene['synthetic_partition']=='validation' for i in scene['instances']];counts={'shared_location_components':len(shared),'local_split_train_sources_in_shared_components':len(train),'local_split_validation_sources_in_shared_components':len(q),'comparison_scene_placements':len(val),'comparison_placements_in_shared_components':sum(x['annotation_id'] in q for x in val),'comparison_unique_sources_in_shared_components':len({x['annotation_id'] for x in val if x['annotation_id'] in q})};result={'format':'r112-ude-site-impact-v1','components_sha256':sha(C),'synthetic_manifest_sha256':sha(M),'script_sha256':sha(Path(__file__)),'counts':counts,'limitation':'Location components connect matching site codes or six-decimal coordinates transitively. They are conservative spatial proxies, not definitive biological samples; shared components do not prove duplicate organisms, and different components do not prove independent populations. The synthetic comparison was already consumed.'};(O/'site-impact.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(counts,indent=2))
