Assignment: More Xarray with El Niño-Southern Oscillation (ENSO) Data

Here will will calculate the NINO 3.4 index of El Nino variabillity and use it to analyze datasets.

First read this page from NOAA. It tells you the following:

  • The Niño 3.4 region is defined as the region between +/- 5 deg. lat, 170 W - 120 W lon.

  • Warm or cold phases of the Oceanic Niño Index are defined by a five consecutive 3-month running mean of sea surface temperature (SST) anomalies in the Niño 3.4 region that is above the threshold of +0.5°C (warm), or below the threshold of -0.5°C (cold). This is known as the Oceanic Niño Index (ONI).

(Note that “anomaly” means that the seasonal cycle, also called the “climatology” has been removed.)

Start by importing Numpy, Matplotlib, and Xarray. Set the default figure size to (12, 6).

1. Reproduce the SST curve from the figure below

Use the file that we worked with in class, located at

You don’t have to match the stylistic details, or use different colors above and below zero, just the “3mth running mean” curve.


Load the data as an Xarray dataset. Drop the time_bnds variable as we did in class and trim the data to 1950 onward for this assignment.

Now calculate the climatology and the SST anomaly.

Now reproduce the plot. Keep the rolling 3-month average of the SST anomaly as a DataArray for the next question.

2. Calculate boolean timeseries representing the positive / negative ENSO phases

Refer to the definitions of warm/cold phases above.

Plot them somehow.

3. Plot composites of SST anomaly for the positive and negative ENSO regimes

These should be pcolormesh maps. First positive ONI.

And negative ONI.

4. Calculate the composite of preciptiation for positive and negative ENSO phases.

First load the precip dataset. Code to fix the broken time coordinate is included.

import pandas as pd
import xarray as xr
url = ''
dsp = xr.open_dataset(url, decode_times=False)
true_time = (pd.date_range(start='1960-01-01', periods=len(dsp['T']), freq='MS'))
dsp['T'] = true_time
dsp = dsp.rename({'T': 'time'})
Dimensions:  (X: 144, Y: 72, time: 362)
  * X        (X) float32 1.25 3.75 6.25 8.75 ... 351.25 353.75 356.25 358.75
  * time     (time) datetime64[ns] 1960-01-01 1960-02-01 ... 1990-02-01
  * Y        (Y) float32 88.75 86.25 83.75 81.25 ... -81.25 -83.75 -86.25 -88.75
Data variables:
    prcp     (time, Y, X) float32 nan nan nan ... 0.023939257 0.024468819
    Conventions:  IRIDL

Now plot the difference between the time-mean of prcp during positive and negative ENSO phases.