The library sum_gtfs_geojson
aims to facilitate the experimentation with Living Labs data within the context of SUM project. The data used within the repository is publicly available by public transport providers.
The library proposes the following features :
- load public transport network data for a Living Lab
- create hexagonal grid for the network
- restrict the perimerer to a given radius in KM
- restrict the perimeter within the country (ignore stops in neighbouring countries)
- convert data to GeoJson
- Demo to display data in map, with HTML/JS and Leaflet library for map display
- Living Lab available : GENEVA
- Read the API documentation sum_gtfs_geojson for complete parameter configuration.
- Check the dynamic map demo with preprocessed data. The files read by this demo were generated by this library, with different parameters.
- Jupyter script to run the code locally. First run project dependencies installation, check 1. Install dependencies and build package
In Python environment, it is a good practice to isolate your project in an environment. The following documentation uses pipenv
to handle packages installation the local environment.
Download the built package available at the dist folder.
Then install from local file.
Install from local file :
pipenv install $PATH_TO_FILE/sum_gtfs_geojson-0.1.0-cp39-cp39-macosx_10_9_universal2.whl
Or install from Github link :
pipenv install https://inria.github.io/inocs-sum-gtfs-geojson/dist/sum_gtfs_geojson-0.1.0-cp39-cp39-macosx_10_9_universal2.whl
Instantiate the class SharedMobilityManager
with the desired configuration.
Refer to API documentation sum_gtfs_geojson for full details on the parameters and full data classes data.
NOTE: only the items specified in the data_types list will be included. If data_types is None, then all data items are generated by default.
from sum_gtfs_geojson import SharedMobilityManager, LivingLabsCity, DataType
data_manager = SharedMobilityManager(city=LivingLabsCity.GENEVA,
data_types=[
DataType.ITINERARIES,
DataType.STOPS,
DataType.BIKE_STATIONS,
DataType.BIKE_TRIPS,
DataType.HEX_GRID
],
restrict_country_boundaries=True,
distance_radius_km=10,
grid_resolution=8
)
To access the data, retrieve from the manager. The data is within a UrbanMobilitySystem
class.
gva_data = data_manager.get_data()
pt_stops = gva_data.public_transport.stops
print(f"There are {len(pt_stops)} stops in the dataset")
pt_lines_itineraries = gva_data.public_transport.itineraries
print(f"There are {len(pt_lines_itineraries)} itineraries in the dataset")
pt_ridership = gva_data.ridership
print(f"There are {len(pt_ridership)} ridership records in the dataset")
bike_stations = gva_data.bike_stations
print(f"There are {len(bike_stations)} bike stations in the dataset")
bike_trips = gva_data.bike_trips
print(f"There are {len(bike_trips)} bike trips in the dataset")
hex_grid_cells = gva_data.hex_grid.cells
print(f"There are {len(hex_grid_cells)} hexagons in the dataset")
Finally, you can save the results in geojson files. These geojson files can then be used as input with GeoPandas library
# Save the data to GeoJSON files, specifying the output directory as argument
gva_data.save_to_geojson("my/folder")
You will find the geojson files for every data started by the manager in specified folder my/folder
Create environment and install pipenv, then install dependencies. Finally, build the package.
python3 -m venv env && source env/bin/activate && pip install pipenv && pipenv install --dev
# Build the wheel
python -m build
# Generate the docs
python build_docs.py
# OPTIONAL : clean and reset the build files
rm -rf build dist *.egg-info
The compiled wheel package .whl file will be at ./dist
folder.
The documentation will be at ./docs
folder.
Ensure you have Python installed (recommended: Python 3.8+).
- Clone the repository
- Create an environment
- Install the necessary packages
- Create experiments and run the models
- Analyze the results
Clone the repository using the following command:
git clone https://github.com/INRIA/inocs-sum-gtfs-geojson.git
Check the Python packaging user guide for more information on how to manage dependencies in Python.
On Debian protected environment, create a virtual enviornment first :
python3 -m venv env && source env/bin/activate && pip install pipenv
Install library pipenv to handle the environment and the dependencies.
pip install pipenv
python -m http.server 8080
Then go to page in browser : http://localhost:8080