# Path: gtfspy/route_types.py
# WALK = -1
# TRAM = 0
# SUBWAY = 1
# RAIL = 2
# BUS = 3
# FERRY = 4
# CABLE_CAR = 5
# GONDOLA = 6
# FUNICULAR = 7
# AIRCRAFT = 99
# ALL_ROUTE_TYPES = {WALK, TRAM, SUBWAY, RAIL, BUS, FERRY, CABLE_CAR, GONDOLA, FUNICULAR}
# TRANSIT_ROUTE_TYPES = ALL_ROUTE_TYPES.difference({WALK})
# ROUTE_TYPE_TO_ZORDER = {
#     WALK: 2,
#     BUS: 3,
#     RAIL: 4,
#     SUBWAY: 5,
#     TRAM: 6,
#     FERRY: 7,
#     CABLE_CAR: 8,
#     GONDOLA: 9,
#     FUNICULAR: 10,
#     AIRCRAFT: 11
# }
# ROUTE_TYPE_TO_DESCRIPTION = {
#     WALK: "Walk, pedestrian travel",
#     SUBWAY: "Subway, Metro. Any underground rail system within a metropolitan area.",
#     RAIL: "Rail. Used for intercity or long - distance travel.",
#     BUS: "Bus. Used for short- and long-distance bus routes.",
#     FERRY: "Ferry. Used for short- and long-distance boat service.",
#     CABLE_CAR: "Cable car. Used for street-level cable cars "
#                            "where the cable runs beneath the car.",
#     GONDOLA: "Gondola, Suspended cable car. "
#                          "Typically used for aerial cable cars where "
#                          "the car is suspended from the cable.",
#     FUNICULAR: "Funicular. Any rail system designed for steep inclines."
# }
# ROUTE_TYPE_TO_SHORT_DESCRIPTION = {
#     WALK: "Walk",
#     TRAM: "Tram",
#     SUBWAY: "Subway",
#     RAIL: "Rail",
#     BUS: "Bus",
#     FERRY: "Ferry",
#     CABLE_CAR: "Cable car",
#     GONDOLA: "Gondola",
#     FUNICULAR: "Funicular",
#     AIRCRAFT: "Aircraft"
# }
# ROUTE_TYPE_TO_LOWERCASE_TAG = {
#     WALK: "walk",
#     TRAM: "tram",
#     SUBWAY: "subway",
#     RAIL: "rail",
#     BUS: "bus",
#     FERRY: "ferry",
#     CABLE_CAR: "cablecar",
#     GONDOLA: "gondola",
#     FUNICULAR: "funicular"
# }
# ROUTE_TYPE_TO_APPROXIMATE_CAPACITY = {
#     WALK: None,
#     TRAM: 200,
#     SUBWAY: 600,
#     RAIL: 600,
#     BUS: 80,
#     FERRY: 200,
#     CABLE_CAR: 40,
#     GONDOLA: 20,
#     FUNICULAR: 20
# }
# ROUTE_TYPE_TO_COLOR = {
#     WALK: "black",
#     TRAM: '#33a02c',
#     SUBWAY: "#ff7f00",
#     RAIL: '#e31a1c',
#     BUS: '#1f78b4',
#     FERRY: "#ffff99",
#     CABLE_CAR: "#6a3d9a",
#     GONDOLA: "#b15928",
#     FUNICULAR: "#fb9a99",
#     AIRCRAFT: "#fb9a99"
# }
# def route_type_to_color_iterable(type):
# def route_type_to_zorder(type):
# 
# Path: gtfspy/util.py
# def wgs84_distance(lat1, lon1, lat2, lon2):
#     """Distance (in meters) between two points in WGS84 coord system."""
#     dLat = math.radians(lat2 - lat1)
#     dLon = math.radians(lon2 - lon1)
#     a = (math.sin(dLat / 2) * math.sin(dLat / 2) +
#          math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
#          math.sin(dLon / 2) * math.sin(dLon / 2))
#     c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
#     d = EARTH_RADIUS * c
#     return d
# 
# def graph_node_attrs(g, node):
#     """Backwards compatability function for networkx < 2.0
# 
#     <2.0:   g.node[n]  --> attribute dict
#     >2.2:   g.nodes[n] --> attribute dict
# 
#     """
#     if hasattr(g, 'node'):
#         # networkx <= 2.4
#         return g.node[node]
#     # networkx >= 2.0
#     return g.nodes[node]


import networkx
import pandas as pd
from math import isnan
from gtfspy import route_types
from gtfspy.util import wgs84_distance, graph_node_attrs
from warnings import warn
                if found is None:
                    link_data["distance_shape"] = None
                else:
                    link_event = link_events.iloc[found]
                    distance = gtfs.get_shape_distance_between_stops(
                        link_event["trip_I"],
                        int(link_event["from_seq"]),
                        int(link_event["to_seq"])
                    )
                    link_data['distance_shape'] = distance
            if "route_I_counts" in link_attributes:
                link_data["route_I_counts"] = link_events.groupby("route_I").size().to_dict()
            net.add_edge(from_stop_I, to_stop_I, **link_data)
    return net


def stop_to_stop_networks_by_type(gtfs):
    """
    Compute stop-to-stop networks for all travel modes (route_types).

    Parameters
    ----------
    gtfs: gtfspy.GTFS

    Returns
    -------
    dict: dict[int, networkx.DiGraph]
        keys should be one of route_types.ALL_ROUTE_TYPES (i.e. GTFS route_types)
    """
    route_type_to_network = dict()

