{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Poleward Heat Transport\n", "\n", "`mom6_tools.polar_heat_transport` collection of functions for computing and plotting poleward heat transport.\n", "\n", "The goal of this notebook is the following:\n", "\n", "1) server as an example on to compute polar heat transport using CESM/MOM6 output; \n", "\n", "2) evaluate model experiments by comparing transports against observed and other model estimates;" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Basemap module not found. Some regional plots may not function properly\n" ] } ], "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "from mom6_tools.poleward_heat_transport import *\n", "from mom6_tools.m6toolbox import cime_xmlquery, add_global_attrs, genBasinMasks\n", "from mom6_tools.m6toolbox import weighted_temporal_mean_vars\n", "from ncar_jobqueue import NCARCluster\n", "from dask.distributed import Client\n", "from datetime import datetime, date\n", "import yaml, os\n", "import matplotlib.pyplot as plt\n", "import matplotlib\n", "import numpy as np\n", "import xarray as xr" ] }, { "cell_type": "code", "execution_count": 3, "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, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Output directory is: /glade/derecho/scratch/gmarques/archive/g.e30_a07c_cesm.GJRAv4.TL319_t232_wgx3_hycom1_N75.2025.130/ocn/hist/\n", "Casename is: g.e30_a07c_cesm.GJRAv4.TL319_t232_wgx3_hycom1_N75.2025.130\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, "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "# create an empty class object\n", "class args:\n", " pass\n", "\n", "args.casename = casename\n", "# set avg dates\n", "avg = diag_config_yml['Avg']\n", "args.start_date = avg['start_date']\n", "args.end_date = avg['end_date']\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.savefigs = False\n", "args.nw = 6 # requesting 6 workers" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating a directory to store netcdf files (ncfiles)... \n", "\n" ] } ], "source": [ "if not os.path.isdir('ncfiles'):\n", " print('Creating a directory to store netcdf files (ncfiles)... \\n')\n", " os.system('mkdir ncfiles')" ] }, { "cell_type": "code", "execution_count": 7, "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.values\n", "except:\n", " depth = grd.deptho.values" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# basin masks - remove Nan's, otherwise genBasinMasks won't work\n", "depth[np.isnan(depth)] = 0.0\n", "basin_code = genBasinMasks(grd.geolon.values, grd.geolat.values, depth, verbose=False)\n", "basin_code_xr = genBasinMasks(grd.geolon.values, grd.geolat.values, depth, verbose=False, xda=True)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Client-84389ce0-940d-11f0-83de-10ffe07f3cea
\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", " |
26405dd7
\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-f802a90c-2c92-4c2f-b99b-14f715d4e8dc
\n", "| \n", " Comm: tcp://128.117.208.174:40495\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: 5kB\n",
"Dimensions: (time: 240)\n",
"Coordinates:\n",
" * time (time) object 2kB 0001-01-16 12:00:00 ... 0020-12-16...\n",
"Data variables:\n",
" T_ady_2d_26.5 (time) float32 960B dask.array<chunksize=(1,), meta=np.ndarray>\n",
" T_diffy_2d_26.5 (time) float32 960B dask.array<chunksize=(1,), meta=np.ndarray>\n",
" T_hbd_diffy_2d_26.5 (time) float32 960B dask.array<chunksize=(1,), meta=np.ndarray><xarray.Dataset> Size: 6MB\n",
"Dimensions: (xh: 540, yq: 480)\n",
"Coordinates:\n",
" * xh (xh) float64 4kB -286.7 -286.0 -285.3 ... 71.33 72.0 72.67\n",
" * yq (yq) float64 4kB -81.51 -81.41 -81.31 ... 87.68 87.73 87.74\n",
"Data variables:\n",
" T_ady_2d (yq, xh) float64 2MB nan nan nan nan nan ... nan nan nan nan\n",
" T_diffy_2d (yq, xh) float64 2MB nan nan nan nan nan ... nan nan nan nan\n",
" T_hbd_diffy_2d (yq, xh) float64 2MB nan nan nan nan nan ... nan nan nan nan