{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "623cbc23-45bf-4dfd-9f49-8d814d0394ba",
   "metadata": {
    "papermill": {
     "duration": 0.002781,
     "end_time": "2025-10-28T22:33:07.829642",
     "exception": false,
     "start_time": "2025-10-28T22:33:07.826861",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# CVDP\n",
    "\n",
    "A number of plots are provided from CVDP. The full output from the stand-alone CDVP configuration is in the link below.\n",
    "\n",
    "\n",
    "Note that in standalone format (eg, CUPiD run not through CESM workflow), CVDP is currently run by users via ADF with the following process:\n",
    "1) Install ADF and activate cupid-analysis\n",
    "2) Use the `CUPiD/helper_scripts/generate_adf_config_file.py` script to generate an ADF config file based on a CUPiD configuration file.\n",
    "   * `cd CUPiD/examples/external_diag_packages`\n",
    "   * `../../helper_scripts/generate_adf_config_file.py --cupid-config-loc . --adf-template ../../externals/ADF/config_amwg_default_plots.yaml --out-file ADF_config.yaml`\n",
    "3) Run ADF with the newly created configuration file.\n",
    "   * `../../externals/ADF/run_adf_diag ADF_config.yaml`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "82af7435-3849-4fd1-bb2d-2e062719ec5b",
   "metadata": {
    "editable": true,
    "execution": {
     "iopub.execute_input": "2025-10-28T22:33:07.834334Z",
     "iopub.status.busy": "2025-10-28T22:33:07.833982Z",
     "iopub.status.idle": "2025-10-28T22:33:08.100767Z",
     "shell.execute_reply": "2025-10-28T22:33:08.100182Z"
    },
    "papermill": {
     "duration": 0.270806,
     "end_time": "2025-10-28T22:33:08.102259",
     "exception": false,
     "start_time": "2025-10-28T22:33:07.831453",
     "status": "completed"
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide-cell"
    ]
   },
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "from IPython.core.display import HTML, Image\n",
    "from IPython.display import display\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2a759f1b-eca7-4eec-a16a-eede1a6ab36c",
   "metadata": {
    "editable": true,
    "execution": {
     "iopub.execute_input": "2025-10-28T22:33:08.108519Z",
     "iopub.status.busy": "2025-10-28T22:33:08.108354Z",
     "iopub.status.idle": "2025-10-28T22:33:08.110955Z",
     "shell.execute_reply": "2025-10-28T22:33:08.110249Z"
    },
    "papermill": {
     "duration": 0.006127,
     "end_time": "2025-10-28T22:33:08.111590",
     "exception": false,
     "start_time": "2025-10-28T22:33:08.105463",
     "status": "completed"
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "parameters",
     "hide-cell"
    ]
   },
   "outputs": [],
   "source": [
    "cvdp_root = \".\"\n",
    "case_name = None\n",
    "key_plots = None\n",
    "# cvdp_root will be external_diag_packages/computed_notebooks/CVDP/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4e52d5ed",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-10-28T22:33:08.114551Z",
     "iopub.status.busy": "2025-10-28T22:33:08.114315Z",
     "iopub.status.idle": "2025-10-28T22:33:08.122305Z",
     "shell.execute_reply": "2025-10-28T22:33:08.121895Z"
    },
    "papermill": {
     "duration": 0.010561,
     "end_time": "2025-10-28T22:33:08.123324",
     "exception": false,
     "start_time": "2025-10-28T22:33:08.112763",
     "status": "completed"
    },
    "tags": [
     "injected-parameters"
    ]
   },
   "outputs": [],
   "source": [
    "# Parameters\n",
    "case_name = \"b.e30_alpha07c_cesm.B1850C_LTso.ne30_t232_wgx3.232\"\n",
    "base_case_name = \"b.e30_alpha07c_cesm.B1850C_LTso.ne30_t232_wgx3.228\"\n",
    "CESM_output_dir = \"/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing\"\n",
    "start_date = \"0001-01-01\"\n",
    "end_date = \"0021-01-01\"\n",
    "base_start_date = \"0001-01-01\"\n",
    "base_end_date = \"0045-01-01\"\n",
    "obs_data_dir = (\n",
    "    \"/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CUPiD_obs_data\"\n",
    ")\n",
    "ts_dir = None\n",
    "lc_kwargs = {\"threads_per_worker\": 1}\n",
    "serial = False\n",
    "cvdp_root = \"../../examples/key_metrics/CVDP_output/\"\n",
    "key_plots = [\n",
    "    \"nino34.spatialcomp.djf1.png\",\n",
    "    \"nino34.hov.elnino.png\",\n",
    "    \"nino34.hov.lanina.png\",\n",
    "    \"sst.stddev.djf.png\",\n",
    "    \"nino34.monstddev.png\",\n",
    "]\n",
    "subset_kwargs = {}\n",
    "product = \"/glade/work/richling/CUPid_pr_test/CUPiD/examples/key_metrics/computed_notebooks//atm/CVDP.ipynb\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ee0774cc-c68a-4385-b94c-08fa806f28c0",
   "metadata": {
    "editable": true,
    "execution": {
     "iopub.execute_input": "2025-10-28T22:33:08.129148Z",
     "iopub.status.busy": "2025-10-28T22:33:08.128887Z",
     "iopub.status.idle": "2025-10-28T22:33:08.136990Z",
     "shell.execute_reply": "2025-10-28T22:33:08.136472Z"
    },
    "papermill": {
     "duration": 0.011984,
     "end_time": "2025-10-28T22:33:08.137935",
     "exception": false,
     "start_time": "2025-10-28T22:33:08.125951",
     "status": "completed"
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "Full CVDP output"
      ],
      "text/plain": [
       ""
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cvdp_case_name = f\"{case_name}\"\n",
    "cvdp_root = os.path.join(cvdp_root, cvdp_case_name, \"output/\")\n",
    "display(\n",
    "    HTML(\n",
    "        f'Full CVDP output'\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9234aec-1fe5-4bbf-ad6c-fb565297afbe",
   "metadata": {
    "papermill": {
     "duration": 0.002469,
     "end_time": "2025-10-28T22:33:08.143182",
     "exception": false,
     "start_time": "2025-10-28T22:33:08.140713",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Key Metrics from CVDP\n",
    "\n",
    "Some important things to look at from the CVDP:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f877ed8e-bca3-4256-8010-69aad302bb32",
   "metadata": {
    "editable": true,
    "execution": {
     "iopub.execute_input": "2025-10-28T22:33:08.146923Z",
     "iopub.status.busy": "2025-10-28T22:33:08.146677Z",
     "iopub.status.idle": "2025-10-28T22:33:08.149890Z",
     "shell.execute_reply": "2025-10-28T22:33:08.149480Z"
    },
    "papermill": {
     "duration": 0.00516,
     "end_time": "2025-10-28T22:33:08.150303",
     "exception": false,
     "start_time": "2025-10-28T22:33:08.145143",
     "status": "completed"
    },
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [],
   "source": [
    "for path_to_key_plot in key_plots:\n",
    "    full_path = os.path.join(cvdp_root, path_to_key_plot)\n",
    "    if os.path.isfile(full_path):\n",
    "        display(Image(full_path))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "cupid-infrastructure",
   "language": "python",
   "name": "cupid-infrastructure"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "papermill": {
   "duration": 1.128281,
   "end_time": "2025-10-28T22:33:08.368167",
   "exception": null,
   "input_path": "/glade/derecho/scratch/richling/tmp/tmpkntarcr2.ipynb",
   "output_path": "/glade/work/richling/CUPid_pr_test/CUPiD/examples/key_metrics/computed_notebooks/atm/CVDP.ipynb",
   "parameters": {
    "CESM_output_dir": "/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing",
    "base_case_name": "b.e30_alpha07c_cesm.B1850C_LTso.ne30_t232_wgx3.228",
    "base_end_date": "0045-01-01",
    "base_start_date": "0001-01-01",
    "case_name": "b.e30_alpha07c_cesm.B1850C_LTso.ne30_t232_wgx3.232",
    "cvdp_root": "../../examples/key_metrics/CVDP_output/",
    "end_date": "0021-01-01",
    "key_plots": [
     "nino34.spatialcomp.djf1.png",
     "nino34.hov.elnino.png",
     "nino34.hov.lanina.png",
     "sst.stddev.djf.png",
     "nino34.monstddev.png"
    ],
    "lc_kwargs": {
     "threads_per_worker": 1
    },
    "obs_data_dir": "/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CUPiD_obs_data",
    "product": "/glade/work/richling/CUPid_pr_test/CUPiD/examples/key_metrics/computed_notebooks//atm/CVDP.ipynb",
    "serial": false,
    "start_date": "0001-01-01",
    "subset_kwargs": {},
    "ts_dir": null
   },
   "start_time": "2025-10-28T22:33:07.239886"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}