Guest User

gee timelapse

a guest
Sep 12th, 2022
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import ee
  2. import geemap
  3. import os
  4. from geemap import cartoee
  5.  
  6. import matplotlib.pyplot as plt
  7. %matplotlib inline
  8.  
  9. lon = [lat here]
  10. lat = [lon here]
  11.  
  12. start_date = 1981
  13. end_date = 2000
  14.  
  15. point = ee.Geometry.Point(lon, lat)
  16. years = ee.List.sequence(start_date, end_date)
  17.  
  18. def get_image(years):
  19. start = ee.Date.fromYMD(start_date, 1, 1)
  20. end = ee.Date.fromYMD(end_date, 12, 31)
  21.  
  22. image = (ee.ImageCollection("ECMWF/ERA5/DAILY")
  23. .filterBounds(point)
  24. .filterDate(start, end)
  25. .select('total_precipitation')
  26. .first()
  27. )
  28. return ee.Image(image)
  29.  
  30. collection = ee.ImageCollection(years.map(get_image))
  31.  
  32. vis_params = {
  33. 'min': 0,
  34. 'max': 0.1,
  35. 'palette': ['#FFFFFF', '#00FFFF', '#0080FF', '#DA00FF', '#FFA400', '#FF0000']
  36. }
  37.  
  38. image = ee.Image(collection.first())
  39. geomPoly = ee.Geometry.BBox(10, 10, 10, 10); #dummy coordinates of BB
  40. region = image.clip(geomPoly)
  41. Map.addLayer(region, vis_params, 'First Image')
  42. Map.setCenter(lon, lat, 4)
  43.  
  44. fig = plt.figure(figsize=(10, 8))
  45. selection = [10, 10, 10, 10]
  46. ax = cartoee.get_map(region, region=selection, vis_params=vis_params)
  47. ax.set_title(label="South Asia")
  48.  
  49. cartoee.get_image_collection_gif(
  50. ee_ic = collection,
  51. out_dir=os.path.expanduser("~/Downloads/timelapse"),
  52. out_gif="animation.gif",
  53. vis_params=vis_params,
  54. region=selection,
  55. fps=3,
  56. mp4=True,
  57. plot_title="South Asia | Precipitation",
  58. date_format="YYYY-MM-dd",
  59. fig_size=(10, 8),
  60. dpi_plot=100,
  61. file_format="png",
  62. verbose=True
  63. )
Advertisement
Add Comment
Please, Sign In to add comment