Skip to content

Commit

Permalink
Update adf_info.py
Browse files Browse the repository at this point in the history
Add logging for failed history file location and climo years
  • Loading branch information
justin-richling committed Nov 19, 2024
1 parent 380087b commit 5cf8a79
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions lib/adf_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,32 @@ def __init__(self, config_file, debug=False):

#Grab first possible hist string, just looking for years of run
base_hist_str = baseline_hist_str[0]

starting_location = Path(baseline_hist_locs)
file_list = sorted(starting_location.glob("*" + base_hist_str + ".*.nc"))

#Check if the history file location exists
if not starting_location.is_dir():
msg = "Checking history file location:\n"
msg += f"\tThere is no history file location: '{starting_location}'."
self.debug_log(msg)
emsg = f"{data_name} starting_location: History file location not found!\n"
emsg += "\tTry checking the path 'cam_hist_loc' in 'diag_cam_baseline_climo' "
emsg += "section in your config file is correct..."
self.end_diag_fail(emsg)
file_list = sorted(starting_location.glob("*" + base_hist_str + ".*.nc"))

#Check if there are any history files
if len(file_list) == 0:
msg = "Checking history files:\n"
msg += f"\tThere are no history files in '{starting_location}'."
self.debug_log(msg)
emsg = f"{data_name} starting_location {starting_location}: "
emsg += f"No history files found for {base_hist_str}!\n"
emsg += "\tTry checking the path 'cam_hist_loc' or the 'hist_str' "
emsg += " in 'diag_cam_baseline_climo' "
emsg += "section in your config file are correct..."
self.end_diag_fail(emsg)

# Partition string to find exactly where h-number is
# This cuts the string before and after the `{hist_str}.` sub-string
# so there will always be three parts:
Expand All @@ -265,6 +288,10 @@ def __init__(self, config_file, debug=False):
#NOTE: this is based off the current CAM file name structure in the form:
# $CASE.cam.h#.YYYY<other date info>.nc
base_climo_yrs = [int(str(i).partition(f"{base_hist_str}.")[2][0:4]) for i in file_list]
if not base_climo_yrs:
msg = f"No climo years found in {baseline_hist_locs}, "
raise AdfError(msg)

base_climo_yrs = sorted(np.unique(base_climo_yrs))

base_found_syr = int(base_climo_yrs[0])
Expand Down Expand Up @@ -421,7 +448,33 @@ def __init__(self, config_file, debug=False):

#Get climo years for verification or assignment if missing
starting_location = Path(cam_hist_locs[case_idx])
print(f"Checking history files in '{starting_location}'")

file_list = sorted(starting_location.glob('*'+hist_str+'.*.nc'))

#Check if the history file location exists
if not starting_location.is_dir():
msg = "Checking history file location:\n"
msg += f"\tThere is no history file location: '{starting_location}'."
self.debug_log(msg)
emsg = f"{case_name} starting_location: History file location not found!\n"
emsg += "\tTry checking the path 'cam_hist_loc' in 'diag_cam_climo' "
emsg += "section in your config file is correct..."
self.end_diag_fail(emsg)

#Check if there are any history files
file_list = sorted(starting_location.glob('*'+hist_str+'.*.nc'))
if len(file_list) == 0:
msg = "Checking history files:\n"
msg += f"\tThere are no history files in '{starting_location}'."
self.debug_log(msg)
emsg = f"{case_name} starting_location {starting_location}: "
emsg += f"No history files found for {hist_str}!\n"
emsg += "\tTry checking the path 'cam_hist_loc' or the 'hist_str' "
emsg += "in 'diag_cam_climo' "
emsg += "section in your config file are correct..."
self.end_diag_fail(emsg)

#Partition string to find exactly where h-number is
#This cuts the string before and after the `{hist_str}.` sub-string
# so there will always be three parts:
Expand All @@ -430,6 +483,9 @@ def __init__(self, config_file, debug=False):
#NOTE: this is based off the current CAM file name structure in the form:
# $CASE.cam.h#.YYYY<other date info>.nc
case_climo_yrs = [int(str(i).partition(f"{hist_str}.")[2][0:4]) for i in file_list]
if not case_climo_yrs:
msg = f"No climo years found in {cam_hist_locs[case_idx]}, "
raise AdfError(msg)
case_climo_yrs = sorted(np.unique(case_climo_yrs))

case_found_syr = int(case_climo_yrs[0])
Expand Down Expand Up @@ -802,7 +858,7 @@ def get_climo_yrs_from_ts(self, input_ts_loc, case_name):
break
else:
logmsg = "get years for time series:"
logmsg = f"\tVar '{var}' not in dataset, skip to next to try and find climo years..."
logmsg = f"\n\tVar '{var}' not in dataset, skip to next to try and find climo years..."
self.debug_log(logmsg)

#Read in file(s)
Expand Down

0 comments on commit 5cf8a79

Please sign in to comment.