Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDAT Migration: Update mp_partition_driver.py to use Dataset from dataset_xr.py #883

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CDAT Migration Regression Testing Notebook (`.png` files)\n",
"\n",
"This notebook is used to perform regression testing between the development and\n",
"production versions of a diagnostic set.\n",
"\n",
"## How to use\n",
"\n",
"PREREQUISITE: The diagnostic set's netCDF stored in `.json` files in two directories\n",
"(dev and `main` branches).\n",
"\n",
"1. Make a copy of this notebook under `auxiliary_tools/cdat_regression_testing/<DIR_NAME>`.\n",
"2. Run `mamba create -n cdat_regression_test -y -c conda-forge \"python<3.12\" xarray netcdf4 dask pandas matplotlib-base ipykernel`\n",
"3. Run `mamba activate cdat_regression_test`\n",
"4. Update `SET_DIR` and `SET_NAME` in the copy of your notebook.\n",
"5. Run all cells IN ORDER.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup Code\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"\n",
"from auxiliary_tools.cdat_regression_testing.utils import get_image_diffs\n",
"\n",
"SET_NAME = \"mp_partition\"\n",
"SET_DIR = \"871-mp-partition\"\n",
"\n",
"DEV_PATH = f\"/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/{SET_DIR}/{SET_NAME}/**\"\n",
"DEV_GLOB = sorted(glob.glob(DEV_PATH + \"/*.png\"))\n",
"DEV_NUM_FILES = len(DEV_GLOB)\n",
"\n",
"MAIN_PATH = f\"/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/{SET_NAME}/**\"\n",
"MAIN_GLOB = sorted(glob.glob(MAIN_PATH + \"/*.png\"))\n",
"MAIN_NUM_FILES = len(MAIN_GLOB)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def _check_if_files_found():\n",
" if DEV_NUM_FILES == 0 or MAIN_NUM_FILES == 0:\n",
" raise IOError(\n",
" \"No files found at DEV_PATH and/or MAIN_PATH. \"\n",
" f\"Please check {DEV_PATH} and {MAIN_PATH}.\"\n",
" )\n",
"\n",
"\n",
"def _check_if_matching_filecount():\n",
" if DEV_NUM_FILES != MAIN_NUM_FILES:\n",
" raise IOError(\n",
" \"Number of files do not match at DEV_PATH and MAIN_PATH \"\n",
" f\"({DEV_NUM_FILES} vs. {MAIN_NUM_FILES}).\"\n",
" )\n",
"\n",
" print(f\"Matching file count ({DEV_NUM_FILES} and {MAIN_NUM_FILES}).\")\n",
"\n",
"\n",
"def _check_if_missing_files():\n",
" missing_count = 0\n",
"\n",
" for fp_main in MAIN_GLOB:\n",
" fp_dev = fp_main.replace(SET_DIR, \"main\")\n",
"\n",
" if fp_dev not in MAIN_GLOB:\n",
" print(f\"No production file found to compare with {fp_dev}!\")\n",
" missing_count += 1\n",
"\n",
" for fp_dev in DEV_GLOB:\n",
" fp_main = fp_main.replace(\"main\", SET_DIR)\n",
"\n",
" if fp_main not in DEV_GLOB:\n",
" print(f\"No development file found to compare with {fp_main}!\")\n",
" missing_count += 1\n",
"\n",
" print(f\"Number of files missing: {missing_count}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Check for matching and equal number of files\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"_check_if_files_found()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of files missing: 0\n"
]
}
],
"source": [
"_check_if_missing_files()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matching file count (1 and 1).\n"
]
}
],
"source": [
"_check_if_matching_filecount()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2 Compare the plots between branches\n",
"\n",
"- Compare \"ref\" and \"test\" files\n",
"- \"diff\" files are ignored because getting relative diffs for these does not make sense (relative diff will be above tolerance)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Comparing:\n",
" * /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/main/mp_partition/mixed-phase_partition/mixed-phase_partition.png\n",
" * /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/871-mp-partition/mp_partition/mixed-phase_partition/mixed-phase_partition.png\n",
" * Difference path /global/cfs/cdirs/e3sm/www/cdat-migration-fy24/871-mp-partition/mp_partition/mixed-phase_partition_diff/mixed-phase_partition.png\n"
]
}
],
"source": [
"for main_path, dev_path in zip(MAIN_GLOB, DEV_GLOB):\n",
" print(\"Comparing:\")\n",
" print(f\" * {main_path}\")\n",
" print(f\" * {dev_path}\")\n",
"\n",
" get_image_diffs(dev_path, main_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Results\n",
"\n",
"All plots are identical\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from auxiliary_tools.cdat_regression_testing.base_run_script import run_set

SET_NAME = "mp_partition"
SET_DIR = "871-mp-partition"
CFG_PATH: str | None = None
MULTIPROCESSING = True

run_set(SET_NAME, SET_DIR, CFG_PATH, MULTIPROCESSING)
Loading
Loading