Tutorial 6 - Animations with GMT 🎦 (extended)#

Content

  • Extension of β€œTutorial 6 - Animations with GMT”

Note

This tutorial is part of the AGU24 annual meeting GMT/PyGMT pre-conference workshop (PREWS9) Mastering Geospatial Visualizations with GMT/PyGMT

History

History

Fee free to play around with these code examples πŸš€. In case you found any kind of error, just report it by opening an issue or provide a fix via a pull request. Please use the GMT forum to ask questions.

3️. Tutorial 2. Earthquakes#

Here I explain how to make an animation with appearing objects. This is more complex and requires the use events and movie modules. In this example, I create an animation showing the occurrences of earthquakes during the year 2018 (with one frame per day). Note that the earthquakes are drawn as they occur and remain visible until the end of the animation.

For this tutorial I follow these steps:

  1. Make image

  2. Make master frame

  3. Make draft animation

  4. Make animation without enhancement

  5. Make animation with enhancement

3.1. Goals of the Tutorial#

  • What is gmt events.

  • How to use a background script for a movie.

  • How to enhance symbols with events.

3.2 Make image#

In this step I plot a map of the earth with all the quakes from 2018.

gmt begin Earth png
    # Set parameters and position
    gmt basemap -Rg -JN14c -B+n
    # Plot relief grid
    gmt grdimage @earth_relief_06m -I
    # Create cpt for the earthquakes
    gmt makecpt -Cred,green,blue -T0,70,300,10000
    # Plot quakes
    gmt plot @quakes_2018.txt -SE- -C
gmt end
_images/ac1f4bddcb2d1e7c7e8c61b7461f3ddb.png

Technical Information

  • I use makecpt to create a CPT to color the earthquakes.

  • I used the earthquakes from the file quakes_2018.txt which has 5 columns.

    Longitude

    Latitude

    Depth

    Magnitude (x50)

    Date

    46.4223

    -38.9126

    10

    260

    2018-01-02T02:16:18.11

    169.3488

    -18.8355

    242.77

    260

    2018-01-02T08:10:00.06

    …

  • Note that the input file has the columns sorted as will be required by the plot and events modules. It was also used for animation 08. Check it to see how it was downloaded and processed.

3.3. Make master frame#

In this step I create the master frame of the animation similar to the previous image.

3.3.1. First attempt (first frame)#

In this first attempt I create the first frame (-Mf,png) of the animation.

cat << 'EOF' > main.sh
gmt begin
  # Set parameters and position
  gmt basemap -Rg -JN${MOVIE_WIDTH} -B+n -X0 -Y0
  # Create background map
  gmt grdimage @earth_relief_06m -I
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000
  gmt plot @quakes_2018.txt -SE- -C
gmt end
EOF

gmt movie main.sh -NQuakes -Mf,png -Zs -V -C24cx12cx80 -T2018-01-01T/2018-12-31T/1d -Gblack \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=-
_images/4efd84b8bb06debc91d27f36c38f433f.png

Technical Information

  • I use -T2018-01-01T/2018-12-31T/1d to create a one-column data set with all days in 2018.

  • I use -Lc0 to add a label with the first column (i.e. the dates).

  • –FONT_TAG=18p,Helvetica,white: This sets the font for the label.

  • –FORMAT_CLOCK_MAP=-: to NOT include the hours in the date and only plot year, month and day in the label.

  • I use a custom canvas of 24 x 12 cm with a resolution of 80 DPC (-C24cx12cx80).

Error

  • The first frame contains all the quakes when none of them should be plotted. I must use events instead.

3.3.2. The events module#

In the previous figure, I use the plot module to draw the symbols. This results that the symbols appear on all frames. However if I want to plot quakes as they unfold, I have to use the events instead.

Important

  • events requires a time column in the input data and will use it and the animation time to determine when symbols should be plotted.

  • The -T is a required argument and is used to set the current plot time.

3.3.3. Second attempt (first frame with events)#

Now, in this attempt I use events with -T${MOVIE_COL0} to plot the quakes as dates progresses

cat << 'EOF' > main.sh
gmt begin
  # Set parameters and position
  gmt basemap -Rg -JN${MOVIE_WIDTH} -B+n -X0 -Y0
  # Create background map
  gmt grdimage @earth_relief_06m -I
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000
  gmt events @quakes_2018.txt -SE- -C -T${MOVIE_COL0}
gmt end
EOF

gmt movie main.sh -NQuakes -Mf,png -Zs -V -C24cx12cx80 -T2018-01-01T/2018-12-31T/1d -Gblack \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=-
_images/766009993fb8ac5fe771d2e99174efa0.png

Warning

The map shows NO earthquakes. This is expected because there are no quakes (in the data file) before January first. However, this could also be due to an error in the command. I must plot the frame from another date to see if the quakes appear.

3.3.4. Third attempt (last frame with events)#

Now, I also plot the last frame (-Ml).

cat << 'EOF' > main.sh
gmt begin
  # Set parameters and position
  gmt basemap -Rg -JN${MOVIE_WIDTH} -B+n -X0 -Y0
  # Create background map
  gmt grdimage @earth_relief_06m -I
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000
  gmt events @quakes_2018.txt -SE- -C -T${MOVIE_COL0}
gmt end
EOF

gmt movie main.sh -NQuakes -Ml,png -Zs -V -C24cx12cx80 -T2018-01-01T/2018-12-31T/1d -Gblack \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=-
_images/98e45dd03e4db1e5750a500ea0a81455.png

3.4. Make draft animation#

In this step, we can make a draft animation. For this example, I recommend making a low quality (with 30 DPC) video to see if the quakes appear correctly.

3.4.1. First attempt#

cat << 'EOF' > main.sh
gmt begin
  # Set parameters and position
  gmt basemap -Rg -JN${MOVIE_WIDTH} -B+n -X0 -Y0
  # Create background map
  gmt grdimage @earth_relief_06m -I
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000
  gmt events @quakes_2018.txt -SE- -C -T${MOVIE_COL0}
gmt end
EOF

gmt movie main.sh -NQuakes -Ml,png -Zs -V -C24cx12cx30 -T2018-01-01T/2018-12-31T/1d -Gblack \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=- -Fmp4

Warning

  • The above script works well but it can be more efficient if a background script is used as well.

3.4.2. The background script#

Within movie module, there is an optional background (-Sb) script that it is used for two purposes:

  1. Create files that will be needed by the main script to make the movie.

  2. Make a static background plot that should form the background for all frames.

Technical Information

The background script is run only once.

3.4.3. Second attempt (with background script)#

In this step, instead of creating just the main script as before, I now create both a background script and a main script. The background script (pre.sh) is used to:

  1. create a CPT file that will be used to color the quakes.

  2. make a static worldwide background map.

Important

  • The animation created is identical to the previous one.

  • The use of a background script allows the creation of the animation much faster because the CPT and the static background map will be created only once (instead of 365 times).

cat << 'EOF' > pre.sh
gmt begin
  # Set parameters and position
  gmt basemap -Rg -JN${MOVIE_WIDTH} -X0 -Y0 -B+n
  # Create background map
  gmt grdimage @earth_relief_06m -I
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000 -H > quakes.cpt
gmt end
EOF

cat << 'EOF' > main.sh
gmt begin
  gmt basemap -Rg -JN${MOVIE_WIDTH} -X0 -Y0 -B+n
  gmt events @quakes_2018.txt -SE- -Cquakes.cpt -T${MOVIE_COL0}
gmt end
EOF

gmt movie main.sh -Sbpre.sh -NQuakes -Ml,png -Zs -V -C24cx12x80 -T2018-01-01T/2018-12-31T/1d -Gblack \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=-

Technical Information

  • For the CPT, I must use -H and give it a name, and then use that name in main.sh.

  • I add -Sbpre.sh within the movie module to use the background script.

  • I repeat the basemap command in the main and background scripts so both have the same positioning (i.e., -X and -Y) and parameters (i.e. -R and -J).

3.5. Make full animation#

Now I make the final high-quality animation (i.e. 80 DPC).

