Exemple #1
0
    parser.add_argument("-y", "--yrange", type=float, help="The plot range on the y-axis", nargs=2, default=[-2, 5])

    args = parser.parse_args()

    # File with the simulation data
    resultspath = os.path.abspath(args.resultspath)

    if not os.path.exists(resultspath):
        raise IOError("The results path does not exist: {}".format(args.resultspath))

    datafile = os.path.abspath(os.path.join(args.resultspath, args.datafile))
    parametersfile = os.path.abspath(os.path.join(args.resultspath, args.parametersfile))

    # Read file with simulation data
    iom = IOManager()
    iom.open_file(filename=datafile)

    # Read file with parameter data for grid
    parameters = iom.load_parameters()

    if args.parametersfile:
        PL = ParameterLoader()
        gridparams = PL.load_from_file(parametersfile)
    else:
        gridparams = parameters

    # The axes rectangle that is plotted
    view = args.xrange + args.yrange

    if parameters["dimension"] == 1:
        Potential = BlockFactory().create_potential(parameters)
                    type = str,
                    help = "The simulation data file",
                    nargs = "?",
                    default = GD.file_resultdatafile)

parser.add_argument("-b", "--blockid",
                    type = str,
                    help = "The data block to handle",
                    nargs = "*",
                    default = ["all"])

args = parser.parse_args()

# Read file with simulation data
iom = IOManager()
iom.open_file(filename=args.datafile)

# Which blocks to handle
blockids = iom.get_block_ids()
if "all" not in args.blockid:
    blockids = [bid for bid in args.blockid if bid in blockids]

# Iterate over all blocks
for blockid in blockids:
    if iom.has_wavefunction(blockid=blockid):
        print("Deleting grid and wavefunction data in block '{}'".format(blockid))
        iom.delete_wavefunction(blockid=blockid)
        if iom.has_grid(blockid=blockid):
            iom.delete_grid(blockid=blockid)

iom.finalize()
Exemple #3
0
        ax.set_ylabel("t")
        ax.set_title(r"Coefficients $c_k^" + str(jndex) + "$")
        fig.savefig("wavepacket_coefficients_map_eigen_cm_component" +
                    str(jndex) + "_block" + str(index) + GD.output_format)
        close(fig)

        fig = figure(figsize=imgsize)
        ax = gca()
        plotcm(coeff, angle(coeff), abs(coeff), darken=True, axes=ax)
        ax.set_xlabel("k")
        ax.set_ylabel("t")
        ax.set_title(r"Coefficients $c_k^" + str(jndex) + "$")
        fig.savefig("wavepacket_coefficients_map_eigen_cm_darken_component" +
                    str(jndex) + "_block" + str(index) + GD.output_format)
        close(fig)


