Skip to content

moshobo/Transit-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transit-Simulator

Python code for simulating transit lines based on General Transit Feed Specification (GTFS) data.

100479_2LINE_2024-12-25

Inspiration

This project is inspired by @QuadMet on Twitter/X who created an animation of Portland, OR transit vehicles based off of GTFS data. They used the 'GTFS Map Generator' from Dan Snow (checkout some simulations of their the Chicago L Trains). However, that code was in R, and I don't know R, so I decided to redo it all in Python.

Usage

Example Usage

Here is an example of how to generate a transit simulation for Sound Transit's 1 Line at 8am on Dec 25, 2024.

python3 main.py -u https://www.soundtransit.org/GTFS-rail/40_gtfs.zip -d 2024-12-25 -s 08:00:00 -r 100479 2LINE -t SimulationFromURL

Here is an example of how to generate a transit simulation using the example file located in /data/gtfs-data/example/SoundTransit_042624_40_gtfs.zip, originally from Sound Transit

python3 main.py -f example/SoundTransit_071224_40_gtfs.zip -d 2024-07-25 -s 08:00:00 -r 100479 -t SimulationFromLocalFile

Command Line Arguments

The following flags can be passed when using the command line:

-f, --file - Specify a GTFS ZIP file to use. File should be in the /data/gtfs-data folder
-u, --url - Specify a URL to get a GTFS ZIP file.
-d, --date - Specify the start date of the simulation in YYYY-MM-DD format.
-s, --start-time - Specify the start time of the simulation in hh:mm:ss format. The timezone used is that of the transit agency specified in the GTFS feed.
-e, --end-time - Specify the end time of the simulation in hh:mm:ss format. The timezone used is that of the transit agency specified in the GTFS feed.
-r, --routes - Declare which Route IDs should be displayed in the simulation.
t, --title - The name to be used on the output GIF file. --station-labels - When specificed, shows station labels for all stations.

Examples

MBTA Red Line - Boston, MA

Red_2024-09-30

LA Metro A, C, and K Lines - Los Angeles, CA

python3 main.py -u https://gitlab.com/LACMTA/gtfs_rail/raw/master/gtfs_rail.zip -d 2024-12-25 -s 08:00:00 -r 807 803 801 -t LA Metro 807_803_801_2024-12-25

F Train - New York, NY

Uses some not-yet-committed code to only display select station names.

python3 main.py -f example/MTA_gtfs_subway_12222025.zip -d 2025-12-22 -s 09:00:00 -e 09:30:00 -r F -t F Train --station-labels F_2025-12-22

Sounder - Greater Seattle Area, Washington

Example of a simulation that uses the --station-label flag to display station names.

python3 main.py -u https://www.soundtransit.org/GTFS-rail/40_gtfs.zip -d 2025-12-22 -s 06:00:00 -e 10:30:00 -r SNDR_EV SNDR_TL -t Sounder North --station-labels SNDR_EV_SNDR_TL_2025-12-22

FAQs

How does it work?

Most of the heavy lifting is being done by gtfs_kit, which take in GTFS feed data and allows you to query it in a number of ways. The most important part of this is feed.locate_trips(), which is able to figure out where transit vehicles are at a given point in time.

Matplotlib's FuncAnimation is then used to animate the vehicles over an array of times

Where can I get GTFS data?

Most transit agencies will make their GTFS data availble for public download, so just try searching for " GTFS data". As an example, Sound Transit provides GTFS data for most transit agencies in the Seattle area on their website

About

Python code for simulating transit lines based on GTFS data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages