fasttrips.Trip

class fasttrips.Trip(input_archive, output_dir, gtfs_feed, today, stops, routes, prepend_route_id_to_trip_id)[source]

Bases: object

Trip class.

One instance represents all of the transit vehicle trips.

Stores Trip information in Trip.trips_df, an instance of pandas.DataFrame and stop time information in Trip.stop_times_df, another instance of pandas.DataFrame.

Also stores Vehicle information in Trip.vehicles_df and Service Calendar information in Trip.service_df

__init__(input_archive, output_dir, gtfs_feed, today, stops, routes, prepend_route_id_to_trip_id)[source]

Constructor. Read the gtfs data from the transitfeed schedule, and the additional fast-trips stops data from the input files in input_archive.

Methods

__init__(input_archive, output_dir, …) Constructor.
add_numeric_trip_id(input_df, id_colname, …) Passing a pandas.DataFrame with a trip ID column called id_colname, adds the numeric trip id as a column named numeric_newcolname and returns it.
add_original_travel_time_and_dwell() Add original travel time to the Trip.stop_times_df as the column named Trip.STOPTIMES_COLUMN_ORIGINAL_TRAVEL_TIME
add_shape_dist_traveled(stops) For any trips in Trip.stop_times_df with rows that are missing column shape_dist_traveled, this method will fill in the column from the stop longitude & latitude.
add_trip_attrs_from_stoptimes() Adds the columns Trip.TRIPS_COLUMN_MAX_STOP_SEQUENCE and Trip.TRIPS_COLUMN_TRIP_DEPARTURE_TIME to the Trip.trips_df datatable to facilitate stop time updates in Trip.update_trip_times()
calculate_headways(trips_df) Calculates headways and sets them into the given trips_df pandas.DataFrame.
get_full_trips() Returns the fullest dataframe of trip + stop information.
get_scheduled_departure(trip_id, stop_id) Return the scheduled departure time for the given stop as a datetime.datetime
get_stop_times(trip_id) Returns pandas.DataFrame with stop times for the given trip id.
has_capacity_configured() Returns true if seated capacity and standing capacity are columns included in the vehicles input.
linkify_vehicle_trips(veh_trips_df, stops) Given a vehicle trips table with columns:
number_of_stops(trip_id) Return the number of stops in this trip.
reset_onboard(df) Resets the onboard fields for the given vehicle trip table.
update_trip_times(trips_df, MSA_RESULTS) Updates trip times for stops with boards and/or alights.
write_trips_for_extension() This writes to an intermediate file a formatted file for the C++ extension.

Attributes

