feat(research): preserve urban geometry pipelines and qualification suites

Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:10:00 +03:00
parent 5d56237124
commit 69dc566665
611 changed files with 52016 additions and 28 deletions
@@ -0,0 +1,54 @@
"""Independent checks of the saved candidate; never refits geometry."""
import numpy as np
from shapely.geometry import shape,box,LineString
from shapely.ops import unary_union
def audit(base,result,hints,reports,graph):
old=[f for f in base['features']if f['properties']['class']=='road_boundary']
new=[f for f in result['features']if f['properties']['class']=='road_boundary']
other=lambda doc:[f for f in doc['features']if f['properties']['class']!='road_boundary']
assert other(base)==other(result)
assert base['source']==result['source']and base['coordinate_system']==result['coordinate_system']
geoms=[shape(f['geometry'])for f in new]
assert all(g.is_simple and not g.is_ring and np.isfinite(g.coords).all()for g in geoms)
contacts=[(new[i]['id'],new[j]['id'])for i,a in enumerate(geoms)for j in range(i+1,len(geoms))if a.intersects(geoms[j])]
assert not contacts,contacts
reviewed=unary_union([box(*h['bounds'])for h in hints['cases']])
before=unary_union([shape(f['geometry'])for f in old]);after=unary_union(geoms)
outside_before=before.difference(reviewed);outside_after=after.difference(reviewed)
lost=outside_before.difference(outside_after.buffer(1e-6)).length;added=outside_after.difference(outside_before.buffer(1e-6)).length
assert lost<1e-5 and added<1e-5,(lost,added)
oldends=[f['geometry']['coordinates'][i]for f in old for i in(0,-1)]
newends=[f['geometry']['coordinates'][i]for f in new for i in(0,-1)]
assert all(p in newends for p in oldends)
assert len(newends)==len(oldends)+2
accounting=[]
for f in old:
intervals=[]
for n in new:
for part in n['properties']['construction']:
intervals.extend(p['interval_m']for p in part['parents']if p['id']==f['id'])
openings=[r['opening']['source_interval_m']for r in reports if r['feature_id']==f['id']and'opening'in r]
cursor=0.;overlap=0.;gap=0.
for a,b in sorted(intervals+openings):
overlap+=max(0.,cursor-a);gap+=max(0.,a-cursor);cursor=max(cursor,b)
gap+=max(0.,shape(f['geometry']).length-cursor)
assert gap<1e-5 and overlap<1e-5,(f['id'],gap,overlap)
accounting.append(dict(id=f['id'],unaccounted_m=gap,duplicate_m=overlap,retained_intervals=intervals,known_opening_intervals=openings))
spans=[]
for f,g in zip(new,geoms):
for span in f['properties'].get('inferred_spans',[]):
s=LineString(span['coordinates']);assert s.difference(g.buffer(1e-6)).length<1e-5,(f['id'],span['method']);spans.append(s)
changed=after.difference(before.buffer(1e-6));unmarked=changed.difference(unary_union(spans).buffer(2e-6)).length
assert unmarked<1e-4,unmarked
nodes={n['id']:n for n in graph['nodes']};assert len(graph['edges'])==len(new)
features={f['id']:f for f in new}
for e in graph['edges']:
assert e['geometry']==features[e['id']]['geometry']
assert nodes[e['start_node']]['coordinates']==e['geometry']['coordinates'][0]
assert nodes[e['end_node']]['coordinates']==e['geometry']['coordinates'][-1]
props=features[e['id']]['properties']
assert nodes[e['start_node']]['status']==props.get('start_reason','open-curb-end')
assert nodes[e['end_node']]['status']==props.get('end_reason','open-curb-end')
assert graph['route_permission']==result['route_permission']=='unassigned'
return dict(status='passed',curb_chains=len(new),total_features=len(result['features']),length_xy_m=sum(g.length for g in geoms),non_curbs_unchanged=len(other(base)),self_intersections=0,pair_contacts=0,rings=0,prior_endpoints_preserved=len(oldends),new_open_access_ends=2,changed_outside_review_m=lost+added,unmarked_new_geometry_m=unmarked,inferred_spans=len(spans),graph_nodes=len(nodes),graph_edges=len(graph['edges']),source_accounting=accounting)