{ "cells": [ { "cell_type": "markdown", "metadata": { "execution": {} }, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ClimateMatchAcademy/course-content/blob/main/projects/project-notebooks/ENSO_impact_on_precipitation_and_temperature.ipynb)   \"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "avjFjFXwWqyW" }, "source": [ "# **The Impact of ENSO on Precipitation and Temperature**\n", "\n", "**Content creators:** Olawale Ikuyajolu & Patrick Orenstein\n", "\n", "**Content reviewers:** Marguerite Brown, Yuxin Zhou\n", "\n", "**Content editors:** Zane Mitrevica, Natalie Steinemann, Jenna Pearson, Chi Zhang, Ohad Zivan\n", "\n", "**Production editors:** Wesley Banfield, Jenna Pearson, Chi Zhang, Ohad Zivan\n", "\n", "**Our 2023 Sponsors:** NASA TOPS, Google DeepMind, and CMIP" ] }, { "cell_type": "markdown", "metadata": { "id": "DZbqRlQKXhnc" }, "source": [ "**In this project** you will work with climate model output, reanalysis data, and Niño 3.4 indices from CMIP5/6, ERA5, NOAA, and HadISST to understand the historical and future impacts of El Niño Southern Oscillation (ENSO) events on rainfall and temperature. You will focus on variables like sea surface temperature, surface air temperature, and precipitation. You will also be able to investigate the relationships between these variables and how they affect community efforts to prepare for the impacts of El Niño phases.\n", "\n", "Recall from W1D1 that ENSO is a climate phenomena that originates in the tropical Pacific ocean but has global impacts on atmospheric circulation, temperature and precipitation. The two phases of ENSO are El Niño (warmer than average SSTs in the central and eastern tropical Pacific Ocean) and La Niña (cooler than average SSTs in the central and eastern tropical Pacific Ocean). The Niño 3.4 region is an area in the central and eastern Pacific Ocean that is often used for determining the phase of ENSO.\n", "\n", "You may also reference W1D5, W2D1, and W2D4 tutorials on CMIP6 and read more about the different CMIP6 scenarios [here](https://www.dkrz.de/en/communication/climate-simulations/cmip6-en/the-ssp-scenarios). Please see the Resources section at the bottom of this notebook for more information.\n" ] }, { "cell_type": "markdown", "metadata": { "id": "XfKMYIRrudl9" }, "source": [ "# Project Template\n", "\n", "![Project Template](https://raw.githubusercontent.com/ClimateMatchAcademy/course-content/main/projects/template-images/ENSO_template_map.svg)\n", "\n", "*Note: The dashed boxes are socio-economic questions.*" ] }, { "cell_type": "markdown", "metadata": { "id": "-uS_n9-3YJrZ" }, "source": [ "# Data Exploration Notebook\n", "## Project Setup" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 675 }, "executionInfo": { "elapsed": 4174, "status": "error", "timestamp": 1685417505725, "user": { "displayName": "Natalie Steinemann", "userId": "07104505925817819178" }, "user_tz": 240 }, "id": "9nDg6MeVY1CX", "outputId": "5f15997d-3064-4f72-9446-8a99c2ab2f74", "tags": [ "colab" ] }, "outputs": [], "source": [ "# google colab installs\n", "\n", "# !pip install condacolab &> /dev/null\n", "# import condacolab\n", "# condacolab.install()\n", "\n", "# install all packages in one call (+ use mamba instead of conda)\n", "# !mamba install xarray-datatree intake-esm gcsfs xmip aiohttp cartopy nc-time-axis cf_xarray xarrayutils \"esmf<=8.3.1\" xesmf &> /dev/null" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# imports\n", "\n", "import time\n", "\n", "tic = time.time()\n", "\n", "import intake\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import xarray as xr\n", "import xesmf as xe\n", "from xmip.preprocessing import combined_preprocessing\n", "from xarrayutils.plotting import shaded_line_plot\n", "from datatree import DataTree\n", "from xmip.postprocessing import _parse_metric\n", "import cartopy.crs as ccrs\n", "import pooch\n", "import os\n", "import tempfile" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "WJLrmNkvC8YW", "tags": [] }, "outputs": [], "source": [ "# functions\n", "\n", "%matplotlib inline\n", "\n", "col = intake.open_esm_datastore(\n", " \"https://storage.googleapis.com/cmip6/pangeo-cmip6.json\"\n", ") # open an intake catalog containing the Pangeo CMIP cloud data\n", "\n", "\n", "def load_cmip6(source_id, variable_id, member_id, table_id): # load selected model\n", " cat = col.search(\n", " source_id=source_ids,\n", " variable_id=variable_id,\n", " member_id=member_id,\n", " table_id=table_id,\n", " grid_label=\"gn\",\n", " experiment_id=[\n", " \"historical\",\n", " \"ssp126\",\n", " \"ssp245\",\n", " \"ssp585\",\n", " ], # downloading the scenarios out of the total 5+historical\n", " require_all_on=[\"source_id\"],\n", " )\n", "\n", " kwargs = dict(\n", " preprocess=combined_preprocessing,\n", " xarray_open_kwargs=dict(use_cftime=True),\n", " storage_options={\"token\": \"anon\"},\n", " )\n", " cat.esmcat.aggregation_control.groupby_attrs = [\"source_id\", \"experiment_id\"]\n", " dt = cat.to_datatree(**kwargs)\n", "\n", " return dt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# helper functions\n", "\n", "def pooch_load(filelocation=None,filename=None,processor=None):\n", " shared_location='/home/jovyan/shared/Data/Projects/ENSO' # this is different for each day\n", " user_temp_cache=tempfile.gettempdir()\n", " \n", " if os.path.exists(os.path.join(shared_location,filename)):\n", " file = os.path.join(shared_location,filename)\n", " else:\n", " file = pooch.retrieve(filelocation,known_hash=None,fname=os.path.join(user_temp_cache,filename),processor=processor)\n", "\n", " return file" ] }, { "cell_type": "markdown", "metadata": { "id": "iYblWn8cZAGT" }, "source": [ "## Dataset 1: Load CMIP6 Model of Your Choice\n", "\n", "Following W2D1 (Week 2 Day 1) tutorial notebooks:\n", "\n", " * We use the *CESM2* model (*source_id*) and ensemble member *r4i1p1f1* (*member_id*) in this template, but you are free to select any model and ensemble member. Make sure the *member_id* selected is available for your model. You can learn more about the *member_id* and other CMIP6 facets through the links at the end of the [CMIP Resource Bank](https://github.com/ClimateMatchAcademy/course-content/blob/main/tutorials/CMIP/CMIP_resource_bank.md)\n", " \n", " * `load_cmip6` function load both historical and ssp585 (future: climate change)\n", " \n", "To learn more about CMIP, including additional ways to access CMIP data, please see our [CMIP Resource Bank](https://github.com/ClimateMatchAcademy/course-content/blob/main/tutorials/CMIP/CMIP_resource_bank.md) and the [CMIP website](https://wcrp-cmip.org/). \n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 238 }, "executionInfo": { "elapsed": 4571, "status": "ok", "timestamp": 1683591426696, "user": { "displayName": "Natalie Steinemann", "userId": "07104505925817819178" }, "user_tz": 240 }, "id": "L0flXmexD8V1", "outputId": "58ee3e7b-34b9-408b-e733-11462b31786f", "tags": [] }, "outputs": [], "source": [ "# pick your model\n", "\n", "source_ids = \"CESM2\"\n", "\n", "dm_tas = load_cmip6(\n", " source_ids, \"tas\", \"r4i1p1f1\", \"Amon\"\n", ") # tas is atmoerhpere temprature\n", "dm_pr = load_cmip6(source_ids, \"pr\", \"r4i1p1f1\", \"Amon\") # pr is precipitation rate\n", "dm_sst = load_cmip6(\n", " source_ids, \"tos\", \"r4i1p1f1\", \"Omon\"\n", ") # tos is surface ocean temprature\n", "print(\n", " dm_tas.keys()\n", ") # an example for one of the datatrees, you can duplicate this for the other DT" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# load cell areas for computing ocean surface temparuters means\n", "\n", "dt_ocean_area = load_cmip6(source_ids, \"areacello\", \"r4i1p1f1\", \"Ofx\")\n", "dt_atmos_area = load_cmip6(source_ids, \"areacella\", \"r4i1p1f1\", \"fx\")\n", "\n", "dt_ocean_with_area = DataTree()\n", "dt_atmos_with_area = DataTree()\n", "\n", "for model, subtree in dm_sst.items():\n", " metric_ocean = dt_ocean_area[model][\"historical\"].ds[\"areacello\"]\n", " dt_ocean_with_area[model] = subtree.map_over_subtree(_parse_metric, metric_ocean)\n", "\n", "for model, subtree in dm_pr.items():\n", " metric_atmos = dt_atmos_area[model][\"historical\"].ds[\"areacella\"]\n", " dt_atmos_with_area[model] = subtree.map_over_subtree(_parse_metric, metric_atmos)\n", "\n", "print(dt_ocean_with_area.keys())" ] }, { "cell_type": "markdown", "metadata": { "id": "W43m6TQBZrpe" }, "source": [ "## Dataset 2: Load Observations\n", "\n", "We use the NOAA Extended Reconstructed Sea Surface Temperature (ERSST) v5 product, a widely used and trusted gridded compilation of historical data going back to 1854. Since the data is provided via an OPeNDAP server, we can load it directly without downloading anything.\n", "\n", "For precipitation, we are using CPC Merged Analysis of Precipitation (CMAP). We can download this dataset from the NOAA PSL, Boulder, Colorado, USA website at https://psl.noaa.gov\n", "\n", "For air temperature, we are using anomalies from NASA GISS Surface Temperature Analysis which we can also download from NOAA PSL, Boulder, Colorado, USA website at https://psl.noaa.gov" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 6590, "status": "ok", "timestamp": 1683591495321, "user": { "displayName": "Natalie Steinemann", "userId": "07104505925817819178" }, "user_tz": 240 }, "id": "drh-swqCsb9k", "outputId": "287ef7e3-cdba-4156-a928-0c4a970e1b1d", "tags": [] }, "outputs": [], "source": [ "# Ocean surface temprature \n", "filename_SST='sst.mnmean.nc'\n", "url_SST = 'https://downloads.psl.noaa.gov/Datasets/noaa.ersst.v5/sst.mnmean.nc'\n", "\n", "do_sst = xr.open_dataset(pooch_load(url_SST,filename_SST), drop_variables=['time_bnds'])\n", "\n", "# Precipitation rate (notice the units in the plot below)\n", "filename_prec_rate='precip.mon.mean.nc'\n", "url_prec_rate='https://downloads.psl.noaa.gov/Datasets/cmap/enh/precip.mon.mean.nc'\n", "do_pr = xr.open_dataset(pooch_load(url_prec_rate,filename_prec_rate))\n", "\n", "# Air Temperature Anomalies\n", "filename_tas='air.2x2.1200.mon.anom.comb.nc'\n", "url_tas='https://downloads.psl.noaa.gov/Datasets/gistemp/combined/1200km/air.2x2.1200.mon.anom.comb.nc'\n", "do_tas = xr.open_dataset(pooch_load(url_tas,filename_tas))\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "9UbbKMMQbI0C" }, "source": [ "We can now visualize the content of the dataset.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 535 }, "executionInfo": { "elapsed": 12662, "status": "ok", "timestamp": 1683591527629, "user": { "displayName": "Natalie Steinemann", "userId": "07104505925817819178" }, "user_tz": 240 }, "id": "BlAQNu898z5s", "outputId": "33077141-2735-44c1-b7b1-fb12c38abf2f", "tags": [] }, "outputs": [], "source": [ "# code to print the shape, array names, etc of the dataset\n", "\n", "# select just a single model and experiment\n", "hist_precip = dm_pr[\"CESM2\"][\"historical\"].ds.pr\n", "\n", "fig, ax_july2000 = plt.subplots(\n", " ncols=1, nrows=1, figsize=[12, 6], subplot_kw={\"projection\": ccrs.Robinson()}\n", ")\n", "\n", "hist_precip.sel(time=\"2000-07\").squeeze().plot(\n", " ax=ax_july2000,\n", " x=\"lon\",\n", " y=\"lat\",\n", " transform=ccrs.PlateCarree(),\n", " cmap=\"magma\",\n", " robust=True,\n", ")\n", "\n", "ax_july2000.coastlines()\n", "ax_july2000.set_title(\"July 2000\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 498 }, "executionInfo": { "elapsed": 3227037, "status": "ok", "timestamp": 1683594776518, "user": { "displayName": "Natalie Steinemann", "userId": "07104505925817819178" }, "user_tz": 240 }, "id": "pnM2BKLbUX1Y", "outputId": "78b474f9-a78a-47a2-cbde-f2c3ddcb4d28", "tags": [] }, "outputs": [], "source": [ "hist_sst = dm_sst[\"CESM2\"][\"historical\"].ds.tos\n", "\n", "fig, ax = plt.subplots(\n", " ncols=1,\n", " nrows=1,\n", " figsize=[12, 6],\n", " subplot_kw={\"projection\": ccrs.Robinson(central_longitude=180)},\n", ")\n", "\n", "ax.coastlines()\n", "ax.gridlines()\n", "hist_sst.sel(time=\"2000-07\").squeeze().plot(\n", " ax=ax,\n", " x=\"lon\",\n", " y=\"lat\",\n", " transform=ccrs.PlateCarree(),\n", " vmin=-2,\n", " vmax=30,\n", " cmap=\"magma\",\n", " robust=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "WB1Y9Sls74DO" }, "source": [ "## Dataset 3: Oceanic Nino Index\n", "\n", "There are several indices used to identify ENSO in the tropical Pacific Ocean. These indices are based on SST anomalies averaged across a given region and are used to define El Niño and La Niña events. Two indices that you will explore in this project are the Nino 3.4 Index and the Oceanic Niño Index (ONI). Both of these indices are averaged over the same region in the tropical Pacific (5N-5S, 170W-120W), but use different running means and criteria for identifying El Niño and La Niña events (i.e. for ONI, SST anomalies must exceed +/- 0.5C for at least five consecutive months to be defined as an ENSO event, whereas for Nino 3.4, SST anomalies must exceed +/- 0.4C for at least six consecutive months). You can find additional information about these indices [here](https://climatedataguide.ucar.edu/climate-data/nino-sst-indices-nino-12-3-34-4-oni-and-tni). For now, we will download the ONI data that we used in W1D3." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "cL9IYv3oTtt5", "tags": [] }, "outputs": [], "source": [ "# get El Nino data from W1D3 tutorial 7\n", "filename_nino='t6_oceanic-nino-index.nc'\n", "url_nino = \"https://osf.io/8rwxb/download/\"\n", "oni = xr.open_dataset(pooch_load(url_nino,filename_nino))\n", "print(oni.keys())\n" ] }, { "cell_type": "markdown", "metadata": { "id": "tRLz4CMRFPD8" }, "source": [ "# Further Reading\n", "\n", "- \"El Niño & La Niña (El Niño-Southern Oscillation)\", NOAA/Climate.gov (https://www.climate.gov/enso)\n", "- \"El Niño and La Niña\", OCHA (https://www.unocha.org/themes/el-ni%C3%B1o/el-ni%C3%B1o-and-la-ni%C3%B1a)\n", "- \"How will climate change change El Nino and La Nina?\", NOAA, 2020 (https://research.noaa.gov/2020/11/09/new-research-volume-explores-future-of-enso-under-influence-of-climate-change/)\n", "- L'Heureux, M., Karamperidou, C., DiNezio, P., Karnauskas, K., Anyamba, A. 2023. \"El Niño and La Niña: Local and global effects\". Climate Central (https://www.climatecentral.org/climate-matters/local-and-global-effects-of-el-nino-and-la-nina-2023)\n", "- Kelly, M. 2023. \"In Years After El Niño, Global Economy Loses Trillions\" (https://home.dartmouth.edu/news/2023/05/years-after-el-nino-global-economy-loses-trillions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# **Resources**\n", "\n", "This tutorial uses data from the simulations conducted as part of the [CMIP6](https://wcrp-cmip.org/) multi-model ensemble. \n", "\n", "For examples on how to access and analyze data, please visit the [Pangeo Cloud CMIP6 Gallery](https://gallery.pangeo.io/repos/pangeo-gallery/cmip6/index.html) \n", "\n", "For more information on what CMIP is and how to access the data, please see this [page](https://github.com/ClimateMatchAcademy/course-content/blob/main/tutorials/CMIP/CMIP_resource_bank.md)." ] } ], "metadata": { "colab": { "provenance": [], "toc_visible": true }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 4 }