コード例 #1
0
def set_extrn_mdl_params():
    """ Sets parameters associated with the external model used for initial 
    conditions (ICs) and lateral boundary conditions (LBCs).
    Args:
        None
    Returns:
        None
    """

    #import all env variables
    import_vars()

    global EXTRN_MDL_LBCS_OFFSET_HRS

    #
    #-----------------------------------------------------------------------
    #
    # Set EXTRN_MDL_LBCS_OFFSET_HRS, which is the number of hours to shift
    # the starting time of the external model that provides lateral boundary
    # conditions.
    #
    #-----------------------------------------------------------------------
    #
    if EXTRN_MDL_NAME_LBCS == "RAP":
        EXTRN_MDL_LBCS_OFFSET_HRS = EXTRN_MDL_LBCS_OFFSET_HRS or "3"
    else:
        EXTRN_MDL_LBCS_OFFSET_HRS = EXTRN_MDL_LBCS_OFFSET_HRS or "0"

    # export values we set above
    env_vars = ["EXTRN_MDL_LBCS_OFFSET_HRS"]
    export_vars(env_vars=env_vars)
コード例 #2
0
def set_predef_grid_params():
    """ Sets grid parameters for the specified predfined grid 

    Args:
        None
    Returns:
        None
    """
    # import all environement variables
    import_vars()

    params_dict = load_config_file("predef_grid_params.yaml")
    params_dict = params_dict[PREDEF_GRID_NAME]

    # if QUILTING = False, skip variables that start with "WRTCMP_"
    if not QUILTING:
        params_dict = {k: v for k,v in params_dict.items() \
                            if not k.startswith("WRTCMP_") }

    # take care of special vars
    special_vars = ['DT_ATMOS', 'LAYOUT_X', 'LAYOUT_Y', 'BLOCKSIZE']
    for var in special_vars:
        if globals()[var] is not None:
            params_dict[var] = globals()[var]

    #export variables to environment
    export_vars(source_dict=params_dict)
