Chapter 5: ANIMATIONS AND GIF IMAGES

Ch5 Sec1. OVERVIEW

A sequence of Ferret plots can be stored and then animated. Each plot is stored as one frame in a movie file. Ferret stores movie frames in Hierarchical Data Format (HDF), a format designed by the National Center for Supercomputing Applications (NCSA). A movie file can then be displayed as an animated sequence of frames with NCSA's xds—X Data Slice (not distributed with Ferret; see the section in this chapter "Displaying an HDF movie" (p. 126), for details).


Ch5 Sec2. CREATING AN HDF MOVIE

Creating a movie requires two steps:

1) designate an output file with SET MOVIE

2) generate a sequence of frames with REPEAT and FRAME

See commands SET MOVIE (p. 310), CANCEL MOVIE (p. 247), SHOW MOVIE (p. 326), FRAME (p. 267), and REPEAT (p. 288) in the Commands Reference section of this manual.

Example: basic movie

yes? SET DATA coads_climatology       !specify data set
yes? SET REGION/@W                    !specify Pacific Ocean
yes? LET/TITLE="SST Anomaly" SST_ANOM = SST - SST[L=1:12@AVE]
yes? REPEAT/L=1:12 (FILL sst_anom; FRAME/FILE=my_movie.mgm)
                                     !filled contour of sea surface\
                                     temp anomaly captured and\
                                     written to HDF file

Optionally, ".mgm" will be assigned to the movie file.

REPEAT executes its argument (in the above example, FILL) successively for each timestep specified. REPEAT can have multiple arguments separated by semi-colons and enclosed in parentheses.

FRAME is a stand-alone command, but also a qualifier for the graphical output commands PLOT, CONTOUR, FILL (alias for CONTOUR/FILL), SHADE, VECTOR and WIRE.

The saved animation frames are exactly the size and shape of the window from which they are created. Thus a large window results in a larger, slower animation that demands more disk space and memory to play back. The SET WINDOW/SIZE=  command is generally used to specify minimally acceptable frame size.

See section "Advanced Movie-making" (p. 126), for more examples.


Ch5 Sec3. DISPLAYING AN HDF MOVIE

Viewing a movie requires software which is not included with the Ferret distribution (although in some cases we have made the binary available in Ferret's anonymous ftp area). NCSA's X Data Slice reads HDF files and is available via anonymous ftp from NCSA. It requires about 1.7Mb of disk space. NCSA's ftp server is

    ftp.ncsa.uiuc.edu      login id is "anonymous", give your e-mail address as the password

Consult the README files you will find there for instructions on obtaining X Data Slice. Other utilities from NCSA can also be used for animations.


Ch5 Sec4. ADVANCED MOVIE-MAKING


Ch5 Sec4.1. REPEAT command

The REPEAT command is quite flexible. It allows you to repeat a sequence of commands, not just a single command as in the basic example above. You can give the GO command as an argument to REPEAT. The following examples demonstrate these techniques.

Note: MODE VERIFY must be SET (this is the default state) for loop counting to work.

Example 1

Here we give multiple arguments to REPEAT; note the semi-colon separation and the parentheses. Note that FRAME, in this example, is used as a stand-alone command.

yes? REPEAT/L=1:12 (FILL SST; GO fland; FRAME/file=my_movie.mgm)

Example 2

In this example we use the REPEAT command to pan and zoom over a sea surface temperature field.

SET DATA coads_climatology
SET REGION/L=1
SET REGION/X=120E:60W/Y=45S:45N
SHADE sst; GO fland

! ZOOM
REPEAT/K=1:5 (SET REGION/DX=+8:-8/DY=+8:-8; SHADE sst; GO fland; FRAME)

! PAN
REPEAT/K=1:5 (SET REGION/DX=+5; SHADE/LEV=(20,30,.5) sst; FRAME)

Example 3

In this example the user calls setup_movie.jnl (text included below), title.jnl, which creates a title frame, then repeats main_movie.jnl (text included below) for each time step desired. Finally, the user adds a frame of credits at the end of the movie. Each of the scripts would end with the FRAME command (except setup_movie). Using GO scripts as arguments to REPEAT allows you to customize the plot with many commands before finally issuing FRAME, as the text of main_movie.jnl below demonstrates.

yes? ! make the movie
yes? GO setup_movie
yes? GO title
yes? REPEAT/L=1:12 GO main_movie
yes? GO credits

! Setup_movie.jnl
SET WINDOW/SIZE=.45/ASPECT=0.7
SET MOVIE/file=my_movie.mgm
SET DATA coads_climatology
SET REGION/X=130E:75W/Y=8S:8N
SET MODE CALENDAR:months
GO bold
PPL SHAKEY ,,.15,.2
PPL AXLEN 8.8,4.8

! Main_movie.jnl
FILL/SET_UP/LEVELS=(16,31,1) sst
PPL LABS; PPL TITLE
PPL FILL
LABEL 210,9.5,0,0,.22 @TRCOADS MONTHLY CLIMATOLOGY (1946-1989)
LABEL 210,-12,0,0,.22 @TRSEA SURFACE TEMPERATURE (DEG C)
LABEL 130,11,-1,0,.22 @TR'LAB4'
FRAME

Note: If you use the FILL command, we suggest that you use SHADE while customizing and fine-tuning your movie, then use FILL for the final run. SHADE is much faster.


Ch5 Sec4.1.1. Initializing the color table

If you create a movie with a title frame, or a first frame which otherwise uses different colors than the rest of the movie, you should be aware of an HDF peculiarity: all the colors that you plan to use in your movie must be in the first frame, or else color behavior will be unpredictable when you animate.

To "reserve" the colors you need, use overlapping full-window viewports. Make a representative plot in the title frame, then cover over it with either a black or white rectangle and finally write the title text. Here is a script which initializes the color table while creating a title frame.

! define 3 identical full-frame viewports
DEFINE VIEW full1;  DEFINE VIEW full2;  DEFINE VIEW full3

! draw frame one of the movie in full color
SET VIEW full1
SET DATA coads_climatology
SHADE/LEVELS=(16,31,1)/L=1 sst                  ! dummy frame

! white-out over the picture
SET VIEW full2
GO setup_text
SHADE/PALETTE=white/NOLAB/NOKEY/i=1:2/j=1:2  (i+j)*0

!put on title frame labels (using [0,1] coordinate space)
SET VIEW full3
GO setup_text
PPL PLOT
LABEL .5,.7,0,0,.3 @TRMy Title
PPL ALINE 1,.2,.55,.8,.55
PPL ALINE 1,.2,.53,.8,.53
LABEL .5,.4,0,0,.2 @CRBy me

!capture the title frame and clean up
FRAME
GO cleanup_text



Ch5 Sec4.1.2. Making movies in batch mode

Ferret, like other Unix applications, can be run in "batch" mode by redirecting standard input and output. Thus

ferret -unmapped <movie_commands.jnl >&movie.log&

will make a movie running in background mode based on the commands in file movie_commands.jnl logging standard output and standard error in file movie.log.

Note, however, that when used in this mode to make a movie Ferret will still require access to an X windows display (as in "setenv DISPLAY node:0"). To eliminate this requirement we recommend the use of the X11R6 "virtual frame buffer" (Xvfb). This application permits the movie frames to be generated in the absence of any physical display device. Consult your system manager for the availability of X11R6 for your system.


Ch5 Sec5. CREATING GIF IMAGES

GIF is a highly compressed format suitable for single images. (Ferret will not directly create GIF89 animations.) The procedure for creating a GIF image is nearly identical to the creation of a single frame of an HDF file. The modification is generally just to select a file name with the ".gif" extension; Ferret will automatically sense this as a request to create a GIF-formatted image file. Alternatively, any file name can be used if the GIF format is specified explicitly using

FRAME/FORMAT=GIF

If a number of GIF images are created using the same file name Ferret will automatically rename subsequent versions with a version number. Thus a repeat loop can be used to generate many GIF images.

Example:

REPEAT/L=1:12(FILL sst; GO fland; FRAME/file=myimage.gif)

Note: In this mode of grabbing an image, Ferret creates a GIF file by requesting the image back from your screen (your X server). That means that the X server normally has to be configured as pseudo-color.

An alternative approach to creating GIF's (which does not share this restriction) is to invoke Ferret with the -gif command line switch "ferret -gif" (p. 6).


Ch5 Sec6. CREATING MPEG ANIMATIONS

MPEG animations can be created from the outputs of the FRAME command—either HDF animation files or a sequence of GIF images. Various public domain utilities are available to perform the conversion from Ferret's output formats into MPEG animations. The routine hdf2mpeg (available in 1995 from ftp.ncsa.uiuc.edu in HDF/contrib/NCSA/HDF2MPEG) can be used to convert HDF files into MPEG animations; mpeg_encode (available from mm-ftp.CS.Berkeley.EDU in /pub/multimedia/mpeg/encode) can be used to convert sequences of GIF files. New and improved routines may have become available since the time of this writing. See further documentation on this topic in the FAQ file from the Ferret WWW home page.


ferret_ug@pmel.noaa.gov

Last modified: September 27, 2000