Give satellite imagery, terrain data, buildings, streetview photos to your LLM
Match streetview google validation
Belluxx535a603265db
diff --git a/aleph.py b/aleph.pyindex 5625e4c..a398c89 100644--- a/aleph.py+++ b/aleph.py@@ -75,10 +75,10 @@ def parser():street.add_argument("--route", type=int, help="choose a returned branch of a street")street.add_argument("--reverse", action="store_true", help="reverse the street traversal order")angle = street.add_mutually_exclusive_group()- angle.add_argument("--heading", type=float, help="single-view heading clockwise from north (default: 0)")+ angle.add_argument("--heading", type=float, help="single-view heading clockwise from north, any finite float32 degrees (default: 0)")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("--pitch", type=float, default=0, help="vertical angle, any finite float32 degrees (default: 0)")+ street.add_argument("--fov", type=int, default=75, help="horizontal field of view, 5–175 whole degrees (default: 75)")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)@@ -109,7 +109,7 @@ def parser():no_plan_help = "start without the confirmation prompt"planning.add_argument("--no-plan", action="store_true", help=no_plan_help)area.add_argument("--step", type=float, help="target Street View spacing in meters (default: 30)")- area.add_argument("--fov", type=float, help="horizontal field of view (default: 75)")+ area.add_argument("--fov", type=int, help="horizontal field of view, 5–175 whole degrees (default: 75)")area.add_argument("--depth", choices=("main", "roads", "all"), help="road/path selection (default: roads)")area.add_argument("--image-format", choices=("jpg", "png"))area.add_argument("--satellite-zoom", type=int, help="satellite zoom, 1–21 (default: 18)")diff --git a/src/assets/index.html b/src/assets/index.htmlindex 0d2ac1d..5e59391 100644--- a/src/assets/index.html+++ b/src/assets/index.html@@ -113,7 +113,7 @@<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="0" step="any" required></label>- <label>Field of view (°)<input name="fov" type="number" min="20" max="120" step="any" required></label>+ <label>Field of view (°)<input name="fov" type="number" min="5" max="175" step="1" required></label></div></div></fieldset>diff --git a/src/capture.py b/src/capture.pyindex cce020b..54dc80a 100644--- a/src/capture.py+++ b/src/capture.py@@ -69,16 +69,15 @@ def settings(values=None):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.")+ options["fov"] = streetview.validate_fov(options["fov"])for key, low, high in (- ("fov", 20, 120),("satellite_zoom", 1, 21), ("terrain_zoom", 1, 14),):value = options[key]if (type(value) not in (int, float) or not math.isfinite(value)- or not low <= value <= high or (key.endswith("zoom") and int(value) != value)):- raise ValueError(f"{key}: use {'a whole number' if key.endswith('zoom') else 'a number'} from {low} to {high}.")- if key.endswith("zoom"):- options[key] = int(value)+ or not low <= value <= high or int(value) != value):+ raise ValueError(f"{key}: use a whole number from {low} to {high}.")+ options[key] = int(value)if options["depth"] not in ("main", "roads", "all"):raise ValueError("Choose main, roads, or all for depth.")if options["image_format"] not in ("jpg", "png"):diff --git a/src/quick.py b/src/quick.pyindex 1297006..ce11ae0 100644--- a/src/quick.py+++ b/src/quick.py@@ -36,9 +36,9 @@ def street_photos(client, output, progress, *, at=None, place=None, pano_id=Nonestreet=None, match=None, endpoint=places.GEOCODER, route=None,reverse=False, stops=10, view="forward", heading=0, look_at=None,pitch=0, fov=75, radius=50, image_format="jpg"):- places.number(heading, "heading", 0, 360)- places.number(pitch, "pitch", -90, 90)- places.number(fov, "fov", 20, 120)+ streetview.validate_angle(heading, "heading")+ streetview.validate_angle(pitch, "pitch")+ fov = streetview.validate_fov(fov)places.positive(radius, "radius")if type(stops) is not int or stops < 1:raise ValueError("stops must be a positive whole number.")@@ -90,7 +90,7 @@ def street_photos(client, output, progress, *, at=None, place=None, pano_id=Noneif "lat" in sample and distance(actual, (sample["lat"], sample["lon"])) > 1:raise MissingImagery("Panorama position changed; retry with --refresh.")for direction in directions if street else (None,):- angle = (sample["heading"] + offsets[direction]) % 360 if street else heading % 360+ angle = (sample["heading"] + offsets[direction]) % 360 if street else headingif look_at is not None:angle = bearing(actual, look_at)address = streetview.image_url(sample["pano_id"], angle, fov, pitch)diff --git a/src/streetview.py b/src/streetview.pyindex 4edc4c2..0b1ec84 100644--- a/src/streetview.py+++ b/src/streetview.py@@ -91,6 +91,21 @@ def metadata_url(pano_id):)+def validate_angle(value, name):+ # Google's pitch and yaw fields use protobuf TYPE_FLOAT.+ if (type(value) not in (int, float) or not math.isfinite(value)+ or abs(value) > float.fromhex("0x1.fffffep+127")):+ raise ValueError(f"{name}: use a finite 32-bit float in degrees.")+ return value+++def validate_fov(value):+ if (type(value) not in (int, float) or not math.isfinite(value)+ or not 5 <= value <= 175 or int(value) != value):+ raise ValueError("fov: use a whole number from 5 to 175.")+ return int(value)++def image_url(pano_id, heading, fov, pitch=0):return url("https://streetviewpixels-pa.googleapis.com/v1/thumbnail",@@ -98,9 +113,9 @@ def image_url(pano_id, heading, fov, pitch=0):cb_client="maps_sv.tactile",w=1024,h=576,- yaw=heading,- pitch=pitch,- thumbfov=fov,+ yaw=validate_angle(heading, "heading"),+ pitch=validate_angle(pitch, "pitch"),+ thumbfov=validate_fov(fov),)diff --git a/tests/test_queries.py b/tests/test_queries.pyindex fe69b3d..29b1a0a 100644--- a/tests/test_queries.py+++ b/tests/test_queries.py@@ -110,12 +110,13 @@ class QueryTests(unittest.TestCase):values = parse_qs(urlsplit(address).query)self.assertAlmostEqual(float(values["yaw"][0]), 90, places=3)self.assertEqual(values["pitch"], ["10.0"])+ self.assertEqual(values["thumbfov"], ["175"])return image_bytes((1024, 576), "blue")self.fail(f"Unexpected request: {address}")self.get.side_effect = responsestatus, result = self.invoke("streetview", "--at", "0", "0", "--look-at", "0", "1",- "--pitch", "10", "-o", str(self.directory))+ "--pitch", "10", "--fov", "175", "-o", str(self.directory))self.assertEqual(status, 0)photo = result["photos"][0]self.assertEqual(photo["pano_id"], "panorama_0001")@@ -195,6 +196,9 @@ class QueryTests(unittest.TestCase):["streetview", "--street", "Test", "--stops", "0"],["streetview", "--at", "0", "0", "--radius", "0"],["streetview", "--at", "0", "0", "--radius", "inf"],+ ["streetview", "--at", "0", "0", "--pitch", "nan"],+ ["streetview", "--at", "0", "0", "--heading", "inf"],+ ["streetview", "--at", "0", "0", "--pitch", "1e39"],["satellite", "--at", "0", "0", "--size", "0"],["satellite", "--at", "0", "0", "--size", "nan"],["satellite", "--tile", "19/1"],@@ -209,6 +213,23 @@ class QueryTests(unittest.TestCase):self.assertEqual(result["error"]["code"], "invalid_arguments")self.get.assert_not_called()+ def test_streetview_passes_extended_angles_through(self):+ def response(address, **kwargs):+ if "/photometa/v1" in address:+ return metadata()+ values = parse_qs(urlsplit(address).query)+ self.assertEqual(values["yaw"], ["-720.5"])+ self.assertEqual(values["pitch"], ["100.25"])+ return image_bytes((1024, 576), "blue")++ self.get.side_effect = response+ status, result = self.invoke("streetview", "--pano-id", "panorama_0001",+ "--heading", "-720.5", "--pitch", "100.25",+ "-o", str(self.directory))+ self.assertEqual(status, 0, result)+ self.assertEqual(result["photos"][0]["heading"], -720.5)+ self.assertEqual(result["photos"][0]["pitch"], 100.25)+class RouteTests(unittest.TestCase):def test_branching_streets_return_choices_and_crossings_do_not_connect(self):diff --git a/tests/test_streetview.py b/tests/test_streetview.pyindex 7332aa4..ab6e705 100644--- a/tests/test_streetview.py+++ b/tests/test_streetview.py@@ -1,12 +1,27 @@import jsonimport unittest+from urllib.parse import parse_qs, urlsplit-from src import geo, streetview+from src import capture, geo, streetviewfrom src.common import MissingImageryfrom tests.fixtures import metadataclass StreetViewTests(unittest.TestCase):+ def test_fov_bounds_and_integer_serialization(self):+ for value in (5, 75.0, 175):+ with self.subTest(value=value):+ options = capture.settings(dict(fov=value))+ self.assertIs(type(options["fov"]), int)+ query = parse_qs(urlsplit(streetview.image_url("panorama_0001", 0, value)).query)+ self.assertEqual(query["thumbfov"], [str(int(value))])+ for value in (4, 176, 82.5, float("nan"), float("inf"), True, "75"):+ with self.subTest(value=value):+ with self.assertRaisesRegex(ValueError, "fov"):+ capture.settings(dict(fov=value))+ with self.assertRaisesRegex(ValueError, "fov"):+ streetview.image_url("panorama_0001", 0, value)+def test_coverage_distinguishes_empty_tiles_from_unreadable_responses(self):row = [[[2, "panorama_0001"], None, [[None, None, 12, 34]]]]data = b")]}'\n" + json.dumps([None, [None, [row, [[1]], [[[3, "user_photo"]]]]]]).encode()