{ "cells": [ { "cell_type": "markdown", "id": "df6b9972-67fd-42b6-8fd4-4d729ce51708", "metadata": {}, "source": [ "# ENSO\n", "\n", "## Purpose:\n", "Compute and plot the ENSO variability and nin3.4 index.\n", "\n", "## Acknowledgment:\n", "This notebook builds on work by John Krasting (https://github.com/jkrasting/mar/blob/main/src/gfdlnb/notebooks/ocean/ENSO.ipynb) and a tutorial provided by the Project Pythia (https://foundations.projectpythia.org/core/xarray/enso-xarray.html)" ] }, { "cell_type": "code", "execution_count": 1, "id": "9d1d46a8-90ef-46bb-9251-c20c58d93555", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "3a0fc487-aada-4433-baf8-50489e46475b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "ERROR 1: PROJ: proj_create_from_database: Open of /glade/work/gmarques/conda-envs/mom6-tools/share/proj failed\n" ] } ], "source": [ "%matplotlib inline\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "import matplotlib\n", "import numpy as np\n", "import xarray as xr\n", "import momlevel as ml\n", "import xwavelet as xw\n", "from ncar_jobqueue import NCARCluster\n", "from dask.distributed import Client\n", "from mom6_tools.MOM6grid import MOM6grid\n", "from mom6_tools.m6toolbox import cime_xmlquery\n", "from mom6_tools.m6toolbox import add_global_attrs\n", "from mom6_tools.enso import plot_enso_obs\n", "from mom6_tools.m6toolbox import geoslice\n", "import matplotlib.pyplot as plt\n", "import cartopy.crs as ccrs\n", "import yaml, os, intake, pickle" ] }, { "cell_type": "code", "execution_count": 3, "id": "6b5e022f-ac7a-41b5-a872-bfc5606d6957", "metadata": {}, "outputs": [], "source": [ "# Read in the yaml file\n", "diag_config_yml_path = \"diag_config.yml\"\n", "diag_config_yml = yaml.load(open(diag_config_yml_path,'r'), Loader=yaml.Loader)" ] }, { "cell_type": "code", "execution_count": 4, "id": "14dd4803-6a53-438a-b402-057a8e334503", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Output directory is: /glade/derecho/scratch/gmarques/archive/g.e30_a03c.GJRAv4.TL319_t232_wgx3_hycom1_N75.2024.079/ocn/hist/\n", "Casename is: g.e30_a03c.GJRAv4.TL319_t232_wgx3_hycom1_N75.2024.079\n" ] } ], "source": [ "caseroot = diag_config_yml['Case']['CASEROOT']\n", "casename = cime_xmlquery(caseroot, 'CASE')\n", "DOUT_S = cime_xmlquery(caseroot, 'DOUT_S')\n", "if DOUT_S:\n", " OUTDIR = cime_xmlquery(caseroot, 'DOUT_S_ROOT')+'/ocn/hist/'\n", "else:\n", " OUTDIR = cime_xmlquery(caseroot, 'RUNDIR')\n", "\n", "print('Output directory is:', OUTDIR)\n", "print('Casename is:', casename)" ] }, { "cell_type": "code", "execution_count": 5, "id": "06674ecb-b173-420e-9873-b8668a0b044e", "metadata": {}, "outputs": [], "source": [ "# The following parameters must be set accordingly\n", "# create an empty class object\n", "class args:\n", " pass\n", "\n", "args.infile = OUTDIR\n", "args.native = casename+diag_config_yml['Fnames']['native']\n", "args.static = casename+diag_config_yml['Fnames']['static']\n", "args.geom = casename+diag_config_yml['Fnames']['geom']\n", "args.year_shift = 0 #1957 # Option to shift by args.year_shift years\n", "args.casename = casename\n", "args.label = diag_config_yml['Case']['SNAME']\n", "args.savefigs = False" ] }, { "cell_type": "code", "execution_count": 6, "id": "077a026d-37a6-42f6-b1cd-0743437d4d75", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "MOM6 grid successfully loaded... \n", "\n" ] } ], "source": [ "# read grid info\n", "geom_file = OUTDIR+'/'+args.geom\n", "if os.path.exists(geom_file):\n", " grd = MOM6grid(OUTDIR+'/'+args.static, geom_file, xrformat=True)\n", "else:\n", " grd = MOM6grid(OUTDIR+'/'+args.static, xrformat=True)\n", "\n", "try:\n", " depth = grd.depth_ocean\n", "except:\n", " depth = grd.deptho" ] }, { "cell_type": "code", "execution_count": 7, "id": "d30f94ac-75eb-4eac-aa2c-9229b94bc684", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Client-3a7af58d-d5c1-11ef-bfdb-3cecef1ac748
\n", "| Connection method: Cluster object | \n", "Cluster type: dask_jobqueue.PBSCluster | \n", " \n", "
| \n", " Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/gmarques/High-mem/proxy/8787/status\n", " | \n", "\n", " |
7b1c9327
\n", "| \n", " Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/gmarques/High-mem/proxy/8787/status\n", " | \n", "\n", " Workers: 0\n", " | \n", "
| \n", " Total threads: 0\n", " | \n", "\n", " Total memory: 0 B\n", " | \n", "
Scheduler-a432f6c3-5e8f-4ab0-b763-0b43bb0e8705
\n", "| \n", " Comm: tcp://128.117.208.105:44673\n", " | \n", "\n", " Workers: 0\n", " | \n", "
| \n", " Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/gmarques/High-mem/proxy/8787/status\n", " | \n", "\n", " Total threads: 0\n", " | \n", "
| \n", " Started: Just now\n", " | \n", "\n", " Total memory: 0 B\n", " | \n", "
<xarray.Dataset> Size: 466MB\n",
"Dimensions: (time: 444, yh: 480, xh: 540)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 4kB 1982-01-16 ... 2018-12-16\n",
" geolat (yh, xh) float64 2MB dask.array<chunksize=(480, 540), meta=np.ndarray>\n",
" geolon (yh, xh) float64 2MB dask.array<chunksize=(480, 540), meta=np.ndarray>\n",
" areacello (yh, xh) float32 1MB 0.0 0.0 0.0 ... 3.986e+07 4.974e+06\n",
"Dimensions without coordinates: yh, xh\n",
"Data variables:\n",
" sst (time, yh, xh) float32 460MB dask.array<chunksize=(444, 480, 540), meta=np.ndarray>