{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example on how to configure a case using mom6-tools\n", "\n", "This is a very simple example showing how to read `diag_config.yaml`, create a case instance, compute a climatology and visualize the results." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Case Information\n", "- **Case:**\n", " - **CASEROOT**: Path to the root directory of the case: \n", " `/glade/work/gmarques/cesm.cases/G/g.e30_a03c.GJRAv4.TL319_t232_wgx3_hycom1_N75.2024.079/`\n", " - **OCN_DIAG_ROOT**: Directory for ocean diagnostics files: \n", " `ncfiles/`\n", " - **SNAME**: Identifier or short name of the case: \n", " `\"079\"`\n", "\n", "---\n", "\n", "### Average Dates\n", "- **Avg:**\n", " - **start_date**: Start date for averaging data: \n", " `'0031-01-01'`\n", " - **end_date**: End date for averaging data: \n", " `'0062-01-01'`\n", "\n", "---\n", "\n", "### CESM History File Naming Conventions\n", "- **Fnames:**\n", " - **rho2**: Format for density files: \n", " `.mom6.h.rho2.????-??.nc`\n", " - **z**: Format for depth files: \n", " `.mom6.h.z.????-??.nc`\n", " - **native**: Format for native files: \n", " `.mom6.h.native.????-??.nc`\n", " - **sfc**: Surface files naming convention: \n", " `.mom6.h.sfc.????-??.nc`\n", " - **static**: Static files naming convention: \n", " `.mom6.h.static.nc`\n", " - **geom**: Ocean geometry files naming convention: \n", " `.mom6.h.ocean_geometry.nc`\n", "\n", "---\n", "\n", "### Transport Sections\n", "- **Transports:**\n", " - **sections**: List of sections where transports are computed, including observational estimates where applicable:\n", " - **`h.Agulhas_Section`**: Uses `umo` component, range `[129.8, 143.6]`\n", " - **`h.Barents_Opening`**: Uses `vmo` component, range `[2.0]`\n", " - **`h.Bering_Strait`**: Uses `vmo` component, range `[0.7, 1.1]`\n", " - *(Additional sections follow similar structure)*\n", "\n", "---\n", "\n", "### Ocean Catalog Path\n", "- **oce_cat**: Path to the ocean-related datasets catalog: \n", " `/glade/u/home/gmarques/libs/oce-catalogs/reference-datasets.yml`\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from mom6_tools.m6toolbox import cime_xmlquery\n", "import yaml, os\n", "import numpy as np\n", "import xarray as xr\n", "import matplotlib\n", "from mom6_tools import m6toolbox\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": 2, "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": 3, "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": 4, "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" ] } ], "source": [ "print('Output directory is:', OUTDIR)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Casename is: g.e30_a03c.GJRAv4.TL319_t232_wgx3_hycom1_N75.2024.079\n" ] } ], "source": [ "print('Casename is:', casename)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# create an empty class object\n", "class args:\n", " pass\n", "\n", "args.static = casename+diag_config_yml['Fnames']['static']\n", "args.native = casename+diag_config_yml['Fnames']['native']\n", "args.geom = casename+diag_config_yml['Fnames']['geom']" ] }, { "cell_type": "code", "execution_count": 7, "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" ] }, { "name": "stdout", "output_type": "stream", "text": [ "MOM6 grid successfully loaded... \n", "\n" ] } ], "source": [ "# Load the grid\n", "from mom6_tools.MOM6grid import MOM6grid\n", "\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)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Client-197af34f-9e18-11ef-a087-3cecef1acc42
\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", " |
00519662
\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-ace8eff9-04d1-437d-935e-857746cff9ed
\n", "| \n", " Comm: tcp://128.117.208.64:37721\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: 41GB\n",
"Dimensions: (time: 3285, yh: 480, xh: 540, xq: 540, yq: 480, nbnd: 2)\n",
"Coordinates:\n",
" * xh (xh) float64 4kB -286.7 -286.0 -285.3 ... 71.33 72.0 72.67\n",
" * yh (yh) float64 4kB -81.56 -81.46 -81.36 ... 87.65 87.71 87.74\n",
" * time (time) object 26kB 0001-01-01 12:00:00 ... 0009-12-31 12:00:00\n",
" * nbnd (nbnd) float64 16B 1.0 2.0\n",
" * xq (xq) float64 4kB -286.3 -285.7 -285.0 ... 71.67 72.33 73.0\n",
" * yq (yq) float64 4kB -81.51 -81.41 -81.31 ... 87.68 87.73 87.74\n",
"Data variables: (12/16)\n",
" SSH (time, yh, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" tos (time, yh, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" sos (time, yh, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" SSU (time, yh, xq) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" SSV (time, yq, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" mass_wt (time, yh, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" ... ...\n",
" mlotst (time, yh, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" oml (time, yh, xh) float32 3GB dask.array<chunksize=(12, 480, 540), meta=np.ndarray>\n",
" average_T1 (time) object 26kB dask.array<chunksize=(12,), meta=np.ndarray>\n",
" average_T2 (time) object 26kB dask.array<chunksize=(12,), meta=np.ndarray>\n",
" average_DT (time) timedelta64[ns] 26kB dask.array<chunksize=(12,), meta=np.ndarray>\n",
" time_bounds (time, nbnd) object 53kB dask.array<chunksize=(12, 2), meta=np.ndarray>\n",
"Attributes:\n",
" NumFilesInSet: 1\n",
" title: MOM6 diagnostic fields table for CESM case: g.e30_a03c...\n",
" associated_files: areacello: g.e30_a03c.GJRAv4.TL319_t232_wgx3_hycom1_N7...\n",
" grid_type: regular\n",
" grid_tile: N/A