if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    # Read the data and plot it, one plot for each data block.
    read_all_datablocks(iom)

    iom.finalize()
    close(fig)


    fig = figure()
    ax = fig.gca()

    ax.semilogy(timegridk, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$")
    ax.grid(True)
    ax.set_xlabel(r"Time $t$")
    ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$")
    ax.set_title(r"Energy drift of the wavepacket $\Psi$")

    fig.savefig("energy_drift_block"+str(index)+"_log"+GD.output_format)
    close(fig)




if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    read_all_datablocks(iom)

    iom.finalize()
Exemple #5
0
from WaveBlocksND import IOManager
from WaveBlocksND import GlobalDefaults as GD


if __name__ == "__main__":

    iomc = IOManager()
    iome = IOManager()

    # Read file with simulation data
    try:
        filename = sys.argv[1]
    except IndexError:
        filename = GD.file_resultdatafile

    iomc.open_file(filename=filename)

    # New file for eigen transformed data
    P = iomc.load_parameters()
    iome.create_file(P, filename=filename[:-5]+"_eigen.hdf5")

    # Iterate over all groups
    for groupid in iomc.get_group_ids():

        # Create the group if necessary
        if not groupid in iome.get_group_ids():
            iome.create_group(groupid=groupid)

        for blockid in iomc.get_block_ids(groupid=groupid):
            print("Computing eigentransformation of data in block '"+str(blockid)+"'")
Exemple #6
0
                        default=[None, None])

    args = parser.parse_args()

    # File with the simulation data
    resultspath = os.path.abspath(args.resultspath)

    if not os.path.exists(resultspath):
        raise IOError("The results path does not exist: {}".format(
            args.resultspath))

    datafile = os.path.abspath(os.path.join(args.resultspath, args.datafile))

    # Read file with simulation data
    iom = IOManager()
    iom.open_file(filename=datafile)

    # Which blocks to handle
    blockids = iom.get_block_ids()
    if "all" not in args.blockid:
        blockids = [bid for bid in args.blockid if bid in blockids]

    # The axes rectangle that is plotted
    view = args.trange + args.vrange

    # Iterate over all blocks
    for blockid in blockids:
        print("Plotting autocorrelations in data block '{}'".format(blockid))

        if iom.has_autocorrelation(blockid=blockid):
            plot_autocorrelations(read_data(iom, blockid=blockid),
Exemple #7
0
def load_from_file(filepath, blockid=0, timestep=0, sizeK=None):
    r"""Utility script to load wavepacket parameters and coefficients
    from another simulation result in a form suitable for the input
    configuration of a new simulation. This is (mainly) used
    to start simulations with previously computed eigenstates.

    :param filepath: The path to the `.hdf5` file from which data will be read.
    :param blockid: The `datablock` from which to read the data.
                    Default is the block with `blockid=0`.
    :param timestep: Load the data corresponding to the given `timestep`.
                     The default timestep is `0`.
    :param sizeK: Load at most 'sizeK' many coefficients. Note that the order
                  is defined by the linearization mapping :math:`\mu` of the
                  packet's current basis shape. We then pick the first `sizeK`
                  ones.
    """
    IOM = IOManager()
    IOM.open_file(filepath)

    # Check if we have data
    tg = IOM.load_wavepacket_timegrid(blockid=blockid)
    if timestep not in tg:
        raise ValueError("No data for timestep {}".format(timestep))

    # Load data and assemble packet
    BF = BlockFactory()

    # Basis shapes
    BS_descr = IOM.load_wavepacket_basisshapes(blockid=blockid)
    BS = {}
    for ahash, descr in BS_descr.items():
        BS[ahash] = BF.create_basis_shape(descr)

    # Create a packet
    wpd = IOM.load_wavepacket_description(blockid=blockid)
    HAWP = BF.create_wavepacket(wpd)

    # Data
    ha, ci = IOM.load_wavepacket_coefficients(blockid=blockid,
                                              timestep=timestep,
                                              get_hashes=True)
    Pi = IOM.load_wavepacket_parameters(blockid=blockid, timestep=timestep)

    HAWP.set_parameters(Pi)
    HAWP.set_basis_shapes([BS[int(h)] for h in ha])
    HAWP.set_coefficients(ci)

    # Reformat data
    C = []

    for n in range(HAWP.get_number_components()):
        B = HAWP.get_basis_shapes(component=n)
        cn = HAWP.get_coefficients(component=n)
        l = []
        for i in range(B.get_basis_size()):
            l.append((B[i], cn[i, 0]))
        C.append(l)

    if sizeK is not None:
        # We load at most 'sizeK' coefficients.
        # Note that this does NOT specify which
        # ones in terms of multi-indices.
        C = [c[:sizeK] for c in C]

    return Pi, C
                    type = str,
                    help = "The data file to write the transformed data.")

args = parser.parse_args()

if not args.outputfile:
    outputfile = args.inputfile.replace(GD.ext_resultdatafile, "") + "_eigen" + GD.ext_resultdatafile
else:
    outputfile = args.outputfile

print("Reading simulation data from the file: "+str(args.inputfile))
print("Writing transformed data to the file: "+str(outputfile))

# Read file with simulation data
iomc = IOManager()
iomc.open_file(args.inputfile)

iome = IOManager()
iome.create_file(outputfile)

# New file for eigen transformed data
P = iomc.load_parameters()

# Save the simulation parameters
iome.add_parameters()
iome.save_parameters(P)