DEFAULT_HEADWAY Default headway if no previous matching route/trip
INPUT_STOPTIMES_FILE
INPUT_TRIPS_FILE
INPUT_VEHICLES_FILE File with fasttrips vehicles information.
OUTPUT_TRIPINFO_FILE File with trip information
OUTPUT_TRIP_ID_NUM_FILE File with trip ID, trip ID number correspondence
SERVICE_COLUMN_END_DATE fasttrips Service column name: End Date as datetime.date
SERVICE_COLUMN_END_DATE_STR fasttrips Service column name: End Date string in ‘YYYYMMDD’ format
SERVICE_COLUMN_START_DATE fasttrips Service column name: Start Date as datetime.date
SERVICE_COLUMN_START_DATE_STR fasttrips Service column name: Start Date string in ‘YYYYMMDD’ format
SIM_COL_VEH_ALIGHTS Result column name: Alights.
SIM_COL_VEH_BOARDS Result column name: Boards.
SIM_COL_VEH_FRICTION Result column name: Friction.
SIM_COL_VEH_MSA_ALIGHTS Result column name: MSA of column SIM_COL_VEH_ALIGHTS.
SIM_COL_VEH_MSA_BOARDS Result column name: MSA of column SIM_COL_VEH_BOARDS.
SIM_COL_VEH_MSA_FRICTION Result column name: MSA Friction.
SIM_COL_VEH_MSA_ONBOARD Result column name: MSA Onboard.
SIM_COL_VEH_MSA_OVERCAP Result column name: Number of MSA onboard passengers minus capacity.
SIM_COL_VEH_MSA_STANDEES Result column name: MSA Standeeds.
SIM_COL_VEH_ONBOARD Result column name: Onboard.
SIM_COL_VEH_OVERCAP Result column name: Number of onboard passengers minus capacity.
SIM_COL_VEH_OVERCAP_FRAC Result column name: Percentage of boards that are problematic.
SIM_COL_VEH_STANDEES Result column name: Standees.
STOPTIMES_COLUMN_ARRIVAL_TIME gtfs Stop times column name: Arrival time.
STOPTIMES_COLUMN_ARRIVAL_TIME_MIN Stop times column name: Arrival time.
STOPTIMES_COLUMN_DEPARTURE_TIME gtfs Stop times column name: Departure time.
STOPTIMES_COLUMN_DEPARTURE_TIME_MIN Stop times column name: Departure time.
STOPTIMES_COLUMN_DROP_OFF_TYPE gtfs Stop times stop times column name: Drop Off Type
STOPTIMES_COLUMN_DWELL_TIME fasttrips Trips column name: Dwell Time.
STOPTIMES_COLUMN_DWELL_TIME_SEC fasttrips Trips column name: Dwell Time in seconds.
STOPTIMES_COLUMN_HEADSIGN gtfs Stop times stop times column name: Stop Headsign
STOPTIMES_COLUMN_ORIGINAL_TRAVEL_TIME fasttrips Trips column name: Original Travel Time.
STOPTIMES_COLUMN_PICKUP_TYPE gtfs Stop times stop times column name: Pickup Type
STOPTIMES_COLUMN_SHAPE_DIST_TRAVELED gtfs Stop times stop times column name: Shape Distance Traveled
STOPTIMES_COLUMN_STOP_ID gtfs Stop times column name: Stop unique identifier
STOPTIMES_COLUMN_STOP_ID_NUM fasttrips Trips column name: Stop Numerical Identifier.
STOPTIMES_COLUMN_STOP_SEQUENCE gtfs Stop times column name: Sequence number of stop within a trip.
STOPTIMES_COLUMN_TIMEPOINT gtfs Stop times stop times column name: Time Point
STOPTIMES_COLUMN_TRAVEL_TIME fasttrips Trips column name: Travel Time.
STOPTIMES_COLUMN_TRAVEL_TIME_SEC fasttrips Trips column name: Travel Time in seconds.
STOPTIMES_COLUMN_TRIP_ID gtfs Stop times column name: Trip unique identifier.
STOPTIMES_COLUMN_TRIP_ID_NUM fasttrips Trips column name: Trip Numerical Identifier.
TRIPS_COLUMN_DIRECTION_ID gtfs Trip column name: Direction binary identifier.
TRIPS_COLUMN_MAX_STOP_SEQUENCE fasttrips Trips column name: Max Stop Sequence number.
TRIPS_COLUMN_MODE_NUM fasttrips Trips column name: Mode Numerical Identifier.
TRIPS_COLUMN_ROUTE_ID gtfs Trips column name: Route unique identifier.
TRIPS_COLUMN_ROUTE_ID_NUM fasttrips Trips column name: Route Numerical Identifier.
TRIPS_COLUMN_SERVICE_ID gtfs Trips column name: Service unique identifier.
TRIPS_COLUMN_SHAPE_ID gtfs Trip column name: Shape ID
TRIPS_COLUMN_TRIP_DEPARTURE_TIME fasttrips Trip column name: Trip departure time (from the first stop).
TRIPS_COLUMN_TRIP_ID gtfs Trips column name: Unique identifier.
TRIPS_COLUMN_TRIP_ID_NUM fasttrips Trips column name: Trip Numerical Identifier.
TRIPS_COLUMN_VEHICLE_NAME fasttrips Trips column name: Vehicle Name
VEHICLES_COLUMN_ACCELERATION fasttrips Vehicles column name: Acceleration (feet per (second^2)) float.
VEHICLES_COLUMN_BICYCLE_CAPACITY fasttrips Vehicles column name: Bicycle Capacity
VEHICLES_COLUMN_DECELERATION fasttrips Vehicles column name: Decelration (feet per (second^2)) float.
VEHICLES_COLUMN_DWELL_FORMULA fasttrips Vehilces column name: Dwell formula (string)
VEHICLES_COLUMN_MAXIMUM_SPEED fasttrips Vehicles column name: Maximum Speed (mph)
VEHICLES_COLUMN_MAXIMUM_SPEED_FPS fasttrips Vehicles column name: Maximum Speed (fps)
VEHICLES_COLUMN_NUMBER_OF_DOORS fasttrips Vehicles column name: Number of Doors
VEHICLES_COLUMN_PLATFORM_HEIGHT fasttrips Vehicles column name: Platform Height (inches)
VEHICLES_COLUMN_PROPULSION_TYPE fasttrips Vehicles column name: Propulsion Type
VEHICLES_COLUMN_SEATED_CAPACITY fasttrips Vehicles column name: Seated Capacity
VEHICLES_COLUMN_STANDING_CAPACITY fasttrips Vehicles column name: Standing Capacity
VEHICLES_COLUMN_TOTAL_CAPACITY fasttrips Trips column name: Vehicle Total (Seated + Standing) Capacity
VEHICLES_COLUMN_VEHICLE_DESCRIPTION fasttrips Vehicles column name: Vehicle Description
VEHICLES_COLUMN_VEHICLE_LENGTH fasttrips Vehicles column name: Vehicle Length (feet)
VEHICLES_COLUMN_VEHICLE_NAME fasttrips Vehicles column name: Vehicle name (identifier)
VEHICLES_COLUMN_WHEELCHAIR_CAPACITY fasttrips Vehicles column name: Wheelchair Capacity (overrides trip)
add_numeric_trip_id(input_df, id_colname, numeric_newcolname)[source]

