Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Egypt Emissions Trend & Climate Inequality Dashboard

Egypt Dashboard

An interactive dashboard exploring Egypt's emissions trajectory through a climate justice lens

πŸš€ Live Demo β€’ Data Source: Our World in Data β€’ AI: OpenRouter β€’ Visualizations: Plotly.js


The Climate Justice Story

Egypt presents a compelling case of climate injustice β€” where vulnerability vastly exceeds responsibility.

Key Statistics (2023)

Metric Egypt Global Average Implication
COβ‚‚ per capita 2.19 t 4.71 t 54% below average
Global COβ‚‚ share 0.64% β€” 1/3 of population share
Population 114 million β€” Growing at ~2M/year
GDP per capita $3,457 (nominal) β€” Developing nation

Why This Matters

  • Egypt contributes less than 0.7% of global COβ‚‚ emissions
  • Hosts COP27 (2022)** and committed to 42% renewable electricity by 2035
  • One of the world's most climate-vulnerable coastal zones faces sea-level rise
  • Despite Zohr gas discovery (2015) making Egypt a net exporter, fossil fuels still account for 90%+ of electricity

Dashboard Features

1. Emissions Trend Analysis

Interactive line charts showing Egypt's COβ‚‚ emissions from 2001-2023 with:

  • Total emissions (Mt COβ‚‚) with historical phases
  • Per capita emissions (t COβ‚‚/person) normalized by population
  • CAGR calculations for each historical period

Historical Phases:

Period Phase CAGR Key Events
2001-2010 Pre-Arab Spring +5.4%/yr Rapid industrialization
2011-2015 Post-Crisis +0.6%/yr Arab Spring, political transition
2016-2019 Reform & Zohr -1.5%/yr Zohr gas online, IMF reform
2020-2023 COVID & Recovery +0.5%/yr Pandemic, global recovery

2. Fuel Mix Breakdown (COβ‚‚/GHG Toggle) with Historical Timeline

Explore emissions by source with a toggle between:

  • COβ‚‚ Mode: Coal, Oil, Gas, Cement, Flaring
  • GHG Mode: Full greenhouse gas breakdown including methane (CHβ‚„), nitrous oxide (Nβ‚‚O)

Interactive Timeline Animation: Features an integrated scrubber and playback β–Ά controls allowing you to see the exact Donut Chart distribution for any year. As the Donut chart animates, a sweeping timeline synchronizes across the Stacked Area historical series (2001-2023) to show how fuel reliance evolved over two decades!

Key Insight: The Zohr gas field (discovered 2015, online 2017) led to Egypt becoming a net gas exporter by 2019 β€” explaining the emissions decline during 2016-2019.

3. Global Comparison with Year Filter

Compare Egypt's performance against different country groups across 2001-2023:

Tier Countries Purpose
Peers India, Morocco, Pakistan, Indonesia Similar development stage
Regional Saudi Arabia, Iran, Iraq, South Africa Geographic neighbors
Responsibility USA, China, Germany, World Historical emitters

Four Comparison Charts:

  1. Per Capita Bar β€” Sorted descending with world average reference line and dynamic gradient shading
  2. GDP vs COβ‚‚ Scatter β€” Advanced linear scaling with area-proportional population bubbles (sizeref scaling)
  3. HDI-Adjusted Emissions β€” COβ‚‚ per capita / HDI score (live HDI data from UNDP Data API)
  4. Carbon Intensity β€” COβ‚‚ per million USD GDP (using nominal US$ from World Bank API)

4. AI-Powered Insights

Generated using free-tier LLMs via OpenRouter, providing:

  • Trend analysis with key drivers
  • Country comparison insights
  • Emission source breakdown analysis
  • Climate justice reflection

5. Global Context Panel

Quick reference metrics showing:

  • GDP per capita (nominal USD, not PPP)
  • vs Global Average (-54% less)
  • Share of Global Emissions (0.64%)

Technical Architecture

