Skip to content

Commit

Permalink
Merge pull request NCAR#154 from mnlevy1981/ADF_in_key_metrics
Browse files Browse the repository at this point in the history
Adf in key metrics
  • Loading branch information
mnlevy1981 authored Dec 5, 2024
2 parents bc9b06f + 5c20647 commit 04ba5eb
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 14 deletions.
1 change: 1 addition & 0 deletions environments/cupid-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- python==3.11.4
- uxarray
- xarray
- xesmf
- yaml
- zarr
- pip:
Expand Down
2 changes: 1 addition & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
externals
*/ADF_output
6 changes: 3 additions & 3 deletions examples/external_diag_packages/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ timeseries:
atm:
vars: ['PSL']
derive_vars: []
hist_str: 'h0a'
hist_str: 'cam.h0a'
start_years: [1,1]
end_years: [100,100]
level: 'lev'
Expand Down Expand Up @@ -115,12 +115,12 @@ compute_notebooks:
parameter_groups:
none:
adf_root: ../../examples/external_diag_packages/ADF_output/
case_year_range: "1_100"
base_case_year_range: "1995_2006"
external_tool:
tool_name: 'ADF'
vars: ['PRECT', 'SST']
plotting_scripts: ["global_latlon_map", "global_latlon_vect_map"]
analysis_scripts: ["amwg_table"]
base_regridded_output: True

# glc:
# LIWG_SMB_diagnostic:
Expand Down
14 changes: 13 additions & 1 deletion examples/key_metrics/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ timeseries:
atm:
vars: ['PSL']
derive_vars: []
hist_str: 'h0a'
hist_str: 'cam.h0a'
start_years: [1,1]
end_years: [100,100]
level: 'lev'
Expand Down Expand Up @@ -124,6 +124,17 @@ compute_notebooks:
regridded_output: False # it looks like output is already on f09 grid, didn't need to regrid time-series file
base_regridded_output: True
validation_path: '/glade/campaign/cesm/development/cross-wg/diagnostic_framework/nmse_validation/fv0.9x1.25'
link_to_ADF:
kernel_name: cupid-infrastructure
parameter_groups:
none:
adf_root: ../../examples/key_metrics/ADF_output/
external_tool:
tool_name: 'ADF'
vars: ['SST', 'TS', 'SWCF', 'LWCF', 'PRECT', 'TAUX', 'TAUY', 'TGCLDLWP']
plotting_scripts: ["global_latlon_map", "global_latlon_vect_map"]
analysis_scripts: ["amwg_table"]
base_regridded_output: True

glc:
Greenland_SMB_visual_compare_obs:
Expand Down Expand Up @@ -211,6 +222,7 @@ book_toc:
- caption: Atmosphere
chapters:
- file: atm/Global_PSL_NMSE_compare_obs_lens
- file: atm/link_to_ADF

# - caption: Ocean
# chapters:
Expand Down
1 change: 1 addition & 0 deletions helper_scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.yml
45 changes: 45 additions & 0 deletions helper_scripts/generate_adf_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
"proc",
"climo",
)
# UPDATE PATHS FOR REGRIDDED DATA
try:
if c_dict["compute_notebooks"]["atm"]["link_to_ADF"]["external_tool"][
"regridded_output"
]:
a_dict["diag_cam_climo"]["cam_hist_loc"] = os.path.join(
a_dict["diag_cam_climo"]["cam_hist_loc"],
"regrid",
)
a_dict["diag_cam_climo"]["cam_ts_loc"] = os.path.join(
a_dict["diag_cam_climo"]["cam_ts_loc"],
"regrid",
)
a_dict["diag_cam_climo"]["cam_climo_loc"] = os.path.join(
a_dict["diag_cam_climo"]["cam_climo_loc"],
"regrid",
)
except: # noqa: E722
pass
# TEST CASE START / END YEARS
test_case_cupid_ts_index = (
ts_case_names.index(test_case_name) if test_case_name in ts_case_names else None
Expand Down Expand Up @@ -158,6 +177,24 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
"proc",
"climo",
)
try:
if c_dict["compute_notebooks"]["atm"]["link_to_ADF"]["external_tool"][
"base_regridded_output"
]:
a_dict["diag_cam_baseline_climo"]["cam_hist_loc"] = os.path.join(
a_dict["diag_cam_baseline_climo"]["cam_hist_loc"],
"regrid",
)
a_dict["diag_cam_baseline_climo"]["cam_ts_loc"] = os.path.join(
a_dict["diag_cam_baseline_climo"]["cam_ts_loc"],
"regrid",
)
a_dict["diag_cam_baseline_climo"]["cam_climo_loc"] = os.path.join(
a_dict["diag_cam_baseline_climo"]["cam_climo_loc"],
"regrid",
)
except: # noqa: E722
pass
a_dict["diag_cam_baseline_climo"]["start_year"] = base_start_date
a_dict["diag_cam_baseline_climo"]["end_year"] = base_end_date

