Example #1
0
    def _save_pole_data(self, n_list, poleData, asymcalc, p):
        if self.archive_root is not None:
            pole_dk_dir = self._get_pole_dks_dir(n_list)
            if not os.path.isdir(pole_dk_dir):
                os.makedirs(pole_dk_dir)

            for i, dk in enumerate(poleData[2]):
                header = ["Npts", "status"] + self._get_num_header(asymcalc)
                rows = []
                for pole in poleData[0][i]:
                    for j in sorted(pole.keys()):
                        m = self._get_pole_row(n_list[j], pole[j][0],
                                               pole[j][2], asymcalc)
                        rows.append(m)
                    rows.append(["", "", "", ""])

                pole_path = self._get_pole_dks_path(pole_dk_dir, dk)
                with th.fwopen(pole_path) as f:
                    th.fw(
                        f,
                        self._get_pole_file_header_str(len(poleData[0][i]),
                                                       asymcalc))
                    th.fw(f, t.tabulate(rows, header))
                    self.log.write_msg("Poles saved to: " + pole_path)
            self._save_pole_config(p)
Example #2
0
def get_tool(toolid,
             data,
             archive_root=None,
             param_file_path=None,
             silent=False):
    """
    Initialises and returns a Tool.

    Parameters
    ----------
    toolid : int 
        Specification of the Tool. Available options are reskit.chart and
        reskit.mcsmatfit.
    data
        Tool data. This is the data container to be used by the Tool.
    archive_root : str, optional
        Specification of the location into which reskit will write its results.
    param_file_path : str, optional
        Location of an existing yaml file containing overrides for the more
        advanced routine parameters.
    silent : bool, optional
        Switch determining whether to suppress output to console.

    Returns
    -------
    tool : Tool
    """
    if safe_mode:
        nw.lockType()
    if toolid == chart:
        import chart as mod
        tool = mod.Chart
    elif toolid == mcsmatfit:
        import mcsmatfit as mod
        tool = mod.MCSMatFit
    else:
        raise Exception(reskit_err_str_unrecog_module)
    if archive_root is not None:
        data_root = archive_root + os.sep + data.get_source_str() + os.sep
        data_root += nw.getConfigString() + os.sep + data.get_hist_str(
        ) + os.sep
        archive_root = data_root + mod.toolName + os.sep
        if not os.path.isdir(data_root):
            os.makedirs(data_root)
            with th.fwopen(data_root + filename_checkdata) as f:
                th.fw(f, data.get_check_str())
        else:
            if os.path.isfile(data_root + filename_checkdata):
                with th.fropen(data_root + filename_checkdata) as f:
                    if str(f.read()) != str(data.get_check_str()):
                        raise Exception(reskit_err_str_bad_data_root)
            else:
                s = reskit_err_str_missing_check_data_1 + data_root
                s += reskit_err_str_missing_check_data_2
                raise Exception(s)
        if not os.path.isdir(archive_root):
            os.makedirs(archive_root)

    return tool(data, archive_root, param_file_path, silent)
Example #3
0
 def _save_coeff(self, coeff, path, type_str):
     for i, cmat in enumerate(coeff):
         coeff_path = self._get_coeff_path(path, type_str, i)
         if nw.mode == nw.mode_python:
             np.savetxt(coeff_path, cmat, delimiter=",", newline='\n')
             self._fix_numpy_file(coeff_path)
         else:
             with th.fwopen(coeff_path) as f:
                 th.fw(f, cmat)
Example #4
0
 def _fix_numpy_file(self, file_name):
     f1 = th.fropen(file_name)
     f2 = th.fwopen(file_name + "_temp")
     for line in f1:
         th.fw(f2, line.replace("+-", '-').replace("\r\n", '\n'))
     f1.close()
     f2.close()
     os.remove(file_name)
     os.rename(file_name + "_temp", file_name)
Example #5
0
 def _write_formatted_QI_table(self, start, new_lines, end, subdir,
                               trunc_Vdk, sig_digits, use_energies,
                               tab_type):
     name = self._formatted_QI_table_name(trunc_Vdk, sig_digits,
                                          use_energies, tab_type)
     save_path = subdir + os.sep + "QIs" + name + ".txt"
     with th.fwopen(save_path) as f:
         th.fw(f, start)
         for l in new_lines:
             th.fw(f, l)
         th.fw(f, end)
         self.log.write_msg("Formatted QI table saved to: " + save_path)
Example #6
0
 def _save_QI_data_file(self, QI_path, pole_dat, asymcalc, type_str, index):
     path = QI_path + "_" + type_str + QI_file_ext
     with th.fwopen(path) as f:
         th.fw(f, self._get_QI_file_header_str(len(pole_dat[0]), asymcalc))
         for i, poleQI in enumerate(pole_dat[0]):
             row = self._get_QI_row(poleQI, asymcalc)
             pid = type_str + "[" + str(i) + "]."
             th.fw(f, pid + QI_file_real + "=" + row[index][0] + "\n")
             th.fw(f, pid + QI_file_imag + "=" + row[index][1] + "\n")
             th.fw(f, QI_file_Vdk + "=" + row[2] + "\n")
             th.fw(f, QI_file_SM + "=" + row[3] + "\n\n")
     return path
Example #7
0
 def _create_raw_QI_table(self, use_energies, subdir, orig_file_name,
                          trunc_Vdk, sig_digits):
     header = ["real", "imag", QI_file_Vdk, QI_file_SM]
     desc, new_lines = self._get_formatted_lines(subdir,
                                                 orig_file_name,
                                                 use_energies,
                                                 trunc_Vdk,
                                                 sig_digits,
                                                 has_final_col_delim=False)
     name = self._formatted_QI_table_name(trunc_Vdk, sig_digits,
                                          use_energies, "raw")
     save_path = subdir + os.sep + "QIs" + name + ".txt"
     with th.fwopen(save_path) as f:
         # Add blank line to prevent tabulate performing it's own formatting.
         new_lines.append([" ", " ", " ", " "])
         th.fw(f, t.tabulate(new_lines, header))
         th.fw(f, "\n" + desc)
         self.log.write_msg("Formatted QI table saved to: " + save_path)
Example #8
0
    def _save_roots(self, Npts, ris, roots, asymcalc, p):
        if self.archive_root is not None:
            root_dir = self._get_root_config_dir()
            if not os.path.isdir(root_dir):
                os.makedirs(root_dir)

            header = self._get_num_header(asymcalc)
            rows = []
            for root in roots:
                rows.append(self._get_kE_row(root, asymcalc))

            root_path = self._get_root_path(root_dir, Npts, ris[0])
            with th.fwopen(root_path) as f:
                th.fw(f, self._get_root_file_header_str(Npts, ris))
                th.fw(f, t.tabulate(rows, header))
                th.fw(f, "\ncomplete")
                self.log.write_msg("Roots saved to: " + root_path)

            self._save_root_config(p)
Example #9
0
 def _save_pole_config(self, p):
     with th.fwopen(self._get_pole_config_path()) as f:
         th.fw(f, str(p))