Skip to content

Commit

Permalink
Add task save_input to save DA analysis before run_fcst
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhuazhou committed Dec 11, 2022
1 parent c6942b6 commit 1684e4c
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 20 deletions.
123 changes: 123 additions & 0 deletions jobs/JREGIONAL_SAVE_INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash

#
#-----------------------------------------------------------------------
#
# This script runs the save_input to save DA analysis files to nwges
#
#-----------------------------------------------------------------------
#

#
#-----------------------------------------------------------------------
#
# Source the variable definitions file and the bash utility functions.
#
#-----------------------------------------------------------------------
#
. ${GLOBAL_VAR_DEFNS_FP}
. $USHDIR/source_util_funcs.sh
#
#-----------------------------------------------------------------------
#
# Save current shell options (in a global array). Then set new options
# for this script/function.
#
#-----------------------------------------------------------------------
#
{ save_shell_opts; set -u -x; } > /dev/null 2>&1
#
#-----------------------------------------------------------------------
#
# Get the full path to the file in which this script/function is located
# (scrfunc_fp), the name of that file (scrfunc_fn), and the directory in
# which the file is located (scrfunc_dir).
#
#-----------------------------------------------------------------------
#
scrfunc_fp=$( readlink -f "${BASH_SOURCE[0]}" )
scrfunc_fn=$( basename "${scrfunc_fp}" )
scrfunc_dir=$( dirname "${scrfunc_fp}" )
#
#-----------------------------------------------------------------------
#
# Print message indicating entry into script.
#
#-----------------------------------------------------------------------
#
print_info_msg "
========================================================================
Entering script: \"${scrfunc_fn}\"
In directory: \"${scrfunc_dir}\"
This is the J-job script for the task that runs the post-processor (UPP)
on the output files corresponding to a specified forecast hour.
========================================================================"
#
#-----------------------------------------------------------------------
#
# Set the run directory.
#
#-----------------------------------------------------------------------
# CYCLE_TYPE is to indicate which type of cycle this job for:
# spinup: this job is for spin-up cycles
# others(prod): this job is for product cycle
#
# NWGES_DIR is the directory in which the model IC file (DA analysis) will be saved
#
CYCLE_TYPE=${CYCLE_TYPE:-prod}
CYCLE_SUBTYPE=${CYCLE_SUBTYPE:-empty}
if [ ${CYCLE_TYPE} == "spinup" ]; then
run_dir="${CYCLE_DIR}${SLASH_ENSMEM_SUBDIR}/fcst_fv3lam_spinup"
nwges_dir="${NWGES_DIR}${SLASH_ENSMEM_SUBDIR}/fcst_fv3lam_spinup"
if [ ${CYCLE_SUBTYPE} == "ensinit" ]; then
run_dir="${CYCLE_DIR}${SLASH_ENSMEM_SUBDIR}/fcst_fv3lam_ensinit"
nwges_dir="${NWGES_DIR}${SLASH_ENSMEM_SUBDIR}/fcst_fv3lam_ensinit"
fi
else
run_dir="${CYCLE_DIR}${SLASH_ENSMEM_SUBDIR}/fcst_fv3lam"
nwges_dir="${NWGES_DIR}${SLASH_ENSMEM_SUBDIR}/fcst_fv3lam"
fi

if [ "${RUN_ENVIR}" = "nco" ]; then
mkdir_vrfy -p "${nwges_dir}/DA_OUTPUT"
fi

