Open In Colab   Open in Kaggle

Tutorial 1: Calculating ENSO with Xarray#

Week 1, Day 2, Ocean-Atmosphere Reanalysis

Content creators: Abigail Bodner, Momme Hell, Aurora Basinski

Content reviewers: Yosemley Bermúdez, Katrina Dobson, Danika Gupta, Maria Gonzalez, Will Gregory, Nahid Hasan, Paul Heubel, Sherry Mi, Beatriz Cosenza Muralles, Jenna Pearson, Chi Zhang, Ohad Zivan

Content editors: Paul Heubel, Jenna Pearson, Chi Zhang, Ohad Zivan

Production editors: Wesley Banfield, Paul Heubel, Jenna Pearson, Konstantine Tsafatinos, Chi Zhang, Ohad Zivan

Our 2024 Sponsors: NFDI4Earth, CMIP

project pythia#

Pythia credit: Rose, B. E. J., Kent, J., Tyle, K., Clyne, J., Banihirwe, A., Camron, D., May, R., Grover, M., Ford, R. R., Paul, K., Morley, J., Eroglu, O., Kailyn, L., & Zacharias, A. (2023). Pythia Foundations (Version v2023.05.01) https://zenodo.org/record/8065851

CMIP.png#

Tutorial Objectives#

Estimated timing of tutorial: 30 mins

In this notebook (adapted from Project Pythia), you will practice using multiple tools to examine sea surface temperature (SST) and explore variations in the climate system that occur during El Niño and La Niña events. You will learn to:

  1. Load sea surface temperature data from the CESM2 model

  2. Mask data using .where()

  3. Compute climatologies and anomalies using .groupby()

  4. Use .rolling() to compute moving average

  5. Compute, normalize, and plot the Oceanic Niño Index

After completing the tasks above, you should be able to plot the Oceanic Niño Index that looks similar to the figure below. The red and blue regions correspond to the phases of El Niño and La Niña, respectively.

ONI index plot from NCAR Climate Data Guide

Credit: NCAR

Pythia credit: Rose, B. E. J., Kent, J., Tyle, K., Clyne, J., Banihirwe, A., Camron, D., May, R., Grover, M., Ford, R. R., Paul, K., Morley, J., Eroglu, O., Kailyn, L., & Zacharias, A. (2023). Pythia Foundations (Version v2023.05.01) https://zenodo.org/record/8065851

Setup#

# installations ( uncomment and run this cell ONLY when using google colab or kaggle )

# !pip install --upgrade --force-reinstall  pythia_datasets cartopy matplotlib geoviews xarray
# !pip install cartopy geoviews pythia_datasets
# # note you will need to restart the kernel after this - there should be a small button at the end of the output.
# imports
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import xarray as xr
from pythia_datasets import DATASETS
import geoviews as gv
import geoviews.feature as gf

Figure Settings#

Hide code cell source
# @title Figure Settings
import ipywidgets as widgets  # interactive display

%config InlineBackend.figure_format = 'retina'
plt.style.use(
    "https://raw.githubusercontent.com/neuromatch/climate-course-content/main/cma.mplstyle"
)

Figure Settings#

Hide code cell source
# @title Figure Settings
import ipywidgets as widgets  # interactive display

%config InlineBackend.figure_format = 'retina'
plt.style.use(
    "https://raw.githubusercontent.com/neuromatch/climate-course-content/main/cma.mplstyle"
)

Video 1: El Niño Southern Oscillation#

Section 1: Introduction to El Niño Southern Oscillation (ENSO)#

In W1D1 you practiced using Xarray to calculate a monthly climatology, climate anomalies, and a running average on monthly global Sea Surface Temperature (SST) data from the Community Earth System Model v2 (CESM2). You also used the .where() method to isolate SST data between 5ºN-5ºS and 190ºE-240ºE (or 170ºW-120ºW). This geographic region, known as the Niño 3.4 region, is in the tropical Pacific Ocean and is commonly used as a metric for determining the phase of the El Niño-Southern Oscillation (ENSO). ENSO is a recurring climate pattern involving changes in SST in the central and eastern tropical Pacific Ocean, which has two alternating phases:

  • El Niño: the phase of ENSO characterized by warmer than average SSTs in the central and eastern tropical Pacific Ocean, weakened east-to-west equatorial winds, and increased rainfall in the eastern tropical Pacific.

  • La Niña: the phase of ENSO which is characterized by cooler than average SSTs in the central and eastern tropical Pacific Ocean, stronger east-to-west equatorial winds, and decreased rainfall in the eastern tropical Pacific.

