Dictionaries for faster lookup.

  • For faster lookup, the GTFS set is post-processed into several dictionaries and provided as pickle files.
    • stops_dict_pkl: Contains stops along the route. Format: {route_id: list of stops}

    • stoptimes_dict_pkl: Contains trips along a route. Format: {route_id: [trip_1, trip_2]}

    • transfers_dict_full: Contains footpath details. Format: {stop_id: [(stop_id, time)]}

    • routes_by_stop: All routes passing from a given stop id. Format: {stop_id: list of routes}

    • idx_by_route_stop: Gives the index of a stop along a route. Format: {(route_id, stop_id): index}

    Functions for building these dicts from the GTFS set are present in dict_builder.py.

Description

Module defines a function to save (using pickling) the GTFS information in the form of a dictionary. This is done for easy/faster data lookup.

dict_builder.dict_builder_functions.build_routesindx_by_stop_dict(NETWORK_NAME: str)dict[source]

This function saves a dictionary.

Parameters

NETWORK_NAME (str) – name of the network

Returns

Keys: stop id, value: [(route_id, stop index), (route_id, stop index)]

Return type

routesindx_by_stop_dict (dict)

dict_builder.dict_builder_functions.build_save_footpath_dict(transfers_file, NETWORK_NAME: str)dict[source]

This function saves a dictionary to provide easy access to all the footpaths through a stop id.

Parameters
  • transfers_file (pandas.dataframe) – dataframe with transfers (footpath) details.

  • NETWORK_NAME (str) – name of the network

Returns

keys: from stop_id, values: list of tuples of form (to stop id, footpath duration). Format-> dict[stop_id]=[(stop_id, footpath_duration)]

Return type

footpath_dict (dict)

dict_builder.dict_builder_functions.build_save_route_by_stop(stop_times_file, NETWORK_NAME: str)dict[source]

This function saves a dictionary to provide easy access to all the routes passing through a stop_id.

Parameters
  • stop_times_file (pandas.dataframe) – stop_times.txt file in GTFS.

  • NETWORK_NAME (str) – name of the network

Returns

keys: stop_id, values: list of routes passing through the stop_id. Format-> dict[stop_id] = [route_id]

Return type

route_by_stop_dict_new (dict)

dict_builder.dict_builder_functions.build_save_stops_dict(stop_times_file, trips_file, NETWORK_NAME: str)dict[source]

This function saves a dictionary to provide easy access to all the stops in the route.

Parameters
  • stop_times_file (pandas.dataframe) – stop_times.txt file in GTFS.

  • trips_file (pandas.dataframe) – trips.txt file in GTFS.

  • NETWORK_NAME (str) – name of the network

Returns

keys: route_id, values: list of stop id in the route_id. Format-> dict[route_id] = [stop_id]

Return type

stops_dict (dict)

dict_builder.dict_builder_functions.build_save_stopstimes_dict(stop_times_file, trips_file, NETWORK_NAME: str)dict[source]

This function saves a dictionary to provide easy access to all the trips passing along a route id. Trips are sorted in the increasing order of departure time. A trip is list of tuple of form (stop id, arrival time)

Parameters
  • stop_times_file (pandas.dataframe) – stop_times.txt file in GTFS.

  • trips_file (pandas.dataframe) – dataframe with transfers (footpath) details.

  • NETWORK_NAME (str) – name of the network

Returns

keys: route ID, values: list of trips in the increasing order of start time. Format-> dict[route_ID] = [trip_1, trip_2] where trip_1 = [(stop id, arrival time), (stop id, arrival time)]

Return type

stoptimes_dict (dict)

dict_builder.dict_builder_functions.build_stop_idx_in_route(stop_times_file, NETWORK_NAME: str)dict[source]

This function saves a dictionary to provide easy access to index of a stop in a route.

Parameters
  • stop_times_file (pandas.dataframe) – stop_times.txt file in GTFS.

  • NETWORK_NAME (str) – name of the network

Returns

Keys: (route id, stop id), value: stop index. Format {(route id, stop id): stop index in route}.

Return type

idx_by_route_stop_dict (dict)