{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b33d27cb-878c-4f98-93e5-3eee28e71c9b",
   "metadata": {},
   "source": [
    "# Loading, processing, and visualizing data\n",
    "\n",
    "This notebook shows how to load a dataset, use the preprocessor functions, and visualize the result. In this notebook we will plot the annual mean temperature from 1850 till 2100 from one model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "13fef9db-3809-4d18-9097-f5f2ff43f3de",
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import iris.quickplot\n",
    "\n",
    "from esmvalcore.config import CFG\n",
    "from esmvalcore.dataset import Dataset\n",
    "from esmvalcore.esgf import download, ESGFFile\n",
    "from esmvalcore.preprocessor import area_statistics, annual_statistics"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ae60756-f808-4972-9baf-b9827dd6e874",
   "metadata": {},
   "source": [
    "Configure ESMValCore so it searches the ESGF for data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c53e31ac-7cf4-4397-b9aa-d860b7f4909e",
   "metadata": {},
   "outputs": [],
   "source": [
    "CFG['search_esgf'] = 'when_missing'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90ac9a7b-2683-41c9-bd8f-9f828ac7efac",
   "metadata": {},
   "source": [
    "Define the dataset we are going to use. In this case surface air temperature (`tas`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1c540dff-6fcb-4b74-8690-8893d9f19b94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dataset:\n",
       "{'dataset': 'MPI-ESM-MR',\n",
       " 'project': 'CMIP5',\n",
       " 'mip': 'Amon',\n",
       " 'short_name': 'tas',\n",
       " 'ensemble': 'r1i1p1',\n",
       " 'exp': 'historical',\n",
       " 'timerange': '1850/2000'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tas = Dataset(\n",
    "    short_name='tas',\n",
    "    mip='Amon',\n",
    "    project='CMIP5',\n",
    "    dataset='MPI-ESM-MR',\n",
    "    ensemble='r1i1p1',\n",
    "    exp='historical',\n",
    "    timerange='1850/2000',\n",
    ")\n",
    "tas"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23ba6512-9769-44ca-a2a4-b9f79555a9a5",
   "metadata": {},
   "source": [
    "In order to compute the area average later on, we add the cell areas (`areacella`) as a supplementary dataset. This will append a new dataset to the list of supplementary datasets. Its facets are copied from the `tas` dataset and updated with the provided facets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c30418f2-d725-4708-8d28-7ac48c6a9863",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Dataset:\n",
       " {'dataset': 'MPI-ESM-MR',\n",
       "  'project': 'CMIP5',\n",
       "  'mip': 'fx',\n",
       "  'short_name': 'areacella',\n",
       "  'ensemble': 'r0i0p0',\n",
       "  'exp': 'historical',\n",
       "  'timerange': '1850/2000'}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tas.add_supplementary(short_name='areacella', mip='fx', ensemble='r0i0p0')\n",
    "tas.supplementaries"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a33ae420-326c-4570-8741-e447b160c9e2",
   "metadata": {},
   "source": [
    "ESMValCore can automatically add extra facets based on the `project`, `mip`, `short_name`, and `dataset`. These extra facets are automatically added and used when searching for input files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e761c044-a695-4bb3-8fdd-0041f83a4ff9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dataset:\n",
       "{'dataset': 'MPI-ESM-MR',\n",
       " 'project': 'CMIP5',\n",
       " 'mip': 'Amon',\n",
       " 'short_name': 'tas',\n",
       " 'ensemble': 'r1i1p1',\n",
       " 'exp': 'historical',\n",
       " 'frequency': 'mon',\n",
       " 'institute': ['MPI-M'],\n",
       " 'long_name': 'Near-Surface Air Temperature',\n",
       " 'modeling_realm': ['atmos'],\n",
       " 'original_short_name': 'tas',\n",
       " 'product': ['output1', 'output2'],\n",
       " 'standard_name': 'air_temperature',\n",
       " 'timerange': '1850/2000',\n",
       " 'units': 'K'}\n",
       "supplementaries:\n",
       "  {'dataset': 'MPI-ESM-MR',\n",
       "   'project': 'CMIP5',\n",
       "   'mip': 'fx',\n",
       "   'short_name': 'areacella',\n",
       "   'ensemble': 'r0i0p0',\n",
       "   'exp': 'historical',\n",
       "   'frequency': 'fx',\n",
       "   'institute': ['MPI-M'],\n",
       "   'long_name': 'Atmosphere Grid-Cell Area',\n",
       "   'modeling_realm': ['atmos', 'land'],\n",
       "   'original_short_name': 'areacella',\n",
       "   'product': ['output1', 'output2'],\n",
       "   'standard_name': 'cell_area',\n",
       "   'units': 'm2'}\n",
       "session: 'session-686367c0-001c-4864-839d-c20887cf7415_20230301_160531'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tas.augment_facets()\n",
    "tas"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1bc53a1-3977-4a22-801c-647cc7087c69",
   "metadata": {},
   "source": [
    "Use the `find_files` method to find the files corresponding to the dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6235e9f6-8ab6-4a30-b521-cb85c04daf36",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ESGFFile:cmip5/output1/MPI-M/MPI-ESM-MR/historical/mon/atmos/Amon/r1i1p1/v20120503/tas_Amon_MPI-ESM-MR_historical_r1i1p1_185001-200512.nc on hosts ['aims3.llnl.gov', 'esgf.ceda.ac.uk', 'esgf.nci.org.au', 'esgf1.dkrz.de']]\n",
      "[ESGFFile:cmip5/output1/MPI-M/MPI-ESM-MR/historical/fx/atmos/fx/r0i0p0/v20120503/areacella_fx_MPI-ESM-MR_historical_r0i0p0.nc on hosts ['aims3.llnl.gov', 'esgf.ceda.ac.uk', 'esgf.nci.org.au', 'esgf1.dkrz.de']]\n"
     ]
    }
   ],
   "source": [
    "tas.find_files()\n",
    "print(tas.files)\n",
    "for supplementary_ds in tas.supplementaries:\n",
    "    print(supplementary_ds.files)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60272c2a-c58d-464f-808d-96d95a9a150e",
   "metadata": {},
   "source": [
    "If the files are not available locally, ESMValCore can download them for us."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "886a38f4-9e37-438e-af75-e8735ee7481d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[LocalFile('~/climate_data/cmip5/output1/MPI-M/MPI-ESM-MR/historical/mon/atmos/Amon/r1i1p1/v20120503/tas_Amon_MPI-ESM-MR_historical_r1i1p1_185001-200512.nc')]\n",
      "[LocalFile('~/climate_data/cmip5/output1/MPI-M/MPI-ESM-MR/historical/fx/atmos/fx/r0i0p0/v20120503/areacella_fx_MPI-ESM-MR_historical_r0i0p0.nc')]\n"
     ]
    }
   ],
   "source": [
    "files = list(tas.files)\n",
    "for supplementary_ds in tas.supplementaries:\n",
    "    files.extend(supplementary_ds.files)\n",
    "files = [file for file in files if isinstance(file, ESGFFile)]\n",
    "download(files, CFG['download_dir'])\n",
    "tas.find_files()\n",
    "print(tas.files)\n",
    "for supplementary_ds in tas.supplementaries:\n",
    "    print(supplementary_ds.files)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6916630-00d5-4043-b594-5df0f4142a9e",
   "metadata": {},
   "source": [
    "The data in the files can be loaded into an [iris.cube.Cube](https://scitools-iris.readthedocs.io/en/latest/generated/api/iris/cube.html#iris.cube.Cube). ESMValCore will automatically check for and fix problems with the data formatting and attach the cell area."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a5dfd5dd-e3ff-4443-a745-ad130a1bb52c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  a.iris {\n",
       "      text-decoration: none !important;\n",
       "  }\n",
       "  table.iris {\n",
       "      white-space: pre;\n",
       "      border: 1px solid;\n",
       "      border-color: #9c9c9c;\n",
       "      font-family: monaco, monospace;\n",
       "  }\n",
       "  th.iris {\n",
       "      background: #303f3f;\n",
       "      color: #e0e0e0;\n",
       "      border-left: 1px solid;\n",
       "      border-color: #9c9c9c;\n",
       "      font-size: 1.05em;\n",
       "      min-width: 50px;\n",
       "      max-width: 125px;\n",
       "  }\n",
       "  tr.iris :first-child {\n",
       "      border-right: 1px solid #9c9c9c !important;\n",
       "  }\n",
       "  td.iris-title {\n",
       "      background: #d5dcdf;\n",
       "      border-top: 1px solid #9c9c9c;\n",
       "      font-weight: bold;\n",
       "  }\n",
       "  .iris-word-cell {\n",
       "      text-align: left !important;\n",
       "      white-space: pre;\n",
       "  }\n",
       "  .iris-subheading-cell {\n",
       "      padding-left: 2em !important;\n",
       "  }\n",
       "  .iris-inclusion-cell {\n",
       "      padding-right: 1em !important;\n",
       "  }\n",
       "  .iris-panel-body {\n",
       "      padding-top: 0px;\n",
       "  }\n",
       "  .iris-panel-title {\n",
       "      padding-left: 3em;\n",
       "  }\n",
       "  .iris-panel-title {\n",
       "      margin-top: 7px;\n",
       "  }\n",
       "</style>\n",
       "<table class=\"iris\" id=\"140733605244992\">\n",
       "    <tr class=\"iris\">\n",
       "<th class=\"iris iris-word-cell\">Air Temperature (K)</th>\n",
       "<th class=\"iris iris-word-cell\">time</th>\n",
       "<th class=\"iris iris-word-cell\">latitude</th>\n",
       "<th class=\"iris iris-word-cell\">longitude</th>\n",
       "</tr>\n",
       "    <tr class=\"iris\">\n",
       "<td class=\"iris-word-cell iris-subheading-cell\">Shape</td>\n",
       "<td class=\"iris iris-inclusion-cell\">1812</td>\n",
       "<td class=\"iris iris-inclusion-cell\">96</td>\n",
       "<td class=\"iris iris-inclusion-cell\">192</td>\n",
       "</tr>\n",
       "    <tr class=\"iris\">\n",
       "    <td class=\"iris-title iris-word-cell\">Dimension coordinates</td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\ttime</td>\n",
       "    <td class=\"iris-inclusion-cell\">x</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tlatitude</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "    <td class=\"iris-inclusion-cell\">x</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tlongitude</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "    <td class=\"iris-inclusion-cell\">x</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-title iris-word-cell\">Cell measures</td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tcell_area</td>\n",
       "    <td class=\"iris-inclusion-cell\">-</td>\n",
       "    <td class=\"iris-inclusion-cell\">x</td>\n",
       "    <td class=\"iris-inclusion-cell\">x</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-title iris-word-cell\">Scalar coordinates</td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\theight</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">2.0 m</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-title iris-word-cell\">Cell methods</td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tmean</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">time</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-title iris-word-cell\">Attributes</td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "    <td class=\"iris-title\"></td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tConventions</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;CF-1.4&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tassociated_files</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;baseURL: http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile: gridspec_atmos_fx_MPI-ESM-MR_historical_r0i0p0.nc ...&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tbranch_time</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">0.0</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tcmor_version</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;2.6.0&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tcontact</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;cmip5-mpi-esm@dkrz.de&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\texperiment</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;historical&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\texperiment_id</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;historical&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tforcing</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;GHG,Oz,SD,Sl,Vl,LU&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tfrequency</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;mon&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tinitialization_method</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">1</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tinstitute_id</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;MPI-M&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tinstitution</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;Max Planck Institute for Meteorology&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tmodel_id</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;MPI-ESM-MR&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tmodeling_realm</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;atmos&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tparent_experiment</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;N/A&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tparent_experiment_id</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;N/A&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tparent_experiment_rip</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;N/A&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tphysics_version</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">1</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tproduct</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;output&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tproject_id</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;CMIP5&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\trealization</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">1</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\treferences</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;ECHAM6: n/a; JSBACH: Raddatz et al., 2007. Will the tropical land biosphere ...&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\tsource</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;MPI-ESM-MR 2011; URL: http://svn.zmaw.de/svn/cosmos/branches/releases/mpi-esm-cmip5/src/mod; ...&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\ttable_id</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;Table Amon (27 April 2011) a5a1c518f52ae340313ba0aada03f862&#x27;</td>\n",
       "</tr>\n",
       "<tr class=\"iris\">\n",
       "    <td class=\"iris-word-cell iris-subheading-cell\">\ttitle</td>\n",
       "    <td class=\"iris-word-cell\" colspan=\"3\">&#x27;MPI-ESM-MR model output prepared for CMIP5 historical&#x27;</td>\n",
       "</tr>\n",
       "</table>\n",
       "        "
      ],
      "text/plain": [
       "<iris 'Cube' of air_temperature / (K) (time: 1812; latitude: 96; longitude: 192)>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cube = tas.load()\n",
    "cube"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3999db7a-a5b3-4a54-a16f-a38937528f51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<CellMeasure: cell_area / (m2)  <lazy>  shape(96, 192)>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cell_area = cube.cell_measures()[0]\n",
    "cell_area"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a0ba10c-78a0-4eec-a9c4-85f823b29485",
   "metadata": {},
   "source": [
    "This code shows how to use some [esmvalcore.preprocessor](https://docs.esmvaltool.org/projects/esmvalcore/en/latest/api/esmvalcore.preprocessor.html) functions to compute the global annual mean temperature in degrees Celsius:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "bba8cc35-ffe7-42a4-b538-dad2ccb4d96c",
   "metadata": {},
   "outputs": [],
   "source": [
    "cube = area_statistics(cube, operator='mean')\n",
    "cube = annual_statistics(cube, operator='mean')\n",
    "cube.convert_units('degrees_C')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50f61460-194a-40ba-a0d0-cb9e0d4d5762",
   "metadata": {},
   "source": [
    "The [iris.quickplot](https://scitools-iris.readthedocs.io/en/latest/generated/api/iris/quickplot.html) module has useful functions for quickly plotting the results:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a835bf2b-a959-48e0-9d85-7601101e4cbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 52356 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "iris.quickplot.plot(cube)\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "esm",
   "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.9"
  },
  "vscode": {
   "interpreter": {
    "hash": "17e81e49408864327be43d3caebcb8eca32ff92a01becb15aa27be73c37f0517"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