flowchart TD
    subgraph Backend [Flask Backend]
        direction LR
        A[app.py<br>Routes] ~~~ B[data_utils.py<br>Data Logic] ~~~ C[ai_service.py<br>OpenRouter API]
    end

    subgraph LocalCache [Local CSV Cache]
        direction LR
        D1[(OWID Data<br>owid_emissions.csv)]
        D2[(UNDP Data<br>undp_hdi_scores.csv)]
        D3[(World Bank Data<br>worldbank_gdp.csv)]
    end

    subgraph Templates [Jinja2 Templates]
        direction LR
        E[base.html<br>Layout & CSS] ~~~ F[index.html<br>Dashboard UI]
    end

    subgraph Frontend [Plotly Frontend]
        direction LR
        G(Line Charts) ~~~ H(Donut Chart) ~~~ I(Bar Charts) ~~~ J(Scatter Plot)
    end

    Backend --> LocalCache
    Backend --> Templates
    Templates --> Frontend
Loading

Tech Stack

Component Technology Purpose
Backend Python Flask API endpoints, data processing
Data (Primary) Pandas, OWID CSV Core emissions metrics
Data (External API) requests module Dynamic HDI (UNDP HDR API) & Nominal GDP (World Bank API)
Frontend HTML/CSS/JavaScript Dashboard UI, Animation loops
Charts Plotly.js Interactive visualizations
AI OpenRouter API Natural language insights
Dev Assistant Opencode Big Pickle HTML/CSS/JS implementation
Fonts Plus Jakarta Sans, Outfit, DM Mono Typography

API Reference

Core Endpoints

Endpoint Method Parameters Description
/ GET β€” Main dashboard
/api/countries GET β€” List available countries
/api/summary/<code> GET code: ISO code Country summary
/api/trend/<code> GET code, metric: co2/ghg Trend statistics
/api/comparison/<code> GET code, tier, year Comparison data
/api/emission-sources/<code> GET code, mode, year Source breakdown

AI Endpoints

Endpoint Method Parameters Description
/api/ai/trend/<code> GET code, metric Trend insight
/api/ai/comparison/<code> GET code, tier Comparison insight
/api/ai/sources/<code> GET code, mode Sources insight
/api/ai/reflection/<code> GET code Climate reflection

Example API Calls

# Get Egypt summary
curl http://localhost:5000/api/summary/EGY

# Get comparison data for 2015
curl "http://localhost:5000/api/comparison/EGY?tier=peers&year=2015"

# Get emission sources in GHG mode
curl "http://localhost:5000/api/emission-sources/EGY?mode=ghg&year=2023"

Setup Instructions

Prerequisites

  • Python 3.8+
  • pip (Python package manager)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd emission_trend_analysis
  2. Create virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment variables

    cp .env.example .env
    # Edit .env and add your OpenRouter API key (optional, for AI features)
  5. Run the dashboard

    python app.py
  6. Open in browser

    http://localhost:5000
    

Environment Variables

Create a .env file:

# OpenRouter API Key (optional - AI features won't work without it)
# Get free key at: https://openrouter.ai/
OPENROUTER_API_KEY=your_api_key_here

# UNDP HDR API Key (required for dynamic HDI metric charts)
HDR_API_KEY=HDR-68M2Tq4FVFxNBTfVHszAALekyuaFxQ4u

# Optional: Flask configuration
FLASK_ENV=development
FLASK_DEBUG=1

Deploying to Vercel

This application is ready to be deployed to Vercel out of the box (configured via vercel.json and app.py).

  1. Push your repository to GitHub.
  2. Log into Vercel and click Add New Project.
  3. Import your GitHub repository.
  4. Add your OPENROUTER_API_KEY to the Environment Variables section.
  5. Click Deploy.

Data Sources & Citations

Primary Data

Source Description URL
Our World in Data COβ‚‚ & GHG emissions dataset github.com/owid/co2-data
Global Carbon Project Emissions data provider globalcarbonproject.org
UNFCCC GHG inventories unfccc.int

Economic & Human Data APIs

Source Description Built-In Integration
World Bank API GDP per capita (nominal USD) NY.GDP.PCAP.CD Data automatically fetched and cached
UNDP HDR API Human Development Index (HDI) Live fetched tracking for over 190 countries

Policy References

Source Description
IEA World Energy Outlook 2023
IPCC AR6 Climate Change 2023 Synthesis Report
ICAP Emissions Trading Worldwide Status Report 2023
UNEP Emissions Gap Report 2024
CCPI Climate Change Performance Index 2024