Section 1.1: Tropical Pacific Climate Processes#

To better understand the climate system processes that result in El Niño and La Niña events, let’s first consider typical climate conditions in the tropical Pacific Ocean. Recall from W1D1, trade winds are winds that blow east to west just north and south of the equator (these are sometimes referred to as “easterly” winds since the winds originate from the east and blow toward the west). As we discussed yesterday, the reason that the trade winds blow from east to west is related to Earth’s rotation, which causes the winds in the Northern Hemisphere to curve to the right and winds in the Southern Hemisphere to curve to the left. This is known as the Coriolis effect.

If Earth’s rotation affects air movement, do you think it also influences surface ocean water movement? It does! As trade winds blow across the tropical Pacific Ocean, they move water because of friction at the ocean surface. But because of the Coriolis effect, surface water moves to the right of the wind direction in the Northern Hemisphere and the left of the wind direction in the Southern Hemisphere, respectively. However, the speed and direction of water movement changes with depth. Ocean surface water moves at an angle to the wind, and the water under the surface water moves at a slightly larger angle, and the water below that turns at an even larger angle. The average direction of all this turning water is about a right angle from the wind direction. This average is known as Ekman transport. Since this process is driven by the trade winds, the strength of this ocean water transport varies in response to changes in the strength of the trade winds.

Section 1.2: Ocean-Atmosphere Interactions During El Niño and La Niña#

So, how does all of this relate to El Niño and La Niña? Changes in the strength of Pacific Ocean trade winds and the resulting impact on Ekman transport create variations in the tropical Pacific Ocean SST, which further results in changes to atmospheric circulation patterns and rainfall.

During an El Niño event, easterly trade winds are weaker. As a result, less warm surface water is transported to the west via Ekman transport, which causes a build-up of warm surface water in the eastern equatorial Pacific. This creates warmer-than-average SSTs in the eastern equatorial Pacific Ocean. The atmosphere responds to this warming with increased rising air motion and above-average rainfall in the eastern Pacific. In contrast, during a La Niña event, easterly trade winds are stronger. As a result, warmer surface water is transported to the west via Ekman transport, and cool water from deeper in the ocean rises in the eastern Pacific during a process known as upwelling. This creates cooler-than-average SSTs in the eastern equatorial Pacific Ocean. This cooling decreases rising air movement in the eastern Pacific, resulting in drier-than-average conditions.

In this tutorial, we’ll examine sea surface temperatures (SST) to explore variations in the climate system that occur during El Niño and La Niña events. Specifically, we will plot and interpret CESM2 SST data from the Niño 3.4 region.

This Niño 3.4 region is the most representative of the ENSO phenomenon (cf. Barnston et al. 1997) and therefore state-of-the-art. Regions 1 to 4 have been historical choices however are still used for historical comparisons and to investigate certain features of the multifaceted ENSO.

Section 2: Calculate the Oceanic Niño Index#

In this notebook, we are going to combine several topics and methods you’ve covered so far to compute the Oceanic Niño Index (ONI) using SST from the CESM2 submission to the CMIP6 project.

You will be working with CMIP6 data later in the week, particularly during W2D1. You can also learn more about CMIP, including additional methods to access CMIP data, please see our CMIP Resource Bank and the CMIP website.

To calculate the Oceanic Niño Index (ONI) you will:

  1. Select SST data from Niño 3.4 region of 5ºN - 5ºS and 190ºE - 240ºE (or 170ºW - 120ºW) shown in the figure below.

  1. Compute the climatology (here from 2000-2014) for the Niño 3.4 region.

  2. Compute the monthly anomaly for the Niño 3.4 region.

  3. Compute the area-weighted mean of the anomalies for the Niño 3.4 region to obtain a time series.

  4. Smooth the time series of anomalies with a 3-month running mean.

