Average soil moisture 2001-2016, Okavango, Botswana

Map: Average soil moisture 2001-2016, Okavango, Botswana

Animation with inset map

Thomas Gumbricht bio photo By Thomas Gumbricht

Contents - introduction - Prerequisites - Image organization - Animation frames - Movie - Resources

introduction

The previous post introduced FFmpeg for creating an animation from satellite time series images. In this post I will show how to use ImageMagick, introduced in an earlier post and FFmpeg for creating an animation combining two time series and an image clock.

Prerequisites

To create an animation with a large map at the bottom and overlaid by a smaller inset map, you need the command line apps ImageMagick and FFmpeg. You also need at least two time series of images. The main image time series will decide the time span and the time resolution of the animation. The second (slave) time series must have images covering the same time span and temporal resolution. If the slave time series contain additional data they will be ignored.

Image organization

The time series data to use for creating the animation shown below must be organized in a way that allows the time corresponding master and slave(s) images to be recognized. This can, for instance be done using a programming language, or by a very strict naming of all images.

All the images used in this post are produced from Karttur’s Geo Imagine Framework. At the time of writing I have not made the parts of Framework needed publicly available. But the essence is that the Framework produces all the time series images and saves them in separate folders, with identical file names. With both the master image time series and all slave time series having exactly the same file name for each time stamp, the animation can be created using only command-line calls to ImageMagick and FFmpeg.

Animation frames

The animation created in this post is a composition of the following elements:

  • Time series of soil moisture images
  • Time series of rainfall images
  • A time line and clock time series of images
  • A vector map of the river basin
image image image image
Images used for composing animation frames, the upper row shows soil moisture and rainfall, the lower row the timeline/clock and the river Basin. The geographical region is the Okavango River basin in southern Africa. If you click on the images you will see them with the input dimensions used for creating the animation.

I want the elements to be layered with:

  • soil moisture as the main image,
  • rainfall as an inset in the upper right corner,
  • time line and clock at the lower edge,
  • both soil moisture and rainfall overlaid with the river basin vector, and
  • embossed watermark for the final frame.
Movie frame combining soil moisture, rainfall, timeline/clock and river basin, and with embossed watermark.

With the soil moisture (master) images and the slave images (rainfall and timeline/clock) having identical file names, the ImageMagick command for creating the frames for the animation becomes:

mkdir frames
for i in *.tif; do convert \( -resize 992x1080! "$i" \) \
\( -resize 992x1080! -background none /path/to/riverbasinvector/river-basin-vector.svg \) -composite \
\( \( -resize 380x -border 1x1 -bordercolor black /path/to/rainfallimages/"$i" \) \
\( -resize 380x -background none /path/to/riverbasinvector/river-basin-vector.svg \) -gravity center -composite \) \
-gravity northeast -composite \
/path/to/timelineclockimages/${i%.*}.png -gravity southwest -composite \
\( -size 992x300 xc:none -font Trebuchet -pointsize 200 -gravity center -draw "fill silver text 1,1 'KARTTUR'  fill whitesmoke text -1,-1 'KARTTUR' fill grey text 0,0 'KARTTUR' " -transparent grey -fuzz 90% \) -composite   "frames/${i%.*}.png"; done

For the mp4 -vcodec libx264 to work with the pixel formatter -pix_fmt yuv420p, both the width and height of the input must be an even number. In the ImageMagick command above I thus forced the dimensions of the master image to even numbers (-resize 992x1080!).

Movie

With the frames ready, the movie is created using FFmpeg as suggested in the previous post. But as the example movie in this post has larger dimensions, I increased the bitrate to 2M.

ffmpeg -r 3 -f image2 -pattern_type glob -i '*.png' -vcodec libx264 -b:v 2M -pix_fmt yuv420p -crf 35 DstMovie.mp4

The movie has a dimension of 992x1080 (approximately 1 km spatial resolution on the ground for the soil moisture). The dimensions when shown below is reduced to 716x780 to fit neatly to the layout in this blog. If you download the movie, and view it on your local machine it will have the original dimensions of 992x1080. (The original data is at approximately 500 m spatial resolution, and a movie at full resolution would thus be 1986×2164).

Soil moisture and rainfall 2001-2016, Okavango River basin

Resources

ImageMagick

FFmpeg

Create FFmpeg movie my previous post.