Passing a pandas.DataFrame with a trip ID column called id_colname, adds the numeric trip id as a column named numeric_newcolname and returns it.

add_original_travel_time_and_dwell()[source]

Add original travel time to the Trip.stop_times_df as the column named Trip.STOPTIMES_COLUMN_ORIGINAL_TRAVEL_TIME

Copies it into working travel time columns Trip.STOPTIMES_COLUMN_TRAVEL_TIME and Trip.STOPTIMES_COLUMN_TRAVEL_TIME_SEC

Also adds dwell time columns named Trip.STOPTIMES_COLUMN_DWELL_TIME and Trip.STOPTIMES_COLUMN_DWELL_TIME_SEC

add_shape_dist_traveled(stops)[source]

For any trips in Trip.stop_times_df with rows that are missing column shape_dist_traveled, this method will fill in the column from the stop longitude & latitude. stops is a Stop instance.

Todo

this will be in miles, but should be configurable

add_trip_attrs_from_stoptimes()[source]

Adds the columns Trip.TRIPS_COLUMN_MAX_STOP_SEQUENCE and Trip.TRIPS_COLUMN_TRIP_DEPARTURE_TIME to the Trip.trips_df datatable to facilitate stop time updates in Trip.update_trip_times()

static calculate_headways(trips_df)[source]

Calculates headways and sets them into the given trips_df pandas.DataFrame.

Returns pandas.DataFrame with headway column added.

get_full_trips()[source]

Returns the fullest dataframe of trip + stop information.

get_scheduled_departure(trip_id, stop_id)[source]

Return the scheduled departure time for the given stop as a datetime.datetime

TODO: problematic if the stop id occurs more than once in the trip.

get_stop_times(trip_id)[source]

Returns pandas.DataFrame with stop times for the given trip id.

has_capacity_configured()[source]

Returns true if seated capacity and standing capacity are columns included in the vehicles input.

static linkify_vehicle_trips(veh_trips_df, stops)[source]

