From 5cf8a79bd147b5b26ee3ceed7d5aba485c746dcb Mon Sep 17 00:00:00 2001 From: justin-richling Date: Tue, 19 Nov 2024 13:35:05 -0700 Subject: [PATCH 1/2] Update adf_info.py Add logging for failed history file location and climo years --- lib/adf_info.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/adf_info.py b/lib/adf_info.py index 36661a0dc..dd4270f6b 100644 --- a/lib/adf_info.py +++ b/lib/adf_info.py @@ -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: @@ -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.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]) @@ -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: @@ -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.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]) @@ -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) From 0b99f542a8cd4336b83e156993b495a69a8ec1f4 Mon Sep 17 00:00:00 2001 From: justin-richling Date: Tue, 19 Nov 2024 13:37:57 -0700 Subject: [PATCH 2/2] Update amwg_table.py --- scripts/analysis/amwg_table.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/analysis/amwg_table.py b/scripts/analysis/amwg_table.py index b2bac7332..0c21dbcdc 100644 --- a/scripts/analysis/amwg_table.py +++ b/scripts/analysis/amwg_table.py @@ -102,10 +102,6 @@ def amwg_table(adf): # VARIABLE-NAME, RUN VALUE, OBS VALUE, RUN-OBS, RMSE #---------------------- - #Notify user that script has started: - print("\n Calculating AMWG variable table...") - - #Extract needed quantities from ADF object: #----------------------------------------- var_list = adf.diag_var_list @@ -167,6 +163,9 @@ def amwg_table(adf): #Write to debug log if enabled: adf.debug_log(f"DEBUG: location of files is {str(input_location)}") + #Notify user that script has started: + print(f"\n Calculating AMWG variable table for '{case_name}'...") + #Create output file name: output_csv_file = output_location / f"amwg_table_{case_name}.csv" @@ -216,7 +215,7 @@ def amwg_table(adf): #Check if variable has a vertical coordinate: if 'lev' in data.coords or 'ilev' in data.coords: - print(f"\t Variable '{var}' has a vertical dimension, "+\ + print(f"\t ** Variable '{var}' has a vertical dimension, "+\ "which is currently not supported for the AMWG Table. Skipping...") #Skip this variable and move to the next variable in var_list: continue