def plot_frames(PP, iom, blockid=0, timerange=None, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=True, gridblockid=None, imgsize=(12, 9), path='.'): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. :param view: The aspect ratio. :param plotphase: Whether to plot the complex phase. (slow) :param plotcomponents: Whether to plot the real/imaginary parts.. :param plotabssqr: Whether to plot the absolute value squared. """ parameters = iom.load_parameters() if not parameters["dimension"] == 1: print("No two-dimensional wavefunction, silent return!") return if PP is None: PP = parameters if load is True: if gridblockid is None: gridblockid = blockid print("Loading grid data from datablock '%s'" % gridblockid) G = iom.load_grid(blockid=gridblockid) grid = real(G.reshape(-1)) else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = real(G.get_nodes(flat=True).reshape(-1)) # View if view[0] is None: view[0] = grid.min() if view[1] is None: view[1] = grid.max() timegrid = iom.load_wavefunction_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in range(parameters["ncomponents"])] # Plot fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"], 1, index + 1) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") if plotcomponents is True: ax.plot(grid, real(component)) ax.plot(grid, imag(component)) ax.set_ylabel(r"$\Re \varphi_{%d}, \Im \varphi_{%d}$" % (index, index)) if plotabssqr is True: ax.plot(grid, real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) if plotphase is True: plotcf(grid, angle(component), real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) ax.set_xlabel(r"$x$") # Set the aspect window ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if "dt" in parameters: fig.suptitle(r"$\Psi$ at time $%f$" % (step * parameters["dt"])) else: fig.suptitle(r"$\Psi$") fig.savefig( os.path.join( path, "wavefunction_block_%s_timestep_%07d.png" % (blockid, step))) close(fig)
def plot_frames(PP, iom, blockid=0, eigentransform=False, timerange=None, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=False, gridblockid=None, imgsize=(12, 9), path='.'): """Plot the wavepacket for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() BF = BlockFactory() if not parameters["dimension"] == 1: print("No one-dimensional wavepacket, silent return!") return if PP is None: PP = parameters if load is True: if gridblockid is None: gridblockid = blockid print("Loading grid data from datablock '{}'".format(gridblockid)) G = iom.load_grid(blockid=gridblockid) grid = real(G.reshape(-1)) else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = real(G.get_nodes(flat=True).reshape(-1)) if eigentransform: V = BF.create_potential(parameters) BT = BasisTransformationHAWP(V) timegrid = iom.load_wavepacket_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") # View if view is not None: if view[0] is None: view[0] = grid.min() if view[1] is None: view[1] = grid.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) HAWP = iom.load_wavepacket(step, blockid=blockid) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(HAWP) values = HAWP.evaluate_at(G.get_nodes(), prefactor=True, component=0) # Plot fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"], 1, index + 1) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") if plotcomponents is True: ax.plot(grid, real(component)) ax.plot(grid, imag(component)) ax.set_ylabel(r"$\Re \varphi_{%d}, \Im \varphi_{%d}$" % (index, index)) if plotabssqr is True: ax.plot(grid, real(component * conj(component))) ax.set_ylabel(r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) if plotphase is True: plotcf(grid, angle(component), real(component * conj(component))) ax.set_ylabel(r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) ax.set_xlabel(r"$x$") # Set the aspect window ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if "dt" in parameters: fig.suptitle(r"$\Psi$ at time $%f$" % (step * parameters["dt"])) else: fig.suptitle(r"$\Psi$") fig.savefig(os.path.join(path, "wavepacket_block_%s_timestep_%07d.png" % (blockid, step))) close(fig)
def plot_frames(PP, iom, blockid=0, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=True, gridblockid=None, imgsize=(12,9)): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. :param view: The aspect ratio. :param plotphase: Whether to plot the complex phase. (slow) :param plotcomponents: Whether to plot the real/imaginary parts.. :param plotabssqr: Whether to plot the absolute value squared. """ parameters = iom.load_parameters() if not parameters["dimension"] == 1: print("No wavefunction of one space dimensions, silent return!") return if PP is None: PP = parameters if load is True: print("Loading grid data from datablock 'global'") if gridblockid is None: gridblockid = blockid G = iom.load_grid(blockid=gridblockid) G = G.reshape((1, -1)) grid = G else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = G.get_nodes(flat=True) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) for step in timegrid: print(" Plotting frame of timestep # " + str(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [ wave[j,...] for j in xrange(parameters["ncomponents"]) ] # Plot the probability densities projected to the eigenbasis fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"],1,index+1) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") if plotcomponents is True: ax.plot(squeeze(grid), real(component)) ax.plot(squeeze(grid), imag(component)) ax.set_ylabel(r"$\Re \varphi_"+str(index)+r", \Im \varphi_"+str(index)+r"$") if plotabssqr is True: ax.plot(squeeze(grid), component*conj(component)) ax.set_ylabel(r"$\langle \varphi_"+str(index)+r"| \varphi_"+str(index)+r"\rangle$") if plotphase is True: plotcf(squeeze(grid), angle(component), component*conj(component)) ax.set_ylabel(r"$\langle \varphi_"+str(index)+r"| \varphi_"+str(index)+r"\rangle$") ax.set_xlabel(r"$x$") # Set the aspect window if view is not None: ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if parameters.has_key("dt"): fig.suptitle(r"$\Psi$ at time $"+str(step*parameters["dt"])+r"$") else: fig.suptitle(r"$\Psi$") fig.savefig("wavefunction_block"+str(blockid)+"_"+ (7-len(str(step)))*"0"+str(step) +GD.output_format) close(fig) print(" Plotting frames finished")
def plot_frames(PP, iom, blockid=0, eigentransform=False, timerange=None, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=False, gridblockid=None, imgsize=(12, 9), path='.'): """Plot the wavepacket for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() BF = BlockFactory() if not parameters["dimension"] == 1: print("No one-dimensional wavepacket, silent return!") return if PP is None: PP = parameters if load is True: if gridblockid is None: gridblockid = blockid print("Loading grid data from datablock '{}'".format(gridblockid)) G = iom.load_grid(blockid=gridblockid) grid = real(G.reshape(-1)) else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = real(G.get_nodes(flat=True).reshape(-1)) if eigentransform: V = BF.create_potential(parameters) BT = BasisTransformationHAWP(V) timegrid = iom.load_wavepacket_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") # View if view is not None: if view[0] is None: view[0] = grid.min() if view[1] is None: view[1] = grid.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) HAWP = iom.load_wavepacket(step, blockid=blockid) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(HAWP) values = HAWP.evaluate_at(G.get_nodes(), prefactor=True, component=0) # Plot fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"], 1, index + 1) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") if plotcomponents is True: ax.plot(grid, real(component)) ax.plot(grid, imag(component)) ax.set_ylabel(r"$\Re \varphi_{%d}, \Im \varphi_{%d}$" % (index, index)) if plotabssqr is True: ax.plot(grid, real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) if plotphase is True: plotcf(grid, angle(component), real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) ax.set_xlabel(r"$x$") # Set the aspect window ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if "dt" in parameters: fig.suptitle(r"$\Psi$ at time $%f$" % (step * parameters["dt"])) else: fig.suptitle(r"$\Psi$") fig.savefig( os.path.join( path, "wavepacket_block_%s_timestep_%07d.png" % (blockid, step))) close(fig)