{ "cells": [ { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "# Analysis of Surface Fields\n", "\n", "`mom6_tools.MOM6grid` returns an object with MOM6 grid data.\n", "\n", "`mom6_tools.latlon_analysis` has a collection of tools used to perform spatial analysis (e.g., time averages and spatial mean).\n", "\n", "The goal of this notebook is the following:\n", "\n", "1) server as an example of how to post-process CESM/MOM6 output;\n", "\n", "2) create time averages of surface fields." ] }, { "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" ] }, { "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": [ "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "import xarray as xr\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import os, yaml, argparse\n", "import pandas as pd\n", "import dask, intake\n", "from datetime import datetime, date\n", "from ncar_jobqueue import NCARCluster\n", "from dask.distributed import Client\n", "from mom6_tools.m6toolbox import cime_xmlquery\n", "from mom6_tools.m6toolbox import add_global_attrs\n", "from mom6_tools.m6plot import xycompare, xyplot\n", "from mom6_tools.MOM6grid import MOM6grid\n", "from mom6_tools.surface import get_SSH, get_MLD, get_BLD" ] }, { "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": [], "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')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "# The following parameters must be set accordingly\n", "######################################################\n", "\n", "# create an empty class object\n", "class args:\n", " pass\n", "\n", "# load avg dates\n", "avg = diag_config_yml['Avg']\n", "\n", "args.start_date = avg['start_date']\n", "args.end_date = avg['end_date']\n", "args.casename = casename\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.label = diag_config_yml['Case']['SNAME']\n", "args.mld_obs = \"mld-deboyer-tx2_3v2\"\n", "args.savefigs = False\n", "args.nw = 6 # requesting 6 workers" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "if not os.path.isdir('PNG/BLD'):\n", " print('Creating a directory to place figures (PNG/BLD)... \\n')\n", " os.system('mkdir -p PNG/BLD')\n", "if not os.path.isdir('PNG/MLD'):\n", " print('Creating a directory to place figures (PNG/MLD)... \\n')\n", " os.system('mkdir -p PNG/MLD')\n", "if not os.path.isdir('ncfiles'):\n", " print('Creating a directory to place netcdf files (ncfiles)... \\n')\n", " os.system('mkdir ncfiles') " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "parallel = False\n", "if args.nw > 1:\n", " parallel = True\n", " cluster = NCARCluster()\n", " cluster.scale(args.nw)\n", " client = Client(cluster)\n", " client" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Client-a90b267a-ad03-11ef-b3cb-3cecef1acbfa
\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", " |
4063fc3a
\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-71528c26-f25a-433d-bb53-e6eb6a38a888
\n", "| \n", " Comm: tcp://128.117.208.112:38481\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: 17MB\n",
"Dimensions: (month: 12, yh: 480, xh: 540)\n",
"Coordinates:\n",
" lon (yh, xh) float64 2MB dask.array<chunksize=(480, 540), meta=np.ndarray>\n",
" lat (yh, xh) float64 2MB dask.array<chunksize=(480, 540), meta=np.ndarray>\n",
" * month (month) int64 96B 1 2 3 4 5 6 7 8 9 10 11 12\n",
"Dimensions without coordinates: yh, xh\n",
"Data variables:\n",
" mld (month, yh, xh) float32 12MB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>