def read_database(path, overwrite_path=None):
    data_param = None
    with open(path, 'r') as param_config:
        data_param = yaml.load(param_config, Loader=yaml.FullLoader)
    case = list(data_param.keys())[0]
    data_param = data_param[case]
    if overwrite_path:
        overwrite_db = None
        with open(overwrite_path, 'r') as param_config:
            overwrite_db = yaml.load(param_config, Loader=yaml.FullLoader)
        modify_dictionary(data_param, overwrite_db)
    return case, data_param
示例#2
0
def update_config(database: dict, run_config: dict, database_overwrite=None):  # pylint: disable=unused-argument
    """Update database before usage

    1. overwrite with potential additional user configuration
    2. adjust paths
    This adjusts database inline ==> no return value

    Args:
        database: dict
            input database as read from YAML
        run_config: dict
            input run configuration as read from default_<stage>.yaml
        database_overwrite: dict (optional)
            substructured corresponding to database used to overwrite
            corresponding fields in database
    """

    logger = get_logger()

    # Extract the case
    case = list(database.keys())[0]
    database = database[case]

    # First overwrite as required by the user
    # To be implemented
    if database_overwrite:
        logger.info("Updating database fields with custom user input")
        modify_dictionary(database, database_overwrite, True)

    # If not an ML analysis...
    if not database["doml"]:
        logger.info(
            "Not an ML analysis, adjust paths and settings accordingly")
        # ...append "_std" to paths where necessary
        data_mc = ("data", "mc")
        pkl_keys = ("pkl_skimmed_dec", "pkl_skimmed_decmerged")
        for keys in product(data_mc, pkl_keys):
            database["mlapplication"][keys[0]][keys[1]][:] = \
                    [f"{path}_std" for path in database["mlapplication"][keys[0]][keys[1]]]
        # ...set the ML working point all to 0
        for k in data_mc:
            database["mlapplication"]["probcutpresel"][k][:] = \
                    [0] * len(database["mlapplication"]["probcutpresel"][k])
        database["mlapplication"]["probcutoptimal"][:] \
                = [0] * len(database["mlapplication"]["probcutoptimal"])