Example #1
0
 def test_maplogzero(self):
     d = numpy.array((0, 1))
     # make function call with a zero and negative number
     dm = xu.maplog(d)
     self.assertAlmostEqual(d.max()/10.0**self.dmax,
                            10.0**dm.max(), places=10)
     self.assertAlmostEqual(d.max()/10.0**self.dmin,
                            10**dm.min(), places=10)
     # call with negative number
     d[0] = -1
     dm = xu.maplog(d)
     self.assertAlmostEqual(d.max()/10.0**self.dmax,
                            10.0**dm.max(), places=10)
     self.assertAlmostEqual(d.max()/10.0**self.dmin,
                            10**dm.min(), places=10)
Example #2
0
 def drawReciprocalMap_Q(self):
     [qx,qy,qz] = self.hxrd.Ang2Q(self.omega,self.ttheta,delta=[0.0, 0.0])
     
     gridder = xu.Gridder2D(100,100)
     gridder(qy,qz, self.intensity)
     INT = xu.maplog(gridder.data.transpose(),6,0)
     
     #clear axes from previous drawing
     self.axes.cla()
     #draw rsm
     cf = self.axes.contourf(gridder.xaxis, gridder.yaxis,INT,100,extend='min')
     #draw center
     self.axes.scatter(self.Q0x, self.Q0z, s = 100, marker = 'x', c = 'w')
     
     #annotate axis
     self.axes.set_xlabel(r'$Q_{[110]}$ ($\AA^{-1}$)')
     self.axes.set_ylabel(r'$Q_{[001]}$ ($\AA^{-1}$)')
     
     # update colorbar
     if not self.colorbar:
         self.colorbar = self.figure.colorbar(cf, ax = self.axes)
     else:
         self.colorbar.update_normal(cf)
         self.colorbar.draw_all()
     #redraw figure
     self.figure.canvas.draw()
Example #3
0
 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
Example #4
0
 def drawReciprocalMap_q(self):
     qx, qz = self.get_q()
     
     gridder = xu.Gridder2D(100,100)
     gridder(qx, qz, self.intensity)
     INT = xu.maplog(gridder.data.transpose(),6,0)
     
     #clear axes from previous drawing
     self.axes.cla()
     #draw rsm
     cf = self.axes.contourf(gridder.xaxis, gridder.yaxis,INT,100,extend='min')
     #draw center, in this mode center is always at zero point
     self.axes.scatter(0, 0, s = 100, marker = 'x', c = 'w')
     
     #annotate axis
     self.axes.set_xlabel(r'$q_{[110]}$ ($\AA^{-1}$)')
     self.axes.set_ylabel(r'$q_{[001]}$ ($\AA^{-1}$)')
     
     if not self.colorbar:
         self.colorbar = self.figure.colorbar(cf, ax = self.axes)
     else:
         self.colorbar.update_normal(cf)
         self.colorbar.draw_all()
     #draw figure
     self.figure.canvas.draw()
Example #5
0
    def drawAngularMap(self):
        gridder = xu.Gridder2D(150,150)
        gridder(self.omega, self.ttheta, self.intensity)
        INT = xu.maplog(gridder.data.transpose(),6,0)

        #clear axes from previous drawing
        self.axes.cla()
        #draw rsm
        cf = self.axes.contourf(gridder.xaxis, gridder.yaxis,INT,100,extend='min')
        #draw center
        self.axes.scatter(self.omega0, self.ttheta0, s = 100, marker = 'x', c = 'w')
        #annotate axes
        self.axes.set_xlabel(r'$\omega$ (deg)')
        self.axes.set_ylabel(r'$2\theta$ (deg)')
        # update colorbar
        if not self.colorbar:
            self.colorbar = self.figure.colorbar(cf, ax = self.axes)
        else:
            #TODO setup user defined values for cmin and cmax
            #self.colorbar.set_clim(-10, 20)
            
            self.colorbar.update_normal(cf)
            self.colorbar.draw_all()
        #redraw figure
        self.figure.canvas.draw()
Example #6
0
 def test_maplog(self):
     d = numpy.logspace(1, 6, 100)
     # make noop
     dm = xu.maplog(d, numpy.inf, -numpy.inf)
     self.assertTrue(numpy.all(numpy.log10(d) == dm))
     # cut bottom
     dl = 3
     dm = xu.maplog(d, dl, -numpy.inf)
     dl = min(dl, self.dmin)
     self.assertAlmostEqual(d.max(), 10.0**dm.max(), places=10)
     self.assertAlmostEqual(d.max()/10.0**dl, 10**dm.min(), places=10)
     # cut top
     dt = 2
     dm = xu.maplog(d, numpy.inf, dt)
     dt = max(dt, self.dmax)
     self.assertAlmostEqual(d.min(), 10.0**dm.min(), places=10)
     self.assertAlmostEqual(d.max()/10.0**dt, 10.0**dm.max(), places=10)
