|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# CDAT Migration Regression Testing Notebook (`.png` files)\n", |
| 8 | + "\n", |
| 9 | + "This notebook is used to perform regression testing between the development and\n", |
| 10 | + "production versions of a diagnostic set.\n", |
| 11 | + "\n", |
| 12 | + "## How to use\n", |
| 13 | + "\n", |
| 14 | + "PREREQUISITE: The diagnostic set's netCDF stored in `.json` files in two directories\n", |
| 15 | + "(dev and `main` branches).\n", |
| 16 | + "\n", |
| 17 | + "1. Make a copy of this notebook under `auxiliary_tools/cdat_regression_testing/<DIR_NAME>`.\n", |
| 18 | + "2. Run `mamba create -n cdat_regression_test -y -c conda-forge \"python<3.12\" xarray netcdf4 dask pandas matplotlib-base ipykernel`\n", |
| 19 | + "3. Run `mamba activate cdat_regression_test`\n", |
| 20 | + "4. Update `SET_DIR` and `SET_NAME` in the copy of your notebook.\n", |
| 21 | + "5. Run all cells IN ORDER.\n" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "markdown", |
| 26 | + "metadata": {}, |
| 27 | + "source": [ |
| 28 | + "## Setup Code\n" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": 1, |
| 34 | + "metadata": {}, |
| 35 | + "outputs": [], |
| 36 | + "source": [ |
| 37 | + "import glob\n", |
| 38 | + "\n", |
| 39 | + "from auxiliary_tools.cdat_regression_testing.utils import get_image_diffs\n", |
| 40 | + "\n", |
| 41 | + "SET_NAME = \"mp_partition\"\n", |
| 42 | + "SET_DIR = \"871-mp-partition\"\n", |
| 43 | + "\n", |
| 44 | + "DEV_PATH = f\"/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/{SET_DIR}/{SET_NAME}/**\"\n", |
| 45 | + "DEV_GLOB = sorted(glob.glob(DEV_PATH + \"/*.png\"))\n", |
| 46 | + "DEV_NUM_FILES = len(DEV_GLOB)\n", |
| 47 | + "\n", |
| 48 | + "MAIN_PATH = f\"/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/{SET_NAME}/**\"\n", |
| 49 | + "MAIN_GLOB = sorted(glob.glob(MAIN_PATH + \"/*.png\"))\n", |
| 50 | + "MAIN_NUM_FILES = len(MAIN_GLOB)" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": 5, |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [], |
| 58 | + "source": [ |
| 59 | + "def _check_if_files_found():\n", |
| 60 | + " if DEV_NUM_FILES == 0 or MAIN_NUM_FILES == 0:\n", |
| 61 | + " raise IOError(\n", |
| 62 | + " \"No files found at DEV_PATH and/or MAIN_PATH. \"\n", |
| 63 | + " f\"Please check {DEV_PATH} and {MAIN_PATH}.\"\n", |
| 64 | + " )\n", |
| 65 | + "\n", |
| 66 | + "\n", |
| 67 | + "def _check_if_matching_filecount():\n", |
| 68 | + " if DEV_NUM_FILES != MAIN_NUM_FILES:\n", |
| 69 | + " raise IOError(\n", |
| 70 | + " \"Number of files do not match at DEV_PATH and MAIN_PATH \"\n", |
| 71 | + " f\"({DEV_NUM_FILES} vs. {MAIN_NUM_FILES}).\"\n", |
| 72 | + " )\n", |
| 73 | + "\n", |
| 74 | + " print(f\"Matching file count ({DEV_NUM_FILES} and {MAIN_NUM_FILES}).\")\n", |
| 75 | + "\n", |
| 76 | + "\n", |
| 77 | + "def _check_if_missing_files():\n", |
| 78 | + " missing_count = 0\n", |
| 79 | + "\n", |
| 80 | + " for fp_main in MAIN_GLOB:\n", |
| 81 | + " fp_dev = fp_main.replace(SET_DIR, \"main\")\n", |
| 82 | + "\n", |
| 83 | + " if fp_dev not in MAIN_GLOB:\n", |
| 84 | + " print(f\"No production file found to compare with {fp_dev}!\")\n", |
| 85 | + " missing_count += 1\n", |
| 86 | + "\n", |
| 87 | + " for fp_dev in DEV_GLOB:\n", |
| 88 | + " fp_main = fp_main.replace(\"main\", SET_DIR)\n", |
| 89 | + "\n", |
| 90 | + " if fp_main not in DEV_GLOB:\n", |
| 91 | + " print(f\"No development file found to compare with {fp_main}!\")\n", |
| 92 | + " missing_count += 1\n", |
| 93 | + "\n", |
| 94 | + " print(f\"Number of files missing: {missing_count}\")" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "markdown", |
| 99 | + "metadata": {}, |
| 100 | + "source": [ |
| 101 | + "## 1. Check for matching and equal number of files\n" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "code", |
| 106 | + "execution_count": 6, |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [], |
| 109 | + "source": [ |
| 110 | + "_check_if_files_found()" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": 7, |
| 116 | + "metadata": {}, |
| 117 | + "outputs": [ |
| 118 | + { |
| 119 | + "name": "stdout", |
| 120 | + "output_type": "stream", |
| 121 | + "text": [ |
| 122 | + "Number of files missing: 0\n" |
| 123 | + ] |
| 124 | + } |
| 125 | + ], |
| 126 | + "source": [ |
| 127 | + "_check_if_missing_files()" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": 8, |
| 133 | + "metadata": {}, |
| 134 | + "outputs": [ |
| 135 | + { |
| 136 | + "name": "stdout", |
| 137 | + "output_type": "stream", |
| 138 | + "text": [ |
| 139 | + "Matching file count (1 and 1).\n" |
| 140 | + ] |
| 141 | + } |
| 142 | + ], |
| 143 | + "source": [ |
| 144 | + "_check_if_matching_filecount()" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "markdown", |
| 149 | + "metadata": {}, |
| 150 | + "source": [ |
| 151 | + "## 2 Compare the plots between branches\n", |
| 152 | + "\n", |
| 153 | + "- Compare \"ref\" and \"test\" files\n", |
| 154 | + "- \"diff\" files are ignored because getting relative diffs for these does not make sense (relative diff will be above tolerance)\n" |
| 155 | + ] |
| 156 | + }, |
| 157 | + { |
| 158 | + "cell_type": "code", |
| 159 | + "execution_count": 9, |
| 160 | + "metadata": {}, |
| 161 | + "outputs": [ |
| 162 | + { |
| 163 | + "name": "stdout", |
| 164 | + "output_type": "stream", |
| 165 | + "text": [ |
| 166 | + "Comparing:\n", |
| 167 | + " * /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/mp_partition/mixed-phase_partition/mixed-phase_partition.png\n", |
| 168 | + " * /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/871-mp-partition/mp_partition/mixed-phase_partition/mixed-phase_partition.png\n", |
| 169 | + " * Difference path /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/871-mp-partition/mp_partition/mixed-phase_partition_diff/mixed-phase_partition.png\n" |
| 170 | + ] |
| 171 | + } |
| 172 | + ], |
| 173 | + "source": [ |
| 174 | + "for main_path, dev_path in zip(MAIN_GLOB, DEV_GLOB):\n", |
| 175 | + " print(\"Comparing:\")\n", |
| 176 | + " print(f\" * {main_path}\")\n", |
| 177 | + " print(f\" * {dev_path}\")\n", |
| 178 | + "\n", |
| 179 | + " get_image_diffs(dev_path, main_path)" |
| 180 | + ] |
| 181 | + }, |
| 182 | + { |
| 183 | + "cell_type": "markdown", |
| 184 | + "metadata": {}, |
| 185 | + "source": [ |
| 186 | + "### Results\n", |
| 187 | + "\n", |
| 188 | + "All plots are identical\n" |
| 189 | + ] |
| 190 | + } |
| 191 | + ], |
| 192 | + "metadata": { |
| 193 | + "kernelspec": { |
| 194 | + "display_name": "Python 3", |
| 195 | + "language": "python", |
| 196 | + "name": "python3" |
| 197 | + }, |
| 198 | + "language_info": { |
| 199 | + "codemirror_mode": { |
| 200 | + "name": "ipython", |
| 201 | + "version": 3 |
| 202 | + }, |
| 203 | + "file_extension": ".py", |
| 204 | + "mimetype": "text/x-python", |
| 205 | + "name": "python", |
| 206 | + "nbconvert_exporter": "python", |
| 207 | + "pygments_lexer": "ipython3", |
| 208 | + "version": "3.10.14" |
| 209 | + } |
| 210 | + }, |
| 211 | + "nbformat": 4, |
| 212 | + "nbformat_minor": 2 |
| 213 | +} |
0 commit comments