Flight Impact: Adding Carbon Emissions to the Itinerary
Building an interactive web app to empower climate-conscious air travelers
For many in the U.S., air travel is an ingrained feature of life. Whether to visit family for the holidays, attend a conference, or take a quick vacation, many of us prepare for takeoff without ever considering that our flight may have non-monetary costs. What’s often missing from our travel plans is an investigation of our trip’s carbon emissions. While environmental impact goes unconsidered for most travelers, the European Federation for Transport and Environment warns that as aviation emissions double or potentially triple by 2050, the industry could consume up to 1/4 our global carbon budget.
There are many very insightful arguments as to why a focus on individual ‘carbon footprints’ is not an effective way to curb the climate crisis. However, aviation does pose an interesting opportunity. In 2018, only 11% of the global population took a flight, and a mere 1% was responsible for 50% of aviation emissions. This means that individuals in this small minority have a unique ability to make an impact with relatively small behavioral changes.
With this in mind, I approached my final project of the METIS data science bootcamp in hopes of building something that empowers consumers to educate themselves and make informed decisions around travel. And so, Flight Impact was born! (Click the link at the bottom of this article to check it out!)
The Assignment
In this project, my classmates and I were challenged to build an entire data pipeline, from API to interactive web app. The pipeline behind Flight Impact is as follows: Call the Climatiq API (CC BY-SA 4.0), clean the data in Google Colab, store it in MongoDB, and finally manipulate it in a .py file that is used to launch my Streamlit App from Github.
The Climatiq API provides emissions calculations for a variety of activities, from passenger travel to shipping. When given a combination of 2 airports, the API returns the CO2 emissions in kilograms for a single economy passenger, one way, between the destinations. I was able to specify which calculation standard I wanted to use, and I chose the U.S. EPA calculation for short-, medium-, and long-haul flights to ensure repeatability. Using a list of the world’s large airports (serving millions of passengers per year) and the Python requests library, I automated API requests for 180,000 pairs of global destinations.
Next, I cleaned my data in Google Colab, adding some features that are useful to the front-end user experience such as the airport’s full country name (rather than just a code) and a calculation of the flight’s emissions in tons. From Google Colab, I used pymongo to insert the cleaned data into a MongoDB database, hosted on CleverCloud.
Building the app in Streamlit
The final step of the pipeline was to build out the user experience of Flight Impact in a .py file. Streamlit, a platform that turns Python data scripts into web apps, allows you to launch an app directly from a file in a Github repo. You simply need to add some Streamlit commands to your code to specify features, such as drop down menus and maps (here’s a link to my Streamlit .py file if you are looking for an example). In this process, I learned not to underestimate the importance of Streamlit’s caching feature. Streamlit re-runs your script every time the user changes something on the page, but adding a simple @st.cache command ahead of your functions will tell the app to only re-run that function if the inputs or the function itself have changed. This helps the app move faster and use less memory.
Introducing: Flight Impact
When a user visits Flight Impact, the goal is to empower them to explore their options and leave as a more informed consumer. The user can:
- View all global flights from their home city, and the associated carbon emissions of each
- Filter by origin country or city, destination country or city, or an emissions limit, to compare a variety of routes
- Depending on whether their route is already decided, view less impactful alternatives or ways to make their chosen flight purchase more fuel efficient, such as traveling economy, avoiding layovers, and only taking flights that are filled to capacity
As individuals look for ways to take part in a solution to the climate crisis, our travel habits can make a difference. Moving forward, let’s make carbon emissions just as important a part of the trip planning process as getting the window seat.
Try the app yourself here! Note: this link uses the free version of Streamlit, which may go over the usage limit after some time. If that’s the case, the video below also shows the Flight Impact experience.
_To dig into my code or presentation for this project, please see the project repo._
Share This Article
Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.
Write for TDS