MyNixOS website logo
Description

Calculate Air Travel Emissions.

A handy tool to calculate carbon footprints from air travel based on three-letter International Air Transport Association (IATA) airport codes or latitude and longitude. footprint first calculates the great-circle distance between departure and arrival destinations. It then uses the Department of Environment, Food & Rural Affairs (DEFRA) greenhouse gas conversion factors for business air travel to estimate the carbon footprint. These conversion factors consider trip length, flight class (e.g. economy, business), and emissions metric (e.g. carbon dioxide equivalent, methane).

R-CMD-check Codecov testcoverage CRANstatus

footprint

The goal of footprint is to calculate carbon footprints from air travel based on IATA airport codes or latitude and longitude.

Installation

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("acircleda/footprint")

Data and Methodology

Package footprint uses the the Haversine great-circle distance formula to calculate distance between airports or distance between latitude and longitude pairs. This distance is then used to derive a carbon footprint estimate, which is based on conversion factors from the Department for Environment, Food & Rural Affairs (UK) 2019 Greenhouse Gas Conversion Factors for Business Travel (air): https://www.gov.uk/government/publications/greenhouse-gas-reporting-conversion-factors-2019.

Example Usage

Load footprint using

library(footprint)

Using Airport Codes

You can use pairs of three-letter IATA airport codes to calculate distance. This function uses the airportr package, which contains the data and does the work of getting the distance between airports. Note: the airportr package offers a number of useful functions for looking up airports by city or name and getting the IATA airport codes.

Calculating a Single Trip

The example below calculates a simple footprint estimation for an economy flight from Los Angeles International (LAX) to Heathrow (LHR). The estimate will be in CO2e (carbon dioxide equivalent, including radiative forcing). The output is always in kilograms.

airport_footprint("LAX", "LHR", "Economy", "co2e")
#> [1] 1312.696

If there is a layover in Chicago, you could calculate each leg of the trip as follows:

airport_footprint("LAX", "ORD", "Economy", "co2e") + 
  airport_footprint("ORD", "LHR", "Economy", "co2e")
#> [1] 1387.167

Calculating More than One Trip

We can calculate the footprint for multiple itineraries at the same time and add to an existing data frame using mutate. Here is some example data:

library(tibble)
#> Warning: package 'tibble' was built under R version 4.0.3

travel_data <- tibble(
  name = c("Mike", "Will", "Elle"),
  from = c("LAX", "LGA", "TYS"),
  to = c("PUS", "LHR", "TPA")
)
namefromto
MikeLAXPUS
WillLGALHR
ElleTYSTPA

Here is how you can take the from and to data and calculate emissions for each trip. The following function calculates an estimate for CO2 (carbon dioxide with radiative forcing).

namefromtoemissions
MikeLAXPUS1434.663
WillLGALHR825.497
ElleTYSTPA136.721

From Latitude and Longitude

If you have a list of cities, it might be easier to calculate emissions based on longitude and latitude rather than trying to locate the airports used. For example, one could take city and state data and join that with data from maps::us.cities to quickly get latitude and longitude. They can then use the latlong_footprint() function to easily calculate emissions based on either a single itinerary or multiple itineraries:

Calculating a Single Trip

The following example calculates the footprint of a flight from Los Angeles (34.052235, -118.243683) to Busan, South Korea (35.179554, 129.075638). It assumes an average passenger (no flightClass argument is included) and its output will be in kilograms of CO2e (the default)

latlong_footprint(34.052235, -118.243683, 35.179554, 129.075638)
#> [1] 1881.589

Calculating Multiple Trips

You can use mutate to calculate emissions based on a dataframe of latitude and longitude pairs.

Here is some example data:

travel_data2 <- tribble(~name, ~departure_lat, ~departure_long, ~arrival_lat, ~arrival_long,
         # Los Angeles -> Busan
        "Mike", 34.052235, -118.243683, 35.179554, 129.075638,
        # New York -> London
        "Will", 40.712776, -74.005974, 51.52, -0.10)
namedeparture_latdeparture_longarrival_latarrival_long
Mike34.05224-118.2436835.17955129.0756
Will40.71278-74.0059751.52000-0.1000

And here is code to apply it to a dataframe:

travel_data2 %>%
  rowwise() %>%
  mutate(emissions = latlong_footprint(departure_lat,
                                       departure_long,
                                       arrival_lat,
                                       arrival_long))
namedeparture_latdeparture_longarrival_latarrival_longemissions
Mike34.05224-118.2436835.17955129.07561881.589
Will40.71278-74.0059751.52000-0.10001090.260
Metadata

Version

0.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows