Problem creating a movie: only the first frame is plotted

Dear GMT community,

I am trying to make an animation using GMT6, following the examples of the historical collection but I was not able to make a GIF using the following script. I only get the grdimage for the first frame.

#!/bin/bash
#
# /-------------------------------------------------------------------------------/
# 
#                     =================================
#                       ** ANIMATION OF HYCOM DATA **
#                     =================================
#
# /-------------------------------------------------------------------------------/
#
# ==> PATHS AND FILENAMES
root_dir='/home/usuario/Documents/'
data_dir=$root_dir'DATA/e-DATA/HYCOM/'
base_file=$data_dir'HYCOM_GLBv0.08_FORECAST_TPCM.nc'
time_file=$data_dir'HYCOM_FORECAST_TIME.txt'


if [ $# -eq 0 ]; then
	opt="-M0,ps -Fnone"
	ps=anim_08.ps
else
	opt="-A+l"
fi

# Base on the historical collection examples
# 1. Create files needed in the loop
cat << EOF > pre.sh
gmt begin	
	gmt makecpt -Cjet -T34/35.2 -Do -Z -H > tpcm_psal.cpt	
gmt end
EOF

# 2. Set up the main frame script
cat << EOF > main.sh
gmt begin 
	gmt coast -R-112/-105/20/27 -JQ4i -Df -Sblack \
               -A100 -Gblack -W0.8p,white
	gmt grdimage -R-112/-105/20/27 -JQ4i -E50 \
		$base_file?salinity[\${MOVIE_FRAME}] -Ctpcm_psal.cpt -Q
	gmt psbasemap -Bxa2f1 -Bya2f1 -BWSEN+t'HYCOM_FORECAST' \
              --FORMAT_GEO_MAP=dddF
gmt end
EOF

# 3. Run the movie
gmt movie main.sh -C6ix6ix72 -Nhycom_test -T96 -Sbpre.sh -D6 -Q $opt

My aim is to make an animation with the output of an ocean model that reproduces the salinity field every three hours. So, I woul like to iterate over each time step in the netcdfile. In my case the utput of ncdump -h of the file looks like this:

netcdf HYCOM_GLBv0.08_FORECAST_TPCM {
dimensions:
	time = UNLIMITED ; // (96 currently)
	lon = 119 ;
	lat = 163 ;
variables:
	double time(time) ;
		time:standard_name = "time" ;
		time:long_name = "Forecast time for ForecastModelRunCollection" ;
		time:units = "hours since 2020-04-03 12:00:00.000 UTC" ;
		time:calendar = "proleptic_gregorian" ;
		time:axis = "T" ;
	double lon(lon) ;
		lon:standard_name = "longitude" ;
		lon:long_name = "Longitude" ;
		lon:units = "degrees_east" ;
		lon:axis = "X" ;
	double lat(lat) ;
		lat:standard_name = "latitude" ;
		lat:long_name = "Latitude" ;
		lat:units = "degrees_north" ;
		lat:axis = "Y" ;
	float surf_el(time, lat, lon) ;
		surf_el:_FillValue = NaNf ;
		surf_el:missing_value = NaNf ;
	float water_temp(time, lat, lon) ;
		water_temp:_FillValue = NaNf ;
		water_temp:missing_value = NaNf ;
	float salinity(time, lat, lon) ;
		salinity:_FillValue = NaNf ;
		salinity:missing_value = NaNf ;

// global attributes:
		:CDI = "Climate Data Interface version ?? (http://mpimet.mpg.de/cdi)" ;
		:Conventions = "CF-1.6" ;
		:history = "Thu Apr 09 17:52:04 2020: cdo mergetime 00_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 01_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 02_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 03_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 04_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 05_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 06_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 07_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 08_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 09_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 10_HYCOM_GLBy0.08_FORECAST_TPCM_.nc 11_HYCOM_GLBy0.08_FORECAST_TPCM_.nc HYCOM_GLBv0.08_FORECAST_TPCM.nc" ;
		:CDO = "Climate Data Operators version 1.9.3 (http://mpimet.mpg.de/cdo)" ;

I will be really grateful if you could help me to run this animation.

Kind regards,

Amaru

Please use -Q and examine the individual png frames. Are they all identical? If so, try -Qs and examine the scripts to see why, say, the 10th frame script is not giving you the right nc layer. Try run one of the scripts manually. Or try without $opt and add -M10 to see if you get the 10th layer.

Dear Paul,

Thank you for your answer to my question.

I tried the options that you indicated but, actually the folder “master” is empty and not png is created.

I also copied the code of the example “One year (2018) of Pacific seismicity events”. After running it, the behaviour is the same. The master folder is empty and only a static .ps figure is created in the parent directory.

Regards,

Amaru

Dear Paul and GMT community,

I was playing with my code to produce an animation of the salinity output of an ocean model.
In my case the animation works if the if statement is removed and using the option -A+l without the $opt (as Paul suggested me). If it can help someone, the code I used was:

#!/bin/bash
#
# /-------------------------------------------------------------------------------/
# 
#                     =================================
#                       ** ANIMATION OF HYCOM DATA **
#                     =================================
#
#
# /-------------------------------------------------------------------------------/
#
# ==> PATHS AND FILENAMES
root_dir='/home/usuario/Documents/'
data_dir=$root_dir'DATA/e-DATA/HYCOM/'
base_file=$data_dir'HYCOM_GLBv0.08_FORECAST_TPCM.nc'
time_file=$data_dir'HYCOM_FORECAST_TIME.txt'


# Base on the histrical collection examples
# 1. Create files needed in the loop
cat << EOF > pre.sh
gmt begin	
	gmt makecpt -Cjet -T34/35.2 -Do -Z -H > tpcm_psal.cpt	
gmt end
EOF

# 2. Set up the main frame script
cat << EOF > main.sh
gmt begin 
	gmt coast -R-112/-105/20/27 -JQ4i -Df -Sblack \
               -A100 -Gblack -W0.8p,white -X2 -Y2
	gmt grdimage -R-112/-105/20/27 -JQ4i -E50 \
		$base_file?salinity[\${MOVIE_FRAME}] -Ctpcm_psal.cpt -Q
	gmt psbasemap -Bxa2f1 -Bya2f1 -BWSEN+t'HYCOM_FORECAST' \
              --FORMAT_GEO_MAP=dddF
gmt end
EOF

# 3. Run the movie
gmt movie main.sh -C6ix6ix72 -Nhycom_test -T96 \
	-Sbpre.sh -D48 -Z -A+l

Thank you all!!

Regards,

Am.-

What OS and GMT version? So none of the animation examples run for you?

Dear Paul,

My OS is Linux Mint 19 (tara) with kernel 4.15.0-76-generic.
The GMT that I am using is 6.0.0rc3.

I tried the example Animation of the sine function but it does not work. Just as in the other cases, only the first frame is plotted as .ps file in the directory where I put the script.

This is that I got after the execution of the script:

anim01

So I assume ffmpeg and gm are installed and working? Maybe you can post as a text file the complete output when you run your gmt movie command with -Vd.

Dear @pwessel ,

Thank you so much for the message.

Yes, I have ffmpeg and gm working on my system.

I run again the same example of the sine function using the -Vd.
This resulted after the execution of the script:

gmt [DEBUG]: Obtained the ppid from parent: 6893
gmt [DEBUG]: Enter: gmtinit_new_GMT_ctrl
gmt [DEBUG]: GMT->session.SHAREDIR = /opt/gmt/share
gmt [DEBUG]: GMT->session.HOMEDIR = /home/usuario
gmt [DEBUG]: GMT->session.USERDIR = /home/usuario/.gmt [created]
gmt [DEBUG]: GMT->session.CACHEDIR = /home/usuario/.gmt/cache [created]
gmt [DEBUG]: GMT: 0. Will try to find subdir=postscriptlight stem = PSL_custom_fonts suffix=.txt
gmt [DEBUG]: GMT: 1. gmt_getsharepath trying current dir
gmt [DEBUG]: GMT: 2. gmt_getsharepath trying USERDIR /home/usuario/.gmt
gmt [DEBUG]: GMT: 3. gmt_getsharepath trying USERDIR subdir /home/usuario/.gmt/postscriptlight
gmt [DEBUG]: GMT: 4. gmt_getsharepath trying SHAREDIR subdir /opt/gmt/share/postscriptlight
gmt [DEBUG]: GMT: 5. gmt_getsharepath failed
gmt [DEBUG]: Map distance calculation will be Cartesian
gmt [DEBUG]: Exit:  gmtinit_new_GMT_ctrl
gmt [DEBUG]: Enter: New_PSL_Ctrl
gmt [DEBUG]: Exit:  New_PSL_Ctrl
gmt [DEBUG]: Enter: gmt_manage_workflow
gmt [DEBUG]: Exit : gmt_manage_workflow
gmt [DEBUG]: Enter: PSL_beginsession
gmt [DEBUG]: Exit : PSL_beginsession
gmt [DEBUG]: Enter: PSL_setdefaults
gmt [DEBUG]: Exit : PSL_setdefaults
gmt [DEBUG]: Enter: gmtlib_io_init
gmt [DEBUG]: Exit : gmtlib_io_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit:  gmt_hash_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit:  gmt_hash_init
gmt [DEBUG]: The PROJ_GEODESIC set to Vincenty
gmt [DEBUG]: Enter: gmt_getdefaults
gmt [DEBUG]: Look for file /home/usuario/gmt.conf
gmt [DEBUG]: Look for file /home/usuario/.gmt/gmt.conf
gmt [DEBUG]: Look for file /home/usuario/.gmt/server/gmt.conf
gmt [DEBUG]: Look for file /home/usuario/.gmt/cache/gmt.conf
gmt [DEBUG]: Could not find file gmt.conf
gmt [DEBUG]: Exit:  gmt_getdefaults
gmt [DEBUG]: Enter: gmtlib_plot_C_format
gmt [DEBUG]: Exit:  gmtlib_plot_C_format
gmt [DEBUG]: Enter: gmtinit_get_history
gmt [DEBUG]: Initialize FFTW with 4 threads.
gmt [DEBUG]: GMT_Create_Session initialized GMT structure
gmt [DEBUG]: Shared Library # 0 (core). Path = libgmt.so
gmt [DEBUG]: Loading core GMT shared library: libgmt.so
gmt [DEBUG]: Loading GMT plugins from: /opt/gmt/lib/gmt/plugins
gmt [DEBUG]: Shared Library # 1 (supplements). Path = /opt/gmt/lib/gmt/plugins/supplements.so
movie [DEBUG]: Found file main.sh
movie [DEBUG]: Found file main.sh
movie [INFORMATION]: Paper dimensions: Width = 4i Height = 2i
movie [INFORMATION]: Pixel dimensions: 500 x 250
movie [DEBUG]: Look for file sin_point.txt in /home/usuario/.gmt
movie [DEBUG]: Look for file sin_point.txt in /home/usuario/.gmt/cache
movie [DEBUG]: Look for file sin_point.txt in /home/usuario/.gmt/server
movie [DEBUG]: Look for file sin_point.txt in /home/usuario/.gmt/server/srtm1
movie [DEBUG]: Look for file sin_point.txt in /home/usuario/.gmt/server/srtm3
movie [INFORMATION]: Create parameter initiation script movie_init.sh
movie [INFORMATION]: Create preflight script movie_preflight.sh and execute it
movie [DEBUG]: Found file sin_point.txt
movie [DEBUG]: Found file sin_point.txt
movie [DEBUG]: Found file sin_point.txt
movie [DEBUG]: Object ID 0 : Registered Data Table File sin_point.txt as an Input resource with geometry Non-Geographical [n_objects = 1]
movie [DEBUG]: api_begin_io: Input resource access is now enabled [container]
movie [DEBUG]: api_import_dataset: Passed ID = 0 and mode = 0
movie [INFORMATION]: Reading Data Table from File sin_point.txt
movie [DEBUG]: Found file sin_point.txt
movie [DEBUG]: Found file sin_point.txt
movie [DEBUG]: Source col types: (Number,Number)
movie [DEBUG]: ASCII source scanned: Numerical columns: 2, Trailing text: N, Record type: Numerical only
movie [DEBUG]: GMT memory: Initialize 2 temporary column double arrays, each of length : 0
movie [DEBUG]: GMT_End_IO: Input resource access is now disabled
movie [INFORMATION]: Number of animation frames: 19
movie [INFORMATION]: Create individual parameter include files per frame for 19 frames
movie [INFORMATION]: Create master frame script movie_master.sh
movie [INFORMATION]: Single master plot (frame 0) built: anim01.ps
movie [DEBUG]: Delete movie_master.sh
movie [DEBUG]: gmtapi_garbage_collection: Destroying object: C=0 A=1 ID=0 W=Input F=Data Table M=File S=Used P=556da10a4e80 N=sin_point.txt
movie (gmt_free_table): tried to free unallocated memory
movie [DEBUG]: GMTAPI_Garbage_Collection freed 1 memory objects
movie [DEBUG]: gmtapi_unregister_io: Unregistering object no 0 [n_objects = 0]
movie [DEBUG]: GMT memory: Free 2 temporary column arrays, each of length : 2097152
gmt [DEBUG]: Entering GMT_Destroy_Session

It only works if I remove the if statement between lines 9-14 from the example script, and also if I use directly the -A+l option instead of $opt. In my case, it produces the .gif file. So, I think it is the solution to the problem I had

Thank you again.

Sure, the if test was for us to run the script with an arbitrary argument to produce a single frame PS file or without argument to make the animated fig. Why it does not run as is for you is a mystery, but I am glad it works now.