Climate Policy Context

Egypt's Climate Commitments

  • COP27 Host (2022): Egypt hosted the UN Climate Change Conference in Sharm El-Sheikh
  • NDC Target: 42% renewable electricity by 2035
  • Zohr Gas Field: Discovery (2015) made Egypt a net gas exporter by 2019
  • Vulnerability: One of world's most climate-vulnerable coastal zones

Historical Context

Event Year Impact on Emissions
Arab Spring 2011 Political instability, growth slowdown
IMF Currency Reform 2016 Economic adjustment, energy reforms
Zohr Gas Online 2017 Natural gas surplus, exports begin
COVID-19 2020 Global emissions dip
COP27 2022 International climate spotlight

Project Structure

emission_trend_analysis/
β”œβ”€β”€ app.py                 # Flask application & routes
β”œβ”€β”€ data_utils.py          # Data processing functions
β”œβ”€β”€ ai_service.py          # OpenRouter AI integration
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ .env.example           # Environment template
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ cache/
β”‚   β”‚   β”œβ”€β”€ owid_emissions.csv  # OWID data (cached)
β”‚   β”‚   └── undp_hdi_scores.csv # UNDP data (cached)
β”‚   β”‚   └── worldbank_gdp.csv   # World Bank data (cached)
β”‚   β”œβ”€β”€ fetch_data.ipynb   # Data fetching notebook
β”‚   β”œβ”€β”€ analysis.ipynb     # Analysis notebook
β”‚   └── countries.ipynb    # Country config notebook
β”‚
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ base.html          # Base template (CSS, layout)
β”‚   └── index.html         # Main dashboard page
β”‚
β”œβ”€β”€ static/
β”‚   └── egypt_hero.jpg     # Hero background image
β”‚
β”œβ”€β”€ CODE_EXPLANATION.md    # Technical documentation
└── README.md              # This file

Key Features Explained

COβ‚‚ vs GHG Toggle

The dashboard supports two emission views:

  • COβ‚‚ Mode: Only carbon dioxide emissions
  • GHG Mode: Full greenhouse gas inventory including methane (CHβ‚„) and nitrous oxide (Nβ‚‚O)

Non-COβ‚‚ Calculation:

Other GHGs = Total GHG (excl. LUCF) - (Coal + Oil + Gas + Cement + Flaring)

Calculated using GWP100 metric via OWID/IPCC methodology.

HDI-Adjusted Emissions

This metric combines COβ‚‚ per capita with Human Development Index to assess climate justice:

HDI-Adjusted = COβ‚‚ per capita / HDI Score

Lower values = more efficient human development per unit of COβ‚‚

Example values (2023):

Country COβ‚‚/capita HDI Adjusted
Egypt 2.19 0.731 3.0
India 2.13 0.645 3.3

CAGR Calculation

Compound Annual Growth Rate calculated from actual data:

CAGR = (End Value / Start Value)^(1/years) - 1

Not hardcoded estimates β€” computed from OWID time series data.


Development Notes

Adding New Countries

  1. Update data_utils.py with country code and HDI score
  2. Add to TIER_COMPARISONS for comparison groups
  3. Create country description in index.html countryDescriptions object

Modifying Charts

All Plotly charts use a shared configuration (PB object) in index.html:

const PB = {
    paper_bgcolor: 'rgba(0,0,0,0)',
    plot_bgcolor: 'rgba(0,0,0,0)',
    font: { family: 'Plus Jakarta Sans', ... },
    margin: { t: 16, r: 16, b: 48, l: 56 },
    // ...
};

AI Service

The AI service uses free-tier models via OpenRouter. Rate limiting (2-second intervals) prevents API overuse. Prompts are optimized for concise, actionable insights.


License

This project is for educational and research purposes. Data sourced from Our World in Data under their license terms, and Human Development Index data from the United Nations Development Programme (UNDP).


Acknowledgments


Built for TISS Mumbai - Climate Change, Sustainability & Development Assignment

About

A full-stack data visualization dashboard for COβ‚‚ emissions analysis of Egypt, built with Flask, Plotly.js, and Pandas. Features real-time AI context, animated timelines, and data from the World Bank & UNDP. 🌱

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages