A R(API)D assessment of travel carbon emissions around the world | by Kyle Baranko | Towards Data Science

As a climate-conscious consumer, I’ve often wondered about the environmental impact of my routine travel from the East Coast to Salt Lake City and back. After seeing one of many recent headlines highlighting air travel’s surprisingly high rates of carbon emissions, I wondered: would taking a train, bus, or driving a car be better for the planet than flying?
Thankfully, I stumbled across an easy-to-use API, built by London programmer Tobe-Nicol, that allows you to compare carbon footprints of various modes of travel. Prepared to put price, comfort, and convenience aside for the sake of the planet, I pulled from this API to compare my options and raised a host of questions about the energy intensity of travel along the way.
What are the API parameters?
I found this API on Twitter and was able to do some quick experimenting in a Jupyter Notebook thanks to the straightforward documentation. The API has the following parameters:
Activity (required): this can be either the fuel consumption of a vehicle or the distance travelled in miles. Since we’re comparing different modes of transportation, I will set this parameter as “3,910” — the roundtrip length, in miles, of travel from New York to Salt Lake City.
activityType: this parameter denotes the value of the integer entered above.
mode: refers to the mode of transportation. There are several options to choose from: dieselCar, petrolCar, anyCar, taxi, economyFlight, businessFlight, firstclassFlight, anyFlight, motorbike, bus and transitRail.
fuelType: this pairs with the modes listed above: motorGasoline (also known as petrol), diesel, aviationGasoline and jetFuel.
I assumed that all commercial flights use jet fuel but paired the parameter “anyFlight” with aviation gasoline to see if there is a major difference in carbon footprint between the two fuel types. I also assigned “dieselCar”, “bus” and “transitRail” to diesel fuel; I assumed all other modes use gasoline.
I began by putting these parameters into two lists of equal length, associating each mode of transportation with each fuel type. I also deleted “anyCar” from the list because it overlaps with “taxi” and “petrolCar” and seemed redundant. Here are the lists:
list_of_modes = ['dieselCar', 'petrolCar', 'taxi', 'motorbike', 'bus', 'transitRail', 'economyFlight', 'businessFlight', 'firstclassFlight', 'anyFlight' ]          list_of_fuels = ['diesel', 'motorGasoline', 'motorGasoline', 'motorGasoline', 'diesel', 'diesel', 'jetFuel', 'jetFuel','jetFuel', 'aviationGasoline']
Rather than manually enter each parameter into the system, I wrote a function to loop through both lists and output the API request as a dictionary. After importing the necessary packages, I defined the function, inserted the lists and packaged the output as a dictionary (for complete code, please see the jupyter notebook attached to this blog post).
#import necessary packages import requestsimport jsonimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltimport numpy as np%matplotlib inline #use carbon_slc_nyc function to create dictionary with mode of #transportation as keys and of carbon footprint as valuescarbon_footprint = {}carbon_footprint = carbon_slc_nyc(list_of_modes, list_of_fuels)
With the output packaged as a dictionary, I turned it into a pandas dataframe, renamed the columns to more appropriate titles, and converted the ‘Carbon Footprint’ column data into floats in preparation for plotting.
df = pd.DataFrame(list(carbon_footprint_ground.items()))df.rename(columns = {0 :'Type of Transport'}, inplace = True)df.rename(columns = {1 :'Carbon_Footprint'}, inplace = True)df['Carbon_Footprint'] = df['Carbon_Footprint'].astype('float64')
With this DataFrame, I plotted a bar graph to visualize how much carbon each mode of transportation emits over the course of a 3,910-mile journey.
plt.figure(figsize=(10,5))sns.barplot(x=df_ground['Type of Transport'], y=df_ground['Carbon_Footprint'])plt.xticks(rotation=45)
Interesting. If I’m choosing a mode of transportation with average fuel consumption, taking a bus, train, or economy flight is my best bet. However, the results create a lot of questions. This data satisfies the logical explanation that driving your own car is less efficient than sharing a ride and spreading total emissions of a vehicle over many people, like on a plane, bus, or train. But why is getting a first-class ticket on a flight so much worse than an economy-ticket? And why does your average bus have the lowest carbon footprint for this trip? Besides electric or LNG-fueled municipal busses, I don’t think diesel-fueled Greyhound or Concord Coach busses are very climate-friendly.
I thought this distribution would be unique to the U.S and used another parameter to compare average mode of transport carbon footprint between countries. The API calls for a ‘usa’, ‘gbr’, and ‘def’ input to compare footprints between the United States, United Kingdom, and global average. Although this new parameter only allowed me to compare with two other options, I wanted to see if travelling 3910 miles outside the US would change the bus’s climate dominance.
The world averages are about the same as in the US, but in the UK, busses are significantly more polluting. All air travel is about the same, suggesting that this emissions calculator standardizes emissions globally, which makes sense given the international nature of the industry. In the UK, travelling via rail or economy flights are my best bet.
How are the emissions calculated?
After looking over these results, I checked the documentation further to find out how emissions are calculated. There are two methods. For the code above, the API used the average emissions factor for a vehicle in a given country and adjusted the result based on the distance travelled parameter. However, the API also offers a more specific calculation using the specific fuel efficiency of the vehicle. In this method, the API multiplies total fuel consumed by the emissions factor for that fuel. The emissions factor is usually provided by a government organization and is recommended by the IPCC.
Total Emissions = Fuel Emission Factor * Fuel Usage
To get a more accurate assessment of my travel options, I needed to know how much energy the engine of each mode of transportation consumes. I picked three top options from the first descriptive analysis and limited the output to results in the US. In the next API call, I incorporated the fuel efficiency of my mom’s Suburu (33 miles per gallon of gasoline), a typical Greyhound bus (6 miles per gallon of diesel fuel), and the miles per gallon, in jet fuel, of an Airbus A220 100.
The Airbus fuel consumption was challenging because the official Wikipedia fuel economy data is listed in either kg/km or miles per seat gallon, meaning I either had to convert the kg/km to mpg or multiply the miles per seat gallon by the number of seats in an Airbus A220 100 (I assumed I’d have a full flight both ways — SLC and NYC are popular destinations). I wasn’t sure if the API’s carbon calculator automatically converts the fuel consumption parameter into miles per seat gallon for public transportation, so I called the data both ways, entering both miles per gallon and miles per seat gallon in fear of counting twice. It made for an interesting contrast anyways.
From a quick Google search, I found that Airbus A220s can have between 120–160 seats. I went with 140 seats.
#miles per seat gallon divided by seats on the plane A220_mpg_A = (85.6 / 140) suburu_mpg_A = 33 greyhound_mpg_A = 6A220_gal_A = 3910/A220_mpg_Asuburu_gal_A = 3910/suburu_mpg_Agreyhound_gal_A = 3910/greyhound_mpg_Alist_gallons_A = [suburu_gal_A, greyhound_gal_A, A220_gal_A]list_fuel_type_A = ['motorGasoline', 'diesel', 'jetFuel']#call API and create dataframe carbon_footprint_A = {}carbon_footprint_A = carbon_fuel(list_gallons_A, list_fuel_type_A) df_A = pd.DataFrame(list(carbon_footprint_A.items()))df_A.rename(columns = {0 :'Fuel_Type'}, inplace = True)df_A.rename(columns = {1 :'Carbon_Footprint'}, inplace = True)df_A['Carbon_Footprint'] = df_A['Carbon_Footprint'].astype('float64')#now adjust to miles per seat gallonA220_mpg_B = 85.6 suburu_mpg_B = 33 #adjusting to miles per seat gallon with 55 seatsgreyhound_mpg_B = 6 * 55 A220_gal_B = 3910/A220_mpg_Bsuburu_gal_B = 3910/suburu_mpg_Bgreyhound_gal_B = 3910/greyhound_mpg_Blist_gallons_B = [suburu_gal_B, greyhound_gal_B, A220_gal_B]list_fuel_type_B = ['motorGasoline', 'diesel', 'jetFuel']#call API and create dataframecarbon_footprint_B = {}carbon_footprint_B = carbon_fuel(list_gallons_B, list_fuel_type_B)df_B = pd.DataFrame(list(carbon_footprint_B.items()))df_B.rename(columns = {0 :'Fuel_Type'}, inplace = True)df_B.rename(columns = {1 :'Carbon_Footprint'}, inplace = True)df_B['Carbon_Footprint'] = df_B['Carbon_Footprint'].astype('float64')
Here are the results:
After plotting the results from the first API call, it is clear that flying my own plane from New York to Salt Lake City and back would have a high environmental impact, as would driving my own Greyhound bus. Driving my mom’s Suburu is obviously more efficient for one person because it is way smaller.
However, when spreading the high MPG and carbon emissions across a plane or bus full of people, it is clear that again, the bus has the lowest carbon footprint. Although a plane carries more than twice as many people as the bus and moves from NYC to SLC much faster than any sort of road travel, the bus has the benefit of using a lower-polluting and less energy-dense fuel while still spreading the climate cost among 55 people. My mom’s Suburu, while having one of the most efficient engines on the gasoline-powered automobile market, can’t compare — even if I picked up two hitchhikers (I did the math).
Conclusion
If limiting carbon emissions on an individual basis is your top priority, don’t drive. Although it requires more energy (and more carbon) to move a bus or commercial airliner across the country, you’re spreading the climate cost across many more people when you elect to travel by train, bus, or air. This analysis could be improved with more nuance and a granular dataset, but it is clear that on a high-level, incentivizing more people to get from A to B in larger vehicles should play a role in formulating decarbonization strategy.
Github link: https://github.com/kbaranko/SLC-to-NYC-Carbon-Costs