polaris.network.transit.transit_elements.Pattern#

class polaris.network.transit.transit_elements.Pattern(geotool, route_id, gtfs_feed=None, path_to_file: PathLike = PosixPath('.'))#

Bases: BasicPTElement

Represents a stop pattern for a particular route, as defined in GTFS

After loading a GTFS feed for a particular date, one can retrieve each pattern for analysis. For example:

from polaris.network.network import Network
from os.path import join

root = 'D:/Argonne/GTFS/DETROIT'

n = Network()
n.open(join(root, 'detroit-Supply.sqlite'))
source = n.transit.new_gtfs(file_path=join(root, 'DDOT', '2020-06-23.zip'),
                      description='Detroit Department of Transportation',
                      agency_id='DDOT')

source.load_date('2020-06-23')

# We can access one pattern with its ID
pat = source.select_patterns['D-d1079f93748abfdf57e28413874d3f54']

# Or loop through all
for pattern_id, pattern in source.select_patterns.items():
    # map_matching each one of them, for example
    pattern.map_match()

# We can retrieve the issue in path finding we have for a pattern with

#The pair of links between which there was an issue computing a path
pair = pattern.get_error('culprit')

# The reconstructed route until the point an issue was found
pth = pattern.get_error('partial_path')

# Once map_matching is complete (or re-done), one can update it in the database
pattern.update_shape(n.conn)
Database class members:
  • pattern_id (str): Pattern ID as saved to the database

  • route_id (str): Route ID as saved to the database

  • seated_capacity (int): Vehicle seated capacity as saved to the database

  • design_capacity (int): Vehicle design capacity as saved to the database

  • total_capacity (int): Vehicle total capacity as saved to the database

  • shape (LineString): Route shape as saved to the database (populated by map_match())

Other class members:
  • raw_shape (LineString): Route shape as retrieved from GTFS

  • route_type (int): GTFS route type

  • full_path (List[int]): Sequence list of links forming the path (negative for BA direction)

  • stops (List[Stop]): List of object stops in order of traversal by the route

  • network_candidates (List[int]): List of link IDs likely to be part of the route (populated by find_network_links())

__init__(geotool, route_id, gtfs_feed=None, path_to_file: PathLike = PosixPath('.')) None#

Args:

pattern_id (str): Pre-computed ID for this pattern geotool (Geo): Suite of geographic utilities. For internal use only

Methods

__init__(geotool, route_id[, gtfs_feed, ...])

Args:

best_shape()

Gets the best version of shape available for this pattern

from_row(data)

get_pattern_id()

map_match()

Map matches the route into the network, considering its appropriate shape

save_to_database(conn[, commit])

Saves the pattern to the Transit_Patterns table

__init__(geotool, route_id, gtfs_feed=None, path_to_file: PathLike = PosixPath('.')) None#

Args:

pattern_id (str): Pre-computed ID for this pattern geotool (Geo): Suite of geographic utilities. For internal use only

save_to_database(conn: Connection, commit=True) None#

Saves the pattern to the Transit_Patterns table

best_shape() LineString#

Gets the best version of shape available for this pattern

map_match()#

Map matches the route into the network, considering its appropriate shape

Part of the map-matching process is to find the network links corresponding the pattern’s raw shape, so that method will be called in case it has not been called before.

The basic algorithm behind the map-matching algorithm is described in https://doi.org/10.3141%2F2646-08

In a nutshell, we compute the shortest path between the nodes corresponding to the links to which stops were geographically matched, for each pair of identified links.

We do not consider links that are in perfect sequence, as we found that it introduces severe issues when stops are close to intersections without clear upsides.

When issues are found, we remove the stops in the immediate vicinity of the issue and attempt new path finding. The First and last stops/corresponding links are always kept.

If an error was found, (record for it will show in the log), it is stored within the object.

get_pattern_id()#