{ "cells": [ { "cell_type": "markdown", "id": "bdb3c520", "metadata": { "tags": [ "papermill-error-cell-tag" ] }, "source": [ "An Exception was encountered at 'In [5]'." ] }, { "cell_type": "markdown", "id": "cdd1e940", "metadata": { "papermill": { "duration": 0.002157, "end_time": "2026-08-26T16:41:51.082557+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.080400+00:00", "status": "completed" }, "tags": [] }, "source": [ "# Greenland Ice Sheet thickness change vs BedMachine\n", "This notebook compares two snapshots of Greenland ice thickness (GrIS) from a CESM/CISM\n", "run to present-day observed ice thickness (BedMachine), and to each other.\n", "\\\n", "Three panels are shown: model-minus-obs at the start of the analysis period,\n", "model-minus-obs at the end of the analysis period, and end-minus-start\n", "(pure model thickness change over the period). No time averaging is\n", "performed — each panel uses single-year snapshots." ] }, { "cell_type": "code", "execution_count": 1, "id": "d43c82dd", "metadata": { "execution": { "iopub.execute_input": "2026-08-26T16:41:51.086427Z", "iopub.status.busy": "2026-08-26T16:41:51.086233Z", "iopub.status.idle": "2026-08-26T16:41:51.815218Z", "shell.execute_reply": "2026-08-26T16:41:51.814702Z" }, "papermill": { "duration": 0.732135, "end_time": "2026-08-26T16:41:51.816355+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.084220+00:00", "status": "completed" }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "# Import packages\n", "import os\n", "\n", "import xarray as xr\n", "import matplotlib.pyplot as plt\n", "\n", "from cupid_utils.glc import utils\n", "\n", "# to display figures in notebook after executing the code.\n", "%matplotlib inline\n" ] }, { "cell_type": "markdown", "id": "92905c9a", "metadata": { "papermill": { "duration": 0.00145, "end_time": "2026-08-26T16:41:51.820059+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.818609+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Parameter configuration\n", "\n", "Some parameters are set in CUPiD's `config.yml` file,\n", "others are derived from these parameters." ] }, { "cell_type": "code", "execution_count": 2, "id": "1b01617a", "metadata": { "execution": { "iopub.execute_input": "2026-08-26T16:41:51.823880Z", "iopub.status.busy": "2026-08-26T16:41:51.823582Z", "iopub.status.idle": "2026-08-26T16:41:51.826538Z", "shell.execute_reply": "2026-08-26T16:41:51.826057Z" }, "papermill": { "duration": 0.005423, "end_time": "2026-08-26T16:41:51.826948+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.821525+00:00", "status": "completed" }, "tags": [ "parameters", "hide-input" ] }, "outputs": [], "source": [ "# Parameter Defaults\n", "\n", "CESM_output_dir = \"\"\n", "case_name = \"\" # case name\n", "start_date = \"\"\n", "end_date = \"\"\n", "\n", "obs_data_dir = \"\" # global directory containing observed dataset\n", "obs_path = \"\" # specific directory containing observed dataset\n", "obs_name = \"\" # file name for observed dataset\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "837d8ff5", "metadata": { "execution": { "iopub.execute_input": "2026-08-26T16:41:51.830661Z", "iopub.status.busy": "2026-08-26T16:41:51.830519Z", "iopub.status.idle": "2026-08-26T16:41:51.833272Z", "shell.execute_reply": "2026-08-26T16:41:51.832815Z" }, "papermill": { "duration": 0.005228, "end_time": "2026-08-26T16:41:51.833717+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.828489+00:00", "status": "completed" }, "tags": [ "injected-parameters" ] }, "outputs": [], "source": [ "# Parameters\n", "case_name = \"N1850.n30b23MM.506.20260821\"\n", "base_case_name = \"\"\n", "CESM_output_dir = \"/datalake/NS9560K/noresm3/cases\"\n", "start_date = \"1407-01-01\"\n", "end_date = \"1466-01-01\"\n", "base_start_date = \"0000-01-01\"\n", "base_end_date = \"0000-01-01\"\n", "lc_kwargs = {\"threads_per_worker\": 1}\n", "serial = False\n", "obs_path = (\n", " \"/nird/datapeak/NS5011K/users/mali/CISM/GrIS/Database7/Obs/Geometry/BM6/Ready\"\n", ")\n", "obs_name = \"BM6_sm06_v1_i04000m.nc\"\n", "subset_kwargs = {}\n", "product = \"/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_thk_test/computed_notebooks//glc/Greenland_thickness_diff.ipynb\"\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "2448f660", "metadata": { "execution": { "iopub.execute_input": "2026-08-26T16:41:51.837710Z", "iopub.status.busy": "2026-08-26T16:41:51.837570Z", "iopub.status.idle": "2026-08-26T16:41:51.840018Z", "shell.execute_reply": "2026-08-26T16:41:51.839558Z" }, "papermill": { "duration": 0.004869, "end_time": "2026-08-26T16:41:51.840415+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.835546+00:00", "status": "completed" }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "start_year = int(start_date.split(\"-\")[0])\n", "end_year = int(end_date.split(\"-\")[0])\n", "\n", "case_path = os.path.join(\n", " CESM_output_dir, case_name, \"glc\", \"hist\"\n", ") # path to CISM component history output\n", "\n", "obs_file = os.path.join(\n", " obs_data_dir, obs_path, obs_name\n", ") # name of observed dataset file\n" ] }, { "cell_type": "markdown", "id": "ba6188eb", "metadata": { "papermill": { "duration": 0.001448, "end_time": "2026-08-26T16:41:51.843424+00:00", "exception": false, "start_time": "2026-08-26T16:41:51.841976+00:00", "status": "completed" }, "tags": [] }, "source": [ "## Make datasets\n", "\n", "Read in the start-year and end-year model snapshots and the observed\n", "thickness, and compute the three difference fields." ] }, { "cell_type": "markdown", "id": "01758f28", "metadata": { "tags": [ "papermill-error-cell-tag" ] }, "source": [ "Execution using papermill encountered an exception here and stopped:" ] }, { "cell_type": "code", "execution_count": 5, "id": "9fe5764d", "metadata": { "execution": { "iopub.execute_input": "2026-08-26T16:41:51.847146Z", "iopub.status.busy": "2026-08-26T16:41:51.846968Z", "iopub.status.idle": "2026-08-26T16:41:51.971002Z", "shell.execute_reply": "2026-08-26T16:41:51.970474Z" }, "papermill": { "duration": 0.126569, "end_time": "2026-08-26T16:41:51.971504+00:00", "exception": true, "start_time": "2026-08-26T16:41:51.844935+00:00", "status": "failed" }, "tags": [ "hide-cell" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No cism.gris.h file found for year 1407; skipping GrIS.\n", "No cism.gris.h file found for year 1466; skipping GrIS.\n" ] }, { "ename": "RuntimeError", "evalue": "GrIS not present in 'N1850.n30b23MM.506.20260821' output — skipping notebook.", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mRuntimeError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 5\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Read single-year model thickness snapshots (no time averaging)\u001b[39;00m\n\u001b[32m 2\u001b[39m thk_start = utils.read_cesm_thk(case_path, case_name, \u001b[33m'GrIS'\u001b[39m, start_year)\n\u001b[32m 3\u001b[39m thk_end = utils.read_cesm_thk(case_path, case_name, \u001b[33m'GrIS'\u001b[39m, end_year)\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m thk_start \u001b[38;5;28;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01mor\u001b[39;00m thk_end \u001b[38;5;28;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m----> \u001b[39m\u001b[32m5\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m RuntimeError(f\"GrIS not present in {case_name!r} output — skipping notebook.\")\n\u001b[32m 6\u001b[39m \n\u001b[32m 7\u001b[39m \u001b[38;5;66;03m# Observed present-day thickness (already regridded to the CISM GrIS grid)\u001b[39;00m\n\u001b[32m 8\u001b[39m thk_obs = xr.open_dataset(obs_file).isel(time=\u001b[32m0\u001b[39m)[\u001b[33m\"thk\"\u001b[39m]\n", "\u001b[31mRuntimeError\u001b[39m: GrIS not present in 'N1850.n30b23MM.506.20260821' output — skipping notebook." ] } ], "source": [ "# Read single-year model thickness snapshots (no time averaging)\n", "thk_start = utils.read_cesm_thk(case_path, case_name, 'GrIS', start_year)\n", "thk_end = utils.read_cesm_thk(case_path, case_name, 'GrIS', end_year)\n", "if thk_start is None or thk_end is None:\n", " raise RuntimeError(f\"GrIS not present in {case_name!r} output — skipping notebook.\")\n", "\n", "# Observed present-day thickness (already regridded to the CISM GrIS grid)\n", "thk_obs = xr.open_dataset(obs_file).isel(time=0)[\"thk\"]\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3974979a", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "# Compute the three difference fields. Obs is pre-regridded to the same\n", "# CISM grid as the model output, but x1/y1 coordinate values are not\n", "# guaranteed to be bit-identical between files, so difference on .data\n", "# directly rather than relying on xarray coordinate alignment.\n", "diff_start_obs = xr.DataArray(thk_start.data - thk_obs.data, dims=thk_start.dims)\n", "diff_end_obs = xr.DataArray(thk_end.data - thk_obs.data, dims=thk_start.dims)\n", "diff_end_start = xr.DataArray(thk_end.data - thk_start.data, dims=thk_start.dims)\n" ] }, { "cell_type": "markdown", "id": "a52737ce", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [] }, "source": [ "## Generate plots\n", "\n", "Three-panel map: model-minus-obs at the start of the period,\n", "model-minus-obs at the end of the period, and end-minus-start." ] }, { "cell_type": "code", "execution_count": null, "id": "53bb9ea4", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "pending" }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "# Comparing model thickness to observations at start/end of period, and to itself.\n", "# The obs-comparison panels (1-2) and the model-drift panel (3) get separate\n", "# color scales: model-vs-obs bias is typically O(10-100 m), while model drift\n", "# over a single run can be much smaller and would be invisible on the obs scale.\n", "# Panels 1-2 share one colorbar (same scale, like the SMB case-vs-obs maps);\n", "# panel 3 gets its own.\n", "\n", "my_cmap_diff = plt.get_cmap(\"RdBu_r\")\n", "\n", "vmin_obs = -500\n", "vmax_obs = 500\n", "\n", "vmin_drift = -50\n", "vmax_drift = 50\n", "\n", "fig, ax = plt.subplots(1, 3, sharey=True, figsize=[22, 9])\n", "\n", "utils.plot_contour_temp(\n", " diff_start_obs,\n", " fig,\n", " ax[0],\n", " f\"{case_name}\\n{start_year} minus obs\",\n", " vmin_obs,\n", " vmax_obs,\n", " my_cmap_diff,\n", " units=\"m\",\n", " left=0.35,\n", ")\n", "\n", "utils.plot_contour_temp(\n", " diff_end_obs,\n", " fig,\n", " ax[1],\n", " f\"{case_name}\\n{end_year} minus obs\",\n", " vmin_obs,\n", " vmax_obs,\n", " my_cmap_diff,\n", " units=\"m\",\n", " show_cbar=False,\n", ")\n", "\n", "utils.plot_contour_temp(\n", " diff_end_start,\n", " fig,\n", " ax[2],\n", " f\"{end_year} minus {start_year}\",\n", " vmin_drift,\n", " vmax_drift,\n", " my_cmap_diff,\n", " units=\"m\",\n", " left=0.89,\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "cupid-analysis", "language": "python", "name": "cupid-analysis" }, "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.13.11" }, "papermill": { "duration": 1.909529, "end_time": "2026-08-26T16:41:52.290390+00:00", "exception": true, "input_path": "/tmp/tmpkm1ir1bu.ipynb", "output_path": "/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_thk_test/computed_notebooks/glc/Greenland_thickness_diff.ipynb", "parameters": { "CESM_output_dir": "/datalake/NS9560K/noresm3/cases", "base_case_name": "", "base_end_date": "0000-01-01", "base_start_date": "0000-01-01", "case_name": "N1850.n30b23MM.506.20260821", "end_date": "1466-01-01", "lc_kwargs": { "threads_per_worker": 1 }, "obs_name": "BM6_sm06_v1_i04000m.nc", "obs_path": "/nird/datapeak/NS5011K/users/mali/CISM/GrIS/Database7/Obs/Geometry/BM6/Ready", "product": "/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_thk_test/computed_notebooks//glc/Greenland_thickness_diff.ipynb", "serial": false, "start_date": "1407-01-01", "subset_kwargs": {} }, "start_time": "2026-08-26T16:41:50.380861+00:00" } }, "nbformat": 4, "nbformat_minor": 5 }