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).
- Program was implemented with Python 3.7 alongside Java
- It mains the following dependencies
Packages pandas requests datetime (included) multiprocessing (included) logging (included) - The Java side is what creates and runs the OTP server, and it needs to be running before running the Python script
- The current script has been implemented with it to execute the calculations in parallel
- 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
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
.
- Installing Java and Python
- You will need to make sure that the languages are installed
- Go here to install Java
- Go here to install Python
- 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.
- You will need to make sure that the languages are installed
- Collecting files
- You will need to collect the
otp.jar
file- Go here
- Navigate to the directory of the highest version number and download the file with extension
.shaded.jar
.
- 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
- 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
- the map file is downloaded from here go through the subregions until you find the map resolution that you need and download the
- You will need to collect the
- Modifying your pbf map file (not required)
- 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
- This website with the option CSV outputs the value needed for the -b flag
- You should shrink your pbf map file, so that you don’t need as much RAM to run the server
- Organize your files
- After you have gotten the necessary files, we will put the files in the following directory manner
- Create a directory called
otp
and it’ll contain agraphs
directoy and the.jar
file (2.i.) - The
graphs
directory will have another directory calledcurrent
- 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 theotp
directory, so OTP doesn’t overwrite when generating the map.
- Create a directory called
- After you have gotten the necessary files, we will put the files in the following directory manner
- Generate the OTP file
- 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 thecurrent
directory
- You will run the following command to generate an image of the map with the transit routes
- Start the OTP server
- 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.
- Access the OTP server
- 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
- The Python script,
- Response from the server
- 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.
- The response will give a json output. Where the current script takes the time values of the trip.
- If extra instruction is needed to setup OTP refer to this
- In the
util
directory of this repository is another instruction fileintro-otp.pdf
that comes from a different repository using OTP.