Example #7
0
 def test_maplog(self):
     d = numpy.logspace(1, 6, 100)
     # make noop
     dm = xu.maplog(d, numpy.inf, -numpy.inf)
     self.assertTrue(numpy.all(numpy.log10(d) == dm))
     # cut bottom
     dl = 3
     dm = xu.maplog(d, dl, -numpy.inf)
     dl = min(dl, self.dmin)
     self.assertAlmostEqual(d.max(), 10.0**dm.max(), places=10)
     self.assertAlmostEqual(d.max() / 10.0**dl, 10**dm.min(), places=10)
     # cut top
     dt = 2
     dm = xu.maplog(d, numpy.inf, dt)
     dt = max(dt, self.dmax)
     self.assertAlmostEqual(d.min(), 10.0**dm.min(), places=10)
     self.assertAlmostEqual(d.max() / 10.0**dt, 10.0**dm.max(), places=10)
Example #8
0
 def test_maplogzero(self):
     d = numpy.array((0, 1))
     # make function call with a zero and negative number
     dm = xu.maplog(d)
     self.assertAlmostEqual(d.max() / 10.0**self.dmax,
                            10.0**dm.max(),
                            places=10)
     self.assertAlmostEqual(d.max() / 10.0**self.dmin,
                            10**dm.min(),
                            places=10)
     # call with negative number
     d[0] = -1
     dm = xu.maplog(d)
     self.assertAlmostEqual(d.max() / 10.0**self.dmax,
                            10.0**dm.max(),
                            places=10)
     self.assertAlmostEqual(d.max() / 10.0**self.dmin,
                            10**dm.min(),
                            places=10)
Example #9
0
    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
Example #10
0
    def set_gridder_resolution(self, nx, ny):

        # update gridder
        self.gridder.SetResolution(nx, ny)

        # regrid data
        self.gridder(self.Qx_data, self.Qz_data, self.Int_data)
        LOGINT = xu.maplog(self.gridder.data.transpose(), 6, 0)

        # draw rsm
        cmin, cmax = self.cs.get_clim()
        self.cs = self.contourf(self.gridder.xaxis, self.gridder.yaxis, LOGINT, 25, extend="min")
        self.cs.set_clim(cmin, cmax)
Example #11
0
    def rsm(self, qx, qz, intensity):
        self.Qx_data = qx
        self.Qz_data = qz
        self.Int_data = intensity

        self.gridder(self.Qx_data, self.Qz_data, self.Int_data)
        LOGINT = xu.maplog(self.gridder.data.transpose(), 6, 0)

        # draw rsm
        self.cs = self.contourf(self.gridder.xaxis, self.gridder.yaxis, LOGINT, 25, extend="min")

        # annotate axis
        self.set_xlabel(r"$Q_{x}$")
        self.set_ylabel(r"$Q_{z}$")
Example #12
0
              str('{:.2f}'.format(qyCOM)), str('{:.2f}'.format(qzCOM)), ']')
    else:  # "max"
        z0, y0, x0 = np.unravel_index(abs(data).argmax(),
                                      data.shape)  # Nexus convention
        qxCOM = qx[z0]
        qzCOM = qz[y0]
        qyCOM = qy[x0]
        print("Max [qx, qy, qz]: [", str('{:.2f}'.format(qxCOM)),
              str('{:.2f}'.format(qyCOM)), str('{:.2f}'.format(qzCOM)), ']')
else:
    print("User defined Bragg peak: [", str('{:.2f}'.format(qxCOM)),
          str('{:.2f}'.format(qyCOM)), str('{:.2f}'.format(qzCOM)), ']')

