From b2f9ce90cfedd36b0c90cb440656c4f92c2a607b Mon Sep 17 00:00:00 2001 From: Daniel Abdi Date: Wed, 26 Apr 2023 12:39:16 +0000 Subject: [PATCH 1/4] Create separate namelists for DA. --- ush/generate_FV3LAM_wflow.py | 335 +++++++++++++++++++++++------- ush/set_FV3nml_ens_stoch_seeds.py | 6 +- 2 files changed, 265 insertions(+), 76 deletions(-) diff --git a/ush/generate_FV3LAM_wflow.py b/ush/generate_FV3LAM_wflow.py index 3e3d689dc7..80a1069ff7 100755 --- a/ush/generate_FV3LAM_wflow.py +++ b/ush/generate_FV3LAM_wflow.py @@ -176,7 +176,6 @@ def generate_FV3LAM_wflow(ushdir, logfile: str = "log.generate_FV3LAM_wflow", de # Copy or symlink fix files # if SYMLINK_FIX_FILES: - log_info( f""" Symlinking fixed files from system directory (FIXgsm) to a subdirectory (FIXam): @@ -360,6 +359,8 @@ def generate_FV3LAM_wflow(ushdir, logfile: str = "log.generate_FV3LAM_wflow", de "target_lon": LON_CTR, "target_lat": LAT_CTR, "nrows_blend": HALO_BLEND, + "regional_bcs_from_gsi": False, + "write_restart_with_bcs": False, # # Question: # For a ESGgrid type grid, what should stretch_fac be set to? This depends @@ -412,15 +413,9 @@ def generate_FV3LAM_wflow(ushdir, logfile: str = "log.generate_FV3LAM_wflow", de gfs_physics_nml_dict.update({ "kice": kice or None, "lsoil": lsoil or None, - "do_shum": DO_SHUM, - "do_sppt": DO_SPPT, - "do_skeb": DO_SKEB, - "do_spp": DO_SPP, - "n_var_spp": N_VAR_SPP, - "n_var_lndp": N_VAR_LNDP, - "lndp_type": LNDP_TYPE, - "fhcyc": FHCYC_LSM_SPP_OR_NOT, + "print_diff_pgr": PRINT_DIFF_PGR, }) + if CPL_AQM: gfs_physics_nml_dict.update({ "cplaqm": True, @@ -494,12 +489,211 @@ def generate_FV3LAM_wflow(ushdir, logfile: str = "log.generate_FV3LAM_wflow", de # if PREDEF_GRID_NAME == "RRFS_NA_3km": settings["fms2_io_nml"] = {"netcdf_default_format": "netcdf4"} + + settings_str = cfg_to_yaml_str(settings) + + log_info( + f""" + The variable 'settings' specifying values of the weather model's + namelist variables has been set as follows:\n""", + verbose=verbose, + ) + log_info("\nsettings =\n\n" + settings_str, verbose=verbose) + # + # ----------------------------------------------------------------------- + # + # Call the set_namelist.py script to create a new FV3 namelist file (full + # path specified by FV3_NML_FP) using the file FV3_NML_BASE_SUITE_FP as + # the base (i.e. starting) namelist file, with physics-suite-dependent + # modifications to the base file specified in the yaml configuration file + # FV3_NML_YAML_CONFIG_FP (for the physics suite specified by CCPP_PHYS_SUITE), + # and with additional physics-suite-independent modifications specified + # in the variable "settings" set above. + # + # ----------------------------------------------------------------------- + # + try: + set_namelist( + [ + "-q", + "-n", + FV3_NML_BASE_SUITE_FP, + "-c", + FV3_NML_YAML_CONFIG_FP, + CCPP_PHYS_SUITE, + "-u", + settings_str, + "-o", + FV3_NML_FP, + ] + ) + except: + logging.exception( + dedent( + f""" + Call to python script set_namelist.py to generate an FV3 namelist file + failed. Parameters passed to this script are: + Full path to base namelist file: + FV3_NML_BASE_SUITE_FP = '{FV3_NML_BASE_SUITE_FP}' + Full path to yaml configuration file for various physics suites: + FV3_NML_YAML_CONFIG_FP = '{FV3_NML_YAML_CONFIG_FP}' + Physics suite to extract from yaml configuration file: + CCPP_PHYS_SUITE = '{CCPP_PHYS_SUITE}' + Full path to output namelist file: + FV3_NML_FP = '{FV3_NML_FP}' + Namelist settings specified on command line:\n + settings =\n\n""" + ) + + settings_str + ) + # + # If not running the TN_MAKE_GRID task (which implies the workflow will + # use pregenerated grid files), set the namelist variables specifying + # the paths to surface climatology files. These files are located in + # (or have symlinks that point to them) in the FIXlam directory. + # + # Note that if running the TN_MAKE_GRID task, this action usually cannot + # be performed here but must be performed in that task because the names + # of the surface climatology files depend on the CRES parameter (which is + # the C-resolution of the grid), and this parameter is in most workflow + # configurations is not known until the grid is created. + # + if not expt_config['rocoto']['tasks'].get('task_make_grid'): + + set_FV3nml_sfc_climo_filenames() + + # + # ----------------------------------------------------------------------- + # + # Generate namelist for surface cycle + # Deleted in newer RRFS_dev version so here for testing only + # + # ----------------------------------------------------------------------- + # + if DO_SURFACE_CYCLE: + if SDF_USES_RUC_LSM: + lsoil=9 + settings = {} + settings["gfs_physics_nml"] = { + "lsoil": lsoil or None + #"fh_dfi_radar": FH_DFI_RADAR # commented out untile develop gets radar tten code + } + + settings_str = cfg_to_yaml_str(settings) + # + # populate the namelist file + # + try: + set_namelist( + [ + "-q", + "-n", + FV3_NML_FP, + "-u", + settings_str, + "-o", + FV3_NML_CYCSFC_FP, + ] + ) + except: + logging.exception( + dedent( + f""" + Call to python script set_namelist.py to generate an FV3 namelist file + failed. Parameters passed to this script are: + Full path to output namelist file: + FV3_NML_FP = '{FV3_NML_FP}' + Full path to output namelist file for DA: + FV3_NML_RESTART_FP = '{FV3_NML_CYCSFC_FP}' + Namelist settings specified on command line:\n + settings =\n\n""" + ) + + settings_str + ) + + # + # ----------------------------------------------------------------------- + # + # Generate namelist for DA cycle + # + # ----------------------------------------------------------------------- + # + if DO_DACYCLE or DO_ENKFUPDATE: + + if SDF_USES_RUC_LSM: + lsoil = 9 + + lupdatebc = False + if DO_UPDATE_BC: + lupdatebc = False # not ready for setting this to true yet + + settings = {} + settings["fv_core_nml"] = { + "external_ic": False, + "make_nh": False, + "na_init": 0, + "nggps_ic": False, + "mountain": True, + "regional_bcs_from_gsi": lupdatebc, + "warm_start": True, + } + settings["gfs_physics_nml"] = { + "lsoil": lsoil or None + #"fh_dfi_radar": FH_DFI_RADAR # commented out untile develop gets radar tten code + } + + settings_str = cfg_to_yaml_str(settings) + # + # populate the namelist file + # + try: + set_namelist( + [ + "-q", + "-n", + FV3_NML_FP, + "-u", + settings_str, + "-o", + FV3_NML_RESTART_FP, + ] + ) + except: + logging.exception( + dedent( + f""" + Call to python script set_namelist.py to generate an FV3 namelist file + failed. Parameters passed to this script are: + Full path to output namelist file: + FV3_NML_FP = '{FV3_NML_FP}' + Full path to output namelist file for DA: + FV3_NML_RESTART_FP = '{FV3_NML_RESTART_FP}' + Namelist settings specified on command line:\n + settings =\n\n""" + ) + + settings_str + ) + # + # ----------------------------------------------------------------------- # # Add the relevant tendency-based stochastic physics namelist variables to # "settings" when running with SPPT, SHUM, or SKEB turned on. If running # with SPP or LSM SPP, set the "new_lscale" variable. Otherwise only # include an empty "nam_stochy" stanza. # + # ----------------------------------------------------------------------- + # + settings = {} + settings["gfs_physics_nml"] = { + "do_shum": DO_SHUM, + "do_sppt": DO_SPPT, + "do_skeb": DO_SKEB, + "do_spp": DO_SPP, + "n_var_spp": N_VAR_SPP, + "n_var_lndp": N_VAR_LNDP, + "lndp_type": LNDP_TYPE, + "fhcyc": FHCYC_LSM_SPP_OR_NOT, + } nam_stochy_dict = {} if DO_SPPT: nam_stochy_dict.update( @@ -583,76 +777,71 @@ def generate_FV3LAM_wflow(ushdir, logfile: str = "log.generate_FV3LAM_wflow", de settings["nam_sfcperts"] = nam_sfcperts_dict settings_str = cfg_to_yaml_str(settings) - - log_info( - f""" - The variable 'settings' specifying values of the weather model's - namelist variables has been set as follows:\n""", - verbose=verbose, - ) - log_info("\nsettings =\n\n" + settings_str, verbose=verbose) # - # ----------------------------------------------------------------------- + #----------------------------------------------------------------------- # - # Call the set_namelist.py script to create a new FV3 namelist file (full - # path specified by FV3_NML_FP) using the file FV3_NML_BASE_SUITE_FP as - # the base (i.e. starting) namelist file, with physics-suite-dependent - # modifications to the base file specified in the yaml configuration file - # FV3_NML_YAML_CONFIG_FP (for the physics suite specified by CCPP_PHYS_SUITE), - # and with additional physics-suite-independent modifications specified - # in the variable "settings" set above. + # Generate namelist files with stochastic physics if needed # - # ----------------------------------------------------------------------- + #----------------------------------------------------------------------- # - try: - set_namelist( - [ - "-q", - "-n", - FV3_NML_BASE_SUITE_FP, - "-c", - FV3_NML_YAML_CONFIG_FP, - CCPP_PHYS_SUITE, - "-u", - settings_str, - "-o", - FV3_NML_FP, - ] - ) - except: - logging.exception( - dedent( - f""" - Call to python script set_namelist.py to generate an FV3 namelist file - failed. Parameters passed to this script are: - Full path to base namelist file: - FV3_NML_BASE_SUITE_FP = '{FV3_NML_BASE_SUITE_FP}' - Full path to yaml configuration file for various physics suites: - FV3_NML_YAML_CONFIG_FP = '{FV3_NML_YAML_CONFIG_FP}' - Physics suite to extract from yaml configuration file: - CCPP_PHYS_SUITE = '{CCPP_PHYS_SUITE}' - Full path to output namelist file: - FV3_NML_FP = '{FV3_NML_FP}' - Namelist settings specified on command line:\n - settings =\n\n""" + if DO_ENSEMBLE and ( DO_SPP or DO_SPPT or DO_SHUM or DO_SKEB or DO_LSM_SPP): + + try: + set_namelist( + [ + "-q", + "-n", + FV3_NML_FP, + "-u", + settings_str, + "-o", + FV3_NML_STOCH_FP, + ] + ) + except: + logging.exception( + dedent( + f""" + Call to python script set_namelist.py to generate an FV3 namelist file + failed. Parameters passed to this script are: + Full path to output namelist file: + FV3_NML_FP = '{FV3_NML_FP}' + Full path to output namelist file for stochastics: + FV3_NML_STOCH_FP = '{FV3_NML_STOCH_FP}' + Namelist settings specified on command line:\n + settings =\n\n""" + ) + + settings_str ) - + settings_str - ) - # - # If not running the TN_MAKE_GRID task (which implies the workflow will - # use pregenerated grid files), set the namelist variables specifying - # the paths to surface climatology files. These files are located in - # (or have symlinks that point to them) in the FIXlam directory. - # - # Note that if running the TN_MAKE_GRID task, this action usually cannot - # be performed here but must be performed in that task because the names - # of the surface climatology files depend on the CRES parameter (which is - # the C-resolution of the grid), and this parameter is in most workflow - # configurations is not known until the grid is created. - # - if not expt_config['rocoto']['tasks'].get('task_make_grid'): - set_FV3nml_sfc_climo_filenames() + if DO_DACYCLE or DO_ENKFUPDATE: + try: + set_namelist( + [ + "-q", + "-n", + FV3_NML_RESTART_FP, + "-u", + settings_str, + "-o", + FV3_NML_RESTART_STOCH_FP, + ] + ) + except: + logging.exception( + dedent( + f""" + Call to python script set_namelist.py to generate an FV3 namelist file + failed. Parameters passed to this script are: + Full path to output namelist file: + FV3_NML_FP = '{FV3_NML_FP}' + Full path to output namelist file for stochastics: + FV3_NML_RESTART_STOCH_FP = '{FV3_NML_RESTART_STOCH_FP}' + Namelist settings specified on command line:\n + settings =\n\n""" + ) + + settings_str + ) # # ----------------------------------------------------------------------- diff --git a/ush/set_FV3nml_ens_stoch_seeds.py b/ush/set_FV3nml_ens_stoch_seeds.py index 08ed944f46..04aa628d43 100644 --- a/ush/set_FV3nml_ens_stoch_seeds.py +++ b/ush/set_FV3nml_ens_stoch_seeds.py @@ -58,7 +58,7 @@ def set_FV3nml_ens_stoch_seeds(cdate): # # ----------------------------------------------------------------------- # - fv3_nml_ensmem_fp = f"{os.getcwd()}{os.sep}{FV3_NML_FN}" + fv3_nml_ensmem_fp = f"{os.getcwd()}{os.sep}{FV3_NML_FN}_base" ensmem_num = ENSMEM_INDX @@ -174,7 +174,7 @@ def setUp(self): mkdir_vrfy("-p", EXPTDIR) cp_vrfy( os.path.join(PARMdir, "input.nml.FV3"), - os.path.join(EXPTDIR, "input.nml"), + os.path.join(EXPTDIR, "input.nml_base"), ) for i in range(2): mkdir_vrfy( @@ -192,7 +192,7 @@ def setUp(self): set_env_var("USHdir", USHdir) set_env_var("ENSMEM_INDX", 2) set_env_var("FV3_NML_FN", "input.nml") - set_env_var("FV3_NML_FP", os.path.join(EXPTDIR, "input.nml")) + set_env_var("FV3_NML_FP", os.path.join(EXPTDIR, "input.nml_base")) set_env_var("DO_SHUM", True) set_env_var("DO_SKEB", True) set_env_var("DO_SPPT", True) From 2565067c5689aca47596015c434955e255657e0b Mon Sep 17 00:00:00 2001 From: Daniel Abdi Date: Wed, 26 Apr 2023 12:44:12 +0000 Subject: [PATCH 2/4] Changes to run_fcst. --- scripts/exregional_run_fcst.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/exregional_run_fcst.sh b/scripts/exregional_run_fcst.sh index 7049b8588e..0728f3de5a 100755 --- a/scripts/exregional_run_fcst.sh +++ b/scripts/exregional_run_fcst.sh @@ -438,15 +438,34 @@ cat > itag < Date: Wed, 26 Apr 2023 12:50:45 +0000 Subject: [PATCH 3/4] Add necessary variables. --- ush/config_defaults.yaml | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/ush/config_defaults.yaml b/ush/config_defaults.yaml index fdc4ec3586..f87032acfb 100644 --- a/ush/config_defaults.yaml +++ b/ush/config_defaults.yaml @@ -648,7 +648,7 @@ workflow: FV3_NML_BASE_SUITE_FN: "input.nml.FV3" FV3_NML_YAML_CONFIG_FN: "FV3.input.yml" FV3_NML_BASE_ENS_FN: "input.nml.base_ens" - FV3_NML_FN: "input.nml" + FV3_NML_FN: '{{ FV3_NML_BASE_SUITE_FN[:-4] }}' FV3_EXEC_FN: "ufs_model" DATA_TABLE_FN: "data_table" @@ -676,6 +676,10 @@ workflow: FIELD_TABLE_FP: '{{ [EXPTDIR, FIELD_TABLE_FN]|path_join }}' NEMS_CONFIG_FP: '{{ [EXPTDIR, NEMS_CONFIG_FN]|path_join }}' FV3_NML_FP: '{{ [EXPTDIR, FV3_NML_FN]|path_join }}' + FV3_NML_CYCSFC_FP: '{{ [EXPTDIR, [FV3_NML_FN, "_cycsfc"]|join ]|path_join }}' + FV3_NML_RESTART_FP: '{{ [EXPTDIR, [FV3_NML_FN, "_restart"]|join ]|path_join }}' + FV3_NML_STOCH_FP: '{{ [EXPTDIR, [FV3_NML_FN, "_stoch"]|join ]|path_join }}' + FV3_NML_RESTART_STOCH_FP: '{{ [EXPTDIR, [FV3_NML_FN, "_restart_stoch"]|join ]|path_join }}' FCST_MODEL: "ufs-weather-model" WFLOW_XML_FN: "FV3LAM_wflow.xml" @@ -1072,6 +1076,32 @@ rrfs: #----------------------------------------------------------------------- # DO_NLDN_LGHT: false + # + #----------------------------------------------------------------------- + # + # Set switches associated with ensembles. Definitions: + # + # DO_ENKFUPDATE: + # Decide whether or not to run EnKF update for the ensemble members + # + #----------------------------------------------------------------------- + # + DO_ENKFUPDATE: false + # + #----------------------------------------------------------------------- + # + # Set switches associated with running data assimilation. Definitions: + # + # DO_DACYCLE: + # Flag that determines whether to run a data assimilation cycle. + # + # DO_SURFACE_CYCLE: + # Flag that determines whether to continue cycle surface fields. + # + #----------------------------------------------------------------------- + # + DO_DACYCLE: false + DO_SURFACE_CYCLE: false #---------------------------- # MAKE GRID config parameters @@ -2213,6 +2243,12 @@ global: # #----------------------------------------------------------------------- # + # PRINT_DIFF_PGR: + # Option to turn on/off pressure tendency diagnostic + # + #----------------------------------------------------------------------- + # + PRINT_DIFF_PGR: false #---------------------------- # verification (vx) parameters From d2c605ead173bc7c02e7fc131d1dab05fd2ae927 Mon Sep 17 00:00:00 2001 From: Daniel Abdi Date: Mon, 1 May 2023 15:16:19 +0000 Subject: [PATCH 4/4] Address reveiewer suggestions. --- ush/config_defaults.yaml | 6 +++--- ush/generate_FV3LAM_wflow.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ush/config_defaults.yaml b/ush/config_defaults.yaml index f87032acfb..92e00dbff3 100644 --- a/ush/config_defaults.yaml +++ b/ush/config_defaults.yaml @@ -645,10 +645,10 @@ workflow: RGNL_GRID_NML_FN: "regional_grid.nml" - FV3_NML_BASE_SUITE_FN: "input.nml.FV3" + FV3_NML_FN: "input.nml" + FV3_NML_BASE_SUITE_FN: "{{ FV3_NML_FN }}.FV3" FV3_NML_YAML_CONFIG_FN: "FV3.input.yml" - FV3_NML_BASE_ENS_FN: "input.nml.base_ens" - FV3_NML_FN: '{{ FV3_NML_BASE_SUITE_FN[:-4] }}' + FV3_NML_BASE_ENS_FN: "{{ FV3_NML_FN }}.base_ens" FV3_EXEC_FN: "ufs_model" DATA_TABLE_FN: "data_table" diff --git a/ush/generate_FV3LAM_wflow.py b/ush/generate_FV3LAM_wflow.py index 80a1069ff7..7f2e32b151 100755 --- a/ush/generate_FV3LAM_wflow.py +++ b/ush/generate_FV3LAM_wflow.py @@ -576,7 +576,6 @@ def generate_FV3LAM_wflow(ushdir, logfile: str = "log.generate_FV3LAM_wflow", de settings = {} settings["gfs_physics_nml"] = { "lsoil": lsoil or None - #"fh_dfi_radar": FH_DFI_RADAR # commented out untile develop gets radar tten code } settings_str = cfg_to_yaml_str(settings)