18 create landsat timelapse
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import geemap
import geemap
In [3]:
Copied!
geemap.show_youtube('OwjSJnGWKJs')
geemap.show_youtube('OwjSJnGWKJs')
In [4]:
Copied!
# geemap.update_package()
# geemap.update_package()
In [5]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Generate a Landsat timelapse animation¶
In [6]:
Copied!
import os
out_dir = os.path.join(os.path.expanduser("~"), 'Downloads')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
import os
out_dir = os.path.join(os.path.expanduser("~"), 'Downloads')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
In [7]:
Copied!
label = 'Urban Growth in Las Vegas'
Map.add_landsat_ts_gif(
label=label,
start_year=1985,
bands=['Red', 'Green', 'Blue'],
font_color='white',
frames_per_second=10,
progress_bar_color='blue',
)
label = 'Urban Growth in Las Vegas'
Map.add_landsat_ts_gif(
label=label,
start_year=1985,
bands=['Red', 'Green', 'Blue'],
font_color='white',
frames_per_second=10,
progress_bar_color='blue',
)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [7], in <cell line: 2>() 1 label = 'Urban Growth in Las Vegas' ----> 2 Map.add_landsat_ts_gif( 3 label=label, 4 start_year=1985, 5 bands=['Red', 'Green', 'Blue'], 6 font_color='white', 7 frames_per_second=10, 8 progress_bar_color='blue', 9 ) AttributeError: 'Map' object has no attribute 'add_landsat_ts_gif'
Create Landsat timeseries¶
In [8]:
Copied!
import os
import ee
import geemap
import os
import ee
import geemap
In [9]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[9]:
Make this Notebook Trusted to load map: File -> Trust Notebook
You and define an roi or draw a rectangle on the map
In [10]:
Copied!
roi = ee.Geometry.Polygon(
[
[
[-115.471773, 35.892718],
[-115.471773, 36.409454],
[-114.271283, 36.409454],
[-114.271283, 35.892718],
[-115.471773, 35.892718],
]
],
None,
False,
)
roi = ee.Geometry.Polygon(
[
[
[-115.471773, 35.892718],
[-115.471773, 36.409454],
[-114.271283, 36.409454],
[-114.271283, 35.892718],
[-115.471773, 35.892718],
]
],
None,
False,
)
In [11]:
Copied!
# roi = Map.draw_last_feature
# roi = Map.draw_last_feature
In [12]:
Copied!
collection = geemap.landsat_timeseries(
roi=roi, start_year=1985, end_year=2019, start_date='06-10', end_date='09-20'
)
collection = geemap.landsat_timeseries(
roi=roi, start_year=1985, end_year=2019, start_date='06-10', end_date='09-20'
)
In [13]:
Copied!
print(collection.size().getInfo())
print(collection.size().getInfo())
35
In [14]:
Copied!
first_image = collection.first()
vis = {'bands': ['NIR', 'Red', 'Green'], 'min': 0, 'max': 4000, 'gamma': [1, 1, 1]}
Map.addLayer(first_image, vis, 'First image')
first_image = collection.first()
vis = {'bands': ['NIR', 'Red', 'Green'], 'min': 0, 'max': 4000, 'gamma': [1, 1, 1]}
Map.addLayer(first_image, vis, 'First image')
Download ImageCollection as a GIF¶
In [15]:
Copied!
# Define arguments for animation function parameters.
video_args = {
'dimensions': 768,
'region': roi,
'framesPerSecond': 10,
'bands': ['NIR', 'Red', 'Green'],
'min': 0,
'max': 4000,
'gamma': [1, 1, 1],
}
# Define arguments for animation function parameters.
video_args = {
'dimensions': 768,
'region': roi,
'framesPerSecond': 10,
'bands': ['NIR', 'Red', 'Green'],
'min': 0,
'max': 4000,
'gamma': [1, 1, 1],
}
In [16]:
Copied!
work_dir = os.path.join(os.path.expanduser("~"), 'Downloads')
if not os.path.exists(work_dir):
os.makedirs(work_dir)
out_gif = os.path.join(work_dir, "landsat_ts.gif")
work_dir = os.path.join(os.path.expanduser("~"), 'Downloads')
if not os.path.exists(work_dir):
os.makedirs(work_dir)
out_gif = os.path.join(work_dir, "landsat_ts.gif")
In [17]:
Copied!
geemap.download_ee_video(collection, video_args, out_gif)
geemap.download_ee_video(collection, video_args, out_gif)
Generating URL... Downloading GIF image from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/videoThumbnails/f6c5be850930843324ef6439314a8249-a4952b5bc4b67722546d27abdb5779ee:getPixels Please wait ... The GIF image has been saved to: /home/runner/Downloads/landsat_ts.gif
Add animated text to GIF¶
In [18]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
In [19]:
Copied!
texted_gif = os.path.join(work_dir, "landsat_ts_text.gif")
geemap.add_text_to_gif(
out_gif,
texted_gif,
xy=('3%', '5%'),
text_sequence=1985,
font_size=30,
font_color='#ffffff',
add_progress_bar=False,
)
texted_gif = os.path.join(work_dir, "landsat_ts_text.gif")
geemap.add_text_to_gif(
out_gif,
texted_gif,
xy=('3%', '5%'),
text_sequence=1985,
font_size=30,
font_color='#ffffff',
add_progress_bar=False,
)
In [20]:
Copied!
label = 'Urban Growth in Las Vegas'
geemap.add_text_to_gif(
texted_gif,
texted_gif,
xy=('2%', '88%'),
text_sequence=label,
font_size=30,
font_color='#ffffff',
progress_bar_color='cyan',
)
label = 'Urban Growth in Las Vegas'
geemap.add_text_to_gif(
texted_gif,
texted_gif,
xy=('2%', '88%'),
text_sequence=label,
font_size=30,
font_color='#ffffff',
progress_bar_color='cyan',
)
In [21]:
Copied!
geemap.show_image(texted_gif)
geemap.show_image(texted_gif)
Last update:
2022-03-14