Spaces:
Sleeping
Sleeping
cassiebuhler
commited on
Commit
·
8424379
1
Parent(s):
2236dd4
added states
Browse files- app.py +29 -1
- static-maps.ipynb +70 -117
app.py
CHANGED
@@ -68,6 +68,7 @@ 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 |
#gdf = df.filter(_.year==1988).execute()
|
72 |
#gdf.to_file("vote.geojson")
|
73 |
|
@@ -93,12 +94,29 @@ style = {
|
|
93 |
"==",
|
94 |
["get", "year"],
|
95 |
year,
|
96 |
-
],
|
97 |
"paint": paint
|
98 |
},
|
99 |
],
|
100 |
}
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
m.add_pmtiles(
|
103 |
url,
|
104 |
style=style,
|
@@ -107,6 +125,16 @@ m.add_pmtiles(
|
|
107 |
tooltip=True,
|
108 |
fit_bounds=False,
|
109 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
#m.add_layer_control()
|
111 |
m.to_streamlit()
|
112 |
|
|
|
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 |
#gdf = df.filter(_.year==1988).execute()
|
73 |
#gdf.to_file("vote.geojson")
|
74 |
|
|
|
94 |
"==",
|
95 |
["get", "year"],
|
96 |
year,
|
97 |
+
],
|
98 |
"paint": paint
|
99 |
},
|
100 |
],
|
101 |
}
|
102 |
|
103 |
+
style_states = {
|
104 |
+
"layers": [
|
105 |
+
{
|
106 |
+
"id": "votes_states",
|
107 |
+
"source": "vote_states",
|
108 |
+
"source-layer": "vote_states",
|
109 |
+
"type": "fill",
|
110 |
+
"filter": [
|
111 |
+
"==",
|
112 |
+
["get", "year"],
|
113 |
+
year,
|
114 |
+
],
|
115 |
+
"paint": {"fill-color": outcome}
|
116 |
+
},
|
117 |
+
],
|
118 |
+
}
|
119 |
+
|
120 |
m.add_pmtiles(
|
121 |
url,
|
122 |
style=style,
|
|
|
125 |
tooltip=True,
|
126 |
fit_bounds=False,
|
127 |
)
|
128 |
+
|
129 |
+
#states are 2D and transparent, thus added separately.
|
130 |
+
m.add_pmtiles(
|
131 |
+
url_states,
|
132 |
+
style=style_states,
|
133 |
+
visible=True,
|
134 |
+
opacity=0.4,
|
135 |
+
tooltip=True,
|
136 |
+
fit_bounds=False,
|
137 |
+
)
|
138 |
#m.add_layer_control()
|
139 |
m.to_streamlit()
|
140 |
|
static-maps.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"id": "b313a218-4778-4d5b-9036-f0370d4212a0",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
@@ -29,7 +29,42 @@
|
|
29 |
},
|
30 |
{
|
31 |
"cell_type": "code",
|
32 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
"id": "ba4d8915-cde3-4ef9-ad8c-7759ed2c8a13",
|
34 |
"metadata": {},
|
35 |
"outputs": [],
|
@@ -65,7 +100,7 @@
|
|
65 |
},
|
66 |
{
|
67 |
"cell_type": "code",
|
68 |
-
"execution_count":
|
69 |
"id": "0cce23c9-245c-4c28-9523-0231eb5acc17",
|
70 |
"metadata": {},
|
71 |
"outputs": [],
|
@@ -102,32 +137,20 @@
|
|
102 |
},
|
103 |
{
|
104 |
"cell_type": "code",
|
105 |
-
"execution_count":
|
106 |
"id": "a1e81807-8ce3-44bf-9a1c-8563fa33817c",
|
107 |
"metadata": {},
|
108 |
"outputs": [],
|
109 |
"source": [
|
110 |
-
"df = df_county.union(df_local)
|
111 |
-
"# df.execute()"
|
112 |
]
|
113 |
},
|
114 |
{
|
115 |
"cell_type": "code",
|
116 |
-
"execution_count":
|
117 |
"id": "5d3bee26-7ca8-490c-be5b-fc69a6c3db2a",
|
118 |
"metadata": {},
|
119 |
-
"outputs": [
|
120 |
-
{
|
121 |
-
"name": "stdout",
|
122 |
-
"output_type": "stream",
|
123 |
-
"text": [
|
124 |
-
"The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n",
|
125 |
-
"Token is valid (permission: write).\n",
|
126 |
-
"Your token has been saved to /home/rstudio/.cache/huggingface/token\n",
|
127 |
-
"Login successful\n"
|
128 |
-
]
|
129 |
-
}
|
130 |
-
],
|
131 |
"source": [
|
132 |
"import subprocess\n",
|
133 |
"import os\n",
|
@@ -172,116 +195,47 @@
|
|
172 |
},
|
173 |
{
|
174 |
"cell_type": "code",
|
175 |
-
"execution_count":
|
176 |
"id": "902ece1d-6e57-4f83-9286-709dbb549fae",
|
177 |
"metadata": {},
|
178 |
-
"outputs": [
|
179 |
-
{
|
180 |
-
"data": {
|
181 |
-
"application/vnd.jupyter.widget-view+json": {
|
182 |
-
"model_id": "2b18fcc2775845c4a3b40eedbe32475b",
|
183 |
-
"version_major": 2,
|
184 |
-
"version_minor": 0
|
185 |
-
},
|
186 |
-
"text/plain": [
|
187 |
-
"FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
|
188 |
-
]
|
189 |
-
},
|
190 |
-
"metadata": {},
|
191 |
-
"output_type": "display_data"
|
192 |
-
},
|
193 |
-
{
|
194 |
-
"data": {
|
195 |
-
"application/vnd.jupyter.widget-view+json": {
|
196 |
-
"model_id": "c7314c0c7d9948c9a3feaddadccde55b",
|
197 |
-
"version_major": 2,
|
198 |
-
"version_minor": 0
|
199 |
-
},
|
200 |
-
"text/plain": [
|
201 |
-
"vote.geojson: 0%| | 0.00/92.9M [00:00<?, ?B/s]"
|
202 |
-
]
|
203 |
-
},
|
204 |
-
"metadata": {},
|
205 |
-
"output_type": "display_data"
|
206 |
-
},
|
207 |
-
{
|
208 |
-
"name": "stderr",
|
209 |
-
"output_type": "stream",
|
210 |
-
"text": [
|
211 |
-
"For layer 0, using name \"vote\"\n",
|
212 |
-
"vote.geojson:496: null geometry (additional not reported): in JSON object {\"type\":\"Feature\",\"properties\":{\"key\":null,\"Status\":\"Fail\",\"yes\":\"43.67%\",\"year\":1990,\"amount\":null,\"log_amount\":null,\"jurisdiction\":\"County\"},\"geometry\":null}\n",
|
213 |
-
"2195 features, 10746823 bytes of geometry and attributes, 58352 bytes of string pool, 0 bytes of vertices, 0 bytes of nodes\n",
|
214 |
-
"Choosing a maxzoom of -z3 for features typically 81840 feet (24945 meters) apart, and at least 10982 feet (3348 meters) apart\n",
|
215 |
-
"Choosing a maxzoom of -z11 for resolution of about 214 feet (65 meters) within features\n",
|
216 |
-
" 99.9% 11/189/562 \n",
|
217 |
-
" 100.0% 11/110/897 \r"
|
218 |
-
]
|
219 |
-
},
|
220 |
-
{
|
221 |
-
"name": "stdout",
|
222 |
-
"output_type": "stream",
|
223 |
-
"text": [
|
224 |
-
"Successfully generated PMTiles file: vote.pmtiles\n"
|
225 |
-
]
|
226 |
-
},
|
227 |
-
{
|
228 |
-
"data": {
|
229 |
-
"application/vnd.jupyter.widget-view+json": {
|
230 |
-
"model_id": "1176d2d9c19e45539fc9efc2a60db944",
|
231 |
-
"version_major": 2,
|
232 |
-
"version_minor": 0
|
233 |
-
},
|
234 |
-
"text/plain": [
|
235 |
-
"vote.pmtiles: 0%| | 0.00/4.81M [00:00<?, ?B/s]"
|
236 |
-
]
|
237 |
-
},
|
238 |
-
"metadata": {},
|
239 |
-
"output_type": "display_data"
|
240 |
-
}
|
241 |
-
],
|
242 |
"source": [
|
243 |
"gdf= df.execute()\n",
|
244 |
"gdf = gdf.set_crs(\"EPSG:4326\")\n",
|
245 |
-
"# print(gdf.crs)\n",
|
246 |
-
"# gdf.to_parquet(\"votes.parquet\")\n",
|
247 |
"\n",
|
248 |
"gdf.to_file(\"vote.geojson\")\n",
|
249 |
"hf_upload(\"vote.geojson\", \"boettiger-lab/landvote\")\n",
|
250 |
"\n",
|
251 |
"generate_pmtiles(\"vote.geojson\", \"vote.pmtiles\")\n",
|
252 |
"hf_upload(\"vote.pmtiles\", \"boettiger-lab/landvote\")\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
"\n"
|
254 |
]
|
255 |
},
|
256 |
{
|
257 |
"cell_type": "code",
|
258 |
-
"execution_count":
|
259 |
"id": "fa397626-6e94-4ab9-a3bb-2bcbd14e8d40",
|
260 |
"metadata": {
|
261 |
"scrolled": true
|
262 |
},
|
263 |
-
"outputs": [
|
264 |
-
{
|
265 |
-
"data": {
|
266 |
-
"application/vnd.jupyter.widget-view+json": {
|
267 |
-
"model_id": "d829e5753c414cc2887dac52fd35dc82",
|
268 |
-
"version_major": 2,
|
269 |
-
"version_minor": 1
|
270 |
-
},
|
271 |
-
"text/plain": [
|
272 |
-
"Map(height='600px', map_options={'bearing': 0, 'center': (0, 20), 'pitch': 0, 'style': 'https://basemaps.carto…"
|
273 |
-
]
|
274 |
-
},
|
275 |
-
"execution_count": 15,
|
276 |
-
"metadata": {},
|
277 |
-
"output_type": "execute_result"
|
278 |
-
}
|
279 |
-
],
|
280 |
"source": [
|
281 |
"import leafmap.maplibregl as leafmap\n",
|
282 |
"m = leafmap.Map(style=\"positron\")\n",
|
283 |
"\n",
|
284 |
-
"
|
|
|
285 |
"\n",
|
286 |
"outcome = [\n",
|
287 |
" 'match',\n",
|
@@ -290,32 +244,31 @@
|
|
290 |
" \"Fail\", '#FF3300', \n",
|
291 |
" '#ccc'\n",
|
292 |
" ]\n",
|
293 |
-
"
|
294 |
-
" \"fill-
|
295 |
-
" \"fill-extrusion-height\": [\"*\", [\"get\", \"log_amount\"], 5000],\n",
|
296 |
" }\n",
|
297 |
-
"
|
298 |
" \"layers\": [\n",
|
299 |
" {\n",
|
300 |
-
" \"id\": \"
|
301 |
-
" \"source\": \"
|
302 |
-
" \"source-layer\": \"
|
303 |
-
" \"type\": \"fill
|
304 |
" \"filter\": [\n",
|
305 |
" \"==\",\n",
|
306 |
" [\"get\", \"year\"],\n",
|
307 |
" 2022,\n",
|
308 |
" ], # only show buildings with height info\n",
|
309 |
-
" \"paint\":
|
310 |
" },\n",
|
311 |
" ],\n",
|
312 |
"}\n",
|
313 |
"\n",
|
314 |
"m.add_pmtiles(\n",
|
315 |
-
"
|
316 |
-
" style=
|
317 |
" visible=True,\n",
|
318 |
-
" opacity=
|
319 |
" tooltip=True,\n",
|
320 |
" fit_bounds=False,\n",
|
321 |
")\n",
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
"id": "b313a218-4778-4d5b-9036-f0370d4212a0",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
|
|
29 |
},
|
30 |
{
|
31 |
"cell_type": "code",
|
32 |
+
"execution_count": null,
|
33 |
+
"id": "09ecf89a-a315-45ef-9ece-783963e6e07e",
|
34 |
+
"metadata": {},
|
35 |
+
"outputs": [],
|
36 |
+
"source": [
|
37 |
+
"vote_states = (votes\n",
|
38 |
+
" .filter(_[\"Jurisdiction Type\"] == \"State\")\n",
|
39 |
+
" .rename(state_id = \"State\")\n",
|
40 |
+
" .rename(amount = 'Conservation Funds at Stake', yes = '% Yes')\n",
|
41 |
+
" .mutate(amount_n=_.amount.replace('$', '').replace(',', '').cast('float'))\n",
|
42 |
+
" .mutate(log_amount=_.amount_n.log())\n",
|
43 |
+
" .mutate(year=_['Date'].year().cast('int32'))\n",
|
44 |
+
" .mutate(\n",
|
45 |
+
" yes=ibis.case()\n",
|
46 |
+
" .when(_.yes.isin(['Pass', 'None','Fail']), None) # Handle non-numeric cases\n",
|
47 |
+
" .when(_.yes.notnull(), (_.yes.replace('%', '').cast('float').round(2).cast(dt.float64)).cast(dt.string) + '%') # Convert valid percentages and add %\n",
|
48 |
+
" .else_(None) # Default to None for other cases\n",
|
49 |
+
" .end()\n",
|
50 |
+
" )\n",
|
51 |
+
" .mutate(log_amount = _.log_amount.round(4))\n",
|
52 |
+
" .select('state_id', 'Status', 'yes', 'year', 'amount', 'log_amount', )\n",
|
53 |
+
" )\n",
|
54 |
+
"\n",
|
55 |
+
"df_states = (states\n",
|
56 |
+
" .select('state_id','geometry')\n",
|
57 |
+
" .right_join(vote_states, \"state_id\")\n",
|
58 |
+
" .mutate(key = _.state_id)\n",
|
59 |
+
" .select('key','geometry','Status', 'yes', 'year', 'amount', 'log_amount')\n",
|
60 |
+
" .mutate(jurisdiction = ibis.literal(\"State\"))\n",
|
61 |
+
" .cast({\"geometry\": \"geometry\"})\n",
|
62 |
+
" )\n"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": null,
|
68 |
"id": "ba4d8915-cde3-4ef9-ad8c-7759ed2c8a13",
|
69 |
"metadata": {},
|
70 |
"outputs": [],
|
|
|
100 |
},
|
101 |
{
|
102 |
"cell_type": "code",
|
103 |
+
"execution_count": null,
|
104 |
"id": "0cce23c9-245c-4c28-9523-0231eb5acc17",
|
105 |
"metadata": {},
|
106 |
"outputs": [],
|
|
|
137 |
},
|
138 |
{
|
139 |
"cell_type": "code",
|
140 |
+
"execution_count": null,
|
141 |
"id": "a1e81807-8ce3-44bf-9a1c-8563fa33817c",
|
142 |
"metadata": {},
|
143 |
"outputs": [],
|
144 |
"source": [
|
145 |
+
"df = df_county.union(df_local)"
|
|
|
146 |
]
|
147 |
},
|
148 |
{
|
149 |
"cell_type": "code",
|
150 |
+
"execution_count": null,
|
151 |
"id": "5d3bee26-7ca8-490c-be5b-fc69a6c3db2a",
|
152 |
"metadata": {},
|
153 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
"source": [
|
155 |
"import subprocess\n",
|
156 |
"import os\n",
|
|
|
195 |
},
|
196 |
{
|
197 |
"cell_type": "code",
|
198 |
+
"execution_count": null,
|
199 |
"id": "902ece1d-6e57-4f83-9286-709dbb549fae",
|
200 |
"metadata": {},
|
201 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
"source": [
|
203 |
"gdf= df.execute()\n",
|
204 |
"gdf = gdf.set_crs(\"EPSG:4326\")\n",
|
|
|
|
|
205 |
"\n",
|
206 |
"gdf.to_file(\"vote.geojson\")\n",
|
207 |
"hf_upload(\"vote.geojson\", \"boettiger-lab/landvote\")\n",
|
208 |
"\n",
|
209 |
"generate_pmtiles(\"vote.geojson\", \"vote.pmtiles\")\n",
|
210 |
"hf_upload(\"vote.pmtiles\", \"boettiger-lab/landvote\")\n",
|
211 |
+
"\n",
|
212 |
+
"\n",
|
213 |
+
"\n",
|
214 |
+
"gdf_states= df_states.execute()\n",
|
215 |
+
"gdf_states = gdf_states.set_crs(\"EPSG:4326\")\n",
|
216 |
+
"\n",
|
217 |
+
"gdf_states.to_file(\"vote_states.geojson\")\n",
|
218 |
+
"hf_upload(\"vote_states.geojson\", \"boettiger-lab/landvote\")\n",
|
219 |
+
"\n",
|
220 |
+
"generate_pmtiles(\"vote_states.geojson\", \"vote_states.pmtiles\")\n",
|
221 |
+
"hf_upload(\"vote_states.pmtiles\", \"boettiger-lab/landvote\")\n",
|
222 |
"\n"
|
223 |
]
|
224 |
},
|
225 |
{
|
226 |
"cell_type": "code",
|
227 |
+
"execution_count": null,
|
228 |
"id": "fa397626-6e94-4ab9-a3bb-2bcbd14e8d40",
|
229 |
"metadata": {
|
230 |
"scrolled": true
|
231 |
},
|
232 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
"source": [
|
234 |
"import leafmap.maplibregl as leafmap\n",
|
235 |
"m = leafmap.Map(style=\"positron\")\n",
|
236 |
"\n",
|
237 |
+
"\n",
|
238 |
+
"url_states = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/vote_states.pmtiles\"\n",
|
239 |
"\n",
|
240 |
"outcome = [\n",
|
241 |
" 'match',\n",
|
|
|
244 |
" \"Fail\", '#FF3300', \n",
|
245 |
" '#ccc'\n",
|
246 |
" ]\n",
|
247 |
+
"paint_states = {\"fill-color\": outcome, \n",
|
248 |
+
" # \"fill-opacity\": 0.2,\n",
|
|
|
249 |
" }\n",
|
250 |
+
"style_states = {\n",
|
251 |
" \"layers\": [\n",
|
252 |
" {\n",
|
253 |
+
" \"id\": \"votes_states\",\n",
|
254 |
+
" \"source\": \"vote_states\",\n",
|
255 |
+
" \"source-layer\": \"vote_states\",\n",
|
256 |
+
" \"type\": \"fill\",\n",
|
257 |
" \"filter\": [\n",
|
258 |
" \"==\",\n",
|
259 |
" [\"get\", \"year\"],\n",
|
260 |
" 2022,\n",
|
261 |
" ], # only show buildings with height info\n",
|
262 |
+
" \"paint\": paint_states\n",
|
263 |
" },\n",
|
264 |
" ],\n",
|
265 |
"}\n",
|
266 |
"\n",
|
267 |
"m.add_pmtiles(\n",
|
268 |
+
" url_states,\n",
|
269 |
+
" style=style_states,\n",
|
270 |
" visible=True,\n",
|
271 |
+
" opacity=0.4,\n",
|
272 |
" tooltip=True,\n",
|
273 |
" fit_bounds=False,\n",
|
274 |
")\n",
|