-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
331 lines (301 loc) · 9.53 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import pandas as pd
import streamlit as st
from pandas.api.types import (
is_categorical_dtype,
is_datetime64_any_dtype,
is_numeric_dtype,
is_object_dtype,
)
with st.sidebar:
st.title("App Filter Options (Lookup)")
ee_Algorithms = st.expander(label='ee.Algorithms')
with ee_Algorithms:
st.markdown("""
* FMask.fillMinima()
* FMask.matchClouds()
* GeometryConstructors.BBox()
* GeometryConstructors.LineString()
* GeometryConstructors.LinearRing()
* GeometryConstructors.MultiGeometry()
* GeometryConstructors.MultiLineString()
* GeometryConstructors.MultiPoint()
* GeometryConstructors.MultiPolygon()
* GeometryConstructors.Point()
* GeometryConstructors.Polygon()
* GeometryConstructors.Rectangle()
* Image.Segmentation.GMeans()
* Image.Segmentation.KMeans()
* Image.Segmentation.SNIC()
* Image.Segmentation.seedGrid()
* Landsat.TOA()
* Landsat.calibratedRadiance()
* Landsat.pathRowLimit()
* Landsat.simpleCloudScore()
* Landsat.simpleComposite()
* Sentinel2.CDI()
* TemporalSegmentation.Ccdc()
* TemporalSegmentation.Ewmacd()
* TemporalSegmentation.LandTrendr()
* TemporalSegmentation.LandTrendrFit()
* TemporalSegmentation.StructuralChangeBreakpoints()
* TemporalSegmentation.VCT()
* TemporalSegmentation.Verdet()
* CannyEdgeDetector()
* Collection(features)
* CrossCorrelation()
* Date()
* Describe()
* Dictionary()
* Feature()
* HillShadow()
* HoughTransform()
* If()
* IsEqual()
* ObjectType()
* Proj()
* ProjectionTransform()
* String()
* Terrain()
""")
ui_Chart = st.expander(label='ui.Chart')
with ui_Chart:
st.markdown("""
* array.values()
* feature.byFeature()
* feature.byProperty()
* feature.groups()
* feature.histogram()
* image.byClass()
* image.byRegion()
* image.doySeries()
* image.doySeriesByRegion()
* image.doySeriesByYear()
* image.histogram()
* image.regions()
* image.series()
* image.seriesByRegion()
""")
ee_Classifier = st.expander(label='ee.Classifier')
with ee_Classifier:
st.markdown("""
* amnhMaxent()
* decisionTree()
* decisionTreeEnsemble()
* libsvm()
* minimumDistance()
* smileCart()
* smileGradientTreeBoost()
* smileNaiveBayes()
* smileRandomForest()
* spectralRegion()
""")
ee_Clusterer = st.expander(label='ee.Clusterer')
with ee_Clusterer:
st.markdown("""
* wekaCascadeKMeans()
* wekaCobweb()
* wekaKMeans()
* wekaLVQ()
* wekaXMeans()
""")
ee_ImageCollection = st.expander(label='ee.ImageCollection')
with ee_ImageCollection:
st.markdown("""
* COPERNICUS/S2
* COPERNICUS/S2_SR
* COPERNICUS/S1_GRD
* COPERNICUS/S2_HARMONIZED
* ECMWF/ERA5_LAND/MONTHLY
* ESA/WorldCover/v100
* FAO/WAPOR/2/L1_AETI_D
* FAO/WAPOR/2/L1_NPP_D
* FIRMS
* JAXA/GPM_L3/GSMaP/v6/operational
* JRC/GSW1_3/MonthlyHistory
* LANDSAT/LC08/C01/T1_SR
* LANDSAT/LC08/C02/T1_L2
* LANDSAT/LC09/C02/T1_L2
* LANDSAT/LE07/C01/T1_SR
* LANDSAT/LT05/C01/T1_SR
* NASA_USDA/HSL/SMAP10KM_soil_moisture
* projects/sat-io/open-datasets/FABDEM
* projects/sat-io/open-datasets/WSF/WSF_2019
* UCSB-CHG/CHIRPS/DAILY
* UCSB-CHG/CHIRPS/PENTAD
""")
ee_Join = st.expander(label='ee.Join')
with ee_Join:
st.markdown("""
* inner()
* inverted()
* saveAll()
* saveBest()
* saveFirst()
* simple()""")
ee_Kernel = st.expander(label='ee.Kernel')
with ee_Kernel:
st.markdown("""
* chebyshev()
* circle()
* compass()
* cross()
* diamond()
* euclidean()
* fixed()
* gaussian()
* kirsch()
* laplacian4()
* laplacian8()
* manhattan()
* octagon()
* plus()
* prewitt()
* rectangle()
* roberts()
* sobel()
* square()""")
ee_Reducer = st.expander(label='ee.Reducer')
with ee_Reducer:
st.markdown("""
* allNonZero()
* and()
* anyNonZero()
* autoHistogram()
* bitwiseAnd()
* bitwiseOr()
* centeredCovariance()
* circularMean()
* circularStddev()
* circularVariance()
* count()
* countDistinct()
* countDistinctNonNull()
* countEvery()
* countRuns()
* covariance()
* first()
* firstNonNull()
* fixed2DHistogram()
* fixedHistogram()
* frequencyHistogram()
* geometricMedian()
* histogram()
* intervalMean()
* kendallsCorrelation()
* kurtosis()
* last()
* lastNonNull()
* linearFit()
* linearRegression()
* max()
* mean()
* median()
* min()
* minMax()
* mode()
* or()
* pearsonsCorrelation()
* percentile()
* product()
* ridgeRegression()
* robustLinearRegression()
* sampleStdDev()
* sampleVariance()
* sensSlope()
* skew()
* spearmansCorrelation()
* stdDev()
* sum()
* toCollection()
* toList()
* variance()""")
ee_Terrain = st.expander(label='ee.Terrain')
with ee_Terrain:
st.markdown("""
* aspect()
* fillMinima()
* hillShadow()
* hillshade()
* products()
* slope()""")
st.title("Earth Engine App Filter")
st.markdown("""
##### Creator: Philipp Gärtner | Last Update: 23/11/2022
""")
st.markdown("""
[](https://twitter.com/Mixed_Pixels) [](https://mapstodon.space/@Mixed_Pixels) [](https://www.buymeacoffee.com/0l94rzR)
""")
st.write(
"""[Earth Engine Apps](https://developers.google.com/earth-engine/guides/apps) are dynamic, shareable user interfaces for Earth Engine analyses. The [ee-appshot](https://github.com/samapriya/ee-appshot) repository creates a weekly snapshot of available Earth Engine Apps and provides their URL’s and script source codes.
This streamlit app provides an object and method filter which allows the users to quickly get to the app functionality they are interested in.
""")
def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
"""
Adds a UI on top of a dataframe to let viewers filter columns
Args:
df (pd.DataFrame): Original dataframe
Returns:
pd.DataFrame: Filtered dataframe
"""
modify = st.checkbox("Add filters")
if not modify:
return df
df = df.copy()
# Try to convert datetimes into a standard format (datetime, no timezone)
for col in df.columns:
if is_object_dtype(df[col]):
try:
df[col] = pd.to_datetime(df[col])
except Exception:
pass
if is_datetime64_any_dtype(df[col]):
df[col] = df[col].dt.tz_localize(None)
modification_container = st.container()
with modification_container:
to_filter_columns = st.multiselect("Filter dataframe on", df.columns)
for column in to_filter_columns:
left, right = st.columns((1, 20))
left.write("↳")
# Treat columns with < 10 unique values as categorical
if is_categorical_dtype(df[column]) or df[column].nunique() < 10:
user_cat_input = right.multiselect(
f"Values for {column}",
df[column].unique(),
default=list(df[column].unique()),
)
df = df[df[column].isin(user_cat_input)]
elif is_numeric_dtype(df[column]):
_min = float(df[column].min())
_max = float(df[column].max())
step = (_max - _min) / 100
user_num_input = right.slider(
f"Values for {column}",
_min,
_max,
(_min, _max),
step=step,
)
df = df[df[column].between(*user_num_input)]
elif is_datetime64_any_dtype(df[column]):
user_date_input = right.date_input(
f"Values for {column}",
value=(
df[column].min(),
df[column].max(),
),
)
if len(user_date_input) == 2:
user_date_input = tuple(map(pd.to_datetime, user_date_input))
start_date, end_date = user_date_input
df = df.loc[df[column].between(start_date, end_date)]
else:
user_text_input = right.text_input(
f"Substring or regex in {column}",
)
if user_text_input:
df = df[df[column].str.contains(user_text_input)]
return df
df = pd.read_csv(
"ee_df.csv"
)
st.dataframe(filter_dataframe(df))