giswqs commited on
Commit
be44c83
·
1 Parent(s): 723797c

Added mp4 options

Browse files
Files changed (1) hide show
  1. apps/timelapse.py +80 -15
apps/timelapse.py CHANGED
@@ -414,6 +414,9 @@ def app():
414
  with st.expander("Customize timelapse"):
415
 
416
  speed = st.slider("Frames per second:", 1, 30, timelapse_speed)
 
 
 
417
  progress_bar_color = st.color_picker(
418
  "Progress bar color:", "#0000ff"
419
  )
@@ -423,7 +426,7 @@ def app():
423
  today.year,
424
  (sensor_start_year, today.year),
425
  )
426
- months = st.slider("Start and end month:", 1, 12, (5, 10))
427
  font_size = st.slider("Font size:", 10, 50, 30)
428
  font_color = st.color_picker("Font color:", "#ffffff")
429
  apply_fmask = st.checkbox(
@@ -434,10 +437,12 @@ def app():
434
  ["arial.ttf", "alibaba.otf"],
435
  index=0,
436
  )
 
437
 
438
  empty_text = st.empty()
439
  empty_image = st.empty()
440
  empty_fire_image = st.empty()
 
441
  submitted = st.form_submit_button("Submit")
442
  if submitted:
443
 
@@ -465,6 +470,8 @@ def app():
465
  end_date=end_date,
466
  bands=bands,
467
  apply_fmask=apply_fmask,
 
 
468
  overlay_data=overlay_data,
469
  overlay_color=overlay_color,
470
  overlay_width=overlay_width,
@@ -483,6 +490,7 @@ def app():
483
  progress_bar_color=progress_bar_color,
484
  progress_bar_height=5,
485
  loop=0,
 
486
  )
487
  elif collection == "Sentinel-2 MSI Surface Reflectance":
488
  out_gif = geemap.sentinel2_timelapse(
@@ -494,6 +502,8 @@ def app():
494
  end_date=end_date,
495
  bands=bands,
496
  apply_fmask=apply_fmask,
 
 
497
  overlay_data=overlay_data,
498
  overlay_color=overlay_color,
499
  overlay_width=overlay_width,
@@ -512,18 +522,27 @@ def app():
512
  progress_bar_color=progress_bar_color,
513
  progress_bar_height=5,
514
  loop=0,
 
515
  )
516
 
517
- if os.path.exists(out_gif):
518
- geemap.reduce_gif_size(out_gif)
519
 
520
  empty_text.text(
521
  "Right click the GIF to save it to your computer👇"
522
  )
523
  empty_image.image(out_gif)
 
 
 
 
 
 
 
 
 
524
  else:
525
  empty_text.error(
526
- "You probably requested too much data. Try reducing the ROI or timespan."
527
  )
528
 
529
  elif collection == "Geostationary Operational Environmental Satellites (GOES)":
@@ -597,10 +616,14 @@ def app():
597
  )
598
  font_size = st.slider("Font size:", 10, 50, 20)
599
  font_color = st.color_picker("Font color:", "#ffffff")
 
 
600
  empty_text = st.empty()
601
  empty_image = st.empty()
 
602
  empty_fire_text = st.empty()
603
  empty_fire_image = st.empty()
 
604
  submitted = st.form_submit_button("Submit")
605
  if submitted:
606
  if sample_roi == "Uploaded GeoJSON" and data is None:
@@ -633,14 +656,23 @@ def app():
633
  overlay_color=overlay_color,
634
  overlay_width=overlay_width,
635
  overlay_opacity=overlay_opacity,
 
636
  )
637
 
638
- if os.path.exists(out_gif):
639
  empty_text.text(
640
  "Right click the GIF to save it to your computer👇"
641
  )
642
  empty_image.image(out_gif)
643
 
 
 
 
 
 
 
 
 
644
  if add_fire:
645
  out_fire_gif = geemap.temp_file_path(".gif")
646
  empty_fire_text.text(
@@ -704,8 +736,17 @@ def app():
704
  )
705
  font_size = st.slider("Font size:", 10, 50, 20)
706
  font_color = st.color_picker("Font color:", "#ffffff")
 
 
 
 
 
 
 
 
