Spaces:
Sleeping
Sleeping
...
Browse files
app.py
CHANGED
@@ -31,6 +31,7 @@ st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon
|
|
31 |
|
32 |
|
33 |
|
|
|
34 |
# LOAD DATA ONCE
|
35 |
@st.cache_resource
|
36 |
def load_data():
|
@@ -42,8 +43,28 @@ def load_data():
|
|
42 |
SET s3_endpoint='minio.carlboettiger.info';
|
43 |
CREATE VIEW gb AS SELECT * FROM read_parquet('s3://shared-data/gbif_gb/**');
|
44 |
''')
|
45 |
-
return con.table("gb")
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
def map(data, lat, lon, zoom):
|
49 |
st.write(
|
@@ -70,34 +91,12 @@ def map(data, lat, lon, zoom):
|
|
70 |
)
|
71 |
|
72 |
|
73 |
-
# +
|
74 |
-
# FILTER DATA FOR A SPECIFIC YEAR. ibis lazytable not cache-able..
|
75 |
-
|
76 |
-
# @st.cache_data
|
77 |
-
def filterdata(df, year):
|
78 |
-
hzoom = "h3z" + str(6)
|
79 |
-
data = (
|
80 |
-
df.
|
81 |
-
filter(_.year == year).
|
82 |
-
select(_[hzoom], _.species).
|
83 |
-
distinct().
|
84 |
-
group_by(_[hzoom]).
|
85 |
-
aggregate(n = _.count()).
|
86 |
-
mutate(color = 255 * _.n / _.n.max()).
|
87 |
-
to_pandas()
|
88 |
-
)
|
89 |
-
return data
|
90 |
-
|
91 |
-
|
92 |
-
# -
|
93 |
-
|
94 |
# CALCULATE MIDPOINT FOR GIVEN SET OF DATA
|
95 |
@st.cache_data
|
96 |
def mpoint(lat, lon):
|
97 |
return (np.average(lat), np.average(lon))
|
98 |
|
99 |
|
100 |
-
|
101 |
# STREAMLIT APP LAYOUT
|
102 |
data = load_data()
|
103 |
|
|
|
31 |
|
32 |
|
33 |
|
34 |
+
# +
|
35 |
# LOAD DATA ONCE
|
36 |
@st.cache_resource
|
37 |
def load_data():
|
|
|
43 |
SET s3_endpoint='minio.carlboettiger.info';
|
44 |
CREATE VIEW gb AS SELECT * FROM read_parquet('s3://shared-data/gbif_gb/**');
|
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 |
+
@st.cache_data
|
62 |
+
def filterdata(df, year):
|
63 |
+
return df[df.year == year]
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
# -
|
68 |
|
69 |
def map(data, lat, lon, zoom):
|
70 |
st.write(
|
|
|
91 |
)
|
92 |
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# CALCULATE MIDPOINT FOR GIVEN SET OF DATA
|
95 |
@st.cache_data
|
96 |
def mpoint(lat, lon):
|
97 |
return (np.average(lat), np.average(lon))
|
98 |
|
99 |
|
|
|
100 |
# STREAMLIT APP LAYOUT
|
101 |
data = load_data()
|
102 |
|