Here we will briefly move through each of these steps, and tomorrow you will learn about them in more detail.

Section 2.1: Open the SST Data#

First, open the SST and areacello datasets, and use Xarray’s .merge() method to combine them into a single dataset:

# retrieve (fetch) the SST data we are going to be working on
SST_path = DATASETS.fetch("CESM2_sst_data.nc")

# open the file we acquired with xarray
SST_data = xr.open_dataset(SST_path)

# remember that a spatial cell of one times one degree does not have a constant area around the globe, each has a different size in square km.
# we need to account for this when taking averages for example

# fetch the weight for each grid cell
gridvars_path = DATASETS.fetch("CESM2_grid_variables.nc")

# open and save only the grid cell weights whose variable name is 'areacello'
# here the 'o' at the end refers to the area cells of the 'ocean' grid
areacello_data = xr.open_dataset(gridvars_path).areacello

# merge the SST and weights into one easy-to-use dataset - ds stands for dataset
ds_SST = xr.merge([SST_data, areacello_data])
ds_SST
/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/xarray/conventions.py:440: SerializationWarning: variable 'tos' has multiple fill values {1e+20, 1e+20}, decoding all values to NaN.
  new_vars[k] = decode_cf_variable(
<xarray.Dataset> Size: 47MB
Dimensions:    (time: 180, d2: 2, lat: 180, lon: 360)
Coordinates:
  * time       (time) object 1kB 2000-01-15 12:00:00 ... 2014-12-15 12:00:00
  * lat        (lat) float64 1kB -89.5 -88.5 -87.5 -86.5 ... 86.5 87.5 88.5 89.5
  * lon        (lon) float64 3kB 0.5 1.5 2.5 3.5 4.5 ... 356.5 357.5 358.5 359.5
Dimensions without coordinates: d2
Data variables:
    time_bnds  (time, d2) object 3kB ...
    lat_bnds   (lat, d2) float64 3kB ...
    lon_bnds   (lon, d2) float64 6kB ...
    tos        (time, lat, lon) float32 47MB ...
    areacello  (lat, lon) float64 518kB ...
Attributes: (12/45)
    Conventions:            CF-1.7 CMIP-6.2
    activity_id:            CMIP
    branch_method:          standard
    branch_time_in_child:   674885.0
    branch_time_in_parent:  219000.0
    case_id:                972
    ...                     ...
    sub_experiment_id:      none
    table_id:               Omon
    tracking_id:            hdl:21.14100/2975ffd3-1d7b-47e3-961a-33f212ea4eb2
    variable_id:            tos
    variant_info:           CMIP6 20th century experiments (1850-2014) with C...
    variant_label:          r11i1p1f1

Visualize the first time point in the early 2000s. You can check this on the indexes of the variable time from the ds_SST above. Note that using the .plot() function of our data array will automatically include this as a title when we select just the first time index.

# create a figure
fig = plt.figure()

# assign axis and define the projection -  centred in pacific
ax = plt.axes(projection=ccrs.Robinson(central_longitude=180))

# add coastlines
ax.coastlines()

# add gridlines (lon and lat)
ax.gridlines()

# plots the first time index (0) of SST (variable name 'tos') at the first time
ds_SST.tos.isel(time=0).plot(
    ax=ax,
    transform=ccrs.PlateCarree(),  # give our axis a map projection
    vmin=-2,
    vmax=30,          # define the temp range of the colorbar from -2 to 30C
    cmap="coolwarm",  # choose a colormap
)
<cartopy.mpl.geocollection.GeoQuadMesh at 0x7f9928addc10>
/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
../../../_images/54da9f1a949890016581292c9f127609a99ad15be88796b55bd629b77223cbae.png
Click here for a description of the plot A map plot showing the sea surface temperature (SST) in January 2000 ranging from -2°C to 30°C from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). Equatorial regions show the warmest temperatures, and polar regions the lowest. A few larger patterns indicate that more than just the latitude is important to create the spatial SST distribution.
Click here for a description of the plot A map plot showing the sea surface temperature (SST) in January 2000 ranging from -2°C to 30°C from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). Equatorial regions show the warmest temperatures, and polar regions the lowest. A few larger patterns indicate that more than just the latitude is important to create the spatial SST distribution.

