Give satellite imagery, terrain data, buildings, streetview photos to your LLM
Remove excessive limits
Belluxx8a3f37acce44
diff --git a/aleph.py b/aleph.pyindex 0bade09..f30ff22 100644--- a/aleph.py+++ b/aleph.py@@ -67,7 +67,7 @@ def parser():source.add_argument("--pano-id", help="exact panorama ID")source.add_argument("--street", help="named street to follow from end to end")street.add_argument("--match", metavar="TYPE/ID", help="choose an OSM ID returned for an ambiguous name")- street.add_argument("--stops", type=int, help="street positions (default: 10; max: 100)")+ street.add_argument("--stops", type=int, help="street positions (default: 10)")street.add_argument("--view", choices=("forward", "backward", "left", "right", "both"),help="street orientation; both saves left and right (default: forward)")street.add_argument("--route", type=int, help="choose a returned branch of a street")@@ -77,7 +77,7 @@ def parser():angle.add_argument("--look-at", nargs=2, type=float, metavar=("LAT", "LON"), help="turn a single view toward this point")street.add_argument("--pitch", type=float, default=0, help="vertical angle in degrees (default: 0)")street.add_argument("--fov", type=float, default=75, help="horizontal field of view (default: 75)")- street.add_argument("--radius", type=float, help="maximum panorama search distance in meters (default: 50; max: 1000)")+ street.add_argument("--radius", type=float, help="maximum panorama search distance in meters (default: 50)")street.add_argument("--image-format", choices=("jpg", "png"), default="jpg")output(street)network(street)diff --git a/docs/cli.md b/docs/cli.mdindex 1016f18..c5beb5f 100644--- a/docs/cli.md+++ b/docs/cli.md@@ -52,7 +52,7 @@ For example, `--stops 10` requests ten positions along the street. Choose a viewIf Aleph finds several places or street branches, choose from the returned options with `--match ID` or `--route N`, respectively.> [!TIP]-> Quick requests start immediately and cache responses for 24 hours. Use `--refresh` to fetch fresh data or `--cache-dir PATH` to change the cache location (default: `$XDG_CACHE_HOME/aleph` or `~/.cache/aleph`). Limits: 128 tiles per request, 16 megapixels per satellite image, and 100 street stops.+> Quick requests start immediately and cache responses for 24 hours. Use `--refresh` to fetch fresh data or `--cache-dir PATH` to change the cache location (default: `$XDG_CACHE_HOME/aleph` or `~/.cache/aleph`).## Capture an areadiff --git a/src/assets/index.html b/src/assets/index.htmlindex 6b65d07..9c1fb32 100644--- a/src/assets/index.html+++ b/src/assets/index.html@@ -112,7 +112,7 @@<div class="settings-group" data-source="streetview"><h3 class="settings-divider"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M3 7h4l2-3h6l2 3h4v13H3Z"/><circle cx="12" cy="13" r="4"/></svg>Street View</h3><div class="settings-grid">- <label>Photo spacing (m)<input name="step" type="number" min="1" max="1000" step="any" required></label>+ <label>Photo spacing (m)<input name="step" type="number" min="0" step="any" required></label><label>Field of view (°)<input name="fov" type="number" min="20" max="120" step="any" required></label></div></div>@@ -132,7 +132,7 @@</div><div class="settings-group"><h3 class="settings-divider"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 4v16M12 4v16M20 4v16M1 8h6m2 8h6m2-6h6"/></svg>General</h3>- <div class="settings-grid"><label>Request delay (s)<input name="delay" type="number" min="0" max="10" step="any" required></label></div>+ <div class="settings-grid"><label>Request delay (s)<input name="delay" type="number" min="0" step="any" required></label></div></div></details></div>diff --git a/src/capture.py b/src/capture.pyindex 89f75f1..f55bb91 100644--- a/src/capture.py+++ b/src/capture.py@@ -63,8 +63,14 @@ def settings(values=None):if not selected or selected - set(SOURCES):raise ValueError("Choose one or more sources: streetview, satellite, osm.")options["include"] = [source for source in SOURCES if source in selected]+ for key in ("step", "delay"):+ value = options[key]+ if (type(value) not in (int, float) or not math.isfinite(value)+ or value < 0 or (key == "step" and value == 0)):+ requirement = "positive" if key == "step" else "nonnegative"+ raise ValueError(f"{key}: use a {requirement} finite number.")for key, low, high in (- ("step", 1, 1000), ("fov", 20, 120), ("delay", 0, 10),+ ("fov", 20, 120),("satellite_zoom", 1, 21), ("terrain_zoom", 1, 14),):value = options[key]diff --git a/src/places.py b/src/places.pyindex d2032e3..154521a 100644--- a/src/places.py+++ b/src/places.py@@ -17,6 +17,12 @@ def number(value, name, low, high):return value+def positive(value, name):+ if not math.isfinite(value) or value <= 0:+ raise ValueError(f"{name} must be a positive finite number.")+ return value++def point(values):lat, lon = valuesnumber(lat, "latitude", -90, 90)@@ -27,7 +33,7 @@ def point(values):def around(center, size):"""A square in ground meters, returned in south/west/north/east order."""lat, lon = point(center)- number(size, "size", 1, 100_000)+ positive(size, "size")dy = math.degrees(size / (2 * RADIUS))if abs(lat) + dy >= 90:raise ValueError("The area cannot cross a pole.")diff --git a/src/quick.py b/src/quick.pyindex ef00d60..6cd669e 100644--- a/src/quick.py+++ b/src/quick.py@@ -7,15 +7,10 @@ from . import capture, places, routes, streetviewfrom .common import MissingImagery, RequestError, atomic_path, now, url, write_jsonfrom .geo import bearing, bounds, coordinate, distance, grid, tiles-MAX_TILES = 128-MAX_PIXELS = 16_000_000-def coverage(client, area, progress):g = grid(area, 17)count = g["rows"] * g["columns"]- if count > MAX_TILES:- raise RequestError("request_too_large", f"Quick requests allow at most {MAX_TILES} coverage tiles.")found = {}for i, tile in enumerate(tiles(g), 1):address = url("https://www.google.com/maps/photometa/ac/v1",@@ -44,8 +39,9 @@ def street_photos(client, output, progress, *, at=None, place=None, pano_id=Noneplaces.number(heading, "heading", 0, 360)places.number(pitch, "pitch", -90, 90)places.number(fov, "fov", 20, 120)- places.number(radius, "radius", 1, 1000)- places.number(stops, "stops", 1, 100)+ places.positive(radius, "radius")+ if type(stops) is not int or stops < 1:+ raise ValueError("stops must be a positive whole number.")if look_at is not None:places.point(look_at)selected_place, selected_route = None, None@@ -149,8 +145,6 @@ def satellite(client, output, progress, *, at=None, place=None, match=None,center, selected_place = location(client, at=at, place=place, match=match, endpoint=endpoint)area = places.around(center, size)g = grid(area, zoom)- if g["rows"] * g["columns"] > MAX_TILES or g["width"] * g["height"] > MAX_PIXELS:- raise RequestError("request_too_large", "Use a smaller area or lower zoom (128 tiles / 16 megapixels maximum).")run = capture.plan(client, area, dict(include=["satellite"], satellite_zoom=zoom), progress)folder = capture.create_folder(run, output)try:diff --git a/tests/test_capture.py b/tests/test_capture.pyindex 6b779f7..240cbba 100644--- a/tests/test_capture.py+++ b/tests/test_capture.py@@ -36,6 +36,17 @@ class CaptureRecoveryTests(unittest.TestCase):self.client.get.side_effect = AssertionError("Unexpected image download")self.client.overpass.side_effect = AssertionError("Unexpected OSM download")+ def test_spacing_and_delay_require_valid_numbers_without_workload_caps(self):+ for step in (0.5, 2000):+ options = capture.settings(dict(step=step, delay=60))+ self.assertEqual((options["step"], options["delay"]), (step, 60))+ self.assertEqual(capture.settings(dict(delay=0))["delay"], 0)+ for key, values in (("step", (0, -1, float("inf"), float("nan"))),+ ("delay", (-1, float("inf"), float("nan")))):+ for value in values:+ with self.subTest(key=key, value=value), self.assertRaises(ValueError):+ capture.settings({key: value})+def test_interrupted_second_side_resumes_from_saved_checkpoint(self):photo = image_bytes((1024, 576), "red")for error, state in ((KeyboardInterrupt(), "stopped"), (OSError("offline"), "failed")):diff --git a/tests/test_queries.py b/tests/test_queries.pyindex 754cd51..4d7c235 100644--- a/tests/test_queries.py+++ b/tests/test_queries.py@@ -89,11 +89,14 @@ class QueryTests(unittest.TestCase):self.assertTrue(Path(result["path"]).is_file())self.assertEqual(self.get.call_count, 1)- def test_quick_satellite_limit_is_checked_before_network(self):- status, result = self.invoke("satellite", "--at", "0", "0", "--size", "100000", "--zoom", "21")- self.assertEqual(status, 1)- self.assertEqual(result["error"]["code"], "request_too_large")- self.get.assert_not_called()+ def test_satellite_exceeds_former_size_tile_and_pixel_caps(self):+ self.get.return_value = image_bytes((256, 256), "red")+ status, result = self.invoke("satellite", "--at", "0", "0", "--size", "200001",+ "--zoom", "12", "-o", str(self.directory))+ self.assertEqual(status, 0, result)+ self.assertGreater(result["width"] * result["height"], 16_000_000)+ self.assertGreater(self.get.call_count, 128)+ self.assertTrue(Path(result["path"]).is_file())def test_single_streetview_uses_actual_camera_and_look_at_without_osm(self):def response(address, **kwargs):@@ -149,6 +152,12 @@ class QueryTests(unittest.TestCase):[f"panorama_{i:04d}" for i in (1, 1, 2, 2, 3, 3)])self.assertEqual([round(p["heading"]) for p in result["photos"]], [0, 180] * 3)self.assertAlmostEqual(result["route"]["length_m"], 222.39, places=2)+ status, result = self.invoke("streetview", "--street", "Test Street", "--stops", "101",+ "-o", str(self.directory))+ self.assertEqual(status, 0, result)+ self.assertEqual(result["requested_stops"], 101)+ self.assertEqual(result["saved_stops"], 3)+ self.assertEqual(len(result["gaps"]), 98)for failure, expected_status in ((OSError("connection lost"), 1), (KeyboardInterrupt(), 130)):with self.subTest(failure=type(failure).__name__):images = 0@@ -162,9 +171,11 @@ class QueryTests(unittest.TestCase):def test_no_coverage_is_a_structured_error_and_does_not_create_output(self):self.get.return_value = coverage([])- status, result = self.invoke("streetview", "--at", "0", "0", "-o", str(self.directory / "output"))+ status, result = self.invoke("streetview", "--at", "0", "0", "--radius", "2000",+ "-o", str(self.directory / "output"))self.assertEqual(status, 1)self.assertEqual(result["error"]["code"], "no_coverage")+ self.assertGreater(self.get.call_count, 128)self.assertFalse((self.directory / "output").exists())def test_invalid_or_conflicting_options_fail_before_requests(self):@@ -173,9 +184,17 @@ class QueryTests(unittest.TestCase):["resolve", "--at", "nan", "0"],["resolve", "Rome", "--nearby"],["resolve", "--at", "1", "2", "--radius", "20"],+ ["resolve", "--at", "1", "2", "--nearby", "--radius", "5001"],+ ["resolve", "Test", "--limit", "51"],+ ["resolve", "--at", "1", "2", "--nearby", "--limit", "51"],["streetview", "--at", "0", "0", "--place", "Rome"],["streetview", "--at", "0", "0", "--stops", "10"],["streetview", "--street", "Test", "--heading", "90"],+ ["streetview", "--street", "Test", "--stops", "0"],+ ["streetview", "--at", "0", "0", "--radius", "0"],+ ["streetview", "--at", "0", "0", "--radius", "inf"],+ ["satellite", "--at", "0", "0", "--size", "0"],+ ["satellite", "--at", "0", "0", "--size", "nan"],["satellite", "--tile", "19/1"],["satellite", "--tile", "1/2/0"],["satellite", "--tile", "19/1/1", "--zoom", "20"],