16 add animated text
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import geemap
import os
import geemap
import os
In [3]:
Copied!
geemap.show_youtube('fDnDVuM_Ke4')
geemap.show_youtube('fDnDVuM_Ke4')
In [4]:
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 [5]:
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 [6]:
Copied!
geemap.show_image(in_gif)
geemap.show_image(in_gif)
Add animated text to GIF¶
In [7]:
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,
)
The input gif file does not exist.
In [8]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
Add place name¶
In [9]:
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'
)
The input gif file does not exist.
In [10]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
Change font type¶
In [11]:
Copied!
geemap.system_fonts()
geemap.system_fonts()
Out[11]:
['DejaVuMathTeXGyre.ttf', 'DejaVuSans-Bold.ttf', 'DejaVuSans-BoldOblique.ttf', 'DejaVuSans-ExtraLight.ttf', 'DejaVuSans-Oblique.ttf', 'DejaVuSans.ttf', 'DejaVuSansCondensed-Bold.ttf', 'DejaVuSansCondensed-BoldOblique.ttf', 'DejaVuSansCondensed-Oblique.ttf', 'DejaVuSansCondensed.ttf', 'DejaVuSansMono-Bold.ttf', 'DejaVuSansMono-BoldOblique.ttf', 'DejaVuSansMono-Oblique.ttf', 'DejaVuSansMono.ttf', 'DejaVuSerif-Bold.ttf', 'DejaVuSerif-BoldItalic.ttf', 'DejaVuSerif-Italic.ttf', 'DejaVuSerif.ttf', 'DejaVuSerifCondensed-Bold.ttf', 'DejaVuSerifCondensed-BoldItalic.ttf', 'DejaVuSerifCondensed-Italic.ttf', 'DejaVuSerifCondensed.ttf', 'Lato-Black.ttf', 'Lato-BlackItalic.ttf', 'Lato-Bold.ttf', 'Lato-BoldItalic.ttf', 'Lato-Hairline.ttf', 'Lato-HairlineItalic.ttf', 'Lato-Heavy.ttf', 'Lato-HeavyItalic.ttf', 'Lato-Italic.ttf', 'Lato-Light.ttf', 'Lato-LightItalic.ttf', 'Lato-Medium.ttf', 'Lato-MediumItalic.ttf', 'Lato-Regular.ttf', 'Lato-Semibold.ttf', 'Lato-SemiboldItalic.ttf', 'Lato-Thin.ttf', 'Lato-ThinItalic.ttf', 'LiberationMono-Bold.ttf', 'LiberationMono-BoldItalic.ttf', 'LiberationMono-Italic.ttf', 'LiberationMono-Regular.ttf', 'LiberationSans-Bold.ttf', 'LiberationSans-BoldItalic.ttf', 'LiberationSans-Italic.ttf', 'LiberationSans-Regular.ttf', 'LiberationSansNarrow-Bold.ttf', 'LiberationSansNarrow-BoldItalic.ttf', 'LiberationSansNarrow-Italic.ttf', 'LiberationSansNarrow-Regular.ttf', 'LiberationSerif-Bold.ttf', 'LiberationSerif-BoldItalic.ttf', 'LiberationSerif-Italic.ttf', 'LiberationSerif-Regular.ttf', 'NotoColorEmoji.ttf']
In [12]:
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)
The input gif file does not exist. The input gif file does not exist.
Prepare for an ImageCollection¶
In [13]:
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 [14]:
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)
Generating URL... Downloading GIF image from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/videoThumbnails/af4c277fc1c3ccfdd895de617899e84e-feb0e16697a9e08f1d4442592ef0bb9c:getPixels Please wait ... The GIF image has been saved to: /home/runner/Downloads/temperature.gif
In [15]:
Copied!
geemap.show_image(saved_gif)
geemap.show_image(saved_gif)
Generate an hourly text sequence¶
In [16]:
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)
['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00']
Add text to GIF¶
In [17]:
Copied!
out_gif = os.path.join(os.path.expanduser('~'), 'Downloads/output2.gif')
out_gif = os.path.join(os.path.expanduser('~'), 'Downloads/output2.gif')
In [18]:
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 [19]:
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 [20]:
Copied!
geemap.show_image(out_gif)
geemap.show_image(out_gif)
Last update:
2022-03-14