707
  empty_text = st.empty()
708
  empty_image = st.empty()
 
709
 
710
  submitted = st.form_submit_button("Submit")
711
  if submitted:
@@ -730,6 +771,7 @@ def app():
730
  overlay_color=overlay_color,
731
  overlay_width=overlay_width,
732
  overlay_opacity=overlay_opacity,
 
733
  )
734
 
735
  geemap.reduce_gif_size(out_gif)
@@ -739,6 +781,14 @@ def app():
739
  )
740
  empty_image.image(out_gif)
741
 
 
 
 
 
 
 
 
 
742
  elif collection == "Any Earth Engine ImageCollection":
743
 
744
  with st.form("submit_ts_form"):
@@ -793,9 +843,11 @@ def app():
793
  ["arial.ttf", "alibaba.otf"],
794
  index=0,
795
  )
 
796
 
797
  empty_text = st.empty()
798
  empty_image = st.empty()
 
799
  empty_fire_image = st.empty()
800
 
801
  roi = None
@@ -844,15 +896,22 @@ def app():
844
  progress_bar_color=progress_bar_color,
845
  progress_bar_height=5,
846
  loop=0,
 
847
  )
848
 
849
- geemap.reduce_gif_size(out_gif)
850
-
851
  empty_text.text(
852
  "Right click the GIF to save it to your computer👇"
853
  )
854
  empty_image.image(out_gif)
855
 
 
 
 
 
 
 
 
 
856
  elif collection == "MODIS Gap filled Land Surface Temperature Daily":
857
 
858
  with st.form("submit_ts_form"):
@@ -878,11 +937,6 @@ def app():
878
  ["median", "mean", "min", "max", "sum", "variance", "stdDev"],
879
  index=0,
880
  )
881
- # data_format = st.selectbox(
882
- # "Select a date format to show on the timelapse:",
883
- # list(feq_dict.keys()),
884
- # index=list(feq_dict.keys()).index(frequency),
885
- # )
886
 
887
  speed = st.slider("Frames per second:", 1, 30, 5)
888
  add_progress_bar = st.checkbox("Add a progress bar", True)
@@ -896,10 +950,11 @@ def app():
896
  ["arial.ttf", "alibaba.otf"],
897
  index=0,
898
  )
 
899
 
900
  empty_text = st.empty()
901
  empty_image = st.empty()
902
- empty_fire_image = st.empty()
903
 
904
  roi = None
905
  if st.session_state.get("roi") is not None:
@@ -916,7 +971,7 @@ def app():
916
  else:
917
 
918
  empty_text.text("Computing... Please wait...")
919
- geemap.create_timelapse(
920
  st.session_state.get("ee_asset_id"),
921
  start_date=start_date.strftime("%Y-%m-%d"),
922
  end_date=end_date.strftime("%Y-%m-%d"),
@@ -947,9 +1002,10 @@ def app():
947
  progress_bar_color=progress_bar_color,
948
  progress_bar_height=5,
949
  loop=0,
 
950
  )
951
 
952
- if os.path.exists(out_gif):
953
 
954
  geemap.reduce_gif_size(out_gif)
955
 
@@ -957,6 +1013,15 @@ def app():
957
  "Right click the GIF to save it to your computer👇"
958
  )
959
  empty_image.image(out_gif)
 
 
 
 
 
 
 
 
 
960
  else:
961
  st.error(
962
  "Something went wrong. You probably requested too much data. Try reducing the ROI or timespan."
 
414
  with st.expander("Customize timelapse"):
415
 
416
  speed = st.slider("Frames per second:", 1, 30, timelapse_speed)
417
+ dimensions = st.slider(
418
+ "Maximum dimensions (Width*Height) in pixels", 768, 2000, 768
419
+ )
420
  progress_bar_color = st.color_picker(
421
  "Progress bar color:", "#0000ff"
422
  )
 
426
  today.year,
427
  (sensor_start_year, today.year),
428
  )
429
+ months = st.slider("Start and end month:", 1, 12, (1, 12))
430
  font_size = st.slider("Font size:", 10, 50, 30)
431
  font_color = st.color_picker("Font color:", "#ffffff")