Interactive Demo 2.1#

You can visualize what the next few times look like in the model by using the interactive sliderbar below.

# a bit more complicated code that allows interactive plots
gv.extension("bokeh")  # load Bokeh
dataset_plot = gv.Dataset(
    ds_SST.isel(time=slice(0, 10))
)  # slice only the first 10 timepoint, as it is a time consuming task
images = dataset_plot.to(gv.Image, ["longitude", "latitude"], "tos", "time")
images.opts(
    cmap="coolwarm",
    colorbar=True,
    width=600,
    height=400,
    projection=ccrs.Robinson(),
    clabel="Sea Surface Temperature [˚C]",
) * gf.coastline
Click here for a description of the plot An interactive map plot showing the sea surface temperature (SST) from January 2000 until October 2000 ranging from -2°C to 30°C from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). Over the annual cycle, the warm and cold SST regions shift depending on the solar input. A few larger patterns indicate that more than just the latitude is important to create the spatial SST distribution, e.g. the equatorial pacific shows a cooler SST trench over the entire year compared to the surrounding subtropical waters.
Click here for a description of the plot An interactive map plot showing the sea surface temperature (SST) from January 2000 until October 2000 ranging from -2°C to 30°C from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). Over the annual cycle, the warm and cold SST regions shift depending on the solar input. A few larger patterns indicate that more than just the latitude is important to create the spatial SST distribution, e.g. the equatorial pacific shows a cooler SST trench over the entire year compared to the surrounding subtropical waters.

Section 2.2: Select the Niño 3.4 Region#

You may have noticed that the lon for the SST data is organized between 0°–360°E.

ds_SST.lon
<xarray.DataArray 'lon' (lon: 360)> Size: 3kB
array([  0.5,   1.5,   2.5, ..., 357.5, 358.5, 359.5])
Coordinates:
  * lon      (lon) float64 3kB 0.5 1.5 2.5 3.5 4.5 ... 356.5 357.5 358.5 359.5
Attributes:
    axis:           X
    bounds:         lon_bnds
    long_name:      longitude
    standard_name:  longitude
    units:          degrees_east

This differs from how we typically use longitude (-180° to 180°). How do we convert the value of longitude between two systems (0° to 360° v.s. -180° to 180°)?

Let’s use lon2 to refer to the longitude system of 0° to 360° while lon refers to the system of -180° to 180°.

Note that 0° to 360° is equivalent to 0° to 180°, -180° to 0°. In other words, lon2 = 181° is the same as lon = -179°. Hence, in the western hemisphere, lon2 = lon + 360.

Therefore, the Niño 3.4 region should be (-5° to 5°, 190° to 240°) using the lon2 system.

Now that we have identified the longitude values we need to select, there are a couple of ways to select the Niño 3.4 region. We will demonstrate how to use both below.

  1. .sel()

# select just the Niño 3.4 region (note our longitude values are in degrees east) by slicing
tos_nino34_op1 = ds_SST.sel(lat=slice(-5, 5), lon=slice(190, 240))
tos_nino34_op1
<xarray.Dataset> Size: 370kB
Dimensions:    (time: 180, d2: 2, lat: 10, lon: 50)
Coordinates:
  * time       (time) object 1kB 2000-01-15 12:00:00 ... 2014-12-15 12:00:00
  * lat        (lat) float64 80B -4.5 -3.5 -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5
  * lon        (lon) float64 400B 190.5 191.5 192.5 193.5 ... 237.5 238.5 239.5
Dimensions without coordinates: d2
Data variables:
    time_bnds  (time, d2) object 3kB ...
    lat_bnds   (lat, d2) float64 160B ...
    lon_bnds   (lon, d2) float64 800B ...
    tos        (time, lat, lon) float32 360kB ...
    areacello  (lat, lon) float64 4kB ...
