-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
119 lines (92 loc) · 2.87 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import pandas as pd
import numpy as np
import altair as alt
import streamlit as st
st.header("Continental Carbon Sequestration")
st.markdown("""
> This simple web app is an **intermediate product**. It is not the final
tool. Rather, it is meant to settle on the features of a final tool before
it goes to the web developers for the final build, which will look more
[like this](https://justice40.earthrise.media/).
The **purpose** of the country level map is to allow users to quickly assess
country level potential, revenue, and jobs across different solutions and
carbon price points.
**Questions**:
1. How much will the rankings vary with Carbon price?
2. Is it more important to compare one country to *all* others, or just *one* other?
3. More generally, what is operational question (which will inform the guided data exploration)?
""")
@st.cache()
def load_data():
countries = alt.topo_feature(
"https://nlambert.gitpages.huma-num.fr/resources/basemaps/world_countries.topojson",
"world_countries_data",
)
sequestration = pd.read_pickle("data/sequestration.pkl")
totals = pd.read_pickle("data/totals.pkl")
return countries, sequestration, totals
countries, sequestration, totals = load_data()
varnames = [
"reforestation",
"avoided_forest_conversion",
"natural_forest_management",
"avoided_woodfuel_harvest",
"savanna_burning",
"biochar",
"trees_in_agricultural_lands",
"nutrient_management",
"rice_management",
"optimal_grazing_intensity",
"grazing_legumes",
"peatland_restoration",
"avoided_peat_impacts",
"avoided_mangrove_impacts",
"mangrove_restoration",
"avoided_grassland_conversion"
]
benefit_type = st.sidebar.selectbox(
"Type of benefit",
[
"Sequestration",
"Sequestration/ha",
"Revenues",
"Revenues/GDP",
"Jobs",
"Jobs/(1000ppl)"
]
)
pathway = st.sidebar.selectbox(
"Pathway",
varnames
)
dollar_price = st.select_slider(
"Price per tCO2e",
options=[10, 30, 50, 70, 100]
)
df = sequestration[sequestration.price==dollar_price]
africa_chart = (
alt.Chart(countries, height=600)
.mark_geoshape(strokeWidth=0)
.encode(
color=alt.Color(
f"{pathway}:Q",
legend=alt.Legend(orient="bottom-left")
),
tooltip=[
alt.Tooltip("properties.NAMEen:O", title="Country"),
alt.Tooltip(f"{pathway}:Q", title="Indicator value"),
]
)
.transform_lookup(
lookup="properties.ISO3",
from_=alt.LookupData(df, "iso3", [pathway]),
).configure_view(
strokeWidth=0
)
)
st.altair_chart(africa_chart, use_container_width=True)
barchart = alt.Chart(df[df[pathway] > 0]).mark_bar().encode(
x=alt.X(f'sum({pathway}):Q', title=pathway),
y=alt.Y('geoname:N', sort='-x', title=None)
)
st.altair_chart(barchart, use_container_width=True)