cboettig commited on
Commit
69b7b38
·
1 Parent(s): d827042
Files changed (1) hide show
  1. app.py +53 -78
app.py CHANGED
@@ -35,21 +35,6 @@ st.set_page_config(layout="wide", page_title="Protected Areas Explorer", page_ic
35
  '''
36
  # US Protected Area Database Explorer
37
 
38
- The map below shows all continental US protected areas overlaid on [NatureServe's Map of Biodiversity Importance](https://www.natureserve.org/map-biodiversity-importance)
39
- which shows species richness for some 2,216 imperiled species in (990 m grid cells).
40
- Use the later tool in the top right to toggle layers on and off for visibility.
41
- Zoom into the map for more detailed rendering -- e.g. try exploring the many tiny public mixed used lands inside Los Angeles.
42
- Mouse over any polygon to see details about name, ownership, mean species richness, and mean rarity-weighted-richness.
43
-
44
- By default, areas are divided into the following categories:
45
- - Publicly managed lands in Gap 1 & 2 (e.g. National Parks) ("public use", blue)
46
- - Publicly managed lands in Gap 3 & 4 (most national forests, BLM lands, etc)
47
- - Privately managed lands
48
- - Tribally managed lands
49
-
50
- Alternative color rules can be applied, for instance, to distinguish between easements (rented) and fee (owned) protected areas. Below the interactive map,
51
- charts summarize the total protected area and mean richness and mean RSR within each group.
52
-
53
  '''
54
  # -
55
 
@@ -124,7 +109,7 @@ gap = {
124
  ['1', "#26633d"],
125
  ['2', "#879647"],
126
  ['3', "#BBBBBB"],
127
- ['4', "#00000000"]
128
  ]
129
  }
130
 
@@ -140,7 +125,7 @@ IUCN = {
140
  ["V", "#9932CC"],
141
  ["VI", "#9400D3"],
142
  ["Other Conservation Area", "#DDA0DD"],
143
- ["Unassigned", "#00000000"]
144
  ]
145
  }
146
 
@@ -199,18 +184,34 @@ with st.sidebar:
199
  if st.toggle("Shaded Relief Topo"):
200
  m.add_basemap("Esri.WorldShadedRelief")
201
 
 
 
202
 
203
- boundaries = st.radio("Boundaries:",
204
- ["None",
205
- "State Boundaries",
206
- "County Boundaries",
207
- "Congressional District",
208
- "custom"]
209
- )
210
 
