{
"cells": [
{
"cell_type": "markdown",
"id": "cb335a6c",
"metadata": {
"tags": [
"papermill-error-cell-tag"
]
},
"source": [
"An Exception was encountered at 'In [5]'."
]
},
{
"cell_type": "markdown",
"id": "b192e157",
"metadata": {
"papermill": {
"duration": 0.002,
"end_time": "2026-08-26T16:40:56.472230+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:56.470230+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"# Antarctic Ice Sheet thickness change vs BedMachine\n",
"This notebook compares two snapshots of Antarctic ice thickness (AIS) 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": "e2a4744c",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T16:40:56.476133Z",
"iopub.status.busy": "2026-08-26T16:40:56.475939Z",
"iopub.status.idle": "2026-08-26T16:40:57.185909Z",
"shell.execute_reply": "2026-08-26T16:40:57.185325Z"
},
"papermill": {
"duration": 0.713233,
"end_time": "2026-08-26T16:40:57.187139+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:56.473906+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": "9c89b4d0",
"metadata": {
"papermill": {
"duration": 0.001379,
"end_time": "2026-08-26T16:40:57.190569+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:57.189190+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": "9738da2f",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T16:40:57.194296Z",
"iopub.status.busy": "2026-08-26T16:40:57.194047Z",
"iopub.status.idle": "2026-08-26T16:40:57.196904Z",
"shell.execute_reply": "2026-08-26T16:40:57.196451Z"
},
"papermill": {
"duration": 0.005368,
"end_time": "2026-08-26T16:40:57.197356+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:57.191988+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": "bbbdeb43",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T16:40:57.201042Z",
"iopub.status.busy": "2026-08-26T16:40:57.200894Z",
"iopub.status.idle": "2026-08-26T16:40:57.203674Z",
"shell.execute_reply": "2026-08-26T16:40:57.203215Z"
},
"papermill": {
"duration": 0.005219,
"end_time": "2026-08-26T16:40:57.204094+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:57.198875+00:00",
"status": "completed"
},
"tags": [
"injected-parameters"
]
},
"outputs": [],
"source": [
"# Parameters\n",
"case_name = \"n1850.LM.n30b23.507.GAaxg.20260820\"\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 = \"/nird/datapeak/NS11016K/CISM/AIS/Input/Geometry/Ready\"\n",
"obs_name = \"BMA3_CISM3_sm6_v4_08000m.nc\"\n",
"subset_kwargs = {}\n",
"product = \"/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_thk_test/computed_notebooks//glc/Antarctica_thickness_diff.ipynb\"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "22c37262",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T16:40:57.207829Z",
"iopub.status.busy": "2026-08-26T16:40:57.207692Z",
"iopub.status.idle": "2026-08-26T16:40:57.210248Z",
"shell.execute_reply": "2026-08-26T16:40:57.209830Z"
},
"papermill": {
"duration": 0.005048,
"end_time": "2026-08-26T16:40:57.210790+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:57.205742+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": "6f5a5573",
"metadata": {
"papermill": {
"duration": 0.001437,
"end_time": "2026-08-26T16:40:57.213716+00:00",
"exception": false,
"start_time": "2026-08-26T16:40:57.212279+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": "46e841ad",
"metadata": {
"tags": [
"papermill-error-cell-tag"
]
},
"source": [
"Execution using papermill encountered an exception here and stopped:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "0178bae7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T16:40:57.217346Z",
"iopub.status.busy": "2026-08-26T16:40:57.217174Z",
"iopub.status.idle": "2026-08-26T16:40:57.300638Z",
"shell.execute_reply": "2026-08-26T16:40:57.300053Z"
},
"papermill": {
"duration": 0.086083,
"end_time": "2026-08-26T16:40:57.301257+00:00",
"exception": true,
"start_time": "2026-08-26T16:40:57.215174+00:00",
"status": "failed"
},
"tags": [
"hide-cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No cism.ais.h file found for year 1407; skipping AIS.\n",
"No cism.ais.h file found for year 1466; skipping AIS.\n"
]
},
{
"ename": "RuntimeError",
"evalue": "AIS not present in 'n1850.LM.n30b23.507.GAaxg.20260820' 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'AIS'\u001b[39m, start_year)\n\u001b[32m 3\u001b[39m thk_end = utils.read_cesm_thk(case_path, case_name, \u001b[33m'AIS'\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\"AIS 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 AIS 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: AIS not present in 'n1850.LM.n30b23.507.GAaxg.20260820' output — skipping notebook."
]
}
],
"source": [
"# Read single-year model thickness snapshots (no time averaging)\n",
"thk_start = utils.read_cesm_thk(case_path, case_name, 'AIS', start_year)\n",
"thk_end = utils.read_cesm_thk(case_path, case_name, 'AIS', end_year)\n",
"if thk_start is None or thk_end is None:\n",
" raise RuntimeError(f\"AIS not present in {case_name!r} output — skipping notebook.\")\n",
"\n",
"# Observed present-day thickness (already regridded to the CISM AIS grid)\n",
"thk_obs = xr.open_dataset(obs_file).isel(time=0)[\"thk\"]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78f24e85",
"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": "7a0064d0",
"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": "6a4df096",
"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.900026,
"end_time": "2026-08-26T16:40:57.619183+00:00",
"exception": true,
"input_path": "/tmp/tmpn4g_r21_.ipynb",
"output_path": "/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_thk_test/computed_notebooks/glc/Antarctica_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.LM.n30b23.507.GAaxg.20260820",
"end_date": "1466-01-01",
"lc_kwargs": {
"threads_per_worker": 1
},
"obs_name": "BMA3_CISM3_sm6_v4_08000m.nc",
"obs_path": "/nird/datapeak/NS11016K/CISM/AIS/Input/Geometry/Ready",
"product": "/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_thk_test/computed_notebooks//glc/Antarctica_thickness_diff.ipynb",
"serial": false,
"start_date": "1407-01-01",
"subset_kwargs": {}
},
"start_time": "2026-08-26T16:40:55.719157+00:00"
}
},
"nbformat": 4,
"nbformat_minor": 5
}