Skip to content

Commit

Permalink
Merge pull request #337 from bstephens82/ilev_support_changes
Browse files Browse the repository at this point in the history
adding support for variables on the ilev vertical grid.
  • Loading branch information
justin-richling authored Nov 11, 2024
2 parents e822515 + de4f0aa commit 904028e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/adf_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1524,4 +1524,4 @@ def my_formatwarning(msg, *args, **kwargs):
return xr.open_dataset(fils[0])
#End if
# End def
########
########
29 changes: 20 additions & 9 deletions scripts/regridding/regrid_and_vert_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -696,4 +707,4 @@ def regrid_data(fromthis, tothis, method=1):
return result
#End if

#####
#####

0 comments on commit 904028e

Please sign in to comment.