def plot_frames(iom, blockid=0): parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return G = BlockFactory().create_grid(parameters) V = BlockFactory().create_potential(parameters) WF = WaveFunction(parameters) WF.set_grid(G) BT = BasisTransformationWF(V) BT.set_grid(G) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) u, v = G.get_nodes(split=True, flat=False) u = real(u) v = real(v) N = WF.get_number_components() 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"]) ] WF.set_values(values) # Transform the values to the eigenbasis # TODO: improve this: if parameters["algorithm"] == "fourier": BT.transform_to_eigen(WF) else: pass Psi = WF.get_values() for level in xrange(N): z = Psi[level] # Plot the probability densities projected to the eigenbasis fig = mlab.figure(size=(800,700)) surfcf(u, v, angle(z), abs(z)) #mlab.contour_surf(u, v, abs(z)) #mlab.outline() #mlab.axes() mlab.savefig("wavefunction_level_"+str(level)+"_timestep_"+(5-len(str(step)))*"0"+str(step)+".png") mlab.close(fig) print(" Plotting frames finished")
def plot_frames(PP, iom, blockid=0, load=False, eigentransform=False, timerange=None, sparsify=10, view=None, interactive=False, path='.'): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return if PP is None: PP = parameters if load is True: # TODO: Implement reshaping raise NotImplementedError("Loading of 2D grids is not implemented") else: G = BlockFactory().create_grid(PP) if eigentransform: V = BlockFactory().create_potential(parameters) BT = BasisTransformationWF(V) BT.set_grid(G) WF = WaveFunction(parameters) WF.set_grid(G) N = WF.get_number_components() 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!") u, v = G.get_nodes(split=True, flat=False) u = real(u[::sparsify, ::sparsify]) v = real(v[::sparsify, ::sparsify]) # View if view is not None: if view[0] is None: view[0] = u.min() if view[1] is None: view[1] = u.max() if view[2] is None: view[2] = v.min() if view[3] is None: view[3] = v.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) # Load the data wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in range(parameters["ncomponents"])] WF.set_values(values) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(WF) Psi = WF.get_values() for level in range(N): # Wavefunction data z = Psi[level] z = z.reshape(G.get_number_nodes())[::sparsify, ::sparsify] # View if view is not None: if view[4] is None: view[4] = 0.0 if view[5] is None: view[5] = 1.1 * abs(z).max() # Plot # if not interactive: # mlab.options.offscreen = True fig = mlab.figure(size=(800, 700)) surfcf(u, v, angle(z), abs(z), view=view) mlab.draw() if interactive: mlab.show() else: mlab.savefig(os.path.join("wavefunction_surface_block_%s_level_%d_timestep_%07d.png" % (blockid, level, step))) mlab.close(fig)
def plot_frames(PP, iom, blockid=0, load=False, eigentransform=False, timerange=None, sparsify=10, view=None, interactive=False, path='.'): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return if PP is None: PP = parameters if load is True: # TODO: Implement reshaping raise NotImplementedError("Loading of 2D grids is not implemented") else: G = BlockFactory().create_grid(PP) if eigentransform: V = BlockFactory().create_potential(parameters) BT = BasisTransformationWF(V) BT.set_grid(G) WF = WaveFunction(parameters) WF.set_grid(G) N = WF.get_number_components() 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!") u, v = G.get_nodes(split=True, flat=False) u = real(u[::sparsify, ::sparsify]) v = real(v[::sparsify, ::sparsify]) # View if view is not None: if view[0] is None: view[0] = u.min() if view[1] is None: view[1] = u.max() if view[2] is None: view[2] = v.min() if view[3] is None: view[3] = v.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) # Load the data wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in range(parameters["ncomponents"])] WF.set_values(values) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(WF) Psi = WF.get_values() for level in range(N): # Wavefunction data z = Psi[level] z = z.reshape(G.get_number_nodes())[::sparsify, ::sparsify] # View if view is not None: if view[4] is None: view[4] = 0.0 if view[5] is None: view[5] = 1.1 * abs(z).max() # Plot # if not interactive: # mlab.options.offscreen = True fig = mlab.figure(size=(800, 700)) surfcf(u, v, angle(z), abs(z), view=view) mlab.draw() if interactive: mlab.show() else: mlab.savefig( os.path.join( "wavefunction_surface_block_%s_level_%d_timestep_%07d.png" % (blockid, level, step))) mlab.close(fig)
def plot_frames(PP, iom, blockid=0, load=False): r""" """ parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return if PP is None: PP = parameters if load is True: # TODO: Implement reshaping raise NotImplementedError("Loading of 2D grids is not implemented") #G = iom.load_grid(blockid=blockid) #G = grid.reshape((1, -1)) else: G = BlockFactory().create_grid(PP) V = BlockFactory().create_potential(parameters) WF = WaveFunction(parameters) WF.set_grid(G) BT = BasisTransformationWF(V) BT.set_grid(G) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) u, v = G.get_nodes(split=True, flat=False) u = real(u) v = real(v) N = WF.get_number_components() 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"]) ] WF.set_values(values) # Transform the values to the eigenbasis # TODO: improve this: if parameters["algorithm"] == "fourier": BT.transform_to_eigen(WF) else: pass Psi = WF.get_values() for level in xrange(N): z = Psi[level] z = z.reshape(G.get_number_nodes()) # Plot the probability densities projected to the eigenbasis fig = mlab.figure(size=(800,700)) surfcf(u, v, angle(z), abs(z)) #mlab.contour_surf(u, v, abs(z)) #mlab.outline() #mlab.axes() mlab.savefig("wavefunction_level_"+str(level)+"_timestep_"+(5-len(str(step)))*"0"+str(step)+".png") mlab.close(fig) print(" Plotting frames finished")