/gtfs_segments

Primary LanguagePythonMIT LicenseMIT

Contributors Forks Stargazers Issues MIT License


Logo

GTFS Segments

A fast and efficient library to generate bus stop spacings

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

map

Transit agencies use the General Transit Feed Specification (GTFS) to publish transit data. More and more cities across the globe are adopting this GTFS format to represent their transit network. The GTFS feed can be downloaded from @transitfeeds and @mobility data. The GTFS segments is a concise representation of GTFS files removing unnecessary repetitions in the data. We do that by considering the services offered only the busiest day(in the data) and representing data in the form of segements.

(back to top)

Getting Started

Prerequisites

The major dependencies of this library are the following packages.

  • numpy
  • shapely
  • pandas
  • geopandas
  • partridge
  • matplotlib
  • contextily

The detailed list of package dependencies can be found in requirements.txt

Installation

Option A

Use pip to install the package. Windows users may have to download and install Microsoft Visual C++ distributions. Follow these instructions.

pip install gtfs-segments

Option B

  1. Clone the repo
    git clone https://github.com/UTEL-UIUC/gtfs_segments.git
  2. Install geopandas using the following code. Read more here
    conda create -n geo_env
    conda activate geo_env
    conda config --env --add channels conda-forge
    conda config --env --set channel_priority strict
    conda install python=3 geopandas
  3. [Optional] Download modified version of partridge library and install it manually.
    git clone https://github.com/praneethd7/partridge
    cd partridge
    python setup.py install
  4. Install requirements using
    pip install -r requirements.txt
  5. Install the gtfs_segments package
    cd gtfs_segments
    python setup.py install

(back to top)

Usage

Import whole package using

import gtfs_segments

Get GTFS Files

Automated Download

Get latest GTFS source list from Mobility Database Catalogs

from gtfs_segments import fetch_gtfs_source
sources_df = fetch_gtfs_source()
sources_df.head()
sources

Download the latest GTFS source files

from gtfs_segments import download_latest_data
download_latest_data("output_folder")

Manual Download

Download the GTFS .zip files from @transitfeeds or @mobility data.

Get GTFS Segments

from gtfs_segments import get_gtfs_segments
segments_df = get_gtfs_segments("path_to_gtfs_zip_file")
segments_df
data

Plot Histogram

from gtfs_segments import plot_hist
plot_hist(segments_df)
histogram

Optionally save figure using

plot_hist(segments_df,file_path = "spacings_hist.png",save_fig = True)

Get Summary Stats

from gtfs_segments import summary_stats
summary_stats(segments_df,max_spacing = 3000,export = True,file_path = "summary.csv")
histogram

Dowload Data

Download the data as either .csv or .geojson

from gtfs_segments import export_segments
export_segments(segments_df,'filename', output_format ='geojson')
# Get csv without geometry
export_segments(segments_df,'filename', output_format ='csv',geometry = False)

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Saipraneeth Devunuri - @praneethDevunu1 - sd37@illinois.edu

Project Link: https://github.com/UTEL-UIUC/gtfs_segments

(back to top)

Acknowledgments

  • Parts of the code use the Partridge library
  • Shoutout to Mobility Data for compiling GTFS from around the globe and constantly maintaining them

(back to top)