From de4f0aa35fc0d9b1d3d205812b5f552c5fce350a Mon Sep 17 00:00:00 2001 From: bstephens82 Date: Wed, 23 Oct 2024 10:20:14 -0600 Subject: [PATCH] adding support for variables on the ilev vertical grid. --- lib/adf_diag.py | 4 +-- scripts/regridding/regrid_and_vert_interp.py | 29 ++++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/adf_diag.py b/lib/adf_diag.py index e37c6a6cd..43c3d2c1c 100644 --- a/lib/adf_diag.py +++ b/lib/adf_diag.py @@ -625,7 +625,7 @@ def call_ncrcat(cmd): # End if (var in var_diag_list) # Check if variable has a "lev" dimension according to first file: - has_lev = bool("lev" in hist_file_ds[var].dims) + has_lev = bool("lev" in hist_file_ds[var].dims or "ilev" in hist_file_ds[var].dims) # Create full path name, file name template: # $cam_case_name.$hist_str.$variable.YYYYMM-YYYYMM.nc @@ -1524,4 +1524,4 @@ def my_formatwarning(msg, *args, **kwargs): return xr.open_dataset(fils[0]) #End if # End def -######## \ No newline at end of file +######## diff --git a/scripts/regridding/regrid_and_vert_interp.py b/scripts/regridding/regrid_and_vert_interp.py index fab356b0e..4958156f7 100644 --- a/scripts/regridding/regrid_and_vert_interp.py +++ b/scripts/regridding/regrid_and_vert_interp.py @@ -443,12 +443,15 @@ def _regrid_and_interpolate_levs(model_dataset, var_name, regrid_dataset=None, r # mdat_ofrac = model_dataset['OCNFRAC'].squeeze() #Check if variable has a vertical component: - if 'lev' in mdata.dims: + if 'lev' in mdata.dims or 'ilev' in mdata.dims: has_lev = True #If lev exists, then determine what kind of vertical coordinate #is being used: - lev_attrs = model_dataset['lev'].attrs + if 'lev' in mdata.dims: + lev_attrs = model_dataset['lev'].attrs + elif 'ilev' in mdata.dims: + lev_attrs = model_dataset['ilev'].attrs #First check if there is a "vert_coord" attribute: if 'vert_coord' in lev_attrs: @@ -492,12 +495,20 @@ def _regrid_and_interpolate_levs(model_dataset, var_name, regrid_dataset=None, r if vert_coord_type == "hybrid": # Need hyam, hybm, and P0 for vertical interpolation of hybrid levels: - if ('hyam' not in model_dataset) or ('hybm' not in model_dataset): - print(f"!! PROBLEM -- NO hyam or hybm for 3-D variable {var_name}, so it will not be re-gridded.") - return None #Return None to skip to next variable. - #End if - mhya = model_dataset['hyam'] - mhyb = model_dataset['hybm'] + if 'lev' in mdata.dims: + if ('hyam' not in model_dataset) or ('hybm' not in model_dataset): + print(f"!! PROBLEM -- NO hyam or hybm for 3-D variable {var_name}, so it will not be re-gridded.") + return None #Return None to skip to next variable. + #End if + mhya = model_dataset['hyam'] + mhyb = model_dataset['hybm'] + elif 'ilev' in mdata.dims: + if ('hyai' not in model_dataset) or ('hybi' not in model_dataset): + print(f"!! PROBLEM -- NO hyai or hybi for 3-D variable {var_name}, so it will not be re-gridded.") + return None #Return None to skip to next variable. + #End if + mhya = model_dataset['hyai'] + mhyb = model_dataset['hybi'] if 'time' in mhya.dims: mhya = mhya.isel(time=0).squeeze() if 'time' in mhyb.dims: @@ -696,4 +707,4 @@ def regrid_data(fromthis, tothis, method=1): return result #End if -##### \ No newline at end of file +#####