# Iterate over all groups
for groupid in iomc.get_group_ids():

    # Create the group if necessary
Exemple #9
0
def load_from_file(filepath, blockid=0, timestep=0, sizeK=None):
    r"""Utility script to load wavepacket parameters and coefficients
    from another simulation result in a form suitable for the input
    configuration of a new simulation. This is (mainly) used
    to start simulations with previously computed eigenstates.

    :param filepath: The path to the `.hdf5` file from which data will be read.
    :param blockid: The `datablock` from which to read the data.
                    Default is the block with `blockid=0`.
    :param timestep: Load the data corresponding to the given `timestep`.
                     The default timestep is `0`.
    :param sizeK: Load at most 'sizeK' many coefficients. Note that the order
                  is defined by the linearization mapping :math:`\mu` of the
                  packet's current basis shape. We then pick the first `sizeK`
                  ones.
    """
    IOM = IOManager()
    IOM.open_file(filepath)

    # Check if we have data
    tg = IOM.load_wavepacket_timegrid(blockid=blockid)
    if timestep not in tg:
        raise ValueError("No data for timestep {}".format(timestep))

    # Load data and assemble packet
    BF = BlockFactory()

    # Basis shapes
    BS_descr = IOM.load_wavepacket_basisshapes(blockid=blockid)
    BS = {}
    for ahash, descr in BS_descr.items():
        BS[ahash] = BF.create_basis_shape(descr)

    # Create a packet
    wpd = IOM.load_wavepacket_description(blockid=blockid)
    HAWP = BF.create_wavepacket(wpd)

    # Data
    ha, ci = IOM.load_wavepacket_coefficients(blockid=blockid, timestep=timestep, get_hashes=True)
    Pi = IOM.load_wavepacket_parameters(blockid=blockid, timestep=timestep)

    HAWP.set_parameters(Pi)
    HAWP.set_basis_shapes([BS[int(h)] for h in ha])
    HAWP.set_coefficients(ci)

    # Reformat data
    C = []

    for n in range(HAWP.get_number_components()):
        B = HAWP.get_basis_shapes(component=n)
        cn = HAWP.get_coefficients(component=n)
        l = []
        for i in range(B.get_basis_size()):
            l.append((B[i], cn[i, 0]))
        C.append(l)

    if sizeK is not None:
        # We load at most 'sizeK' coefficients.
        # Note that this does NOT specify which
        # ones in terms of multi-indices.
        C = [c[:sizeK] for c in C]

    return Pi, C
                    nargs = "?",
                    default = GD.file_resultdatafile)

parser.add_argument("-b", "--blockid",
                    help = "The data block to handle",
                    nargs = "*",
                    default = [0])

parser.add_argument("-p", "--params",
                    help = "An additional configuration parameters file")

args = parser.parse_args()

# Read file with simulation data
iom = IOManager()
iom.open_file(filename=args.simfile)

# Read the additional grid parameters
if args.params:
    parametersfile = args.params
    PA = ParameterLoader().load_from_file(parametersfile)
else:
    PA = None

# Which blocks to handle
if "all" in args.blockid:
    blocks_to_handle = iom.get_block_ids()
else:
    blocks_to_handle = map(int, args.blockid)

# Iterate over all blocks
inputfile = os.path.abspath(os.path.join(args.resultspath, args.inputfile))

# No output file name given
if not args.outputfile:
    outputfile = inputfile.replace(GD.ext_resultdatafile, "") + "_eigen" + GD.ext_resultdatafile
else:
    outputfile = args.outputfile

outputfile = os.path.abspath(os.path.join(args.resultspath, outputfile))

print("Reading simulation data from the file: {}".format(inputfile))
print("Writing transformed data to the file: {}".format(outputfile))

# Read file with simulation data
iomc = IOManager()
iomc.open_file(inputfile)

iome = IOManager()
iome.create_file(outputfile)

# New file for eigen transformed data
P = iomc.load_parameters()

# Save the simulation parameters
iome.add_parameters()
iome.save_parameters(P)

# Iterate over all groups
for groupid in iomc.get_group_ids():

    # Create the group if necessary