Attributes: (12/45)
    Conventions:            CF-1.7 CMIP-6.2
    activity_id:            CMIP
    branch_method:          standard
    branch_time_in_child:   674885.0
    branch_time_in_parent:  219000.0
    case_id:                972
    ...                     ...
    sub_experiment_id:      none
    table_id:               Omon
    tracking_id:            hdl:21.14100/2975ffd3-1d7b-47e3-961a-33f212ea4eb2
    variable_id:            tos
    variant_info:           CMIP6 20th century experiments (1850-2014) with C...
    variant_label:          r11i1p1f1
  1. Use .where() and select all values within the bounds of interest

# select just the Niño 3.4 region (note our longitude values are in degrees east) by boolean conditioning
tos_nino34_op2 = ds_SST.where(
    (ds_SST.lat > -5) & (ds_SST.lat < 5) & (ds_SST.lon > 190) & (ds_SST.lon < 240),
    drop=True,
)  # use dataset .where() function. use boolean commands. drop data that is not of interest
tos_nino34_op2
<xarray.Dataset> Size: 2MB
Dimensions:    (time: 180, d2: 2, lat: 10, lon: 50)
Coordinates:
  * time       (time) object 1kB 2000-01-15 12:00:00 ... 2014-12-15 12:00:00
  * lat        (lat) float64 80B -4.5 -3.5 -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5
  * lon        (lon) float64 400B 190.5 191.5 192.5 193.5 ... 237.5 238.5 239.5
Dimensions without coordinates: d2
Data variables:
    time_bnds  (time, d2, lat, lon) object 1MB 2000-01-01 00:00:00 ... 2015-0...
    lat_bnds   (lat, d2, lon) float64 8kB -5.0 -5.0 -5.0 -5.0 ... 5.0 5.0 5.0
    lon_bnds   (lon, d2, lat) float64 8kB 190.0 190.0 190.0 ... 240.0 240.0
    tos        (time, lat, lon) float32 360kB 28.26 28.16 28.06 ... 28.57 28.63
    areacello  (lat, lon) float64 4kB 1.233e+10 1.233e+10 ... 1.233e+10
Attributes: (12/45)
    Conventions:            CF-1.7 CMIP-6.2
    activity_id:            CMIP
    branch_method:          standard
    branch_time_in_child:   674885.0
    branch_time_in_parent:  219000.0
    case_id:                972
    ...                     ...
    sub_experiment_id:      none
    table_id:               Omon
    tracking_id:            hdl:21.14100/2975ffd3-1d7b-47e3-961a-33f212ea4eb2
    variable_id:            tos
    variant_info:           CMIP6 20th century experiments (1850-2014) with C...
    variant_label:          r11i1p1f1

You can verify that tos_nino34_op1 and tos_nino34_op2 are the same by comparing the lat and lon indexes.

We only need one of these, so let us choose the second option and set that to the variable we will use moving forward.

# SST in just the Niño 3.4 region
tos_nino34 = tos_nino34_op2

Let’s utilize the same code we used to plot the entire Earth, but this time focusing on the Niño 3.4 region slice only.

# define the figure size
fig = plt.figure(constrained_layout=True)

# assign axis and projection
ax = plt.axes(projection=ccrs.Robinson(central_longitude=180))

# add coastlines
ax.coastlines()

# add gridlines (lon and lat)
ax.gridlines()

# plot as above
tos_nino34.tos.isel(time=0).plot(
    ax=ax, transform=ccrs.PlateCarree(), vmin=-2, vmax=30, cmap="coolwarm"
)

# make sure we see more areas of the earth and not only the square around Niño 3.4
ax.set_extent((120, 300, 10, -10))
../../../_images/d1f2ef84d15802e042371356391d4e7034b9314524e0ba7e2789938798b8f034.png
Click here for a description of the plot A map plot zoomed into the Pacific Ocean showing the sea surface temperature (SST) in the Niño3.4 region in January 2000 ranging from -2°C to 30°C from the CESM Earth system models historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). The closer to the equator, the colder the water masses at the surface caused by upwelling from below induced by easterly winds and consequent Ekman transport.

Interactive Demo 2.2#

