Example #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "path",
        nargs="?",
        type=Path,
        default=Path("momentum_distribution.h5"),
        help="path to the momentum_distribution file",
    )
    parser.add_argument("--colorbar", type=bool)
    add_argparse_2d_args(parser)
    add_argparse_save_arg(parser)
    args = parser.parse_args()

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

    times, momenta, density = read_momentum_distribution_hdf5(
        args.path,
        "momentum_distribution",
    )

    average_momentum = numpy.zeros_like(times)
    for i, _ in enumerate(average_momentum):
        average_momentum[i] = numpy.sum(momenta * density[i])

    Y, X = numpy.meshgrid(momenta, times)
    mesh = ax.pcolormesh(X, Y, density)
    plt.plot(times, average_momentum)

    apply_2d_args(ax, figure, args)

    handle_saving(figure, args)

    plt.show()
Example #2
0
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()
Example #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "path",
        nargs="?",
        type=Path,
        default="propagate.h5/output",
        help="path to the output file",
    )
    add_argparse_2d_args(parser)
    add_argparse_save_arg(parser)
    args = parser.parse_args()

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

    time, _, energy, _ = read_output(args.path)
    plot_energy(ax, time, energy)

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

    apply_2d_args(ax, figure, args)

    handle_saving(figure, args)
    plt.show()
Example #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("path", nargs=2, help="path to the output file")
    add_argparse_2d_args(parser)
    args = parser.parse_args()

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

    time1, _, energy1, _ = read_output(args.path[0])
    time2, _, energy2, _ = read_output(args.path[1])

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

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

    plot_energy_diff(ax, time1, energy1, energy2)

    system = units.get_default_unit_system()
    ax.set_xlabel(system.get_time_unit().format_label("t"))
    ax.set_ylabel(system.get_energy_unit().format_label(r"\Delta E"))

    apply_2d_args(ax, figure, args)

    plt.show()
Example #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "path",
        nargs="?",
        type=Path,
        default=Path("propagate.h5/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")
    add_argparse_2d_args(parser)
    add_argparse_save_arg(parser)
    args = parser.parse_args()

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

    time, natpop = read_natpop(args.path, node=args.node, dof=args.dof)
    plot_natpop(ax, time, natpop)

    try:
        ax.set_xlabel(
            units.get_default_unit_system().get_time_unit().format_label("t"))
    except units.MissingUnitError:
        ax.set_xlabel("$t$")

    apply_2d_args(ax, figure, args)
    handle_saving(figure, args)

    if not args.output:
        plt.show()
Example #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "path",
        nargs="?",
        type=Path,
        default=Path("propagate.h5/gpop"),
        help="path to the gpop file",
    )
    parser.add_argument("-d",
                        "--dof",
                        type=int,
                        default=1,
                        help="degree of freedom")
    parser.add_argument(
        "--momentum",
        action="store_true",
        help="whether to transform to momentum space",
    )
    parser.add_argument("--logz", action="store_true")
    parser.add_argument("--zmin", type=float)
    parser.add_argument("--zmax", type=float)
    parser.add_argument("--colorbar", action="store_true")
    add_argparse_2d_args(parser)
    add_argparse_save_arg(parser)
    args = parser.parse_args()

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

    data = read_gpop(args.path, dof=args.dof)
    if args.momentum:
        data = transform_to_momentum_space(data)
    mesh = plot_gpop(ax, *data, args.zmin, args.zmax, args.logz)
    if args.colorbar:
        figure.colorbar(mesh, ax=ax).solids.set_rasterized(True)

    unitsys = units.get_default_unit_system()
    try:
        ax.set_xlabel(unitsys.get_time_unit().format_label("t"))
    except units.MissingUnitError:
        ax.set_xlabel("$t$")

    try:
        ax.set_ylabel(unitsys.get_length_unit().format_label("x"))
    except units.MissingUnitError:
        ax.set_ylabel("$x$")

    apply_2d_args(ax, figure, args)

    handle_saving(figure, args)

    if not args.output:
        plt.show()
Example #7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("path",
                        type=Path,
                        nargs="+",
                        help="path to the output file")
    parser.add_argument(
        "--fft",
        action="store_true",
        help="whether to transform the signal to frequency space",
    )
    parser.add_argument("--xname", help="", default="time")
    add_argparse_2d_args(parser)
    add_argparse_save_arg(parser)
    args = parser.parse_args()

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

    unitsys = mlxtk.units.get_default_unit_system()

    for file in args.path:
        name = file.stem
        time, values = read_expval_hdf5(file, xname=args.xname)
        if args.fft:
            plot_expval(ax,
                        *mlxtk.tools.signal.fourier_transform(time, values),
                        label=name)

            ax.set_xlabel(
                (1 / unitsys.get_time_unit()).format_label(r"\omega"))
            ax.set_ylabel(
                mlxtk.units.ArbitraryUnit().format_label(
                    r"\mathrm{amplitude}"), )
        else:
            plot_expval(ax, time, values, label=name)
            if args.xname == "time":
                ax.set_xlabel(unitsys.get_time_unit().format_label("t"))
            else:
                ax.set_xlabel(args.xname)

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

    apply_2d_args(ax, figure, args)

    handle_saving(figure, args)

    if not args.output:
        plt.show()
