Skip to content

Commit

Permalink
Merge branch 'main' into dataclass-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-richling authored Jul 12, 2024
2 parents 7e5fe82 + 0e6e19c commit dd62506
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/adf_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ def __init__(self, config_file, debug=False):
self.__cam_climo_info[conf_var] = [conf_val]
#End if
#End for

#If hist_str (component.hist_num) was not in yaml file, set to default
hist_str = self.__cam_climo_info['hist_str']
if not hist_str:
hist_str = [['cam.h0a']]*self.__num_cases
#End if

#-------------------------------------------

#Initialize ADF variable list:
Expand Down Expand Up @@ -250,19 +243,28 @@ def __init__(self, config_file, debug=False):

# Check if history file path exists:
if any(baseline_hist_locs):
if not isinstance(baseline_hist_str, list):
baseline_hist_str = [baseline_hist_str]
hist_str = baseline_hist_str[0]
#Check if user provided
if not baseline_hist_str:
baseline_hist_str = ['cam.h0a']
else:
#Make list if not already
if not isinstance(baseline_hist_str, list):
baseline_hist_str = [baseline_hist_str]
#Initialize baseline history string list
self.__base_hist_str = baseline_hist_str

#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("*" + hist_str + ".*.nc"))
file_list = sorted(starting_location.glob("*" + base_hist_str + ".*.nc"))
# 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
base_climo_yrs = [int(str(i).partition(f"{hist_str}.")[2][0:4]) for i in file_list]
base_climo_yrs = [int(str(i).partition(f"{base_hist_str}.")[2][0:4]) for i in file_list]
base_climo_yrs = sorted(np.unique(base_climo_yrs))

base_found_syr = int(base_climo_yrs[0])
Expand Down Expand Up @@ -348,7 +350,7 @@ def __init__(self, config_file, debug=False):
cam_hist_locs = self.get_cam_info('cam_hist_loc')

#Get cleaned nested list of hist_str for test case(s) (component.hist_num, eg cam.h0)
cam_hist_str = self.__cam_climo_info['hist_str']
cam_hist_str = self.__cam_climo_info.get('hist_str', None)

if not cam_hist_str:
hist_str = [['cam.h0a']]*self.__num_cases
Expand Down Expand Up @@ -411,8 +413,9 @@ def __init__(self, config_file, debug=False):
#End if

#Check if history file path exists:
hist_str_case = cam_hist_str[case_idx]
hist_str_case = hist_str[case_idx]
if any(cam_hist_locs):
#Grab first possible hist string, just looking for years of run
hist_str = hist_str_case[0]

#Get climo years for verification or assignment if missing
Expand Down
1 change: 1 addition & 0 deletions scripts/plotting/tape_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def tape_recorder(adfobj):
hist_str = runs_LT2[key][1]
fils= sorted(ts_loc.glob(f'*{hist_str}.{var}.*.nc'))
dat = adfobj.data.load_timeseries_dataset(fils)

if not dat:
dmsg = f"\t No data for `{var}` found in {fils}, case will be skipped in tape recorder plot."
print(dmsg)
Expand Down

0 comments on commit dd62506

Please sign in to comment.