diff --git a/lib/adf_info.py b/lib/adf_info.py index 0112845ce..f46a0a50d 100644 --- a/lib/adf_info.py +++ b/lib/adf_info.py @@ -268,19 +268,20 @@ def __init__(self, config_file, debug=False): for case_idx, case_name in enumerate(case_names): syear = int(f"{str(syears[case_idx]).zfill(4)}") - syears_fixed.append(syear) eyear = int(f"{str(eyears[case_idx]).zfill(4)}") - eyears_fixed.append(eyear) #Check if history file path exists: if cam_hist_locs: #Get climo years for verification or assignment if missing starting_location = Path(cam_hist_locs[case_idx]) files_list = sorted(starting_location.glob('*'+hist_str+'.*.nc')) - case_climo_yrs_str = sorted(np.unique([i.stem[-7:-3] for i in files_list])) - case_climo_yrs = [] - for year in case_climo_yrs_str: - case_climo_yrs.append(int(year)) + #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: before sub-string, sub-string, and after sub-string + #Since the last part always(?) includes the time range, grab that with last index (2) + #NOTE: this is based off the current CAM file name structure in the form $CASE.cam.h#.YYYY.nc + case_climo_yrs = sorted(np.unique([int(str(i).partition(f"{hist_str}.")[2][0:4]) for i in files_list])) + #Check if start or end year is missing. If so then just assume it is the #start or end of the entire available model data. @@ -311,6 +312,10 @@ def __init__(self, config_file, debug=False): #End if #End if + #Update climo year lists in case anything changed + syears_fixed.append(syear) + eyears_fixed.append(eyear) + #Update case name with provided/found years: case_name += f"_{syear}_{eyear}"