Peartree

repository·master·Indexed 42 days ago

https://github.com/kuanb/peartree

A library for converting GTFS (General Transit Feed Specification) schedules into representative directed network multigraphs. Peartree integrates Partridge, Pandas, and NetworkX to facilitate transit network analysis, allowing users to load feeds as graphs for specific time windows.

Tokens
723
Snippets
3
Records
4
Agent score
3%

What's inside Peartree

  1. How peartree processes GTFS data

    master

    Peartree acts as a bridge between transit schedule data and graph theory tools. It uses the following stack:

    • Partridge: Used to convert target operator GTFS schedule data into Pandas dataframes.
    • Pandas: Used for data manipulation of the schedule.
    • NetworkX: Used to hold and manipulate the final schedule data as a directed multigraph.

    This allows developers to perform complex network analysis (like centrality or clustering) on transit networks using standard Python graph libraries.

  2. Convert a GTFS feed to a NetworkX graph

    master

    To convert a GTFS feed into a directed network multigraph, follow these steps:

    1. Use pt.get_representative_feed(path) to automatically identify the busiest day in the GTFS zip file and load it as a Partridge feed.
    2. Define a start and end time period (in seconds from midnight) to represent the window of service you want to analyze.
    3. Use pt.load_feed_as_graph(feed, start, end) to convert that specific subset of the feed into a NetworkX graph object.

    This workflow is useful for summarizing transit impedance and performing graph analysis on specific time windows.

    import peartree as pt
    
    path = 'path/to/actransit_gtfs.zip'
    
    # Automatically identify the busiest day and
    # read that in as a Partridge feed
    feed = pt.get_representative_feed(path)
    
    # Set a target time period to
    # use to summarize impedance
    start = 7*60*60  # 7:00 AM
    end = 10*60*60  # 10:00 AM
    
    # Converts feed subset into a directed
    # network multigraph
    G = pt.load_feed_as_graph(feed, start, end)
  3. Run Peartree via Docker Compose with Jupyter Notebook

    master

    You can run the Peartree environment using Docker Compose, which sets up a Jupyter Notebook service. The service builds from the local context, loads environment variables from a .env file, and maps the local directory to /code inside the container. The notebook is accessible on port 9797.

    version: "3"
    
    services:
      notebook:
        build:
          context: .
        env_file: .env
        command: jupyter notebook --config jupyter_notebook_config.py --allow-root
        volumes:
          - .:/code
          - /tmp:/tmp
        ports:
          - "9797:9797"