Example #8
0
    def init_plot(self):
        if self.mesh:
            self.mesh.remove()
            self.mesh = None

        X2, X1 = numpy.meshgrid(self.index2, self.index1)
        self.mesh = self.axes.pcolormesh(
            X1,
            X2,
            numpy.abs(self.dmat[self.time_index]),
            cmap="gnuplot",
            rasterized=True,
        )
        plot.apply_2d_args(self.axes, self.plot.figure, self.plot_args)
        self.plot.canvas.draw()
Example #9
0
    def init_plot(self):
        self.label.setText(f"Time: {self.time[0]:6.2f}")

        if self.line:
            self.line.remove()
            self.line = None

        unit_system = units.get_default_unit_system()
        self.axes.set_xlabel(unit_system.get_length_unit().format_label("x_1"))
        self.axes.set_ylabel(unit_system.get_time_unit().format_label("t"))

        (self.line,) = self.axes.plot(self.grid, self.density[0])

        if self.plot_args:
            plot.apply_2d_args(self.axes, self.plot.figure, self.plot_args)

        self.plot.canvas.draw()
Example #10
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()
Example #11
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()
Example #12
0
    def init_plot(self):
        self.label.setText(f"Time: {self.time[0]:6.2f}")

        if self.mesh:
            self.mesh.remove()
            self.mesh = None

        if self.plot_args:
            plot.apply_2d_args(self.axes, self.plot.figure, self.plot_args)

        unit_system = units.get_default_unit_system()
        self.axes.set_xlabel(unit_system.get_length_unit().format_label("x_1"))
        self.axes.set_ylabel(unit_system.get_length_unit().format_label("x_2"))

        X2, X1 = numpy.meshgrid(self.x2, self.x1)
        self.mesh = self.axes.pcolormesh(
            X1,
            X2,
            self.values[0],
            cmap="gnuplot",
            rasterized=True,
        )
        self.plot.canvas.draw()
Example #13
0
    def init_plot(self):
        if self.line_real:
            self.line_real.remove()
            self.line_real = None

        if self.line_imag:
            self.line_imag.remove()
            self.line_imag = None

        if self.line_abs:
            self.line_abs.remove()
            self.line_abs = None

        self.line_abs = self.axes.plot(
            self.grid,
            numpy.abs(self.evecs[self.index, self.time_index]),
        )[0]
        self.line_real = self.axes.plot(
            self.grid,
            numpy.real(self.evecs[self.index, self.time_index]),
        )[0]
        self.line_imag = self.axes.plot(
            self.grid,
            numpy.imag(self.evecs[self.index, self.time_index]),
        )[0]

        self.line_abs.set_visible(self.check_abs.isChecked())
        self.line_real.set_visible(self.check_real.isChecked())
        self.line_imag.set_visible(self.check_imag.isChecked())

        system = units.get_default_unit_system()
        self.axes.set_xlabel(system.get_length_unit().format_label("x"))
        self.axes.set_ylabel(r"$\varphi(x)$")
        plot.apply_2d_args(self.axes, self.plot.figure, self.plot_args)
        self.update_yrange()

        self.plot.canvas.draw()
Example #14
0
    def init_plot(self):
        self.label.setText(f"Time: {self.time[0]:6.2f}")

        if self.mesh:
            self.mesh.remove()
            self.mesh = None

        if self.plot_args:
            plot.apply_2d_args(self.axes, self.plot.figure, self.plot_args)

        self.axes.set_xlabel("i")
        self.axes.set_ylabel("j")
        self.axes.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(integer=True))
        self.axes.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(integer=True))

        X2, X1 = numpy.meshgrid(self.indices2, self.indices1)
        self.mesh = self.axes.pcolormesh(
            X1 - 0.5,
            X2 - 0.5,
            self.values[0],
            cmap="gnuplot",
            rasterized=True,
        )
        self.plot.canvas.draw()
Example #15
0
 def apply_args(fig: Figure, ax: Axes, parameters: Parameters):
     del parameters
     plot.apply_2d_args(ax, fig, args)