Skip to content

Commit

Permalink
Allow config.aero to be modified by the machine yamls
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidHuber-NOAA committed Nov 6, 2024
1 parent 4ad195f commit fc75a22
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion ci/cases/yamls/ufs_hybatmDA_defaults.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ nsst:
NST_MODEL: "1"
sfcanl:
DONST: "NO"

4 changes: 4 additions & 0 deletions parm/config/gfs/yaml/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ prepoceanobs:
OBSPREP_YAML: "${PARMgfs}/gdas/soca/obsprep/obsprep_config.yaml"
use_exp_obs: "YES"
dmpdir_exp: "${BASE_DATA}/experimental_obs"

# config.aero has just a system-specific path to add.
# This is handled by the setup_expt.py, but it has to be told to write to it.
aero: {}
30 changes: 19 additions & 11 deletions workflow/setup_expt.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def _update_defaults(dict_in: dict) -> dict:
stage_dict = dict(stage_dict, **host_dict)
stage_input = f'{inputs.configdir}/config.stage_ic'
stage_output = f'{inputs.expdir}/{inputs.pslot}/config.stage_ic'
edit_config(stage_input, stage_output, stage_dict)
edit_config(stage_input, stage_output, host_dict, stage_dict)

# Loop over other configs and update them with defaults
for cfg in yaml_dict.keys():
if cfg == 'base':
continue
cfg_file = f'{inputs.expdir}/{inputs.pslot}/config.{cfg}'
cfg_dict = get_template_dict(yaml_dict[cfg])
edit_config(cfg_file, cfg_file, cfg_dict)
edit_config(cfg_file, cfg_file, host_dict, cfg_dict)

return

Expand Down Expand Up @@ -146,24 +146,24 @@ def edit_baseconfig(host, inputs, yaml_dict):
if 'base' in yaml_dict:
base_dict = dict(base_dict, **get_template_dict(yaml_dict['base']))

# Finally, override defaults with machine-specific capabilties
# e.g. some machines are not able to run metp jobs
host_dict = get_template_dict(host.info)
base_dict = dict(base_dict, **host_dict)

base_input = f'{inputs.configdir}/config.base'
base_output = f'{inputs.expdir}/{inputs.pslot}/config.base'
edit_config(base_input, base_output, base_dict)
edit_config(base_input, base_output, host.info, base_dict)

return


def edit_config(input_config, output_config, config_dict):
def edit_config(input_config, output_config, host_info, config_dict):
"""
Given a templated input_config filename, parse it based on config_dict and
write it out to the output_config filename.
host_info and write it out to the output_config filename.
"""

# Override defaults with machine-specific capabilties
# e.g. some machines are not able to run metp jobs
host_dict = get_template_dict(host_info)
config_dict = dict(config_dict, **host_dict)

# Read input config
with open(input_config, 'rt') as fi:
config_str = fi.read()
Expand All @@ -186,9 +186,17 @@ def edit_config(input_config, output_config, config_dict):


def get_template_dict(input_dict):
# Reads a templated input dictionary and updates the output

output_dict = dict()

for key, value in input_dict.items():
output_dict[f'@{key}@'] = value
# In some cases, the same config may be templated twice
# Prevent adding additional "@"s
if "@" in key:
output_dict[f'{key}'] = value
else:
output_dict[f'@{key}@'] = value

return output_dict

Expand Down

0 comments on commit fc75a22

Please sign in to comment.