Spaces:
Sleeping
Sleeping
test
Browse files
app.py
CHANGED
|
@@ -18,8 +18,7 @@ import ibis
|
|
| 18 |
from ibis import _
|
| 19 |
|
| 20 |
# SETTING PAGE CONFIG TO WIDE MODE AND ADDING A TITLE AND FAVICON
|
| 21 |
-
st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon=":
|
| 22 |
-
|
| 23 |
|
| 24 |
|
| 25 |
# +
|
|
@@ -39,7 +38,7 @@ def load_data(zoom=7):
|
|
| 39 |
return df_all
|
| 40 |
|
| 41 |
@st.cache_data
|
| 42 |
-
def load_class(taxa
|
| 43 |
con = ibis.duckdb.connect()
|
| 44 |
path = "gbif-vert-gb-h3z" + str(zoom) + ".csv"
|
| 45 |
df = (con.
|
|
@@ -87,21 +86,25 @@ def map(data, lat, lon, zoom):
|
|
| 87 |
# LAYING OUT THE TOP SECTION OF THE APP
|
| 88 |
row1_1, row1_2 = st.columns((2, 3))
|
| 89 |
|
| 90 |
-
## Interactive elements
|
| 91 |
with row1_1:
|
| 92 |
st.title("GBIF Species Richness")
|
| 93 |
-
taxa = st.text_input('taxonomic class (Chordates only)')
|
| 94 |
|
| 95 |
-
zoom = st.slider(
|
| 96 |
-
"Select hex resolution", 4, 7, key="zoom"
|
| 97 |
-
)
|
| 98 |
|
| 99 |
|
| 100 |
with row1_2:
|
| 101 |
st.write(
|
| 102 |
"""
|
| 103 |
-
##
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
"""
|
| 106 |
)
|
| 107 |
|
|
@@ -120,17 +123,17 @@ with row2_1:
|
|
| 120 |
st.write(
|
| 121 |
f"""**All**"""
|
| 122 |
)
|
| 123 |
-
map(load_data(zoom=zoom), midpoint[0], midpoint[1],
|
| 124 |
|
| 125 |
with row2_2:
|
| 126 |
st.write(f"Selected class is {taxa}")
|
| 127 |
-
map(load_class(taxa=taxa, zoom=zoom), midpoint[0], midpoint[1],
|
| 128 |
|
| 129 |
with row2_3:
|
| 130 |
st.write("**Mammals**")
|
| 131 |
-
map(load_class("Mammalia", zoom=zoom), midpoint[0], midpoint[1],
|
| 132 |
|
| 133 |
with row2_4:
|
| 134 |
st.write("**Birds**")
|
| 135 |
-
map(load_class("Aves", zoom=zoom), midpoint[0], midpoint[1],
|
| 136 |
|
|
|
|
| 18 |
from ibis import _
|
| 19 |
|
| 20 |
# SETTING PAGE CONFIG TO WIDE MODE AND ADDING A TITLE AND FAVICON
|
| 21 |
+
st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon=":globe:")
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
# +
|
|
|
|
| 38 |
return df_all
|
| 39 |
|
| 40 |
@st.cache_data
|
| 41 |
+
def load_class(taxa, zoom=7):
|
| 42 |
con = ibis.duckdb.connect()
|
| 43 |
path = "gbif-vert-gb-h3z" + str(zoom) + ".csv"
|
| 44 |
df = (con.
|
|
|
|
| 86 |
# LAYING OUT THE TOP SECTION OF THE APP
|
| 87 |
row1_1, row1_2 = st.columns((2, 3))
|
| 88 |
|
| 89 |
+
## Interactive elements, see https://docs.streamlit.io/library/api-reference/widgets
|
| 90 |
with row1_1:
|
| 91 |
st.title("GBIF Species Richness")
|
| 92 |
+
taxa = st.text_input('taxonomic class (Chordates only)', value = "Amphibia")
|
| 93 |
|
| 94 |
+
zoom = st.slider("Select hex resolution", 4, 7, key="zoom", value = 5)
|
|
|
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
with row1_2:
|
| 98 |
st.write(
|
| 99 |
"""
|
| 100 |
+
## GBIF Streamlit demo
|
| 101 |
+
|
| 102 |
+
This shows a simple interactive demonstration using a series of [pydeck maps](https://deckgl.readthedocs.io/) overlaid with
|
| 103 |
+
[h3 hexagons](https://h3geo.org/) whose height and color indicate species richness of the group.
|
| 104 |
+
|
| 105 |
+
Adjust the [h3 hexagon size](https://h3geo.org/docs/core-library/restable/) to increase the geographic area over which richness coordinates are aggregated. Select a focal taxonomic group to compare, zoom in and out of maps.
|
| 106 |
+
|
| 107 |
+
Data derived from GBIF 2024-02-01 and h3 aggregations are pre-computed for cell sizes 1-7 across the UK using [duckdb-hs](https://github.com/isaacbrodsky/h3-duckdb)
|
| 108 |
"""
|
| 109 |
)
|
| 110 |
|
|
|
|
| 123 |
st.write(
|
| 124 |
f"""**All**"""
|
| 125 |
)
|
| 126 |
+
map(load_data(zoom=zoom), midpoint[0], midpoint[1], 3)
|
| 127 |
|
| 128 |
with row2_2:
|
| 129 |
st.write(f"Selected class is {taxa}")
|
| 130 |
+
map(load_class(taxa=taxa, zoom=zoom), midpoint[0], midpoint[1], 3)
|
| 131 |
|
| 132 |
with row2_3:
|
| 133 |
st.write("**Mammals**")
|
| 134 |
+
map(load_class("Mammalia", zoom=zoom), midpoint[0], midpoint[1], 4)
|
| 135 |
|
| 136 |
with row2_4:
|
| 137 |
st.write("**Birds**")
|
| 138 |
+
map(load_class("Aves", zoom=zoom), midpoint[0], midpoint[1], 4)
|
| 139 |
|