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 6: Creating SSS Time Series

Learning Objectives

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

  1. Find and download sea surface salinity (SSS) data from the NASA SMAP satellite

  2. Utilize the NASA/JPL Physical Oceanography DAAC Data Subscriber tools for data access

  3. Read in multiple files to generate a time series using a loop

  4. Convert date string to numpy datetime types

  5. Write a function in Python to consolidate code used iteratively

Motivation

In the previous lab on sea surface temperature, we obtained data provided in a single, convenient netCDF file. However, we often receive data spread across many files that may not always be formatted consistently. For example, the data could be provided on different grids corresponding to the satellite swath along its orbit. In this lab, we will see how to obtain a collection of files for sea surface salinity (SSS) data and generate a time series from this set.

Sticking with the theme of the previous lab, we will consider salinity variations in the coastal ocean near Monterey Bay region. Because coastal upwelling can bring relatively salty subsurface water toward the surface, we might expect higher SSS during periods of stronger upwelling. However, the salinity signal may also reflect precipitation, evaporation, freshwater input, horizontal transport, and mixing. Let’s have a look.

Getting Started

Import modules for this notebook

To begin this lab, we’ll import the modules used in this notebook:

Note that this notebook provides the functionality to download a set of files from JPL’s Physical Oceanography DAAC (PO.DAAC) using their podaac-data-subscriber package which we downloaded with the notes in the Getting Started section.

Info detailing how these scripts work can be found on the github page here: https://github.com/podaac/data-subscriber/tree/main

Set paths to your local and external folders

In this lab, we will access a non-negligible volume of data. In the previous lab, we stored our data in the same directory as our notebook. It is good practice to maintain an organized local data repository of data obtained from online databases, so we will demo that here - and continue this practice in subsequent notebooks.

Part 1: Download SSS files

To begin this lab, we will obtain sea surface salinity data estimated from the NASA Surface Moisture Active Passive (SMAP) satellite obtained with the PO.DAAC tools.

User Inputs

Here, we will define the query parameters for our search of SSS data:

Note that the short name is identified on the PO.DAAC landing page for the data product of interest. In this lab, the SSS data is provided HERE.

Creating the Download Arguments

Next, we’ll organize our query using the PO.DAAC tools:

Run the downloading script

The run method will download the files found in PO.DAAC. Nothing will print in the Jupyter notebook but the files will show up in the download folder you created above.

After this code has finished running, you will find all of the SSS data for the years corresponding to your query in your data folder.

Part 2: Generating a time series

Formulate a list of files

In the subsequent sections, we’re going to write a loop to iterate through each of the files we’ve obtained and extract the salinity data at a location of interest. In anticipation of this larger loop, here will use a shorter example of a loop to make a list of the files that we have downloaded:

Found 37 files

Make an array of dates

Now that we’ve identified our list of files, next we will construct an array of dates that will be used for our independent data (i.e. the x-axis of our time series plot). For reference, this is equivalent to the dates object we constructed for our time series of SST in the previous lab. However, the format will be slightly different. Here, we will see another date format included with the numpy package called datetime64 whereas the previous lab used a datetime object from the datetime package. As we will see in the coming labs, there are many different ways that time can be defined for computations and visualization.

To construct our date array, we will leverage the fact that each file contains the year, month, and day in the file name. When formatted as a string of the form YYYY-MM-DD, these values can be easily converted to a datetime64 object in numpy.

Make an array of SSS values

Now that we’ve got our time data, we’ll turn our attention to the salinity data. Below, we will loop through each of the files but before we begin, its helpful to get familiar with a single file to examine the format.

Open a single file and read in the data

Begin by opening one of the files in Panoply, similar to the steps we completed in the previous lab. Note the structure of the file and the names of the variables. Your view in Panoply should look like the following screenshot:

SMAP SSS data in Panoply

Figure 1:SMAP SSS data in Panoply

After you’ve inspected the file, use the netCDF package to read in the longitude, latitude, and SSS variables, following the steps used in the previous lab:

../data/labs/lab06/SMAP_L3_SSS_201712_MONTHLY_V5.0.nc

Find an SSS value at the location closest to Monterey Bay

Now that you’ve got the data read in, let’s identify a location near to Monterey Bay. As in the previous lab, we’ll define one pair of longitude and latitude values corresponding to this location:

Note that this location is further offshore of Monterey than the location used in our previous lab due to issues with coastal resolution and contamination.

Then, we’ll find the closest row and column to this point, and extract the SSS value at this location:

Longitude sanity check: -123 -123.125
Latitude sanity check: 37 37.125
Closest salinity estimate: 33.390404

Generalize the reading and extraction to a function

In the previous step, we opened a single file to get the SSS value. You could imagine copying and pasting this code for each of the files we downloaded above. However, that would be pretty inefficient. Luckily, a loop is designed precisely to run the same code over and over again - we just need to bundle our code up into a function.

Here, we will write a function that will take in a file path (a given data file) along with a location and return an SSS value based on the location:

Note that this is the exact same code from above - just written under the defined read_SSS_from_file function definition.

Make a list of SSS values

With our list of files in hand and our SSS function written, we’re prepared to extract the SSS values corresponding to each of our files. This loop will look quite similar to the one above for dates:

Part 3: Make a plot

After collecting all of the salinity values in the Monterey Bay location, now we’re ready to make a plot!

Make the plot of the SSS time series

Using code similar to the plotting of the time series in the previous lab, make a plot of the monthly salinity values:

<Figure size 1000x400 with 1 Axes>

There is substantial seasonal and interannual variability observed in the plot above. Explain some key features and provide a hypothesis for what might contribute to this variability.

🤔 Try it for yourself!

In the example above, we looked at SSS in the Monterey Bay region during 2018-2020. Consider another process in the ocean that you expect to have a significant SSS signal - think about regions with strong seasonal precipitation, upwelling, ice melt, etc. Then, using the steps above, obtain some data from the SMAP SSS product and use it to examine your process of interest. Be sure to visualize a time series and consider what contributes to the observed variability.