Ejemplo n.º 1
0
    def read_isdata(self, inpdir):

        yaml_file = f"{inpdir}/{COV_INFO_FILENAME}"
        yaml_info = util.extract_yaml(yaml_file, None, None)
        isdata = False  # arbitrary default in dase key is missing

        key = KEYNAME_ISDATA
        if key in yaml_info:
            isdata = (yaml_info[KEYNAME_ISDATA] > 0)

        return isdata, yaml_info
Ejemplo n.º 2
0
    def train_prep_survey_map(self):

        # read survey.yaml map so that user-input calibration shifts
        # can be converted into a specific file & key-value to modify.
        # This map is NOT used for nominal training; it is used only
        # for systematic variations in the calibration.

        CONFIG = self.config_yaml['CONFIG']
        PATH_INPUT_CALIB = CONFIG[KEY_PATH_INPUT_CALIB]  # aka SALTPATH
        PATH_EXPAND = os.path.expandvars(PATH_INPUT_CALIB)
        msgerr = []

        if not os.path.exists(PATH_EXPAND):
            msgerr.append(f"Cannot find path for")
            msgerr.append(f"  {PATH_INPUT_CALIB}")
            msgerr.append(f"Check arg of {KEY_PATH_INPUT_CALIB}.")
            self.log_assert(False, msgerr)

        survey_map_file = (f"{PATH_EXPAND}/survey.yaml")
        survey_yaml = util.extract_yaml(survey_map_file, None, None)

        self.config_prep['survey_yaml'] = survey_yaml
        self.config_prep['survey_map_file'] = survey_map_file
Ejemplo n.º 3
0
    # check option for long HELP menus
    if args.HELP : 
        print_HELP()

    # check option to "purge" un-needed files with linux find and rm;
    # removes tarred script-dirs, root & hbook files, etc ...
    if args.purge :
        purge_old_submit_output()
        sys.exit(' Done with purge: exiting Main.')

    # check input file: does it have a path? Does it need to be translated?
    check_input_file_name(args)

    # Here we know there's a CONFIG block, so read the YAML input
    config_yaml = util.extract_yaml(args.input_file, "CONFIG:", KEY_END_YAML)
    config_yaml['args'] = args  # store args here for convenience

    # set logical merge flag before running program_class
    config_yaml['args'].merge_flag   = set_merge_flag(config_yaml)

    logging.debug(config_yaml)  # ???

    # - - - - - -
    # determine which program class (sim, fit, bbc, train ...)
    program_class = which_program_class(config_yaml)

    # run the class
    program = program_class(config_yaml)  # calls __init only

    # - - - - - - - -
