{
"cells": [
{
"cell_type": "markdown",
"id": "673f28e9",
"metadata": {
"tags": [
"papermill-error-cell-tag"
]
},
"source": [
"An Exception was encountered at 'In [5]'."
]
},
{
"cell_type": "markdown",
"id": "0baa957d",
"metadata": {
"papermill": {
"duration": 0.00255,
"end_time": "2026-08-26T20:27:16.167718+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.165168+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": "a9fc643d",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:27:16.171868Z",
"iopub.status.busy": "2026-08-26T20:27:16.171634Z",
"iopub.status.idle": "2026-08-26T20:27:16.934224Z",
"shell.execute_reply": "2026-08-26T20:27:16.933345Z"
},
"papermill": {
"duration": 0.766113,
"end_time": "2026-08-26T20:27:16.935484+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.169371+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": "f2b910e8",
"metadata": {
"papermill": {
"duration": 0.001502,
"end_time": "2026-08-26T20:27:16.939366+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.937864+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": "ee7d3e31",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:27:16.943876Z",
"iopub.status.busy": "2026-08-26T20:27:16.943299Z",
"iopub.status.idle": "2026-08-26T20:27:16.946547Z",
"shell.execute_reply": "2026-08-26T20:27:16.946045Z"
},
"papermill": {
"duration": 0.006154,
"end_time": "2026-08-26T20:27:16.947012+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.940858+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": "b768f45f",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:27:16.950998Z",
"iopub.status.busy": "2026-08-26T20:27:16.950818Z",
"iopub.status.idle": "2026-08-26T20:27:16.953752Z",
"shell.execute_reply": "2026-08-26T20:27:16.953318Z"
},
"papermill": {
"duration": 0.005831,
"end_time": "2026-08-26T20:27:16.954420+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.948589+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",
"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": "0a8805d0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:27:16.958318Z",
"iopub.status.busy": "2026-08-26T20:27:16.958147Z",
"iopub.status.idle": "2026-08-26T20:27:16.960883Z",
"shell.execute_reply": "2026-08-26T20:27:16.960354Z"
},
"papermill": {
"duration": 0.005271,
"end_time": "2026-08-26T20:27:16.961320+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.956049+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": "a6b36b53",
"metadata": {
"papermill": {
"duration": 0.001484,
"end_time": "2026-08-26T20:27:16.964432+00:00",
"exception": false,
"start_time": "2026-08-26T20:27:16.962948+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": "eb9b706d",
"metadata": {
"tags": [
"papermill-error-cell-tag"
]
},
"source": [
"Execution using papermill encountered an exception here and stopped:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9fb8414d",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-26T20:27:16.968331Z",
"iopub.status.busy": "2026-08-26T20:27:16.968152Z",
"iopub.status.idle": "2026-08-26T20:27:17.057787Z",
"shell.execute_reply": "2026-08-26T20:27:17.057114Z"
},
"papermill": {
"duration": 0.092572,
"end_time": "2026-08-26T20:27:17.058520+00:00",
"exception": true,
"start_time": "2026-08-26T20:27:16.965948+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.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 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.n30b23MM.506.20260821' 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": "8fbfa7cb",
"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": "ccda0553",
"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": "54a30831",
"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": 2.236735,
"end_time": "2026-08-26T20:27:17.475800+00:00",
"exception": true,
"input_path": "/tmp/tmpwr23l6gb.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.n30b23MM.506.20260821",
"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:27:15.239065+00:00"
}
},
"nbformat": 4,
"nbformat_minor": 5
}