#
#-----------------------------------------------------------------------
#
# Call the ex-script for this J-job and pass to it the necessary varia-
# bles.
#
#-----------------------------------------------------------------------
#
$SCRIPTSDIR/exregional_save_input.sh \
cdate="${CDATE}" \
run_dir="${run_dir}" \
nwges_dir="${nwges_dir}" \
cycle_type="${CYCLE_TYPE}" \
cycle_subtype="${CYCLE_SUBTYPE}" || \
print_err_msg_exit "\
Call to ex-script corresponding to J-job \"${scrfunc_fn}\" failed."
#
#-----------------------------------------------------------------------
#
# Print exit message.
#
#-----------------------------------------------------------------------
#
print_info_msg "
========================================================================
Exiting script: \"${scrfunc_fn}\"
In directory: \"${scrfunc_dir}\"
========================================================================"
#
#-----------------------------------------------------------------------
#
# Restore the shell options saved at the beginning of this script/func-
# tion.
#
#-----------------------------------------------------------------------
#
{ restore_shell_opts; } > /dev/null 2>&1

4 changes: 2 additions & 2 deletions scripts/exregional_run_analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ if [[ ${regional_ensemble_option:-1} -eq 5 ]]; then
ens_nstarthr=$( printf "%02d" ${DA_CYCLE_INTERV} )
imem=1
ifound=0
for hrs in ${CYCL_HRS_HYB_FV3LAM_ENS}; do
for hrs in ${CYCL_HRS_HYB_FV3LAM_ENS[@]}; do
if [ $HH == ${hrs} ]; then

while [[ $imem -le ${NUM_ENS_MEMBERS} ]];do
Expand All @@ -219,7 +219,7 @@ if [[ ${regional_ensemble_option:-1} -eq 5 ]]; then
slash_ensmem_subdir=$memchar
bkpathmem=${rrfse_fg_root}/${YYYYMMDDHHmInterv}/${slash_ensmem_subdir}/fcst_fv3lam/RESTART
if [ ${DO_SPINUP} == "TRUE" ]; then
for cycl_hrs in ${CYCL_HRS_PRODSTART_ENS}; do
for cycl_hrs in ${CYCL_HRS_PRODSTART_ENS[@]}; do
if [ $HH == ${cycl_hrs} ]; then
bkpathmem=${rrfse_fg_root}/${YYYYMMDDHHmInterv}/${slash_ensmem_subdir}/fcst_fv3lam_spinup/RESTART
fi
Expand Down
152 changes: 152 additions & 0 deletions scripts/exregional_save_input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/bin/bash

#
#-----------------------------------------------------------------------
#
# Source the variable definitions file and the bash utility functions.
#
#-----------------------------------------------------------------------
#
. ${GLOBAL_VAR_DEFNS_FP}
. $USHDIR/source_util_funcs.sh
#
#-----------------------------------------------------------------------
#
# Save current shell options (in a global array). Then set new options
# for this script/function.
#
#-----------------------------------------------------------------------
#
{ save_shell_opts; set -u +x; } > /dev/null 2>&1
#
#-----------------------------------------------------------------------
#
# Get the full path to the file in which this script/function is located
# (scrfunc_fp), the name of that file (scrfunc_fn), and the directory in
# which the file is located (scrfunc_dir).
#
#-----------------------------------------------------------------------
#
scrfunc_fp=$( readlink -f "${BASH_SOURCE[0]}" )
scrfunc_fn=$( basename "${scrfunc_fp}" )
scrfunc_dir=$( dirname "${scrfunc_fp}" )
#
#-----------------------------------------------------------------------
#
# Print message indicating entry into script.
#
#-----------------------------------------------------------------------
#
print_info_msg "
========================================================================
Entering script: \"${scrfunc_fn}\"
In directory: \"${scrfunc_dir}\"
This is the ex-script for the task that runs the post-processor (UPP) on
the output files corresponding to a specified forecast hour.
========================================================================"
#
#-----------------------------------------------------------------------
#
# Specify the set of valid argument names for this script/function.
# Then process the arguments provided to this script/function (which
# should consist of a set of name-value pairs of the form arg1="value1",
# etc).
#
#-----------------------------------------------------------------------
#
valid_args=( \
"cdate" \
"run_dir" \
"nwges_dir" \
"cycle_type" \
"cycle_subtype" \
)
process_args valid_args "$@"
#
#-----------------------------------------------------------------------
#
# For debugging purposes, print out values of arguments passed to this
# script. Note that these will be printed out only if VERBOSE is set to
# TRUE.
#
#-----------------------------------------------------------------------
#
print_input_args valid_args
#
#-----------------------------------------------------------------------
#
# Get the cycle date and hour (in formats of yyyymmdd and hh, respectively)
# from cdate.
#
#-----------------------------------------------------------------------
#
yyyymmdd=${cdate:0:8}
hh=${cdate:8:2}
cyc=$hh

