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:
- A distance matrix maps
(poi_score tier, distance threshold) -> access_score. :func:default_distance_matrixbuilds a simple diagonal matrix; callers may also supply their own (e.g. calibrated with :mod:UrbanAccessAnalyzer.scoring). - :func:
distance_matrix_to_processing_ordercollapses that matrix to one row per distinctaccess_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. - For each row, :func:
compute_node_accessrunsrouting.multi_source_distancesfrom 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. - 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_distof either endpoint that is not already claimed by a better tier is assigned to that tier and its sub-segment geometry cut withshapely.ops.substring(this replaces the old WKT-string / pandas__exact_isochronespass ingraph_processing.pywith a vectorized NumPy pass over the smalln_edges x n_tiersmatrix). - :func:
bufferscomputes the pure Euclidean (no street network) equivalent for cases where a network isn't available or wanted: nested tier buffers around POIs withshapely.differenceused 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 |
required |
distance_steps
|
Sequence[float]
|
Distance thresholds (e.g. |
required |
poi_score_col
|
str
|
Column in |
'poi_score'
|
score_bins
|
Optional[int]
|
Optional number of quantile buckets used to collapse
how many distinct rank positions continuous Measured tradeoff (real Cambridge, MA street network + GTFS
stops, 866 distinct continuous 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 ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
distance_matrix |
DataFrame
|
one row per distinct poi_score (excluding 0),
one column per distance step plus a |
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: |
required |
access_score_values
|
Optional[Sequence]
|
Explicit access-score labels. When
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with columns |
DataFrame
|
|
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 ( |
required |
edges
|
DataFrame
|
Directed edge table ( |
required |
points
|
DataFrame
|
POI table with a |
required |
process_order
|
DataFrame
|
Output of :func: |
required |
poi_score_col
|
Optional[str]
|
Column in |
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 |
tier_tables |
dict[float, DataFrame]
|
dict mapping each distinct |
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 ( |
required |
edges
|
DataFrame
|
Full directed edge table, projected, matching |
required |
points
|
DataFrame
|
POI table, see :func: |
required |
process_order
|
DataFrame
|
Output of :func: |
required |
crs
|
str
|
The projected CRS |
required |
poi_score_col
|
Optional[str]
|
See :func: |
None
|
undirected
|
bool
|
See :func: |
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
|
1000.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Same shape as :func: |
dict[float, DataFrame]
|
tier_tables) |
tuple[DataFrame, dict[float, DataFrame]]
|
|
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: |
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: |
tuple[DataFrame, dict[float, DataFrame]]
|
within one tier), so :func: |
tuple[DataFrame, dict[float, DataFrame]]
|
against the original, unchunked |
tuple[DataFrame, dict[float, DataFrame]]
|
function's |
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 ( |
required |
process_order
|
DataFrame
|
Output of :func: |
required |
tier_tables
|
dict[float, DataFrame]
|
Per-tier |
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
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with the same columns as |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
represented, in full, by one or more output pieces; with it set to |
DataFrame
|
|
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 ( |
required |
process_order
|
DataFrame
|
Output of :func: |
required |
tier_tables
|
dict[float, DataFrame]
|
Per-tier |
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
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with the same columns as |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
represented, in full, by one or more output pieces; with it set to |
DataFrame
|
|
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 ( |
required |
edges
|
DataFrame
|
Projected directed edge table ( |
required |
points
|
DataFrame
|
POI table with a |
required |
distance_matrix
|
Union[DataFrame, Sequence[float]]
|
See :func: |
required |
poi_score_col
|
Optional[str]
|
Column in |
None
|
access_score_values
|
Optional[Sequence]
|
Explicit access-score labels (see
:func: |
None
|
min_edge_length
|
float
|
Minimum edge/sub-segment length used both when
snapping points (:func: |
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
|
chunk_h3_resolution
|
Optional[int]
|
If set, runs the memory-bounded
:func: |
None
|
chunk_buffer_m
|
float
|
Forwarded to :func: |
1000.0
|
crs
|
Optional[str]
|
Projected CRS of |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Tuple |
DataFrame
|
func: |
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 |
required |
distance_matrix
|
Union[DataFrame, Sequence[float]]
|
See :func: |
required |
poi_score_col
|
Optional[str]
|
Column in |
None
|
access_score_values
|
Optional[Sequence]
|
Explicit access-score labels. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with columns |
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. |