Skip to content

Commit

Permalink
Cleaned up glacier notebook a little more
Browse files Browse the repository at this point in the history
1. Reorganized cells and added markdown headers (parameter configuration, set
up grid, make datasets, generate plots).
2. Fixed issue with plotting base maps (tested by comparing first 40 years of
run to last 40 years of run)
3. Added years included in climatology to the title of plots
  • Loading branch information
mnlevy1981 committed Jul 24, 2024
1 parent 3df4d5e commit f1b015d
Showing 1 changed file with 93 additions and 45 deletions.
138 changes: 93 additions & 45 deletions examples/nblibrary/glc/LIWG_SMB_diagnostic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"id": "24029ab9-fe52-4c7e-bb41-847c7f3a0b1d",
"metadata": {},
"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": null,
Expand Down Expand Up @@ -84,6 +95,16 @@
" base_file = f\"{base_case_path}/{base_case_name}.cpl.hx.1yr2glc.{base_last_year:04d}-01-01-00000.nc\" # name of last cpl simulation output"
]
},
{
"cell_type": "markdown",
"id": "70ee51c9-1c10-475d-a45b-b97583a3a5a9",
"metadata": {},
"source": [
"## Set up grid\n",
"\n",
"Read in the grid data, compute resolution and other grid-specific parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -106,25 +127,6 @@
"ny_cism = len(y_cism)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69891e0a-0cc6-48bd-a9bf-b61e19da13b4",
"metadata": {},
"outputs": [],
"source": [
"## The observed dataset\n",
"nid = Dataset(obs_file, \"r\")\n",
"x_obs = nid.variables[\"x\"][:]\n",
"y_obs = nid.variables[\"y\"][:]\n",
"smb_obs_src = np.squeeze(nid.variables[\"SMB\"][0, :, :])\n",
"nid.close()\n",
"\n",
"## For the observed grid\n",
"nx_obs = len(x_obs)\n",
"ny_obs = len(y_obs)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -155,6 +157,37 @@
"}"
]
},
{
"cell_type": "markdown",
"id": "68fca423-582b-4179-8771-16250a5f1904",
"metadata": {},
"source": [
"## Make datasets\n",
"\n",
"Read in observations and CESM output.\n",
"Also do necessary computations\n",
"(global mean for time series, temporal mean for climatology)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69891e0a-0cc6-48bd-a9bf-b61e19da13b4",
"metadata": {},
"outputs": [],
"source": [
"## The observed dataset\n",
"nid = Dataset(obs_file, \"r\")\n",
"x_obs = nid.variables[\"x\"][:]\n",
"y_obs = nid.variables[\"y\"][:]\n",
"smb_obs_src = np.squeeze(nid.variables[\"SMB\"][0, :, :])\n",
"nid.close()\n",
"\n",
"## For the observed grid\n",
"nx_obs = len(x_obs)\n",
"ny_obs = len(y_obs)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -217,6 +250,37 @@
" smb_base_climo = np.where(mask, 0, smb_base_climo)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a38682c9-dc87-4d7b-887d-8abbbe8a7265",
"metadata": {},
"outputs": [],
"source": [
"# Integrated SMB time series\n",
"params[\"mask\"] = mask\n",
"first_year, avg_smb_case_climo = utils.compute_annual_climo(\n",
" case_path, case_name, last_year, params\n",
")\n",
"\n",
"if base_case_name:\n",
" base_first_year, avg_smb_base_case_climo = utils.compute_annual_climo(\n",
" base_case_path, base_case_name, base_last_year, params\n",
" )"
]
},
{
"cell_type": "markdown",
"id": "1641747b-4997-45ad-bf70-981ed97688dd",
"metadata": {},
"source": [
"## Generate plots\n",
"\n",
"Map comparing CESM to observation,\n",
"possibly map comparing CESM to older case,\n",
"and time series of spatial mean SMB."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -243,7 +307,7 @@
" smb_case_climo,\n",
" fig,\n",
" ax[0],\n",
" f\"{case_name}\\nSMB (mm/y w.e.)\",\n",
" f\"{case_name}\\nSMB (mm/y w.e.)\\nMean from {first_year:04d} - {last_year:04d}\",\n",
" vmin,\n",
" vmax,\n",
" my_cmap,\n",
Expand Down Expand Up @@ -292,8 +356,9 @@
" ## Left panel\n",
" utils.plot_contour(\n",
" smb_case_climo,\n",
" fig,\n",
" ax[0],\n",
" f\"{case_name}\\nSMB (mm/y w.e.)\",\n",
" f\"{case_name}\\nSMB (mm/y w.e.)\\nMean from {first_year:04d} - {last_year:04d}\",\n",
" vmin,\n",
" vmax,\n",
" my_cmap,\n",
Expand All @@ -303,8 +368,9 @@
" ## Center panel\n",
" utils.plot_contour(\n",
" smb_base_climo,\n",
" fig,\n",
" ax[1],\n",
" f\"{base_case_name}\\nSMB (mm/y w.e.)\",\n",
" f\"{base_case_name}\\nSMB (mm/y w.e.)\\nMean from {base_first_year:04d} - {base_last_year:04d}\",\n",
" vmin,\n",
" vmax,\n",
" my_cmap,\n",
Expand All @@ -315,6 +381,7 @@
" utils.plot_contour_diff(\n",
" smb_case_climo,\n",
" smb_base_climo,\n",
" fig,\n",
" ax[2],\n",
" \"SMB difference (mm/yr w.e.)\",\n",
" vmin,\n",
Expand All @@ -324,25 +391,6 @@
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a38682c9-dc87-4d7b-887d-8abbbe8a7265",
"metadata": {},
"outputs": [],
"source": [
"# Integrated SMB time series\n",
"params[\"mask\"] = mask\n",
"first_year, avg_smb_case_climo = utils.compute_annual_climo(\n",
" case_path, case_name, last_year, params\n",
")\n",
"\n",
"if base_case_name:\n",
" base_first_year, avg_smb_base_case_climo = utils.compute_annual_climo(\n",
" base_case_path, base_case_name, base_last_year, params\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -392,15 +440,15 @@
" time,\n",
" line=\"-\",\n",
" color=\"blue\",\n",
" label=f\"{case_name}\",\n",
" label=f\"{case_name} ({first_year:04d} - {last_year:04d})\",\n",
" linewidth=2,\n",
")\n",
"utils.plot_line(\n",
" avg_smb_case_timeseries[:],\n",
" time,\n",
" line=\":\",\n",
" color=\"blue\",\n",
" label=f\"{case_name} (mean)\",\n",
" label=f\"{case_name} (mean from {first_year:04d} - {last_year:04d})\",\n",
" linewidth=2,\n",
")\n",
"if base_case_name:\n",
Expand All @@ -409,15 +457,15 @@
" base_time,\n",
" line=\"-\",\n",
" color=\"red\",\n",
" label=f\"{base_case_name}\",\n",
" label=f\"{base_case_name} ({base_first_year:04d} - {base_last_year:04d})\",\n",
" linewidth=2,\n",
" )\n",
" utils.plot_line(\n",
" avg_smb_base_timeseries[:],\n",
" base_time,\n",
" line=\":\",\n",
" color=\"red\",\n",
" label=f\"{base_case_name} (mean)\",\n",
" label=f\"{base_case_name} (mean from {base_first_year:04d} - {base_last_year:04d})\",\n",
" linewidth=2,\n",
" )\n",
"utils.plot_line(\n",
Expand Down

0 comments on commit f1b015d

Please sign in to comment.