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 5: Plotting SST in Python

Learning Objectives

By the end of this lab, you should be able to

  1. Find and download sea surface temperature (SST) data from the NASA MUR dataset

  2. Describe the structure of a netCDF file

  3. Plot a time series of SST from data in a netCDF file

  4. Plot a map of SST and SST differences from a netCDF file

Motivation

In the previous labs, we’ve used QGIS to visualize and analyze satellite imagery. Here, we will start to transition to using Python which will allow us assess data much for efficiently than in GIS.

In this notebook, we will analyze sea surface temperature in the California Current where upwelling of cold water is a prevalent feature of the system.

Part 1: Obtaining SST Data from the MUR Product

To begin, we’ll access data from the Multi-scale Ultra-high Resolution (MUR) Sea Surface Temperature (SST) product. This product is supported by the NASA MEaSUREs program. mMore information can be found at this project on the product page at JPL’s Physical Oceanography DAAC.

Here, we will use a convenient tool from the Environmental Research Division’s Data Access Program (ERRDAP) to gather SST data in a given location over a specific time frame. For the MUR product, we can access the data HERE.

Navigate to the Data Access Form page and select a subset of data according to the following specifications:

  • time: 2008-02-01T09:00:00Z to 2008-07-31T09:00:00Z

  • latitude: 34°N to 41°N

  • longitude -126°E to -118°E

  • analysed_sst (checked)

From the dropdown of output file types, choose the .nc option.

On ERRDAP, your query should look like the following screenshot:

Screenshot of a data request from ERRDAP for the MURv4.1 data around Monterey Bay during spring 2008.

Figure 1:Screenshot of a data request from ERRDAP for the MURv4.1 data around Monterey Bay during spring 2008.

When the file has downloaded, save it into your Lab 5/Data folder, renaming it at MUR_SST.nc. Then, to facilitate the codes below, enter the path to your data folder into the following coding block:

Understanding the structure of a netCDF file

The netCDF file structure - short for Network Common Data Format - is an organizational structure for gridded data used widely in oceanography and other Earth sciences. To explore this file, open the file with the Panoply and take a look at the contents.

You should see the following fields:

  • analysed_sst

  • longitude

  • latitude

  • time

MUR in Panoply

Figure 2:MUR in Panoply

Of course, these match up with all of the fields selected from the ERRDAP portal. Here, we see that the .nc file contains the full collection of complementary fields.

By clicking each field in the file list, you can see lots of metadata about each field and, importantly, its size. For example, you can see that the analysed_sst field has a shape of (182, 701, 801) corresponding to the dimensions of time, latitude, and longitude. You can visualize this as a 3D grid composed of 2D maps stacked through time:

The structure of the SST data in the MUR file

Figure 3:The structure of the SST data in the MUR file

Part 2: Reading netCDF data in Python

Loading Packages in Python

Before reading in our data for plotting, we’ll need to load in a few packages. While Python has some built-in functionality, the code for specific tasks such as reading and plotting data are contained in packages. Here, we will import some packages used in this notebook.

Typically, we will import packages at the start of a notebook but they are put here near the code for this initial example.

Reading netCDF files

In Python, the netCDF package provides the functionality to read in nc files. For example, we can read the file into a Dataset object and print out the names of the variables as follows:

dict_keys(['time', 'latitude', 'longitude', 'analysed_sst'])

Here, we see that the variables are the same as those above. We can read in the data from the file as follows:

In the fields above, we can see that they are read in with their shape in mind - the 1D fields are appended with the [:] field while the 3D fields are appended with [:,:,:].

After reading in the fields, we’ll be sure to close the file:

Part 3: Plotting a Time Series

Now that we’ve got our data read in, we’re ready for some plotting. Since the goal of this exploration is to examine the effect of upwelling on SST, let’s have a look at a time series of temperature in the middle of Monterey Bay at 36.75°N, 122.03°W.

In order to make a time series at this location, we’ll need to find its location in the grid. Here, we’ll find the closest indices in the longitude and latitude grids that correspond to the Monterey Bay location. Let’s define this here:

Longitude Index: 397
Latitude Index: 275
Model Longitude: -122.03
Model Latitude: 36.75

With these indices in hand, we can sample the big 3D grid along the respective dimensions. Above, we saw that latitude corresponded to the dimension with index 1 and longitude corresponded to the dimension with index 2, so we’ll enter these here:

The : in dimension 0 indicates that we will take all values along this dimension i.e. all times.

With this data in hand, we can make a plot of the time series:

<Figure size 800x400 with 1 Axes>

In the plot above, we see that the time was labeled as “Seconds since 1970-01-01” and this was labeled in the metadata in the nc file. This type of time, called Unix time, is convenient for storing time in a continuous format but it’s not very helpful for human interpretation. Luckily, there is a convenient function that can be used to convert each Unix time to a date. Let’s do that here:

With our dates in hand, we can recreate the plot above:

<Figure size 800x400 with 1 Axes>

With our converted dates, we can see that the dates from February through July 2008 are now used for the x-axis in our new plot, consistent with the query from ERRDAP.

Part 4: Plotting a Map

In addition to plotting a time series, we can also plot a map of our data by “slicing” our data differently.

Plotting a Map on a Given Day

Let’s take a look at the first timestep, plotting the grid along all rows and columns of the data array:

<Figure size 700x700 with 2 Axes>

Similar to the plot above, we can also plot our figure with references to the longitude and latitude coordinates provided with the file. Let’s check this out for another timestep in the file:

<Figure size 700x700 with 2 Axes>

🤔 Try it for yourself

In the plot above, change the timesteps and investigate maps at different times of the upwelling season. Where do you find evidence of upwelling in these SST estimates?

Plotting a Statistical Summary

Another component of this data we might be interested in is some statistical summary over a given time period. Here, let’s compute the mean and visualize this along the California coast.

<Figure size 700x700 with 2 Axes>

Estimating Temporal Differences in Space

With the temperature fields at our fingertips, we can compute many different components of our system. Here, we’ll choose a simple calculation - the temperature differences between winter and summer.

<Figure size 700x700 with 2 Axes>

As we would probably expect, the SST is warmer in summer than in winter - but we can estimate the magnitude of this effect with our SST data.

Another computation we could consider is the anomaly of temperature relative to some given time period. For example, we could ask: how does the temperature in spring compare to the mean over the winter-summer period? Let’s compute this here:

<Figure size 700x700 with 2 Axes>

Here, we can see that the waters in the spring are anomalously cold along the CA coastline in spring.

🤔 Try it for yourself!

In the example above, we looked at upwelling in the California Current system during spring of 2008 - only a small part of the decades-long global MUR SST product. Consider another process in the ocean that you expect to have a significant SST signal - think ENSO events, marine heat waves, ice sheet melt, etc. Then, using the steps above, find some data from the MURv4.2 product and use it to examine your process of interest. Be sure to visualize a time series, a map, and compute some statistics for your region of interest.