Below we plot an interactive version of the Niño 3.4 region. You can explore the data by zooming in with the tools from the righthand toolbar and visualize what the next few time steps look like in the model by using the interactive slider bar on the most right. Note that the color bar and the corresponding SST scale have changed to make the changing pattern more visible.

# again more complicated code that allows interactive plots
gv.extension("bokeh")  # load Bokeh
dataset_plot = gv.Dataset(
    ds_SST.where(
    (ds_SST.lat > -5) & (ds_SST.lat < 5) & (ds_SST.lon > 190) & (ds_SST.lon < 240)
).isel(time=slice(0, 10))
)  # slice only the first 10 timepoint, as it is a time consuming task
images = dataset_plot.to(gv.Image, ["longitude", "latitude"], "tos", "time")
# aesthetics
images.opts(
    cmap="coolwarm",
    colorbar=True,
    width=600,
    height=400,
    projection=ccrs.Robinson(central_longitude=180),
    clabel="Sea Surface Temperature [˚C]",
) * gf.coastline
Click here for a description of the plot An interactive map plot showing the sea surface temperature (SST) from January 2000 until October 2000 ranging from 23.5°C to 30.5°C from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). Over the annual cycle, the SST increases in the northern hemispherical summer. The closer to the equator, the colder the water masses at the surface caused by upwelling induced by easterly winds and consequent Ekman transport. The more west in the region the warmer the water masses also caused by this transport.
Click here for a description of the plot A map plot zoomed into the Pacific Ocean showing the sea surface temperature (SST) in the Niño3.4 region in January 2000 ranging from -2°C to 30°C from the CESM Earth system models historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). The closer to the equator, the colder the water masses at the surface caused by upwelling from below induced by easterly winds and consequent Ekman transport.

Interactive Demo 2.2#

Below we plot an interactive version of the Niño 3.4 region. You can explore the data by zooming in with the tools from the righthand toolbar and visualize what the next few time steps look like in the model by using the interactive slider bar on the most right. Note that the color bar and the corresponding SST scale have changed to make the changing pattern more visible.

# again more complicated code that allows interactive plots
gv.extension("bokeh")  # load Bokeh
dataset_plot = gv.Dataset(
    ds_SST.where(
    (ds_SST.lat > -5) & (ds_SST.lat < 5) & (ds_SST.lon > 190) & (ds_SST.lon < 240)
).isel(time=slice(0, 10))
)  # slice only the first 10 timepoint, as it is a time consuming task
images = dataset_plot.to(gv.Image, ["longitude", "latitude"], "tos", "time")
# aesthetics
images.opts(
    cmap="coolwarm",
    colorbar=True,
    width=600,
    height=400,
    projection=ccrs.Robinson(central_longitude=180),
    clabel="Sea Surface Temperature [˚C]",
) * gf.coastline
Click here for a description of the plot An interactive map plot showing the sea surface temperature (SST) from January 2000 until October 2000 ranging from 23.5°C to 30.5°C from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6). Over the annual cycle, the SST increases in the northern hemispherical summer. The closer to the equator, the colder the water masses at the surface caused by upwelling induced by easterly winds and consequent Ekman transport. The more west in the region the warmer the water masses also caused by this transport.

Section 2.3: Compute the Climatology and Anomalies#

Now that we have selected our area, we can compute the monthly anomaly by first grouping all the data by month, and then subtracting the monthly climatology from each month. Taking the area-weighted average of these anomalies finally results in a time series with a temporal resolution of months.

# group the dataset by month
tos_nino34_mon = tos_nino34.tos.groupby("time.month")

# find the monthly climatology in the Nino 3.4 region
tos_nino34_clim = tos_nino34_mon.mean(dim="time")

# find the monthly anomaly in the Nino 3.4 region
tos_nino34_anom = tos_nino34_mon - tos_nino34_clim