Ejemplo n.º 4
0
    def make_wfit_summary(self):

        CONFIG = self.config_yaml['CONFIG']
        output_dir = self.config_prep['output_dir']
        submit_info_yaml = self.config_prep['submit_info_yaml']
        script_dir = submit_info_yaml['SCRIPT_DIR']
        use_wa = submit_info_yaml['USE_wa']
        INPDIR_LIST = submit_info_yaml['INPDIR_LIST']
        WFITOPT_LIST = submit_info_yaml['WFITOPT_LIST']

        SUMMARYF_FILE = f"{output_dir}/{WFIT_SUMMARY_FILE}"
        logging.info(f"\t Writing wfit summary to {WFIT_SUMMARY_FILE}")
        f = open(SUMMARYF_FILE, "w")

        MERGE_LOG_PATHFILE = (f"{output_dir}/{MERGE_LOG_FILE}")
        MERGE_INFO_CONTENTS,comment_lines = \
                util.read_merge_file(MERGE_LOG_PATHFILE)

        dirnum_last = "xyz"
        wfit_summary_table = {}
        nrow = 0
        for row in MERGE_INFO_CONTENTS[TABLE_MERGE]:
            nrow += 1
            dirnum = row[COLNUM_WFIT_MERGE_DIROPT][-3:]  # e.g., 000
            covnum = row[COLNUM_WFIT_MERGE_COVOPT][-3:]  # e.g., 001
            wfitnum = row[COLNUM_WFIT_MERGE_WFITOPT][-3:]  # idem
            prefix = self.wfit_prefix(row)
            YAML_FILE = f"{script_dir}/{prefix}.YAML"

            wfit_yaml = util.extract_yaml(YAML_FILE, None, None)
            wfit_values_dict = util.get_wfit_values(wfit_yaml)

            w = wfit_values_dict['w']
            w_sig = wfit_values_dict['w_sig']
            omm = wfit_values_dict['omm']
            omm_sig = wfit_values_dict['omm_sig']
            chi2 = wfit_values_dict['chi2']
            sigint = wfit_values_dict['sigint']
            blind = wfit_values_dict['blind']

            # extract user labels for cov and wfit
            str_diropt = 'DIROPT' + dirnum
            str_covopt = 'COVOPT' + covnum
            dir_name = INPDIR_LIST[str_diropt]  # create_cov dir
            covopt_dict = INPDIR_LIST[f'COVOPTS({str_diropt})']
            covopt_label = covopt_dict[str_covopt]
            wfitopt_label = WFITOPT_LIST[int(wfitnum)][1]

            if wfitopt_label == "None": wfitopt_label = "NoLabel"

            if use_wa:
                wa = wfit_values_dict['wa']
                wa_sig = wfit_values_dict['wa_sig']
                FoM = wfit_values_dict['FoM']
                Rho = wfit_values_dict['Rho']
            else:
                wa = 0
                wa_sig = 0

            # load table for weighted avg (the table is not used here)
            local_dict = {
                'dirnum': dirnum,
                'covnum': covnum,
                'wfitnum': wfitnum,
                'w': w,
                'w_sig': w_sig,
                'omm': omm,
                'omm_sig': omm_sig,
                'wa': wa,
                'wa_sig': wa_sig,
                'covopt_label': covopt_label,
                'wfitopt_label': wfitopt_label
            }

            unique_key = dir_name + '_' + covnum + '_' + wfitnum
            wfit_summary_table[unique_key] = local_dict

            if nrow == 1:
                self.write_wfit_summary_header(f, wfit_values_dict)

            if dirnum != dirnum_last:
                f.write(f"#\n# {str_diropt}={dir_name}\n")
            str_nums = f"{dirnum} {covnum} {wfitnum}"
            if use_wa:
                str_results = f"{w:.4f} {w_sig:.4f} "
                str_results += f"{wa:7.4f} {wa_sig:7.4f} "
                str_results += f"{FoM:5.1f} {Rho:6.3f} "
                str_results += f"{omm:.3f} {omm_sig:.3f}  "
            else:
                str_results = f"{w:.5f} {w_sig:.5f}  "
                str_results += f"{omm:.5f} {omm_sig:.5f}  "

            str_misc = f"{chi2:4.1f} {blind} "
            str_labels = f"{covopt_label:<10} {wfitopt_label}"
            f.write(f"ROW: {nrow:3d} {str_nums} {str_results}  " \
                    f"{str_misc} {str_labels}\n")

            dirnum_last = dirnum

        f.close()

        self.config_prep['wfit_summary_table'] = wfit_summary_table
Ejemplo n.º 5
0
        see_me = (f" !!! ************************************************ !!!")
        print(f"\n{see_me}\n{see_me}\n{see_me}")
        print(f"{HELP_MENU[args.HELP]}")
        sys.exit(' Scroll up to see full HELP menu.\n Done: exiting Main.')

    # check option to "purge" un-needed files with linux find and rm;
    # removes tarred script-dirs, root & hbook files, etc ...
    if args.purge:
        purge_old_submit_output()
        sys.exit(' Done with purge: exiting Main.')

    # check input file: does it have a path? Does it need to be translated?
    check_input_file_name(args)

    # Here we know there's a CONFIG block, so read the YAML input
    config_yaml = util.extract_yaml(args.input_file)
    config_yaml['args'] = args  # store args here for convenience

    # set logical merge flag before running program_class
    config_yaml['args'].merge_flag = set_merge_flag(config_yaml)
    # xxx mark delete config_yaml['args'].legacy_input = False

    logging.debug(config_yaml)  # ???

    # - - - - - -
    # determine which program class (sim, fit, bbc)
    program_class = which_program_class(config_yaml)

    # run the class
    program = program_class(config_yaml)  # calls __init only