432
  apply_fmask = st.checkbox(
 
437
  ["arial.ttf", "alibaba.otf"],
438
  index=0,
439
  )
440
+ mp4 = st.checkbox("Save timelapse as MP4", True)
441
 
442
  empty_text = st.empty()
443
  empty_image = st.empty()
444
  empty_fire_image = st.empty()
445
+ empty_video = st.container()
446
  submitted = st.form_submit_button("Submit")
447
  if submitted:
448
 
 
470
  end_date=end_date,
471
  bands=bands,
472
  apply_fmask=apply_fmask,
473
+ frames_per_second=speed,
474
+ dimensions=dimensions,
475
  overlay_data=overlay_data,
476
  overlay_color=overlay_color,
477
  overlay_width=overlay_width,
 
490
  progress_bar_color=progress_bar_color,
491
  progress_bar_height=5,
492
  loop=0,
493
+ mp4=mp4,
494
  )
495
  elif collection == "Sentinel-2 MSI Surface Reflectance":
496
  out_gif = geemap.sentinel2_timelapse(
 
502
  end_date=end_date,
503
  bands=bands,
504
  apply_fmask=apply_fmask,
505
+ frames_per_second=speed,
506
+ dimensions=dimensions,
507
  overlay_data=overlay_data,
508
  overlay_color=overlay_color,
509
  overlay_width=overlay_width,
 
522
  progress_bar_color=progress_bar_color,
523
  progress_bar_height=5,
524
  loop=0,
525
+ mp4=mp4,
526
  )
527
 
528
+ if out_gif is not None and os.path.exists(out_gif):
 
529
 
530
  empty_text.text(
531
  "Right click the GIF to save it to your computer👇"
532
  )
533
  empty_image.image(out_gif)
534
+
535
+ out_mp4 = out_gif.replace(".gif", ".mp4")
536
+ if mp4 and os.path.exists(out_mp4):
537
+ with empty_video:
538
+ st.text(
539
+ "Right click the MP4 to save it to your computer👇"
540
+ )
541
+ st.video(out_gif.replace(".gif", ".mp4"))
542
+
543
  else:
544
  empty_text.error(
545
+ "Something went wrong. You probably requested too much data. Try reducing the ROI or timespan."
546
  )
547
 
548
  elif collection == "Geostationary Operational Environmental Satellites (GOES)":
 
616
  )
617
  font_size = st.slider("Font size:", 10, 50, 20)
618
  font_color = st.color_picker("Font color:", "#ffffff")
619
+ mp4 = st.checkbox("Save timelapse as MP4", True)
620
+
621
  empty_text = st.empty()
622
  empty_image = st.empty()
623
+ empty_video = st.container()
624
  empty_fire_text = st.empty()
625
  empty_fire_image = st.empty()
626
+
627
  submitted = st.form_submit_button("Submit")
628
  if submitted:
629
  if sample_roi == "Uploaded GeoJSON" and data is None:
 
656
  overlay_color=overlay_color,
657
  overlay_width=overlay_width,
658
  overlay_opacity=overlay_opacity,
659
+ mp4=mp4,
660
  )
661
 
662
+ if out_gif is not None and os.path.exists(out_gif):
663
  empty_text.text(
664
  "Right click the GIF to save it to your computer👇"
665
  )
666
  empty_image.image(out_gif)
667
 
668
+ out_mp4 = out_gif.replace(".gif", ".mp4")
669
+ if mp4 and os.path.exists(out_mp4):
670
+ with empty_video:
671
+ st.text(
672
+ "Right click the MP4 to save it to your computer👇"
673
+ )
674
+ st.video(out_gif.replace(".gif", ".mp4"))
675
+
676
  if add_fire:
677
  out_fire_gif = geemap.temp_file_path(".gif")
678
  empty_fire_text.text(
 
736
  )
737
  font_size = st.slider("Font size:", 10, 50, 20)
738
  font_color = st.color_picker("Font color:", "#ffffff")
739
+
740
+ font_type = st.selectbox(
741
+ "Select the font type for the title:",
742
+ ["arial.ttf", "alibaba.otf"],
743
+ index=0,
744
+ )
745
+ mp4 = st.checkbox("Save timelapse as MP4", True)
746
+
747
  empty_text = st.empty()
