-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include ILAMB output in notebook and provide link to full diagnostic package #165
base: main
Are you sure you want to change the base?
Changes from 24 commits
daafc0b
eae2ea4
dcfc44a
2e72ef3
39d155a
6fa116d
df797d1
caa2598
2b2ccf1
7f68daa
c18fd96
efb9bc3
96de2d4
576d629
aadfbd1
718d4ed
b726b7d
3ba5df7
5e66869
927780b
b1f14a8
65b8a6c
cf71813
20d8b76
6dcbe48
b5ee7fa
4c8c87f
28d6771
c07722e
cab3e5b
cec63e3
38964d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*/ADF_output | ||
*/ILAMB_output | ||
*/model_setup.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,58 +115,24 @@ compute_notebooks: | |
parameter_groups: | ||
none: | ||
adf_root: ../../examples/external_diag_packages/ADF_output/ | ||
key_plots: ["Surface_Wind_Stress_ANN_LatLon_Vector_Mean.png", "PRECT_ANN_LatLon_Mean.png", "PS_DJF_SHPolar_Mean.png", "TaylorDiag_ANN_Special_Mean.png"] | ||
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: | ||
# parameter_groups: | ||
# none: | ||
# obs_path: '/glade/u/home/gunterl/obs_diagnostic_cesm/' | ||
# obs_name: 'GrIS_MARv3.12_climo_1960_1999.nc' | ||
# climo_nyears: 40 | ||
|
||
# ice: | ||
# seaice: | ||
# parameter_groups: | ||
# none: | ||
# cases: | ||
# - g.e23_a16g.GJRAv4.TL319_t232_hycom1_N75.2024.005 | ||
# - g.e23_a16g.GJRAv4.TL319_t232_zstar_N65.2024.004 | ||
# begyr1: 245 | ||
# endyr1: 305 | ||
# begyr2: 245 | ||
# endyr2: 305 | ||
# nyears: 25 | ||
|
||
# lnd: | ||
# land_comparison: | ||
# parameter_groups: | ||
# none: | ||
# cases: | ||
# - ctsm51d159_f45_GSWP3_bgccrop_1850pAD | ||
# - ctsm51d159_f45_GSWP3_bgccrop_1850pSASU | ||
# type: | ||
# - 1850pAD | ||
# - 1850pSASU | ||
|
||
# ocn: | ||
# ocean_surface: | ||
# parameter_groups: | ||
# none: | ||
# Case: b.e23_alpha16b.BLT1850.ne30_t232.054 | ||
# savefigs: False | ||
# mom6_tools_config: | ||
# start_date: '0091-01-01' | ||
# end_date: '0101-01-01' | ||
# Fnames: | ||
# native: 'mom6.h.native.????-??.nc' | ||
# static: 'mom6.h.static.nc' | ||
# oce_cat: /glade/u/home/gmarques/libs/oce-catalogs/reference-datasets.yml | ||
lnd: | ||
link_to_ILAMB: | ||
parameter_groups: | ||
none: | ||
ilamb_root: ../../examples/external_diag_packages/ILAMB_output | ||
key_plots: ["EcosystemandCarbonCycle/GrossPrimaryProductivity/FLUXCOM/CTSM51_global_bias.png", "EcosystemandCarbonCycle/LeafAreaIndex/AVHRR/CTSM51_global_bias.png", "EcosystemandCarbonCycle/GlobalNetEcosystemCarbonBalance/GCP/CTSM51_global_accumulate.png", "ILAMB_output_backup/HydrologyCycle/Permafrost/Brown2002/CTSM51_global_bias.png"] | ||
print_table: False | ||
external_tool: | ||
tool_name: 'ILAMB' | ||
ilamb_config_data_loc: '/glade/campaign/cesm/community/lmwg/diag/ILAMB/' | ||
|
||
########### JUPYTER BOOK CONFIG ########### | ||
|
||
|
@@ -192,23 +158,11 @@ book_toc: | |
|
||
- caption: Atmosphere | ||
chapters: | ||
- file: atm/link_to_ADF | ||
|
||
# - caption: Ocean | ||
# chapters: | ||
# - file: ocn/ocean_surface | ||
- file: atm/link_to_ADF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the spacing changed here? comparing old line 195 to new line 161 I see - - file: atm/link_to_ADF
+ - file: atm/link_to_ADF |
||
|
||
# - caption: Land | ||
# chapters: | ||
# - file: lnd/land_comparison | ||
|
||
# - caption: Sea Ice | ||
# chapters: | ||
# - file: ice/seaice | ||
|
||
# - caption: Land Ice | ||
# chapters: | ||
# - file: glc/LIWG_SMB_diagnostic | ||
- caption: Land | ||
chapters: | ||
- file: lnd/link_to_ILAMB | ||
|
||
##################################### | ||
# Keys for Jupyter Book _config.yml # | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ compute_notebooks: | |
parameter_groups: | ||
none: | ||
adf_root: ../../examples/key_metrics/ADF_output/ | ||
key_plots: ["Surface_Wind_Stress_ANN_LatLon_Vector_Mean.png", "PRECT_ANN_LatLon_Mean.png", "PS_DJF_SHPolar_Mean.png", "TaylorDiag_ANN_Special_Mean.png"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised these weren't already included in the |
||
external_tool: | ||
tool_name: 'ADF' | ||
vars: ['SST', 'TS', 'SWCF', 'LWCF', 'PRECT', 'TAUX', 'TAUY', 'TGCLDLWP'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*.cfg | ||
*.txt | ||
*.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/usr/bin/env python3 | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
import yaml | ||
|
||
|
||
def _parse_args(): | ||
"""Parse command line arguments""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Generate an ILAMB model_setup.txt file based on an existing CUPID YAML file", | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
) | ||
# Command line argument for location of CESM source code (required) | ||
parser.add_argument( | ||
"--cesm-root", | ||
action="store", | ||
dest="cesm_root", | ||
required=True, | ||
help="Location of CESM source code", | ||
) | ||
# Command line argument for CUPiD example from which to get config.yml | ||
parser.add_argument( | ||
"--cupid-config-loc", | ||
action="store", | ||
dest="cupid_config_loc", | ||
default=None, | ||
help="CUPiD config file to use information from for model_setup.txt", | ||
) | ||
parser.add_argument( | ||
"--run-type", | ||
action="store", | ||
required=True, | ||
help="either 'BGC' (biogeochemistry) or 'SP' (satellite phenology)", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def generate_ilamb_cfg(cesm_root, cupid_config_loc, run_type): | ||
"""Create config file for use in ILAMB""" | ||
sys.path.append(os.path.join(cesm_root, "cime")) | ||
|
||
cupid_root = os.path.join(cesm_root, "tools", "CUPiD") | ||
# Is cupid_config_loc a valid value? | ||
if cupid_config_loc is None: | ||
cupid_config_loc = os.path.join(cupid_root, "examples", "key_metrics") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this default be |
||
if not os.path.exists(os.path.join(cupid_config_loc, "config.yml")): | ||
raise KeyError(f"Can not find config.yml in {cupid_config_loc}") | ||
|
||
with open(os.path.join(cupid_config_loc, "config.yml")) as c: | ||
c_dict = yaml.safe_load(c) | ||
ilamb_config_data_loc = c_dict["compute_notebooks"]["lnd"]["link_to_ILAMB"][ | ||
"external_tool" | ||
]["ilamb_config_data_loc"] | ||
|
||
ilamb_config_loc = os.path.join(cesm_root, "tools", "CUPiD", "ilamb_aux") | ||
print(run_type) | ||
with open( | ||
os.path.join( | ||
ilamb_config_loc, | ||
f"ilamb_nohoff_final_CLM_{run_type}_template.cfg", | ||
), | ||
) as cfg: | ||
cfg_content = cfg.read() | ||
cfg_content = cfg_content.replace("PATH/", ilamb_config_data_loc) | ||
print(f"writing ilamb_nohoff_final_CLM_{run_type}.cfg") | ||
with open( | ||
os.path.join(ilamb_config_loc, f"ilamb_nohoff_final_CLM_{run_type}.cfg"), | ||
"w", | ||
) as cfg: | ||
cfg.write(cfg_content) | ||
print(f"wrote {ilamb_config_loc}/ilamb_nohoff_final_CLM_{run_type}.cfg") | ||
|
||
|
||
def generate_ilamb_model_setup(cesm_root, cupid_config_loc, run_type): | ||
"""Create model_setup.txt file for use in ILAMB""" | ||
sys.path.append(os.path.join(cesm_root, "cime")) | ||
|
||
cupid_root = os.path.join(cesm_root, "tools", "CUPiD") | ||
# Is cupid_config_loc a valid value? | ||
if cupid_config_loc is None: | ||
cupid_config_loc = os.path.join(cupid_root, "examples", "key_metrics") | ||
if not os.path.exists(os.path.join(cupid_config_loc, "config.yml")): | ||
raise KeyError(f"Can not find config.yml in {cupid_config_loc}") | ||
|
||
with open(os.path.join(cupid_config_loc, "config.yml")) as c: | ||
c_dict = yaml.safe_load(c) | ||
base_case_output_dir = os.path.join( | ||
c_dict["global_params"]["CESM_output_dir"], | ||
c_dict["global_params"]["base_case_name"], | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the spec, users can specify if "base_case_output_dir" in c_dict["global_params"]:
base_case_output_dir = os.path.join(
c_dict["global_params"]["base_case_output_dir"],
c_dict["global_params"]["base_case_name"],
)
else:
base_case_output_dir = os.path.join(
c_dict["global_params"]["CESM_output_dir"],
c_dict["global_params"]["base_case_name"],
) |
||
with open(cupid_config_loc + "model_setup.txt", "w") as ms: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
ms.write( | ||
"# Model Name , Location of Files , Shift From, Shift To\n", # noqa: E501 | ||
) | ||
ms.write( | ||
f"CTSM51 , {base_case_output_dir}/lnd/hist/regrid/", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should add some sort of "if regrid" then append the regrid directory here. Perhaps this would be useful to in the long term create the regridded files if they don't yet exist, and in the short term print out a "warning: please run regridding with command below" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a note that regridded files are required |
||
) # TODO: aslo update model name? Add to cupid config file? | ||
print(f"wrote {cupid_config_loc}model_setup.txt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about using |
||
print("You can now run ILAMB with the following commands:") | ||
print("---") | ||
print("qinteractive -l select=1:ncpus=16:mpiprocs=16:mem=100G -l walltime=06:00:00") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The print("You can now run ILAMB with the following commands:")
print("(Users on a super computer should make sure they are on a compute node rather than a login node)")
print("---") I'm not sure what to do about the fact that we're having trouble with MPI on derecho and casper; in general, users will need the |
||
print("conda activate cupid-analysis") | ||
print("export ILAMB_ROOT=../ilamb_aux") | ||
if run_type == "SP": | ||
print( | ||
f"ilamb-run --config ../ilamb_aux/ilamb_nohoff_final_CLM_SP.cfg --build_dir {cupid_config_loc}ILAMB_output/ --df_errs ../ilamb_aux/quantiles_Whittaker_cmip5v6.parquet --define_regions ../ilamb_aux/DATA/regions/LandRegions.nc ../ilamb_aux/DATA/regions/Whittaker.nc --regions global --model_setup {cupid_config_loc}odel_setup.txt --filter .clm2.h0.", # noqa: E501 | ||
TeaganKing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
elif run_type == "BGC": | ||
print( | ||
f"ilamb-run --config ../ilamb_aux/ilamb_nohoff_final_CLM_BGC.cfg --build_dir {cupid_config_loc}ILAMB_output/ --df_errs ../ilamb_aux/quantiles_Whittaker_cmip5v6.parquet --define_regions ../ilamb_aux/DATA/regions/LandRegions.nc ../ilamb_aux/DATA/regions/Whittaker.nc --regions global --model_setup {cupid_config_loc}model_setup.txt --filter .clm2.h0.", # noqa: E501 | ||
) | ||
print("---------") | ||
|
||
|
||
if __name__ == "__main__": | ||
args = vars(_parse_args()) | ||
print(args) | ||
generate_ilamb_cfg(args["cesm_root"], args["cupid_config_loc"], args["run_type"]) | ||
generate_ilamb_model_setup( | ||
args["cesm_root"], | ||
args["cupid_config_loc"], | ||
args["run_type"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ilamb_nohoff_final_CLM_BGC.cfg | ||
ilamb_nohoff_final_CLM_SP.cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think line 63 is necessary, it's the same if statement as line 51. Removing it will let us change the current line 64 to an else-if, since
control["compute_notebooks"][component][notebook]["external_tool"].get("tool_name")
can't be"ILAMB"
if it is"ADF"
.