Spaces:
Sleeping
Sleeping
cassiebuhler
commited on
Commit
·
46bc3f8
1
Parent(s):
8424379
color intensity
Browse files
app.py
CHANGED
@@ -60,33 +60,25 @@ with st.sidebar:
|
|
60 |
# year = st.slider("Select a year", min_value=1988, max_value=2024, value=2022, step=2)
|
61 |
year = st.slider("Select a year", min_value=1988, max_value=2024, value=2022, step=1)
|
62 |
|
63 |
-
#gdf = df.filter(_.year==year).execute()
|
64 |
-
|
65 |
-
|
66 |
import leafmap.maplibregl as leafmap
|
67 |
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
|
68 |
|
69 |
url = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote.pmtiles"
|
70 |
|
71 |
url_states = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote_states.pmtiles"
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
]
|
82 |
-
paint = {"fill-extrusion-color": outcome,
|
83 |
-
"fill-extrusion-opacity": 0.7,
|
84 |
-
"fill-extrusion-height": ["*", ["get", "log_amount"], 5000],
|
85 |
-
}
|
86 |
style = {
|
87 |
"layers": [
|
88 |
{
|
89 |
-
"id": "
|
90 |
"source": "vote",
|
91 |
"source-layer": "vote",
|
92 |
"type": "fill-extrusion",
|
@@ -94,8 +86,23 @@ style = {
|
|
94 |
"==",
|
95 |
["get", "year"],
|
96 |
year,
|
97 |
-
],
|
98 |
-
"paint":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
},
|
100 |
],
|
101 |
}
|
@@ -103,7 +110,7 @@ style = {
|
|
103 |
style_states = {
|
104 |
"layers": [
|
105 |
{
|
106 |
-
"id": "
|
107 |
"source": "vote_states",
|
108 |
"source-layer": "vote_states",
|
109 |
"type": "fill",
|
@@ -111,30 +118,48 @@ style_states = {
|
|
111 |
"==",
|
112 |
["get", "year"],
|
113 |
year,
|
114 |
-
],
|
115 |
-
"paint": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
},
|
117 |
],
|
118 |
}
|
119 |
|
|
|
|
|
|
|
|
|
120 |
m.add_pmtiles(
|
121 |
-
|
122 |
-
style=
|
123 |
visible=True,
|
124 |
-
opacity=
|
125 |
tooltip=True,
|
126 |
-
fit_bounds=False
|
127 |
)
|
128 |
|
129 |
-
#states are 2D and transparent, thus added separately.
|
130 |
m.add_pmtiles(
|
131 |
-
|
132 |
-
style=
|
133 |
visible=True,
|
134 |
-
opacity=0
|
135 |
tooltip=True,
|
136 |
-
fit_bounds=False
|
137 |
)
|
138 |
-
|
|
|
139 |
m.to_streamlit()
|
140 |
|
|
|
60 |
# year = st.slider("Select a year", min_value=1988, max_value=2024, value=2022, step=2)
|
61 |
year = st.slider("Select a year", min_value=1988, max_value=2024, value=2022, step=1)
|
62 |
|
|
|
|
|
|
|
63 |
import leafmap.maplibregl as leafmap
|
64 |
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
|
65 |
|
66 |
url = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote.pmtiles"
|
67 |
|
68 |
url_states = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote_states.pmtiles"
|
69 |
+
|
70 |
+
|
71 |
+
dark_orange = 'rgba(171, 86, 1, 1)' # dark orange - min value
|
72 |
+
light_orange = 'rgba(242, 185, 130, 1)' # light orange
|
73 |
+
grey = 'rgba(211, 211, 211, 1)' # grey
|
74 |
+
light_green = 'rgba(195, 219, 195, 1)' # light green
|
75 |
+
dark_green = 'rgba(65, 125, 65, 1)' # dark green - max value
|
76 |
+
|
77 |
+
|
|
|
|
|
|
|
|
|
|
|
78 |
style = {
|
79 |
"layers": [
|
80 |
{
|
81 |
+
"id": "counties & municipals",
|
82 |
"source": "vote",
|
83 |
"source-layer": "vote",
|
84 |
"type": "fill-extrusion",
|
|
|
86 |
"==",
|
87 |
["get", "year"],
|
88 |
year,
|
89 |
+
],
|
90 |
+
"paint": {
|
91 |
+
"fill-extrusion-color": [
|
92 |
+
'interpolate',
|
93 |
+
['linear'],
|
94 |
+
[
|
95 |
+
'to-number',
|
96 |
+
['slice', ['get', 'yes'], 0, -1] # remove %
|
97 |
+
],
|
98 |
+
20, dark_orange,
|
99 |
+
45, light_orange,
|
100 |
+
50, grey,
|
101 |
+
55, light_green,
|
102 |
+
85, dark_green,
|
103 |
+
],
|
104 |
+
"fill-extrusion-height": ["*", ["get", "log_amount"], 5000],
|
105 |
+
}
|
106 |
},
|
107 |
],
|
108 |
}
|
|
|
110 |
style_states = {
|
111 |
"layers": [
|
112 |
{
|
113 |
+
"id": "states",
|
114 |
"source": "vote_states",
|
115 |
"source-layer": "vote_states",
|
116 |
"type": "fill",
|
|
|
118 |
"==",
|
119 |
["get", "year"],
|
120 |
year,
|
121 |
+
],
|
122 |
+
"paint": {
|
123 |
+
"fill-color": [
|
124 |
+
'interpolate',
|
125 |
+
['linear'],
|
126 |
+
[
|
127 |
+
'to-number',
|
128 |
+
['slice', ['get', 'yes'], 0, -1] # remove %
|
129 |
+
],
|
130 |
+
20, dark_orange,
|
131 |
+
45, light_orange,
|
132 |
+
50, grey,
|
133 |
+
55, light_green,
|
134 |
+
85, dark_green,
|
135 |
+
]
|
136 |
+
}
|
137 |
},
|
138 |
],
|
139 |
}
|
140 |
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
#states are 2D and transparent, thus added separately.
|
145 |
m.add_pmtiles(
|
146 |
+
url_states,
|
147 |
+
style=style_states,
|
148 |
visible=True,
|
149 |
+
opacity=0.6,
|
150 |
tooltip=True,
|
151 |
+
fit_bounds=False
|
152 |
)
|
153 |
|
|
|
154 |
m.add_pmtiles(
|
155 |
+
url,
|
156 |
+
style=style,
|
157 |
visible=True,
|
158 |
+
opacity=1.0,
|
159 |
tooltip=True,
|
160 |
+
fit_bounds=False
|
161 |
)
|
162 |
+
|
163 |
+
m.add_layer_control()
|
164 |
m.to_streamlit()
|
165 |
|