Given a vehicle trips table with columns:

Transforms and returns a link-version more relevant to passengers. The columns will be: * mode, mode_num, route_id, route_id_num, trip_id, trip_id_num * A_id, A_id_num, A_seq * B_id, B_id_num, B_seq * A_lat, A_lon * B_lat, B_lon * A_arrival_time, A_departure_time, B_arrival_time, B_departure_time

number_of_stops(trip_id)[source]

Return the number of stops in this trip.

static reset_onboard(df)[source]

Resets the onboard fields for the given vehicle trip table.

static update_trip_times(trips_df, MSA_RESULTS)[source]

Updates trip times for stops with boards and/or alights.

If vehicle max_speed and deceleration rate specified, for non first/last stop, adds lost time due to stopping. If vehicle max_speed and acceleration rate specified, for non first/last stop, adds lost time due to stopping. If dwell time formula specified, adds dwell time at stop.

Updates the following columns: - Trip.SIM_COL_VEH_STANDEES - Trip.SIM_COL_VEH_MSA_STANDEES - Trip.SIM_COL_VEH_FRICTION - Trip.SIM_COL_VEH_MSA_FRICTION - Trip.STOPTIMES_COLUMN_TRAVEL_TIME - Trip.STOPTIMES_COLUMN_TRAVEL_TIME_SEC - Trip.STOPTIMES_COLUMN_DWELL_TIME - Trip.STOPTIMES_COLUMN_DWELL_TIME_SEC - Trip.STOPTIMES_COLUMN_ARRIVAL_TIME - Trip.STOPTIMES_COLUMN_DEPARTURE_TIME

write_trips_for_extension()[source]

This writes to an intermediate file a formatted file for the C++ extension. Since there are strings involved, it’s easier than passing it to the extension.

DEFAULT_HEADWAY = 60

Default headway if no previous matching route/trip

INPUT_STOPTIMES_FILE = 'stop_times_ft.txt'
INPUT_TRIPS_FILE = 'trips_ft.txt'
INPUT_VEHICLES_FILE = 'vehicles_ft.txt'

File with fasttrips vehicles information. See vehicles_ft specification.

OUTPUT_TRIPINFO_FILE = 'ft_intermediate_trip_info.txt'

File with trip information

OUTPUT_TRIP_ID_NUM_FILE = 'ft_intermediate_trip_id.txt'

File with trip ID, trip ID number correspondence

SERVICE_COLUMN_END_DATE = 'end_date'

fasttrips Service column name: End Date as datetime.date

SERVICE_COLUMN_END_DATE_STR = 'end_date_str'

fasttrips Service column name: End Date string in ‘YYYYMMDD’ format

SERVICE_COLUMN_START_DATE = 'start_date'

fasttrips Service column name: Start Date as datetime.date

SERVICE_COLUMN_START_DATE_STR = 'start_date_str'

fasttrips Service column name: Start Date string in ‘YYYYMMDD’ format

SIM_COL_VEH_ALIGHTS = 'alights'

Result column name: Alights. Int.

SIM_COL_VEH_BOARDS = 'boards'

Result column name: Boards. Int.

SIM_COL_VEH_FRICTION = 'friction'

Result column name: Friction. Where positive, friction = on+off+standees. Int.

SIM_COL_VEH_MSA_ALIGHTS = 'msa_alights'

Result column name: MSA of column SIM_COL_VEH_ALIGHTS. Float.

SIM_COL_VEH_MSA_BOARDS = 'msa_boards'

Result column name: MSA of column SIM_COL_VEH_BOARDS. Float.

SIM_COL_VEH_MSA_FRICTION = 'msa_friction'

Result column name: MSA Friction. Where positive, MSA friction = MSA boards + MSA alights + MSA standees. Float.

SIM_COL_VEH_MSA_ONBOARD = 'msa_onboard'

Result column name: MSA Onboard. Cumulative sum of SIM_COL_VEH_MSA_BOARDS - SIM_COL_VEH_MSA_ALIGHTS. Float.

