Spaces:
Sleeping
Sleeping
test
Browse files
app.py
CHANGED
@@ -32,37 +32,30 @@ st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon
|
|
32 |
|
33 |
|
34 |
# +
|
35 |
-
|
36 |
-
@st.
|
37 |
-
def load_data():
|
38 |
con = ibis.duckdb.connect()
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
''')
|
46 |
-
|
47 |
-
hzoom = "h3z" + str(6)
|
48 |
-
|
49 |
-
data = (
|
50 |
-
con.table("gb").
|
51 |
-
select(_[hzoom], _.species, _.year).
|
52 |
-
distinct().
|
53 |
-
group_by([_[hzoom], _.year]).
|
54 |
-
aggregate(n = _.count()).
|
55 |
mutate(color = 255 * _.n / _.n.max()).
|
56 |
to_pandas()
|
57 |
-
|
58 |
-
return data
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
63 |
@st.cache_data
|
64 |
-
def
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
|
@@ -127,8 +120,10 @@ def update_query_params():
|
|
127 |
|
128 |
with row1_1:
|
129 |
st.title("GBIF Species Richness")
|
130 |
-
|
131 |
-
|
|
|
|
|
132 |
)
|
133 |
|
134 |
|
@@ -136,7 +131,7 @@ with row1_2:
|
|
136 |
st.write(
|
137 |
"""
|
138 |
##
|
139 |
-
|
140 |
"""
|
141 |
)
|
142 |
|
@@ -149,7 +144,24 @@ midpoint = (52.0, -1.0) #mpoint(data["lat"], data["lon"])
|
|
149 |
# STREAMLIT APP LAYOUT
|
150 |
data = load_data()
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
# +
|
35 |
+
|
36 |
+
@st.cache_data
|
37 |
+
def load_data(zoom=7):
|
38 |
con = ibis.duckdb.connect()
|
39 |
+
path = "gbif-vert-gb-h3z" + str(zoom) + .csv
|
40 |
+
df_all = (
|
41 |
+
con.
|
42 |
+
read_csv(path).
|
43 |
+
group_by(_.h3).
|
44 |
+
aggregate(n = _.n.sum()).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
mutate(color = 255 * _.n / _.n.max()).
|
46 |
to_pandas()
|
47 |
+
)
|
|
|
|
|
|
|
|
|
48 |
|
49 |
@st.cache_data
|
50 |
+
def load_class(df, taxa="Amphibia", zoom=7):
|
51 |
+
con = ibis.duckdb.connect()
|
52 |
+
path = "gbif-vert-gb-h3z" + str(zoom) + .csv
|
53 |
+
df = (con.
|
54 |
+
read_csv(path).
|
55 |
+
filter(_['class']==taxa).
|
56 |
+
mutate(color = 255 * _.n / _.n.max()).
|
57 |
+
to_pandas()
|
58 |
+
)
|
59 |
|
60 |
|
61 |
|
|
|
120 |
|
121 |
with row1_1:
|
122 |
st.title("GBIF Species Richness")
|
123 |
+
taxa = st.text_input('taxonomic class (Chordates only)')
|
124 |
+
|
125 |
+
zoom = st.slider(
|
126 |
+
"Select hex resolution", 4, 7, key="zoom"
|
127 |
)
|
128 |
|
129 |
|
|
|
131 |
st.write(
|
132 |
"""
|
133 |
##
|
134 |
+
Testing
|
135 |
"""
|
136 |
)
|
137 |
|
|
|
144 |
# STREAMLIT APP LAYOUT
|
145 |
data = load_data()
|
146 |
|
147 |
+
# +
|
148 |
+
row2_1, row2_2, row2_3, row2_4 = st.columns((2, 1, 1, 1))
|
149 |
+
|
150 |
+
with row2_1:
|
151 |
+
st.write(
|
152 |
+
f"""**All**"""
|
153 |
+
)
|
154 |
+
map(filterdata(data, taxa), midpoint[0], midpoint[1], 10)
|
155 |
+
|
156 |
+
with row2_2:
|
157 |
+
st.write("**Amphibians**")
|
158 |
+
map(load_class(df, taxa="Amphibia", zoom=7), midpoint[0], midpoint[1], 11)
|
159 |
+
|
160 |
+
with row2_3:
|
161 |
+
st.write("**Mammals**")
|
162 |
+
map(filterdata(data, "Mammalia"), midpoint[0], midpoint[1], 9)
|
163 |
+
|
164 |
+
with row2_4:
|
165 |
+
st.write("**Birds**")
|
166 |
+
map(filterdata(data, "Aves"), midpoint[0], midpoint[1], 11)
|
167 |
+
|