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

Parameters

__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.

fromTransitNetwork(transit_network_object[, …])

RoadwayNetwork to ModelRoadwayNetwork

read_gtfs(gtfs_feed_dir[, parameters])

Reads GTFS files from a directory and returns a StandardTransit instance.

route_properties_gtfs_to_cube(self)

Prepare gtfs for cube lin file.

shape_gtfs_to_cube(row)

Creates a list of nodes that for the route in appropriate cube 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.

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

Return type

int

cube_format(row)[source]

Creates a string represnting the route in cube line file notation.

Parameters

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

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.

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)[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.

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

write_as_cube_lin(outpath=None)[source]

Writes the gtfs feed as a cube line file after converting gtfs properties to MetCouncil cube properties.

Parameters

outpath – File location for output cube line file.