SIM_COL_VEH_MSA_OVERCAP = 'msa_overcap'

Result column name: Number of MSA onboard passengers minus capacity. Float.

SIM_COL_VEH_MSA_STANDEES = 'msa_standees'

Result column name: MSA Standeeds. MSA onboard - sitting capacity, if configured. Float.

SIM_COL_VEH_ONBOARD = 'onboard'

Result column name: Onboard. Cumulative sum of SIM_COL_VEH_BOARDS - SIM_COL_VEH_ALIGHTS. Int.

SIM_COL_VEH_OVERCAP = 'overcap'

Result column name: Number of onboard passengers minus capacity. Int. Can be negative.

SIM_COL_VEH_OVERCAP_FRAC = 'overcap_frac'

Result column name: Percentage of boards that are problematic. (overcap/boards)

SIM_COL_VEH_STANDEES = 'standees'

Result column name: Standees. Onboard - sitting capacity, if configured. Int.

STOPTIMES_COLUMN_ARRIVAL_TIME = 'arrival_time'

gtfs Stop times column name: Arrival time. This is a DateTime.

STOPTIMES_COLUMN_ARRIVAL_TIME_MIN = 'arrival_time_min'

Stop times column name: Arrival time. This is a float, minutes after midnight.

STOPTIMES_COLUMN_DEPARTURE_TIME = 'departure_time'

gtfs Stop times column name: Departure time. This is a DateTime.

STOPTIMES_COLUMN_DEPARTURE_TIME_MIN = 'departure_time_min'

Stop times column name: Departure time. This is a float, minutes after midnight.

STOPTIMES_COLUMN_DROP_OFF_TYPE = 'drop_off_type'

gtfs Stop times stop times column name: Drop Off Type

STOPTIMES_COLUMN_DWELL_TIME = 'dwell_time'

fasttrips Trips column name: Dwell Time. This is a timedelta.

STOPTIMES_COLUMN_DWELL_TIME_SEC = 'dwell_time_sec'

fasttrips Trips column name: Dwell Time in seconds. Float

STOPTIMES_COLUMN_HEADSIGN = 'stop_headsign'

gtfs Stop times stop times column name: Stop Headsign

STOPTIMES_COLUMN_ORIGINAL_TRAVEL_TIME = 'original_travel_time'

fasttrips Trips column name: Original Travel Time. This is a timedelta. This represents the travel from original input, and is assumed to include accel from first stop and decel to last stop, but no dwell times and no other accel/decel times.

STOPTIMES_COLUMN_PICKUP_TYPE = 'pickup_type'

gtfs Stop times stop times column name: Pickup Type

STOPTIMES_COLUMN_SHAPE_DIST_TRAVELED = 'shape_dist_traveled'

gtfs Stop times stop times column name: Shape Distance Traveled

STOPTIMES_COLUMN_STOP_ID = 'stop_id'

gtfs Stop times column name: Stop unique identifier

STOPTIMES_COLUMN_STOP_ID_NUM = 'stop_id_num'

fasttrips Trips column name: Stop Numerical Identifier. Int.

STOPTIMES_COLUMN_STOP_SEQUENCE = 'stop_sequence'

gtfs Stop times column name: Sequence number of stop within a trip. Starts at 1 and is sequential

STOPTIMES_COLUMN_TIMEPOINT = 'timepoint'

gtfs Stop times stop times column name: Time Point

STOPTIMES_COLUMN_TRAVEL_TIME = 'travel_time'

fasttrips Trips column name: Travel Time. This is a timedelta.

STOPTIMES_COLUMN_TRAVEL_TIME_SEC = 'travel_time_sec'

fasttrips Trips column name: Travel Time in seconds. Float.

STOPTIMES_COLUMN_TRIP_ID = 'trip_id'

gtfs Stop times column name: Trip unique identifier. (String)

STOPTIMES_COLUMN_TRIP_ID_NUM = 'trip_id_num'

fasttrips Trips column name: Trip Numerical Identifier. Int.

