16 add animated text
Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# !pip install geemap
# !pip install geemap
In [ ]:
Copied!
import geemap
import os
import geemap
import os
In [ ]:
Copied!
geemap.show_youtube('fDnDVuM_Ke4')
geemap.show_youtube('fDnDVuM_Ke4')
In [ ]:
Copied!
# geemap.update_package()
# geemap.update_package()
Add animated text to an existing GIF¶
You can download this GIF example from here. You can also create GIF images from Earth Engine data using this amazing LT-GEE Time Series Animator, which was created by Justin Braaten.
In [ ]:
Copied!
in_gif = os.path.abspath('../data/animation.gif')
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
out_gif = os.path.join(out_dir, 'output.gif')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
in_gif = os.path.abspath('../data/animation.gif')
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
out_gif = os.path.join(out_dir, 'output.gif')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
In [ ]:
Copied!
geemap.show_image(in_gif)
geemap.show_image(in_gif)
Add animated text to GIF¶
In [ ]:
Copied!
geemap.add_text_to_gif(
in_gif,
out_gif,
xy=('5%', '5%'),
text_sequence=1984,
font_size=30,
font_color='#0000ff',
duration=100,
)
geemap.add_text_to_gif(
in_gif,
out_gif,
xy=('5%', '5%'),
text_sequence=1984,
font_size=30,
font_color='#0000ff',
duration=100,
)
In [ ]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
Add place name¶
In [ ]:
Copied!
geemap.add_text_to_gif(
out_gif, out_gif, xy=('30%', '85%'), text_sequence="Las Vegas", font_color='black'
)
geemap.add_text_to_gif(
out_gif, out_gif, xy=('30%', '85%'), text_sequence="Las Vegas", font_color='black'
)
In [ ]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
Change font type¶
In [ ]:
Copied!
geemap.system_fonts()
geemap.system_fonts()
In [ ]:
Copied!
geemap.add_text_to_gif(
in_gif,
out_gif,
xy=('5%', '5%'),
text_sequence=1984,
font_size=30,
font_color='#0000ff',
duration=100,
)
geemap.add_text_to_gif(
out_gif,
out_gif,
xy=('30%', '85%'),
text_sequence="Las Vegas",
font_type="timesbd.ttf",
font_size=30,
font_color='black',
)
geemap.show_image(out_gif)
geemap.add_text_to_gif(
in_gif,
out_gif,
xy=('5%', '5%'),
text_sequence=1984,
font_size=30,
font_color='#0000ff',
duration=100,
)
geemap.add_text_to_gif(
out_gif,
out_gif,
xy=('30%', '85%'),
text_sequence="Las Vegas",
font_type="timesbd.ttf",
font_size=30,
font_color='black',
)
geemap.show_image(out_gif)
Prepare for an ImageCollection¶
In [ ]:
Copied!
import ee
import geemap
ee.Initialize()
# Define an area of interest geometry with a global non-polar extent.
aoi = ee.Geometry.Polygon(
[[[-179.0, 78.0], [-179.0, -58.0], [179.0, -58.0], [179.0, 78.0]]], None, False
)
# Import hourly predicted temperature image collection for northern winter
# solstice. Note that predictions extend for 384 hours; limit the collection
# to the first 24 hours.
tempCol = (
ee.ImageCollection('NOAA/GFS0P25')
.filterDate('2018-12-22', '2018-12-23')
.limit(24)
.select('temperature_2m_above_ground')
)
# Define arguments for animation function parameters.
videoArgs = {
'dimensions': 768,
'region': aoi,
'framesPerSecond': 10,
'crs': 'EPSG:3857',
'min': -40.0,
'max': 35.0,
'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'],
}
import ee
import geemap
ee.Initialize()
# Define an area of interest geometry with a global non-polar extent.
aoi = ee.Geometry.Polygon(
[[[-179.0, 78.0], [-179.0, -58.0], [179.0, -58.0], [179.0, 78.0]]], None, False
)
# Import hourly predicted temperature image collection for northern winter
# solstice. Note that predictions extend for 384 hours; limit the collection
# to the first 24 hours.
tempCol = (
ee.ImageCollection('NOAA/GFS0P25')
.filterDate('2018-12-22', '2018-12-23')
.limit(24)
.select('temperature_2m_above_ground')
)
# Define arguments for animation function parameters.
videoArgs = {
'dimensions': 768,
'region': aoi,
'framesPerSecond': 10,
'crs': 'EPSG:3857',
'min': -40.0,
'max': 35.0,
'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'],
}
Save the GIF to local drive¶
In [ ]:
Copied!
saved_gif = os.path.join(os.path.expanduser('~'), 'Downloads/temperature.gif')
geemap.download_ee_video(tempCol, videoArgs, saved_gif)
saved_gif = os.path.join(os.path.expanduser('~'), 'Downloads/temperature.gif')
geemap.download_ee_video(tempCol, videoArgs, saved_gif)
In [ ]:
Copied!
geemap.show_image(saved_gif)
geemap.show_image(saved_gif)
Generate an hourly text sequence¶
In [ ]:
Copied!
text = [str(n).zfill(2) + ":00" for n in range(0, 24)]
print(text)
text = [str(n).zfill(2) + ":00" for n in range(0, 24)]
print(text)
Add text to GIF¶
In [ ]:
Copied!
out_gif = os.path.join(os.path.expanduser('~'), 'Downloads/output2.gif')
out_gif = os.path.join(os.path.expanduser('~'), 'Downloads/output2.gif')
In [ ]:
Copied!
geemap.add_text_to_gif(
saved_gif,
out_gif,
xy=('3%', '5%'),
text_sequence=text,
font_size=30,
font_color='#ffffff',
)
geemap.add_text_to_gif(
saved_gif,
out_gif,
xy=('3%', '5%'),
text_sequence=text,
font_size=30,
font_color='#ffffff',
)
In [ ]:
Copied!
geemap.add_text_to_gif(
out_gif,
out_gif,
xy=('32%', '92%'),
text_sequence='NOAA GFS Hourly Temperature',
font_color='white',
)
geemap.add_text_to_gif(
out_gif,
out_gif,
xy=('32%', '92%'),
text_sequence='NOAA GFS Hourly Temperature',
font_color='white',
)
In [ ]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
Last update:
2023-04-06
Created: 2020-03-31
Created: 2020-03-31