cat << 'EOF' > pre.sh
gmt begin
  # Create background map
  gmt grdimage @earth_relief_06m -I -JN${MOVIE_WIDTH} -Rg -X0 -Y0
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000 -H > quakes.cpt
gmt end
EOF

cat << 'EOF' > main.sh
gmt begin
  gmt basemap -Rg -JN${MOVIE_WIDTH} -X0 -Y0 -B+n
  gmt events @quakes_2018.txt -SE- -Cquakes.cpt -T${MOVIE_COL0}
gmt end
EOF

gmt movie main.sh -Sbpre.sh -NQuakes -Ml,png -Zs -V -C24cx12cx80 -T2018-01-01T/2018-12-31T/1d -Gblack -Fmp4 \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=-

3.6. Make full animation with enhancement#

In the previous animation, the earthquakes appear but it is hard to see when they do it. With events it is possible to draw attention to the arrival of a new event.

3.6.1. How to enhance symbols with events#

The idea is to change the default behavior of the symbols to enhance their appearance as shown in the following video:


This can be done by using -M and -E arguments. The -M arguments allows to temporarily change attributes of the symbol like:

  • -Ms: Provide a factor to modify the size.

  • -Mc: Provide a value to brighten (up to 1) or darken (up to -1) the color intensity.

  • -Mt: Transparency. Set a value between 100 (invisible) to 0 (opaque).

The duration of the temporary changes is controlled via the -E argument.

  • -Er: rise phase. It takes place before the start of the event.

  • -Ep: plateau phase. It takes place after the start of the event.

  • -Ed: decay phase. It develops after the plateau phase. If the plateau phase does not occur, then it takes place after the start of the event.

Note

  • For finite symbols there are also normal and fade phases.

  • It is also possible to change the data value with -Mv.

3.6.2. Make full animation#

In this step I announce each quake by magnifying size and whitening the color for a little bit (during the rise phase). Later the symbols return to their original properties during the decay phase. The plateau phase is not used.

cat << 'EOF' > pre.sh
gmt begin
  # Create background map
  gmt grdimage @earth_relief_06m -I -JN${MOVIE_WIDTH} -Rg -X0 -Y0
  # Create cpt for the earthquakes
  gmt makecpt -Cred,green,blue -T0,70,300,10000 -H > quakes.cpt
gmt end
EOF

cat << 'EOF' > main.sh
gmt begin
  gmt basemap -Rg -JN${MOVIE_WIDTH} -X0 -Y0 -B+n
  gmt events @quakes_2018.txt -SE- -Cquakes.cpt -T${MOVIE_COL0} -Es+r2+d6 -Ms5+c1 -Mi1+c0 -Mt+c0 --TIME_UNIT=d
gmt end
EOF

gmt movie main.sh -Sbpre.sh -NQuakes -Ml,png -Zs -V -C24cx12cx80 -T2018-01-01T/2018-12-31T/1d -Gblack -Fmp4 \
-Lc0 --FONT_TAG=18p,Helvetica,white --FORMAT_CLOCK_MAP=-

Technical Information

  • --TIME_UNIT=d: This sets that the values of -E are in days (d).

  • -Es+r2+d6: This sets the duration of the rise phase and the decay phase.

  • -Ms5+c1: modify the size. The size will increase 5 times during the rise phase and then reduce to the original size in the coda phase.

  • -Mt+c0: modify the transparency. The transparency will remain to 0 at the coda phase. This allows it to be seen after its occurrence.

  • -Mi1+c0: modify the intensity of the color. It gets lighter during the rise phase and then returns to its original color in the coda phase.

4️⃣. See also#

5️⃣. References#

  • Wessel, P., Luis, J. F., Uieda, L., Scharroo, R., Wobbe, F., Smith, W. H. F., & Tian, D. (2019). The Generic Mapping Tools Version 6. Geochemistry, Geophysics, Geosystems, 20(11), 5556–5564. https://doi.org/10.1029/2019GC008515

  • Wessel, P., Esteban, F., & Delaviel-Anger, G. (2024). The Generic Mapping Tools and animations for the masses. Geochemistry, Geophysics, Geosystems, 25, e2024GC011545. https://doi.org/10.1029/2024GC011545.