transitlos¶
transitLOS: transit level-of-service accessibility scoring.
Ties street-network accessibility (UrbanAccessAnalyzer), transit stops
(pyGTFSHandler), and population/census data (pycensus/geohierarchy)
together into a single transit level-of-service accessibility score. The scoring formulas are in
transitlos.scoring; transitlos.api is the consolidated public surface re-exported below.
level_of_service_to_h3(access_gdf, resolution, aoi=None, score_col='level_of_service', margin_m=10.0, fallback_radius_multiplier=5.0, no_access_value=0.0)
¶
Resample a street-edges level_of_service column onto an H3 grid.
Each returned H3 cell holds the maximum score_col among streets that
intersect it (or, absent that, its single nearest street within
fallback_radius_multiplier cell-edge-lengths) -- see module docstring
for the full policy. Cells with no qualifying street at all get
no_access_value rather than a null, matching the fillna(0.0)
convention used elsewhere in the downstream pipeline for "no coverage".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_gdf
|
GeoDataFrame
|
Street-edges GeoDataFrame with |
required |
resolution
|
int
|
H3 resolution the grid is built at (typically the maximum/finest resolution configured for the AOI). |
required |
aoi
|
Optional[GeoDataFrame]
|
Geometry whose extent the H3 grid should cover. Defaults to
|
None
|
score_col
|
str
|
Column in |
'level_of_service'
|
margin_m
|
float
|
Extra distance (in meters) beyond one cell's own
footprint still counted as "touching" a street -- forwarded to
|
10.0
|
fallback_radius_multiplier
|
Optional[float]
|
How many cell-edge-lengths a cell may
look for its nearest street once the normal margin turns up
nothing. |
5.0
|
no_access_value
|
float
|
Value assigned to a cell that found no street even within the fallback radius. |
0.0
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with |
GeoDataFrame
|
per H3 cell covering |
GeoDataFrame
|
populated. |
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 |
required |
feed_source
|
GTFS feed source forwarded to
|
None
|
|
network
|
Optional[StreetNetwork]
|
A pre-built |
None
|
stops
|
Optional[GeoDataFrame]
|
A pre-built stops GeoDataFrame; if |
None
|
region
|
str
|
Region key forwarded to |
'global'
|
cache_dir
|
Optional[str]
|
Passed to |
None
|
walk_distance_steps
|
Sequence[float]
|
Deprecated/unused by default as of
2026-08-12 -- distance thresholds are now derived automatically
by |
(400, 800, 1200)
|
weights
|
Optional[tuple[float, float, float]]
|
Optional |
None
|
pbf_path
|
Optional[str]
|
Passed to |
None
|
date_range
|
Optional[tuple[Union[date, datetime], Union[date, datetime]]]
|
Optional |
None
|
score_bins
|
Optional[int]
|
Deprecated/unused by default as of 2026-08-12 --
|
50
|
max_walk_distance_m
|
Optional[float]
|
Optional hard outer walk-distance cutoff
(meters) forwarded to |
None
|
chunk_h3_resolution
|
Optional[int]
|
Opt-in memory-bounded isochrone computation --
forwarded to |
None
|
chunk_buffer_m
|
float
|
Forwarded as |
1000.0
|
stops_crop_buffer_m
|
float
|
Metres to buffer |
500.0
|
**stops_kwargs
|
Extra keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
1.0}` internally (see module docstring, point 3) and then rescaled |
GeoDataFrame
|
to |
GeoDataFrame
|
every 0-1 score be displayed/stored on a 0-100 scale. |
compute_stop_scores(stops_df, region='global', weights=None, default_headway_cv=None, stop_score_mode='nested')
¶
Add mrc_score/speed_score/frequency_score/stop_score columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stops_df
|
Union[DataFrame, 'gpd.GeoDataFrame']
|
A pandas DataFrame or GeoDataFrame with |
required |
region
|
str
|
Region key forwarded to every |
'global'
|
weights
|
Optional[tuple[float, float, float]]
|
Only meaningful when |
None
|
stop_score_mode
|
str
|
Forwarded to |
'nested'
|
default_headway_cv
|
Optional[float]
|
No longer substituted into |
None
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame, 'gpd.GeoDataFrame']
|
|
Union[DataFrame, 'gpd.GeoDataFrame']
|
|
Union[DataFrame, 'gpd.GeoDataFrame']
|
|
cross_with_population(access_gdf, population_source='worldpop', aoi=None, region_for_census=None, id_col='edge_id', access_columns=None, census_level='tract', census_dataset='acs', worldpop_date=None, worldpop_resolution='1km', worldpop_folder=None, **kwargs)
¶
Combine access_gdf (street edges with an level_of_service column) with population data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_gdf
|
GeoDataFrame
|
Street-edges GeoDataFrame with an |
required |
population_source
|
str
|
|
'worldpop'
|
aoi
|
Optional[GeoDataFrame]
|
Area of interest, required for |
None
|
region_for_census
|
Optional[Union[str, list]]
|
For |
None
|
id_col
|
str
|
Name to give the population polygon's unique-id column in
the returned GeoDataFrame ( |
'edge_id'
|
access_columns
|
Optional[list]
|
Edge columns from |
None
|
census_level
|
str
|
Geometry level forwarded to |
'tract'
|
census_dataset
|
str
|
|
'acs'
|
worldpop_date
|
Year (or date/datetime) forwarded to
|
None
|
|
worldpop_resolution
|
str
|
|
'1km'
|
worldpop_folder
|
Optional[str]
|
Download destination forwarded to
|
None
|
**kwargs
|
Extra keyword arguments forwarded to the underlying
|
{}
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
GeoDataFrame with one row per population polygon: |
GeoDataFrame
|
geometry, |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
download_and_prepare_stops(feed_source, aoi=None, date_range=None, start_time=time.min, end_time=time.max, route_types=None, by='route_id', at='parent_station', how='add', scoring='direction_best', speed_method='straight', window_min=15.0, window_direction='both', **kwargs)
¶
Load a GTFS feed and build a per-stop headway/speed table.
scoring="direction_best" (default) scores every parent station from the MERGED departures of all routes split in the two directions
of travel, searching mode tier x minimum trip speed for the best stop score (scoring.direction_subset); by/how then do not apply
and the table already carries stop_score. scoring="route" is the previous route-level headway (by/how) with the speed max.
feed_source is passed straight through to pyGTFSHandler.feed.Feed's
gtfs_dirs constructor argument -- this function does not implement any
downloading/geocoding-to-feed-source resolution of its own, it only
orchestrates a Feed that has already been (or can already be) loaded
from a path/URL/list understood by pyGTFSHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed_source
|
Union[str, Path, Sequence[Union[str, Path]]]
|
One or more GTFS directory/zip paths, forwarded to
|
required |
aoi
|
Optional[GeoDataFrame]
|
Optional Area of Interest GeoDataFrame/GeoSeries used to geospatially filter stops while loading the feed. |
None
|
date_range
|
Optional[tuple[Union[date, datetime], Union[date, datetime]]]
|
Optional Performance: passing |
None
|
start_time
|
Union[datetime, time]
|
Start of the daily analysis window, forwarded to both
|
min
|
end_time
|
Union[datetime, time]
|
End of the daily analysis window, forwarded the same way. Defaults to end of day. |
max
|
route_types
|
Optional[Union[list, int, str]]
|
Optional GTFS route type filter, forwarded to both
|
None
|
by
|
str
|
Grouping key forwarded to |
'route_id'
|
at
|
str
|
Spatial stop-identity column forwarded to both analysis calls
( |
'parent_station'
|
how
|
str
|
Aggregation strategy forwarded to both analysis calls. Note
Changed from |
'add'
|
speed_method
|
str
|
How the speed at a stop is measured: |
'straight'
|
window_min
|
float
|
Minutes on each side of the stop the speed is measured over (default 15). |
15.0
|
window_direction
|
str
|
|
'both'
|
**kwargs
|
Extra keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
geopandas.GeoDataFrame with columns: |
GeoDataFrame
|
used), |
GeoDataFrame
|
|
GeoDataFrame
|
docstring), |
GeoDataFrame
|
by the underlying calls. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the feed has no usable date to analyze (no
|
equity_statistics(combined_gdf, score_col='level_of_service', population_col='population', groups=None, thresholds=(0.25, 0.5, 0.75))
¶
Compute population-weighted access-equity statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
combined_gdf
|
DataFrame
|
DataFrame/GeoDataFrame with |
required |
score_col
|
str
|
Column holding the per-row level of service. |
'level_of_service'
|
population_col
|
str
|
Column holding the per-row population count, used as weights throughout. |
'population'
|
groups
|
Optional[Union[str, Sequence[str]]]
|
Optional column name (or list of column names) to also break statistics down by, in addition to the overall figures. |
None
|
thresholds
|
Sequence[float]
|
Score thresholds used to report the population share above/below each one. |
(0.25, 0.5, 0.75)
|
Returns:
| Type | Description |
|---|---|
dict
|
A dict with keys |
dict
|
|
dict
|
|
dict
|
if |
dict
|
the group column(s) with the same statistics per group. |
prepare_street_network(aoi, cache_dir=None, cluster_distance=10.0, pbf_path=None, network_type='all', ignore_oneway=True)
¶
Return a simplified, AOI-cropped StreetNetwork, using a cache if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
AreaOfInterest
|
Area of interest the network is built/cropped for. |
required |
cache_dir
|
Optional[str]
|
Directory to load a previously |
None
|
cluster_distance
|
float
|
Cluster distance (meters) passed to
|
10.0
|
pbf_path
|
Optional[str]
|
Path to a local |
None
|
network_type
|
str
|
Defaults to |
'all'
|
ignore_oneway
|
bool
|
Defaults to |
True
|
Returns:
| Type | Description |
|---|---|
StreetNetwork
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no cached network is found and |