"""One deterministic native-image traversal; no prior map or missed-object input.""" from pathlib import Path import json,time,hashlib import numpy as np,cv2,shapely from shapely.geometry import mapping,shape from scipy.ndimage import distance_transform_edt from layer_common import sample,feature from fit_scene import world from search_views import SearchViews from line_reconstruction import extract,dedup from search_rules import pack from paint_observations import collect as paint_observations from catalog_observations import collect as catalog_observations from compact_observations import collect as compact_observations from crossing_discovery import primitives def main(): O=Path('/out');start=time.monotonic();cv2.setNumThreads(3);cv2.setRNGSeed(2026) with np.load('/evidence_plan/fields.npz')as z:labels=z['labels'];low,high=z['bounds'] tiles=[t for t in json.loads(Path('/survey/tile-index.json').read_text())['tiles']if t['status']=='surveyed'] views=SearchViews(tiles,labels,low,high,None) lines=[];paint=[];crossbars=[];glyphs=[];compact=[];seeds=[];reports=[];sources={} from observation_tiles import ordered_tiles workers=int(__import__('os').environ.get('OBSERVATION_WORKERS','4')) for row in ordered_tiles(views.tiles,workers): lines.extend(row['lines']);paint.extend(row['paint']);crossbars.extend(row['crossbars']) glyphs.extend(row['glyphs']);compact.extend(row['compact']);seeds.extend(row['seeds']) reports.append(row['report']);sources[row['report']['tile']]=row['source'] print('OBSERVATION',json.dumps(reports[-1]),flush=True) (O/'observation-progress.json').write_text(json.dumps(reports)) from stroke_inventory import deduplicate as indexed_line_dedup def suppress(records,geometry,threshold): ordered=sorted(records,key=lambda r:-geometry(r).area);geometries=[geometry(r)for r in ordered] if not geometries:return [] tree=shapely.STRtree(geometries);accepted=set();result=[] for i,(r,p)in enumerate(zip(ordered,geometries)): if any(j in accepted and p.intersection(geometries[j]).area/max(min(p.area,geometries[j].area),1e-9)>threshold for j in tree.query(p,predicate='intersects')):continue accepted.add(i);result.append(r) return result lines=indexed_line_dedup(lines);glyphs=suppress(glyphs,lambda r:shape(r['geometry']),.85) seeds=suppress(seeds,lambda p:p,.5) # IDs and search inputs depend only on this observation run; there is no map seed. (O/'search-proposals.json').write_text(json.dumps(dict(lines=[pack(r)for r in lines],source_fields_sha256=hashlib.sha256(Path('/evidence_plan/fields.npz').read_bytes()).hexdigest(),glyphs=[],tile_reports=reports,source='systematic-primary-native-observations',manual_rois=[]),allow_nan=False)) (O/'catalog-proposals.json').write_text(json.dumps(dict(glyphs=glyphs,source_fields_sha256=hashlib.sha256(Path('/evidence_plan/fields.npz').read_bytes()).hexdigest(),tile_reports=reports,source='systematic-primary-native-observations',manual_rois=[]),allow_nan=False)) (O/'compact-seeds.json').write_text(json.dumps(compact)) (O/'crossing-seeds.json').write_text(json.dumps([feature(p,'road_marking',subtype='crosswalk')for p in seeds])) (O/'observations.json').write_text(json.dumps(dict(paint=paint,crossbars=crossbars,source_semantics=sources,manual_rois=[],existing_map_input=False),allow_nan=False)) (O/'observation-report.json').write_text(json.dumps(dict(tiles=len(reports),seconds=time.monotonic()-start,linear=len(lines),catalog=len(glyphs),paint=len(paint),crossbars=len(crossbars),compact=len(compact),crossing_seeds=len(seeds),existing_map_input=False,full_scene_traversals=1,workers=workers,maximum_pending_tiles=workers*2,detector_seconds={k:sum(r['detectors'][k]for r in reports)for k in reports[0]['detectors']}),indent=2)) print('OBSERVATIONS_COMPLETE',time.monotonic()-start,flush=True) if __name__=='__main__':main()