#
#-----------------------------------------------------------------------
#
# Let's save the DA analysis files if needed before run fcst.
# This will copy the data assimilation analysis files from $run_dir/INPUT/
# to ${nwges_dir}/DA_OUTPUT/,
# this is to prepare for ensemble free forecast after the ensemble data assimilation
#
#-----------------------------------------------------------------------
#
filelist="fv_core.res.nc coupler.res"
filelistn="fv_core.res.tile1.nc fv_srf_wnd.res.tile1.nc fv_tracer.res.tile1.nc phy_data.nc sfc_data.nc"
filelistcold="gfs_data.tile7.halo0.nc sfc_data.tile7.halo0.nc"
n_iolayouty=$(($IO_LAYOUT_Y-1))
list_iolayout=$(seq 0 $n_iolayouty)

if [ ! -r ${nwges_dir}/DA_OUTPUT/gfs_ctrl.nc ]; then
cp_vrfy $run_dir/INPUT/gfs_ctrl.nc ${nwges_dir}/DA_OUTPUT/gfs_ctrl.nc
if [ -r ${run_dir}/INPUT/coupler.res ]; then # warm start
if [ "${IO_LAYOUT_Y}" == "1" ]; then
for file in ${filelistn}; do
cp_vrfy $run_dir/INPUT/${file} ${nwges_dir}/DA_OUTPUT/${file}
done
else
for file in ${filelistn}; do
for ii in ${list_iolayout}
do
iii=$(printf %4.4i $ii)
cp_vrfy $run_dir/INPUT/${file}.${iii} ${nwges_dir}/DA_OUTPUT/${file}.${iii}
done
done
fi
for file in ${filelist}; do
cp_vrfy $run_dir/INPUT/${file} ${nwges_dir}/DA_OUTPUT/${file}
done
else # cold start
for file in ${filelistcold}; do
cp_vrfy $run_dir/INPUT/${file} ${nwges_dir}/DA_OUTPUT/${file}
done
fi
fi
#
#-----------------------------------------------------------------------
#
# Print message indicating successful completion of script.
#
#-----------------------------------------------------------------------
#
print_info_msg "
========================================================================
save DA analysis completed successfully.
Exiting script: \"${scrfunc_fn}\"
In directory: \"${scrfunc_dir}\"
========================================================================"
#
#-----------------------------------------------------------------------
#
# Restore the shell options saved at the beginning of this script/func-
# tion.
#
#-----------------------------------------------------------------------
#
{ restore_shell_opts; } > /dev/null 2>&1

