From 5f84b41574d5d403804bc8087ff85f685864b063 Mon Sep 17 00:00:00 2001 From: Daniel Abdi Date: Tue, 24 May 2022 22:52:35 +0000 Subject: [PATCH] Updates from PR #776 --- .../WE2E/get_WE2Etest_names_subdirs_descs.sh | 149 ++---------------- ush/calculate_cost.py | 105 ++++++++++++ ush/constants.py | 27 ---- ush/constants.sh | 6 +- ush/get_crontab_contents.py | 1 - ush/set_gridparams_ESGgrid.py | 33 ++-- ush/set_gridparams_ESGgrid.sh | 4 +- ush/set_gridparams_GFDLgrid.py | 2 - ush/set_predef_grid_params.py | 5 +- ush/set_predef_grid_params.sh | 12 +- ush/setup.py | 78 +++------ 11 files changed, 173 insertions(+), 249 deletions(-) create mode 100755 ush/calculate_cost.py delete mode 100644 ush/constants.py diff --git a/tests/WE2E/get_WE2Etest_names_subdirs_descs.sh b/tests/WE2E/get_WE2Etest_names_subdirs_descs.sh index 57262e9261..8bea98da25 100755 --- a/tests/WE2E/get_WE2Etest_names_subdirs_descs.sh +++ b/tests/WE2E/get_WE2Etest_names_subdirs_descs.sh @@ -1220,70 +1220,16 @@ ${test_desc}${stripped_line} " # parameters. The way the latter are obtained depends on whether or not # a predefined grid is being used. # -# If using a predefined grid, call the set_predef_grid_params() function -# to get the grid parameters. -# - if [ ! -z "${PREDEF_GRID_NAME}" ]; then -# -# Note: -# Can set "quilting" to "FALSE" in the following argument list because -# the write-component parameters are not needed below; only those of the -# native grid are needed. -# - set_predef_grid_params \ - predef_grid_name="${PREDEF_GRID_NAME}" \ - quilting="FALSE" \ - outvarname_grid_gen_method="grid_gen_method" \ - outvarname_esggrid_lon_ctr="esggrid_lon_ctr" \ - outvarname_esggrid_lat_ctr="esggrid_lat_ctr" \ - outvarname_esggrid_delx="esggrid_delx" \ - outvarname_esggrid_dely="esggrid_dely" \ - outvarname_esggrid_nx="esggrid_nx" \ - outvarname_esggrid_ny="esggrid_ny" \ - outvarname_esggrid_pazi="esggrid_pazi" \ - outvarname_esggrid_wide_halo_width="esggrid_wide_halo_width" \ - outvarname_gfdlgrid_lon_t6_ctr="gfdlgrid_lon_t6_ctr" \ - outvarname_gfdlgrid_lat_t6_ctr="gfdlgrid_lat_t6_ctr" \ - outvarname_gfdlgrid_stretch_fac="gfdlgrid_stretch_fac" \ - outvarname_gfdlgrid_res="gfdlgrid_res" \ - outvarname_gfdlgrid_refine_ratio="gfdlgrid_refine_ratio" \ - outvarname_gfdlgrid_istart_of_rgnl_dom_on_t6g="gfdlgrid_istart_of_rgnl_dom_on_t6g" \ - outvarname_gfdlgrid_iend_of_rgnl_dom_on_t6g="gfdlgrid_iend_of_rgnl_dom_on_t6g" \ - outvarname_gfdlgrid_jstart_of_rgnl_dom_on_t6g="gfdlgrid_jstart_of_rgnl_dom_on_t6g" \ - outvarname_gfdlgrid_jend_of_rgnl_dom_on_t6g="gfdlgrid_jend_of_rgnl_dom_on_t6g" \ - outvarname_dt_atmos="dta" -# -# If using a custom grid, the test's configuration file should contain -# the grid parameters. Source this file and set the values of the grid -# parameters it contains to local variables. -# - else - - . ./${config_fn} - grid_gen_method="${GRID_GEN_METHOD}" - if [ "${grid_gen_method}" = "GFDLgrid" ]; then - gfdlgrid_lon_t6_ctr="${GFDLgrid_LON_T6_CTR}" - gfdlgrid_lat_t6_ctr="${GFDLgrid_LAT_T6_CTR}" - gfdlgrid_res="${GFDLgrid_RES}" - gfdlgrid_stretch_fac="${GFDLgrid_STRETCH_FAC}" - gfdlgrid_refine_ratio="${GFDLgrid_REFINE_RATIO}" - gfdlgrid_istart_of_rgnl_dom_on_t6g="${GFDLgrid_ISTART_OF_RGNL_DOM_ON_T6G}" - gfdlgrid_iend_of_rgnl_dom_on_t6g="${GFDLgrid_IEND_OF_RGNL_DOM_ON_T6G}" - gfdlgrid_jstart_of_rgnl_dom_on_t6g="${GFDLgrid_JSTART_OF_RGNL_DOM_ON_T6G}" - gfdlgrid_jend_of_rgnl_dom_on_t6g="${GFDLgrid_JEND_OF_RGNL_DOM_ON_T6G}" - elif [ "${grid_gen_method}" = "ESGgrid" ]; then - esggrid_lon_ctr="${ESGgrid_LON_CTR}" - esggrid_lat_ctr="${ESGgrid_LAT_CTR}" - esggrid_delx="${ESGgrid_DELX}" - esggrid_dely="${ESGgrid_DELY}" - esggrid_nx="${ESGgrid_NX}" - esggrid_ny="${ESGgrid_NY}" - esggrid_pazi="${ESGgrid_PAZI}" - esggrid_wide_halo_width="${ESGgrid_WIDE_HALO_WIDTH}" - fi - dta="${DT_ATMOS}" +params=$(\ + PREDEF_GRID_NAME="${PREDEF_GRID_NAME}" \ + QUILTING="FALSE" \ + RADIUS_EARTH=${RADIUS_EARTH} \ + DEGS_PER_RADIAN=${DEGS_PER_RADIAN} \ + NH4=${NH4} \ + $ushdir/calculate_cost.py -c "${test_configs_basedir}/$subdir/${config_fn}") + +read dta nxny dta_r nxny_r <<< "${params}" - fi # # Save the value of dta (which is just dt_atmos) in an array. The single # quote at the beginning forces Google Sheets to interpret this quantity @@ -1292,49 +1238,9 @@ ${test_desc}${stripped_line} " # prim_test_dt_atmos+=( "'${dta}" ) # -# The way the number of grid points in the horizontal directions (nx and -# ny) are calculated depends on the method used to generate the grid as -# well as the grid parameters for that method. -# - if [ "${grid_gen_method}" = "GFDLgrid" ]; then -# -# Note: -# The workflow generation mode (run_envir) can be set to "community" here -# since this does not affect the values of nx and ny. -# - set_gridparams_GFDLgrid \ - lon_of_t6_ctr="${gfdlgrid_lon_t6_ctr}" \ - lat_of_t6_ctr="${gfdlgrid_lat_t6_ctr}" \ - res_of_t6g="${gfdlgrid_res}" \ - stretch_factor="${gfdlgrid_stretch_fac}" \ - refine_ratio_t6g_to_t7g="${gfdlgrid_refine_ratio}" \ - istart_of_t7_on_t6g="${gfdlgrid_istart_of_rgnl_dom_on_t6g}" \ - iend_of_t7_on_t6g="${gfdlgrid_iend_of_rgnl_dom_on_t6g}" \ - jstart_of_t7_on_t6g="${gfdlgrid_jstart_of_rgnl_dom_on_t6g}" \ - jend_of_t7_on_t6g="${gfdlgrid_jend_of_rgnl_dom_on_t6g}" \ - verbose="$verbose" \ - outvarname_nx_of_t7_on_t7g="nx" \ - outvarname_ny_of_t7_on_t7g="ny" - - elif [ "${grid_gen_method}" = "ESGgrid" ]; then - - set_gridparams_ESGgrid \ - lon_ctr="${esggrid_lon_ctr}" \ - lat_ctr="${esggrid_lat_ctr}" \ - nx="${esggrid_nx}" \ - ny="${esggrid_ny}" \ - pazi="${esggrid_pazi}" \ - halo_width="${esggrid_wide_halo_width}" \ - delx="${esggrid_delx}" \ - dely="${esggrid_dely}" \ - outvarname_nx="nx" \ - outvarname_ny="ny" - - fi -# # Calculate the total number of horizontal grid points. # - num_grid_pts=$(( nx*ny )) + num_grid_pts=$nxny # # Calculate the number of time steps for the test. Note that FCST_LEN_HRS # is in units of hours while dta is in units of seconds. @@ -1345,30 +1251,6 @@ ${test_desc}${stripped_line} " # ac=$(( num_grid_pts*num_time_steps*nf )) # -# Unset all grid paramters so that they are not accidentally reused for -# the next test. -# - unset gfdlgrid_lon_t6_ctr \ - gfdlgrid_lat_t6_ctr \ - gfdlgrid_res \ - gfdlgrid_stretch_fac \ - gfdlgrid_refine_ratio \ - gfdlgrid_istart_of_rgnl_dom_on_t6g \ - gfdlgrid_iend_of_rgnl_dom_on_t6g \ - gfdlgrid_jstart_of_rgnl_dom_on_t6g \ - gfdlgrid_jend_of_rgnl_dom_on_t6g \ - esggrid_lon_ctr \ - esggrid_lat_ctr \ - esggrid_nx \ - esggrid_ny \ - esggrid_pazi \ - esggrid_wide_halo_width \ - esggrid_delx \ - esggrid_dely \ - dta \ - nx \ - ny -# # Save the absolute cost for this test in the array that will eventually # contain the relative cost. The values in this array will be divided # by abs_cost_ref later below to obtain relative costs. @@ -1394,16 +1276,9 @@ ${test_desc}${stripped_line} " # #----------------------------------------------------------------------- # - set_predef_grid_params \ - predef_grid_name="RRFS_CONUS_25km" \ - quilting="FALSE" \ - outvarname_esggrid_nx="nx" \ - outvarname_esggrid_ny="ny" \ - outvarname_dt_atmos="dta" - - num_grid_pts=$(( nx*ny )) + num_grid_pts=$nxny_r fcst_len_hrs="6" - num_time_steps=$(( fcst_len_hrs*3600/dta+ 1 )) + num_time_steps=$(( fcst_len_hrs*3600/dta_r+ 1 )) abs_cost_ref=$(( num_grid_pts*num_time_steps )) for (( i=0; i<=$((num_prim_tests-1)); i++ )); do diff --git a/ush/calculate_cost.py b/ush/calculate_cost.py new file mode 100755 index 0000000000..f982829020 --- /dev/null +++ b/ush/calculate_cost.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 + +import os +import unittest +import argparse + +from python_utils import set_env_var, import_vars, export_vars, load_config_file + +from set_predef_grid_params import set_predef_grid_params +from set_gridparams_ESGgrid import set_gridparams_ESGgrid +from set_gridparams_GFDLgrid import set_gridparams_GFDLgrid + +def calculate_cost(config_fn): + global PREDEF_GRID_NAME, QUILTING, GRID_GEN_METHOD + + #import all environment variables + import_vars() + + #get grid config parameters (predefined or custom) + if PREDEF_GRID_NAME: + set_env_var('QUILTING',False) + set_predef_grid_params() + import_vars() + else: + cfg_u = load_config_file(config_fn) + import_vars(dictionary=cfg_u) + + #number of gridpoints (nx*ny) depends on grid generation method + if GRID_GEN_METHOD == "GFDLgrid": + (\ + LON_CTR,LAT_CTR,NX,NY,NHW,STRETCH_FAC, + ISTART_OF_RGNL_DOM_WITH_WIDE_HALO_ON_T6SG, + IEND_OF_RGNL_DOM_WITH_WIDE_HALO_ON_T6SG, + JSTART_OF_RGNL_DOM_WITH_WIDE_HALO_ON_T6SG, + JEND_OF_RGNL_DOM_WITH_WIDE_HALO_ON_T6SG \ + ) = \ + set_gridparams_GFDLgrid( \ + lon_of_t6_ctr=GFDLgrid_LON_T6_CTR, \ + lat_of_t6_ctr=GFDLgrid_LAT_T6_CTR, \ + res_of_t6g=GFDLgrid_RES, \ + stretch_factor=GFDLgrid_STRETCH_FAC, \ + refine_ratio_t6g_to_t7g=GFDLgrid_REFINE_RATIO, \ + istart_of_t7_on_t6g=GFDLgrid_ISTART_OF_RGNL_DOM_ON_T6G, \ + iend_of_t7_on_t6g=GFDLgrid_IEND_OF_RGNL_DOM_ON_T6G, \ + jstart_of_t7_on_t6g=GFDLgrid_JSTART_OF_RGNL_DOM_ON_T6G, \ + jend_of_t7_on_t6g=GFDLgrid_JEND_OF_RGNL_DOM_ON_T6G) + + elif GRID_GEN_METHOD == "ESGgrid": + (\ + LON_CTR,LAT_CTR,NX,NY,PAZI, + NHW,STRETCH_FAC,DEL_ANGLE_X_SG,DEL_ANGLE_Y_SG, + NEG_NX_OF_DOM_WITH_WIDE_HALO, + NEG_NY_OF_DOM_WITH_WIDE_HALO \ + ) = \ + set_gridparams_ESGgrid( \ + lon_ctr=ESGgrid_LON_CTR, \ + lat_ctr=ESGgrid_LAT_CTR, \ + nx=ESGgrid_NX, \ + ny=ESGgrid_NY, \ + pazi=ESGgrid_PAZI, \ + halo_width=ESGgrid_WIDE_HALO_WIDTH, \ + delx=ESGgrid_DELX, \ + dely=ESGgrid_DELY) + + cost = [DT_ATMOS, NX*NY] + + #reference grid (6-hour forecast on RRFS_CONUS_25km) + PREDEF_GRID_NAME="RRFS_CONUS_25km" + + export_vars() + set_predef_grid_params() + import_vars() + cost.extend([DT_ATMOS, ESGgrid_NX*ESGgrid_NY]) + + return cost + +#interface +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=\ + 'Calculates parameters needed for calculating cost.') + parser.add_argument('--cfg','-c',dest='cfg',required=True, + help='config file containing grip params') + args = parser.parse_args() + + params = calculate_cost(args.cfg) + print(' '.join(map(str,params))) + +class Testing(unittest.TestCase): + def test_calculate_cost(self): + USHDIR = os.path.dirname(os.path.abspath(__file__)) + config_fn = os.path.join(USHDIR, "config.community.sh") + params = calculate_cost(config_fn) + self.assertCountEqual(params, [36, 1987440, 36, 28689]) + + def setUp(self): + set_env_var('DEBUG',False) + set_env_var('PREDEF_GRID_NAME',"RRFS_CONUS_3km") + set_env_var('DT_ATMOS',36) + set_env_var('LAYOUT_X',18) + set_env_var('LAYOUT_Y',36) + set_env_var('BLOCKSIZE',28) + set_env_var('QUILTING',False) + set_env_var('RADIUS_EARTH',6371200.0) + set_env_var('DEGS_PER_RADIAN',57.2957795131) + diff --git a/ush/constants.py b/ush/constants.py deleted file mode 100644 index e0ff60a0b0..0000000000 --- a/ush/constants.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/env/bin python3 - -# -#----------------------------------------------------------------------- -# -# Mathematical and physical constants. -# -#----------------------------------------------------------------------- -# - -# Pi. -pi_geom = 3.14159265358979323846264338327 - -# Degrees per radian. -degs_per_radian = 360.0 / (2.0 * pi_geom) - -# Radius of the Earth in meters. -radius_Earth = 6371200.0 - -# -#----------------------------------------------------------------------- -# -# Other. -# -#----------------------------------------------------------------------- -# -valid_vals_BOOLEAN = [True, False] diff --git a/ush/constants.sh b/ush/constants.sh index 26f4cb1b32..f5bce884e8 100644 --- a/ush/constants.sh +++ b/ush/constants.sh @@ -7,13 +7,13 @@ # # Pi. -pi_geom="3.14159265358979323846264338327" +PI_GEOM="3.14159265358979323846264338327" # Degrees per radian. -degs_per_radian=$( bc -l <<< "360.0/(2.0*${pi_geom})" ) +DEGS_PER_RADIAN=$( bc -l <<< "360.0/(2.0*${PI_GEOM})" ) # Radius of the Earth in meters. -radius_Earth="6371200.0" +RADIUS_EARTH="6371200.0" # #----------------------------------------------------------------------- # diff --git a/ush/get_crontab_contents.py b/ush/get_crontab_contents.py index 6daeca0c40..3f885ad978 100644 --- a/ush/get_crontab_contents.py +++ b/ush/get_crontab_contents.py @@ -8,7 +8,6 @@ from python_utils import import_vars, set_env_var, print_input_args, \ run_command, define_macos_utilities, print_info_msg -from constants import valid_vals_BOOLEAN def get_crontab_contents(called_from_cron): """ diff --git a/ush/set_gridparams_ESGgrid.py b/ush/set_gridparams_ESGgrid.py index c1ead9522f..722c2f27e2 100644 --- a/ush/set_gridparams_ESGgrid.py +++ b/ush/set_gridparams_ESGgrid.py @@ -3,7 +3,6 @@ import unittest from datetime import datetime,timedelta -from constants import radius_Earth,degs_per_radian from python_utils import import_vars, set_env_var, print_input_args def set_gridparams_ESGgrid(lon_ctr,lat_ctr,nx,ny,halo_width,delx,dely,pazi): @@ -24,6 +23,10 @@ def set_gridparams_ESGgrid(lon_ctr,lat_ctr,nx,ny,halo_width,delx,dely,pazi): """ print_input_args(locals()) + + # get needed environment variables + IMPORTS = ['RADIUS_EARTH', 'DEGS_PER_RADIAN'] + import_vars(env_vars=IMPORTS) # #----------------------------------------------------------------------- # @@ -57,8 +60,8 @@ def set_gridparams_ESGgrid(lon_ctr,lat_ctr,nx,ny,halo_width,delx,dely,pazi): # #----------------------------------------------------------------------- # - del_angle_x_sg = (delx / (2.0 * radius_Earth)) * degs_per_radian - del_angle_y_sg = (dely / (2.0 * radius_Earth)) * degs_per_radian + del_angle_x_sg = (delx / (2.0 * RADIUS_EARTH)) * DEGS_PER_RADIAN + del_angle_y_sg = (dely / (2.0 * RADIUS_EARTH)) * DEGS_PER_RADIAN neg_nx_of_dom_with_wide_halo = -(nx + 2 * halo_width) neg_ny_of_dom_with_wide_halo = -(ny + 2 * halo_width) # @@ -69,10 +72,10 @@ def set_gridparams_ESGgrid(lon_ctr,lat_ctr,nx,ny,halo_width,delx,dely,pazi): #----------------------------------------------------------------------- # return (lon_ctr,lat_ctr,nx,ny,pazi,halo_width,stretch_factor, - "{:0.10f}".format(del_angle_x_sg), - "{:0.10f}".format(del_angle_y_sg), - "{:.0f}".format(neg_nx_of_dom_with_wide_halo), - "{:.0f}".format(neg_ny_of_dom_with_wide_halo)) + del_angle_x_sg, + del_angle_y_sg, + int(neg_nx_of_dom_with_wide_halo), + int(neg_ny_of_dom_with_wide_halo)) class Testing(unittest.TestCase): def test_set_gridparams_ESGgrid(self): @@ -93,18 +96,18 @@ def test_set_gridparams_ESGgrid(self): self.assertEqual(\ (LON_CTR,LAT_CTR,NX,NY,PAZI,NHW,STRETCH_FAC, - DEL_ANGLE_X_SG, - DEL_ANGLE_Y_SG, + round(DEL_ANGLE_X_SG,10), + round(DEL_ANGLE_Y_SG,10), NEG_NX_OF_DOM_WITH_WIDE_HALO, NEG_NY_OF_DOM_WITH_WIDE_HALO), (-97.5, 38.5, 1748, 1038, 0.0, 6,0.999, - "0.0134894006", - "0.0134894006", - "-1760", - "-1050") + 0.0134894006, + 0.0134894006, + -1760, + -1050) ) def setUp(self): - set_env_var('DEBUG',True) - set_env_var('VERBOSE',True) + set_env_var('RADIUS_EARTH',6371200.0) + set_env_var('DEGS_PER_RADIAN',57.2957795131) diff --git a/ush/set_gridparams_ESGgrid.sh b/ush/set_gridparams_ESGgrid.sh index 4b81377713..b32ae3d405 100644 --- a/ush/set_gridparams_ESGgrid.sh +++ b/ush/set_gridparams_ESGgrid.sh @@ -140,10 +140,10 @@ function set_gridparams_ESGgrid() { # #----------------------------------------------------------------------- # - del_angle_x_sg=$( bc -l <<< "(${delx}/(2.0*${radius_Earth}))*${degs_per_radian}" ) + del_angle_x_sg=$( bc -l <<< "(${delx}/(2.0*${RADIUS_EARTH}))*${DEGS_PER_RADIAN}" ) del_angle_x_sg=$( printf "%0.10f\n" ${del_angle_x_sg} ) - del_angle_y_sg=$( bc -l <<< "(${dely}/(2.0*${radius_Earth}))*${degs_per_radian}" ) + del_angle_y_sg=$( bc -l <<< "(${dely}/(2.0*${RADIUS_EARTH}))*${DEGS_PER_RADIAN}" ) del_angle_y_sg=$( printf "%0.10f\n" ${del_angle_y_sg} ) neg_nx_of_dom_with_wide_halo=$( bc -l <<< "-($nx + 2*${halo_width})" ) diff --git a/ush/set_gridparams_GFDLgrid.py b/ush/set_gridparams_GFDLgrid.py index 0dab11f756..40a74d8105 100644 --- a/ush/set_gridparams_GFDLgrid.py +++ b/ush/set_gridparams_GFDLgrid.py @@ -2,8 +2,6 @@ import unittest -from constants import radius_Earth,degs_per_radian - from python_utils import import_vars, set_env_var, print_input_args, \ print_info_msg, print_err_msg_exit diff --git a/ush/set_predef_grid_params.py b/ush/set_predef_grid_params.py index cd9742337a..970187e1de 100644 --- a/ush/set_predef_grid_params.py +++ b/ush/set_predef_grid_params.py @@ -3,8 +3,6 @@ import unittest import os -from constants import radius_Earth,degs_per_radian - from python_utils import process_args,import_vars,export_vars,set_env_var,get_env_var,\ print_input_args,define_macos_utilities, load_config_file, \ cfg_to_yaml_str @@ -21,7 +19,8 @@ def set_predef_grid_params(): IMPORTS = ['PREDEF_GRID_NAME', 'QUILTING', 'DT_ATMOS', 'LAYOUT_X', 'LAYOUT_Y', 'BLOCKSIZE'] import_vars(env_vars=IMPORTS) - params_dict = load_config_file("predef_grid_params.yaml") + USHDIR = os.path.dirname(os.path.abspath(__file__)) + params_dict = load_config_file(os.path.join(USHDIR,"predef_grid_params.yaml")) params_dict = params_dict[PREDEF_GRID_NAME] # if QUILTING = False, skip variables that start with "WRTCMP_" diff --git a/ush/set_predef_grid_params.sh b/ush/set_predef_grid_params.sh index 71c3d12a7e..59c93b38f5 100644 --- a/ush/set_predef_grid_params.sh +++ b/ush/set_predef_grid_params.sh @@ -673,8 +673,8 @@ function set_predef_grid_params() { # __wrtcmp_lat_upr_rght__="13.56176982" ## __wrtcmp_dlon__="0.11691181" ## __wrtcmp_dlat__="0.11691181" -# __wrtcmp_dlon__=$( printf "%.9f" $( bc -l <<< "(${esggrid_delx}/${radius_Earth})*${degs_per_radian}" ) ) -# __wrtcmp_dlat__=$( printf "%.9f" $( bc -l <<< "(${esggrid_dely}/${radius_Earth})*${degs_per_radian}" ) ) +# __wrtcmp_dlon__=$( printf "%.9f" $( bc -l <<< "(${esggrid_delx}/${RADIUS_EARTH})*${DEGS_PER_RADIAN}" ) ) +# __wrtcmp_dlat__=$( printf "%.9f" $( bc -l <<< "(${esggrid_dely}/${RADIUS_EARTH})*${DEGS_PER_RADIAN}" ) ) # fi ;; # @@ -1533,8 +1533,8 @@ function set_predef_grid_params() { __wrtcmp_lat_lwr_left__="-37.0" __wrtcmp_lon_upr_rght__="61.0" __wrtcmp_lat_upr_rght__="37.0" - __wrtcmp_dlon__=$( printf "%.9f" $( bc -l <<< "(${__esggrid_delx__}/${radius_Earth})*${degs_per_radian}" ) ) - __wrtcmp_dlat__=$( printf "%.9f" $( bc -l <<< "(${__esggrid_dely__}/${radius_Earth})*${degs_per_radian}" ) ) + __wrtcmp_dlon__=$( printf "%.9f" $( bc -l <<< "(${__esggrid_delx__}/${RADIUS_EARTH})*${DEGS_PER_RADIAN}" ) ) + __wrtcmp_dlat__=$( printf "%.9f" $( bc -l <<< "(${__esggrid_dely__}/${RADIUS_EARTH})*${DEGS_PER_RADIAN}" ) ) fi ;; # @@ -1577,8 +1577,8 @@ function set_predef_grid_params() { __wrtcmp_lat_lwr_left__="-37.0" __wrtcmp_lon_upr_rght__="61.0" __wrtcmp_lat_upr_rght__="37.0" - __wrtcmp_dlon__="0.025" #$( printf "%.9f" $( bc -l <<< "(${__esggrid_delx__}/${radius_Earth})*${degs_per_radian}" ) ) - __wrtcmp_dlat__="0.025" #$( printf "%.9f" $( bc -l <<< "(${__esggrid_dely__}/${radius_Earth})*${degs_per_radian}" ) ) + __wrtcmp_dlon__="0.025" #$( printf "%.9f" $( bc -l <<< "(${__esggrid_delx__}/${RADIUS_EARTH})*${DEGS_PER_RADIAN}" ) ) + __wrtcmp_dlat__="0.025" #$( printf "%.9f" $( bc -l <<< "(${__esggrid_dely__}/${RADIUS_EARTH})*${DEGS_PER_RADIAN}" ) ) fi ;; diff --git a/ush/setup.py b/ush/setup.py index 586303e77d..784639ab9d 100644 --- a/ush/setup.py +++ b/ush/setup.py @@ -91,6 +91,14 @@ def setup(): not defined in the default configuration file {EXPT_DEFAULT_CONFIG_FN}''') import_vars(dictionary=cfg_u) + # + #----------------------------------------------------------------------- + # Source constants.sh and save its contents to a variable for later + #----------------------------------------------------------------------- + # + cfg_c=load_config_file(os.path.join(ushdir,CONSTANTS_FN)) + const_lines=cfg_to_shell_str(cfg_c) + import_vars(dictionary=cfg_c) # #----------------------------------------------------------------------- # @@ -99,14 +107,10 @@ def setup(): # #----------------------------------------------------------------------- # - - # export env vars before calling another module - export_vars() - if PREDEF_GRID_NAME: + export_vars() set_predef_grid_params() - - import_vars() + import_vars() # #----------------------------------------------------------------------- @@ -1419,50 +1423,6 @@ def setup(): # #----------------------------------------------------------------------- # - # Any regional model must be supplied lateral boundary conditions (in - # addition to initial conditions) to be able to perform a forecast. In - # the FV3-LAM model, these boundary conditions (BCs) are supplied using a - # "halo" of grid cells around the regional domain that extend beyond the - # boundary of the domain. The model is formulated such that along with - # files containing these BCs, it needs as input the following files (in - # NetCDF format): - # - # 1) A grid file that includes a halo of 3 cells beyond the boundary of - # the domain. - # 2) A grid file that includes a halo of 4 cells beyond the boundary of - # the domain. - # 3) A (filtered) orography file without a halo, i.e. a halo of width - # 0 cells. - # 4) A (filtered) orography file that includes a halo of 4 cells beyond - # the boundary of the domain. - # - # Note that the regional grid is referred to as "tile 7" in the code. - # We will let: - # - # * NH0 denote the width (in units of number of cells on tile 7) of - # the 0-cell-wide halo, i.e. NH0 = 0; - # - # * NH3 denote the width (in units of number of cells on tile 7) of - # the 3-cell-wide halo, i.e. NH3 = 3; and - # - # * NH4 denote the width (in units of number of cells on tile 7) of - # the 4-cell-wide halo, i.e. NH4 = 4. - # - # We define these variables next. - # - #----------------------------------------------------------------------- - # - global NH0,NH3,NH4 - NH0=0 - NH3=3 - NH4=4 - - # export env vars - EXPORTS = ["NH0","NH3","NH4"] - export_vars(env_vars = EXPORTS) - # - #----------------------------------------------------------------------- - # # Set parameters according to the type of horizontal grid generation # method specified. First consider GFDL's global-parent-grid based # method. @@ -1779,11 +1739,26 @@ def setup(): global GLOBAL_VAR_DEFNS_FP GLOBAL_VAR_DEFNS_FP=os.path.join(EXPTDIR,GLOBAL_VAR_DEFNS_FN) all_lines=cfg_to_shell_str(cfg_d) + with open(GLOBAL_VAR_DEFNS_FP,'w') as f: msg = f""" # + # #----------------------------------------------------------------------- #----------------------------------------------------------------------- # Section 1: + # This section contains definitions of the various constants defined in + # the file {CONSTANTS_FN}. + #----------------------------------------------------------------------- + #----------------------------------------------------------------------- + # + """ + f.write(dedent(msg)) + f.write(const_lines) + + msg = f""" # + #----------------------------------------------------------------------- + #----------------------------------------------------------------------- + # Section 2: # This section contains (most of) the primary experiment variables, i.e. # those variables that are defined in the default configuration file # (config_defaults.sh) and that can be reset via the user-specified @@ -1975,9 +1950,6 @@ def setup(): # GTYPE='{GTYPE}' TILE_RGNL='{TILE_RGNL}' - NH0='{NH0}' - NH3='{NH3}' - NH4='{NH4}' LON_CTR='{LON_CTR}' LAT_CTR='{LAT_CTR}'