def plotRadialProjection(pattern, parameters, logscale=True, offset=1.e-5, unit="q_nm^-1"): """ Perform integration over azimuthal angle and plot as function of radius. :param unit:can be "q_nm^-1", "q_A^-1", "2th_deg", "2th_rad", "r_mm". :type unit: str """ qs, intensities = azimuthalIntegration(pattern, parameters, unit=unit) if logscale: plt.semilogy(qs, intensities + offset) else: plt.plot(qs, intensities) if (unit == "q_nm^-1"): plt.xlabel("q (1/nm)") elif (unit == "q_A^-1"): plt.xlabel("q (1/A)") elif (unit == "2th_deg"): plt.xlabel("2theta (degrees)") elif (unit == "2th_rad"): plt.xlabel("2theta (radians)") elif (unit == "r_mm"): plt.xlabel("mm") plt.ylabel("Intensity (arb. units)") plt.tight_layout()
def plot_charge(self): """ Plot the average number of electrons per atom per atomic species as function of time. """ for d in self.__trajectory['charge'].T: plt.plot(d) ### TODO: time axis, labels, legend plt.xlabel('Time [fs]') plt.ylabel('Number of bound electrons per atom')
def plot_displacement(self): """ Plot the average displacement per atomic species as function of time. """ #t = self.trajectory['time'] for d in self.__trajectory['displacement'].T: plt.plot( d ) # self.trajectory['disp'][ : , pylab.find( sel_Z == pylab.array( list(data['sample']['selZ'].keys()) ) ) ] , xcolor ) plt.xlabel('Time [fs]') plt.ylabel('Average displacement [$\AA$]')
def plotResolutionRings(parameters): """ Show resolution rings on current plot. :param parameters: Parameters needed to construct the resolution rings. :type parameters: dict """ # Extract parameters. beam = parameters['beam'] geom = parameters['geom'] # Photon energy and wavelength E0 = beam['photonEnergy'] lmd = 1239.8 / E0 # Pixel dimension apix = geom['pixelWidth'] # Sample-detector distance Ddet = geom['detectorDist'] # Number of pixels in each dimension Npix = geom['mask'].shape[0] # Find center. center = 0.5 * (Npix - 1) # Max. scattering angle. theta_max = math.atan(center * apix / Ddet) # Min resolution. d_min = 0.5 * lmd / math.sin(theta_max) # Next integer resolution. d0 = 0.1 * math.ceil(d_min * 10.0) # 10 powers to get Angstrom # Array of resolution rings to plot. ds = numpy.array([1.0, 0.5, .3]) # Pixel numbers corresponding to resolution rings. Ns = Ddet / apix * numpy.arctan(numpy.arcsin(lmd / 2. / ds)) # Plot each ring and attach a label. for i, N in enumerate(Ns): x0 = center X = numpy.linspace(x0 - N, x0 + N, 512) Y_up = x0 + numpy.sqrt(N**2 - (X - x0)**2) Y_dn = x0 - numpy.sqrt(N**2 - (X - x0)**2) plt.plot(X, Y_up, color='k') plt.plot(X, Y_dn, color='k') plt.text(x0 + 0.75 * N, x0 + 0.75 * N, "%2.1f" % (ds[i] * 10.)) plt.xlim(0, Npix - 1) plt.ylim(0, Npix - 1)
def plotRadialProjection(pattern, parameters, logscale=True, offset=1.e-5): """ Perform integration over azimuthal angle and plot as function of radius. """ qs, intensities = azimuthalIntegration(pattern, parameters) if logscale: plt.semilogy(qs, intensities + offset) else: plt.plot(qs, intensities) plt.xlabel("q (1/nm)") plt.ylabel("Intensity (arb. units)") plt.tight_layout()
def plotTotalPower(self, spectrum=False): """ Method to plot the total power. :param spectrum: Whether to plot the power density in energy domain (True) or time domain (False, default). :type spectrum: bool """ """ Adapted from github:Samoylv/WPG/wpg/wpg_uti_wf.integral_intensity() """ print("\n Plotting total power.") # Setup new figure. plt.figure() # Switch to frequency (energy) domain if requested. if spectrum: print("\n Switching to frequency domain.") wpg.srwlib.srwl.SetRepresElecField(self.wavefront._srwl_wf, 'f') self.intensity = self.wavefront.get_intensity() # Get dimensions. mesh = self.wavefront.params.Mesh dx = (mesh.xMax - mesh.xMin)/(mesh.nx - 1) dy = (mesh.yMax - mesh.yMin)/(mesh.ny - 1) # Get intensity by integrating over transverse dimensions. int0 = self.intensity.sum(axis=(0,1)) # Scale to get unit W/mm^2 int0 = int0*(dx*dy*1.e6) # amplitude units sqrt(W/mm^2) int0max = int0.max() # Get center pixel numbers. center_nx = int(mesh.nx/2) center_ny = int(mesh.ny/2) # Get meaningful slices. aw = [a[0] for a in numpy.argwhere(int0 > int0max*0.01)] int0_mean = int0[min(aw):max(aw)] # meaningful range of pulse dSlice = (mesh.sliceMax - mesh.sliceMin)/(mesh.nSlices - 1) xs = numpy.arange(mesh.nSlices)*dSlice+ mesh.sliceMin xs_mf = numpy.arange(min(aw), max(aw))*dSlice + mesh.sliceMin if(self.wavefront.params.wDomain=='time'): plt.plot(xs*1e15, int0) # time axis converted to fs. plt.plot(xs_mf*1e15, int0_mean, 'ro') plt.title('Power') plt.xlabel('time (fs)') plt.ylabel('Power (W)') dt = (mesh.sliceMax - mesh.sliceMin)/(mesh.nSlices - 1) print(('Pulse energy {:1.2g} J'.format(int0_mean.sum()*dt))) else: #frequency domain plt.plot(xs, int0) plt.plot(xs_mf, int0_mean, 'ro') plt.title('Spectral Energy') plt.xlabel('eV') plt.ylabel('J/eV') # Switch back to time domain. wpg.srwlib.srwl.SetRepresElecField(self.wavefront._srwl_wf, 't') self.intensity = self.wavefront.get_intensity()
def plotResolutionRings(parameters, rings=(10, 5.0, 3.5), half=True): """ Show resolution rings on current plot. :param parameters: Parameters needed to construct the resolution rings. :type parameters: dict :param rings: the rings shown on the figure :type rings: list :param half: show half period resolution (True, default) or full period resolution (False) :type half: bool """ # Extract parameters. beam = parameters['beam'] geom = parameters['geom'] # Photon energy and wavelength E0 = beam['photonEnergy'] lmd = 1239.8 / E0 # Pixel dimension apix = geom['pixelWidth'] # Sample-detector distance Ddet = geom['detectorDist'] # Number of pixels in each dimension Npix = geom['mask'].shape[0] # Find center. center = 0.5 * (Npix - 1) # Max. scattering angle. theta_max = math.atan(center * apix / Ddet) # Min resolution. if (half): d_min = 0.5 * lmd / math.sin(theta_max / 2.0) / 2.0 else: d_min = 0.5 * lmd / math.sin(theta_max / 2.0) # Next integer resolution. d0 = 0.1 * math.ceil(d_min * 10.0) # 10 powers to get Angstrom # Array of resolution rings to plot. ds = numpy.array(rings) / 10 # nm # Pixel numbers corresponding to resolution rings. if (half): Ns = Ddet / apix * numpy.tan(numpy.arcsin(lmd / 2. / ds / 2.) * 2) else: Ns = Ddet / apix * numpy.tan(numpy.arcsin(lmd / 2. / ds) * 2) # Plot each ring and attach a label. for i, N in enumerate(Ns): x0 = center X = numpy.linspace(x0 - N, x0 + N, 512) Y_up = x0 + numpy.sqrt(N**2 - (X - x0)**2) Y_dn = x0 - numpy.sqrt(N**2 - (X - x0)**2) plt.plot(X, Y_up, color='k') plt.plot(X, Y_dn, color='k') plt.text(x0 + 0.75 * N, x0 + 0.75 * N, "%2.1f" % (ds[i] * 10.), color='red') plt.xlim(0, Npix - 1) plt.ylim(0, Npix - 1)
def plotOnAxisPowerDensity(self, spectrum=False): """ Method to plot the on-axis power density. :param spectrum: Whether to plot the power density in energy domain (True) or time domain (False, default). :type spectrum: bool """ """ Adapted from github:Samoylv/WPG/wpg/wpg_uti_wf.integral_intensity() """ print("\n Plotting on-axis power density.") # Setup new figure. plt.figure() # Switch to frequency (energy) domain if requested. if spectrum: wpg.srwlib.srwl.SetRepresElecField(self.wavefront._srwl_wf, 'f') self.intensity = self.wavefront.get_intensity() # Get dimensions. mesh = self.wavefront.params.Mesh dx = (mesh.xMax - mesh.xMin)/(mesh.nx - 1) dy = (mesh.yMax - mesh.yMin)/(mesh.ny - 1) # Get center pixel numbers. center_nx = int(mesh.nx/2) center_ny = int(mesh.ny/2) # Get time slices of intensity. intensity = self.intensity # Get on-axis intensity. int0_00 = intensity[center_ny, center_nx, :] int0 = intensity.sum(axis=(0,1))*(dx*dy*1.e6) # amplitude units sqrt(W/mm^2) int0max = int0.max() # Get meaningful slices. aw = [a[0] for a in numpy.argwhere(int0 > int0max*0.01)] if aw == []: raise RuntimeError("No significant intensities found.") dSlice = (mesh.sliceMax - mesh.sliceMin)/(mesh.nSlices - 1) xs = numpy.arange(mesh.nSlices)*dSlice+ mesh.sliceMin xs_mf = numpy.arange(min(aw), max(aw))*dSlice + mesh.sliceMin # Plot. if(self.wavefront.params.wDomain=='time'): plt.plot(xs*1e15,int0_00) plt.plot(xs_mf*1e15, int0_00[min(aw):max(aw)], 'ro') plt.title('On-Axis Power Density') plt.xlabel('time (fs)') plt.ylabel(r'Power density (W/mm${}^{2}$)') else: #frequency domain plt.plot(xs,int0_00) plt.plot(xs_mf, int0_00[min(aw):max(aw)], 'ro') plt.title('On-Axis Spectral Fluence') plt.xlabel('photon energy (eV)') plt.ylabel(r'fluence (J/eV/mm${}^{2}$)') # Switch back to time domain. wpg.srwlib.srwl.SetRepresElecField(self.wavefront._srwl_wf, 't') self.intensity = self.wavefront.get_intensity()