Skip to content

UrbanAccessAnalyzer.isochrones

Multi-tier accessibility isochrones on top of the Polars routing core.

An isochrone here is not just "reachable within N meters" — points of interest (POIs) can have different access scores (e.g. a large well-staffed school scores higher than a one-room schoolhouse), and each score tier reaches a different distance before its contribution to accessibility drops off. This module computes, for every street node and every point along every edge, the best access score reachable within that tier's distance budget from any POI, using :mod:UrbanAccessAnalyzer.routing (scipy CSR Dijkstra) as the distance engine and Polars for all tabular orchestration.

Methodology:

  1. A distance matrix maps (poi_score tier, distance threshold) -> access_score. :func:default_distance_matrix builds a simple diagonal matrix; callers may also supply their own (e.g. calibrated with :mod:UrbanAccessAnalyzer.scoring).
  2. :func:distance_matrix_to_processing_order collapses that matrix to one row per distinct access_score, carrying the maximum distance at which each POI-score tier still earns that access_score, and ranks access_score values from best (rank 0) to worst.
  3. For each row, :func:compute_node_access runs routing.multi_source_distances from the POIs in that tier, at that tier's radius, and keeps, per node, the largest "remaining distance" (radius - shortest_dist) seen for that access_score across all rows that share it. A node's final access score is the best (lowest rank) tier for which it has positive remaining distance — ties broken by whichever tier has more remaining distance, matching the original "keep the larger remaining distance" reconciliation rule.
  4. Edges get split at the exact point where the best-reaching tier gives out and a worse tier picks up: for each tier from best to worst, the portion of an edge within remaining_dist of either endpoint that is not already claimed by a better tier is assigned to that tier and its sub-segment geometry cut with shapely.ops.substring (this replaces the old WKT-string / pandas __exact_isochrones pass in graph_processing.py with a vectorized NumPy pass over the small n_edges x n_tiers matrix).
  5. :func:buffers computes the pure Euclidean (no street network) equivalent for cases where a network isn't available or wanted: nested tier buffers around POIs with shapely.difference used to keep only the outermost ring not already covered by a better tier.

This package is scoped to general OSM-derived accessibility, so there is no transit/GTFS-specific code here — a GTFS feed's stops are just another POI input with precomputed access scores.

default_distance_matrix(poi, distance_steps, poi_score_col='poi_score', score_bins=None)

Build a diagonal poi-score x distance access-score matrix.

Higher poi_score and shorter distance both push the resulting access_score towards 1.0; poi_score == 0 always yields access_score 0.

Parameters:

Name Type Description Default
poi DataFrame

DataFrame with a poi_score_col column of POI quality/score values in some numeric range.

required
distance_steps Sequence[float]

Distance thresholds (e.g. [200, 400, 800, 1200] meters), best (shortest) first or any order — sorted internally.

required
poi_score_col str

Column in poi holding the per-POI score.

'poi_score'
score_bins Optional[int]

Optional number of quantile buckets used to collapse how many distinct rank positions continuous poi_score values are spread across, before computing each row's access score. Defaults to None, which preserves the exact current behavior: each distinct poi_score gets its own rank and thus (generally) its own access-score tier. When POI scores are continuous floats (e.g. a computed score in [0, 1]), this can produce dozens of near-duplicate tiers -- each requiring a full network search in :func:compute_node_access / :func:exact_edge_access -- for little accuracy benefit, since nearly-identical scores yield nearly-identical access outcomes anyway. Setting score_bins (20-50 is a reasonable range) quantile-buckets the distinct nonzero scores into at most that many rank groups (scores in the same bucket share one rank and therefore one access-score value per distance step, so they collapse into the same downstream tier), which can turn a step that used to build ~90 tiers into ~10-20. The poi_score column of the returned matrix still contains the original, unbucketed score values -- so it still joins correctly against a points/poi table with continuous scores -- only the value assigned to nearby scores is quantized, at the cost of a small approximation error in the resulting access scores for POIs whose scores fall in the same bucket. This parameter is opt-in and score_bins=None leaves today's behavior bit-for-bit unchanged.

Measured tradeoff (real Cambridge, MA street network + GTFS stops, 866 distinct continuous stop_score values, distance steps (400, 800, 1200), error measured on the [0, 1] per-node access_score scale vs. the score_bins=None baseline): score_bins=50 -> mean abs error 0.0045, max error 0.010, ~2.9x speedup; score_bins=100 -> mean abs error 0.0028, max error 0.005, ~2.6x speedup. See transitlos.level_of_service.compute_level_of_service's docstring for the full table across more bin counts -- that function defaults to score_bins=50 for transitLOS's public pipeline (this library-level default stays None).

Note: prior to a fix, the bucket-rank normalization here re-ranked binned scores down to small contiguous integers while the access-score formula's denominator (max_idx) stayed at the original (unbucketed) scale -- this made every binned access_score collapse toward the same value regardless of bin count, with errors of 0.3-0.9 on realistic data instead of the small quantization error described above. Bucket ranks now keep their original-scale mean rank position instead of being re-ranked to contiguous small integers.

None

Returns:

Name Type Description
distance_matrix DataFrame

one row per distinct poi_score (excluding 0), one column per distance step plus a poi_score column, values are access scores in [0, 1].

access_score_values list[float]

sorted distinct access score values found in the matrix, best first.

distance_matrix_to_processing_order(distance_matrix, access_score_values=None)

Collapse a distance matrix into one row per distinct access_score.

Parameters:

Name Type Description Default
distance_matrix Union[DataFrame, Sequence[float]]

Either a Polars DataFrame (as returned by :func:default_distance_matrix, with a poi_score column and one column per distance) or a flat sequence of distances (in which case every POI is treated as a single undifferentiated tier, poi_score = 1, one access_score per distance).

required
access_score_values Optional[Sequence]

