cboettig commited on
Commit
9a29af3
·
1 Parent(s): 92c5791
Files changed (2) hide show
  1. app.py +22 -34
  2. uk.csv.gz +0 -3
app.py CHANGED
@@ -35,17 +35,14 @@ st.set_page_config(layout="wide", page_title="GBIF Biodiversity Demo", page_icon
35
  @st.cache_resource
36
  def load_data():
37
  con = ibis.duckdb.connect()
38
- path = "butterflies_gb.parquet"
39
- if os.path.isfile(path):
40
- return con.read_parquet(path)
41
- df = con.read_parquet("s3://anonymous@gbif-open-data-us-east-1/occurrence/2023-06-01/occurrence.parquet")
42
- data = (df
43
- .dropna(["decimallongitude", "decimallatitude", "year"], how="any")
44
- .filter([_.order == "Lepidoptera", _.countrycode=="GB"])
45
- .filter(_.year >= 2010)
46
- .select(['year', 'decimallongitude', 'decimallatitude'])
47
- )
48
- return data
49
 
50
 
51
  def map(data, lat, lon, zoom):
@@ -60,7 +57,7 @@ def map(data, lat, lon, zoom):
60
  },
61
  layers=[
62
  pdk.Layer(
63
- "HexagonLayer",
64
  data=data,
65
  get_position=["decimallongitude", "decimallatitude"],
66
  radius=1000,
@@ -78,7 +75,18 @@ def map(data, lat, lon, zoom):
78
 
79
  # @st.cache_data
80
  def filterdata(df, year):
81
- return df.filter(_.year == year).to_pandas()
 
 
 
 
 
 
 
 
 
 
 
82
 
83
 
84
  # -
@@ -130,7 +138,7 @@ with row1_2:
130
  )
131
 
132
  # LAYING OUT THE MIDDLE SECTION OF THE APP WITH THE MAPS
133
- row2_1, row2_2, row2_3, row2_4 = st.columns((2, 1, 1, 1))
134
 
135
  # +
136
  # SETTING THE ZOOM LOCATIONS FOR THE AIRPORTS
@@ -145,23 +153,3 @@ with row2_1:
145
  f"""**Large Map**"""
146
  )
147
  map(filterdata(data, year_selected), midpoint[0], midpoint[1], 4)
148
-
149
- with row2_2:
150
- st.write("**Panel 1**")
151
- map(filterdata(data, year_selected), midpoint[0], midpoint[1], 3)
152
-
153
- with row2_3:
154
- st.write("**Panel 2**")
155
- map(filterdata(data, year_selected), midpoint[0], midpoint[1], 2)
156
-
157
- with row2_4:
158
- st.write("**Panel 3**")
159
- map(filterdata(data, year_selected), midpoint[0], midpoint[1], 1)
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
 
35
  @st.cache_resource
36
  def load_data():
37
  con = ibis.duckdb.connect()
38
+ con.raw_sql('''
39
+ INSTALL httpfs;
40
+ LOAD httpfs;
41
+ SET s3_url_style='path';
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):
 
57
  },
58
  layers=[
59
  pdk.Layer(
60
+ "H3HexagonLayer",
61
  data=data,
62
  get_position=["decimallongitude", "decimallatitude"],
63
  radius=1000,
 
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
  # -
 
138
  )
139
 
140
  # LAYING OUT THE MIDDLE SECTION OF THE APP WITH THE MAPS
141
+ row2_1 = st.columns((2))
142
 
143
  # +
144
  # SETTING THE ZOOM LOCATIONS FOR THE AIRPORTS
 
153
  f"""**Large Map**"""
154
  )
155
  map(filterdata(data, year_selected), midpoint[0], midpoint[1], 4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
uk.csv.gz DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:2ced2e4e5b2558830129a13acba50c321d76bd531bb9e76c64422cf5f100ca98
3
- size 54615