SANIDHYAG commited on
Commit
4c9424b
·
verified ·
1 Parent(s): 0455f2b

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +48 -0
  2. app.py +119 -0
  3. requirements.txt +4 -0
README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "Climate Clock Observatory"
3
+ emoji: 🌍
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: streamlit
7
+ sdk_version: "1.32.0"
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # 🌍 Climate Clock Observatory
13
+
14
+ This Streamlit app visualizes real-time climate indicators using the [Climate Clock API](https://docs.climateclock.world/climate-clock-docs/climate-clock-api). It is built as part of a final project to demonstrate how data can be transformed into an engaging and informative climate observatory.
15
+
16
+ ## 📊 Visualizations Included
17
+
18
+ 1. **CO₂ Budget Depletion Projection** – 10-year forecast using current depletion rates.
19
+ 2. **Global Energy Mix** – A donut chart showing the percentage of global energy from renewables.
20
+ 3. **Lifeline Metrics** – A bar chart showing positive contributions like trees planted and energy created.
21
+ 4. **Time Until 1.5°C Breach** – Countdown clock showing years, months, and days remaining.
22
+ 5. **CO₂ Budget Simulator** – Interactive slider that simulates reduced emissions and updates the budget timeline.
23
+
24
+ ## 🚀 How to Run
25
+
26
+ ```bash
27
+ pip install -r requirements.txt
28
+ streamlit run app.py
29
+ ```
30
+
31
+ ## 🛠️ Tech Stack
32
+
33
+ - Streamlit
34
+ - Altair
35
+ - Pandas
36
+ - Climate Clock API
37
+
38
+ ## 👥 Contributors
39
+
40
+ Sanidhya and Group Members
41
+
42
+ ## 📝 Notes
43
+
44
+ - All plots are created using Altair as per project guidelines.
45
+ - The app uses a refresh-button-friendly design and pseudo real-time data.
46
+
47
+ Enjoy exploring our climate observatory!
48
+
app.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+ import altair as alt
5
+ from datetime import datetime, timedelta
6
+
7
+ st.set_page_config(page_title="Climate Clock Observatory", layout="wide")
8
+ st.title("🌍 Real-Time Climate Clock Observatory")
9
+
10
+ # -- Helper: Fetch and parse Climate Clock API data
11
+ @st.cache_data(ttl=300)
12
+ def fetch_climate_data():
13
+ url = "https://api.climateclock.world/v2/clock"
14
+ response = requests.get(url)
15
+ if response.status_code == 200:
16
+ return response.json().get("data", {}).get("clocks", {})
17
+ return {}
18
+
19
+ clock = fetch_climate_data()
20
+
21
+ if not clock:
22
+ st.error("Unable to fetch Climate Clock API data.")
23
+ st.stop()
24
+
25
+ # 1️⃣ CO₂ Budget Depletion Line Chart (10-year projection)
26
+ st.header("1️⃣ CO₂ Budget Depletion Projection")
27
+ try:
28
+ co2_clock = clock.get("co2", {})
29
+ co2_remaining = float(co2_clock.get("remaining", 0))
30
+ co2_rate = float(co2_clock.get("rate", 0))
31
+
32
+ years = list(range(datetime.now().year, datetime.now().year + 10))
33
+ values = [max(co2_remaining - i * co2_rate, 0) for i in range(10)]
34
+ df_proj = pd.DataFrame({"Year": years, "Remaining CO₂ Budget (Gt)": values})
35
+
36
+ chart = alt.Chart(df_proj).mark_line(point=True).encode(
37
+ x='Year:O',
38
+ y='Remaining CO₂ Budget (Gt):Q',
39
+ tooltip=['Year', 'Remaining CO₂ Budget (Gt)']
40
+ ).properties(width=700)
41
+ st.altair_chart(chart, use_container_width=True)
42
+ except Exception as e:
43
+ st.warning(f"Could not generate CO₂ projection chart: {e}")
44
+
45
+ # 2️⃣ Renewable Energy Share Donut Chart
46
+ st.header("2️⃣ Global Energy Mix – Renewables vs Others")
47
+ try:
48
+ renewables_clock = clock.get("renewables", {})
49
+ percent = float(renewables_clock.get("percentage", 0))
50
+ energy_df = pd.DataFrame({
51
+ 'Type': ['Renewables', 'Other'],
52
+ 'Percentage': [percent, 100 - percent]
53
+ })
54
+
55
+ pie = alt.Chart(energy_df).mark_arc(innerRadius=50).encode(
56
+ theta='Percentage:Q',
57
+ color='Type:N',
58
+ tooltip=['Type', 'Percentage']
59
+ ).properties(width=400, height=400)
60
+ st.altair_chart(pie, use_container_width=True)
61
+ except Exception as e:
62
+ st.warning(f"Could not load renewable energy chart: {e}")
63
+
64
+ # 3️⃣ Lifeline Metrics – Positive Climate Interventions
65
+ st.header("3️⃣ Lifeline Metrics – Positive Contributions")
66
+ try:
67
+ lifelines = clock.get("lifelines", [])
68
+ lifeline_df = pd.DataFrame([
69
+ {"Label": l.get("label", ""), "Value": float(l.get("value", 0))}
70
+ for l in lifelines
71
+ ])
72
+ bar = alt.Chart(lifeline_df).mark_bar().encode(
73
+ x=alt.X("Label:N", sort="-y"),
74
+ y="Value:Q",
75
+ tooltip=["Label", "Value"]
76
+ ).properties(width=700)
77
+ st.altair_chart(bar, use_container_width=True)
78
+ except Exception as e:
79
+ st.warning(f"Could not generate lifeline chart: {e}")
80
+
81
+ # 4️⃣ Climate Deadline Countdown Display
82
+ st.header("4️⃣ Time Left to 1.5°C Threshold")
83
+ try:
84
+ deadline_clock = clock.get("deadline", {})
85
+ deadline_parts = list(map(int, deadline_clock.get("time_left", "0:0:0:0:0").split(":")))
86
+ time_left_str = f"{deadline_parts[0]} years, {deadline_parts[1]} months, {deadline_parts[2]} days"
87
+ st.success(f"⏳ Estimated Time Remaining Before 1.5°C Limit is Breached: {time_left_str}")
88
+ except Exception as e:
89
+ st.warning(f"Could not show climate deadline: {e}")
90
+
91
+ # 5️⃣ Interactive What-If: CO₂ Emission Reduction Simulator
92
+ st.header("5️⃣ CO₂ Budget Simulator – What If We Reduce Emissions?")
93
+ try:
94
+ st.markdown("📉 Use the slider below to simulate reduced annual emissions and see when we would run out of CO₂ budget.")
95
+ new_rate = st.slider("New Annual CO₂ Emission Rate (Gt/year)", min_value=10.0, max_value=45.0, value=co2_rate, step=0.5)
96
+ sim_years = []
97
+ sim_budget = []
98
+ budget = co2_remaining
99
+ year = datetime.now().year
100
+
101
+ while budget > 0 and len(sim_years) < 20:
102
+ sim_years.append(year)
103
+ sim_budget.append(budget)
104
+ budget -= new_rate
105
+ year += 1
106
+
107
+ sim_df = pd.DataFrame({'Year': sim_years, 'Projected CO₂ Budget (Gt)': sim_budget})
108
+ sim_chart = alt.Chart(sim_df).mark_line(point=True).encode(
109
+ x='Year:O',
110
+ y='Projected CO₂ Budget (Gt):Q',
111
+ tooltip=['Year', 'Projected CO₂ Budget (Gt)']
112
+ ).properties(width=700)
113
+ st.altair_chart(sim_chart, use_container_width=True)
114
+ except Exception as e:
115
+ st.warning(f"Could not run simulation: {e}")
116
+
117
+ # Footer
118
+ st.markdown("---")
119
+ st.caption("Made by Sanidhya and Group Members | Data from Climate Clock API")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ altair
4
+ requests