# take the area-weighted average of anomalies in the Nino 3.4 region
tos_nino34_anom_mean = tos_nino34_anom.weighted(tos_nino34.areacello).mean(
    dim=["lat", "lon"]
)
tos_nino34_anom_mean
<xarray.DataArray 'tos' (time: 180)> Size: 1kB
array([-1.09020308, -0.94682967, -0.87016883, -0.67314585, -0.5896447 ,
       -0.42163336, -0.10459058,  0.03671597,  0.10723407,  0.17852156,
        0.03699042,  0.03701826,  0.18047588,  0.13209801,  0.18591603,
        0.23601154,  0.40335284,  0.41607815,  0.56452048,  0.7156873 ,
        0.94604362,  1.54824452,  1.64511465,  1.71039094,  1.68536348,
        1.59079585,  1.06137072,  0.42683035,  0.2822014 ,  0.01182273,
       -0.5027431 , -1.3148968 , -1.34690015, -1.74364298, -2.16279025,
       -2.25649865, -2.34426802, -2.36370228, -2.04569951, -2.06573353,
       -1.83853622, -1.44441815, -0.95012919, -0.29584977,  0.02383242,
        0.3042806 ,  0.42201278,  0.49855503,  0.48539388,  0.51069795,
        0.39988392,  0.32679846,  0.06415626, -0.1690822 ,  0.07204666,
        0.55496833,  0.65673461,  0.5782174 ,  0.65645894,  0.64569521,
        0.83701729,  0.75305043,  0.68472174,  0.4662565 ,  0.27632609,
       -0.16299999, -0.66729629, -0.97958271, -1.00201322, -1.34717395,
       -1.34564212, -1.5687706 , -1.43570687, -0.91709915, -0.60461387,
       -0.44474815, -0.39675868, -0.34406607, -0.19599502, -0.22287627,
       -0.27117918, -0.64625184, -0.58092383, -0.67215061, -0.69564109,
       -0.71416741, -0.51178699, -0.60251528, -0.50095791, -0.22583468,
       -0.02674855, -0.04463507, -0.11126017,  0.14102337,  0.30948326,
        0.28171994,  0.29325418,  0.38412105,  0.42648491,  0.75224678,
        1.00070394,  1.25250363,  1.52579141,  1.6265083 ,  1.62089045,
        1.74093504,  1.82211014,  2.04950726,  2.12185863,  1.92467521,
        1.41653584,  1.11950444,  0.51565087, -0.44916467, -1.6465778 ,
       -2.1730143 , -2.60500166, -2.81257114, -2.88834864, -2.78450974,
       -2.76460869, -2.71103108, -2.78661375, -2.20402372, -2.07531217,
       -1.83626326, -1.5576376 , -1.53099869, -1.38395769, -1.43226815,
       -1.52907286, -1.55885587, -1.0503494 , -0.66684357,  0.06911011,
        0.35993642,  0.32698893,  0.49531355,  0.58532673,  0.64840051,
        0.83827151,  1.0457816 ,  1.13088582,  1.39856505,  1.74717943,
        1.74436116,  1.53452864,  1.35453206,  1.6764909 ,  2.10747711,
        2.56691607,  2.78958849,  2.36954885,  2.26843067,  2.38747457,
        2.45266712,  2.80075557,  2.3257725 ,  1.7404829 ,  1.65213993,
        1.56080468,  1.18142005,  0.4727693 ,  0.02291108, -0.19411329,
       -0.45835799, -0.61915154, -0.69644116, -0.77052288, -1.04589789,
       -0.70015282, -0.70409144, -0.70546687, -0.41115267, -0.13565224,
        0.1670741 ,  0.35186849,  0.63483207,  0.71539744,  0.46310999])
Coordinates:
  * time     (time) object 1kB 2000-01-15 12:00:00 ... 2014-12-15 12:00:00
    month    (time) int64 1kB 1 2 3 4 5 6 7 8 9 10 11 ... 3 4 5 6 7 8 9 10 11 12

Section 2.4: Smooth the Anomaly Time Series#

ENSO occurs on interannual timescales (a few years or more). To isolate the variability of this longer-term phenomenon on the Niño 3.4 region, we can smooth out the fluctuations due to variability on shorter timescales. To achieve this, we will apply a 3-month running mean to our time series of SST anomalies.

In other words, even though we have almost the same amount of values in our time series, one SST anomaly entry now also depends on its neighboring months. The neighboring entries now influence the extremity of, e.g., a peak, by reducing its height in correspondence with their difference to this fluctuation. In summary, this removes short-term deviations and highlights when the signal is sustained over a longer time.

