giswqs commited on
Commit
c0ac56e
·
1 Parent(s): 516b90f

Added Sentinel-2 timelapse

Browse files
Files changed (1) hide show
  1. apps/timelapse.py +93 -53
apps/timelapse.py CHANGED
@@ -35,7 +35,7 @@ def app():
35
 
36
  today = date.today()
37
 
38
- st.title("Create Landsat/GOES/MODIS Timelapse")
39
 
40
  st.markdown(
41
  """
@@ -68,13 +68,17 @@ def app():
68
  "Select a satellite image collection: ",
69
  [
70
  "Landsat TM-ETM-OLI Surface Reflectance",
 
71
  "Geostationary Operational Environmental Satellites (GOES)",
72
  "MODIS Vegetation Indices (NDVI/EVI) 16-Day Global 1km",
73
  ],
74
  index=0,
75
  )
76
 
77
- if collection == "Landsat TM-ETM-OLI Surface Reflectance":
 
 
 
78
  roi_options = ["Uploaded GeoJSON"] + list(landsat_rois.keys())
79
 
80
  elif collection == "Geostationary Operational Environmental Satellites (GOES)":
@@ -89,9 +93,58 @@ def app():
89
  index=0,
90
  )
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  with row1_col1:
93
- # m = geemap.Map(basemap="HYBRID", plugin_Draw=True, draw_export=True)
94
- # m.add_basemap("ROADMAP")
95
 
96
  with st.expander(
97
  "Steps: Draw a rectangle on the map -> Export it as a GeoJSON -> Upload it back to the app -> Click the Submit button. Expand this tab to see a demo 👉"
@@ -118,7 +171,10 @@ def app():
118
  else:
119
  m.set_center(4.20, 18.63, zoom=2)
120
  else:
121
- if collection == "Landsat TM-ETM-OLI Surface Reflectance":
 
 
 
122
  gdf = gpd.GeoDataFrame(
123
  index=[0], crs=crs, geometry=[landsat_rois[sample_roi]]
124
  )
@@ -136,7 +192,10 @@ def app():
136
 
137
  if sample_roi != "Uploaded GeoJSON":
138
 
139
- if collection == "Landsat TM-ETM-OLI Surface Reflectance":
 
 
 
140
  gdf = gpd.GeoDataFrame(
141
  index=[0], crs=crs, geometry=[landsat_rois[sample_roi]]
142
  )
@@ -162,8 +221,19 @@ def app():
162
 
163
  with row1_col2:
164
 
165
- if collection == "Landsat TM-ETM-OLI Surface Reflectance":
 
 
 
166
 
 
 
 
 
 
 
 
 
167
  video_empty.video("https://youtu.be/VVRK_-dEjR4")
168
 
169
  with st.form("submit_landsat_form"):
@@ -174,7 +244,7 @@ def app():
174
  out_gif = geemap.temp_file_path(".gif")
175
 
176
  title = st.text_input(
177
- "Enter a title to show on the timelapse: ", "Landsat Timelapse"
178
  )
179
  RGB = st.selectbox(
180
  "Select an RGB band combination:",
@@ -195,12 +265,15 @@ def app():
195
 
196
  with st.expander("Customize timelapse"):
197
 
198
- speed = st.slider("Frames per second:", 1, 30, 10)
199
  progress_bar_color = st.color_picker(
200
  "Progress bar color:", "#0000ff"
201
  )
202
  years = st.slider(
203
- "Start and end year:", 1984, today.year, (1984, today.year)
 
 
 
204
  )
205
  months = st.slider("Start and end month:", 1, 12, (5, 10))
206
  font_size = st.slider("Font size:", 10, 50, 30)
@@ -228,6 +301,7 @@ def app():
228
  start_date = str(months[0]).zfill(2) + "-01"
229
  end_date = str(months[1]).zfill(2) + "-30"
230
  bands = RGB.split("/")
 
231
 
232
  out_gif = geemap.landsat_timelapse(
233
  roi=roi,
@@ -238,6 +312,10 @@ def app():
238
  end_date=end_date,
239
  bands=bands,
240
  apply_fmask=apply_fmask,
 
 
 
 
241
  )
242
 
243
  geemap.add_text_to_gif(
@@ -376,6 +454,10 @@ def app():
376
  progress_bar_color=progress_bar_color,
377
  progress_bar_height=5,
378
  loop=0,
 
 
 
 
379
  )
380
 
381
  if os.path.exists(out_gif):
@@ -423,49 +505,6 @@ def app():
423
  satellite = st.selectbox("Select a satellite:", ["Terra", "Aqua"])
424
  band = st.selectbox("Select a band:", ["NDVI", "EVI"])
425
 
426
- add_outline = st.checkbox(
427
- "Overlay an administrative boundary on timelapse", False
428
- )
429
-
430
- if add_outline:
431
-
432
- with st.expander("Customize administrative boundary", True):
433
-
434
- overlay_options = {
435
- "User-defined": None,
436
- "Countries": "countries",
437
- "US States": "us_states",
438
- "China Administrative Boundary Level 0": "chn_admin_level0",
439
- "China Administrative Boundary Level 1": "chn_admin_level1",
440
- "China Administrative Boundary Level 2": "chn_admin_level2",
441
- }
442
-
443
- overlay = st.selectbox(
444
- "Select an administrative boundary:",
445
- list(overlay_options.keys()),
446
- index=1,
447
- )
448
-
449
- overlay_data = overlay_options[overlay]
450
-
451
- if overlay_data is None:
452
- asset_id = st.text_input(
453
- "Specify an ee.FeatureCollection asset id:",
454
- "USDOS/LSIB_SIMPLE/2017",
455
- )
456
- overlay_data = ee.FeatureCollection(asset_id)
457
-
458
- overlay_color = st.color_picker(
459
- "Select a color for the administrative boundary:", "#000000"
460
- )
461
- overlay_width = st.slider(
462
- "Select a line width for the administrative boundary:", 1, 10, 1
463
- )
464
- else:
465
- overlay_data = None
466
- overlay_color = None
467
- overlay_width = None
468
-
469
  with st.form("submit_modis_form"):
470
 
471
  roi = None
@@ -516,6 +555,7 @@ def app():
516
  overlay_data=overlay_data,
517
  overlay_color=overlay_color,
518
  overlay_width=overlay_width,
 
519
  )
520
 
521
  geemap.reduce_gif_size(out_gif)
 
35
 
36
  today = date.today()
37
 
38
+ st.title("Create Timelapse")
39
 
40
  st.markdown(
41
  """
 
68
  "Select a satellite image collection: ",
69
  [
70
  "Landsat TM-ETM-OLI Surface Reflectance",
71
+ "Sentinel-2 MSI Surface Reflectance",
72
  "Geostationary Operational Environmental Satellites (GOES)",
73
  "MODIS Vegetation Indices (NDVI/EVI) 16-Day Global 1km",
74
  ],
75
  index=0,
76
  )