Expand All @@ -179,6 +216,7 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
a_dict["user"] = os.environ["USER"]

diag_var_list = []
analysis_scripts = []
plotting_scripts = []
for component in c_dict["compute_notebooks"]:
for nb in c_dict["compute_notebooks"][component]:
Expand All @@ -195,11 +233,18 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
diag_var_list.append(var)
for script in c_dict["compute_notebooks"][component][nb][
"external_tool"
].get("analysis_scripts", []):
if script not in analysis_scripts:
analysis_scripts.append(script)
for script in c_dict["compute_notebooks"][component][nb][
"external_tool"
].get("plotting_scripts", []):
if script not in plotting_scripts:
plotting_scripts.append(script)
if diag_var_list:
a_dict["diag_var_list"] = diag_var_list
if analysis_scripts:
a_dict["analysis_scripts"] = analysis_scripts
if plotting_scripts:
a_dict["plotting_scripts"] = plotting_scripts

Expand Down
96 changes: 88 additions & 8 deletions nblibrary/atm/link_to_ADF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"outputs": [],
"source": [
"import os\n",
"\n",
"from IPython.core.display import HTML, Image\n",
"from IPython.display import display"
"from IPython.display import display\n",
"import pandas as pd"
]
},
{
Expand All @@ -59,21 +61,77 @@
"adf_root = \".\"\n",
"case_name = None\n",
"base_case_name = None\n",
"case_year_range = None\n",
"base_case_year_range = None\n",
"start_date = \"\"\n",
"end_date = \"\"\n",
"base_start_date = None\n",
"base_end_date = None\n",
"# adf_root will be external_diag_packages/computed_notebooks/ADF/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81bf4573-8806-486f-a2f6-79e244415c07",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"# Want some base case parameter defaults to equal control case values\n",
"if base_case_name is not None:\n",
" if base_start_date is None:\n",
" base_start_date = start_date\n",
"\n",
" if base_end_date is None:\n",
" base_end_date = end_date"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4104f878-a8c3-4d0f-8c00-555e6b2b3273",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"# convert start-date and end-date to year range\n",
"case_year_range = [int(start_date.split(\"-\")[0]), int(end_date.split(\"-\")[0]) - 1]\n",
"\n",
"base_case_year_range = [\n",
" int(base_start_date.split(\"-\")[0]),\n",
" int(base_end_date.split(\"-\")[0]) - 1,\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee0774cc-c68a-4385-b94c-08fa806f28c0",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"adf_comparison_name = (\n",
" f\"{case_name}_{case_year_range}_vs_{base_case_name}_{base_case_year_range}\"\n",
")\n",
"adf_comparison_name = f\"{case_name}_{case_year_range[0]}_{case_year_range[1]}_vs_{base_case_name}_{base_case_year_range[0]}_{base_case_year_range[1]}\"\n",
"adf_root = os.path.join(adf_root, adf_comparison_name)\n",
"display(\n",
" HTML(\n",
Expand All @@ -88,7 +146,29 @@
"metadata": {},
"source": [
"## Key Metrics from ADF\n",
"These will eventually be put in the key_metrics example, but are a proof of concept of including individual plots from ADF directly linked in the JupyterBook."
"\n",
"Some important things to look at from ADF include a comparison table and a few maps:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5b02451-98ad-4089-b184-75391a262db3",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"comparison_table = os.path.join(adf_root, \"amwg_table_comp.csv\")\n",
"if os.path.isfile(comparison_table):\n",
" table = pd.read_csv(comparison_table)\n",
" display(HTML(table.to_html(index=False, float_format=\"{:6g}\".format)))"
]
},
{
Expand Down

0 comments on commit 04ba5eb

Please sign in to comment.