Skip to content

transitlos.level_of_service

Orchestrates network + stops + scoring into a street-edges level_of_service GeoDataFrame.

Pipeline: network.prepare_street_network (if network not given) + stops.download_and_prepare_stops (if stops not given) + stop_scores.compute_stop_scores (if stops lacks a stop_score column yet) feed a UrbanAccessAnalyzer.api.PointsOfInterest (transit stops, scored by stop_score) into an AccessibilityAnalyzer, whose .run() + .to_gdf() produce the final street-edges level_of_service GeoDataFrame.

2026-08-12 rewrite, at the user's explicit request: this module used to rely on AccessibilityAnalyzer.default_distance_matrix's own generic rank-based falloff, deliberately not calling transitlos.scoring's own walk_decay/accessibility_score to avoid double-counting walk decay (once via that generic falloff, once via walk_decay). That tradeoff is now resolved the other way: transitlos.scoring.distance_matrix .build_intelligent_distance_matrix builds the distance_matrix argument AccessibilityAnalyzer.run expects from transitlos.scoring's own offset-power D(t; stop_score) decay (see walk_access.py), so the isochrone engine now runs transitLOS's own decay directly -- there is no longer a second, independent falloff to double-count against.

This also implements "intelligent discretization" (see distance_matrix.py's module docstring for the full rationale):

  1. Distance steps are no longer a flat convention (the old walk_distance_steps=(400, 800, 1200) default) -- they are derived by inverting the decay curve at each output-grid tier's midpoint, so every isochrone distance computed maps directly onto an output-visible {0.0, 0.1, ..., 1.0} boundary.
  2. Stops are grouped ("bucketed") by output-equivalent stop_score, not left as hundreds of near-duplicate continuous values -- two stops whose stop_score would produce identical ceiling-discretized output at every chosen distance collapse into one distance-matrix row, directly minimizing the number of (poi_score, distance) isochrone/Dijkstra runs UrbanAccessAnalyzer.isochrones has to perform (that module already batches every POI sharing a tier into one multi-source search -- see its docstring -- so fewer distinct tiers is exactly fewer runs).
  3. The final level_of_service is ceiling-discretized onto {0.0, 0.1, ..., 1.0} both inside the matrix and, as a safety net, on the final per-edge output column (UrbanAccessAnalyzer's exact_edge_access can produce edge-interpolated values between matrix grid points that a matrix-only discretization wouldn't catch).

walk_distance_steps remains an accepted parameter for backward compatibility and manual overrides, but is no longer used by default -- compute_level_of_service only falls back to it if build_intelligent_distance_matrix is explicitly bypassed (region=None is not a valid escape hatch here; pass distance_matrix/bucket_map yourself if you need the old flat-convention behavior).

compute_level_of_service(aoi, feed_source=None, network=None, stops=None, region='global', cache_dir=None, walk_distance_steps=(400, 800, 1200), weights=None, pbf_path=None, date_range=None, score_bins=50, max_walk_distance_m=None, chunk_h3_resolution=None, chunk_buffer_m=1000.0, stops_crop_buffer_m=500.0, **stops_kwargs)

Compute a street-edges GeoDataFrame with a transit-access level_of_service column.

Parameters:

Name Type Description Default
aoi AreaOfInterest

Area of interest for the network and (if stops not given) the GTFS feed.

required
feed_source

GTFS feed source forwarded to stops.download_and_prepare_stops if stops is not given.

None
network Optional[StreetNetwork]

A pre-built StreetNetwork; if None, network.prepare_street_network(aoi, cache_dir=cache_dir, pbf_path=pbf_path) is called.

None
stops Optional[GeoDataFrame]

A pre-built stops GeoDataFrame; if None, stops.download_and_prepare_stops(feed_source, aoi=aoi, date_range=date_range, **stops_kwargs) is called. If given but missing a stop_score column, stop_scores.compute_stop_scores is applied to it.

None
region str

Region key forwarded to compute_stop_scores and to build_intelligent_distance_matrix (selects the decay-shape defaults walk_decay/accessibility_score use).

'global'
cache_dir Optional[str]

Passed to prepare_street_network for network caching.

None
walk_distance_steps Sequence[float]

Deprecated/unused by default as of 2026-08-12 -- distance thresholds are now derived automatically by build_intelligent_distance_matrix from transitLOS's own decay curve (see module docstring). Kept only so existing calls don't break; passing a non-default value has no effect unless you also bypass build_intelligent_distance_matrix yourself.

(400, 800, 1200)
weights Optional[tuple[float, float, float]]

Optional (w1, w2, w3, w4) weights forwarded to compute_stop_scores.

None
pbf_path Optional[str]

Passed to prepare_street_network when a network must be built from scratch.

None
date_range Optional[tuple[Union[date, datetime], Union[date, datetime]]]

Optional (start_date, end_date) forwarded to download_and_prepare_stops (ignored if stops is given directly). Strongly recommended whenever you already know a valid service date for feed_source: it skips download_and_prepare_stops's expensive service-day auto-detection fallback, which alone can cost ~7s of a ~10s call on a real multi-file GTFS feed (see that function's docstring for details). If omitted, the safe (but slower) auto-detection default is used.

None
score_bins Optional[int]

Deprecated/unused by default as of 2026-08-12 -- build_intelligent_distance_matrix already collapses stop_score into output-equivalent buckets (see module docstring), which supersedes this parameter's quantile-bucketing approach.

50
max_walk_distance_m Optional[float]

Optional hard outer walk-distance cutoff (meters) forwarded to build_intelligent_distance_matrix. The decay curve (walk_access.walk_decay) never truly reaches zero, so without this the isochrone search radius can extend several kilometers for the lowest access tier; set this to cap it (e.g. 2000 m) while still searching the entire requested radius (see that function's docstring for how the cutoff is applied). None (default) leaves the search radius unbounded.

None
chunk_h3_resolution Optional[int]

Opt-in memory-bounded isochrone computation -- forwarded to UrbanAccessAnalyzer.api.AccessibilityAnalyzer.run's chunk_h3_resolution. None (default) is the original whole-network behavior, unaffected. Set to e.g. 4 for oversized AOIs (Boston, Shanghai) where the unchunked path OOMs.

None
chunk_buffer_m float

Forwarded as chunk_buffer_m when chunk_h3_resolution is set. Must be >= the largest isochrone search radius the chosen decay curve can produce (see max_walk_distance_m above and AccessibilityAnalyzer.run/compute_node_access_chunked's own docstrings) or results near chunk boundaries will be truncated.

1000.0
stops_crop_buffer_m float

Metres to buffer aoi by before querying stops (only when stops is not given directly) -- see the note where it's used, below. 0 for the exact-AOI behavior.

500.0
**stops_kwargs

Extra keyword arguments forwarded to download_and_prepare_stops (e.g. route_types).

{}

Returns:

Type Description
GeoDataFrame

geopandas.GeoDataFrame of street edges (network CRS) with a

GeoDataFrame

level_of_service column, ceiling-discretized onto `{0.0, 0.1, ...,

GeoDataFrame

1.0}` internally (see module docstring, point 3) and then rescaled

GeoDataFrame

to {0, 10, ..., 100} -- 2026-09-23, explicit user request that

GeoDataFrame

every 0-1 score be displayed/stored on a 0-100 scale.