{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Finding Climate Modes with EOFs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "In this notebook, we will identify and plot a few different modes of climate variability with the help of an EOF package that interfaces with Xarray called [`xeofs`](https://github.com/nicrie/xeofs)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites\n", "\n", "| Concepts | Importance | Notes |\n", "| --- | --- | --- |\n", "| [Intro to Xarray](https://foundations.projectpythia.org/core/xarray/xarray-intro.html) | Necessary | |\n", "| [Intro to EOFs](eof-intro) | Helpful | |\n", "\n", "- **Time to learn**: 30 minutes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import xarray as xr\n", "import matplotlib.pyplot as plt\n", "import matplotlib.path as mpath\n", "from matplotlib.colors import CenteredNorm\n", "from scipy import stats, signal\n", "from cartopy import crs as ccrs, feature as cfeature\n", "from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter\n", "import xeofs as xe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Accessing and preparing the data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will use the [NOAA Extended Reconstructed Sea Surface Temperature version 5 (ERSSTv5)](https://www.psl.noaa.gov/data/gridded/data.noaa.oisst.v2.html) monthly gridded dataset {cite:p}`Huang:2017a`, which is accessible using [OPeNDAP](https://www.opendap.org/). More information on [using OPeNDAP to access NOAA data can be found here](https://psl.noaa.gov/data/help/using_opendap.html)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data_url = 'https://psl.noaa.gov/thredds/dodsC/Datasets/noaa.ersst.v5/sst.mnmean.nc'" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'sst' (time: 2045, lat: 89, lon: 180)> Size: 131MB\n", "[32760900 values with dtype=float32]\n", "Coordinates:\n", " * lat (lat) float32 356B 88.0 86.0 84.0 82.0 ... -82.0 -84.0 -86.0 -88.0\n", " * lon (lon) float32 720B 0.0 2.0 4.0 6.0 8.0 ... 352.0 354.0 356.0 358.0\n", " * time (time) datetime64[ns] 16kB 1854-01-01 1854-02-01 ... 2024-05-01\n", "Attributes:\n", " long_name: Monthly Means of Sea Surface Temperature\n", " units: degC\n", " var_desc: Sea Surface Temperature\n", " level_desc: Surface\n", " statistic: Mean\n", " dataset: NOAA Extended Reconstructed SST V5\n", " parent_stat: Individual Values\n", " actual_range: [-1.8 42.32636]\n", " valid_range: [-1.8 45. ]\n", " _ChunkSizes: [ 1 89 180]
<xarray.DataArray 'explained_variance_ratio' (mode: 4)> Size: 32B\n", "array([0.82575411, 0.03647744, 0.02654952, 0.01653281])\n", "Coordinates:\n", " * mode (mode) int64 32B 1 2 3 4\n", "Attributes: (12/16)\n", " model: EOF analysis\n", " software: xeofs\n", " version: 2.3.2\n", " date: 2024-06-07 15:13:21\n", " n_modes: 4\n", " center: True\n", " ... ...\n", " feature_name: feature\n", " random_state: None\n", " verbose: False\n", " compute: True\n", " solver: auto\n", " solver_kwargs: {}
<xarray.DataArray 'explained_variance_ratio' (mode: 4)> Size: 32B\n", "array([0.12226184, 0.04733037, 0.034539 , 0.03201537])\n", "Coordinates:\n", " * mode (mode) int64 32B 1 2 3 4\n", "Attributes: (12/16)\n", " model: EOF analysis\n", " software: xeofs\n", " version: 2.3.2\n", " date: 2024-06-07 15:14:36\n", " n_modes: 4\n", " center: True\n", " ... ...\n", " feature_name: feature\n", " random_state: None\n", " verbose: False\n", " compute: True\n", " solver: auto\n", " solver_kwargs: {}
<xarray.DataArray 'explained_variance_ratio' (mode: 4)> Size: 32B\n", "array([0.32955431, 0.08712222, 0.05315635, 0.04717559])\n", "Coordinates:\n", " * mode (mode) int64 32B 1 2 3 4\n", "Attributes: (12/16)\n", " model: EOF analysis\n", " software: xeofs\n", " version: 2.3.2\n", " date: 2024-06-07 15:14:39\n", " n_modes: 4\n", " center: True\n", " ... ...\n", " feature_name: feature\n", " random_state: None\n", " verbose: False\n", " compute: True\n", " solver: auto\n", " solver_kwargs: {}
<xarray.DataArray 'explained_variance_ratio' (mode: 4)> Size: 32B\n", "array([0.17464065, 0.11074887, 0.072165 , 0.06702556])\n", "Coordinates:\n", " * mode (mode) int64 32B 1 2 3 4\n", "Attributes: (12/16)\n", " model: EOF analysis\n", " software: xeofs\n", " version: 2.3.2\n", " date: 2024-06-07 15:14:57\n", " n_modes: 4\n", " center: True\n", " ... ...\n", " feature_name: feature\n", " random_state: None\n", " verbose: False\n", " compute: True\n", " solver: auto\n", " solver_kwargs: {}