Temporal Events
Collect event timestamps via a spatial join and explore them over time with ak.EventSeries linked to the map.
Python Script
python
"""Events over time — noise complaints within 200 m of each road, as a line chart of events per day (gallery: temporal-events-click).
The join collects the complaint dates of each road; the line chart buckets them by day.
"""
from __future__ import annotations
from pathlib import Path
import pyautark as ak
DATA_DIR = Path(__file__).resolve().parents[1] / "data"
roads = ak.GeoJSON("roads", url=(DATA_DIR / "mnt_roads.geojson").as_uri(), coordinate_format="EPSG:4326")
noise = ak.CSV(
"noise",
url=(DATA_DIR / "noise_manhattan_clean.csv").as_uri(),
geometry=ak.latlng("latitude", "longitude", coordinate_format="EPSG:4326"),
)
brush = ak.interval("days")
spec = ak.Spec(
metadata=ak.Metadata(title="Temporal Events"),
data=[roads, noise],
transforms=[
ak.SpatialJoin(root=roads, join=noise, near=ak.Near(200), group_by=[ak.count("key"), ak.collect("date")]),
],
views=[
ak.Map(
style="light",
layers=[
ak.Layer(roads, id="roads")
.encode(color=ak.field("sjoin.count.noise", ak.Scale(type="quantile", scheme="reds")))
.style(width=14)
],
),
ak.EventSeries(
roads,
"sjoin.collect.noise",
timestamp="date",
resolution="day",
reducer="count",
selection=brush,
title="Noise events per day",
width=760,
margins={"left": 60, "right": 20, "top": 50, "bottom": 140},
),
],
links=[ak.Link(brush, target="roads")],
layout=ak.Layout(type="vertical"),
)
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.