Exemplo n.º 1
0
def write_results(bins, bins_data, src_file):
    base_fname = os.path.splitext(src_file)[0]
    xyz_file = base_fname + '.xyz'
    move_existing_file(xyz_file)
    log_file = base_fname + '.log'
    move_existing_file(log_file)
    with open(xyz_file, 'w') as xyz:
        xyz.write(str(len(bins_data)) + '\n')
        xyz.write("{} {}\n".format(src_file, datetime.datetime.today()))
        with open(log_file, 'w') as bin_log:
            csv_log = csv.writer(bin_log)
            csv_log.writerow(
                ("bin", "count", "ax", "dx", "ay", "dy", "az", "dz"))
            for cur_bin in bins:
                if cur_bin in bins_data:
                    bin_coords = bins_data[cur_bin]
                    bin_mean = list(map(np.mean, zip(*bin_coords)))
                    bin_stdev = list(map(np.std, zip(*bin_coords)))
                    xyz.write(
                        "B   {: .4f}   {: .4f}   {: .4f}\n".format(*bin_mean))
                    merged_xyz = [
                        item for sublist in zip(bin_mean, bin_stdev)
                        for item in sublist
                    ]
                    csv_log.writerow(
                        [FLOAT_FMT.format(cur_bin),
                         len(bin_coords)] +
                        [FLOAT_FMT.format(coord) for coord in merged_xyz])
Exemplo n.º 2
0
def main(argv=None):
    """
    Runs the main program.

    :param argv: The command line arguments.
    :return: The return code for the program's termination.
    """
    args, ret = parse_cmdline(argv)
    if ret != GOOD_RET or args is None:
        return ret

    cfg = args.config

    try:
        tpl_str = read_tpl(cfg[PAR_TPL])
        tpl_dict = dict(cfg[TPL_VALS])
        for f_name_key in [BEST_PARAMS_FNAME, FITTING_SUM_FNAME]:
            if cfg[f_name_key] is not None:
                move_existing_file(cfg[f_name_key])
        if len(cfg[OPT_PARAMS]) == 0:
            warning(
                "No parameters will be optimized, as no parameters were listed for the keyword '{}' "
                "in the '{}' section of the configuration file.".format(
                    OPT_PARAMS, MAIN_SEC))
            eval_eqs(cfg, tpl_dict)
            fill_save_tpl(cfg,
                          tpl_str,
                          tpl_dict,
                          cfg[PAR_TPL],
                          cfg[PAR_FILE_NAME],
                          print_info=cfg[PRINT_INFO])
            trial_result = float(
                check_output([cfg[BASH_DRIVER], tpl_dict[NEW_FNAME]]).strip())
            tpl_dict[RESID] = round(trial_result, cfg[NUM_PARAM_DECIMALS])
            if cfg[PAR_COPY_NAME] is not None or cfg[RESULT_COPY] is not None:
                copy_par_result_file(cfg, tpl_dict)
            print("Result without optimizing parameters: {}".format(
                trial_result))
        else:
            min_params(cfg, tpl_dict, tpl_str)

    except (TemplateNotReadableError, IOError) as e:
        warning("Problems reading file: {}".format(e))
        return IO_ERROR
    except (KeyError, InvalidDataError, ValueError) as e:
        warning(e)
        return IO_ERROR

    return GOOD_RET
Exemplo n.º 3
0
def write_results(bins, bins_data, src_file):
    base_fname = os.path.splitext(src_file)[0]
    xyz_file = base_fname + '.xyz'
    move_existing_file(xyz_file)
    log_file = base_fname + '.log'
    move_existing_file(log_file)
    with open(xyz_file, 'w') as xyz:
        xyz.write(str(len(bins_data)) + '\n')
        xyz.write("{} {}\n".format(src_file, datetime.datetime.today()))
        with open(log_file, 'w') as bin_log:
            csv_log = csv.writer(bin_log)
            csv_log.writerow(("bin", "count", "ax", "dx", "ay", "dy", "az", "dz"))
            for cur_bin in bins:
                if cur_bin in bins_data:
                    bin_coords = bins_data[cur_bin]
                    bin_mean = list(map(np.mean, zip(*bin_coords)))
                    bin_stdev = list(map(np.std, zip(*bin_coords)))
                    xyz.write("B   {: .4f}   {: .4f}   {: .4f}\n".format(
                        *bin_mean))
                    merged_xyz = [item for sublist in zip(bin_mean, bin_stdev) for item in sublist]
                    csv_log.writerow([FLOAT_FMT.format(cur_bin), len(bin_coords)] +
                                     [FLOAT_FMT.format(coord) for coord in merged_xyz])