Skip to content

Commit

Permalink
wow this LUmip file.... case9 is gonna be a fun one
Browse files Browse the repository at this point in the history
  • Loading branch information
ilaflott committed Nov 15, 2024
1 parent fe59511 commit 8672155
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions fre/cmor/cmor_mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,28 @@ def get_vertical_dimension(ds,target_var):
vert_dim = dim
return vert_dim

def create_tmp_dir(outdir):
def create_tmp_dir(outdir, json_exp_config = None):
'''
creates a tmp_dir based on targeted output directory root. returns the name of the tmp dir.
accepts one argument:
outdir: string, representing the final output directory root for the cmor modules netcdf
file output. tmp_dir will be slightly different depending on the output directory
targeted
'''
outdir_from_exp_config=None
if json_exp_config is not None:
with open(json_exp_config, "r", encoding = "utf-8") as table_config_file:
try:
print(' FOO')
exp_config = json.load(table_config_file)
print(' BAR')
outdir_from_exp_config = exp_config["outpath"]
except:
print(f'(create_tmp_dir) could not read outdir from json_exp_config... oh well!')


print(f"(create_tmp_dir) outdir = {outdir}")
assert False
tmp_dir = None
if any( [ outdir == "/local2",
outdir.find("/work") != -1,
Expand All @@ -164,6 +177,8 @@ def create_tmp_dir(outdir):
tmp_dir = str( Path(f"{outdir}/tmp/").resolve() )
try:
os.makedirs(tmp_dir, exist_ok=True)
if outdir_from_exp_config is not None:
os.makedirs(tmp_dir+'/'+outdir_from_exp_config, exist_ok=True)
except Exception as exc:
raise OSError('(create_tmp_dir) problem creating temp output directory. stop.') from exc
return tmp_dir
Expand Down Expand Up @@ -275,7 +290,7 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,

# Check var_dim and vert_dim and assign lev if relevant.
# error if vert_dim wrong given var_dim
lev, lev_units = None, ""
lev, lev_units = None, "1" #1 #"none" #None #""
if vert_dim != 0:
if vert_dim not in [ "landuse", "plev39", "plev30", "plev19", "plev8",
"height2m", "level", "lev", "levhalf"] :
Expand All @@ -289,7 +304,7 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,
cmor.setup(
netcdf_file_action = cmor.CMOR_PRESERVE,
set_verbosity = cmor.CMOR_NORMAL, #CMOR_QUIET, #default is CMOR_NORMAL
exit_control = cmor.CMOR_NORMAL,
exit_control = cmor.CMOR_EXIT_ON_WARNING,#CMOR_NORMAL,
logfile = './foo.log',
create_subdirectories = 1
)
Expand Down Expand Up @@ -374,7 +389,7 @@ def rewrite_netcdf_file_var ( proj_table_vars = None,
cmor_vert_dim_name = vert_dim
if vert_dim == "landuse":
cmor_vert_dim_name = "landUse" # this is why can't we have nice things
cmor_lev = cmor.axis( vert_dim,
cmor_lev = cmor.axis( cmor_vert_dim_name,
coord_vals = lev[:], units = lev_units )

elif vert_dim in ["level", "lev", "levhalf"]:
Expand Down Expand Up @@ -514,7 +529,7 @@ def cmorize_target_var_files( indir = None, target_var = None, local_var = None,


#determine a tmp dir for working on files.
tmp_dir = create_tmp_dir( outdir ) + '/'
tmp_dir = create_tmp_dir( outdir, json_exp_config) + '/'
print(f'(cmorize_target_var_files) will use tmp_dir={tmp_dir}')


Expand Down

0 comments on commit 8672155

Please sign in to comment.