Skip to content

examples: London route notebook, roads notebook and examples README - #61

Merged
petercorke merged 9 commits into
mainfrom
docs/notebooks
Oct 12, 2026
Merged

petercorke merged 9 commits into
mainfrom
docs/notebooks

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Two Jupyter notebooks and the examples README.

examples/london.ipynb, with osm.py and london.json

A real-world example: the road network of central London from OpenStreetMap as a directed, embedded DGraph, and the shortest drive between Buckingham Palace and Tower Bridge, there and back (the routes differ because of one-way streets). It shows

  • turning latitude and longitude into metres with a transverse Mercator projection (local_projection, checked against PROJ to 3 nm over the area; the simple scaling it replaces is out by up to 9 m),
  • which OSM nodes become vertices, with a table of how many roads meet at each (only 37% are junctions in the everyday sense),
  • an Edge subclass that carries the street name and the shape of the road, and parallel edges for roads that join the same vertices,
  • the strongly connected part of a directed graph (forward ∩ backward reachability from a central vertex),
  • why plot() is the wrong tool for a map, against the saved edge shapes, in a region pruned from the graph,
  • closest, A* and breadth-first search, there and back.

osm.py has the OpenStreetMap-specific parts (the Overpass request and its required User-Agent, which ways a car may use and in which direction, the cache) and needs only the standard library and numpy. london.json is the area saved from OpenStreetMap, one way or node per line, ways first, so a re-fetch is a few changed lines in a diff. The notebook reads it, so it runs offline.

Map data © OpenStreetMap contributors, Open Database License; the notebook, osm.py and the README say so, and the file's own source entry.

examples/roads.ipynb

The Queensland example as a notebook, with its comments as markdown cells.

examples/README.md

Describes both examples and the benchmark.

No source changes. The notebooks were executed and their stored outputs match a fresh run.

🤖 Generated with Claude Code

petercorke and others added 8 commits October 13, 2026 09:10
The roads.py example as a notebook, with its comments as markdown cells and
its output (verbose search, path, plot) included.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A notebook that builds a DGraph from an OpenStreetMap extract of central
London (junctions as vertices, one edge per driving direction, costs along
the shape of the road), keeps the strongly connected part, and plans routes
between landmarks with A*, there and back.

osm.py holds the OpenStreetMap-specific parts (the Overpass request, which
ways a car may use, their direction, a JSON cache); london.json is the
cached extract, (c) OpenStreetMap contributors, ODbL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
local_projection(lat0, lon0) returns project(lat, lon): the transverse
Mercator on the WGS84 ellipsoid centred on the map, by Krueger's series to
fourth order.  It agrees with PROJ to 3 nm over the box.  The equirectangular
scaling that it replaces was out by up to 9 m, and the routes by 15 m.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
osm.py writes the cache with one way or node per line, ways before nodes,
so a re-fetch is a few changed lines in a diff and a reader sees the ways
first.  london.json is the area fetched on 2026-10-13, in that layout.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Which nodes become vertices, with the arms table; the ways by direction in
an ansitable table; the shape of an edge; plot() against the edge shapes,
pruned to a region; the nodes called vertices throughout.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 43 complexity · 0 duplication

Metric Results
Complexity 43
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 1cc79f3 into main Oct 12, 2026
12 checks passed
@petercorke
petercorke deleted the docs/notebooks branch October 12, 2026 23:15
@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.18%. Comparing base (f9555d8) to head (122b9a9).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #61   +/-   ##
=======================================
  Coverage   97.18%   97.18%           
=======================================
  Files           3        3           
  Lines        1562     1562           
=======================================
  Hits         1518     1518           
  Misses         44       44           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant