lasso.StandardTransit
- class lasso.StandardTransit(ptg_feed, parameters={})[source]
Bases:
object
Holds a standard transit feed as a Partridge object and contains methods to manipulate and translate the GTFS data to MetCouncil’s Cube Line files.
Typical usage example:
cube_transit_net = StandardTransit.read_gtfs(BASE_TRANSIT_DIR) cube_transit_net.write_as_cube_lin(os.path.join(WRITE_DIR, "outfile.lin"))
- feed
Partridge Feed object containing read-only access to GTFS feed
- parameters
Parameters instance containing information about time periods and variables.
- Type:
- __init__(ptg_feed, parameters={})[source]
- Parameters:
ptg_feed – partridge feed object
parameters – dictionary of parameter settings (see Parameters class) or an instance of Parameters
Methods
__init__
(ptg_feed[, parameters])- param ptg_feed:
partridge feed object
calculate_cube_mode
(row)Assigns a cube mode number by following logic.
cube_format
(row)Creates a string represnting the route in cube line file notation. #MC :param row: row of a DataFrame representing a cube-formatted trip, with the Attributes trip_id, shape_id, NAME, LONGNAME, tod, HEADWAY, MODE, ONEWAY, OPERATOR.
evaluate_differences
(transit_changes)Compare changes from the transit_changes dataframe with the standard transit network returns the project card changes in dictionary format
fromTransitNetwork
(transit_network_object[, ...])RoadwayNetwork to ModelRoadwayNetwork
read_gtfs
(gtfs_feed_dir[, parameters])Reads GTFS files from a directory and returns a StandardTransit instance.
Prepare gtfs for cube lin file.
shape_gtfs_to_cube
(row[, add_nntime])Creates a list of nodes that for the route in appropriate cube format.
shape_gtfs_to_dict_list
(trip_id, shape_id, ...)This is a copy of StandardTransit.shape_gtfs_to_cube() because we need the same logic of stepping through the routed nodes and corresponding them with shape nodes.
shape_gtfs_to_emme
(trip_row)Creates transit segment for the trips in appropriate emme format.
time_to_cube_time_period
(start_time_secs[, ...])Converts seconds from midnight to the cube time period.
write_as_cube_lin
([outpath])Writes the gtfs feed as a cube line file after converting gtfs properties to MetCouncil cube properties.
- calculate_cube_mode(row)[source]
Assigns a cube mode number by following logic. #MC For rail, uses GTFS route_type variable: https://developers.google.com/transit/gtfs/reference
- ::
# route_type : cube_mode route_type_to_cube_mode = {0: 8, # Tram, Streetcar, Light rail
3: 0, # Bus; further disaggregated for cube 2: 9} # Rail
For buses, uses route id numbers and route name to find express and suburban buses as follows:
- ::
- if not cube_mode:
- if ‘express’ in row[‘LONGNAME’].lower():
cube_mode = 7 # Express
- elif int(row[‘route_id’].split(“-“)[0]) > 99:
cube_mode = 6 # Suburban Local
- else:
cube_mode = 5 # Urban Local
- Parameters:
row – A DataFrame row with route_type, route_long_name, and route_id
- Returns:
cube mode number
- cube_format(row)[source]
Creates a string represnting the route in cube line file notation. #MC :param row: row of a DataFrame representing a cube-formatted trip, with the Attributes
trip_id, shape_id, NAME, LONGNAME, tod, HEADWAY, MODE, ONEWAY, OPERATOR
- Returns:
string representation of route in cube line file notation
- evaluate_differences(transit_changes)[source]
Compare changes from the transit_changes dataframe with the standard transit network returns the project card changes in dictionary format
- static fromTransitNetwork(transit_network_object, parameters={})[source]
RoadwayNetwork to ModelRoadwayNetwork
- Parameters:
transit_network_object – Reference to an instance of TransitNetwork.
parameters – dictionary of parameter settings (see Parameters class) or an instance of Parameters. If not provided will use default parameters.
- Returns:
StandardTransit
- static read_gtfs(gtfs_feed_dir, parameters={})[source]
Reads GTFS files from a directory and returns a StandardTransit instance.
- Parameters:
gtfs_feed_dir – location of the GTFS files
parameters – dictionary of parameter settings (see Parameters class) or an instance of Parameters. If not provided will use default parameters.
- Returns:
StandardTransit instance
- static route_properties_gtfs_to_cube(self)[source]
Prepare gtfs for cube lin file. #MC Does the following operations: 1. Combines route, frequency, trip, and shape information 2. Converts time of day to time periods 3. Calculates cube route name from gtfs route name and properties 4. Assigns a cube-appropriate mode number 5. Assigns a cube-appropriate operator number
- Returns:
- DataFrame of trips with cube-appropriate values for:
NAME
ONEWAY
OPERATOR
MODE
HEADWAY
- Return type:
trip_df (DataFrame)
- shape_gtfs_to_cube(row, add_nntime=False)[source]
Creates a list of nodes that for the route in appropriate cube format.
- Parameters:
row – DataFrame row with both shape_id and trip_id
- Returns: a string representation of the node list
for a route in cube format.
- shape_gtfs_to_dict_list(trip_id, shape_id, add_nntime)[source]
This is a copy of StandardTransit.shape_gtfs_to_cube() because we need the same logic of stepping through the routed nodes and corresponding them with shape nodes.
TODO: eliminate this necessity by tagging the stop nodes in the shapes to begin with when the transit routing on the roadway network is first performed.
As such, I’m copying the code from StandardTransit.shape_gtfs_to_cube() with minimal modifications.
- Parameters:
question (shape_id of the trip in) –
question –
- Returns:
trip_id shape_id shape_pt_sequence shape_mode_node_id is_stop access stop_sequence
- Return type:
list of dict records with columns
- shape_gtfs_to_emme(trip_row)[source]
Creates transit segment for the trips in appropriate emme format.
- Parameters:
row – DataFrame row with both shape_id and trip_id
- Returns: a dataframe representation of the transit segment
for a trip in emme format.
- time_to_cube_time_period(start_time_secs, as_str=True, verbose=False)[source]
Converts seconds from midnight to the cube time period.
- Parameters:
start_time_secs – start time for transit trip in seconds from midnight
as_str – if True, returns the time period as a string, otherwise returns a numeric time period
- Returns:
- if as_str is False, returns the numeric
time period
- this_tp: if as_str is True, returns the Cube time period
name abbreviation
- Return type:
this_tp_num