{
"cells": [
{
"cell_type": "markdown",
"id": "8e4937eb",
"metadata": {
"tags": [
"papermill-error-cell-tag"
]
},
"source": [
"An Exception was encountered at 'In [5]'."
]
},
{
"cell_type": "markdown",
"id": "531c7a35",
"metadata": {
"papermill": {
"duration": 0.002011,
"end_time": "2026-08-26T20:26:35.843807+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:35.841796+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"# Greenland time series\n",
"This notebook plots whole-ice-sheet scalar diagnostics (GrIS) from the CISM\n",
"component history stream over the full run: ice area (grounded/floating),\n",
"ice mass (total / above flotation), and the individual mass balance flux\n",
"terms (SMB, calving, frontal melt, basal melt, grounding-line flux, and\n",
"the force-retreat / remove-icecap correction terms)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b57d3ca8",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:26:35.848148Z",
"iopub.status.busy": "2026-08-26T20:26:35.847878Z",
"iopub.status.idle": "2026-08-26T20:26:36.573530Z",
"shell.execute_reply": "2026-08-26T20:26:36.572949Z"
},
"papermill": {
"duration": 0.729236,
"end_time": "2026-08-26T20:26:36.574658+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:35.845422+00:00",
"status": "completed"
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"# Import packages\n",
"import os\n",
"\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"
]
},
{
"cell_type": "markdown",
"id": "525018c7",
"metadata": {
"papermill": {
"duration": 0.001424,
"end_time": "2026-08-26T20:26:36.578316+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:36.576892+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": "abb0b8dd",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:26:36.582091Z",
"iopub.status.busy": "2026-08-26T20:26:36.581818Z",
"iopub.status.idle": "2026-08-26T20:26:36.584517Z",
"shell.execute_reply": "2026-08-26T20:26:36.583954Z"
},
"papermill": {
"duration": 0.005627,
"end_time": "2026-08-26T20:26:36.585358+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:36.579731+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"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ba391d62",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:26:36.589918Z",
"iopub.status.busy": "2026-08-26T20:26:36.589744Z",
"iopub.status.idle": "2026-08-26T20:26:36.595023Z",
"shell.execute_reply": "2026-08-26T20:26:36.594434Z"
},
"papermill": {
"duration": 0.008365,
"end_time": "2026-08-26T20:26:36.595588+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:36.587223+00:00",
"status": "completed"
},
"tags": [
"injected-parameters"
]
},
"outputs": [],
"source": [
"# Parameters\n",
"case_name = \"n1850.LM.n30b23.507.woGAaxg.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",
"subset_kwargs = {}\n",
"product = \"/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_full_test/computed_notebooks//glc/Greenland_time_series.ipynb\"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7bf0a8cf",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:26:36.600064Z",
"iopub.status.busy": "2026-08-26T20:26:36.599817Z",
"iopub.status.idle": "2026-08-26T20:26:36.602658Z",
"shell.execute_reply": "2026-08-26T20:26:36.602107Z"
},
"papermill": {
"duration": 0.005626,
"end_time": "2026-08-26T20:26:36.603126+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:36.597500+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"
]
},
{
"cell_type": "markdown",
"id": "80afca90",
"metadata": {
"papermill": {
"duration": 0.001443,
"end_time": "2026-08-26T20:26:36.606125+00:00",
"exception": false,
"start_time": "2026-08-26T20:26:36.604682+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## Make dataset\n",
"\n",
"Read the scalar time series over the full run and convert to the\n",
"same units used elsewhere in CUPiD's glc notebooks (Gt, Gt/yr, km2)."
]
},
{
"cell_type": "markdown",
"id": "ba4579ec",
"metadata": {
"tags": [
"papermill-error-cell-tag"
]
},
"source": [
"Execution using papermill encountered an exception here and stopped:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "423ef06d",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:26:36.609915Z",
"iopub.status.busy": "2026-08-26T20:26:36.609744Z",
"iopub.status.idle": "2026-08-26T20:26:36.698656Z",
"shell.execute_reply": "2026-08-26T20:26:36.697886Z"
},
"papermill": {
"duration": 0.091822,
"end_time": "2026-08-26T20:26:36.699424+00:00",
"exception": true,
"start_time": "2026-08-26T20:26:36.607602+00:00",
"status": "failed"
},
"tags": [
"hide-cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No cism.gris.h files found for 1407-1466; skipping GrIS.\n"
]
},
{
"ename": "RuntimeError",
"evalue": "GrIS not present in 'n1850.LM.n30b23.507.woGAaxg.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 17\u001b[39m\n\u001b[32m 13\u001b[39m scalars = utils.read_cesm_scalars(\n\u001b[32m 14\u001b[39m case_path, case_name, \u001b[33m'GrIS'\u001b[39m, start_year, end_year, AREA_VARS + MASS_VARS + FLUX_VARS,\n\u001b[32m 15\u001b[39m )\n\u001b[32m 16\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m scalars \u001b[38;5;28;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m17\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m RuntimeError(f\"GrIS not present in {case_name!r} output — skipping notebook.\")\n",
"\u001b[31mRuntimeError\u001b[39m: GrIS not present in 'n1850.LM.n30b23.507.woGAaxg.20260820' output — skipping notebook."
]
}
],
"source": [
"AREA_VARS = [\"iareag\"] # floating ice area omitted for GrIS (negligible)\n",
"MASS_VARS = [\"imass\", \"imass_above_flotation\"]\n",
"FLUX_VARS = [\n",
" \"total_smb_flux\",\n",
" \"total_calving_flux\",\n",
" \"total_frontal_melt_flux\",\n",
" \"total_bmb_flux\",\n",
" \"total_rmicecap_flux\",\n",
" \"total_forceretreat_flux\",\n",
" \"total_gl_flux\",\n",
"]\n",
"\n",
"scalars = utils.read_cesm_scalars(\n",
" case_path, case_name, 'GrIS', start_year, end_year, AREA_VARS + MASS_VARS + FLUX_VARS,\n",
")\n",
"if scalars is None:\n",
" raise RuntimeError(f\"GrIS not present in {case_name!r} output — skipping notebook.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "592a66e1",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"# Unit conversions\n",
"sec_in_yr = 60 * 60 * 24 * 365\n",
"kg_to_Gt = 1e-12\n",
"m2_to_km2 = 1e-6\n",
"\n",
"area = {v: scalars[v].data * m2_to_km2 for v in AREA_VARS}\n",
"mass = {v: scalars[v].data * kg_to_Gt for v in MASS_VARS}\n",
"flux = {v: scalars[v].data * sec_in_yr * kg_to_Gt for v in FLUX_VARS}\n",
"\n",
"# CISM time is cftime, not plottable directly; use integer years instead\n",
"time = scalars[\"time\"].dt.year.data"
]
},
{
"cell_type": "markdown",
"id": "2226bec9",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"source": [
"## Generate plots\n",
"\n",
"Three panels: ice area, ice mass, and the individual mass balance flux\n",
"terms, following the same line-plot style used for the SMB average\n",
"evolution time series."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ff4bc61e",
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"LONG_NAMES = {\n",
" \"iareag\": \"grounded ice area\",\n",
" \"iareaf\": \"floating ice area\",\n",
" \"imass\": \"total ice mass\",\n",
" \"imass_above_flotation\": \"ice mass above flotation\",\n",
" \"total_smb_flux\": \"surface mass balance\",\n",
" \"total_calving_flux\": \"calving\",\n",
" \"total_frontal_melt_flux\": \"frontal melt\",\n",
" \"total_bmb_flux\": \"basal mass balance\",\n",
" \"total_rmicecap_flux\": \"remove-icecap\",\n",
" \"total_forceretreat_flux\": \"force-retreat\",\n",
" \"total_gl_flux\": \"grounding-line flux\",\n",
"}\n",
"\n",
"# Dashed for the two removal/correction terms, dotted for grounding-line\n",
"# flux, solid for the physical mass balance terms.\n",
"FLUX_LINESTYLES = {\n",
" \"total_rmicecap_flux\": \"--\",\n",
" \"total_forceretreat_flux\": \"--\",\n",
" \"total_gl_flux\": \":\",\n",
"}\n",
"\n",
"area_colors = [\"steelblue\", \"darkorange\"]\n",
"mass_colors = [\"steelblue\", \"darkorange\"]\n",
"flux_colors = [\"#1f77b4\", \"#ff7f0e\", \"#2ca02c\", \"#d62728\", \"#9467bd\", \"#8c564b\", \"#e377c2\"]\n",
"\n",
"sizefont = 14\n",
"\n",
"fig, axes = plt.subplots(3, 1, figsize=(16, 15), sharex=True)\n",
"\n",
"plt.sca(axes[0])\n",
"for v, color in zip(AREA_VARS, area_colors):\n",
" utils.plot_line(area[v], time, line=\"-\", color=color, label=LONG_NAMES[v], linewidth=2)\n",
"axes[0].set_ylabel(\"Ice area\\n(km$^2$)\", fontsize=sizefont, fontweight=\"bold\")\n",
"axes[0].legend(loc=\"best\", fontsize=11)\n",
"axes[0].grid(True, alpha=0.3)\n",
"\n",
"plt.sca(axes[1])\n",
"for v, color in zip(MASS_VARS, mass_colors):\n",
" utils.plot_line(mass[v], time, line=\"-\", color=color, label=LONG_NAMES[v], linewidth=2)\n",
"axes[1].set_ylabel(\"Ice mass\\n(Gt)\", fontsize=sizefont, fontweight=\"bold\")\n",
"axes[1].legend(loc=\"best\", fontsize=11)\n",
"axes[1].grid(True, alpha=0.3)\n",
"\n",
"plt.sca(axes[2])\n",
"for v, color in zip(FLUX_VARS, flux_colors):\n",
" utils.plot_line(\n",
" flux[v], time, line=FLUX_LINESTYLES.get(v, \"-\"), color=color, label=LONG_NAMES[v], linewidth=2,\n",
" )\n",
"axes[2].set_ylabel(\"Mass balance fluxes\\n(Gt/yr)\", fontsize=sizefont, fontweight=\"bold\")\n",
"axes[2].legend(loc=\"best\", fontsize=10, ncol=2)\n",
"axes[2].grid(True, alpha=0.3)\n",
"axes[2].set_xlabel(r\"$Time$ (y)\", fontsize=sizefont, fontweight=\"bold\")\n",
"\n",
"fig.suptitle(f\"{case_name}\\nGreenland time series\", fontsize=sizefont)\n",
"plt.tight_layout()"
]
}
],
"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.916136,
"end_time": "2026-08-26T20:26:37.017703+00:00",
"exception": true,
"input_path": "/tmp/tmpzeuac9ae.ipynb",
"output_path": "/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_full_test/computed_notebooks/glc/Greenland_time_series.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.woGAaxg.20260820",
"end_date": "1466-01-01",
"lc_kwargs": {
"threads_per_worker": 1
},
"product": "/nird/datapeak/NS9560K/users/heig/CUPiD_Apr/examples/glc_full_test/computed_notebooks//glc/Greenland_time_series.ipynb",
"serial": false,
"start_date": "1407-01-01",
"subset_kwargs": {}
},
"start_time": "2026-08-26T20:26:35.101567+00:00"
}
},
"nbformat": 4,
"nbformat_minor": 5
}