コード例 #3
0
def set_ozone_param(ccpp_phys_suite_fp):
    """ Function that does the following:
    (1) Determines the ozone parameterization being used by checking in the
        CCPP physics suite XML.
   
    (2) Sets the name of the global ozone production/loss file in the FIXgsm
        FIXgsm system directory to copy to the experiment's FIXam directory.
   
    (3) Resets the last element of the workflow array variable
        FIXgsm_FILES_TO_COPY_TO_FIXam that contains the files to copy from
        FIXgsm to FIXam (this last element is initially set to a dummy 
        value) to the name of the ozone production/loss file set in the
        previous step.
   
    (4) Resets the element of the workflow array variable 
        CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING (this array contains the 
        mapping between the symlinks to create in any cycle directory and
        the files in the FIXam directory that are their targets) that 
        specifies the mapping for the ozone symlink/file such that the 
        target FIXam file name is set to the name of the ozone production/
        loss file set above.

    Args:
        ccpp_phys_suite_fp: full path to CCPP physics suite
    Returns:
        ozone_param: a string
    """

    print_input_args(locals())

    # import all environment variables
    import_vars()

    #
    #-----------------------------------------------------------------------
    #
    # Get the name of the ozone parameterization being used.  There are two
    # possible ozone parameterizations:
    #
    # (1) A parameterization developed/published in 2015.  Here, we refer to
    #     this as the 2015 parameterization.  If this is being used, then we
    #     set the variable ozone_param to the string "ozphys_2015".
    #
    # (2) A parameterization developed/published sometime after 2015.  Here,
    #     we refer to this as the after-2015 parameterization.  If this is
    #     being used, then we set the variable ozone_param to the string
    #     "ozphys".
    #
    # We check the CCPP physics suite definition file (SDF) to determine the
    # parameterization being used.  If this file contains the line
    #
    #   <scheme>ozphys_2015</scheme>
    #
    # then the 2015 parameterization is being used.  If it instead contains
    # the line
    #
    #   <scheme>ozphys</scheme>
    #
    # then the after-2015 parameterization is being used.  (The SDF should
    # contain exactly one of these lines; not both nor neither; we check for
    # this.)
    #
    #-----------------------------------------------------------------------
    #
    tree = load_xml_file(ccpp_phys_suite_fp)
    ozone_param = ""
    if has_tag_with_value(tree, "scheme", "ozphys_2015"):
        fixgsm_ozone_fn = "ozprdlos_2015_new_sbuvO3_tclm15_nuchem.f77"
        ozone_param = "ozphys_2015"
    elif has_tag_with_value(tree, "scheme", "ozphys"):
        fixgsm_ozone_fn = "global_o3prdlos.f77"
        ozone_param = "ozphys"
    else:
        print_err_msg_exit(f'''
        Unknown or no ozone parameterization
        specified in the CCPP physics suite file (ccpp_phys_suite_fp):
          ccpp_phys_suite_fp = \"{ccpp_phys_suite_fp}\"
          ozone_param = \"{ozone_param}\"''')
    #
    #-----------------------------------------------------------------------
    #
    # Set the last element of the array FIXgsm_FILES_TO_COPY_TO_FIXam to the
    # name of the ozone production/loss file to copy from the FIXgsm to the
    # FIXam directory.
    #
    #-----------------------------------------------------------------------
    #
    i = len(FIXgsm_FILES_TO_COPY_TO_FIXam) - 1
    FIXgsm_FILES_TO_COPY_TO_FIXam[i] = f"{fixgsm_ozone_fn}"
    #
    #-----------------------------------------------------------------------
    #
    # Set the element in the array CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING that
    # specifies the mapping between the symlink for the ozone production/loss
    # file that must be created in each cycle directory and its target in the
    # FIXam directory.  The name of the symlink is alrady in the array, but
    # the target is not because it depends on the ozone parameterization that
    # the physics suite uses.  Since we determined the ozone parameterization
    # above, we now set the target of the symlink accordingly.
    #
    #-----------------------------------------------------------------------
    #
    ozone_symlink = "global_o3prdlos.f77"
    fixgsm_ozone_fn_is_set = False
    regex_search = "^[ ]*([^| ]*)[ ]*[|][ ]*([^| ]*)[ ]*$"
    num_symlinks = len(CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING)

    for i in range(num_symlinks):
        mapping = CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING[i]
        symlink = find_pattern_in_str(regex_search, mapping)
        if symlink is not None:
            symlink = symlink[0]
        if symlink == ozone_symlink:
            regex_search = "^[ ]*([^| ]+[ ]*)[|][ ]*([^| ]*)[ ]*$"
            mapping_ozone = find_pattern_in_str(regex_search, mapping)[0]
            mapping_ozone = f"{mapping_ozone}| {fixgsm_ozone_fn}"
            CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING[i] = f"{mapping_ozone}"
            fixgsm_ozone_fn_is_set = True
            break
    #
    #-----------------------------------------------------------------------
    #
    # If fixgsm_ozone_fn_is_set is set to True, then the appropriate element
    # of the array CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING was set successfully.
    # In this case, print out the new version of this array.  Otherwise, print
    # out an error message and exit.
    #
    #-----------------------------------------------------------------------
    #
    if fixgsm_ozone_fn_is_set:

        msg = dedent(f'''
        After setting the file name of the ozone production/loss file in the
        FIXgsm directory (based on the ozone parameterization specified in the
        CCPP suite definition file), the array specifying the mapping between
        the symlinks that need to be created in the cycle directories and the
        files in the FIXam directory is:
        
        ''')
        msg += dedent(f'''
          CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING = {list_to_str(CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING)}
        ''')
        print_info_msg(msg, verbose=VERBOSE)

    else:

        print_err_msg_exit(f'''
        Unable to set name of the ozone production/loss file in the FIXgsm directory
        in the array that specifies the mapping between the symlinks that need to
        be created in the cycle directories and the files in the FIXgsm directory:
          fixgsm_ozone_fn_is_set = \"{fixgsm_ozone_fn_is_set}\"''')

    EXPORTS = [
        "CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING",
        "FIXgsm_FILES_TO_COPY_TO_FIXam"
    ]
    export_vars(env_vars=EXPORTS)

    return ozone_param
