You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mostly written by @mvdebolskiy — I just prettified it a bit. It’s now possible to run ADF from the terminal with arguments.
Just copy the script at the end of this comment and place it in your ADF folder. You’ll need to provide a config yaml file, but it will create a new one rather than overwrite your default.
The script can, of course, be modified to include paths to cases, check whether the data and years exist, or incorporate any additional information you may want to add.
Just sharing this as an example, won’t really be able to provide ADF support.
It is also possible to provide multiple cases (but analyzed for the same years and with the same ref case / or towards observations), but it can be of course by improved
The script (We called it cmd_adf , but feel free to call it whatever you want ):
#!/usr/bin/env python3
import yaml
import sys
import argparse
import os
import re
def main():
parser = argparse.ArgumentParser(description="Run adf_diag over multiple cases")
parser.add_argument("--base-config","-b", type=str, default=None, help="base yaml config, required")
parser.add_argument("casenames",type=str,nargs="+",help="Case names (at least one; multiple allowed)")
parser.add_argument("--dry-run","-d", action="store_true")
parser.add_argument("--sy", type=int,help="Case start year (optional).")
parser.add_argument("--ey", type=int,help="Case end year (optional).")
parser.add_argument("--ref-case", type=str, help="Reference case (optional). If not given, 'obs' is used.")
parser.add_argument("--ref-sy", type=int,help="Reference case start year (optional).")
parser.add_argument("--ref-ey", type=int,help="Reference case end year (optional).")
args=parser.parse_args()
re.compile(r'\$\{[a-z_\.\d]+\}')
if not args.base_config:
print("No base config file provided")
sys.exit(1)
else:
bsname=args.base_config.replace(".yaml","")
with open(args.base_config, encoding='UTF-8') as fil:
yml = yaml.load(fil, Loader=yaml.SafeLoader)
print(yml["diag_cam_climo"]["cam_case_name"])
print(yml["diag_cam_climo"]['cam_hist_loc'])
for case in args.casenames:
ymlc=yml
ymlc["diag_cam_climo"]["cam_case_name"]=case
if args.sy:
ymlc["diag_cam_climo"]["start_year"]=args.sy
if args.ey:
ymlc["diag_cam_climo"]["end_year"]=args.ey
if args.ref_case:
ymlc["diag_cam_baseline_climo"]["cam_case_name"] = args.ref_case
if args.ref_sy:
ymlc["diag_cam_baseline_climo"]["start_year"] = args.ref_sy
if args.ref_ey:
ymlc["diag_cam_baseline_climo"]["end_year"] = args.ref_ey
else:
ymlc["diag_basic_info"]["compare_obs"] = True
hist_loc=ymlc["diag_cam_climo"]["cam_hist_loc"]
hlreg=re.compile(r'\$\{[a-z_\.\d]+\}')
tmpm=re.sub(hlreg,case,hist_loc,count=0,flags=0)
case_conf=None
if not os.path.isdir(tmpm):
print(f"WARNING: Case {case} does not have cam history at {tmpm}")
print(f"Ignoring {case}")
else:
case_conf=f"{bsname}_{case}.yaml"
cmd=f"./run_adf_diag {case_conf}"
if not args.dry_run:
with open(case_conf, 'w') as file:
yaml.dump(ymlc, file, sort_keys=False)
os.system(cmd)
else:
print(f"Will create {case_conf}")
yaml.dump(ymlc, file, sort_keys=False)
print(f"Will run: {cmd}")
if __name__ == "__main__":
main()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Mostly written by @mvdebolskiy — I just prettified it a bit. It’s now possible to run ADF from the terminal with arguments.
Just copy the script at the end of this comment and place it in your ADF folder. You’ll need to provide a config yaml file, but it will create a new one rather than overwrite your default.
The script can, of course, be modified to include paths to cases, check whether the data and years exist, or incorporate any additional information you may want to add.
Just sharing this as an example, won’t really be able to provide ADF support.
For example:
and if the ref case is not provided, it will compare against observations:
It is also possible to provide multiple cases (but analyzed for the same years and with the same ref case / or towards observations), but it can be of course by improved
The script (We called it
cmd_adf, but feel free to call it whatever you want ):All reactions