TRIPS_COLUMN_DIRECTION_ID = 'direction_id'

gtfs Trip column name: Direction binary identifier.

TRIPS_COLUMN_MAX_STOP_SEQUENCE = 'max_stop_seq'

fasttrips Trips column name: Max Stop Sequence number. Int.

TRIPS_COLUMN_MODE_NUM = 'mode_num'

fasttrips Trips column name: Mode Numerical Identifier. Int.

TRIPS_COLUMN_ROUTE_ID = 'route_id'

gtfs Trips column name: Route unique identifier.

TRIPS_COLUMN_ROUTE_ID_NUM = 'route_id_num'

fasttrips Trips column name: Route Numerical Identifier. Int.

TRIPS_COLUMN_SERVICE_ID = 'service_id'

gtfs Trips column name: Service unique identifier.

TRIPS_COLUMN_SHAPE_ID = 'shape_id'

gtfs Trip column name: Shape ID

TRIPS_COLUMN_TRIP_DEPARTURE_TIME = 'trip_departure_time'

fasttrips Trip column name: Trip departure time (from the first stop).

TRIPS_COLUMN_TRIP_ID = 'trip_id'

gtfs Trips column name: Unique identifier. This will be the index of the trips table. (object)

TRIPS_COLUMN_TRIP_ID_NUM = 'trip_id_num'

fasttrips Trips column name: Trip Numerical Identifier. Int.

TRIPS_COLUMN_VEHICLE_NAME = 'vehicle_name'

fasttrips Trips column name: Vehicle Name

VEHICLES_COLUMN_ACCELERATION = 'acceleration'

fasttrips Vehicles column name: Acceleration (feet per (second^2)) float.

VEHICLES_COLUMN_BICYCLE_CAPACITY = 'bicycle_capacity'

fasttrips Vehicles column name: Bicycle Capacity

VEHICLES_COLUMN_DECELERATION = 'deceleration'

fasttrips Vehicles column name: Decelration (feet per (second^2)) float.

VEHICLES_COLUMN_DWELL_FORMULA = 'dwell_formula'

fasttrips Vehilces column name: Dwell formula (string)

VEHICLES_COLUMN_MAXIMUM_SPEED = 'max_speed'

fasttrips Vehicles column name: Maximum Speed (mph)

VEHICLES_COLUMN_MAXIMUM_SPEED_FPS = 'max_speed_fps'

fasttrips Vehicles column name: Maximum Speed (fps)

VEHICLES_COLUMN_NUMBER_OF_DOORS = 'number_of_doors'

fasttrips Vehicles column name: Number of Doors

VEHICLES_COLUMN_PLATFORM_HEIGHT = 'platform_height'

fasttrips Vehicles column name: Platform Height (inches)

VEHICLES_COLUMN_PROPULSION_TYPE = 'propulsion_type'

fasttrips Vehicles column name: Propulsion Type

VEHICLES_COLUMN_SEATED_CAPACITY = 'seated_capacity'

fasttrips Vehicles column name: Seated Capacity

VEHICLES_COLUMN_STANDING_CAPACITY = 'standing_capacity'

fasttrips Vehicles column name: Standing Capacity

VEHICLES_COLUMN_TOTAL_CAPACITY = 'capacity'

fasttrips Trips column name: Vehicle Total (Seated + Standing) Capacity

VEHICLES_COLUMN_VEHICLE_DESCRIPTION = 'vehicle_description'

fasttrips Vehicles column name: Vehicle Description

VEHICLES_COLUMN_VEHICLE_LENGTH = 'vehicle_length'

fasttrips Vehicles column name: Vehicle Length (feet)

VEHICLES_COLUMN_VEHICLE_NAME = 'vehicle_name'

fasttrips Vehicles column name: Vehicle name (identifier)

VEHICLES_COLUMN_WHEELCHAIR_CAPACITY = 'wheelchair_capacity'

fasttrips Vehicles column name: Wheelchair Capacity (overrides trip)