Skip to content

Commit

Permalink
[develop] Refactor setup.py to remove use of global variables. (#505)
Browse files Browse the repository at this point in the history
Global variable use has been removed in setup.py, and reduced in generate_FV3LAM_wflow.py. The use of globals is a carry-over from the bash era of this utility, and does not meet modern coding standards.
  • Loading branch information
christinaholtNOAA authored Dec 16, 2022
1 parent bea3633 commit bf07542
Show file tree
Hide file tree
Showing 18 changed files with 1,571 additions and 2,098 deletions.
11 changes: 4 additions & 7 deletions parm/FV3LAM_wflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ Directories and files.
{%- endif %}

{%- if run_envir == "nco" %}
<!ENTITY LOGDIR "{{ logdir }}/<cyclestr>@Y@m@d</cyclestr>">
<!ENTITY LOGDIR "{{ logbasedir }}/<cyclestr>@Y@m@d</cyclestr>">
<!ENTITY LOGEXT ".{{ workflow_id }}.log" >
{%- else %}
<!ENTITY LOGDIR "{{ logdir }}">
<!ENTITY LOGDIR "{{ logbasedir }}">
<!ENTITY LOGEXT ".log" >
{%- endif %}
<!ENTITY CMPEXT "_task_complete.txt">
Expand Down Expand Up @@ -362,11 +362,8 @@ MODULES_RUN_TASK_FP script.
{%- if do_ensemble %}
<metatask name="run_ensemble">

<var name="{{ ensmem_indx_name }}">
{%- for m in range(1, num_ens_members+1) -%}
{%- set fmtstr=" %0"~ndigits_ensmem_names~"d" -%}
{{- fmtstr%m -}}
{%- endfor %} </var>
<var name="{{ ensmem_indx_name }}">{% for m in range(1, num_ens_members+1) %}{{ "%03d " % m }}{% endfor %}</var>

{%- endif %}

{%- if run_task_make_ics %}
Expand Down
2 changes: 1 addition & 1 deletion scripts/exregional_run_vx_ensgrid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export fhr_last
fhr_list=`echo ${FHR} | $SED "s/ /,/g"`
export fhr_list

NUM_PAD=${NDIGITS_ENSMEM_NAMES}
NUM_PAD=3

#
#-----------------------------------------------------------------------
Expand Down
12 changes: 10 additions & 2 deletions tests/WE2E/run_WE2E_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,12 @@ Please correct and rerun."
#
#-----------------------------------------------------------------------
#

# Save the environment variable since a default will override when
# sourced.
save_USHdir=${USHdir}
source_config ${USHdir}/config_defaults.yaml
USHdir=${save_USHdir}
MACHINE_FILE=${machine_file:-"${USHdir}/machine/${machine,,}.yaml"}
source_config ${MACHINE_FILE}
source_config ${test_config_fp}
Expand Down Expand Up @@ -1026,7 +1031,7 @@ model_ver="we2e""
#
# Set NCO mode OPSROOT
#
OPSROOT=\"${opsroot}\""
OPSROOT=\"${opsroot:-$OPSROOT}\""

fi
#
Expand Down Expand Up @@ -1314,10 +1319,13 @@ exist or is not a directory:
#
#-----------------------------------------------------------------------
#
$USHdir/generate_FV3LAM_wflow.py || \
$USHdir/generate_FV3LAM_wflow.py

if [ $? != 0 ] ; then
print_err_msg_exit "\
Could not generate an experiment for the test specified by test_name:
test_name = \"${test_name}\""
fi

done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ user:
RUN_ENVIR: community
workflow:
DATA_TABLE_TMPL_FN: data_table
DIAG_TABLE_TMPL_FN: diag_table
FIELD_TABLE_TMPL_FN: field_table
DIAG_TABLE_TMPL_FN: diag_table.FV3_GFS_v15p2
FIELD_TABLE_TMPL_FN: field_table.FV3_GFS_v15p2
MODEL_CONFIG_TMPL_FN: model_configure
NEMS_CONFIG_TMPL_FN: nems.configure
CCPP_PHYS_SUITE: FV3_GFS_v15p2
Expand Down
33 changes: 19 additions & 14 deletions ush/calculate_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ def calculate_cost(config_fn):
]
import_vars(env_vars=IMPORTS)

ushdir = os.path.dirname(os.path.abspath(__file__))

# get grid config parameters (predefined or custom)
if PREDEF_GRID_NAME:
QUILTING = False
params_dict = set_predef_grid_params(
PREDEF_GRID_NAME,
QUILTING,
DT_ATMOS,
LAYOUT_X,
LAYOUT_Y,
BLOCKSIZE,
USHdir=ushdir,
grid_name=PREDEF_GRID_NAME,
quilting=QUILTING,
)
for param, value in params_dict.items():
if param in IMPORTS and globals()[param] is not None:
params_dict[param] = globals()[param]
import_vars(dictionary=params_dict)
else:
cfg_u = load_config_file(config_fn)
Expand All @@ -60,11 +62,13 @@ def calculate_cost(config_fn):
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,
RUN_ENVIR="community",
VERBOSE=False,
run_envir="community",
verbose=False,
nh4=4,
)

elif GRID_GEN_METHOD == "ESGgrid":
constants = load_config_file(os.path.join(ushdir, "constants.yaml"))
grid_params = set_gridparams_ESGgrid(
lon_ctr=ESGgrid_LON_CTR,
lat_ctr=ESGgrid_LAT_CTR,
Expand All @@ -74,6 +78,7 @@ def calculate_cost(config_fn):
halo_width=ESGgrid_WIDE_HALO_WIDTH,
delx=ESGgrid_DELX,
dely=ESGgrid_DELY,
constants=constants["constants"],
)

NX = grid_params["NX"]
Expand All @@ -84,13 +89,13 @@ def calculate_cost(config_fn):
PREDEF_GRID_NAME = "RRFS_CONUS_25km"

params_dict = set_predef_grid_params(
PREDEF_GRID_NAME,
QUILTING,
DT_ATMOS,
LAYOUT_X,
LAYOUT_Y,
BLOCKSIZE,
USHdir=os.path.dirname(os.path.abspath(__file__)),
grid_name=PREDEF_GRID_NAME,
quilting=QUILTING,
)
for param, value in params_dict.items():
if param in IMPORTS and globals()[param] is not None:
params_dict[param] = globals()[param]
import_vars(dictionary=params_dict)

cost.extend([DT_ATMOS, ESGgrid_NX * ESGgrid_NY])
Expand Down
1 change: 0 additions & 1 deletion ush/config.nco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ nco:
NET: rrfs
model_ver: v1.0
RUN: rrfs_test
OPSROOT: ""
task_get_extrn_ics:
EXTRN_MDL_NAME_ICS: FV3GFS
FV3GFS_FILE_FMT_ICS: grib2
Expand Down
Loading

0 comments on commit bf07542

Please sign in to comment.