77
 
78
+ if collection in [
79
+ "Landsat TM-ETM-OLI Surface Reflectance",
80
+ "Sentinel-2 MSI Surface Reflectance",
81
+ ]:
82
  roi_options = ["Uploaded GeoJSON"] + list(landsat_rois.keys())
83
 
84
  elif collection == "Geostationary Operational Environmental Satellites (GOES)":
 
93
  index=0,
94
  )
95
 
96
+ add_outline = st.checkbox(
97
+ "Overlay an administrative boundary on timelapse", False
98
+ )
99
+
100
+ if add_outline:
101
+
102
+ with st.expander("Customize administrative boundary", True):
103
+
104
+ overlay_options = {
105
+ "User-defined": None,
106
+ "Continents": "continents",
107
+ "Countries": "countries",
108
+ "US States": "us_states",
109
+ "China Administrative Boundary Level 0": "chn_admin_level0",
110
+ "China Administrative Boundary Level 1": "chn_admin_level1",
111
+ "China Administrative Boundary Level 2": "chn_admin_level2",
112
+ }
113
+
114
+ overlay = st.selectbox(
115
+ "Select an administrative boundary:",
116
+ list(overlay_options.keys()),
117
+ index=2,
118
+ )
119
+
120
+ overlay_data = overlay_options[overlay]
121
+
122
+ if overlay_data is None:
123
+ overlay_data = st.text_input(
124
+ "Enter an HTTP URL to a GeoJSON file or an ee.FeatureCollection asset id:",
125
+ "https://raw.githubusercontent.com/giswqs/geemap/master/examples/data/countries.geojson",
126
+ )
127
+
128
+ overlay_color = st.color_picker(
129
+ "Select a color for the administrative boundary:", "#000000"
130
+ )
131
+ overlay_width = st.slider(
132
+ "Select a line width for the administrative boundary:", 1, 20, 1
133
+ )
134
+ overlay_opacity = st.slider(
135
+ "Select an opacity for the administrative boundary:",
136
+ 0.0,
137
+ 1.0,
138
+ 1.0,
139
+ 0.05,
140
+ )
141
+ else:
142
+ overlay_data = None
143
+ overlay_color = "black"
144
+ overlay_width = 1
145
+ overlay_opacity = 1
146
+
147
  with row1_col1:
 
 
