Skip to content

Commit

Permalink
Make budget table hist_str user input
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-richling authored Dec 13, 2024
1 parent b169e43 commit a2a3082
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions scripts/analysis/aerosol_gas_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def aerosol_gas_tables(adfobj):

# Grab history file locations from config yaml file
hist_locs = adfobj.get_cam_info("cam_hist_loc", required=True)

# Grab history file locations from config yaml file
hist_strs = adfobj.get_cam_info("aerosol_hist_str", required=True)

# Check if this is test model vs baseline model
# If so, update test case(s) lists created above
Expand All @@ -180,8 +183,10 @@ def aerosol_gas_tables(adfobj):
end_years += [adfobj.climo_yrs["eyear_baseline"]]

# Get history file info
#hist_strs += [adfobj.hist_string["base_hist_str"]]
hist_locs += [adfobj.get_baseline_info("cam_hist_loc")]

# Grab history file locations from config yaml file
hist_strs = +[adfobj.get_baseline_info("aerosol_hist_str", required=True)]
# End if

# Check to ensure number of case names matches number history file locations.
Expand Down Expand Up @@ -254,9 +259,10 @@ def aerosol_gas_tables(adfobj):

# Get currenty history file directory
data_dir = data_dirs[i]
hist_str = hist_strs[i]

# Get all files, lats, lons, and area weights for current case
Files,Lats,Lons,areas[case],ext1_SE = Get_files(adfobj,data_dir,start_year,end_year,area=True)#,case_hist_strs[i]
Files,Lats,Lons,areas[case],ext1_SE = Get_files(adfobj,data_dir,hist_str,start_year,end_year,area=True)#,case_hist_strs[i]

# find the name of all the variables in the file.
# this will help the code to work for the variables that are not in the files (assingn 0s)
Expand Down Expand Up @@ -325,7 +331,7 @@ def aerosol_gas_tables(adfobj):
# Helper functions
##################

def list_files(adfobj, directory, start_year ,end_year):#, h_case
def list_files(adfobj, directory, hist_str, start_year ,end_year):#, h_case

"""
This function extracts the files in the directory that are within the chosen dates
Expand All @@ -345,12 +351,11 @@ def list_files(adfobj, directory, start_year ,end_year):#, h_case
# break
# #h_case = "cam.h0a"

#use_h_case =
h_case = "cam.h2a"
test_files = sorted(Path(directory).glob(f'*.{h_case}.{yrs[0]}-*'))

test_files = sorted(Path(directory).glob(f'*.{hist_str}.{yrs[0]}-*'))
all_filenames = []
for i in yrs:
all_filenames.append(sorted(Path(directory).glob(f'*.{use_h_case}.{i}-*')))
all_filenames.append(sorted(Path(directory).glob(f'*.{hist_str}.{i}-*')))

# Flattening the list of lists
filenames = list(itertools.chain.from_iterable(sorted(all_filenames)))
Expand All @@ -364,7 +369,7 @@ def list_files(adfobj, directory, start_year ,end_year):#, h_case
#####


def Get_files(adfobj, data_dir, start_year, end_year, **kwargs):#h_case
def Get_files(adfobj, data_dir, hist_str, start_year, end_year, **kwargs):#h_case

"""
This function retrieves the files, latitude, and longitude information
Expand All @@ -375,7 +380,7 @@ def Get_files(adfobj, data_dir, start_year, end_year, **kwargs):#h_case

Earth_rad=6.371e6 # Earth Radius in meters

current_files = list_files(adfobj, data_dir, start_year, end_year)#,h_case
current_files = list_files(adfobj, data_dir, hist_str, start_year, end_year)#,h_case

# get the Lat and Lons for each case
tmp_file = xr.open_dataset(Path(data_dir) / current_files[0])
Expand Down

0 comments on commit a2a3082

Please sign in to comment.