Skip to content

Commit

Permalink
Add flexibility for globbing different h-numbers
Browse files Browse the repository at this point in the history
Also move where ADF appends case climo years in case the ADF has to update climo years from what user requested.
  • Loading branch information
justin-richling committed Jan 8, 2024
1 parent f45ffbd commit a8bdb18
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/adf_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<other date info>.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.
Expand Down Expand Up @@ -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}"

Expand Down

0 comments on commit a8bdb18

Please sign in to comment.