148
 
149
  with st.expander(
150
  "Steps: Draw a rectangle on the map -> Export it as a GeoJSON -> Upload it back to the app -> Click the Submit button. Expand this tab to see a demo 👉"
 
171
  else:
172
  m.set_center(4.20, 18.63, zoom=2)
173
  else:
174
+ if collection in [
175
+ "Landsat TM-ETM-OLI Surface Reflectance",
176
+ "Sentinel-2 MSI Surface Reflectance",
177
+ ]:
178
  gdf = gpd.GeoDataFrame(
179
  index=[0], crs=crs, geometry=[landsat_rois[sample_roi]]
180
  )
 
192
 
193
  if sample_roi != "Uploaded GeoJSON":
194
 
195
+ if collection in [
196
+ "Landsat TM-ETM-OLI Surface Reflectance",
197
+ "Sentinel-2 MSI Surface Reflectance",
198
+ ]:
199
  gdf = gpd.GeoDataFrame(
200
  index=[0], crs=crs, geometry=[landsat_rois[sample_roi]]
201
  )
 
221
 
222
  with row1_col2:
223
 
224
+ if collection in [
225
+ "Landsat TM-ETM-OLI Surface Reflectance",
226
+ "Sentinel-2 MSI Surface Reflectance",
227
+ ]:
228
 
229
+ if collection == "Landsat TM-ETM-OLI Surface Reflectance":
230
+ sensor_start_year = 1984
231
+ timelapse_title = "Landsat Timelapse"
232
+ timelapse_speed = 10
233
+ elif collection == "Sentinel-2 MSI Surface Reflectance":
234
+ sensor_start_year = 2015
235
+ timelapse_title = "Sentinel-2 Timelapse"
236
+ timelapse_speed = 5
237
  video_empty.video("https://youtu.be/VVRK_-dEjR4")
238
 
239
  with st.form("submit_landsat_form"):
 
244
  out_gif = geemap.temp_file_path(".gif")
245
 
246
  title = st.text_input(
247
+ "Enter a title to show on the timelapse: ", timelapse_title
248
  )
249
  RGB = st.selectbox(
250
  "Select an RGB band combination:",
 
265
 
266
  with st.expander("Customize timelapse"):
267
 
268
+ speed = st.slider("Frames per second:", 1, 30, timelapse_speed)
269
  progress_bar_color = st.color_picker(
270
  "Progress bar color:", "#0000ff"
271
  )
272
  years = st.slider(
273
+ "Start and end year:",
274
+ sensor_start_year,
275
+ today.year,
276
+ (sensor_start_year, today.year),
277
  )
278
  months = st.slider("Start and end month:", 1, 12, (5, 10))
279
  font_size = st.slider("Font size:", 10, 50, 30)
 
301
  start_date = str(months[0]).zfill(2) + "-01"
302
  end_date = str(months[1]).zfill(2) + "-30"
303
  bands = RGB.split("/")
304
+ print(overlay_color)
305
 
306
  out_gif = geemap.landsat_timelapse(
307
  roi=roi,
 
312
  end_date=end_date,
313
  bands=bands,
314
  apply_fmask=apply_fmask,
315
+ overlay_data=overlay_data,
316
+ overlay_color=overlay_color,
317
+ overlay_width=overlay_width,
318
+ overlay_opacity=overlay_opacity,
319
  )
320
 
321
  geemap.add_text_to_gif(
 
454
  progress_bar_color=progress_bar_color,
455
  progress_bar_height=5,
456
  loop=0,
457
+ overlay_data=overlay_data,
458
+ overlay_color=overlay_color,
459
+ overlay_width=overlay_width,
460
+ overlay_opacity=overlay_opacity,
461
  )
462
 
463
  if os.path.exists(out_gif):
 
505
  satellite = st.selectbox("Select a satellite:", ["Terra", "Aqua"])
506
  band = st.selectbox("Select a band:", ["NDVI", "EVI"])
507
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
508
  with st.form("submit_modis_form"):
509
 
510
  roi = None
 
555
  overlay_data=overlay_data,
556
  overlay_color=overlay_color,
557
  overlay_width=overlay_width,
558
+ overlay_opacity=overlay_opacity,
559
  )
560
 
561
  geemap.reduce_gif_size(out_gif)