Skip to content

Sky Exposure Render Pass ​

Use ak.Compute.render() to measure the share of sky visible from each road segment around 3D buildings.

Python Script ​

python
"""Render analysis — the share of sky each road segment sees, from GPU renders of the buildings around it
(gallery: compute-render-osm-sky-exposure).

Each road is a viewpoint. `Compute.render` draws the buildings from it in 8 directions and counts the pixels of each
class; the background class is the sky. The result is a copy of the roads in a new table, `sky`.
"""
from __future__ import annotations

from pathlib import Path

import pyautark as ak

DATA_DIR = Path(__file__).resolve().parents[1] / "data"

osm = ak.OSM(
    "mnt",
    bbox=(-74.015, 40.703, -74.003, 40.713),
    layers=["roads", "buildings"],
    source="pbf",
    pbf_file_url=(DATA_DIR / "lower_mnt.osm.pbf").as_uri(),
)

sky = ak.Compute.render(
    output="sky",
    layers=[{"id": "buildings", "source": "mnt_buildings", "type": "buildings"}],
    viewpoints={"source": "mnt_roads", "sampling": {"directions": 8}},
    aggregation={"type": "classes", "includeBackground": True},
    tile_size=64,
)

spec = ak.Spec(
    metadata=ak.Metadata(title="Sky Exposure"),
    data=[osm],
    transforms=[sky],
    views=[
        ak.Map(
            camera=ak.Camera(zoom=13, pitch=45),
            layers=[
                ak.Layer("mnt_buildings", id="buildings").style(color="#bbbbbb", opacity=0.35),
                ak.Layer("sky", id="sky exposure")
                .encode(color=ak.field("compute.render.classes.background", ak.Scale(scheme="blues")))
                .style(width=14),
            ],
        )
    ],
)

if __name__ == "__main__":
    spec.window(height="760px")

Run in Jupyter or standalone HTML

Replace spec.window(...) with spec.widget() inside a Jupyter notebook (requires pip install "pyautark[widget]") or spec.save_html("out.html") to export a standalone web page.

This example comes from the pyautark repository.

Released under the MIT License.