if plot_2D == 1:
    _, ax0 = plt.subplots(1, 1)
    plt.contourf(qz, qx, xu.maplog(intensity.sum(axis=2)), 150, cmap=my_cmap)
    ax0.tick_params(labelbottom='off',
                    labelleft='off',
                    bottom='off',
                    top='off',
                    left='off',
                    right='off',
                    direction=tick_direction,
                    length=tick_length,
                    width=tick_width)
    plt.savefig(savedir + 'QzQx' + comment + '.png', bbox_inches="tight")
    ax0.tick_params(labelbottom='on',
                    labelleft='on',
                    bottom='on',
                    top='off',
                    left='on',
Example #13
0
    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
                                                      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()

# line cut with integration along 2theta to remove beam footprint broadening
qycpos, qzcpos = [0, 4.5]
    InP.Q(3, 3, 3))  # nominal values of the substrate peak

# 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)")
# except NameError: s = xu.io.SPECFile(sample+".spec",path=specdir)
# else:
#    s.Update()
# s.Save2HDF5(h5file)
# in ipython run with: "run -i script" to just update the spec file and parse
# for new scans only

# number of points to be used during the gridding
nx, ny, nz = 100, 101, 102

# read and grid data with helper function
qx, qy, qz, gint, gridder = id01.gridmap(h5file, SCANNR, ccdfiletmp,
                                         nx, ny, nz)

# prepare data for export to VTK image file
INT = xu.maplog(gint, 3.0, 0)

# export variables qx, qy, qz, INT
qx0 = qx.min()
dqx = (qx.max() - qx.min()) / nx

qy0 = qy.min()
dqy = (qy.max() - qy.min()) / ny

qz0 = qz.min()
dqz = (qz.max() - qz.min()) / nz

INT = numpy.transpose(INT).reshape((INT.size))
data_array = numpy_support.numpy_to_vtk(INT)

image_data = vtk.vtkImageData()
    r'$(\bar 1\bar 1 3)$',
    r'$(\bar 1 3\bar 1)$',
    r'$( 3\bar 1\bar 1)$')

df = xu.io.XRDMLFile(os.path.join(datadir, "polefig_Ge113.xrdml.bz2"))
s = df.scan

chi = 90 - s['Psi']
phi = s['Phi']
INT = s['detector']

# create 2D arrays for the angles
CHI = chi[:, numpy.newaxis] * numpy.ones(INT.shape)
PHI = phi

INT = xu.maplog(INT, 6, 0)

fig = plt.figure()
plt.clf()
# plt.title("(113) pole figure")
m = Basemap(boundinglat=-1., lon_0=180.0, resolution=None,
            projection='npstere')
X, Y = m(PHI, CHI)
ax = plt.subplot(111)
ax.set_frame_on(False)
CS = m.contourf(X, Y, INT, 50)
m.drawparallels(numpy.arange(0, 91, 10), labels=[1, 1, 1, 1],
                color='gray', dashes=[2, 2])
m.drawmeridians(numpy.arange(0, 360, 60), labels=[1, 1, 1, 1],
                color='gray', labelstyle='+/-', dashes=[2, 2])
                                                      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)
omalign = 59.550  # experimental aligned values
ttalign = 80.099
psdraw = normalizer_detcorr(MAP)
# remove unusable detector channels/regions (no averaging of detector channels)
psd = xu.blockAveragePSD(psdraw, 1, roi=roi)

# 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.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)
omalign = 59.550  # experimental aligned values
[omnominal, dummy, dummy, ttnominal] = hxrd.Q2Ang(Si.Q(0, 0, 4))

# read the data from the xrdml files
om, tt, psd = xu.io.getxrdml_map(sample + '_%d.xrdml.bz2', [1, 2, 3, 4, 5],
                                 path='data')

