Skip to content

Commit

Permalink
Templating diag_tables with Jinja (#211)
Browse files Browse the repository at this point in the history
* Templating diag table with jinja.

* Cleaning modulefiles, and adding run_fcst.local.

* Small mods needed at run time.

* Jet modulefile should be same as Hera.

* Adding missing files back.

* Addressing Gerard's comments.

* Applying this PR's mods to recent additions.

* Updating modulefiles.

* Cheyenne modulefile needs "system" command to call ncar_pylib

Co-authored-by: Michael Kavulich, Jr <[email protected]>
  • Loading branch information
christinaholtNOAA and mkavulich authored Jun 22, 2020
1 parent 8b0dac6 commit 2bfa034
Show file tree
Hide file tree
Showing 22 changed files with 124 additions and 418 deletions.
6 changes: 6 additions & 0 deletions modulefiles/tasks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
make_orog
make_ics
make_lbcs
make_sfc_climo
run_fcst
run_post
2 changes: 2 additions & 0 deletions modulefiles/tasks/cheyenne/run_fcst.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

system "ncar_pylib /glade/p/ral/jntp/UFS_CAM/ncar_pylib_20200427"
1 change: 1 addition & 0 deletions modulefiles/tasks/hera/make_ics.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module load wgrib2

module use -a /contrib/miniconda3/modulefiles
module load miniconda3
Expand Down
1 change: 1 addition & 0 deletions modulefiles/tasks/hera/make_lbcs.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module load wgrib2

module use -a /contrib/miniconda3/modulefiles
module load miniconda3
Expand Down
5 changes: 5 additions & 0 deletions modulefiles/tasks/hera/run_fcst.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module use -a /contrib/miniconda3/modulefiles
module load miniconda3
if [module-info mode load] {
system "conda activate regional_workflow"
}
4 changes: 3 additions & 1 deletion modulefiles/tasks/jet/make_grid
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ module load hdf5/1.10.5

module use -a /contrib/miniconda3/modulefiles
module load miniconda3
system "conda activate regional_workflow"
if [module-info mode load] {
system "conda activate regional_workflow"
}
1 change: 1 addition & 0 deletions modulefiles/tasks/jet/make_ics.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module load wgrib2/2.0.8

module use -a /contrib/miniconda3/modulefiles
module load miniconda3
Expand Down
1 change: 1 addition & 0 deletions modulefiles/tasks/jet/make_lbcs.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module load wgrib2/2.0.8

module use -a /contrib/miniconda3/modulefiles
module load miniconda3
Expand Down
5 changes: 5 additions & 0 deletions modulefiles/tasks/jet/run_fcst.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module use -a /contrib/miniconda3/modulefiles
module load miniconda3
if [module-info mode load] {
system "conda activate regional_workflow"
}
47 changes: 31 additions & 16 deletions scripts/exregional_run_fcst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,6 @@ print_info_msg "$VERBOSE" "
Copying cycle-dependent model input files from the templates directory
to the current cycle's run directory..."

print_info_msg "$VERBOSE" "
Copying the template diagnostics table file to the current cycle's run
directory..."
diag_table_fp="${CYCLE_DIR}/${DIAG_TABLE_FN}"
cp_vrfy "${DIAG_TABLE_TMPL_FP}" "${diag_table_fp}"

print_info_msg "$VERBOSE" "
Copying the template model configuration file to the current cycle's
run directory..."
Expand All @@ -414,24 +408,45 @@ YYYY=${CDATE:0:4}
MM=${CDATE:4:2}
DD=${CDATE:6:2}
HH=${CDATE:8:2}
YYYYMMDD=${CDATE:0:8}
#
#-----------------------------------------------------------------------
#
# Set parameters in the diagnostics table file.
#
#-----------------------------------------------------------------------
#

diag_table_fp="${CYCLE_DIR}/${DIAG_TABLE_FN}"

print_info_msg "$VERBOSE" "
Setting parameters in file:
diag_table_fp = \"${diag_table_fp}\""

set_file_param "${diag_table_fp}" "CRES" "$CRES"
set_file_param "${diag_table_fp}" "YYYY" "$YYYY"
set_file_param "${diag_table_fp}" "MM" "$MM"
set_file_param "${diag_table_fp}" "DD" "$DD"
set_file_param "${diag_table_fp}" "HH" "$HH"
set_file_param "${diag_table_fp}" "YYYYMMDD" "$YYYYMMDD"
Using the template diagnostics table file:
diag_table_tmpl_fp = ${DIAG_TABLE_TMPL_FP}
to create:
diag_table_fp = \"${diag_table_fp}\""

settings="
starttime: !datetime ${CDATE}
cres: ${CRES}
"

$USHDIR/fill_jinja_template.py -q -u "${settings}" -t "${DIAG_TABLE_TMPL_FP}" -o "${diag_table_fp}"

if [[ $? -ne 0 ]] ; then
echo "
!!!!!!!!!!!!!!!!!
fill_jinja_template.py failed!
!!!!!!!!!!!!!!!!!
"

exit 1
fi


#
#-----------------------------------------------------------------------
#
Expand Down
2 changes: 1 addition & 1 deletion ush/create_xml.py → ush/fill_jinja_template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

'''
This utility fills in a user-supplied Jinja template from either a YAML file, or
Expand Down
22 changes: 12 additions & 10 deletions ush/generate_FV3SAR_wflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,35 +184,36 @@ settings="\
# Forecast length (same for all cycles).
#
'fcst_len_hrs': ${FCST_LEN_HRS}"
#
# For debugging purposes, print out what "settings" has been set to.
#

print_info_msg $VERBOSE "
The variable \"settings\" specifying values of the rococo XML variables
has been set as follows:
#-----------------------------------------------------------------------
settings =
$settings"

#
# Set the full path to the template rocoto XML file. Then call a python
# script to generate the experiment's actual XML file from this template
# file.
#
template_xml_fp="${TEMPLATE_DIR}/${WFLOW_XML_FN}"
$USHDIR/create_xml.py -q \
-t ${template_xml_fp} \
-u "$settings" \
-o ${WFLOW_XML_FP} || \
$USHDIR/fill_jinja_template.py -q \
-u "${settings}" \
-t ${template_xml_fp} \
-o ${WFLOW_XML_FP} || \
print_err_msg_exit "\
Call to python script create_xml.py to create a rocoto workflow XML file
from a template file failed. Parameters passed to this script are:
Call to python script fill_jinja_template.py to create a rocoto workflow
XML file from a template file failed. Parameters passed to this script
are:
Full path to template rocoto XML file:
template_xml_fp = \"${template_xml_fp}\"
Full path to output rocoto XML file:
WFLOW_XML_FP = \"${WFLOW_XML_FP}\"
Namelist settings specified on command line:
settings =
$settings"

#
#-----------------------------------------------------------------------
#
Expand Down Expand Up @@ -269,6 +270,7 @@ fi
#
# Only some platforms build EMC_post using modules.
#

case $MACHINE in

"CHEYENNE")
Expand Down
105 changes: 39 additions & 66 deletions ush/load_modules_run_task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,40 +160,9 @@ jjob_fp="$2"
#
# where HOMErrfs is the base directory of the workflow, machine is the
# name of the machine that we're running on (in lowercase), and task_-
# name is the name of the current task (an input to this script). For
# all tasks in the rocoto XML except run_fcst, these are actual files
# (as opposed to symlinks). For the run_fcst task, there are two possi-
# ble module files. The first one is named "run_fcst_no_ccpp" and is
# used to run FV3 without CCPP (i.e. it is used if USE_CCPP is set to
# "FALSE" in the experiment/workflow configuration file). This is also
# an actual file. The second one is named "run_fcst_ccpp" and is used
# to run FV3 with CCPP (i.e. it is used if USE_CCPP is set to "TRUE").
# This second file is a symlink (and is a part of the regional_workflow
# repo), and its target is
#
# ${UFS_WTHR_MDL_DIR}/NEMS/src/conf/modules.fv3
#
# Here, UFS_WTHR_MDL_DIR is the directory in which the ufs_weather_model
# repository containing the FV3 model is cloned (normally "$HOMErrfs/
# sorc/ufs_weather_model"), and modules.fv3 is a module file that is ge-
# nerated by the forecast model's build process. It contains the appro-
# priate modules to use when running the FV3 model. Thus, we just point
# to it via the symlink "run_fcst_ccpp" in the modulefiles/$machine di-
# rectory.
#
# QUESTION:
# Why don't we do this for the non-CCPP version of FV3?
#
# ANSWER:
# Because for that case, we load different versions of intel and impi
# (compare modules.nems to the modules loaded for the case of USE_CCPP
# set to "FALSE" in run_FV3SAR.sh). Maybe these can be combined at some
# point. Note that a modules.nems file is generated in the same rela-
# tive location in the non-CCPP-enabled version of the FV3 forecast mo-
# del, so maybe that can be used and the run_FV3SAR.sh script modified
# to accomodate such a change. That way the below can be performed for
# both the CCPP-enabled and non-CCPP-enabled versions of the forecast
# model.
# name is the name of the current task (an input to this script). The
# collection of modulefiles is staged by the generate_workflow.sh
# script. Please see that script for information on their creation.
#
#-----------------------------------------------------------------------
#
Expand All @@ -217,6 +186,7 @@ use_default_modulefile=0
# fi
#fi
#

#-----------------------------------------------------------------------
#
# This comment needs to be updated:
Expand Down Expand Up @@ -310,45 +280,48 @@ Loading modules for task \"${task_name}\" ..."
module use "${modules_dir}" || print_err_msg_exit "\
Call to \"module use\" command failed."

#
# If NOT using the default modulefile...
#
#
# If NOT using the default modulefile...
#
if [ ${use_default_modulefile} -eq 0 ]; then
#
# Some of the task module files that are symlinks to module files in the
# external repositories are in fact shell scripts (they shouldn't be;
# such cases should be fixed in the external repositories). For such
# files, we source the "module" file. For true module files, we use the
# "module load" command.
#

#
# Some of the task module files that are symlinks to module files in the
# external repositories are in fact shell scripts (they shouldn't be;
# such cases should be fixed in the external repositories). For such
# files, we source the "module" file. For true module files, we use the
# "module load" command.
#
case "${task_name}" in
#
"${MAKE_ICS_TN}" | "${MAKE_LBCS_TN}" | "${MAKE_SFC_CLIMO_TN}")
. ${modulefile_path} || print_err_msg_exit "\
Sourcing of \"module\" file (modulefile_path; really a shell script) for
the specified task (task_name) failed:
task_name = \"${task_name}\"
modulefile_path = \"${modulefile_path}\""
;;
#
*)
module load ${modulefile_name} || print_err_msg_exit "\
Loading of module file (modulefile_name; in directory specified by
modules_dir) for the specified task (task_name) failed:
task_name = \"${task_name}\"
modulefile_name = \"${modulefile_name}\"
modules_dir = \"${modules_dir}\""
;;
#

"${MAKE_ICS_TN}" | "${MAKE_LBCS_TN}" | "${MAKE_SFC_CLIMO_TN}")
. ${modulefile_path} || print_err_msg_exit "\
Sourcing of \"module\" file (modulefile_path; really a shell script) for
the specified task (task_name) failed:
task_name = \"${task_name}\"
modulefile_path = \"${modulefile_path}\""

;;
*)
module use "${modules_dir}" || print_err_msg_exit "\
Call to \"module use\" command failed."

module load ${modulefile_name} || print_err_msg_exit "\
Loading of module file (modulefile_name; in directory specified by mod-
ules_dir) for the specified task (task_name) failed:
task_name = \"${task_name}\"
modulefile_name = \"${modulefile_name}\"
modules_dir = \"${modules_dir}\""
;;
esac

else # using default modulefile

module load ${default_modulefile_name} || print_err_msg_exit "\
Loading of default module file failed:
task_name = \"${task_name}\"
default_modulefile_name = \"${default_modulefile_name}\"
default_modules_dir = \"${default_modules_dir}\""
Loading of default module file failed:
task_name = \"${task_name}\"
default_modulefile_name = \"${default_modulefile_name}\"
default_modules_dir = \"${default_modules_dir}\""

fi

Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_CPT_v0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_4xdaily", 6, "hours", 1, "days", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_GFS_2017_gfdlmp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_static", -1, "hours", 1, "hours", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_GFS_v15p2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_4xdaily", 6, "hours", 1, "days", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_GFS_v16beta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_4xdaily", 6, "hours", 1, "days", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_GSD_SAR
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_static", -1, "hours", 1, "hours", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_GSD_SAR_v1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_static", -1, "hours", 1, "hours", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_GSD_v0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_static", -1, "hours", 1, "hours", "time"
Expand Down
4 changes: 2 additions & 2 deletions ush/templates/diag_table.FV3_RRFS_v0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<YYYYMMDD>.<HH>Z.<CRES>.32bit.non-hydro.regional
<YYYY> <MM> <DD> <HH> 0 0
{{ starttime.strftime("%Y%m%d.%H") }}Z.{{ cres }}.32bit.non-hydro.regional
{{ starttime.strftime("%Y %m %d %H %M %S") }}

"grid_spec", -1, "months", 1, "days", "time"
"atmos_static", -1, "hours", 1, "hours", "time"
Expand Down
Loading

0 comments on commit 2bfa034

Please sign in to comment.