Explicit access-score labels. When distance_matrix is a plain list of distances, must be the same length and positionally aligned (access_score_values[i] is awarded within distance_matrix[i]); rank is then assigned by first-appearance order in access_score_values (index 0 = best/rank 0). When distance_matrix is a DataFrame, used only to control rank order for otherwise-inferred access_score values (must align with the matrix's own distinct values).

None

Returns:

Type Description
DataFrame

Polars DataFrame with columns poi_score (list[f64]),

DataFrame

distance (f64), access_score, rank (i64, 0=best),

DataFrame

sorted best-rank-first.

compute_node_access(nodes, edges, points, process_order, poi_score_col=None, undirected=True, verbose=True)

Compute the best reachable access score for every graph node.

Parameters:

Name Type Description Default
nodes DataFrame

Node table (node_id at minimum).

required
edges DataFrame

Directed edge table (u, v, length_m).

required
points DataFrame

POI table with a node_id column (already snapped onto the graph, e.g. via :func:UrbanAccessAnalyzer.graph_ops.snap_points) and, if poi_score_col is given, a matching score column.

required
process_order DataFrame

Output of :func:distance_matrix_to_processing_order.

required
poi_score_col Optional[str]

Column in points with per-POI score values matching the poi_score groups in process_order. If None, every point is treated as tier 1.0.

None
undirected bool

Whether to ignore edge direction during the search.

True
verbose bool

Print progress per tier.

True
Note

The sparse CSR adjacency matrix (:func:UrbanAccessAnalyzer.routing.build_csr) is built once, before the per-tier loop, and reused for every tier's Dijkstra call -- the graph topology never changes between tiers, only the source-node set and radius do. This is a pure performance optimization with no effect on results.

Returns:

Name Type Description
node_access DataFrame

columns node_id, access_score, rank, remaining_dist — one row per node with the best (lowest rank) access score it can reach and how much distance budget is left at that tier's radius. access_score is a "higher is better" score, so a node with no row here has no computed access at all; if you left-join this against a full node table for a dense result, fill those nulls with 0 (the worst score), not left as null -- mirroring :func:UrbanAccessAnalyzer.scoring.score_by_values's convention. remaining_dist, by contrast, is a "lower is better"-style distance quantity and should stay null for unreached nodes rather than being filled with anything.

tier_tables dict[float, DataFrame]

dict mapping each distinct access_score value to a node_id, remaining_dist DataFrame, needed by :func:exact_edge_access to reproduce the same per-tier reach when splitting edges.

compute_node_access_chunked(nodes, edges, points, process_order, crs, poi_score_col=None, undirected=True, verbose=True, chunk_h3_resolution=4, buffer_m=1000.0)

Memory-bounded :func:compute_node_access, chunked by H3 res-N cell.

compute_node_access builds one sparse CSR adjacency matrix for the entire input graph and keeps it (plus every tier's reach table) in memory for the whole run -- fine for an ordinary metro, but this scales with total graph size regardless of how "local" any given isochrone search actually is, and has caused real OOM crashes on oversized AOIs (e.g. Boston's accidentally state-scale AOI, Shanghai's population scale). This function instead partitions the graph into H3 res-N cells (chunk_h3_resolution, coarse by default -- res 4 is ~1,770 km^2 per cell), clips nodes/edges to each cell expanded by buffer_m, and calls the existing, unmodified :func:compute_node_access on just that clipped subgraph -- so the only new logic here is graph partitioning and result merging; the actual Dijkstra/tiering logic is exactly the unchunked code path, just run on smaller inputs, one cell at a time.

Buffer correctness (read before changing the default): the buffer must be at least as large as the longest real search radius any tier in process_order can reach (process_order["distance"].max()), or a stop/POI near a cell's edge will have its isochrone truncated at the chunk boundary instead of reaching its true extent -- a silent correctness bug, not a crash, so this is checked and warned on (not silently allowed) rather than asserted, since a caller intentionally accepting a smaller buffer for a coarser approximation is plausible but should never happen by accident. The default (1000m) matches the project's own initial proposal but is NOT automatically correct for every study -- e.g. CS_transitLOS's StudyParams.walk_distance_steps reaches 2000m, so studies using that config must pass buffer_m >= 2000 explicitly.

A node that falls within one cell's buffer-only zone (not its own core res-N cell) may get computed redundantly by that neighboring cell too; results are merged by keeping, per node_id, the best (lowest rank, then largest remaining_dist) row across every chunk that computed it -- the same "overlap and take the best" reconciliation :func:compute_node_access itself already uses across tiers within one chunk. This makes chunking a pure performance/memory strategy with no effect on results: a node inside a cell's buffer zone will, by construction, also be computed by its own home cell (whose buffer covers the reverse direction), and merging always picks that better-or-equal result -- see tests/test_isochrones_chunked.py for a chunked vs. unchunked equivalence test.

Parameters:

Name Type Description Default
nodes DataFrame

Full node table, projected (node_id, x, y). Each node's lon/lat (needed to assign it to an H3 cell, since H3 always operates in lon/lat) is derived by inverse-projecting x, y back through crs, so no separate lon/lat columns are required even after :func:UrbanAccessAnalyzer.graph_ops.simplify (which does not retain them).

required
edges DataFrame

Full directed edge table, projected, matching nodes.

required
points DataFrame

POI table, see :func:compute_node_access.

required
process_order DataFrame

Output of :func:distance_matrix_to_processing_order.

required
crs str

The projected CRS nodes/edges are in (e.g. as returned by :func:UrbanAccessAnalyzer.graph_ops.project) -- used to reproject each H3 cell's lon/lat boundary into the graph's own CRS for clipping.

required
poi_score_col Optional[str]

See :func:compute_node_access.

None
undirected bool

See :func:compute_node_access.

True
verbose bool

Print a progress bar over chunks (and disables the per-chunk, per-tier progress bar to avoid nested bar spam).

True
chunk_h3_resolution int

H3 resolution defining the chunk grid. Default 4 (~1,770 km^2/cell) -- comfortably larger than any single city's dense core. Must be explicitly chosen per study/city, not hardcoded by a caller.

4
buffer_m float

Buffer distance (meters) added around each cell before clipping. Default 1000m. Must be >= the longest distance in process_order (checked, see above) or results near chunk edges will be truncated/wrong.

1000.0

Returns:

Type Description
DataFrame

Same shape as :func:compute_node_access: ``(node_access,

dict[float, DataFrame]

tier_tables), plus one extra column onnode_access``,

tuple[DataFrame, dict[float, DataFrame]]

h3_chunk_cell -- the res-chunk_h3_resolution H3 cell the

tuple[DataFrame, dict[float, DataFrame]]

node itself (not a buffer neighbor's cell) falls in, for downstream

tuple[DataFrame, dict[float, DataFrame]]

chunk-labeled consumers (e.g. chunked tile generation). Unlike

tuple[DataFrame, dict[float, DataFrame]]

func:compute_node_access, the returned tier_tables are

tuple[DataFrame, dict[float, DataFrame]]

per-chunk-merged-by-best only for nodes; per-tier remaining_dist

tuple[DataFrame, dict[float, DataFrame]]

tables are unioned across chunks with a max-reduction (same rule

tuple[DataFrame, dict[float, DataFrame]]

func:compute_node_access itself uses to merge duplicate node_ids

tuple[DataFrame, dict[float, DataFrame]]

within one tier), so :func:exact_edge_access can still be called

tuple[DataFrame, dict[float, DataFrame]]

against the original, unchunked edges table with this

tuple[DataFrame, dict[float, DataFrame]]

function's tier_tables output.

exact_edge_access_reference(edges, process_order, tier_tables, min_edge_length=0.0, unreached_access_score=0.0)

Split edges at exact tier boundaries and assign an access_score to each piece.

For each tier from best to worst, the portion of every edge within that tier's remaining distance of either endpoint (and not already claimed by a better tier) is cut out with shapely.ops.substring and labeled with that tier's access_score. This reproduces sub-edge isochrone boundary precision without node-level snapping artifacts.

Parameters:

Name Type Description Default
edges DataFrame

Directed edge table (u, v, length_m, geometry_wkb, plus any extra columns, which are copied onto every output piece).

required
process_order DataFrame

Output of :func:distance_matrix_to_processing_order (used for tier ranking, best first).

required
tier_tables dict[float, DataFrame]

Per-tier node_id, remaining_dist tables from :func:compute_node_access.

required
min_edge_length float

Minimum sub-segment length to keep; shorter fragments are dropped (their access_score effectively inherited by the adjacent kept piece).

0.0
unreached_access_score Optional[float]

Access score given to the parts of the network no tier reaches -- both whole edges outside every isochrone and the un-covered middle of a partially-covered edge. Defaults to 0.0: on a "higher is better" access score, 0 is a real, meaningful value ("this street exists, and has no useful access"), whereas omitting the edge entirely (the pre-2026-08-13 behaviour) silently shrank the analysed network down to a halo around the POIs and made every downstream consumer see a network cropped to POI range rather than to the AOI. Pass None to restore that old drop-the-edge behaviour. Ignored (treated as None) when access_score is categorical rather than numeric -- see :func:_numeric_access_scores.

0.0

Returns:

Type Description
DataFrame

Polars DataFrame with the same columns as edges plus

DataFrame

access_score (f64), one row per kept sub-segment. With

DataFrame

unreached_access_score set (the default) every input edge is

DataFrame

represented, in full, by one or more output pieces; with it set to

DataFrame

None, edges no tier reaches are dropped.

Performance note

Per-tier, per-edge remaining-distance lookups (rem_u/rem_v) are vectorized with NumPy (np.searchsorted against a sorted array of node ids, instead of a Python-level dict.get loop over every edge for every tier). The final per-edge segment cut still loops in Python because shapely.ops.substring has no vectorized (array-in, array-out) form, but that loop is restricted to only the edges with nonzero available length in the current tier (via np.nonzero) instead of iterating over every edge on every tier regardless of whether it has anything left to cut.

exact_edge_access(edges, process_order, tier_tables, min_edge_length=0.0, unreached_access_score=0.0)

Split edges at exact tier boundaries and assign an access_score to each piece.

For each tier from best to worst, the portion of every edge within that tier's remaining distance of either endpoint (and not already claimed by a better tier) is cut out with shapely.ops.substring and labeled with that tier's access_score. This reproduces sub-edge isochrone boundary precision without node-level snapping artifacts.

Parameters:

Name Type Description Default
edges DataFrame

Directed edge table (u, v, length_m, geometry_wkb, plus any extra columns, which are copied onto every output piece).

required
process_order DataFrame

Output of :func:distance_matrix_to_processing_order (used for tier ranking, best first).

required
tier_tables dict[float, DataFrame]

Per-tier node_id, remaining_dist tables from :func:compute_node_access.

required
min_edge_length float

Minimum sub-segment length to keep; shorter fragments are dropped (their access_score effectively inherited by the adjacent kept piece).

0.0
unreached_access_score Optional[float]

Access score given to the parts of the network no tier reaches -- both whole edges outside every isochrone and the un-covered middle of a partially-covered edge. Defaults to 0.0: on a "higher is better" access score, 0 is a real, meaningful value ("this street exists, and has no useful access"), whereas omitting the edge entirely (the pre-2026-08-13 behaviour) silently shrank the analysed network down to a halo around the POIs and made every downstream consumer see a network cropped to POI range rather than to the AOI. Pass None to restore that old drop-the-edge behaviour. Ignored (treated as None) when access_score is categorical rather than numeric -- see :func:_numeric_access_scores.

0.0

Returns:

Type Description
DataFrame

Polars DataFrame with the same columns as edges plus

DataFrame

access_score (f64), one row per kept sub-segment. With

DataFrame

unreached_access_score set (the default) every input edge is

DataFrame

represented, in full, by one or more output pieces; with it set to

DataFrame

None, edges no tier reaches are dropped.

Performance note

Per-tier, per-edge remaining-distance lookups (rem_u/rem_v) are vectorized with NumPy (np.searchsorted against a sorted array of node ids, instead of a Python-level dict.get loop over every edge for every tier). The final per-edge segment cut still loops in Python because shapely.ops.substring has no vectorized (array-in, array-out) form, but that loop is restricted to only the edges with nonzero available length in the current tier (via np.nonzero) instead of iterating over every edge on every tier regardless of whether it has anything left to cut.

graph(nodes, edges, points, distance_matrix, poi_score_col=None, access_score_values=None, min_edge_length=0.0, max_dist=None, undirected=True, verbose=True, unreached_access_score=0.0, chunk_h3_resolution=None, chunk_buffer_m=1000.0, crs=None)

Compute a full multi-tier access-score isochrone over a street graph.

Parameters:

Name Type Description Default
nodes DataFrame

Projected node table (node_id, x, y).

required
edges DataFrame

Projected directed edge table (u, v, length_m, geometry_wkb).

required
points DataFrame

POI table with a geometry (shapely Point array) column (or an already-present node_id column if points are pre-snapped) and, optionally, a score column.

required
distance_matrix Union[DataFrame, Sequence[float]]

See :func:distance_matrix_to_processing_order.

required
poi_score_col Optional[str]

Column in points with per-POI scores.

None
access_score_values Optional[Sequence]

Explicit access-score labels (see :func:distance_matrix_to_processing_order).

None
min_edge_length float

Minimum edge/sub-segment length used both when snapping points (:func:UrbanAccessAnalyzer.graph_ops.snap_points) and when splitting edges at tier boundaries.

0.0
max_dist Optional[float]

Maximum snap distance for points onto the graph.

None
undirected bool

Whether to ignore one-way restrictions during the search.

True
verbose bool

Print per-tier progress.

True
unreached_access_score Optional[float]

Score for network the isochrones never reach. Defaults to 0.0, which makes both returned tables dense over the whole input network: every node gets a row and every edge is represented in full, with access_score = 0 where there is no access rather than the row being absent/null. remaining_dist is a distance, not a "0 means nothing" score, so it deliberately stays null for unreached nodes. Pass None for the old sparse behaviour; ignored for categorical access scores.

0.0
chunk_h3_resolution Optional[int]

If set, runs the memory-bounded :func:compute_node_access_chunked instead of :func:compute_node_access -- opt-in, additive path; None (default) is the original, unaffected behavior. See that function's docstring for the H3-chunked isochrone strategy. Requires crs to also be given.

None
chunk_buffer_m float

Forwarded to :func:compute_node_access_chunked as buffer_m when chunk_h3_resolution is set. Default 1000m -- must be >= the largest distance in distance_matrix or results near chunk edges will be truncated (see that function's docstring).

1000.0
crs Optional[str]

Projected CRS of nodes/edges, required (and only used) when chunk_h3_resolution is set.

None

Returns:

Type Description
DataFrame

Tuple (node_access, edge_access) — see

DataFrame

func:compute_node_access and :func:exact_edge_access.

buffers(poi, distance_matrix, poi_score_col=None, access_score_values=None, verbose=True)

Compute Euclidean (no street network) buffer-ring access-score zones.

Parameters:

Name Type Description Default
poi DataFrame

DataFrame with a WKB geometry column (projected CRS, meters) and, optionally, a score column.

required
distance_matrix Union[DataFrame, Sequence[float]]

See :func:distance_matrix_to_processing_order.

required
poi_score_col Optional[str]

Column in poi with per-POI scores.

None
access_score_values Optional[Sequence]

Explicit access-score labels.

None

Returns:

Type Description
DataFrame

Polars DataFrame with columns access_score, rank, geometry_wkb —

DataFrame

one non-overlapping ring per tier, best tier's ring drawn first and

DataFrame

subtracted from worse tiers so no area is double-counted.