text stringlengths 0 1.47k |
|---|
continue |
lat, lon = r["cam"] |
br = near(lat, lon) |
if not len(br): |
continue |
by = (br[:, 0] - lat) * 110540 |
bx = (br[:, 1] - lon) * 111320 * math.cos(math.radians(lat)) |
bd = np.hypot(bx, by) |
baz = np.degrees(np.arctan2(bx, by)) % 360 |
best = None |
for dH in np.arange(-6, 6.1, 1.5): |
H = r["H"] + dH |
off = (baz - H + 180) % 360 - 180 |
def dmin(lo_, hi_): |
m = (off > lo_) & (off < hi_) & (bd > 150) |
return float(bd[m].min()) if m.any() else None |
c = dmin(-3, 3); L = dmin(-27, -21); Rr = dmin(18, 27) |
if c is None or L is None or Rr is None: |
continue |
pen = 0 |
pen += max(0, 550 - c) / 200 + max(0, c - 900) / 200 |
pen += max(0, 350 - L) / 200 + max(0, L - 750) / 200 |
pen += max(0, 800 - Rr) / 300 + max(0, Rr - 1700) / 300 |
if L >= c or c >= Rr: |
pen += 1 |
if best is None or pen < best[0]: |
best = (pen, H, c, L, Rr) |
if best is None: |
continue |
out.append({**r, "rail_pen": round(best[0], 2), "H2": best[1], "dC": round(best[2]), "dL": round(best[3]), "dR": round(best[4]), |
"total": round(r["rms"] + r["flatpen"] + 0.3 * best[0], 3)}) |
out.sort(key=lambda x: x["total"]) |
sel = [] |
for x in out: |
if all(abs(x["cam"][0] - y["cam"][0]) > 0.02 or abs(x["cam"][1] - y["cam"][1]) > 0.02 for y in sel): |
sel.append(x) |
json.dump(sel, open("f3_sel.json", "w"), ensure_ascii=False) |
print(len(out), len(sel)) |
for i, x in enumerate(sel[:30]): |
print(i, x["name"] or "-", x["cam"], "H", x["H2"], "rms", x["rms"], "railpen", x["rail_pen"], "dL/C/R", x["dL"], x["dC"], x["dR"], "total", x["total"]) |
# ===== file: examples/rail-skyline-session/refine.py ===== |
# /// script |
# requires-python = ">=3.10" |
# dependencies = ["pillow", "numpy"] |
# /// |
"""Local fine search: given a center, camera positions on a 100 m grid, scored by z13 DEM skyline + bridge-line distance together. |
This is a case-specific script for episode 13 with the photo parameters hard-coded (focal length, horizon row, ridge points, expected bridge distances 430/660/1150 m). |
Kept only as a reproduction record; not guaranteed to run on another photo. |
Usage: refine.py lat,lon radius_m out.json |
""" |
import json, math, sys |
from pathlib import Path |
import numpy as np |
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "skills/geo-sleuth/scripts")) |
import terrain # noqa |
lat0, lon0 = map(float, sys.argv[1].split(",")) |
RAD = float(sys.argv[2]) |
Z = 13 |
F0, HROW, CX = 1281.0, 935.0, 640.0 |
ridge = {760: 826, 780: 816, 800: 813, 820: 811, 840: 810, 860: 804, 880: 794, 900: 787, 920: 783, 940: 771, 960: 765, |
980: 757, 1000: 755, 1020: 747, 1040: 741, 1060: 740, 1080: 738, 1100: 737, 1120: 738, 1140: 736, 1160: 735, |
1180: 734, 1200: 725, 1220: 728, 1240: 725, 1260: 724} |
RX = np.array(list(ridge.keys()), float); RY = np.array(list(ridge.values()), float) |
FLX = np.arange(0, 281, 20, dtype=float) |
R = 6371008.8 |
dem = terrain.DEM((lat0, lon0), RAD + 16000, Z, Path(".geo-cache/dem"), None) |
gj = json.load(open("rail_bridges.geojson")) |
pts = [] |
for f in gj["features"]: |
c = f["geometry"]["coordinates"] |
if not any(abs(y - lat0) < 0.1 and abs(x - lon0) < 0.1 for x, y in c): |
continue |
for (x1, y1), (x2, y2) in zip(c, c[1:]): |
d = math.hypot((x2 - x1) * 111320 * math.cos(math.radians(y1)), (y2 - y1) * 110540) |
n = max(1, int(d // 25)) |
for k in range(n + 1): |
pts.append((y1 + (y2 - y1) * k / n, x1 + (x2 - x1) * k / n)) |
BR = np.array(pts) |
AZ = np.arange(0, 360, 0.25) |
NA = len(AZ) |
NS = 400 |
DIST = 100 * (16000 / 100) ** (np.arange(NS) / (NS - 1)) |
HS = np.arange(0, NA) |
out = [] |
for dy in np.arange(-RAD, RAD + 1, 100): |
for dx in np.arange(-RAD, RAD + 1, 100): |
clat = lat0 + dy / 110540; clon = lon0 + dx / (111320 * math.cos(math.radians(lat0))) |
ring = terrain._dest_np(clat, clon, np.arange(0, 360, 45.0), np.array([0, 100, 200.0])) |
g = dem.sample(ring[0], ring[1]) |
if g.max() - g.min() > 6: |
continue |
g0 = float(g[:, 0].mean()) |
la, lo = terrain._dest_np(clat, clon, AZ, DIST) |
hh = dem.sample(la, lo) |
drop = DIST ** 2 / (2 * R) * 0.87 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.