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,48 @@
from pathlib import Path
import json, hashlib, time, os
from datetime import datetime, timezone
import numpy as np, cv2, shapely
from shapely.geometry import shape
from layer_common import O, S
from search_views import SearchViews
from discovery_evidence import glyph_views
from strip_validation import VERSION, POLICY, unsupported
cv2.setNumThreads(3)
started = time.monotonic()
baseline = Path('/fullplan/full-map.json')
old = json.loads(baseline.read_text())
with np.load('/evidence_plan/fields.npz') as z:
labels, low, high = z['labels'], z['bounds'][0], z['bounds'][1]
tiles = [t for t in json.loads((S/'tile-index.json').read_text())['tiles'] if t['status']=='surveyed']
views = SearchViews(tiles, labels, low, high, shapely.GeometryCollection())
evaluated, edits, rejected = [], [], set()
for f in old['features']:
p = f['properties']
if p.get('class') != 'road_marking' or p.get('subtype') != 'linear_marking' or p.get('method') != POLICY['candidate_method']:
continue
polygon = shapely.force_2d(shape(f['geometry']))
evidence, names = glyph_views(polygon, views, None, None)
reject = unsupported(evidence)
evaluated.append(dict(id=f['id'], source_tiles=names, evidence=evidence, rejected=reject))
if reject:
rejected.add(f['id'])
edits.append(dict(kind='unsupported-legacy-strip', source_ids=[f['id']], output_ids=[],
before=[f], after=[], bounds_xy=list(polygon.bounds), evidence=evidence, source_tiles=names))
result = dict(old, features=[f for f in old['features'] if f['id'] not in rejected],
strip_validation=dict(version=VERSION, rejected=len(rejected), manual_geometry=False))
raw = json.dumps(result, ensure_ascii=False, allow_nan=False).encode()
(O/'full-map.json').write_bytes(raw)
(O/'marking-rows.json').write_text(json.dumps(edits, ensure_ascii=False, indent=2))
checks = dict(only_negative_evidence_removed=all(unsupported(r['evidence']) for r in edits),
retained_features_identical=result['features']==[f for f in old['features'] if f['id'] not in rejected],
no_new_features=all(f in old['features'] for f in result['features']),
unique_ids=len({f['id'] for f in result['features']})==len(result['features']))
audit = dict(passed=all(checks.values()), checks=checks, full_map_sha256=hashlib.sha256(raw).hexdigest(),
metric_accuracy_measured=False, complete_recall_measured=False)
(O/'strip-audit.json').write_text(json.dumps(audit, indent=2))
report = dict(version=VERSION, policy=POLICY, scene=os.environ['SCENE'], utc=datetime.now(timezone.utc).isoformat(),
monotonic_started=started, seconds=time.monotonic()-started, baseline_sha256=hashlib.sha256(baseline.read_bytes()).hexdigest(),
evaluated=evaluated, rejected=sorted(rejected), output_features=len(result['features']))
(O/'strip-report.json').write_text(json.dumps(report, indent=2))
print(json.dumps(dict(scene=report['scene'], checked=len(evaluated), rejected=sorted(rejected), passed=audit['passed'])), flush=True)
@@ -0,0 +1,15 @@
"""Negative evidence may reject old free-form strips, never invent new paint."""
import math
VERSION = 'legacy-strip-negative-evidence-v1'
POLICY = dict(min_valid=.98, max_paint_support=.20, required_views=2,
candidate_method='parametric-paint-strip', manual_rois=[], point_clouds=False)
def unsupported(evidence):
return len(evidence) == POLICY['required_views'] and all(
math.isfinite(e.get('valid', float('nan')))
and math.isfinite(e.get('support', float('nan')))
and e['valid'] >= POLICY['min_valid']
and e['support'] <= POLICY['max_paint_support']
for e in evidence)
@@ -0,0 +1,27 @@
import json
from pathlib import Path
import numpy as np
from shapely.geometry import box
from discovery_rules import glyph_score
from strip_validation import unsupported
dark=dict(valid=1.,support=0.)
checks = {
'two_dark_views_rejected':unsupported([dark,dark]),
'one_view_insufficient':not unsupported([dark]),
'missing_views_insufficient':not unsupported([]),
'occlusion_not_negative_evidence':not unsupported([dark,dict(valid=.4,support=0.)]),
'paint_in_either_view_protects':not unsupported([dark,dict(valid=1.,support=.7)]),
'nan_rejected_as_evidence':not unsupported([dark,dict(valid=1.,support=float('nan'))]),
}
x,y=np.meshgrid(np.arange(-1,3,.04),np.arange(-1,1,.04))
points=np.c_[x.ravel(),y.ravel()]; polygon=box(0,-.06,2,.06)
rgb=np.full((*x.shape,3),90,dtype=np.uint8); valid=np.ones(x.shape,bool)
blank=glyph_score(rgb,valid,points,polygon)
checks['blank_gaussian_rgb_rejects']=unsupported([blank,blank])
rgb[(abs(y)<.07)&(x>=0)&(x<=2)]=230
paint=glyph_score(rgb,valid,points,polygon)
checks['synthetic_paint_preserved']=not unsupported([paint,paint])
assert all(checks.values()),checks
Path('/out/strip-tests.json').write_text(json.dumps(dict(passed=True,checks=checks),indent=2))
print(json.dumps(checks),flush=True)