text stringlengths 0 1.47k |
|---|
ang = np.degrees(np.arctan2(hh - drop[None, :] - g0 - 1.6, DIST[None, :])) |
hor = ang.max(axis=1) |
by = (BR[:, 0] - clat) * 110540; bx = (BR[:, 1] - clon) * 111320 * math.cos(math.radians(clat)) |
bd = np.hypot(bx, by); baz = np.degrees(np.arctan2(bx, by)) % 360 |
best = None |
for fs in (1.0, 1.08, 1.16): |
f = F0 * fs |
r_off = np.degrees(np.arctan((RX - CX) / f)); r_el = np.degrees(np.arctan((HROW - RY) / f)) |
fl_off = np.degrees(np.arctan((FLX - CX) / f)) |
ri = (HS[:, None] + np.round(r_off / 0.25).astype(int)[None, :]) % NA |
fi = (HS[:, None] + np.round(fl_off / 0.25).astype(int)[None, :]) % NA |
diff = hor[ri] - r_el[None, :] |
cc = np.clip(np.median(diff, axis=1), -0.7, 0.7) |
rms = np.sqrt(np.mean((diff - cc[:, None]) ** 2, axis=1)) |
pen = np.mean(np.clip(hor[fi] - cc[:, None] - 1.0, 0, None), axis=1) |
s = rms + 1.5 * pen |
for k in np.argsort(s)[:12]: |
H = k * 0.25 |
off = (baz - H + 180) % 360 - 180 |
def dmin(a, b): |
m = (off > a) & (off < b) & (bd > 100) |
return float(bd[m].min()) if m.any() else 99999 |
hf = math.degrees(math.atan(640 / f)) |
L = dmin(-hf, -hf + 5); C = dmin(-2, 2); Rr = dmin(hf - 8, hf) |
eL, eC, eR = 430 * fs, 660 * fs, 1150 * fs |
rp = abs(math.log(L / eL)) + abs(math.log(C / eC)) + abs(math.log(Rr / eR)) |
tot = float(s[k]) + 0.5 * rp |
if best is None or tot < best["total"]: |
best = {"cam": [round(clat, 5), round(clon, 5)], "g": round(g0, 1), "H": H, "fs": fs, "cc": round(float(cc[k]), 2), |
"rms": round(float(rms[k]), 3), "flatpen": round(float(pen[k]), 3), "dL": round(L), "dC": round(C), "dR": round(Rr), |
"railpen": round(rp, 3), "total": round(tot, 3)} |
if best: |
out.append(best) |
out.sort(key=lambda x: x["total"]) |
json.dump(out, open(sys.argv[3], "w"), ensure_ascii=False) |
for x in out[:15]: |
print(x) |
# ===== file: examples/rail-skyline-session/skyfit2.py ===== |
# /// script |
# requires-python = ">=3.10" |
# dependencies = ["pillow", "numpy"] |
# /// |
"""Round 2: camera-position grid + three constraints scored together. |
This is a case-specific script for episode 13 with the photo parameters hard-coded: focal length F0, horizon row HROW, the 26 ridge pixel points ridge, |
and the flat-horizon column range FLX were all measured from that photo. Kept only as a reproduction record; not guaranteed to run on another photo. |
A ground at the camera position is flat (relief < 8 m within 300 m) |
B bridge in the left part of the frame [-27°,-10°] (250–1000 m), bridge in the right part [3°,27°] (400–2000 m) |
C ridgeline RMS (heading, horizon offset, and focal-length scale searched together) |
D skyline < 1° in the left part [-27°,-12°] |
""" |
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 |
Z = 11 |
CACHE = Path(".geo-cache/dem") |
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 |
hits = json.load(open(sys.argv[1])) |
a0, a1 = (int(v) for v in sys.argv[3].split(":")) |
# bridge sample points (100 m) |
gj = json.load(open("rail_bridges.geojson")) |
cell = {} |
def add(lat, lon): |
cell.setdefault((int(lat / 0.02), int(lon / 0.02)), []).append((lat, lon)) |
for f in gj["features"]: |
if f["properties"].get("electrified") == "no": |
continue |
c = f["geometry"]["coordinates"] |
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 // 100)) |
for k in range(n + 1): |
add(y1 + (y2 - y1) * k / n, x1 + (x2 - x1) * k / n) |
def bridges_near(lat, lon): |
i, j = int(lat / 0.02), int(lon / 0.02) |
out = [] |
for di in (-1, 0, 1): |
for dj in (-1, 0, 1): |
out += cell.get((i + di, j + dj), []) |
return np.array(out) if out else np.zeros((0, 2)) |
AZ = np.arange(0, 360, 0.5) |
NS = 260 |
DIST = 150 * (15000 / 150) ** (np.arange(NS) / (NS - 1)) |
HS = np.arange(0, 720) # headings in 0.5° steps |
def fit(hor): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.