Example #1
0
def get_transit_connections(gtfs, start_time_ut, end_time_ut):
    """
    Parameters
    ----------
    gtfs: gtfspy.GTFS
    end_time_ut: int
    start_time_ut: int

    Returns
    -------
    list[Connection]
    """
    if start_time_ut + 20 * 3600 < end_time_ut:
        warn(
            "Note that it is possible that same trip_I's can take place during multiple days, "
            "which could (potentially) affect the outcomes of the CSA routing!"
        )
    assert (isinstance(gtfs, GTFS))
    events_df = temporal_network(gtfs,
                                 start_time_ut=start_time_ut,
                                 end_time_ut=end_time_ut)
    assert (isinstance(events_df, pandas.DataFrame))
    return list(
        map(
            lambda e: Connection(e.from_stop_I, e.to_stop_I, e.dep_time_ut, e.
                                 arr_time_ut, e.trip_I, e.seq),
            events_df.itertuples()))
Example #2
0
def write_temporal_network(gtfs, output_filename, start_time_ut=None, end_time_ut=None):
    """
    Parameters
    ----------
    gtfs : gtfspy.GTFS
    output_filename : str
        path to the directory where to store the extracts
    start_time_ut: int | None
        start time of the extract in unixtime (seconds after epoch)
    end_time_ut: int | None
        end time of the extract in unixtime (seconds after epoch)
    """
    util.makedirs(os.path.dirname(os.path.abspath(output_filename)))
    pandas_data_frame = temporal_network(gtfs, start_time_ut=start_time_ut, end_time_ut=end_time_ut)
    pandas_data_frame.to_csv(output_filename, encoding='utf-8', index=False)
Example #3
0
def write_temporal_networks_by_route_type(gtfs, extract_output_dir):
    """
    Write temporal networks by route type to disk.

    Parameters
    ----------
    gtfs: gtfspy.GTFS
    extract_output_dir: str
    """
    util.makedirs(extract_output_dir)
    for route_type in route_types.TRANSIT_ROUTE_TYPES:
        pandas_data_frame = temporal_network(gtfs, start_time_ut=None, end_time_ut=None, route_type=route_type)
        tag = route_types.ROUTE_TYPE_TO_LOWERCASE_TAG[route_type]
        out_file_name = os.path.join(extract_output_dir, tag + ".tnet")
        pandas_data_frame.to_csv(out_file_name, encoding='utf-8', index=False)
Example #4
0
 def test_temporal_network(self):
     temporal_pd = networks.temporal_network(self.gtfs)
     self.assertGreater(temporal_pd.shape[0], 10)
Example #5
0
from example_import import load_or_import_example_gtfs
from gtfspy import networks
from gtfspy import route_types

g = load_or_import_example_gtfs()
day_start_ut = g.get_weekly_extract_start_date(ut=True)

start_ut = day_start_ut + 7 * 3600
end_ut = day_start_ut + 8 * 3600

# get elementary bus events (connections) taking place within a given time interval:
all_events = networks.temporal_network(g,
                                       start_time_ut=start_ut,
                                       end_time_ut=end_ut)
print("Number of elementary PT events during rush hour in Kuopio: ",
      len(all_events))

# get  elementary bus events (connections) taking place within a given time interval:
tram_events = networks.temporal_network(g,
                                        start_time_ut=start_ut,
                                        end_time_ut=end_ut,
                                        route_type=route_types.TRAM)
assert (len(tram_events) == 0
        )  # there should be no trams in our example city (Kuopio, Finland)

# construct a networkx graph
print("\nConstructing a combined stop_to_stop_network")

graph = networks.combined_stop_to_stop_transit_network(g,
                                                       start_time_ut=start_ut,
                                                       end_time_ut=end_ut)