コード例 #1
0
ファイル: entropy_diff.py プロジェクト: f-koehler/mlxtk
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("path", nargs=2, help="path to the natpop file")
    parser.add_argument("-n", "--node", type=int, default=1, help="node")
    parser.add_argument("-d",
                        "--dof",
                        type=int,
                        default=1,
                        help="degree of freedom")
    add_argparse_2d_args(parser)
    args = parser.parse_args()

    figure, ax = plt.subplots(1, 1)

    time1, natpop1 = read_natpop(args.path[0], node=args.node, dof=args.dof)
    time2, natpop2 = read_natpop(args.path[1], node=args.node, dof=args.dof)

    if time1.shape != time2.shape:
        raise ValueError("number of time points differs")

    if not numpy.allclose(time1, time2):
        raise ValueError("time points differ")

    entropy1 = compute_entropy(natpop1)
    entropy2 = compute_entropy(natpop2)

    plot_entropy_diff(ax, time1, entropy1, entropy2)

    system = units.get_default_unit_system()
    ax.set_xlabel(system.get_time_unit().format_label("t"))

    apply_2d_args(ax, figure, args)

    plt.show()
コード例 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "path",
        nargs="+",
        default=["natpop"],
        help="path to the natpop file",
    )
    parser.add_argument("-n", "--node", type=int, default=1, help="node")
    parser.add_argument("-d",
                        "--dof",
                        type=int,
                        default=1,
                        help="degree of freedom")
    parser.add_argument(
        "--normalize",
        action="store_true",
        help="whether to normalize the entropy",
    )
    add_argparse_2d_args(parser)
    add_argparse_save_arg(parser)
    args = parser.parse_args()

    labels = labels_from_paths(args.path)
    figure, ax = plt.subplots(1, 1)

    for path, label in zip(args.path, labels):
        time, natpop = read_natpop(path, node=args.node, dof=args.dof)
        try:
            entropy = compute_entropy(natpop, args.normalize)
        except ZeroDivisionError:
            entropy = compute_entropy(natpop)
            args.normalize = False
        plot_entropy(ax, time, entropy, label=label, normalize=args.normalize)

    system = units.get_default_unit_system()
    ax.set_xlabel(system.get_time_unit().format_label("t"))

    apply_2d_args(ax, figure, args)
    if len(args.path) > 1:
        ax.legend()

    handle_saving(figure, args)
    if not args.output:
        plt.show()
コード例 #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "path_natpop",
        nargs="?",
        default="natpop",
        help="path to the natpop file",
    )
    parser.add_argument(
        "path_evals",
        nargs="?",
        default="eval_dmat_dof1",
        help="path to the file containing the dmat eigenvalues",
    )
    parser.add_argument("-n", "--node", type=int, default=1, help="node")
    parser.add_argument("-d",
                        "--dof",
                        type=int,
                        default=1,
                        help="degree of freedom")
    add_argparse_2d_args(parser)
    args = parser.parse_args()

    figure, ax = plt.subplots(1, 1)

    time, natpop = read_natpop(args.path_natpop, node=args.node, dof=args.dof)
    time2, evals = read_dmat_evals(args.path_evals)

    if not numpy.allclose(time, time2):
        raise RuntimeError("time points do not match")

    for natpop, value in zip(natpop.T, evals.T):
        plt.plot(time, natpop - value)

    system = units.get_default_unit_system()
    ax.set_xlabel(system.get_time_unit().format_label("t"))

    apply_2d_args(ax, figure, args)

    plt.show()
コード例 #4
0
def plot_natpop(
    index: int,
    path: Path,
    parameters: Parameters,
    file_path: Path,
    dof: int = 1,
    node: int = 1,
    extension: str = ".pdf",
):
    total_path = path / file_path
    try:
        fig, ax = plot.create_subplots(1, 1)
        plot.plot_natpop(ax, *inout.read_natpop(total_path, dof=dof, node=node))
        system = units.get_default_unit_system()
        ax.set_xlabel(system.get_time_unit().format_label("t"))
        ax.set_ylabel(r"$\lambda_i(t)$")
        for func in MODFUNCS:
            func(fig, ax, parameters)
        plot.save(fig, str(index) + extension)
        plot.close_figure(fig)
    except FileNotFoundError:
        LOGGER.warning("file does not exist: %s", total_path)
コード例 #5
0
def plot_natpop(
    index: int,
    path: Path,
    parameters: Parameters,
    file_path: Path,
    dof: int = 1,
    node: int = 1,
    extension: str = ".pdf",
    modfunc: Callable[[Figure, Axes, Parameters], None] = None,
):
    total_path = path / file_path
    try:
        fig, ax = plot.create_subplots(1, 1)
        plot.plot_depletion(ax, *inout.read_natpop(total_path, dof=dof, node=node))
        system = units.get_default_unit_system()
        ax.set_xlabel(system.get_time_unit().format_label("t"))
        if modfunc:
            modfunc(fig, ax, parameters)
        plot.save(fig, str(index) + extension)
        plot.close_figure(fig)
    except FileNotFoundError:
        LOGGER.warning("file does not exist: %s", total_path)