211
- "## Raster layers"
212
-
213
- if st.toggle("Species Richness"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  m.add_tile_layer(url="https://data.source.coop/cboettig/mobi/tiles/red/species-richness-all/{z}/{x}/{y}.png",
215
  name="MOBI Species Richness",
216
  attribution="NatureServe",
@@ -243,25 +244,18 @@ with st.sidebar:
243
  hi="https://data.source.coop/vizzuality/hfp-100/hfp_2021_100m_v1-2_cog.tif"
244
  m.add_cog_layer(hi, palette="purples", name="Human Impact", transparent_bg=True, opacity = 0.8, zoom_to_layer=False)
245
 
246
- "## Protected Areas"
247
 
248
- style_dict = {"Manager Type": manager,
249
- "Fee/Easement": easement,
250
- "GAP Status Code": gap,
251
- "IUCN Status Code": IUCN,
252
- "Mean Richness": richness,
253
- "Mean RSR": rsr,
254
- "custom": eval(custom_style)}
255
-
256
- if st.toggle("PAD US-3", True):
257
- alpha = st.slider("transparency", 0.0, 1.1, 0.5)
258
- style_choice = st.radio("Color protected Areas by", style_dict)
259
 
260
- style=pad_style(style_dict[style_choice], alpha)
261
- m.add_pmtiles(pad_pmtiles, name="Protected Areas (PAD-US-3)", style=style, overlay=True, show=True, zoom_to_layer=False)
262
-
263
 
264
-
265
  # Fire Polygons, USGS
266
  if st.toggle("Fire boundaries"):
267
  usgs = "https://data.source.coop/cboettig/fire/usgs-mtbs.pmtiles"
@@ -281,7 +275,6 @@ with st.sidebar:
281
  m.add_pmtiles(usgs, name="Fire", style=combined_style, overlay=True, show=True, zoom_to_layer=False)
282
 
283
 
284
-
285
  # -
286
 
287
 
@@ -298,7 +291,7 @@ with st.sidebar:
298
 
299
  # m.add_legend(legend_dict=legend_dict)
300
 
301
- m.to_streamlit(height=900)
302
  # -
303
 
304
  st.divider()
@@ -419,44 +412,26 @@ with col2_2:
419
  df = eval(query)
420
  st.write(df.to_pandas())
421
 
422
- # -
423
-
424
- '''
425
- ## Technical errata
426
-
427
-
428
- **Protected Areas** data are derived from the
429
-
430
- > U.S. Geological Survey (USGS) Gap Analysis Project (GAP), 2022, Protected Areas Database of the United States (PAD-US) 3.0: U.S. Geological Survey data release, https://doi.org/10.5066/P9Q9LQ4B.
431
-
432
- Data is subset to the continental US (matching availability in MOBI data), and restricted to feature classes of "Fee" and "Easements",
433
- except for tribal boundaries which are taken from the "Proclamations." See [ProtectedLands.net](https://www.protectedlands.net/pad-us-data-structure-attributes/)
434
- for a more detailed discussion of the data structure and classification involved in PAD.
435
 
436
- USGS PAD-v3 is distributed as an ESRI Geodatabase. After subsetting the data and labelling according to the additional classification listed above based
437
- on manager type indicated in the data, core attributes are serialized into [PMTiles](https://docs.protomaps.com/pmtiles/) and [Geoparquet](https://geoparquet.org/)
438
- formats hosted on [source.coop](https://beta.source.coop/repositories/cboettig/pad-us-3/description/). PMTiles allows for rapid rendering of vector objects
439
- at the appropriate zoom level in an interactive map from remote servers. Geoparquet provides a high-performance serialization that can be efficiently queried directly from
440
- remote https addresses without download using software such as [duckdb](https://duckdb.org), widely available in python, R, and other languages.
441
 
442
- See our public Source.Coop repository [pad-us-3](https://beta.source.coop/repositories/cboettig/pad-us-3/description/) for more information on data processing
443
- and for direct access to the processed data layers.
444
 
445
- **Biodiversity Importance** data are derived from:
 
446
 
447
- > The Map of Biodiversity Importance, (2022), NatureServe.
448
 
449
- The 2018 version of this data product can be found on Microsoft Planetary Computer, but the 2022 release is currently distributed through their [ESRI GeoHub](https://geohub-natureserve.opendata.arcgis.com/search?q=mobi).
450
- The original data is provided in the geotiff format (ESRI LayerFiles) at 990 meter resolution, and includes assets subset by various taxonomic groups for three indicators: for 2,216 imperiled species (species with global conservation status of G1, G2 or listed as threatened or endagered under the United States Ednagered Species Act).
451
- The indicators include species richness (the number of imperiled species occurring in a given pixel),
452
- range-size rarity (RSR, the sum of the inverse of the range sizes of each species occurring in a given pixel),
453
- and protection-weighted RSR (RSR times the perecent of the range that is unprotected in GAP 1 & Gap 2).
454
- See [geohub description](https://geohub-natureserve.opendata.arcgis.com/content/e5a6de94cc7b4d5b9204e2cc5d8b6e4e/about) for more details.
455
- Only data from all species for the species richness and RSR metrics is processed here (at the time of writing).
456
 
457
- Our public Source.Coop repository [mobi](https://beta.source.coop/repositories/cboettig/mobi/) provides access
458
- to the geotiffs for species richness and RSR.
459
- The repository also includes static tiles from zooms 1-10 that can be used as a static tile server in interactive maps.
460
- Technical details on processing are described in the repository.
461
 
 
 
462
  '''
 
 
35
  '''
36
  # US Protected Area Database Explorer
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  '''
39
  # -
40
 
 
109
  ['1', "#26633d"],
110
  ['2', "#879647"],
111
  ['3', "#BBBBBB"],
112
+ ['4', "#FFFFFF"]
113
  ]
114
  }
115
 
 
125
  ["V", "#9932CC"],
126
  ["VI", "#9400D3"],
127
  ["Other Conservation Area", "#DDA0DD"],
128
+ ["Unassigned", "#FFFFFF"]
129
  ]
130
  }
131
 
 
184
  if st.toggle("Shaded Relief Topo"):
185
  m.add_basemap("Esri.WorldShadedRelief")
186
 
