Skip to content

Commit

Permalink
Merge branch 'scm_lam_updates' into 20240819_combiner
Browse files Browse the repository at this point in the history
  • Loading branch information
grantfirl committed Aug 19, 2024
2 parents 97719c7 + 32568dd commit 1e3475c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 20 additions & 14 deletions scm/etc/scripts/UFS_case_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,15 @@ def find_lon_lat_of_indices(indices, dir, tile, lam):
########################################################################################
#
########################################################################################
def find_loc_indices_UFS_history(loc, dir):
def find_loc_indices_UFS_history(loc, dir, lam):
"""Find the nearest neighbor UFS history file grid point given a lon/lat pair"""
#returns the indices of the nearest neighbor point in the given tile, the lon/lat of the nearest neighbor,
#and the distance (m) from the given point to the nearest neighbor grid cell

filename_pattern = 'atmf000.nc'

if lam:
filename_pattern = 'dynf000.nc'
else:
filename_pattern = 'atmf000.nc'

for f_name in os.listdir(dir):
if fnmatch.fnmatch(f_name, filename_pattern):
Expand Down Expand Up @@ -659,7 +662,7 @@ def check_IC_hist_surface_compatibility(dir, i, j, surface_data, lam, old_chgres

# Determine UFS history file format (tiled/quilted)
if lam:
filename_pattern = '*sfcf000.tile{}.nc'.format(tile)
filename_pattern = '*phyf000.nc'
else:
filename_pattern = '*sfcf000.nc'

Expand Down Expand Up @@ -740,7 +743,7 @@ def get_IC_data_from_UFS_history(dir, i, j, lam, tile):

# Determine UFS history file format (tiled/quilted)
if lam:
filename_pattern = '*atmf000.tile{}.nc'.format(tile)
filename_pattern = '*dynf000.nc'
else:
filename_pattern = '*atmf000.nc'

Expand Down Expand Up @@ -1963,8 +1966,8 @@ def get_UFS_forcing_data_advective_tendency(dir, i, j, tile, neighbors, dx, dy,

# Determine UFS history file format (tiled/quilted)
if lam:
atm_ftag = 'atmf*.tile{0}.nc'.format(tile)
sfc_ftag = 'sfcf*.tile{0}.nc'.format(tile)
atm_ftag = '*dynf*.nc'
sfc_ftag = '*phyf*.nc'
else:
atm_ftag = '*atmf*.nc'
sfc_ftag = '*sfcf*.nc'
Expand Down Expand Up @@ -2315,8 +2318,8 @@ def get_UFS_forcing_data(nlevs, state_IC, location, use_nearest, forcing_dir, gr

# Determine UFS history file format (tiled/quilted)
if lam:
atm_ftag = 'atmf*.tile{0}.nc'.format(tile)
sfc_ftag = 'sfcf*.tile{0}.nc'.format(tile)
atm_ftag = '*dynf*.nc'
sfc_ftag = '*phyf*.nc'
else:
atm_ftag = '*atmf*.nc'
sfc_ftag = '*sfcf*.nc'
Expand Down Expand Up @@ -3636,9 +3639,12 @@ def write_comparison_file(comp_data, case_name, date, surface):
########################################################################################
#
########################################################################################
def find_date(forcing_dir):

atm_ftag = '*atmf*.nc'
def find_date(forcing_dir, lam):

if lam:
atm_ftag = '*dynf*.nc'
else:
atm_ftag = '*atmf*.nc'

atm_filenames = []
for f_name in os.listdir(forcing_dir):
Expand Down Expand Up @@ -3679,7 +3685,7 @@ def main():
old_chgres, lam, save_comp, use_nearest, forcing_method, vertical_method, geos_wind_forcing, wind_nudge) = parse_arguments()

#find indices corresponding to both UFS history files and initial condition (IC) files
(hist_i, hist_j, hist_lon, hist_lat, hist_dist_min, angle_to_hist_point, neighbors, dx, dy) = find_loc_indices_UFS_history(location, forcing_dir)
(hist_i, hist_j, hist_lon, hist_lat, hist_dist_min, angle_to_hist_point, neighbors, dx, dy) = find_loc_indices_UFS_history(location, forcing_dir, lam)

(IC_i, IC_j, tile, IC_lon, IC_lat, IC_dist_min, angle_to_IC_point) = find_loc_indices_UFS_IC(location, grid_dir, lam, tile, indices)

Expand Down Expand Up @@ -3715,7 +3721,7 @@ def main():

if not date:
# date was not included on command line; look in atmf* file for initial date
date = find_date(forcing_dir)
date = find_date(forcing_dir, lam)

#get grid cell area if not given
if not area:
Expand Down
2 changes: 2 additions & 0 deletions scm/etc/scripts/UFS_forcing_ensemble_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
parser.add_argument('-sdf', '--suite', help='CCPP suite definition file to use for ensemble', default = 'SCM_GFS_v16')
parser.add_argument('-sc', '--save_comp', help='flag to save a file with UFS data for comparisons', action='store_true')
parser.add_argument('-near', '--use_nearest', help='flag to indicate using the nearest UFS history file gridpoint, no regridding',action='store_true')
parser.add_argument('-lam', '--lam', help='flag to signal that the ICs and forcing is from a limited-area model run' ,action='store_true')
parser.add_argument('-fm', '--forcing_method', help='method used to calculate forcing (1=total tendencies from UFS dycore, 2=advective terms calculated from UFS history files, 3=total time tendency terms calculated)', type=int, choices=range(1,4), default=2)
parser.add_argument('-vm', '--vertical_method',help='method used to calculate vertical advective forcing (1=vertical advective terms calculated from UFS history files and added to total, 2=smoothed vertical velocity provided)', type=int, choices=range(1,3), default=2)
parser.add_argument('-wn', '--wind_nudge', help='flag to turn on wind nudging to UFS profiles', action='store_true')
Expand Down Expand Up @@ -142,6 +143,7 @@ def main():
com_config = ''
if args.save_comp: com_config = com_config + ' -sc'
if args.use_nearest: com_config = com_config + ' -near'
if args.lam: com_config = com_config + ' -lam'
if args.forcing_method: com_config = com_config + ' -fm ' + str(args.forcing_method)
if args.vertical_method: com_config = com_config + ' -vm ' + str(args.vertical_method)
if args.wind_nudge: com_config = com_config + ' -wn'
Expand Down

0 comments on commit 1e3475c

Please sign in to comment.