transitlos.flex.profiles¶
GTFS -> station profiles (up to P (mode, headway, speed) combinations per parent station).
Same method as transitlos.scoring.direction_subset (feeds grouped by window, stops grouped within 150 m, the same departure table, the same candidate
search: three mode tiers x minimum trip speed in 5 km/h steps, headway = the better of the two directions, speed = sum(distance)/sum(time)). The
difference: instead of keeping only the best candidate per station, every candidate is kept, then floors + dominance + the cap (core.select_profiles)
choose at most P of them.
Modes: 0 bus, 1 tram, 2 rail (the tier, as direction_subset scores it).
cand = state_candidates(gtfs_dirs, aoi) # slow part (loads the feeds); cache it
stations, prof, cutoffs = select(cand, Config(P=10)) # fast; redo with other caps/floors without reloading
usable_feeds(gtfs_dirs)
¶
Feed folders that really hold a static GTFS (some downloads are not: empty folders, partial zips).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gtfs_dirs
|
Sequence[Path]
|
Candidate feed folders. |
required |
Returns:
| Type | Description |
|---|---|
List[Path]
|
The usable folders. |
drop_duplicate_feeds(gtfs_dirs)
¶
The same service published twice (agency feed + Mobility Database copy, ...) would count every trip twice and change the stop clustering; keep the larger copy, as the original study does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gtfs_dirs
|
Sequence[Path]
|
Feed folders. |
required |
Returns:
| Type | Description |
|---|---|
List[Path]
|
The folders without the duplicates. |
feed_route_modes(feed)
¶
route_id -> scoring_mode for the route ids the loaded Feed really uses, from each route's own GTFS route_type (BRT marker 702 -> tram).
Keyed by the Feed's final ids: when several feeds are loaded together the Feed renames a route id that exists in more than one of them to
<id>_file_<n>. A table built from the feeds' own routes.txt files and joined on the final id gave those routes no mode, and an id shared by
a bus feed and a rail feed took the first feed's mode -- LA Metro Rail, LIRR, NJ Transit rail... came out as buses or were lost
(the original study fixed the same trap in usa_study/code/best_subset_scoring.feed_route_modes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
A loaded pyGTFSHandler Feed. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
feed_candidates(feed, analysis_date, route_modes, start=START, end=END, step=SPEED_STEP, speed_method=None, window_min=None, window_direction=None, departures=None)
¶
Every (tier, minimum speed) candidate of every parent station: columns parent_station, mode, cutoff, headway_min, speed_kmh.
speed_method / window_min / window_direction: how the speed at the station is measured
(transitlos.scoring.direction_subset.departures_with_direction); None = its defaults (straight line, 15 min, both sides).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
A loaded pyGTFSHandler Feed. |
required | |
analysis_date
|
Service date. |
required | |
route_modes
|
|
required | |
start
|
Start of the scoring window. |
START
|
|
end
|
End of the scoring window. |
END
|
|
step
|
Minimum-speed step (km/h). |
SPEED_STEP
|
|
speed_method
|
|
None
|
|
window_min
|
Minutes on each side of the station; |
None
|
|
window_direction
|
|
None
|
|
departures
|
The departure table (:func: |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per candidate. |
feed_departures(feed, analysis_date, route_modes, start=START, end=END, speed_method=None, window_min=None, window_direction=None)
¶
One row per departure at a parent station (transitlos.scoring.direction_subset.departures_with_direction, the defaults of the study).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
A loaded pyGTFSHandler Feed. |
required | |
analysis_date
|
Service date. |
required | |
route_modes
|
|
required | |
start
|
Start of the scoring window. |
START
|
|
end
|
End of the scoring window. |
END
|
|
speed_method
|
|
None
|
|
window_min
|
Minutes on each side of the station; |
None
|
|
window_direction
|
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
feed_routes(feed, departures, max_shapes=4)
¶
The routes of the departures (for the map editor): one row per route (route_id, short / long name, colour, mode 0 bus 1 tram 2 rail)
and its main shapes (up to max_shapes shapes run by at least 10 % of its trips, as LINESTRINGs, EPSG:4326).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
The loaded pyGTFSHandler Feed the departures come from. |
required | |
departures
|
DataFrame
|
:func: |
required |
max_shapes
|
int
|
Shapes kept per route. |
4
|
Returns:
| Type | Description |
|---|---|
|
|
split_feeds_by_window(gtfs_dirs, aoi, analysis_date=ANALYSIS_DATE, stop_group_distance=STOP_GROUP_M)
¶
(feeds with a trip on analysis_date, the others). The others are scored alone on their own typical weekday (a feed with no service on the
shared day would otherwise lose all its stops silently).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gtfs_dirs
|
Sequence[Path]
|
Feed folders. |
required |
aoi
|
Study area. |
required | |
analysis_date
|
The shared analysis date. |
ANALYSIS_DATE
|
|
stop_group_distance
|
float
|
Stop grouping distance (m). |
STOP_GROUP_M
|
weighted_stations(feed, parents)
¶
Real stops of the stations in parents (column parent_station) with the station location as the centroid of its stop_ids weighted by their
service (stop_times rows of the loaded window, proportional to 1/headway) -- so a station sits where its service is, not at the plain mean.
Returns (stops: stop_id, stop_name, stop_lat, stop_lon, parent_station, weight; stations: parent_station, lat, lon).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
A loaded pyGTFSHandler Feed. |
required | |
parents
|
DataFrame
|
Table with a |
required |
state_candidates(gtfs_dirs, state_aoi, log=print, stops_sink=None, speed_method=None, window_min=None, window_direction=None, routes_sink=None)
¶
Candidates of all stations inside state_aoi (any area; a state in the US study): columns lat, lon, mode, cutoff, headway_min, speed_kmh (feeds loaded as the original does:
in-window feeds together, every other feed alone on its own typical weekday). Speed options as in feed_candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gtfs_dirs
|
Sequence[Path]
|
Feed folders of the area. |
required |
state_aoi
|
The area (GeoDataFrame). |
required | |
log
|
Progress function. |
print
|
|
stops_sink
|
list | None
|
Optional list that receives the real stops of each feed group. |
None
|
speed_method
|
|
None
|
|
window_min
|
Minutes on each side of the station; |
None
|
|
window_direction
|
|
None
|
|
routes_sink
|
list | None
|
Optional list that receives, per feed group, |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The candidates. |
select(cand, cfg=core.Config(), params=DEFAULT)
¶
Group candidates by station location (same place in different feed groups = one station), apply floors/dominance/cap. Returns (stations DataFrame [lat, lon, n_candidates, n_profiles, dropped], core.Profiles, selected candidate rows).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cand
|
DataFrame
|
Candidates from :func: |
required |
cfg
|
Config
|
Caps and floors. |
Config()
|
params
|
ScoreParams
|
Scoring parameters. |
DEFAULT
|