コード例 #4
0
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)
        cfg_u = flatten_dict(cfg_u)
        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_NUM_CELLS, \
          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
コード例 #5
0
def set_thompson_mp_fix_files(ccpp_phys_suite_fp, thompson_mp_climo_fn):
    """ Function that first checks whether the Thompson
    microphysics parameterization is being called by the selected physics
    suite.  If not, it sets the output variable whose name is specified by
    output_varname_sdf_uses_thompson_mp to "FALSE" and exits.  If so, it 
    sets this variable to "TRUE" and modifies the workflow arrays
    FIXgsm_FILES_TO_COPY_TO_FIXam and CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING
    to ensure that fixed files needed by the Thompson microphysics
    parameterization are copied to the FIXam directory and that appropriate
    symlinks to these files are created in the run directories.

    Args:
        ccpp_phys_suite_fp: full path to CCPP physics suite
        thompson_mp_climo_fn: netcdf file for thompson microphysics
    Returns:
        boolean: sdf_uses_thompson_mp
    """

    print_input_args(locals())

    # import all environment variables
    import_vars()

    #
    #-----------------------------------------------------------------------
    #
    # Check the suite definition file to see whether the Thompson microphysics
    # parameterization is being used.
    #
    #-----------------------------------------------------------------------
    #
    tree = load_xml_file(ccpp_phys_suite_fp)
    sdf_uses_thompson_mp = has_tag_with_value(tree, "scheme", "mp_thompson")
    #
    #-----------------------------------------------------------------------
    #
    # If the Thompson microphysics parameterization is being used, then...
    #
    #-----------------------------------------------------------------------
    #
    if sdf_uses_thompson_mp:
    #
    #-----------------------------------------------------------------------
    #
    # Append the names of the fixed files needed by the Thompson microphysics
    # parameterization to the workflow array FIXgsm_FILES_TO_COPY_TO_FIXam, 
    # and append to the workflow array CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING 
    # the mappings between these files and the names of the corresponding 
    # symlinks that need to be created in the run directories.
    #
    #-----------------------------------------------------------------------
    #
        thompson_mp_fix_files=[
          "CCN_ACTIVATE.BIN",
          "freezeH2O.dat",
          "qr_acr_qg.dat",
          "qr_acr_qs.dat",
          "qr_acr_qgV2.dat",
          "qr_acr_qsV2.dat"
        ]
    
        if (EXTRN_MDL_NAME_ICS  != "HRRR" and EXTRN_MDL_NAME_ICS  != "RAP") or \
           (EXTRN_MDL_NAME_LBCS != "HRRR" and EXTRN_MDL_NAME_LBCS != "RAP"):
          thompson_mp_fix_files.append(thompson_mp_climo_fn)
    
        FIXgsm_FILES_TO_COPY_TO_FIXam.extend(thompson_mp_fix_files)
    
        for fix_file in thompson_mp_fix_files:
          mapping=f"{fix_file} | {fix_file}"
          CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING.append(mapping)
    
        msg=dedent(f'''
            Since the Thompson microphysics parameterization is being used by this 
            physics suite (CCPP_PHYS_SUITE), the names of the fixed files needed by
            this scheme have been appended to the array FIXgsm_FILES_TO_COPY_TO_FIXam, 
            and the mappings between these files and the symlinks that need to be 
            created in the cycle directories have been appended to the array
            CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING.  After these modifications, the 
            values of these parameters are as follows:
            
            ''')
        msg+=dedent(f'''
                CCPP_PHYS_SUITE = \"{CCPP_PHYS_SUITE}\"
            
                FIXgsm_FILES_TO_COPY_TO_FIXam = {list_to_str(FIXgsm_FILES_TO_COPY_TO_FIXam)}
            ''')
        msg+=dedent(f'''
                CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING = {list_to_str(CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING)}
            ''')
        print_info_msg(msg)

        EXPORTS = [ "CYCLEDIR_LINKS_TO_FIXam_FILES_MAPPING", "FIXgsm_FILES_TO_COPY_TO_FIXam" ]
        export_vars(env_vars=EXPORTS)

    return sdf_uses_thompson_mp