# Path: gtfspy/route_types.py
# WALK = -1
# TRAM = 0
# SUBWAY = 1
# RAIL = 2
# BUS = 3
# FERRY = 4
# CABLE_CAR = 5
# GONDOLA = 6
# FUNICULAR = 7
# AIRCRAFT = 99
# ALL_ROUTE_TYPES = {WALK, TRAM, SUBWAY, RAIL, BUS, FERRY, CABLE_CAR, GONDOLA, FUNICULAR}
# TRANSIT_ROUTE_TYPES = ALL_ROUTE_TYPES.difference({WALK})
# ROUTE_TYPE_TO_ZORDER = {
#     WALK: 2,
#     BUS: 3,
#     RAIL: 4,
#     SUBWAY: 5,
#     TRAM: 6,
#     FERRY: 7,
#     CABLE_CAR: 8,
#     GONDOLA: 9,
#     FUNICULAR: 10,
#     AIRCRAFT: 11
# }
# ROUTE_TYPE_TO_DESCRIPTION = {
#     WALK: "Walk, pedestrian travel",
#     SUBWAY: "Subway, Metro. Any underground rail system within a metropolitan area.",
#     RAIL: "Rail. Used for intercity or long - distance travel.",
#     BUS: "Bus. Used for short- and long-distance bus routes.",
#     FERRY: "Ferry. Used for short- and long-distance boat service.",
#     CABLE_CAR: "Cable car. Used for street-level cable cars "
#                            "where the cable runs beneath the car.",
#     GONDOLA: "Gondola, Suspended cable car. "
#                          "Typically used for aerial cable cars where "
#                          "the car is suspended from the cable.",
#     FUNICULAR: "Funicular. Any rail system designed for steep inclines."
# }
# ROUTE_TYPE_TO_SHORT_DESCRIPTION = {
#     WALK: "Walk",
#     TRAM: "Tram",
#     SUBWAY: "Subway",
#     RAIL: "Rail",
#     BUS: "Bus",
#     FERRY: "Ferry",
#     CABLE_CAR: "Cable car",
#     GONDOLA: "Gondola",
#     FUNICULAR: "Funicular",
#     AIRCRAFT: "Aircraft"
# }
# ROUTE_TYPE_TO_LOWERCASE_TAG = {
#     WALK: "walk",
#     TRAM: "tram",
#     SUBWAY: "subway",
#     RAIL: "rail",
#     BUS: "bus",
#     FERRY: "ferry",
#     CABLE_CAR: "cablecar",
#     GONDOLA: "gondola",
#     FUNICULAR: "funicular"
# }
# ROUTE_TYPE_TO_APPROXIMATE_CAPACITY = {
#     WALK: None,
#     TRAM: 200,
#     SUBWAY: 600,
#     RAIL: 600,
#     BUS: 80,
#     FERRY: 200,
#     CABLE_CAR: 40,
#     GONDOLA: 20,
#     FUNICULAR: 20
# }
# ROUTE_TYPE_TO_COLOR = {
#     WALK: "black",
#     TRAM: '#33a02c',
#     SUBWAY: "#ff7f00",
#     RAIL: '#e31a1c',
#     BUS: '#1f78b4',
#     FERRY: "#ffff99",
#     CABLE_CAR: "#6a3d9a",
#     GONDOLA: "#b15928",
#     FUNICULAR: "#fb9a99",
#     AIRCRAFT: "#fb9a99"
# }
# def route_type_to_color_iterable(type):
# def route_type_to_zorder(type):
# 
# Path: gtfspy/util.py
# def wgs84_distance(lat1, lon1, lat2, lon2):
#     """Distance (in meters) between two points in WGS84 coord system."""
#     dLat = math.radians(lat2 - lat1)
#     dLon = math.radians(lon2 - lon1)
#     a = (math.sin(dLat / 2) * math.sin(dLat / 2) +
#          math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
#          math.sin(dLon / 2) * math.sin(dLon / 2))
#     c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
#     d = EARTH_RADIUS * c
#     return d
# 
# def graph_node_attrs(g, node):
#     """Backwards compatability function for networkx < 2.0
# 
#     <2.0:   g.node[n]  --> attribute dict
#     >2.2:   g.nodes[n] --> attribute dict
# 
#     """
#     if hasattr(g, 'node'):
#         # networkx <= 2.4
#         return g.node[node]
#     # networkx >= 2.0
#     return g.nodes[node]


# Path: gtfspy/networks.py
import networkx
import pandas as pd
from math import isnan
from gtfspy import route_types
from gtfspy.util import wgs84_distance, graph_node_attrs
from warnings import warn

                if found is None:
                    link_data["distance_shape"] = None
                else:
                    link_event = link_events.iloc[found]
                    distance = gtfs.get_shape_distance_between_stops(
                        link_event["trip_I"],
                        int(link_event["from_seq"]),
                        int(link_event["to_seq"])
                    )
                    link_data['distance_shape'] = distance
            if "route_I_counts" in link_attributes:
                link_data["route_I_counts"] = link_events.groupby("route_I").size().to_dict()
            net.add_edge(from_stop_I, to_stop_I, **link_data)
    return net


def stop_to_stop_networks_by_type(gtfs):
    """
    Compute stop-to-stop networks for all travel modes (route_types).

    Parameters
    ----------
    gtfs: gtfspy.GTFS

    Returns
    -------
    dict: dict[int, networkx.DiGraph]
        keys should be one of route_types.ALL_ROUTE_TYPES (i.e. GTFS route_types)
    """
    route_type_to_network = dict()

    for route_type in route_types.ALL_ROUTE_TYPES: