From 26cc15f9d4b5acb3f1f8e809838f1a0091b53e6e Mon Sep 17 00:00:00 2001 From: amtiYo Date: Mon, 23 Nov 2026 17:05:57 +0100 Subject: [PATCH] feat(curation): places of the day from Panoramax, for Ukraine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mapillary lists Ukrainian frames in its tiles but serves no picture for any of them, so a Mapillary harvest can never yield a place in Ukraine (#45). harvest_px.py harvests from Panoramax instead and writes the same batch layout, so screen.py, maply-places and faces.py read it unchanged. It keeps 360° pictures from 2018 on with a known direction, in the parts of a country pool.allowed() lets in; a plan entry may name the picture a reviewer picked. maply-places takes a Panoramax picture's direction from the batch as its heading, since there is no Mapillary to ask, and links its Panoramax page. The owner let Kharkiv itself into the Ukrainian zone; the region around it, which runs to the front and the border, stays out. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 +++ cmd/maply-places/main.go | 11 ++- docs/design.md | 4 +- scripts/curation/harvest_px.py | 119 +++++++++++++++++++++++++++++++++ scripts/curation/pool.py | 4 ++ 5 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 scripts/curation/harvest_px.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e1a1b..60216fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,15 @@ See [`docs/versioning.md`](docs/versioning.md) for what the numbers mean and ## Unreleased +### Added + +- Places of the day can come from Panoramax: `scripts/curation/harvest_px.py` + harvests a batch in the same layout as `harvest.py`, and `maply-places` + takes a Panoramax picture's direction as its heading and links its page. + Mapillary serves no image in Ukraine, so the first Ukrainian places of the + day, Kyiv and Kharkiv, come this way. Kharkiv itself is now inside the + curation's Ukrainian zone. + ## v0.1.0-beta.1 - 2026-11-23 For the operator: this release applies migrations 031 and 032. Pull the image diff --git a/cmd/maply-places/main.go b/cmd/maply-places/main.go index dfd95e8..b899bf7 100644 --- a/cmd/maply-places/main.go +++ b/cmd/maply-places/main.go @@ -69,6 +69,10 @@ type candidate struct { IsPano bool `json:"is_pano"` Author string `json:"author"` License string `json:"license"` + // Heading is the direction the frame's centre faces, as the harvest + // found it. Mapillary's is asked again (see heading); a Panoramax + // batch's comes from the picture's view:azimuth and is used as is. + Heading *float64 `json:"heading"` } type reviews struct { @@ -289,6 +293,8 @@ func (p *preparer) prepare(batchDir, ref string, c candidate, yaw *float64) (*pl if pl.heading, err = p.heading(c, cacheBase+".heading.json"); err != nil { return nil, err } + } else { + pl.heading = c.Heading } if c.IsPano { if pl.thumbYaw, err = p.thumbYaw(pl.key, cacheBase+".v1.yaw", yaw); err != nil { @@ -557,8 +563,11 @@ func (pl *place) insert() string { kind = "panorama" } sourceURL := "" - if pl.c.Source == "mapillary" { + switch pl.c.Source { + case "mapillary": sourceURL = "https://www.mapillary.com/app/?pKey=" + pl.c.SourceID + case "panoramax": + sourceURL = "https://api.panoramax.xyz/#focus=pic&pic=" + pl.c.SourceID } heading := "NULL" if pl.heading != nil { diff --git a/docs/design.md b/docs/design.md index 99b3ae1..a408582 100644 --- a/docs/design.md +++ b/docs/design.md @@ -434,7 +434,9 @@ The hood and handlebar at the bottom of a frame are no reason to drop a place. F Difficulty by weekday: Monday is easy (a recognizable city), Friday is hard (remote areas), weekends are for "Where am I?" and themed rounds. -Russia, Ukraine and Belarus are in the game (decision of 22 October 2026). Excluded: the front line, Crimea and occupied territories, military sites, and frames with recognizable faces. Mapillary blurs faces and plates itself. Whether Panoramax does so has not been checked. +Russia, Ukraine and Belarus are in the game (decision of 22 October 2026). Excluded: the front line, Crimea and occupied territories, military sites, and frames with recognizable faces. Mapillary blurs faces and plates itself, and so does Panoramax. + +Mapillary serves no image for any frame in Ukraine: its tiles list the frames, but the API gives none of them a picture (#45). Ukraine comes from Panoramax through `harvest_px.py`, which writes the same batch layout as `harvest.py`, with the picture's direction as the heading. Its 360° coverage there is thin: in November 2026 a scan of the country found one sequence in Kyiv, one picture in Brovary (at night) and one in Kharkiv. Kharkiv itself is in; the region around it is not. ### The free pool diff --git a/scripts/curation/harvest_px.py b/scripts/curation/harvest_px.py new file mode 100644 index 0000000..56d48fc --- /dev/null +++ b/scripts/curation/harvest_px.py @@ -0,0 +1,119 @@ +"""Collect candidate places of the day from Panoramax. + +Mapillary serves no image for any frame in Ukraine (see issue #45), so +Ukraine comes from Panoramax. This is harvest.py for Panoramax: the same +batch layout, so screen.py, choose.py, maply-places and faces.py read it as +they read a Mapillary batch. + +For every region of the plan it asks Panoramax's search for the pictures +within the region's radius and keeps one: a 360° equirectangular panorama +captured in 2018 or later, with a known direction (view:azimuth, which +becomes the game's compass heading), in a part of a country pool.allowed() +lets in. Among those it takes the largest original, then the newest. + + python -I harvest_px.py + +plan.json is a list of {"region": "Kyiv, UA", "lat": 50.41, "lon": 30.52, +"km": 3, "kind": "city"}; kind is the scene (city, town or nature). An +"id" names the picture a reviewer picked from the region's sequence; it +still has to pass the same checks. + +Output: /candidates.json and /full/NNN.jpg, the panorama scaled to +4096 px wide, the width maply-places -sharpen gives Mapillary panoramas. +A region with nothing usable says why. +""" +import io, json, math, os, sys, time, urllib.request +from PIL import Image +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +os.environ.setdefault("MAPILLARY_TOKEN", "") # pool.py reads it at import; nothing here calls Mapillary +import pool + +API = "https://api.panoramax.xyz/api/search" +UA = pool.UA +MIN_DATE = "2018" +WIDTH = 4096 + + +def get(url, timeout=120): + for attempt in range(3): + try: + req = urllib.request.Request(url, headers={"User-Agent": UA}) + return urllib.request.urlopen(req, timeout=timeout).read() + except Exception: + if attempt == 2: + raise + time.sleep(2 * (attempt + 1)) + + +def usable(f, countries): + """The reason a picture is passed over, or "" when it can be a candidate.""" + p = f["properties"] + if (p.get("pers:interior_orientation") or {}).get("field_of_view") != 360: + return "not a 360° panorama" + if p.get("view:azimuth") is None: + return "no direction" + if (p.get("datetime") or "") < MIN_DATE: + return "before 2018" + lon, lat = f["geometry"]["coordinates"] + iso = pool.country_of(countries, lat, lon) + if not iso or not pool.allowed(iso, lat, lon): + return "in a part left out" + if "hd" not in f.get("assets", {}): + return "no original" + return "" + + +def main(): + out, plan_path = sys.argv[1], sys.argv[2] + plan = json.load(open(plan_path)) + countries = pool.load_countries() + os.makedirs(f"{out}/full", exist_ok=True) + cands = [] + for r in plan: + d = r.get("km", 3) / 111 + dl = d / math.cos(math.radians(r["lat"])) + bbox = f"{r['lon'] - dl},{r['lat'] - d},{r['lon'] + dl},{r['lat'] + d}" + feats = json.loads(get(f"{API}?bbox={bbox}&limit=500")).get("features", []) + why = {} + ok = [] + for f in feats: + reason = usable(f, countries) + if reason: + why[reason] = why.get(reason, 0) + 1 + else: + ok.append(f) + if not ok: + print(f"{r['region']}: nothing of {len(feats)} pictures: {why}", file=sys.stderr) + continue + ok.sort(key=lambda f: (f["properties"].get("original_file:size") or 0, f["properties"]["datetime"]), reverse=True) + if r.get("id"): + ok = [f for f in ok if f["id"] == r["id"]] + if not ok: + print(f"{r['region']}: picture {r['id']} is not usable or not within {r.get('km', 3)} km", file=sys.stderr) + continue + f = ok[0] + p = f["properties"] + n = len(cands) + 1 + im = Image.open(io.BytesIO(get(f["assets"]["hd"]["href"]))).convert("RGB") + if im.width > WIDTH: + im = im.resize((WIDTH, WIDTH // 2), Image.LANCZOS) + im.save(f"{out}/full/{n:03d}.jpg", quality=92) + lon, lat = f["geometry"]["coordinates"] + producer = p.get("geovisio:producer") or next( + (x.get("name") for x in f.get("providers", []) if "producer" in x.get("roles", [])), "") + cands.append({ + "n": n, "region": r["region"], "kind": r.get("kind", "city"), + "country": pool.country_of(countries, lat, lon), + "source": "panoramax", "source_id": f["id"], + "lat": lat, "lon": lon, "is_pano": True, + "captured_at": int(time.mktime(time.strptime(p["datetime"][:19], "%Y-%m-%dT%H:%M:%S")) * 1000), + "heading": float(p["view:azimuth"]), + "author": producer, "license": p.get("license") or "CC-BY-SA-4.0", + }) + print(f"{n:03d} {r['region']}: {len(ok)} of {len(feats)} usable, took {f['id']} ({p['datetime'][:10]}, {im.width} px)", file=sys.stderr) + json.dump(cands, open(f"{out}/candidates.json", "w"), ensure_ascii=False, indent=1) + print(f"candidates: {len(cands)} of {len(plan)} regions", file=sys.stderr) + + +if __name__ == "__main__": + main() diff --git a/scripts/curation/pool.py b/scripts/curation/pool.py index b5e5ca8..ad4d718 100644 --- a/scripts/curation/pool.py +++ b/scripts/curation/pool.py @@ -76,6 +76,10 @@ def allowed(iso, lat, lon): near them, disputed land, and far islands of another continent.""" if iso == "UA": # West and centre only: no front line, no occupied land, no Crimea. + # Kharkiv itself is in (owner decision, 2026-11-23): the city, not + # the region around it, which runs up to the front and the border. + if abs(lat - 49.99) < 0.12 and abs(lon - 36.23) < 0.2: + return True return (lon < 32.5 and lat > 47.0) or (lon < 31.0 and lat > 45.6) if iso == "RU": if lon < 40 and lat < 54: # the regions along the Ukrainian border