6 changes: 6 additions & 0 deletions ush/config_defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ PROCESS_SMOKE_TN="process_smoke"
RADAR_REFL2TTEN_TN="radar_refl2tten"
CLDANL_NONVAR_TN="cldanl_nonvar"
SAVE_RESTART_TN="save_restart"
SAVE_INPUT_TN="save_input"
JEDI_ENVAR_IODA_TN="jedi_envar_ioda"
#
# Number of nodes.
Expand Down Expand Up @@ -1820,6 +1821,7 @@ MAXTRIES_PROCESS_SMOKE="1"
MAXTRIES_RADAR_REF2TTEN="1"
MAXTRIES_CLDANL_NONVAR="1"
MAXTRIES_SAVE_RESTART="1"
MAXTRIES_SAVE_INPUT="1"
MAXTRIES_JEDI_ENVAR_IODA="1"
#
#
Expand Down Expand Up @@ -1955,6 +1957,9 @@ TILE_SETS="full"
# DO_RECENTER:
# Decide whether or not to run recenter for the ensemble members
#
# DO_SAVE_INPUT:
# Decide whether or not to run save_input after the DA analysis
#
# DO_ENS_GRAPHICS:
# Flag to turn on/off ensemble graphics. Turns OFF deterministic
# graphics.
Expand Down Expand Up @@ -2000,6 +2005,7 @@ DO_RECENTER="FALSE"
DO_ENS_GRAPHICS="FALSE"
DO_ENSPOST="FALSE"
DO_ENSINIT="FALSE"
DO_SAVE_INPUT="FALSE"
#
#-----------------------------------------------------------------------
#
Expand Down
3 changes: 3 additions & 0 deletions ush/generate_FV3LAM_wflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ settings="\
'cldanl_nonvar': ${CLDANL_NONVAR_TN}
'run_bufrsnd_tn': ${RUN_BUFRSND_TN}
'save_restart': ${SAVE_RESTART_TN}
'save_input': ${SAVE_INPUT_TN}
'tag': ${TAG}
'jedi_envar_ioda': ${JEDI_ENVAR_IODA_TN}
#
Expand Down Expand Up @@ -368,6 +369,7 @@ settings="\
'maxtries_radar_ref2tten': ${MAXTRIES_RADAR_REF2TTEN}
'maxtries_cldanl_nonvar': ${MAXTRIES_CLDANL_NONVAR}
'maxtries_save_restart': ${MAXTRIES_SAVE_RESTART}
'maxtries_save_input': ${MAXTRIES_SAVE_INPUT}
'maxtries_jedi_envar_ioda': ${MAXTRIES_JEDI_ENVAR_IODA}
#
# Flags that specify whether to run the preprocessing tasks.
Expand Down Expand Up @@ -473,6 +475,7 @@ settings="\
'do_ens_graphics': ${DO_ENS_GRAPHICS}
'do_enspost': ${DO_ENSPOST}
'do_ensinit': ${DO_ENSINIT}
'do_save_input': ${DO_SAVE_INPUT}
#
# data assimilation related parameters.
#
Expand Down
22 changes: 21 additions & 1 deletion ush/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ fi
#
check_var_valid_value "DO_ENSINIT" "valid_vals_DO_ENSINIT"
#
# Set DO_ENSFCST to either "TRUE" or "FALSE" so we don't have to consider
# Set DO_ENSINIT to either "TRUE" or "FALSE" so we don't have to consider
# other valid values later on.
#
DO_ENSINIT=${DO_ENSINIT^^}
Expand All @@ -1654,6 +1654,26 @@ fi
#
#-----------------------------------------------------------------------
#
# Make sure that DO_SAVE_INPUT is set to a valid value.
#
#-----------------------------------------------------------------------
#
check_var_valid_value "DO_SAVE_INPUT" "valid_vals_DO_SAVE_INPUT"
#
# Set DO_SAVE_INPUT to either "TRUE" or "FALSE" so we don't have to consider
# other valid values later on.
#
DO_SAVE_INPUT=${DO_SAVE_INPUT^^}
if [ "$DO_SAVE_INPUT" = "TRUE" ] || \
[ "$DO_SAVE_INPUT" = "YES" ]; then
DO_SAVE_INPUT="TRUE"
elif [ "$DO_SAVE_INPUT" = "FALSE" ] || \
[ "$DO_SAVE_INPUT" = "NO" ]; then
DO_SAVE_INPUT="FALSE"
fi
#
#-----------------------------------------------------------------------
#
# Make sure that DO_ENSFCST is set to a valid value.
#
#-----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 1684e4c

Please sign in to comment.