187
+
188
+ "## Protected Areas"
189
 
190
+ if st.toggle("PAD US-3", True):
191
+ alpha = st.slider("transparency", 0.0, 1.1, 0.5)
 
 
 
 
 
192
 
193
+ with st.expander("custom style"):
194
+ custom = st.text_area(
195
+ label = "Define a custom mapbox fill-color rule",
196
+ value = custom_style,
197
+ height = 100)
198
+
199
+ style_options = {
200
+ "GAP Status Code": gap,
201
+ "IUCN Status Code": IUCN,
202
+ "Manager Type": manager,
203
+ "Fee/Easement": easement,
204
+ "Mean Richness": richness,
205
+ "Mean RSR": rsr,
206
+ "custom": eval(custom)}
207
+
208
+ style_choice = st.radio("Color protected Areas by", style_options)
209
+ style = pad_style(style_options[style_choice], alpha)
210
+ m.add_pmtiles(pad_pmtiles, name="Protected Areas (PAD-US-3)", style=style, overlay=True, show=True, zoom_to_layer=False)
211
+
212
+
213
+ "## Data layers"
214
+ if st.toggle("Species Richness", True):
215
  m.add_tile_layer(url="https://data.source.coop/cboettig/mobi/tiles/red/species-richness-all/{z}/{x}/{y}.png",
216
  name="MOBI Species Richness",
217
  attribution="NatureServe",
 
244
  hi="https://data.source.coop/vizzuality/hfp-100/hfp_2021_100m_v1-2_cog.tif"
245
  m.add_cog_layer(hi, palette="purples", name="Human Impact", transparent_bg=True, opacity = 0.8, zoom_to_layer=False)
246
 
 
247
 
248
+ # "## Boundaries"
249
+ # boundaries = st.radio("Boundaries:",
250
+ # ["None",
251
+ # "State Boundaries",
252
+ # "County Boundaries",
253
+ # "Congressional District",
254
+ # "custom"]
255
+ # )
 
 
 
256
 
 
 
 
257
 
258
+ "## Additional elements"
259
  # Fire Polygons, USGS
260
  if st.toggle("Fire boundaries"):
261
  usgs = "https://data.source.coop/cboettig/fire/usgs-mtbs.pmtiles"
 
275
  m.add_pmtiles(usgs, name="Fire", style=combined_style, overlay=True, show=True, zoom_to_layer=False)
276
 
277
 
 
278
  # -
279
 
280
 
 
291
 
292
  # m.add_legend(legend_dict=legend_dict)
293
 
294
+ m.to_streamlit(height=700)
295
  # -
296
 
297
  st.divider()
 
412
  df = eval(query)
413
  st.write(df.to_pandas())
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
 
416
+ # +
 
 
 
 
417
 
418
+ '''
419
+ ## Credits
420
 
421
+ Author: Carl Boettiger, UC Berkeley
422
+ License: BSD-2-clause
423
 
424
+ ### Data sources
425
 
426
+ - US Protected Areas Database v3 by USGS, data hosted on https://beta.source.coop/cboettig/us-pad-3. Citation: https://doi.org/10.5066/P9Q9LQ4B, License: Public Domain
427
+ - Carbon-loss by Vizzuality, on https://beta.source.coop/repositories/vizzuality/lg-land-carbon-data. Citation: https://doi.org/10.1101/2023.11.01.565036, License: CC-BY
428
+ - Human Footprint by Vizzuality, on https://beta.source.coop/repositories/vizzuality/hfp-100. Citation: https://doi.org/10.3389/frsen.2023.1130896, License: Public Domain
429
+ - Fire polygons by USGS, reprocessed to PMTiles on https://beta.source.coop/cboettig/fire/. License: Public Domain.
430
+ - Irrecoverable Carbon from Conservation International, reprocessed to COG on https://beta.source.coop/cboettig/carbon, citation: https://doi.org/10.1038/s41893-021-00803-6, License: CC-BY-NC
 
 
431
 
432
+ ### Software
 
 
 
433
 
434
+ Proudly built with a free and Open Source software stack: Streamlit (reactive application), HuggingFace (application hosting), Source.Coop (data hosting),
435
+ using cloud-native data serializations in COG, PMTiles, and GeoParquet. Coded in pure python using leafmap and duckdb. Map styling with [MapLibre](https://maplibre.org/).
436
  '''
437
+