{ "cells": [ { "cell_type": "markdown", "id": "a68de7fe", "metadata": { "papermill": { "duration": 0.156068, "end_time": "2023-10-18T22:47:24.491599", "exception": false, "start_time": "2023-10-18T22:47:24.335531", "status": "completed" }, "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;\n", "\n", "3) create time-series of globally-averaged surface fields;" ] }, { "cell_type": "code", "execution_count": 1, "id": "df66d664", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:24.517790Z", "iopub.status.busy": "2023-10-18T22:47:24.517587Z", "iopub.status.idle": "2023-10-18T22:47:24.614615Z", "shell.execute_reply": "2023-10-18T22:47:24.579164Z" }, "papermill": { "duration": 0.11706, "end_time": "2023-10-18T22:47:24.616614", "exception": false, "start_time": "2023-10-18T22:47:24.499554", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "c894c82e", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:24.639091Z", "iopub.status.busy": "2023-10-18T22:47:24.638892Z", "iopub.status.idle": "2023-10-18T22:47:37.359235Z", "shell.execute_reply": "2023-10-18T22:47:37.357356Z" }, "papermill": { "duration": 12.735375, "end_time": "2023-10-18T22:47:37.360684", "exception": false, "start_time": "2023-10-18T22:47:24.625309", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Basemap module not found. Some regional plots may not function properly\n" ] } ], "source": [ "import xarray as xr\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import warnings, 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.DiagsCase import DiagsCase\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\n", "\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "a61ef0b7", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:37.369940Z", "iopub.status.busy": "2023-10-18T22:47:37.369488Z", "iopub.status.idle": "2023-10-18T22:47:39.579906Z", "shell.execute_reply": "2023-10-18T22:47:39.579197Z" }, "papermill": { "duration": 2.216036, "end_time": "2023-10-18T22:47:39.581600", "exception": false, "start_time": "2023-10-18T22:47:37.365564", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Output directory is: /glade/scratch/gmarques/archive/g.e23_b15.GJRAv4.TL319_t232_zstar_N65.baseline.001/ocn/hist/\n", "Casename is: g.e23_b15.GJRAv4.TL319_t232_zstar_N65.baseline.001\n" ] } ], "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)\n", "\n", "# load avg dates\n", "avg = diag_config_yml['Avg']\n", "\n", "# Create the case instance\n", "dcase = DiagsCase(diag_config_yml['Case'])\n", "DOUT_S = dcase.get_value('DOUT_S')\n", "if DOUT_S:\n", " OUTDIR = dcase.get_value('DOUT_S_ROOT')+'/ocn/hist/'\n", "else:\n", " OUTDIR = dcase.get_value('RUNDIR')+'/'\n", "\n", "print('Output directory is:', OUTDIR)\n", "print('Casename is:', dcase.casename)" ] }, { "cell_type": "code", "execution_count": 4, "id": "0ba1ae68", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:39.603916Z", "iopub.status.busy": "2023-10-18T22:47:39.603721Z", "iopub.status.idle": "2023-10-18T22:47:39.821075Z", "shell.execute_reply": "2023-10-18T22:47:39.818491Z" }, "papermill": { "duration": 0.234292, "end_time": "2023-10-18T22:47:39.822657", "exception": false, "start_time": "2023-10-18T22:47:39.588365", "status": "completed" }, "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", "args.start_date = avg['start_date']\n", "args.end_date = avg['end_date']\n", "args.casename = dcase.casename\n", "args.native = dcase.casename+diag_config_yml['Fnames']['native']\n", "args.static = dcase.casename+diag_config_yml['Fnames']['static']\n", "args.mld_obs = \"mld-deboyer-tx2_3v2\"\n", "args.savefigs = False\n", "args.nw = 6 # requesting 6 workers" ] }, { "cell_type": "code", "execution_count": 5, "id": "354399f1", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:39.829600Z", "iopub.status.busy": "2023-10-18T22:47:39.829416Z", "iopub.status.idle": "2023-10-18T22:47:40.120983Z", "shell.execute_reply": "2023-10-18T22:47:40.120328Z" }, "papermill": { "duration": 0.296412, "end_time": "2023-10-18T22:47:40.122370", "exception": false, "start_time": "2023-10-18T22:47:39.825958", "status": "completed" }, "tags": [ "injected-parameters" ] }, "outputs": [], "source": [ "# Parameters\n", "test_global_param = \"hello\"\n", "sname = \"adf-quick-run\"\n", "subset_kwargs = {}\n", "product = \"/glade/u/home/eromashkova/codes/test-combined-diags/computed_notebooks/adf-quick-run/surface.ipynb\"\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "6728fe11", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:40.129251Z", "iopub.status.busy": "2023-10-18T22:47:40.129068Z", "iopub.status.idle": "2023-10-18T22:47:40.347120Z", "shell.execute_reply": "2023-10-18T22:47:40.345319Z" }, "papermill": { "duration": 0.223522, "end_time": "2023-10-18T22:47:40.348785", "exception": false, "start_time": "2023-10-18T22:47:40.125263", "status": "completed" }, "tags": [] }, "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, "id": "ce114bef", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:40.375893Z", "iopub.status.busy": "2023-10-18T22:47:40.375672Z", "iopub.status.idle": "2023-10-18T22:47:46.728953Z", "shell.execute_reply": "2023-10-18T22:47:46.728363Z" }, "papermill": { "duration": 6.363518, "end_time": "2023-10-18T22:47:46.730490", "exception": false, "start_time": "2023-10-18T22:47:40.366972", "status": "completed" }, "tags": [] }, "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, "id": "ff47a791", "metadata": { "execution": { "iopub.execute_input": "2023-10-18T22:47:46.739278Z", "iopub.status.busy": "2023-10-18T22:47:46.739109Z", "iopub.status.idle": "2023-10-18T22:47:47.216750Z", "shell.execute_reply": "2023-10-18T22:47:47.214896Z" }, "papermill": { "duration": 0.483538, "end_time": "2023-10-18T22:47:47.218533", "exception": false, "start_time": "2023-10-18T22:47:46.734995", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Client-59c06341-6e08-11ee-8730-3cecef1a526c
\n", "Connection method: Cluster object | \n", "Cluster type: dask_jobqueue.PBSCluster | \n", " \n", "
\n", " Dashboard: /proxy/42880/status\n", " | \n", "\n", " |
67fe2e36
\n", "\n", " Dashboard: /proxy/42880/status\n", " | \n", "\n", " Workers: 0\n", " | \n", "
\n", " Total threads: 0\n", " | \n", "\n", " Total memory: 0 B\n", " | \n", "
Scheduler-03f4ee5c-1e26-4882-b23f-3d9cfdfdf81d
\n", "\n", " Comm: tcp://10.12.206.53:42260\n", " | \n", "\n", " Workers: 0\n", " | \n", "
\n", " Dashboard: /proxy/42880/status\n", " | \n", "\n", " Total threads: 0\n", " | \n", "
\n", " Started: Just now\n", " | \n", "\n", " Total memory: 0 B\n", " | \n", "