def test_plot_cspad(geometry, fname_data, amp_range=(0, 0.5)): """ The same test as previous, but use get_pixel_coord_indexes(...) method """ #rad1 = 93 #rad2 = 146 rad1 = 655 rad2 = 670 # get pixel coordinate index arrays: xc, yc = 1000, 1000 xyc = xc, yc # None #iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=None) iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=xyc, do_tilt=True) ixo, iyo = geometry.point_coord_indexes(xy0_off_pix=xyc, do_tilt=True) print 'Detector origin indexes ixo, iyo:', ixo, iyo root, ext = os.path.splitext(fname_data) arr = np.load(fname_data) if ext == '.npy' else np.loadtxt(fname_data, dtype=np.float) arr.shape = (4, 8, 185, 388) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape arr.shape = iX.shape img = img_from_pixel_arrays(iX, iY, W=arr) xyc_ring = (yc, xc) axim = gg.plotImageLarge(img, amp_range=amp_range) gg.drawCircle(axim, xyc_ring, rad1, linewidth=1, color='w', fill=False) gg.drawCircle(axim, xyc_ring, rad2, linewidth=1, color='w', fill=False) gg.drawCenter(axim, xyc_ring, rad1, linewidth=1, color='w') gg.move(500, 10) gg.show()
def test_plot_cspad(geometry, fname_data, amp_range=(0,0.5)) : """ The same test as previous, but use get_pixel_coord_indexes(...) method """ #rad1 = 93 #rad2 = 146 rad1 = 655 rad2 = 670 # get pixel coordinate index arrays: xc, yc = 1000, 1000 xyc = xc, yc # None #iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=None) iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=xyc, do_tilt=True) ixo, iyo = geometry.point_coord_indexes(xy0_off_pix=xyc, do_tilt=True) print 'Detector origin indexes ixo, iyo:', ixo, iyo root, ext = os.path.splitext(fname_data) arr = np.load(fname_data) if ext == '.npy' else np.loadtxt(fname_data, dtype=np.float) arr.shape= (4,8,185,388) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape arr.shape = iX.shape img = img_from_pixel_arrays(iX, iY, W=arr) xyc_ring = (yc, xc) axim = gg.plotImageLarge(img,amp_range=amp_range) gg.drawCircle(axim, xyc_ring, rad1, linewidth=1, color='w', fill=False) gg.drawCircle(axim, xyc_ring, rad2, linewidth=1, color='w', fill=False) gg.drawCenter(axim, xyc_ring, rad1, linewidth=1, color='w') gg.move(500,10) gg.show()
def plot_lattice(b1 = (1.,0.,0.), b2 = (0.,1.,0.), b3 = (0.,0.,1.),\ hmax=3, kmax=2, lmax=1, cdtype=np.float32,\ evald_rad=0.5, qtol=0.01, prefix='', do_movie=False, delay=400) : """Plots 2-d reciprocal space lattice, evald sphere, generates series of plots for rotated lattice and movie from these plots. - do_movie = True/False - on/off production of movie - delay - is a time in msec between movie frames. """ import matplotlib.pyplot as plt import algos.graph.GlobalGraphics as gg print '\nIn %s' % sys._getframe().f_code.co_name print '%s\nTest lattice with default parameters' % (80*'_') x, y, z, r, h, k, l = lattice(b1, b2, b3, hmax, kmax, lmax, cdtype) xlimits = ylimits = (-0.3, 0.3) # plot limits in (1/A) #ylimits = (-0.4, 0.4) # plot limits in (1/A) #xlimits = (-0.5, 0.3) # plot limits in (1/A) fig, ax = gg.plotGraph(x,y, figsize=(8,7.5), window=(0.15, 0.10, 0.78, 0.86), pfmt='bo') ax.set_xlim(xlimits) ax.set_ylim(ylimits) ax.set_xlabel('Reciprocal x ($1/\AA$)', fontsize=18) ax.set_ylabel('Reciprocal y ($1/\AA$)', fontsize=18) gg.save_fig(fig, '%sreciprocal-space-lattice.png' % prefix, pbits=1) lst_omega = range(0,180,2) if do_movie else range(0,13,11) #lst_omega = range(0,180,5) if do_movie else range(0,13,11) #lst_omega = range(0,180,45) if do_movie else range(0,13,11) beta_deg = 0 for omega_deg in lst_omega : xrot1, yrot1 = rotation(x, y, omega_deg) xrot2, zrot2 = rotation(xrot1, z, beta_deg) dr, qv, qh = radial_distance(xrot2, yrot1, zrot2, evald_rad) xhit = [xr for dq,xr in zip(dr.flatten(), xrot2.flatten()) if math.fabs(dq)<qtol] yhit = [yr for dq,yr in zip(dr.flatten(), yrot1.flatten()) if math.fabs(dq)<qtol] #fig, ax = gg.plotGraph(xrot2, yrot1, figsize=(8,7.5), window=(0.15, 0.10, 0.78, 0.84), pfmt='bo') ax.cla() ax.set_xlim(xlimits) ax.set_ylim(ylimits) ax.plot(xrot1, yrot1, 'yo') if len(xhit)>0 and len(yhit)>0 : ax.plot(xhit, yhit, 'bo') ax.set_title('beta=%.0f omega=%.0f' % (beta_deg, omega_deg), color='k', fontsize=20) ax.set_xlabel('Reciprocal x ($1/\AA$)', fontsize=18) ax.set_ylabel('Reciprocal y ($1/\AA$)', fontsize=18) gg.drawCenter(ax, (-evald_rad,0), s=0.04, linewidth=2, color='k') gg.drawCircle(ax, (-evald_rad,0), evald_rad, linewidth=1, color='k', fill=False) fig.canvas.draw() gg.show('Do not hold!') gg.save_fig(fig, '%sreciprocal-space-lattice-rotated-beta=%03d-omega=%03d.png'%\ (prefix, int(beta_deg), int(omega_deg)), pbits=1) if do_movie : import os #dir_movie = 'movie' #os.system('mkdir %s'% dir_movie) cmd = 'convert -delay %f %sreciprocal-space-lattice-rotated-beta=*.png movie.gif' % (delay, prefix) print 'Wait for completion of the command: %s' % cmd os.system(cmd) print 'DONE!' gg.show()
def plot_lattice(b1 = (1.,0.,0.), b2 = (0.,1.,0.), b3 = (0.,0.,1.),\ hmax=3, kmax=2, lmax=1, cdtype=np.float32,\ evald_rad=0.5, qtol=0.01, prefix='', do_movie=False, delay=400) : """Plots 2-d reciprocal space lattice, evald sphere, generates series of plots for rotated lattice and movie from these plots. - do_movie = True/False - on/off production of movie - delay - is a time in msec between movie frames. """ import matplotlib.pyplot as plt import algos.graph.GlobalGraphics as gg print '\nIn %s' % sys._getframe().f_code.co_name print '%s\nTest lattice with default parameters' % (80 * '_') x, y, z, r, h, k, l = lattice(b1, b2, b3, hmax, kmax, lmax, cdtype) xlimits = ylimits = (-0.3, 0.3) # plot limits in (1/A) #ylimits = (-0.4, 0.4) # plot limits in (1/A) #xlimits = (-0.5, 0.3) # plot limits in (1/A) fig, ax = gg.plotGraph(x, y, figsize=(8, 7.5), window=(0.15, 0.10, 0.78, 0.86), pfmt='bo') ax.set_xlim(xlimits) ax.set_ylim(ylimits) ax.set_xlabel('Reciprocal x ($1/\AA$)', fontsize=18) ax.set_ylabel('Reciprocal y ($1/\AA$)', fontsize=18) gg.save_fig(fig, '%sreciprocal-space-lattice.png' % prefix, pbits=1) lst_omega = range(0, 180, 2) if do_movie else range(0, 13, 11) #lst_omega = range(0,180,5) if do_movie else range(0,13,11) #lst_omega = range(0,180,45) if do_movie else range(0,13,11) beta_deg = 0 for omega_deg in lst_omega: xrot1, yrot1 = rotation(x, y, omega_deg) xrot2, zrot2 = rotation(xrot1, z, beta_deg) dr, qv, qh = radial_distance(xrot2, yrot1, zrot2, evald_rad) xhit = [ xr for dq, xr in zip(dr.flatten(), xrot2.flatten()) if math.fabs(dq) < qtol ] yhit = [ yr for dq, yr in zip(dr.flatten(), yrot1.flatten()) if math.fabs(dq) < qtol ] #fig, ax = gg.plotGraph(xrot2, yrot1, figsize=(8,7.5), window=(0.15, 0.10, 0.78, 0.84), pfmt='bo') ax.cla() ax.set_xlim(xlimits) ax.set_ylim(ylimits) ax.plot(xrot1, yrot1, 'yo') if len(xhit) > 0 and len(yhit) > 0: ax.plot(xhit, yhit, 'bo') ax.set_title('beta=%.0f omega=%.0f' % (beta_deg, omega_deg), color='k', fontsize=20) ax.set_xlabel('Reciprocal x ($1/\AA$)', fontsize=18) ax.set_ylabel('Reciprocal y ($1/\AA$)', fontsize=18) gg.drawCenter(ax, (-evald_rad, 0), s=0.04, linewidth=2, color='k') gg.drawCircle(ax, (-evald_rad, 0), evald_rad, linewidth=1, color='k', fill=False) fig.canvas.draw() gg.show('Do not hold!') gg.save_fig(fig, '%sreciprocal-space-lattice-rotated-beta=%03d-omega=%03d.png'%\ (prefix, int(beta_deg), int(omega_deg)), pbits=1) if do_movie: import os #dir_movie = 'movie' #os.system('mkdir %s'% dir_movie) cmd = 'convert -delay %f %sreciprocal-space-lattice-rotated-beta=*.png movie.gif' % ( delay, prefix) print 'Wait for completion of the command: %s' % cmd os.system(cmd) print 'DONE!' gg.show()