Skip to content

floriandierickx/emission-budgets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOI

Concept

Visualising national and personal remaining carbon budgets interactively, based on the blogpost and dataset from Stefan Rahmstorf. This could be further extended with different types of carbon budget calculation.

Data sources

The original dataset is extended with EDGAR historical emissions data from JRC and World Bank Population data. The combined dataset that is used in the application can be found in this google sheet (imported sheet = import). To be able to display the historical EDGAR emission data for each country, the country order in the original excel sheet has been changed a little bit.

Structure of the code

Note: the app uses Dash and Plotly to create an interactive figure. The script app.py is divided in 3 main parts:

  1. Data import and definition of global variables : code link
    • df_budget = pd.read_csv("data.csv") : importing the data.csv file, which is the same as the input sheet in the google sheets
    • definition of global variables:
      • global_budget_2016 = 580 + 80 : used for testing, not reused in the code
      • global_emissions = 40 : global emissions in 2016 (Gt CO2), taken from the google sheets, cell E16
      • global_per_capita_emissions = 5.4 : global per capita emissions in 2016 (t CO2), taken from the google sheets, cell E18
  2. The app layout with text, interative inputs and outputs : code link. It contains
    • A country-selection box, id = country-dropdown to be selected from df_budget.country
    • Global carbon budget input, id = carbon-budget to stay within the range of 50 and 2500
    • Global reach of global carbon budget paragraph :, id = global-reach
    • Country carbon budget and timeline, id = country-carbon-budget
    • a bar chart (id: emission-graph) displaying:
      • Historical emissions : code link
      • "Recent" (2018/2019) emissions : code link
      • Future linear decrease in country carbon budget : code link
    • Personal carbon emissions projection : code link
    • Credits and data : code link
  3. A series of 'callback' functions to update the above app layout based on changing inputs, code link :
    • Update of the country emission graph (id: emission-graph) based on country : code link
    • Update of the personal emission graph (id: emission-graph) based on country : code link
    • Calculation of the global reach of the given global emission budget, country-specific budgets, country-specific carbon budget (2016), country-specific carbon budget from 2019 onwards, years left at constant emissions or linearly decreasing emissions code link

Calculations

  • The country-specific annual emission in 2017, 2018 or 2019: assumed to have stayed the same as in 2017, as is this the latest data available for all the countries in the JRC EDGAR historical emission database (and 2019 is almost over). This yearly emission data for a specific country can be taken directly from the imported dataset using

    round(df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0], 2),

    (see line 299)

  • The country-specific emission budget that can be used from the start of 2016 onwards (year of the Paris agreement). This value can be calculated from the data using (see lines 288 to 293, based on the premise that the budget is distributed on an equal per capita basis at the start of 2016.

    round(((carbon_budget + 80)  # carbon budget country
        * df_budget.loc[df_budget['country'] == selected_country,   'total_kton_CO2'].values.flatten().tolist()[0])
        / df_budget.loc[df_budget['country'] == selected_country,   'per_capita_CO2'].values.flatten().tolist()[0]
        / global_emissions[0]
        * global_per_capita_emissions[0]
        / 1000, 2),

    This value is calculated as: Screenshot 2019-09-30 at 17 53 58

    (taken from the spreadsheet of Stefan Rahmstorf - for example cell E25 for Afghanistan in the original sheet. I hope I interpreted it here correctly)

  • The country-specific emission budget that is left to deplete from 2020 onwards, accounting for the 4 years that have already passed: this can be calculated by using the above 2016-country emission budget and deducing the 2016 emissions + three yeras of constant 2017-emissions - 2018 and 2019 are assumed to have stayed constant as 2017 is the latest data available in the EDGAR dataset (see lines 305-310), by substracting

    - (df_budget.loc[df_budget['country'] == selected_country, '2016'].values.flatten().tolist()[0] + (3 * df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0]))
  • From then it is straightforward to calculate the remaining years left at constant emissions from 2020 onwards for each country, by dividing the remaining carbon budget from 2020 onwards by a constant 2017 (or 2018/2019) emission level, as done in line 316 to 322.

    / df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0], 2)
    • To calculate the time before depletion and yearly rate of emission decrease in the case of linear decrease until the remaining budget is depleted (here a remaining carbon budget from the start of 2019 is used) [emissions(t) = emissions(2019) - slope . t(depletion)], we can start from the premise that the total budget (budget) and starting emissions (emissions_2019) are known, out of which we can calculate the slope (rate of decrease) and time before depletion (t_depletion):

    System of equations:

    Solution:

    • The depletion time can be then be calculated as:

      (round(df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0], 2)
               /
               ((round(df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0], 2) ^ 2)
                  /
                  (2 * round(((carbon_budget + 80)  # carbon budget country
                              * df_budget.loc[df_budget['country'] == selected_country, 'total_kton_CO2'].values.flatten().tolist()[0])
                             / df_budget.loc[df_budget['country'] == selected_country, 'per_capita_CO2'].values.flatten().tolist()[0]
                             / global_emissions[0]
                             * global_per_capita_emissions[0]
                             / 1000
                             - (df_budget.loc[df_budget['country'] == selected_country, '2016'].values.flatten().tolist()[0] + (3 * df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0])), 2) - round(df_budget.loc[df_budget['country'] == selected_country, '2017'].values.flatten().tolist()[0], 2))
               )
              )

Development and workflow

  • The app can be run on a local server. See below for more information.
  • This github respository is showcased using a Railway application (emission-budgets.up.railway.app/).

Running the app locally for testing

Note: instructions are for OSX with Homebrew and Anaconda or Windows with Anaconda installed.

Information taken from https://towardsdatascience.com/how-to-create-your-first-web-app-using-python-plotly-dash-and-google-sheets-api-7a2fe3f5d256.

create conda environment and install required packages

conda create --name emission-budgets python=3.8
conda activate emission-budgets
pip install dash
pip install dash-renderer
pip install dash-core-components
pip install dash-html-components
pip install plotly
pip install dash-table-experiments
pip install numpy
pip install pandas
pip install gunicorn

Running the app on a local host

  1. Go to working directory in terminal
  2. Activate conda environment with conda activate emission-budgets
  3. Run the app with python app.py (it should display a url with the application that you can open in a browser)