Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab 9: Visualizing SSH Data in a Movie

In this notebook, we’ll see how to create movies from data. A movie is just a set of frames that we view in quick succession and they can be effective tools for examining data and sharing it with our colleagues. To make a movie in Python, we can generate a series of plots and then stitch them together into a movie format. In this tutorial, we will generate a series of plots using the cartopy module and then use the moviepy module to format them together into a movie.

This notebook has three parts:

  1. Download sea surface height data using Copernicus’ copernicusmarine package

  2. Generate panels for sea surface height in the Pacific Ocean

  3. Stitch together them to show variability in sea surface height over the year 2026

  4. Test a few additional updates to the movie formatting and interpretation

Import the modules for this notebook

Part 1: Downloading Sea Surface Height Data via the Copernicus Marine Service

In this lab, we will use gridded sea level anomaly (SLA) data in the Global Ocean Gridded L4 Sea Surface Heights And Derived Variables Nrt. The steps to obtain this data are similar to those introduced in the previous lab for interfacing with Earthdata.

As before, start by defining a folder where the data will be downloaded:

Next, let’s “log in” to the Copernicus Marine service:

INFO - 2026-10-25T23:54:11Z - Using existing credentials from /Users/mike/.copernicusmarine/.copernicusmarine-credentials. Use --force-overwrite combined with credentials (specified by arguments, netrc file or environment variables) to always overwrite.

Up next, we’ll provide a query to determine which files exist. Here, let’s gather all of the sea surface height anomaly files for the year 2026. The query using the copernicusmarine module takes a dictionary in the following form:

Next, we can take a peek at the list of files found using a “dry run” for a preview:

INFO - 2026-10-25T23:54:14Z - Selected dataset version: "202506"
INFO - 2026-10-25T23:54:14Z - Selected dataset part: "default"
INFO - 2026-10-25T23:54:15Z - Listing files on remote server...
1it [00:01,  1.52s/it]
INFO - 2026-10-25T23:54:16Z - Total size of the download: 29.37 GB.
Files selected: 847
Total size: 30070.76630973816

Using our query, we’ll download the data using the download command:

Part 2: Generating Movie Panels

To make a movie, we will need to make the panels first and then stitch them together.

Make a function to read and plot the data

To generate a plot for all of our data, we would like to loop through each data file and generate an identical plot. To facilitate this process, first we will write a function that will generate a plot for us.

Test one file

Test the function above for just one file. Once you’re happy with the output, then we can loop through all of the available data files to generate the contents of our movie.

Then, test the panel function:

<Figure size 900x700 with 2 Axes>

Loop through the data panels

When you are happy with your plot, next we can loop through each file to create the panels for our movie

Part 3: Generating the Movie

Now that all of the panels are made, it’s time to stitch them together into a movie.

Moviepy - Building video ../data/labs/lab09/SSH Anomalies 2026.mp4.
Moviepy - Writing video ../data/labs/lab09/SSH Anomalies 2026.mp4

                                                                                                                        
Moviepy - Done !
Moviepy - video ready ../data/labs/lab09/SSH Anomalies 2026.mp4
Loading...

Part 4: A Few Additional Movie Improvements

Adding Elapsed Time to the Visualization

In the movie above, we could see the progression of the fields but it was difficult to see which dates these fields corresponded to because the date was rapidly changing in the header of the figure. An alternative method is to build an additional axis which keeps track of the time elapse over a given period. Here, we’ll add one for 2026:

Let’s see what the figure generated by this code looks like:

<Figure size 700x600 with 3 Axes>

🤔 Try it for yourself

The above code shows how to make an axis for elapsed time in a given month. Adapt the code above to make an additional movie which shows the progression of time elapsed through the visualization.

Adding a Time Series

The above code shows how to make an additional axis with the elapsed time. However, we could alternatively use our data to generate a time series for a given region of the domain.

🤔 Try it for yourself

Modify the code above to plot a time series on the axis below the plot, rather than an elapsed time bar. Generate the time series first and then use a thick marker to identify the plotting date. The marker should move along the time series as the visualization progresses.