Skip to content

Commit

Permalink
Rename GSD_RAP13km grid and adjust its write-component grid (#458)
Browse files Browse the repository at this point in the history
## DESCRIPTION OF CHANGES:
* Rename GSD_RAP13km grid to RRFS_NA_13km.
* In ush/set_predef_grid_params.sh:
  * Change parameters of the (newly renamed) RRFS_NA_13km grid to make its write-component grid be completely within the native grid.
  * For the (newly renamed) RRFS_NA_13km grid, automate calculation of WRTCMP_dlon and WRTCMP_dlat from ESGgrid_DELX and ESGgrid_DELY, respectively.
* NCL scripts:
  * Make modifications to make scripts more general and have the find_wrtcmp_grid_params.ncl script work for a write-component grid of type "rotated_latlon".
  * Remove unused code in NCL scripts.
* Fix up comments.

## TESTS CONDUCTED: 
Ran the (renamed) WE2E test grid_RRFS_NA_13km on Hera.  Was successful.

## CONTRIBUTORS (optional): 
This grid was also tested by @jaymes-kenyon on Jet.
  • Loading branch information
gsketefian authored Mar 26, 2021
1 parent 05b5598 commit c608e29
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RUN_ENVIR="community"
PREEXISTING_DIR_METHOD="rename"

PREDEF_GRID_NAME="GSD_RAP13km"
PREDEF_GRID_NAME="RRFS_NA_13km"
QUILTING="TRUE"

CCPP_PHYS_SUITE="FV3_GSD_v0"
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ get_from_HPSS_ics_RAP_lbcs_RAP
grid_CONUS_25km_GFDLgrid_FV3GFS_FV3GFS
grid_CONUS_3km_GFDLgrid_FV3GFS_FV3GFS
grid_GSD_HRRR_AK_50km
grid_GSD_RAP13km
grid_RRFS_AK_13km_FV3GFS_FV3GFS
grid_RRFS_AK_13km_RAP_RAP
grid_RRFS_AK_3km_FV3GFS_FV3GFS
Expand Down Expand Up @@ -49,6 +48,7 @@ grid_RRFS_CONUS_3km_ics_HRRR_lbcs_RAP_suite_GFS_v15p2
grid_RRFS_CONUS_3km_ics_HRRR_lbcs_RAP_suite_GSD_SAR
grid_RRFS_CONUS_3km_ics_HRRR_lbcs_RAP_suite_HRRR
grid_RRFS_CONUS_3km_ics_HRRR_lbcs_RAP_suite_RRFS_v1beta
grid_RRFS_NA_13km
grid_RRFS_SUBCONUS_3km_ics_FV3GFS_lbcs_FV3GFS_suite_GFS_v16beta
grid_RRFS_SUBCONUS_3km_ics_HRRR_lbcs_RAP_suite_GFS_v15p2
grid_RRFS_SUBCONUS_3km_ics_HRRR_lbcs_RAP_suite_GSD_SAR
Expand Down
4 changes: 2 additions & 2 deletions ush/NCL/calc_wrtcmp_grid_params_lambert_cnfrml.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ begin
param_value := char_sq + "lambert_conformal" + char_sq
param_value_str := tostring(param_value)

regex_search = "^(\s*" + param_name + ":\s+)('\{\{ " + param_name + " \}\}')(\s*)(.*)"
regex_search = "^(\s*" + param_name + ":\s+)('\{\{\s*" + param_name + "\s*\}\}')(\s*)(.*)"

regex_print = "\1" + param_value_str
sed_cmd = "sed -n -r -e " + char_dq + "s|" + regex_search + "|" \
Expand Down Expand Up @@ -326,7 +326,7 @@ begin
;
; Set the regular expression to search for.
;
regex_search = "^(\s*" + param_name + ":\s+)(\{\{ " + param_name + " \}\})(\s*)(.*)"
regex_search = "^(\s*" + param_name + ":\s+)(\{\{\s*" + param_name + "\s*\}\})(\s*)(.*)"
;
; Get the parameter name and value without the trailing comment (if any).
;
Expand Down
144 changes: 129 additions & 15 deletions ush/NCL/calc_wrtcmp_grid_params_rotated_latlon.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ loadscript(lib_location + "constants.ncl")
loadscript(lib_location + "strcmp_exact.ncl")
loadscript(lib_location + "strpad.ncl")
loadscript(lib_location + "repeat_str.ncl")
loadscript(lib_location + "interpol_extrapol_linear.ncl")
loadscript(lib_location + "calc_rotated_sphr_coords_from_sphr.ncl")
loadscript(lib_location + "calc_sphr_coords_from_rotated_sphr.ncl")
loadscript(lib_location + "convert_from_to_sphr_coords_to_from_rotated_sphr.ncl")

undef("calc_wrtcmp_grid_params_rotated_latlon")

function calc_wrtcmp_grid_params_rotated_latlon( \
wrtcmp_config_fn:string, \
model_config_tmpl_fp:string, \
lon_ctr_native:snumeric, lat_ctr_native:snumeric, \
lon_tile_corners_face_midpts_native[8]:snumeric, \
lat_tile_corners_face_midpts_native[8]:snumeric, \
lon_bdy_native[*]:snumeric, \
lat_bdy_native[*]:snumeric, \
nx_native:snumeric, ny_native:snumeric, \
dx_native:snumeric, dy_native:snumeric, \
angle_units:string)

Expand Down Expand Up @@ -113,8 +117,6 @@ print("(lon_tile_corners_face_midpts_native, lat_tile_corners_face_midpts_native
pause

end if


;
; **********************************************************************
;
Expand All @@ -123,13 +125,28 @@ end if
;
; **********************************************************************
;
;print("")
;print("(lon_tile_corners_face_midpts_native, lat_tile_corners_face_midpts_native) = " + \
; lon_tile_corners_face_midpts_native + ", " + \
; lat_tile_corners_face_midpts_native)
;pause

rotated_sphr_coords \
:= convert_from_to_sphr_coords_to_from_rotated_sphr( \
lon_ctr, lat_ctr, angle_units, 1, \
lon_tile_corners_face_midpts_native, \
lat_tile_corners_face_midpts_native)
x_tile_corners_face_midpts_native = rotated_sphr_coords@lon_out
y_tile_corners_face_midpts_native = rotated_sphr_coords@lat_out

rotated_sphr_coords \
:= convert_from_to_sphr_coords_to_from_rotated_sphr( \
lon_ctr, lat_ctr, angle_units, 1, \
lon_bdy_native, \
lat_bdy_native)
x_bdy_native = rotated_sphr_coords@lon_out
y_bdy_native = rotated_sphr_coords@lat_out

;print("")
;print("(x_tile_corners_face_midpts_native, y_tile_corners_face_midpts_native) = " + \
; x_tile_corners_face_midpts_native + ", " + \
Expand Down Expand Up @@ -219,8 +236,103 @@ end if
y_S_native_max = max((/y_SW_native, y_S_native, y_SE_native/))
y_N_native_min = min((/y_NW_native, y_N_native, y_NE_native/))

;
; The following code is for the case in which in the xy-plane [i.e. in the
; lonp-latp plane, where lonp and latp are the rotated latlon coordinates
; (with the "p" indicating "prime")] the left and right boundaries are
; concave (bow into the domain) and the bottom and top boundaries are
; convex (bow out of the domain). It allows the write-component domain
; in the y (i.e. latp) direction to be slightly larger by calculating
; the lower and upper bounds of the domain in a less conservative way.
; This needs to be generalized to cases in which the left and right
; boundaries are convex and the bottom and top boundaries are convex.
;
; This code (after generalization) needs to be included in the file
; calc_wrtcmp_grid_params_lambert_cnfrml.ncl.
;
if (True) then
;if (False) then

if ((y_S_native .lt. y_SW_native) .and. (y_S_native .lt. y_SE_native)) then

indx_start = 0
indx_end = indx_start + nx_native
x_bdy_native_bot := x_bdy_native(indx_start:indx_end)
y_bdy_native_bot := y_bdy_native(indx_start:indx_end)

inds_sort := dim_pqsort(x_bdy_native_bot, 2)
y_bdy_native_bot := y_bdy_native_bot(inds_sort)

indx_nearest = ind_nearest_coord(x_W_native_max, x_bdy_native_bot, 0)
if (x_W_native_max .lt. x_bdy_native_bot(indx_nearest)) then
indx_1 = indx_nearest - 1
indx_2 = indx_nearest
else if (x_W_native_max .ge. x_bdy_native_bot(indx_nearest)) then
indx_1 = indx_nearest
indx_2 = indx_nearest + 1
end if
end if

; y_S_native_max_linear := interpol_extrapol_linear( \
; x_SW_native, y_SW_native, \
; x_S_native, y_S_native, \
; x_W_native_max)
y_S_native_max = interpol_extrapol_linear( \
x_bdy_native_bot(indx_1), y_bdy_native_bot(indx_1), \
x_bdy_native_bot(indx_2), y_bdy_native_bot(indx_2), \
x_W_native_max)
;print("NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN")
;print("y_S_native_max_linear = " + y_S_native_max_linear)
;print("y_S_native_max = " + y_S_native_max)
;pause

end if


if ((y_N_native .gt. y_NW_native) .and. (y_N_native .gt. y_NE_native)) then

indx_start = nx_native + ny_native
indx_end = indx_start + nx_native
x_bdy_native_top := x_bdy_native(indx_start:indx_end)
y_bdy_native_top := y_bdy_native(indx_start:indx_end)

inds_sort := dim_pqsort(x_bdy_native_top, 2)
y_bdy_native_top := y_bdy_native_top(inds_sort)

indx_nearest = ind_nearest_coord(x_W_native_max, x_bdy_native_top, 0)
if (x_W_native_max .lt. x_bdy_native_top(indx_nearest)) then
indx_1 = indx_nearest - 1
indx_2 = indx_nearest
else if (x_W_native_max .ge. x_bdy_native_top(indx_nearest)) then
indx_1 = indx_nearest
indx_2 = indx_nearest + 1
end if
end if

; y_N_native_min_linear := interpol_extrapol_linear( \
; x_NW_native, y_NW_native, \
; x_N_native, y_N_native, \
; x_W_native_max)
y_N_native_min = interpol_extrapol_linear( \
x_bdy_native_top(indx_1), y_bdy_native_top(indx_1), \
x_bdy_native_top(indx_2), y_bdy_native_top(indx_2), \
x_W_native_max)
;print("NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN")
;print("y_N_native_min_linear = " + y_N_native_min_linear)
;print("y_N_native_min = " + y_N_native_min)
;pause

end if

end if



y_S = y_S_native_max + num_margin_cells*dy
y_N = y_N_native_min - num_margin_cells*dy
print("")
print("y_S = " + y_S)
print("y_N = " + y_N)

y_S = -min(abs((/y_S, y_N/)))
y_N = -y_S
Expand All @@ -236,7 +348,7 @@ end if
; **********************************************************************
;
; Calculate the spherical coordinates of the southwest corner of the
; native grid from its Lambert coordinates.
; native grid from its rotated latlon coordinates.
;
; **********************************************************************
;
Expand Down Expand Up @@ -300,16 +412,16 @@ end if
param_value := char_sq + "rotated_latlon" + char_sq
param_value_str := tostring(param_value)

regex_search = "^(\s*" + param_name + ":\s+)(<" + param_name + ">)(\s*)(.*)"
regex_search = "^(\s*" + param_name + ":\s+)('\{\{\s*" + param_name + "\s*\}\}')(\s*)(.*)"

regex_print = "\1" + param_value_str
sed_cmd = "sed -n -r -e " + char_dq + "s|" + regex_search + "|" \
+ regex_print + "|p" + char_dq + " " + wrtcmp_config_fn
+ regex_print + "|p" + char_dq + " " + model_config_tmpl_fp
param_names_and_vals(np) = systemfunc(sed_cmd)

regex_print = "\4"
sed_cmd = "sed -n -r -e " + char_dq + "s|" + regex_search + "|" \
+ regex_print + "|p" + char_dq + " " + wrtcmp_config_fn
+ regex_print + "|p" + char_dq + " " + model_config_tmpl_fp
trailing_comments(np) = systemfunc(sed_cmd)
;
; **********************************************************************
Expand Down Expand Up @@ -366,30 +478,32 @@ end if
end if
;
; Generate a string containing the parameter value and formatted as spe-
; cified by fmt_str. Then strip any leading and trailing whitespace
; cified by fmt_str. Then strip any leading and trailing whitespace
; from it.
;
param_value_str := sprintf(fmt_str, param_value)
param_value_str := str_strip(param_value_str)
;
; Set the regular expression to search for.
;
regex_search = "^(\s*" + param_name + ":\s+)(<" + param_name + ">)(\s*)(.*)"
regex_search = "^(\s*" + param_name + ":\s+)(\{\{\s*" + param_name + "\s*\}\})(\s*)(.*)"
;
; Get the parameter name and value without the trailing comment (if any).
;
regex_print = "\1" + param_value_str
sed_cmd = "sed -n -r -e " + char_dq + "s|" + regex_search + "|" \
+ regex_print + "|p" + char_dq + " " + wrtcmp_config_fn
param_names_and_vals(np) = systemfunc(sed_cmd)
+ regex_print + "|p" + char_dq + " " + model_config_tmpl_fp
tmp := systemfunc(sed_cmd)
param_names_and_vals(np) = tmp(0)
;
; Get the trailing name and comment.
;
regex_print = "\4"
sed_cmd = "sed -n -r -e " + char_dq + "s|" + regex_search + "|" \
+ regex_print + "|p" + char_dq + " " + wrtcmp_config_fn
trailing_comments(np) = systemfunc(sed_cmd)

+ regex_print + "|p" + char_dq + " " + model_config_tmpl_fp
tmp := systemfunc(sed_cmd)
trailing_comments(np) = tmp(0)

end do
;
; **********************************************************************
Expand Down Expand Up @@ -429,7 +543,7 @@ end if
regex_search = "^(\s*" + param_name + ":\s+)(<" + param_name + ">)(\s*)(.*)"
regex_replace = lines_final(np)
sed_cmd = "sed -i -r -e " + char_dq + "s|" + regex_search + "|" \
+ regex_replace + "|" + char_dq + " " + wrtcmp_config_fn
+ regex_replace + "|" + char_dq + " " + model_config_tmpl_fp
sed_output = systemfunc(sed_cmd)
end do
;
Expand Down
34 changes: 33 additions & 1 deletion ush/NCL/find_wrtcmp_grid_params.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ expt_dir = "/scratch2/BMC/det/Gerard.Ketefian/UFS_CAM/PR_feature_maximize_CONUS_

expt_dir = "/scratch2/BMC/det/Gerard.Ketefian/UFS_CAM/PR_feature_maximize_CONUS_grids/expt_dirs/try01/grid_RRFS_CONUS_3km_ics_FV3GFS_lbcs_FV3GFS_suite_GFS_v15p2"

expt_dir = "/scratch2/BMC/det/Gerard.Ketefian/UFS_CAM/PR_Jeff_Duda_subhourly_post/expt_dirs/big_grid01/grid_GSD_RAP13km_pregen"
expt_dir = "/scratch2/BMC/det/Gerard.Ketefian/UFS_CAM/PR_Jeff_Duda_subhourly_post/expt_dirs/big_grid01/grid_GSD_RAP13km_pregen_old003"

;
; **********************************************************************
;
Expand Down Expand Up @@ -202,7 +205,8 @@ print("AAAAAAAAAAAAAAAAAAAAAAAAAAA")
;
print("BBBBBBBBBBBBBBBBBBBBBBBBBBB")
remove_rgnl_halo = True
get_tile_bdies = False
; get_tile_bdies = False
get_tile_bdies = True

grid_info := read_FV3LAM_grid_native( \
expt_dir, \
Expand All @@ -221,6 +225,18 @@ print("BBBBBBBBBBBBBBBBBBBBBBBBBBB")
lat_tile_corners_face_midpts_tiles_to_plot \
= grid_info@lat_tile_corners_face_midpts_all_tiles

lon_bdy_tiles_to_plot = grid_info@lon_bdy_all_tiles
lat_bdy_tiles_to_plot = grid_info@lat_bdy_all_tiles

nx_all_tiles := grid_info@nx_all_tiles
ny_all_tiles := grid_info@ny_all_tiles

;print("LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL")
;print("dimsizes(lon_tile_corners_face_midpts_tiles_to_plot) = " + dimsizes(lon_tile_corners_face_midpts_tiles_to_plot))
;print("dimsizes(lon_bdy_tiles_to_plot) = " + dimsizes(lon_bdy_tiles_to_plot))
;print("dimsizes(nx_all_tiles) = " + dimsizes(nx_all_tiles))
;pause

;lon_tile_corners_face_midpts_tiles_to_plot \
;= where(lon_tile_corners_face_midpts_tiles_to_plot .gt. 0.0d+0, \
; lon_tile_corners_face_midpts_tiles_to_plot - 360.0d+0, \
Expand Down Expand Up @@ -249,6 +265,19 @@ print("BBBBBBBBBBBBBBBBBBBBBBBBBBB")
lat_tile_corners_face_midpts_native \
:= lat_tile_corners_face_midpts_tiles_to_plot(nn,:)

nx_native := nx_all_tiles(nn)
ny_native := ny_all_tiles(nn)
;print("nx_native = " + nx_native)
;print("ny_native = " + ny_native)
;pause

indx_start := 0
indx_end := 2*(nx_native + ny_native)
lon_bdy_native := lon_bdy_tiles_to_plot(indx_start:indx_end)
lat_bdy_native := lat_bdy_tiles_to_plot(indx_start:indx_end)
;print("dimsizes(lon_bdy_native) = " + dimsizes(lon_bdy_native))
;pause

angle_units = "deg"

valid_vals_WRTCMP_output_grid \
Expand All @@ -264,6 +293,9 @@ print("BBBBBBBBBBBBBBBBBBBBBBBBBBB")
lon_grid_cntr_native, lat_grid_cntr_native, \
lon_tile_corners_face_midpts_native, \
lat_tile_corners_face_midpts_native, \
lon_bdy_native, \
lat_bdy_native, \
nx_native, ny_native, \
dx_native, dy_native, \
angle_units)

Expand Down
Loading

0 comments on commit c608e29

Please sign in to comment.