748
  empty_image = st.empty()
749
+ empty_video = st.container()
750
 
751
  submitted = st.form_submit_button("Submit")
752
  if submitted:
 
771
  overlay_color=overlay_color,
772
  overlay_width=overlay_width,
773
  overlay_opacity=overlay_opacity,
774
+ mp4=mp4,
775
  )
776
 
777
  geemap.reduce_gif_size(out_gif)
 
781
  )
782
  empty_image.image(out_gif)
783
 
784
+ out_mp4 = out_gif.replace(".gif", ".mp4")
785
+ if mp4 and os.path.exists(out_mp4):
786
+ with empty_video:
787
+ st.text(
788
+ "Right click the MP4 to save it to your computer👇"
789
+ )
790
+ st.video(out_gif.replace(".gif", ".mp4"))
791
+
792
  elif collection == "Any Earth Engine ImageCollection":
793
 
794
  with st.form("submit_ts_form"):
 
843
  ["arial.ttf", "alibaba.otf"],
844
  index=0,
845
  )
846
+ mp4 = st.checkbox("Save timelapse as MP4", True)
847
 
848
  empty_text = st.empty()
849
  empty_image = st.empty()
850
+ empty_video = st.container()
851
  empty_fire_image = st.empty()
852
 
853
  roi = None
 
896
  progress_bar_color=progress_bar_color,
897
  progress_bar_height=5,
898
  loop=0,
899
+ mp4=mp4,
900
  )
901
 
 
 
902
  empty_text.text(
903
  "Right click the GIF to save it to your computer👇"
904
  )
905
  empty_image.image(out_gif)
906
 
907
+ out_mp4 = out_gif.replace(".gif", ".mp4")
908
+ if mp4 and os.path.exists(out_mp4):
909
+ with empty_video:
910
+ st.text(
911
+ "Right click the MP4 to save it to your computer👇"
912
+ )
913
+ st.video(out_gif.replace(".gif", ".mp4"))
914
+
915
  elif collection == "MODIS Gap filled Land Surface Temperature Daily":
916
 
917
  with st.form("submit_ts_form"):
 
937
  ["median", "mean", "min", "max", "sum", "variance", "stdDev"],
938
  index=0,
939
  )
 
 
 
 
 
940
 
941
  speed = st.slider("Frames per second:", 1, 30, 5)
942
  add_progress_bar = st.checkbox("Add a progress bar", True)
 
950
  ["arial.ttf", "alibaba.otf"],
951
  index=0,
952
  )
953
+ mp4 = st.checkbox("Save timelapse as MP4", True)
954
 
955
  empty_text = st.empty()
956
  empty_image = st.empty()
957
+ empty_video = st.container()
958
 
959
  roi = None
960
  if st.session_state.get("roi") is not None:
 
971
  else:
972
 
973
  empty_text.text("Computing... Please wait...")
974
+ out_gif = geemap.create_timelapse(
975
  st.session_state.get("ee_asset_id"),
976
  start_date=start_date.strftime("%Y-%m-%d"),
977
  end_date=end_date.strftime("%Y-%m-%d"),
 
1002
  progress_bar_color=progress_bar_color,
1003
  progress_bar_height=5,
1004
  loop=0,
1005
+ mp4=mp4,
1006
  )
1007
 
1008
+ if out_gif is not None and os.path.exists(out_gif):
1009
 
1010
  geemap.reduce_gif_size(out_gif)
1011
 
 
1013
  "Right click the GIF to save it to your computer👇"
1014
  )
1015
  empty_image.image(out_gif)
1016
+
1017
+ out_mp4 = out_gif.replace(".gif", ".mp4")
1018
+ if mp4 and os.path.exists(out_mp4):
1019
+ with empty_video:
1020
+ st.text(
1021
+ "Right click the MP4 to save it to your computer👇"
1022
+ )
1023
+ st.video(out_gif.replace(".gif", ".mp4"))
1024
+
1025
  else:
1026
  st.error(
1027
  "Something went wrong. You probably requested too much data. Try reducing the ROI or timespan."