# Load cycle hire data from London and filter trips longer than 30 minutesSession 5: Routing
1 Introduction
Artificial Intelligence (AI) is rapidly transforming transport planning and data science. In this session, we explore how AI tools—particularly GitHub Copilot and large language models (LLMs)—can enhance productivity, code quality, and problem-solving in transport data analysis.
By the end of this session, you should be able to:
- Understand the role of AI in modern transport planning workflows
- Use GitHub Copilot effectively for R and Python coding
- Apply prompt engineering techniques for transport data tasks
- Recognize ethical considerations and limitations of AI tools
- Integrate AI-assisted coding into reproducible research practices
2 Why AI for Transport Planning?
Transport planning involves:
- Complex spatial data (networks, zones, flows)
- Large datasets (GPS traces, survey data, traffic counts)
- Interdisciplinary methods (statistics, optimization, visualization)
- Reproducibility requirements (code, documentation, version control)
AI tools can assist with:
- Code generation - Writing boilerplate, data transformations, plotting
- Debugging - Identifying errors and suggesting fixes
- Documentation - Generating comments, README files, and reports
- Learning - Explaining unfamiliar functions or concepts
- Optimization - Suggesting more efficient algorithms or approaches
3 GitHub Copilot for Transport Data Science
3.1 What is GitHub Copilot?
GitHub Copilot is an AI pair programmer that suggests code completions in your editor (VS Code, RStudio, etc.). It is powered by large language models trained on billions of lines of public code.
3.2 Setting Up Copilot
Students can access GitHub Copilot for free through the GitHub Student Developer Pack:
- Verify your student status at education.github.com
- Install the Copilot extension in your IDE (VS Code, RStudio, etc.)
- Sign in with your GitHub account
- Start coding - Copilot will suggest completions automatically
3.3 Practical Examples
3.3.1 Example 1: Loading and Filtering Transport Data
Prompt (as a comment in R):
Copilot might suggest:
library(dplyr)
library(readr)
# Load cycle hire data
cycle_data = read_csv("cycle_hire.csv")
# Filter trips longer than 30 minutes
long_trips = cycle_data |>
filter(duration_minutes > 30)3.3.2 Example 2: Creating an Interactive Map
Prompt:
# Create an interactive map showing bike share stations in Leeds using tmapCopilot might suggest:
library(sf)
library(tmap)
# Load bike share stations
stations = st_read("bike_stations.geojson")
# Create interactive map
tmap_mode("view")
tm_shape(stations) +
tm_dots(size = 0.5, col = "blue", alpha = 0.7) +
tm_basemap("OpenStreetMap")3.3.3 Example 3: Routing Analysis
Prompt:
# Calculate cycling routes between origin-destination pairs using stplanrCopilot might suggest:
library(stplanr)
library(sf)
# Create OD data
od = data.frame(
from_lon = c(-1.55, -1.56),
from_lat = c(53.80, 53.81),
to_lon = c(-1.54, -1.53),
to_lat = c(53.79, 53.78)
)
# Convert to spatial lines
od_sf = od_to_sf(od, crs = 4326)
# Route using CycleStreets API
routes = route_cyclestreets(od_sf, plan = "fastest")3.4 Best Practices for Using Copilot
3.4.1 ✅ Do:
- Write clear comments describing what you want
- Review suggestions carefully - Copilot can make mistakes
- Test generated code before using in production
- Use Copilot for learning - examine suggestions to understand new approaches
- Iterate on prompts - refine your requests if initial suggestions aren’t helpful
3.4.2 ❌ Don’t:
- Blindly accept suggestions without understanding them
- Share sensitive data in prompts (API keys, personal information)
- Rely solely on AI - develop your own understanding
- Ignore licensing - be aware of code provenance
- Skip testing - AI-generated code needs validation
4 Prompt Engineering for Transport Tasks
Effective prompts help AI generate better code:
4.1 Structure of a Good Prompt
- Context - What domain/dataset are you working with?
- Task - What do you want to accomplish?
- Constraints - Any specific requirements (packages, formats)?
- Example - Show desired input/output if possible
4.2 Example Prompts
4.2.1 Poor Prompt:
# Make a map4.2.2 Better Prompt:
# Create an interactive map of Leeds showing:
# - Bike share stations as blue circles
# - Cycle routes as green lines
# - Background OpenStreetMap tiles
# Use tmap and sf packages4.2.3 Excellent Prompt:
# Create an interactive map of Leeds bike infrastructure:
# Input: bike_stations.geojson (sf points), cycle_routes.geojson (sf lines)
# Requirements:
# - Use tmap in view mode
# - Stations: blue circles, size proportional to capacity
# - Routes: green lines, width 2px
# - Popup showing station name and capacity
# - OpenStreetMap basemap
# Output: Interactive HTML map5 AI Tools Beyond Copilot
5.1 ChatGPT / Claude for Transport Analysis
- Data exploration - “How do I analyze origin-destination matrices in R?”
- Debugging - Paste error messages for explanations
- Code review - Ask for suggestions to improve efficiency
- Documentation - Generate README files or method descriptions
5.2 AI-Powered Tools for Transport
- OpenAI Codex - Powers GitHub Copilot
- Cursor - AI-first code editor
- Copilot Chat - Conversational AI in VS Code
- Tabnine - Alternative code completion tool
- Amazon CodeWhisperer - AWS-focused AI assistant
6 Ethical Considerations
6.1 Bias and Fairness
- AI models are trained on historical data, which may contain biases
- Be critical when AI suggests transport solutions that may disadvantage certain communities
- Validate outputs against equity and accessibility principles
6.2 Data Privacy
- Avoid sending sensitive transport data (personal GPS traces, private surveys) to AI services
- Use anonymized or synthetic data for demonstrations
- Review your organization’s AI usage policies
6.3 Academic Integrity
- Cite AI tools when used significantly in your work
- Understand the code you submit - you are responsible for it
- Follow assignment guidelines on AI usage (this module encourages AI use!)
- Develop your skills - AI is a tool to enhance, not replace, learning
6.4 Limitations
- AI can generate plausible but incorrect code
- AI lacks domain expertise in specialized transport methods
- AI cannot validate results - you must check outputs
- AI may suggest outdated approaches or deprecated functions
7 AI Rating for This Module
This module actively encourages the use of AI tools including GitHub Copilot, ChatGPT, and similar assistants.
You should:
- Use AI to accelerate coding and problem-solving
- Learn from AI suggestions and explanations
- Document your AI usage in reflective sections
- Develop critical evaluation skills for AI outputs
We expect:
- You understand the code you submit (whether AI-generated or not)
- You can explain your methods and results
- You test and validate all code before submission
- You acknowledge significant AI contributions in your work
8 Practical Exercise: AI-Assisted Analysis
8.1 Task 1: Generate Data Loading Code
Use GitHub Copilot or ChatGPT to:
- Load origin-destination data for a UK city
- Filter for trips by a specific mode (e.g., cycling)
- Calculate summary statistics (total trips, average distance)
Prompt template:
# Load OD data from [city] and calculate cycling trip statistics
# Data format: CSV with columns origin, destination, mode, distance, trips
# Filter for mode == "bike" and calculate:
# - Total number of trips
# - Average trip distance
# - Top 5 origin zones by trip count8.2 Task 2: Create Visualization
Use AI to generate code for:
- An interactive map showing top cycling routes
- A bar chart of trips by hour of day
- A spatial heatmap of trip density
8.3 Task 3: Debug and Optimize
- Intentionally introduce an error in your code
- Use Copilot Chat or ChatGPT to diagnose and fix it
- Ask AI to suggest performance optimizations
9 Further Resources
9.1 Learning More
9.2 Transport-Specific AI Applications
- Traffic prediction - ML models for congestion forecasting
- Demand modeling - Neural networks for trip generation
- Route optimization - Reinforcement learning for vehicle routing
- Image analysis - Computer vision for traffic counting
- Natural language processing - Analyzing transport surveys and reports# Summary
AI tools like GitHub Copilot are transforming how we work with transport data:
- Accelerate coding with intelligent suggestions
- Learn faster by examining AI-generated examples
- Focus on analysis rather than syntax
- Maintain critical thinking - AI is a tool, not a replacement for expertise
Key Takeaways:
- Use AI to enhance productivity, not replace understanding
- Write clear prompts for better results
- Always review, test, and validate AI suggestions
- Be mindful of ethical considerations and limitations
- Embrace AI as part of modern reproducible research workflows
10 Homework
- Set up GitHub Copilot on your computer (free for students)
- Complete one analysis from a previous session using AI assistance - document what worked well and what didn’t
- Write a reflection (200-300 words) on how AI tools could benefit your transport planning work
- Share one insight you gained from using AI in the course discussion forum