City3D-MultiGen / scripts /build_dataset.py
e32's picture
Initial release: reconstruction pipeline + metadata
e95f494 verified
Raw
History Blame Contribute Delete
3.76 kB
#!/usr/bin/env python3
"""
City3D-MultiGen — pipeline runner.
This runs the reconstruction stages for one city in order. It does NOT host any
data: it drives the same scripts documented in the README to rebuild the aligned
multi-modal tiles locally from (1) source 3D data you downloaded yourself and
(2) live Google Maps Static API calls made under your own key.
Manual prerequisites (NOT automated here — see README.md):
1. Download the source 3D data:
- Melbourne: City of Melbourne 3D Point Cloud 2018 (LAS).
- HoliCity (London): FBX meshes, then sample a point cloud to LAS with
CloudCompare, and georeference it with holicity/convert_coord.py and
holicity/add_coord_head.py.
2. Install PDAL (conda install -c conda-forge pdal) — the tiler calls it.
3. Export your Google credentials:
GOOGLE_MAPS_API_KEY, GOOGLE_MAPS_URL_SIGNING_SECRET, GOOGLE_MAPS_STYLE_MAP_ID
4. Set the input/output paths at the top of each stage script (the tilers read
their LAS input dir and output dir from module-level constants).
Stages run by this script (per city):
A. <city>/export_las_blocks_noKML.py -> tiles + per-tile DSM + BEV
B. <city>/Obtain_corresponding_map_signed.py -> satellite + 6 semantic masks
C. make_splits.py -> train/val/test tile lists
Usage:
python scripts/build_dataset.py --city melbourne
python scripts/build_dataset.py --city holicity --data_root ./output --skip_splits
"""
import argparse
import os
import shutil
import subprocess
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
ENV_VARS = ("GOOGLE_MAPS_API_KEY", "GOOGLE_MAPS_URL_SIGNING_SECRET", "GOOGLE_MAPS_STYLE_MAP_ID")
def check_prereqs():
missing = [k for k in ENV_VARS if not os.environ.get(k)]
if missing:
sys.exit(f"[error] Missing environment variables: {', '.join(missing)}. See README.md.")
if shutil.which("pdal") is None:
sys.exit("[error] PDAL not found on PATH. Install it: conda install -c conda-forge pdal")
def run(script_rel, *cli_args):
path = os.path.join(HERE, script_rel)
cmd = [sys.executable, path, *cli_args]
print(f"\n>>> {' '.join(cmd)}", flush=True)
subprocess.run(cmd, check=True)
def main():
ap = argparse.ArgumentParser(description="Run the City3D-MultiGen reconstruction stages.")
ap.add_argument("--city", choices=["melbourne", "holicity"], required=True)
ap.add_argument("--data_root", default="./output",
help="Directory holding the assembled tiles (used for the split step).")
ap.add_argument("--skip_splits", action="store_true", help="Do not run make_splits.py.")
args = ap.parse_args()
check_prereqs()
print(f"[info] Running the {args.city} pipeline. Ensure the manual prerequisites in this "
f"script's docstring are done and paths are configured at the top of each stage script.")
# Stage A — tile the (already downloaded / sampled) source point clouds.
run(f"{args.city}/export_las_blocks_noKML.py")
# Stage B — fetch satellite + semantic maps for the tiles produced in Stage A.
if args.city == "melbourne":
run("melbourne/Obtain_corresponding_map_signed.py", "--folder", args.data_root)
else:
run("holicity/Obtain_corresponding_map_signed.py")
# Stage C — generate the train/val/test split lists.
if not args.skip_splits:
run("make_splits.py", "--data_root", args.data_root,
"--out_dir", os.path.join(HERE, "..", "metadata", "splits"))
print("\n[done] Reminder: Google Maps imagery is subject to the Google Maps Platform ToS; "
"do not redistribute the fetched *_sat.png / *_map.png / *_<Class>.png files.")
if __name__ == "__main__":
main()