Skip to content

shailikadakia/traffic-light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚦 Intersection Insights: Analyzing Traffic Light Spacing & Accident Risk

Intersection Insights analyzes whether closely spaced traffic signals are associated with higher accident risk in urban environments.

The project combines geospatial analysis, statistical testing, and a desktop visualization tool to explore real-world traffic safety questions using open municipal data.

📍 Case studies: Ottawa (primary) and Brampton (motivating example)

Motivation

The idea originated from a real-life close call at an intersection in Brampton — where short spacing between traffic lights likely contributed to a missed red light. That experience sparked the question:

Does short spacing between traffic lights increase driver confusion and accident risk?

Research Question

Are intersections with traffic signals spaced less than 200 meters apart associated with higher accident rates?

Features

  • Interactive Desktop GUI

    • Tkinter-based interface
    • Drop pins to select locations
    • Adjustable distance thresholds and search radius
  • Custom Geospatial Analysis

    • Traffic signal clustering using DBSCAN
    • Distance-based flagging (25–200m)
  • Automated Statistical Testing

    • Chi-square test
    • Mann–Whitney U test
    • Stratified distance-group analysis
  • Geospatial Visualization

    • OSMnx + Folium maps
    • Accident heatmaps
    • Flagged intersection overlays

Application Preview

App Screenshot Figure 1: The interactive Tkinter GUI landing page, allows users to provide a distance between lights (meters) and a radius (meters)


App Screenshot Figure 2: Users can select a location to analysis by adding a marker


App Screenshot Figure 3: A selected location is shown as a red marker

Scope & Generalization

  • The methodology is city-agnostic and can be applied to any municipality with:

    • Open traffic signal data (OpenStreetMap)
    • Collision datasets with latitude/longitude
  • Ottawa is used as the primary case study because:

    • High-quality, publicly available accident data
    • Consistent formatting and precise geolocation

🔎 Cities like Toronto, Vancouver, or NYC could be analyzed using this same pipeline.

Methodology Overview

Step Description
1 Pull traffic signal data from OpenStreetMap
2 Cluster nearby signals into intersections using DBSCAN
3 Flag intersections with signals spaced 25–200m apart
4 Match accidents to intersections via lat/lon
5 Apply buffer analysis (25m, 50m, 100m, 200m)
6 Filter to signal-controlled intersections only
7 Run statistical tests (Chi-square, Mann–Whitney U)
8 Visualize flagged intersections + accident heatmaps

Key Findings

Hypothesis Result Statistically Significant?
Flagged vs. non-flagged intersections have more accidents ❌ Not supported p > 0.05
Closer spacing (e.g., 50–100m) leads to more accidents ❌ No trend p > 0.05
Flagged intersections more dangerous at night ❌ No difference in lighting conditions p > 0.05
Flagged intersections align with accident hotspots ⚠️ Mixed visual overlap Visual only

alt text Figure 4: Shows accident density (heatmap) with flagged intersections by spacing group.

  • 🔴 50–100m
  • 🟠 100–150m
  • 🟣 150–200m

Observation: No observations of area with many accidents


alt text

Figure 5: Bar chart comparing lighting conditions at flagged vs. non-flagged intersections.

Observation: Both have similar distributions — most accidents happen in daylight, not at night.


Takeaways

Traffic light spacing alone is not a predictor of higher accident rates in Ottawa. Lighting conditions and distance buckets (50–200m) did not significantly affect accident likelihood.


Statistical Analysis

Chi-Square Test

  • Tested whether flagged intersections had a higher chance of ≥1 accident.
  • Result: No significant difference (p > 0.05)

Mann-Whitney U Test

  • Tested whether accident counts per intersection differed across groups.
  • Result: No significant difference between flagged and non-flagged groups.

Stratification (50–100m, 100–150m, 150–200m)

  • Measured % of intersections with ≥1 accident in each distance group.
  • No distance group showed significantly more risk.

Lighting Condition Analysis

  • Compared lighting condition at time of accidents (day/dusk/night).
  • Both flagged and non-flagged intersections showed similar distributions.

Next Steps

  • Apply to other cities (Toronto, Vancouver, NYC)
  • Integrate accident text descriptions via NLP to detect signal confusion
  • Partner with municipalities for dashboard pilot
  • Explore human factors & visual psychology research to support design changes

Files Included

File Purpose
filtered_route_violations_50_200m.csv Intersections flagged for proximity
accidents_exactly_at_intersections.csv Accident matches at flagged intersections
flagged_intersections_with_closest_distance_group.csv Final grouped summary for analysis
ottawa_accident_heatmap_with_flagged_intersections.html Interactive map
accident_summary_by_distance_group.csv Stratified summary
flagged_intersection_vs_non_flagged_intersection_MannWhitneyU.csv Mann-Whitney test results

Installation (macOS, Windows, Linux)

1. Clone the Repository

git clone https://github.com/your-username/traffic-light-proximity.git
cd traffic-light-proximity

2. Create and Activate a Conda Environment

conda create -n traffic-geo python=3.10 -y
conda activate traffic-geo

3. Install Required Dependencies

conda install -c conda-forge \
  osmnx \
  geopandas \
  folium \
  matplotlib \
  shapely \
  networkx \
  scikit-learn \
  scipy \
  geopy \
  ipykernel -y
pip install tkintermapview

Note: tkinter is included with most Python distributions. If you encounter errors:

  • On macOS: brew install python-tk
  • On Ubuntu/Debian: sudo apt-get install python3-tk
  • On Windows: It should already be available.

▶️ Running the Script

From Command Line

python main.py

Running in VS Code

  1. Open the folder in VS Code.
  2. Press Ctrl + Shift + P → search for Python: Select Interpreter.
  3. Choose the traffic-geo conda environment.
  4. Run your script from the integrated terminal.

Output Files

All generated files (CSV summaries, heatmaps, charts, maps, and GeoJSON) will be saved to your selected export directory. Key outputs include:

  • ottawa_traffic_lights.geojson
  • filtered_route_violations_50_200m.csv
  • accident_counts_per_intersection.csv
  • ottawa_map.html (folium interactive map)
  • lighting_condition_bar_chart.png
  • Summary tables and stratified analysis CSVs

About

Python project analyzing traffic light spacing and its correlation with accident rates in Ottawa. Uses OSMnx, GeoPandas, and folium to identify intersections, measure distances, cluster signals, and visualize high-risk areas. Includes statistical testing (chi-square, Mann-Whitney U) to explore accident associations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors