Give satellite imagery, terrain data, buildings, streetview photos to your LLM
Faster satellite loading
Belluxx3915029d59d1
diff --git a/src/dashboard_tiles.py b/src/dashboard_tiles.pyindex 3d00c7c..5d6fd74 100644--- a/src/dashboard_tiles.py+++ b/src/dashboard_tiles.py@@ -82,7 +82,7 @@ def tile_state(grid, count, z, x, y):class Tiles:def __init__(self, cache):self.cache = cache- self.lock = threading.Lock()+ self.locks = {kind: threading.Lock() for kind in ("satellite", "terrain")}self.versions = {}def get(self, folder, run, kind, z, x, y):@@ -98,9 +98,17 @@ class Tiles:grid = stage["grid"]count = len(stage["results"]) if kind == "satellite" else grid["columns"] * grid["rows"]version, complete = tile_state(grid, count, z, x, y)+ # Native imagery is already browser-readable; avoid decoding or re-encoding it.+ if kind == "satellite" and version and z == grid["zoom"]:+ original = contained(folder, stage["results"][version - 1]["filename"])+ if original.is_file():+ return original, completefilename = directory / str(z) / str(x) / f"{y}.png"- # Limit concurrent decoding and avoid two requests writing the same cache tile.- with self.lock:+ # Published cache files are atomic. Ready tiles never wait for an overview build.+ if self.versions.get(filename, -1) >= version:+ return filename, complete+ # Bound decoding to one tree per layer, without terrain blocking satellite imagery.+ with self.locks[kind]:if self.versions.get(filename, -1) < version:with self._image(folder, directory, grid, stage["results"], count, kind, z, x, y) as image:if kind == "terrain":@@ -118,17 +126,16 @@ class Tiles:if self.versions.get(filename, -1) >= version:with Image.open(filename) as image:return image.copy()+ if not elevation and version and z == grid["zoom"]:+ path = contained(folder, results[version - 1]["filename"])+ if path.is_file():+ with Image.open(path) as patch:+ return patch.convert("RGBA")image = Image.new(mode, (size, size))if version and z == grid["zoom"]:if elevation:image.close()image = terrain_tile(contained(folder, "terrain.tif"), grid, x, y)- else:- item = results[version - 1]- path = contained(folder, item["filename"])- if path.is_file():- with Image.open(path) as patch:- image.paste(patch)elif version:for dy in range(2):for dx in range(2):diff --git a/tests/test_dashboard_tiles.py b/tests/test_dashboard_tiles.pyindex 47ad345..5b6ab02 100644--- a/tests/test_dashboard_tiles.py+++ b/tests/test_dashboard_tiles.py@@ -1,6 +1,8 @@import tempfileimport unittest+from concurrent.futures import ThreadPoolExecutorfrom pathlib import Path+from unittest.mock import patchfrom PIL import Image@@ -9,6 +11,32 @@ from tests.fixtures import image_bytesclass DashboardTileTests(unittest.TestCase):+ def test_native_and_cached_tiles_do_not_wait_for_generation(self):+ with tempfile.TemporaryDirectory() as directory, ThreadPoolExecutor() as workers:+ root = Path(directory).resolve()+ folder = root / "capture"+ folder.mkdir()+ with Image.new("RGB", (256, 256), "red") as image:+ image.save(folder / "original.jpg")+ with Image.new("RGBA", (256, 256)) as image:+ image.save(folder / "gap.png")+ stage = dict(mode="satellite", grid=dict(zoom=2, x0=0, y0=0, columns=2, rows=2),+ results=[dict(filename=name) for name in+ ("original.jpg", "gap.png", "original.jpg", "original.jpg")])+ run = dict(stages=[stage])+ tiles = Tiles(root / "cache")+ overview, _ = tiles.get(folder, run, "satellite", 1, 0, 0)+ # Only the overview needs encoding; originals remain the native tiles.+ self.assertEqual(list((root / "cache").rglob("*.png")), [overview])+ with tiles.locks["satellite"], tiles.locks["terrain"], patch.object(+ Image, "open", side_effect=AssertionError("Ready tiles must not be decoded")+ ):+ for z, x, expected in ((2, 0, folder / "original.jpg"), (2, 1, folder / "gap.png"),+ (1, 0, overview)):+ with self.subTest(zoom=z, x=x):+ result = workers.submit(tiles.get, folder, run, "satellite", z, x, 0)+ self.assertEqual(result.result(timeout=2), (expected, True))+def test_cached_overview_refreshes_as_capture_fills_in(self):with tempfile.TemporaryDirectory() as directory:root = Path(directory)