Skip to content

Commit

Permalink
Address reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkavulich committed Oct 21, 2022
1 parent 7f37049 commit 5d43ec2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
17 changes: 8 additions & 9 deletions ush/generate_FV3LAM_wflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,11 @@ def generate_FV3LAM_wflow(USHdir, logfile: str = 'log.generate_FV3LAM_wflow') ->

set_FV3nml_sfc_climo_filenames()

# Call script to get NOMADS data
# Call function to get NOMADS data
if NOMADS:
get_nomads_data(NOMADS_file_type,EXPTDIR,USHdir,DATE_FIRST_CYCL,CYCL_HRS,FCST_LEN_HRS,LBC_SPEC_INTVL_HRS)
raise Exception("Nomads script does not work!")

# get_nomads_data(NOMADS_file_type,EXPTDIR,USHdir,DATE_FIRST_CYCL,CYCL_HRS,FCST_LEN_HRS,LBC_SPEC_INTVL_HRS)

#
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -959,10 +961,9 @@ def generate_FV3LAM_wflow(USHdir, logfile: str = 'log.generate_FV3LAM_wflow') ->
========================================================================
"""
)
#
# -----------------------------------------------------------------------
#
# If rocoto is required, print instructions on how to load and use it
# If rocoto is required, print instructions on how to use it
#
# -----------------------------------------------------------------------
#
Expand Down Expand Up @@ -1007,9 +1008,8 @@ def get_nomads_data(NOMADS_file_type,EXPTDIR,USHdir,DATE_FIRST_CYCL,CYCL_HRS,FCS
print(f"NOMADS_file_type= {NOMADS_file_type}")
cd_vrfy(EXPTDIR)
NOMADS_script = os.path.join(USHdir, "NOMADS_get_extrn_mdl_files.sh")
# run_command(f"""{NOMADS_script} {date_to_str(DATE_FIRST_CYCL,format="%Y%m%d")} \
# {date_to_str(DATE_FIRST_CYCL,format="%H")} {NOMADS_file_type} {FCST_LEN_HRS} {LBC_SPEC_INTVL_HRS}""")
raise Exception("Nomads script does not work")
run_command(f"""{NOMADS_script} {date_to_str(DATE_FIRST_CYCL,format="%Y%m%d")} \
{date_to_str(DATE_FIRST_CYCL,format="%H")} {NOMADS_file_type} {FCST_LEN_HRS} {LBC_SPEC_INTVL_HRS}""")

def setup_logging(logfile: str = 'log.generate_FV3LAM_wflow') -> None:
"""
Expand All @@ -1036,11 +1036,10 @@ def setup_logging(logfile: str = 'log.generate_FV3LAM_wflow') -> None:
try:
generate_FV3LAM_wflow(USHdir, logfile)
except:
# If the call to the generate_FV3LAM_wflow function above was not successful,
# print out an error message and exit with a nonzero return code.
logging.exception(dedent(
f"""
*********************************************************************
FATAL ERROR:
Experiment generation failed. See the error message(s) printed below.
For more detailed information, check the log file from the workflow
generation script: {logfile}
Expand Down
7 changes: 2 additions & 5 deletions ush/python_utils/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@
def load_yaml_config(config_file):
"""Safe load a yaml file"""

try:
with open(config_file, "r") as f:
cfg = yaml.safe_load(f)
except yaml.YAMLError as e:
raise Exception(f"Unable to load yaml file {config_file}")
with open(config_file, "r") as f:
cfg = yaml.safe_load(f)

return cfg

Expand Down
6 changes: 3 additions & 3 deletions ush/python_utils/print_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def print_info_msg(info_msg, verbose=True):
return True
return False

def log_info(info_msg, verbose=True, ddent=True):
def log_info(info_msg, verbose=True, dedent_=True):
"""Function to print information message using the logging module. This function
should not be used if python logging has not been initialized.
Args:
info_msg : info message to print
verbose : set to False to silence printing
ddent : set to False to disable "dedenting" (print string as-is)
dedent_ : set to False to disable "dedenting" (print string as-is)
Returns:
None
"""
Expand All @@ -57,7 +57,7 @@ def log_info(info_msg, verbose=True, ddent=True):
logger=getLogger(sys._getframe().f_back.f_code.co_name)

if verbose:
if ddent:
if dedent_:
logger.info(indent(dedent(info_msg), ' '))
else:
logger.info(info_msg)
Expand Down
10 changes: 3 additions & 7 deletions ush/set_ozone_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ def set_ozone_param(ccpp_phys_suite_fp):
fixgsm_ozone_fn = "global_o3prdlos.f77"
ozone_param = "ozphys"
else:
raise Exception(
f'''
Unknown or no ozone parameterization
specified in the CCPP physics suite file (ccpp_phys_suite_fp):
ccpp_phys_suite_fp = \"{ccpp_phys_suite_fp}\"'''
)
raise KeyError(f'Unknown or no ozone parameterization specified in the '
'CCPP physics suite file "{ccpp_phys_suite_fp}"')
#
# -----------------------------------------------------------------------
#
Expand Down Expand Up @@ -158,7 +154,7 @@ def set_ozone_param(ccpp_phys_suite_fp):
""", verbose=VERBOSE)
log_info(f"""
CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING = {list_to_str(CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING)}
""", verbose=VERBOSE, ddent=False)
""", verbose=VERBOSE, dedent_=False)

else:

Expand Down
13 changes: 7 additions & 6 deletions ush/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import datetime
import traceback
from textwrap import dedent
from logging import getLogger

Expand Down Expand Up @@ -86,8 +87,7 @@ def setup():
EXPT_CONFIG_FN = cfg_d["workflow"]["EXPT_CONFIG_FN"]


# Load the user config file, containing contains user-specified values
# variables that override their default values. Ensure all user-specified
# Load the user config file, then ensure all user-specified
# variables correspond to a default value.
if not os.path.exists(EXPT_CONFIG_FN):
raise FileNotFoundError(f'User config file not found: EXPT_CONFIG_FN = {EXPT_CONFIG_FN}')
Expand All @@ -97,16 +97,16 @@ def setup():
except:
errmsg = dedent(f'''\n
Could not load YAML config file: {EXPT_CONFIG_FN}
The file may be formatted incorrectly; reference the Users Guide for more info
Reference the above traceback for more information.
''')
raise Exception(errmsg) from None
raise Exception(errmsg)

cfg_u = flatten_dict(cfg_u)
for key in cfg_u:
if key not in flatten_dict(cfg_d):
raise Exception(dedent(f'''
User-specified variable "{key}" in {EXPT_CONFIG_FN} is not valid
Check {EXPT_DEFAULT_CONFIG_FN} for allowed user-specified variables\n'''))
Check {EXPT_DEFAULT_CONFIG_FN} for allowed user-specified variables.\n'''))

# Mandatory variables *must* be set in the user's config; the default value is invalid
mandatory = ['MACHINE']
Expand Down Expand Up @@ -427,9 +427,10 @@ def get_location(xcs,fmt):

# Mandatory variables *must* be set in the user's config or the machine file; the default value is invalid
mandatory = ['NCORES_PER_NODE', 'FIXgsm', 'FIXaer', 'FIXlut', 'TOPO_DIR', 'SFC_CLIMO_INPUT_DIR']
globalvars = globals()
for val in mandatory:
# globals() returns dictionary of global variables
if not globals()[val]:
if not globalvars[val]:
raise Exception(dedent(f'''
Mandatory variable "{val}" not found in:
user config file {EXPT_CONFIG_FN}
Expand Down

0 comments on commit 5d43ec2

Please sign in to comment.