def plotQ(self, xGrid, yGrid, dynLow, dynHigh, ax=None, **kwargs): if ax is None: fig, ax = plt.subplots() #ax.set_title( self.filename ) self.gridder = xu.Gridder2D(xGrid,yGrid) self.gridder(self.qy, self.qz, self.data) intHigh = np.argmax(self.data) intMin = np.argmin(self.data) dynhigh = np.rint(np.log10(intHigh)) #print('intMin = ' + str(intMin)) #print('intHigh = ' + str(intHigh)) INT = xu.maplog(self.gridder.data, dynLow, dynHigh) levels = np.linspace(1, dynhigh, num=20) levels = 10**(levels) #print(levels) ax.contourf(self.gridder.xaxis, self.gridder.yaxis, np.transpose(INT), **kwargs) #ax.colorbar(label='Data') #ax.set_aspect('equal') ax.set_xlabel(r'$Q_{[' + str(self.iHKL[0]) + '' + str(self.iHKL[1]) + '' + str(self.iHKL[2]) + ']}$', fontsize=18) ax.set_ylabel(r'$Q_{[' + str(self.oHKL[0]) + '' + str(self.oHKL[1]) + '' + str(self.oHKL[2]) + ']}$', fontsize=18) ax.tick_params(axis='both', which='major', labelsize=18) return ax
def setUpClass(cls): cls.nx = 10 # do not change this here unless you fix also the tests cases cls.ny = 19 cls.xmin = 1 cls.xmax = 10 cls.x = numpy.linspace(cls.xmin, cls.xmax, num=cls.nx) cls.y = cls.x.copy() cls.data = numpy.random.rand(cls.nx) cls.gridder = xu.Gridder2D(cls.nx, cls.ny) cls.gridder(cls.x, cls.y, cls.data)
def plotQ(self, xGrid, yGrid, dynLow, dynHigh, fig=None, ax=None, nlev=None, show_title=False, axlabels='hkl', **kwargs): if ax is None or fig is None: fig, ax = plt.subplots() if show_title == True: ax.set_title(self.filename) self.gridder = xu.Gridder2D(xGrid, yGrid) self.gridder(self.qy, self.qz, self.data) intHigh = np.argmax(self.data) intMin = np.argmin(self.data) dynhigh = np.rint(np.log10(intHigh)) INT = xu.maplog(self.gridder.data, dynLow, dynHigh) levels = np.linspace(1, dynhigh, num=20) levels = 10**(levels) #print(levels) ax.contourf(self.gridder.xaxis, self.gridder.yaxis, np.transpose(INT), nlev, **kwargs) if axlabels == 'ipoop': xlabel = '$Q_{ip}$' ylabel = '$Q_{oop}$' ax.set_xlabel(xlabel, fontsize=18) ax.set_ylabel(ylabel, fontsize=18) else: xlabel = [ '\\bar{' + str(-i) + '}' if i < 0 else str(i) for i in self.iHKL ] ylabel = [ '\\bar{' + str(-i) + '}' if i < 0 else str(i) for i in self.oHKL ] ax.set_xlabel(r'$Q_{[' + xlabel[0] + '' + xlabel[1] + '' + xlabel[2] + ']}$', fontsize=18) ax.set_ylabel(r'$Q_{[' + ylabel[0] + '' + ylabel[1] + '' + ylabel[2] + ']}$', fontsize=18) ax.tick_params(axis='both', which='major', labelsize=18) return fig, ax
omalign, ttalign, p, cov = xu.analysis.fit_bragg_peak(om, tt, psd, omalign, ttalign, hxrd, plot=False) # convert angular coordinates to reciprocal space + correct for offsets [qx, qy, qz] = hxrd.Ang2Q.linear(om, tt, delta=[omalign - omnominal, ttalign - ttnominal]) # calculate data on a regular grid of 200x201 points gridder = xu.Gridder2D(200, 201) gridder(qy, qz, psd) INT = xu.maplog(gridder.data.transpose(), 8.5, 0) # plot the intensity as contour plot plt.figure() plt.clf() cf = plt.contourf(gridder.xaxis, gridder.yaxis, INT, 100, extend='min') plt.xlabel(r'$Q_{[11\bar2]}$ ($\AA^{-1}$)') plt.ylabel(r'$Q_{[\bar1\bar1\bar1]}$ ($\AA^{-1}$)') cb = plt.colorbar(cf) cb.set_label(r"$\log($Int$)$ (cps)") # The same again for a second (asymmetric peak) # reciprocal space map around the InP (224)
def plotQ(self, xGrid, yGrid, dynLow, dynHigh, fig=None, ax=None, nlev = None, show_title=False, axlabels='hkl', **kwargs): """ Plots X-ray diffraction mesh scan in reciprocal space. First needs to nonlinearly regrid the angular data into reciprocal space and plot this. Parameters ---------- xGrid : int number of x bins for regridding data yGrid : int number of y bins for regridding data dynLow : float soft lower limit for intensity colorscale. Equivalent to 10^-(dynLow) dynHigh : float soft upper limit for intensity colorscale. Equivalent to 10^(dynHigh) """ if ax is None or fig is None: fig, ax = plt.subplots() if show_title == True: ax.set_title( self.filename ) if "cmap" not in kwargs.keys(): # Generate new colormap for RSM display rainbow = cm.get_cmap('magma_r', 256) newcolors = rainbow(np.linspace(0, 1, 256)) white = np.array([1, 1, 1, 1]) newcolors[:20, :] = white kwargs["cmap"] = ListedColormap(newcolors) self.gridder = xu.Gridder2D(xGrid,yGrid) self.gridder.KeepData(True) self.gridder.dataRange( self._gridder_ymin, self._gridder_ymax, self._gridder_zmin, self._gridder_zmax, ) # If multiple datasets have been loaded, add each one to gridder for d in range(self._num_datasets): x = self.qy[d].ravel() y = self.qz[d].ravel() z = self.data[d].ravel() self.gridder(x,y,z) intHigh = np.argmax(self.gridder.data) intMin = np.argmin(self.gridder.data) dynhigh = np.rint(np.log10(intHigh)) INT = xu.maplog(self.gridder.data, dynLow, dynHigh) im = ax.contourf(self.gridder.xaxis, self.gridder.yaxis, np.transpose(INT), nlev, **kwargs) for c in im.collections: c.set_edgecolor("face") if axlabels == 'ipoop': xlabel = '$q_{ip}$' ylabel = '$q_{oop}$' ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) else: xlabel = [ '\\bar{'+str(-i)+'}' if i < 0 else str(i) for i in self.iHKL ] ylabel = [ '\\bar{'+str(-i)+'}' if i < 0 else str(i) for i in self.oHKL ] ax.set_xlabel(r'$q_{[' + xlabel[0] + '' + xlabel[1] + '' + xlabel[2] + ']}$') ax.set_ylabel(r'$q_{[' + ylabel[0] + '' + ylabel[1] + '' + ylabel[2] + ']}$') ax.tick_params(axis='both', which='major') return fig, ax
# determine offset of substrate peak from experimental values (optional) omalign, ttalign, p, cov = xu.analysis.fit_bragg_peak(om, tt, psd, omalign, ttalign, hxrd, plot=False) # convert angular coordinates to reciprocal space + correct for offsets qx, qy, qz = hxrd.Ang2Q(om, tt, delta=[omalign - omnominal, ttalign - ttnominal]) # calculate data on a regular grid of 200x201 points gridder = xu.Gridder2D(200, 600) gridder(qy, qz, psd) INT = xu.maplog(gridder.data.transpose(), 6, 0) # plot the intensity as contour plot plt.figure() cf = plt.contourf(gridder.xaxis, gridder.yaxis, INT, 100, extend='min') plt.xlabel(r'$Q_{[110]}$ ($\mathrm{\AA}^{-1}$)') plt.ylabel(r'$Q_{[001]}$ ($\mathrm{\AA}^{-1}$)') cb = plt.colorbar(cf) cb.set_label(r"$\log($Int$)$ (cps)") tr = SiGe.RelaxationTriangle([0, 0, 4], Si, hxrd) # plt.plot(tr[0], tr[1], 'ok') plt.tight_layout()
# convert angular coordinates to reciprocal space + correct for offsets [qx, qy, qz] = hxrd.Ang2Q(om, tt, delta=[omalign - omnominal, ttalign - ttnominal]) ############################################# # three different visualization possibilities # plot the intensity as contour plot plt.figure(figsize=(12, 6)) MIN = 1 MAX = 3e5 plt.subplot(131) plt.title('Gridder2D') # data on a regular grid of 200x800 points gridder = xu.Gridder2D(200, 300) gridder(qy, qz, psd) cf = plt.pcolormesh(gridder.xaxis, gridder.yaxis, gridder.data.T, norm=LogNorm(MIN, MAX)) plt.subplot(132) plt.title('FuzzyGridder2D') # data on a regular grid with FuzzyGridding gridder = xu.FuzzyGridder2D(200, 300) gridder(qy, qz, psd, width=(0.0008, 0.0003)) cf = plt.pcolormesh(gridder.xaxis, gridder.yaxis, gridder.data.T, norm=LogNorm(MIN, MAX)) plt.subplot(133) plt.title('pcolormesh') # using pcolor-variants
# read the data from the HDF5 file # scan number:36, names of motors in spec file: omega= sample rocking, gamma = # twotheta [om, tt], MAP = xu.io.geth5_scan(h5file, 36, 'omega', 'gamma') # normalize the intensity values (absorber and count time corrections) psdraw = normalizer_detcorr(MAP) # remove unusable detector channels/regions (no averaging of detector channels) psd = xu.blockAveragePSD(psdraw, 1, roi=roi) # convert angular coordinates to reciprocal space + correct for offsets [qx, qy, qz] = hxrd.Ang2Q.linear(om, tt, delta=[omalign - omnominal, ttalign - ttnominal]) # calculate data on a regular grid of 200x201 points gridder = xu.Gridder2D(200, 201) gridder(qy, qz, psd) # maplog function limits the shown dynamic range to 8 orders of magnitude # from the maxium INT = xu.maplog(gridder.data.T, 8., 0) # plot the intensity as contour plot using matplotlib plt.figure() cf = plt.contourf(gridder.xaxis, gridder.yaxis, INT, 100, extend='min') plt.xlabel(r'$Q_{[11\bar2]}$ ($\mathrm{\AA}^{-1}$)') plt.ylabel(r'$Q_{[\bar1\bar1\bar1]}$ ($\mathrm{\AA}^{-1}$)') cb = plt.colorbar(cf) cb.set_label(r"$\log($Int$)$ (cps)")
'Eta', 'Nu', 'Delta', xmotor='adcY', ymotor='adcX', ccdnr='imgnr', path=specdir) # retrace clean all scans fss.retrace_clean() # align different scans (misalignment needs to be determined manually or if # your application allows also by a 2d correllation code # see e.g. scipy.signal.correlate2d # fss.align(deltax,deltay) # real space grid g2d = xu.Gridder2D(nx, ny) # read all motor positions from the data files fss.read_motors() # plot counter intensity on a grid for idx, fs in enumerate(fss.fastscans): print(idx) g2d.Clear() g2d(fs.data['adcX'], fs.data['adcY'], fs.data['mpx4int']) plt.figure() plt.contourf(g2d.xaxis, g2d.yaxis, g2d.data.T, 50) plt.xlabel("X (um)") plt.ylabel("Y (um)") posx, posy = 50, 30 # reduce data: number of pixels to average in each detector direction