GPU Compute
Run a custom WGSL function per feature on the GPU with ak.Compute.gpgpu() and map the computed attribute.
Python Script
python
from __future__ import annotations
import json
from pathlib import Path
import pyautark as ak
DATA_DIR = Path(__file__).resolve().parents[1] / "data"
with (DATA_DIR / "mnt_neighs.geojson").open(encoding="utf-8") as f:
neighborhoods_data = json.load(f)
neighborhoods = ak.GeoJSON(
"neighborhoods",
values=neighborhoods_data,
layer_type="polygons",
)
compactness = ak.Compute.gpgpu(
neighborhoods,
output="computed_neighborhoods",
layer_type="polygons",
variable_mapping={
"x": "properties.shape_area",
"y": "properties.shape_leng",
},
result_field="result",
wgsl_body="return (4.0 * 3.1415927 * x) / (y * y);",
)
spec = ak.Spec(
metadata=ak.Metadata(title="Compute Function - Neighborhood Compactness"),
data=[neighborhoods],
transforms=[compactness],
views=[
ak.Map(
layers=[
ak.Layer(
"computed_neighborhoods",
id="neighborhoods_layer",
encoding=ak.Encoding(
color=ak.field(
"properties.compute.result",
ak.Scale(type="quantile", scheme="spectral"),
)
),
)
]
)
],
)
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.