From 2edce7c73a0efca4db0b8b0cf6ed26f2cf3e3d8f Mon Sep 17 00:00:00 2001 From: Oliver Gaskell Date: Sun, 2 Nov 2025 15:47:33 +0000 Subject: [PATCH 1/4] engine: trilat improvements --- engine.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/engine.py b/engine.py index cf5da69..5d8efea 100755 --- a/engine.py +++ b/engine.py @@ -6,7 +6,7 @@ import overpy import numpy as np import pandas as pd import scipy -# import random +import random from pathlib import Path @@ -19,7 +19,7 @@ BRANDS: dict[str, str] = { CACHE_FOLDER = Path(".cache") LOCS_COUNT = 5 -DISTS_COUNT = 5 +DISTS_COUNT = 2 FORMAT_FACTOR = 1e6 # μm FIRST_SEP = ':' @@ -137,17 +137,25 @@ def trilaterate(stations: list[StationT], disp: bool = False) -> tuple[float, fl Each station is of the format ((lat, lon), distance). """ - res = scipy.optimize.minimize( - lambda pos: trilat_error(stations, pos), - # stations[0][0], - (0.0, 0.0), - method='Nelder-Mead', - ) + best_err = None + best = (0., 0.) - if not res.success: - print("WARNING: Optimisation failed.") + for pos, _ in stations: + res = scipy.optimize.minimize( + lambda pos: trilat_error(stations, pos), + # stations[0][0], + pos, + method='Nelder-Mead', + ) - return res.x + if not res.success: + continue + + if best_err is None or res.fun < best_err: + best = res.x + best_err = res.fun + + return best def encode_greggs(loc: int) -> list[float]: From 1b280827ea985519a913baf1a9ad38ae17e3dd9e Mon Sep 17 00:00:00 2001 From: Oliver Gaskell Date: Sun, 2 Nov 2025 15:47:47 +0000 Subject: [PATCH 2/4] engine_test: improve _greggs test --- engine_test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine_test.py b/engine_test.py index 8441ef9..70a7b38 100755 --- a/engine_test.py +++ b/engine_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from engine import encode_greggs, decode_greggs, encode, decode, format_location, parse_location, spherical_dist, fetch_data +from engine import encode_greggs, decode_greggs, encode, decode, format_location, parse_location, spherical_dist, fetch_data, format_dist, parse_dist from tqdm import tqdm import numpy as np import time @@ -62,8 +62,11 @@ def test_encode_decode_greggs(): encoded = encode_greggs(i) # tqdm.write(f"Encoding took {time.monotonic() - t:.3f}s") + stringified = ",".join(map(format_dist, encoded)) + parsed = [parse_dist(s.strip()) for s in stringified.split(",")] + # t = time.monotonic() - decoded = decode_greggs(encoded) + decoded = decode_greggs(parsed) # tqdm.write(f"Decoding took {time.monotonic() - t:.3f}s") if i != decoded: From 7109190f80244f9c48cccfe7686a9c16465cd634 Mon Sep 17 00:00:00 2001 From: Oliver Gaskell Date: Sun, 2 Nov 2025 15:49:07 +0000 Subject: [PATCH 3/4] engine: format change --- engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine.py b/engine.py index 5d8efea..dff3eb5 100755 --- a/engine.py +++ b/engine.py @@ -24,7 +24,7 @@ DISTS_COUNT = 2 FORMAT_FACTOR = 1e6 # μm FIRST_SEP = ':' OTHER_SEP = ',' -LOC_SEP = ';' +LOC_SEP = '; ' cached_dists = {} cached_series = {} From 89ca5851b817fc3fc048b28a03192a1feae7f3b2 Mon Sep 17 00:00:00 2001 From: Oliver Gaskell Date: Sun, 2 Nov 2025 15:52:35 +0000 Subject: [PATCH 4/4] engine: change to mm --- engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine.py b/engine.py index dff3eb5..72b3bf6 100755 --- a/engine.py +++ b/engine.py @@ -21,7 +21,7 @@ CACHE_FOLDER = Path(".cache") LOCS_COUNT = 5 DISTS_COUNT = 2 -FORMAT_FACTOR = 1e6 # μm +FORMAT_FACTOR = 1e3 # μm FIRST_SEP = ':' OTHER_SEP = ',' LOC_SEP = '; '