# 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()
plt.clf()
cf = plt.contourf(gridder.xaxis, gridder.yaxis, INT, 100, extend='min')
plt.xlabel(r'$Q_{[110]}$ ($\AA^{-1}$)')
plt.ylabel(r'$Q_{[001]}$ ($\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], 'ko')
Example #21
0
# mask_top[np.where((volume_R_top < (radius_mean+dr)) & (volume_R_top > (radius_mean-dr)))] = 1
mask_top = np.logical_and((distances_top < (radius_mean + dr)),
                          (distances_top > (radius_mean - dr)))
mask_bottom = np.logical_and((distances_bottom < (radius_mean + dr)),
                             (distances_bottom > (radius_mean - dr)))

############################
# plot 2D maps
############################
fig, ax = plt.subplots(num=1,
                       figsize=(20, 15),
                       dpi=80,
                       facecolor='w',
                       edgecolor='k')
plt.subplot(2, 2, 1)
plt.contourf(qz, qx, xu.maplog(data.sum(axis=2)), 150, cmap=my_cmap)
plt.plot([min(qz), max(qz)], [qxCOM, qxCOM],
         color='k',
         linestyle='-',
         linewidth=2)
plt.plot([qzCOM, qzCOM], [min(qx), max(qx)],
         color='k',
         linestyle='-',
         linewidth=2)
circle = plt.Circle((qzCOM, qxCOM),
                    radius_mean + dr,
                    color='0',
                    fill=False,
                    linestyle='dotted')
fig.gca().add_artist(circle)
circle = plt.Circle((qzCOM, qxCOM),
Example #22
0
# 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)")
# one of the following import statements is needed
# depending on the system/distribution you use
# from mayavi import mlab
# from enthough.mayavi import mlab
# plot 3D map using mayavi mlab
# QX,QY,QZ = numpy.mgrid[qx.min():qx.max():1j * nx,
#                        qy.min():qy.max():1j * ny,
#                        qz.min():qz.max():1j*nz]
# INT = xu.maplog(gint,4.5,0)
# mlab.figure()
# mlab.contour3d(QX, QY, QZ, INT, contours=15, opacity=0.5)
# mlab.colorbar(title="log(int)", orientation="vertical")
# mlab.axes(nb_labels=5, xlabel='Qx', ylabel='Qy', zlabel='Qz')
# mlab.close(all=True)
############################################

# plot 2D sums using matplotlib
plt.figure()
plt.contourf(qx, qy, xu.maplog(gint.sum(axis=2), 2.8, 1.5).T, 50)
plt.xlabel(r"QX ($1/\AA$)")
plt.ylabel(r"QY ($1/\AA$)")
plt.colorbar()
# plt.savefig(os.path.join("pics","filename.png"))

# plot 2D slice using matplotlib
plt.figure()
plt.contourf(qx, qy, xu.maplog(gint[:, :, 81:89].sum(axis=2), 3.75, 0).T, 50)
plt.xlabel(r"QX ($1/\AA$)")
plt.ylabel(r"QY ($1/\AA$)")
plt.colorbar()
# except NameError: s = xu.io.SPECFile(sample+".spec",path=specdir)
# else:
#    s.Update()
# s.Save2HDF5(h5file)
# in ipython run with: "run -i script" to just update the spec file and parse
# for new scans only

# number of points to be used during the gridding
nx, ny, nz = 100, 101, 102

# read and grid data with helper function
qx, qy, qz, gint, gridder = id01.gridmap(h5file, SCANNR, ccdfiletmp, nx, ny,
                                         nz)

# prepare data for export to VTK image file
INT = xu.maplog(gint, 3.0, 0)

# export variables qx, qy, qz, INT
qx0 = qx.min()
dqx = (qx.max() - qx.min()) / nx

qy0 = qy.min()
dqy = (qy.max() - qy.min()) / ny

qz0 = qz.min()
dqz = (qz.max() - qz.min()) / nz

INT = numpy.transpose(INT).reshape((INT.size))
data_array = numpy_support.numpy_to_vtk(INT)

image_data = vtk.vtkImageData()
Example #25
0
# one of the following import statements is needed
# depending on the system/distribution you use
# from mayavi import mlab
# # from enthough.mayavi import mlab
# # plot 3D map using mayavi mlab
# QX,QY,QZ = numpy.mgrid[qx.min():qx.max():1j * nx,
#                        qy.min():qy.max():1j * ny,
#                        qz.min():qz.max():1j * nz]
# INT = xu.maplog(gint,4.5,0)
# mlab.figure()
# mlab.contour3d(QX, QY, QZ, INT, contours=15, opacity=0.5)
# mlab.colorbar(title="log(int)", orientation="vertical")
# mlab.axes(nb_labels=5, xlabel='Qx', ylabel='Qy', zlabel='Qz')
# # mlab.close(all=True)
############################################

# plot 2D sums using matplotlib
plt.figure()
plt.contourf(qx, qy, xu.maplog(gint.sum(axis=2), 2.8, 1.5).T, 50)
plt.xlabel(r"QX ($1/\mathrm{\AA}$)")
plt.ylabel(r"QY ($1/\mathrm{\AA}$)")
plt.colorbar()
# plt.savefig(os.path.join("pics","filename.png"))

# plot 2D slice using matplotlib
plt.figure()
plt.contourf(qx, qy, xu.maplog(gint[:, :, 81:89].sum(axis=2), 3.75, 0).T, 50)
plt.xlabel(r"QX ($1/\mathrm{\AA}$)")
plt.ylabel(r"QY ($1/\mathrm{\AA}$)")
plt.colorbar()