qunetin / network-commute-transit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Network Transit

This project calcultes the network travel time between a source and destination point for transit routes. It uses Open Trip Planner (OTP) software to calculate the time difference.

Project was created by David James for the Institute of Transportation Studies (ITS).

Design

  1. Program was implemented with Python 3.7 alongside Java
  2. It mains the following dependencies
    Packages
    pandas
    requests
    datetime (included)
    multiprocessing (included)
    logging (included)
  3. The Java side is what creates and runs the OTP server, and it needs to be running before running the Python script
  4. The current script has been implemented with it to execute the calculations in parallel

Files

README.org
documentation on current project
networkTransit.py
the script designed to run concurrently with the software
util/intro-otp.pdf
another tutorial that descibes how to use OTP

Installing and Setting Up

Before beginning, you will need to run any bash commands from your terminal. If you’re running a Mac, search for the application called terminal.

  1. Installing Java and Python
    1. You will need to make sure that the languages are installed
      1. Go here to install Java
      2. Go here to install Python
      3. When installations are complete run the following commands
        # this should Python 3.#.# showing your current version
        python3 --version
        
        # similar to the previous command
        # you should see Openjdk #.#.#
        java --version
                    
        NOTE
        If you are getting an error, then the installation was not done correctly. You will need to troubleshoot this step before proceeding.
  2. Collecting files
    1. You will need to collect the otp.jar file
      1. Go here
      2. Navigate to the directory of the highest version number and download the file with extension .shaded.jar.
    2. You will need to collect the necessary GTFS files, so OTP knows what transit routes it will generate
      NOTE
      GTFS files must be zipped up, and all its contents should be in the root of the zip archive
    3. You will need the map file, so OTP knows what area to generate with the transit routes
      • the map file is downloaded from here go through the subregions until you find the map resolution that you need and download the .osm.pbf file
  3. Modifying your pbf map file (not required)
    1. You should shrink your pbf map file, so that you don’t need as much RAM to run the server
      # this is an example of the command that can shrink the pbf file
      # you will need to install osmconvert if your system doesn't have it yet
      osmconvert socal-latest.osm.pbf -b=-118.9647,33.1005,-116.7894,34.9847 --complete-ways -o=socal.pbf
      
      # this example is has the similar coordinates I used to shrink socal-latest
      # to mainly cover LA county and some of its exterior
              
      1. This website with the option CSV outputs the value needed for the -b flag
  4. Organize your files
    1. After you have gotten the necessary files, we will put the files in the following directory manner
      1. Create a directory called otp and it’ll contain a graphs directoy and the .jar file (2.i.)
      2. The graphs directory will have another directory called current
      3. The current directory will contain your GTFS files (2.ii.) and the pbf map file (2.iii. or 3.i.)
        NOTE
        The current directory must contain only ONE pbf file, if you decided to shrink the original file, move the original somewhere outside of the otp directory, so OTP doesn’t overwrite when generating the map.
  5. Generate the OTP file
    1. You will run the following command to generate an image of the map with the transit routes
      # make sure you are in the otp directory
      # the following command generates the object file
      java -Xmx3G -jar otp.jar --build graphs/current
      
      # the -Xmx3G flag decideds how much RAM to use to generate the image
      # 3G was the needed amount for generating LA County with its transit network
      # if this command crashes it could be due to not enough RAM being allocated
              
      NOTE
      • This takes about 10 minutes to build the file depending on your machine.
      • You should see a Graph.obj file in the current directory

Executing

  1. Start the OTP server
    1. This command will start up the server
    # Starting up the OTP server requires the following command
    java -Xmx3G -jar otp.jar --router current --graphs graphs --server
        
    NOTE
    You will see Grizzly server running near the end, meaning that the server is up.
  2. Access the OTP server
    1. The Python script, networkTransit.py, has a function that will call the server and collect the responses
      # import the function from the .py file
      from networkTransit import mp_transitDriver
      
      # you will need the pandas library
      import pandas as pd
      
      data = pd.read_csv('someData.csv')
      
      # the following is the function header for the input and how the data needs to be organized
      # If you're data has extra columns or is not formatted correctly
      # you may get errors or incorrect output
      # for more information on the script check the module for the other comments
      
      # ################################################################################
      # function mp_transitDriver
      # A function designed to run mp_transitTime when given a set
      # of data to process.
      # @param: DataFrame(
      #            Series, data['Trip ID']    - int,   Unique ID code for trip
      #            Series, data['Source Lat'] - float, source latitude
      #            Series, data['Source Lon'] - float, source longiutde
      #            Series, data['Dest Lat']   - float, destination latitude
      #            Series, data['Dest Lon']   - float, destination longitude
      #            Series, data['time']       - str,   time to arrive by the destination
      #                                         format can be 15:42:1 or 3.42pm
      #            Series, data['date']       - str,   date of the trip
      #                                         format can be 11/12/18 or 11-12-18)
      # @return: NONE
      mp_transitDriver(data)
      
      # the output from this will create new CSV files which are the results of the output
      # depending on how large your sample of data is, this can take several hours to run
              
  3. Response from the server
    1. The response will give a json output. Where the current script takes the time values of the trip.
      Remark
      For more documentation on what OTP can output refer to this for a description of their JSON response.

Extra Help

  1. If extra instruction is needed to setup OTP refer to this
  2. In the util directory of this repository is another instruction file intro-otp.pdf that comes from a different repository using OTP.

About


Languages

Language:Python 100.0%