X

NV5 Geospatial Blog

Each month, NV5 Geospatial posts new blog content across a variety of categories. Browse our latest posts below to learn about important geospatial information or use the search bar to find a specific topic or author. Stay informed of the latest blog posts, events, and technologies by joining our email list!



Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

6/3/2025

Rethinking the Reliability of Type 1a Supernovae   How do astronomers measure the universe? It all starts with distance. From gauging the size of a galaxy to calculating how fast the universe is expanding, measuring cosmic distances is essential to understanding everything in the sky. For nearby stars, astronomers use... Read More >

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

5/26/2025

Whether you’re new to remote sensing or a seasoned expert, there is no doubt that large language models (LLMs) like OpenAI’s ChatGPT or Google’s Gemini can be incredibly useful in many aspects of research. From exploring the electromagnetic spectrum to creating object detection models using the latest deep learning... Read More >

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

4/28/2025

When every second counts, the ability to process geospatial data rapidly and accurately isn’t just helpful, it’s critical. Geospatial Intelligence (GEOINT) has always played a pivotal role in defense, security, and disaster response. But in high-tempo operations, traditional workflows are no longer fast enough. Analysts are... Read More >

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

4/24/2025

This blog was written by Eli Dwek, Emeritus, NASA Goddard Space Flight Center, Greenbelt, MD and Research Fellow, Center for Astrophysics, Harvard & Smithsonian, Cambridge, MA. It is the fifth blog in a series showcasing our IDL® Fellows program which supports passionate retired IDL users who may need support to continue their work... Read More >

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

2/25/2025

This blog was written in collaboration with Adam O’Connor from Wyvern.   As hyperspectral imaging (HSI) continues to grow in importance, access to high-quality satellite data is key to unlocking new insights in environmental monitoring, agriculture, forestry, mining, security, energy infrastructure management, and more.... Read More >

1345678910Last
11761 Rate this article:
4.5

Guest Request - How to create an animated plot video

Jim Pendleton

Very recently I had the opportunity to go for a hike here in Boulder with a friend from my college years.  He's now a successful scientist, using IDL since about 1985.  I sense causality.

Of course, since we're both science and software geeks, the topic of conversation rapidly devolved from family and the rejuvenating power of nature, to general health topics for 40-somethings, and coding quandaries.

He had a practical question for me.  "Let's say I want to animate a plot and programmatically generate a video for a presentation.  Is this easy to do in IDL these days?"

He'd not studied the What's New sections of the IDL documentation for a couple releases.  Science takes precedence, and his impressions were based on the now-obsolete MPEG_WRITE functionality.

The answer of course is that IDL now makes this task very simple, indeed. Here is a quick example, animating a simple sine wave plot.

(Recall that as of 8.3, you can copy and paste lines including the IDL prompt from this web page to the Workbench IDL Console, and the "IDL>" string will be stripped automatically.)

First, generate your wave form using the PLOT function.

IDL> x = findgen(361)*!dtor
IDL> y = sin(x)
IDL> p = plot(x, y)

For this exercise, we'll generate an output MPEG-4 file in your temporary directory.

IDL> file = filepath('test.mp4', /tmp)

We'll use the Plot::CopyWindow method to scrape the bitmap from the plot graphic.  This is returned in exactly the shape the WRITE_VIDEO procedure requires as input.

If you are generating output using Direct Graphics, the equivalent action is to call the function TVRD(TRUE=1) .  And if you are using Object Graphics, get the IMAGE_DATA property from your destination object, such as an IDLgrWindow.

IDL> write_video, file, p.copywindow(/antialias), handle = handle, $
IDL>        format = 'mp4', video_fps = 30

We've now written the first frame of our video.

Here, we've specified the format explicitly as MPEG-4 and the playback rate for the video as 30 frames per second.  On the first call to WRITE_VIDEO the HANDLE keyword is an output.  We will use it as input when writing the remainder of our frames.

Let's loop over 360 degrees by a single degree and update the plot at each step.  Our animation will produce about 12 seconds of video in playback.  (361 frames/30 frames per second.)

IDL> for i = 0, 359 do begin & $
IDL>    y = shift(y, 1) & $
IDL>    p.setdata, x, y & $
IDL>    write_video, file, p.copywindow(/antialias), handle = handle & $
IDL> endfor

Once we have written all our frames, explicitly close the video file to commit the changes.

IDL> write_video, /close, handle = handle

If you're running an OS that understands file associations, you should be able to simply SPAWN the file from IDL to verify its playback.

IDL> spawn, file, /hide

That was indeed easy.

If you want to "slow down" your animation at a critical point for highlighting, simply write a single image buffer multiple times.  For example, you might add this code snippet to slow down the animation during playback's central frames:

    if (i gt 90 && i lt 270) then begin
        for j = 0, 3 do begin
            write_video, file, p.copywindow(/antialias), handle = handle
        endfor
    endif

The WRITE_VIDEO procedure is a wrapper for the IDLffVideoWrite class which in turn wraps the popular open-source FFmpeg library.  WRITE_VIDEO provides options for writing an audio stream to your video as well.

In the online help, see the note on "Replacing the FFmpeg Version" in the Creating Video topic if you need to write your animations in a format whose support is outside the defaults in IDL, such as H.264 video format or MP3 audio.

 

Please login or register to post comments.