# smooth using a centered 3 month running mean
oni_index = tos_nino34_anom_mean.rolling( time = 3, center=True ).mean()
# define the plot size
fig = plt.figure()

# assign axis
ax = plt.axes()

# plot the monhtly data on the assigned axis
tos_nino34_anom_mean.plot(ax=ax)

# plot the smoothed data on the assigned axis
oni_index.plot(ax=ax)

# add legend
ax.legend(["monthly", "3-month running mean"])

# add ylabel
ax.set_ylabel("Sea Surface Temperature Anomalies (°C)")

# add xlabel
ax.set_xlabel("Time (years)")
Text(0.5, 0, 'Time (years)')
../../../_images/6293d2c093a3f497aab36cc4bbed7758e2f48e295a9d517180c2be32ad328884.png
Click here for a description of the plot Time series of the sea surface temperature anomalies before smoothing (blue) and after smoothing via the rolling mean over 3 months (orange). A few peaks exceed the $\pm$0.5 threshold for at least five consecutive months which is operationally used by NOAA to classify El Niño or La Niña. Data is from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6).

Section 3: Identify El Niño and La Niña Events#

We will highlight values in excess of \(\pm\)0.5, roughly corresponding to El Niño (warm) and La Niña (cold) events.

fig = plt.figure()

plt.fill_between(  # plot with color in between
    oni_index.time.data,  # x values
    # top boundary - y values above or equal 0.5
    oni_index.where(oni_index >= 0.5).data,
    0.5,            # bottom boundary - 0.5
    color = "red",  # color
    alpha = 0.9,    # transparency value
)
plt.fill_between(
    oni_index.time.data,
    oni_index.where(oni_index <= -0.5).data,
    -0.5,
    color = "blue",
    alpha = 0.9,
)

oni_index.plot(color="black")          # plot the smoothed data
plt.axhline(0, color="black", lw = 0.5)  # add a black line at x=0
plt.axhline(
    0.5, color="black", linewidth = 0.5, linestyle="dotted"
)  # add a black line at x = 0.5
plt.axhline(
    -0.5, color="black", linewidth = 0.5, linestyle="dotted"
)  # add a black line at x = -0.5

# aesthetics
plt.title("Oceanic Niño Index (ONI)")
plt.xlabel('Time (years)')
plt.ylabel("Sea Surface Temperature Anomalies (°C)")
Text(0, 0.5, 'Sea Surface Temperature Anomalies (°C)')
../../../_images/779263ee9fc4163a143267399e300595f9bff2a45341a7e3a2500229916d2c8f.png
Click here for a description of the plot Time series of the 3-month averaged sea surface temperature anomalies with highlighted threshold areas, exceeding +0.5 in red and -0.5 in blue, respectively. A few peaks exceed the $\pm$0.5 threshold for at least five consecutive months which is operationally used by NOAA to classify El Niño or La Niña. Data is from the CESM Earth system model's historical simulation for the Sixth Phase of the Coupled Intercomparison Project (CMIP6).

Questions 3:#

Now that we’ve normalized the data and highlighted SST anomalies that correspond to El Niño (warm) and La Niña (cold) events, consider the following questions:

  1. How frequently do El Niño and La Niña events occur over the period of time studied here?

  2. When were the strongest El Niño and La Niña events over this time period?

  3. Considering the ocean-atmosphere interactions that cause El Niño and La Niña events, can you hypothesize potential reasons one El Niño or La Niña event may be stronger than others?

Click for solution

Summary#

In this tutorial, we have learned to utilize a variety of Xarray tools to examine variations in SST during El Niño and La Niña events. We’ve practiced loading SST data from the CESM2 model, and masking data using the .where() function for focused analysis. We have also computed climatologies and anomalies using the .groupby() function, and learned to compute moving averages using the .rolling() function. Finally, we have calculated, normalized, and plotted the Oceanic Niño Index (ONI), enhancing our understanding of the El Niño Southern Oscillation (ENSO) and its impacts on global climate patterns.

Resources#

Data from this tutorial can be accessed here.