def test_plot_beta() : print """Test plot for beta angle""" import pyimgalgos.GlobalGraphics as gg xarr = np.linspace(-2,2,50) phi = 0 y0 = [funcy(x, phi, 0) for x in xarr] y1 = [funcy(x, phi, -2) for x in xarr] y2 = [funcy(x, phi, -5) for x in xarr] y3 = [funcy(x, phi, -6) for x in xarr] y4 = [funcy(x, phi, -7) for x in xarr] y5 = [funcy(x, phi, -10) for x in xarr] y6 = [funcy(x, phi, 2) for x in xarr] y7 = [funcy(x, phi, 5) for x in xarr] y8 = [funcy(x, phi, 10) for x in xarr] fig2, ax2 = gg.plotGraph(xarr, y0, figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80)) ax2.plot(xarr, y1,'r-') ax2.plot(xarr, y2,'y-') ax2.plot(xarr, y3,'b-') ax2.plot(xarr, y4,'m-') ax2.plot(xarr, y5,'g-') ax2.plot(xarr, y6,'r.') ax2.plot(xarr, y7,'g.') ax2.plot(xarr, y8,'b.') ax2.set_xlabel('x', fontsize=14) ax2.set_ylabel('y', fontsize=14) ax2.set_title('phi=0, theta=10, 5, 2, 0,-2,-5,-6,-7,-10', color='k', fontsize=20) #gg.savefig('variation-theta.png') gg.show()
def test_plot_phi() : print """Test plot for phi angle""" import pyimgalgos.GlobalGraphics as gg xarr = np.linspace(-2,2,50) tet = -12 y0 = [funcy(x, 0, tet) for x in xarr] y1 = [funcy(x, -5, tet) for x in xarr] y2 = [funcy(x, -6, tet) for x in xarr] y3 = [funcy(x, -7, tet) for x in xarr] y4 = [funcy(x, -10, tet) for x in xarr] y5 = [funcy(x, 10, tet) for x in xarr] fig1, ax1 = gg.plotGraph(xarr, y0, figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80)) ax1.plot(xarr, y1,'r-') ax1.plot(xarr, y2,'y-') ax1.plot(xarr, y3,'k-') ax1.plot(xarr, y4,'m-') ax1.plot(xarr, y5,'g.') ax1.set_xlabel('x', fontsize=14) ax1.set_ylabel('y', fontsize=14) ax1.set_title('tet=-12, phi=10,0,-5,-6,-7,-10', color='k', fontsize=20) #gg.savefig('variation-phi.png') gg.show()
def test_plot_beta_l0() : print """Test plot for beta angle""" import pyimgalgos.GlobalGraphics as gg xarr = np.linspace(-2,2,50) phi = 0 cmt = 'l0' y_000 = [funcy_l0(x, phi, 0) for x in xarr] y_p10 = [funcy_l0(x, phi, 10) for x in xarr] y_p20 = [funcy_l0(x, phi, 20) for x in xarr] y_p30 = [funcy_l0(x, phi, 30) for x in xarr] y_p40 = [funcy_l0(x, phi, 40) for x in xarr] y_p50 = [funcy_l0(x, phi, 50) for x in xarr] # 48 y_m10 = [funcy_l0(x, phi, -10) for x in xarr] y_m20 = [funcy_l0(x, phi, -20) for x in xarr] y_m30 = [funcy_l0(x, phi, -30) for x in xarr] y_m40 = [funcy_l0(x, phi, -40) for x in xarr] y_m50 = [funcy_l0(x, phi, -50) for x in xarr] # -48 #fig2, ax2 = gg.plotGraph(xarr, y_m01, pfmt='k.', figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80)) fig2, ax2 = gg.plotGraph(xarr, y_000, pfmt='k-', figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80), lw=2) #b: blue #g: green #r: red #c: cyan #m: magenta #y: yellow #k: black #w: white ax2.plot(xarr, y_p50,'g-x', label=' 50') ax2.plot(xarr, y_p40,'m-', label=' 40') ax2.plot(xarr, y_p30,'b-', label=' 30') ax2.plot(xarr, y_p20,'y-', label=' 20') ax2.plot(xarr, y_p10,'r-', label=' 10') ax2.plot(xarr, y_000,'k-', label=' 0') ax2.plot(xarr, y_m10,'r.', label='-10') ax2.plot(xarr, y_m20,'y.', label='-20') ax2.plot(xarr, y_m30,'b.', label='-30') ax2.plot(xarr, y_m40,'m.', label='-40') ax2.plot(xarr, y_m50,'g+', label='-50') ax2.legend(loc='upper right') ax2.set_xlabel('x', fontsize=14) ax2.set_ylabel('y', fontsize=14) ax2.set_title('%s: phi=%.1f, beta=[-50,50]' % (cmt,phi), color='k', fontsize=20) gg.savefig('test-plot-beta-l0.png') gg.show()
def test_plot_beta_l1(DoR=0.4292, sgnrt=1.) : print """Test plot for beta angle""" import pyimgalgos.GlobalGraphics as gg xarr = np.linspace(-2,2,50) phi = 0 fancy_plt = funcy_l1_v1 #fancy_plt = funcy_l1_v0 cmt = 'POS' if sgnrt > 0 else 'NEG' #'-B -/+ sqrt(B*B-C)' cmt = '%s-DoR-%.3f' % (cmt, DoR) y_p10 = [fancy_plt(x, phi, 10, DoR, sgnrt) for x in xarr] y_000 = [fancy_plt(x, phi, 0, DoR, sgnrt) for x in xarr] y_m10 = [fancy_plt(x, phi, -10, DoR, sgnrt) for x in xarr] y_m13 = [fancy_plt(x, phi, -13, DoR, sgnrt) for x in xarr] y_m15 = [fancy_plt(x, phi, -15, DoR, sgnrt) for x in xarr] y_m20 = [fancy_plt(x, phi, -20, DoR, sgnrt) for x in xarr] y_m30 = [fancy_plt(x, phi, -30, DoR, sgnrt) for x in xarr] y_m35 = [fancy_plt(x, phi, -35, DoR, sgnrt) for x in xarr] y_m40 = [fancy_plt(x, phi, -40, DoR, sgnrt) for x in xarr] fig2, ax2 = gg.plotGraph(xarr, y_000, pfmt='k-', figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80), lw=2) ax2.plot(xarr, y_p10,'g-', label=' 10') ax2.plot(xarr, y_000,'k-', label=' 0') ax2.plot(xarr, y_m10,'g.', label='-10') ax2.plot(xarr, y_m13,'r-.', label='-13') ax2.plot(xarr, y_m15,'y.', label='-14') ax2.plot(xarr, y_m20,'r.', label='-20') ax2.plot(xarr, y_m30,'c.', label='-30') ax2.plot(xarr, y_m35,'m.', label='-35') ax2.plot(xarr, y_m40,'b+', label='-40') ax2.legend(loc='upper right') ax2.set_title('%s: phi=%.1f, beta=[-40,10]' % (cmt,phi), color='k', fontsize=20) ax2.set_xlabel('x', fontsize=14) ax2.set_ylabel('y', fontsize=14) gg.savefig('test-plot-beta-l1-%s.png' % cmt) gg.show()
def test_plot_beta_l1_zoom(DoR=0.4292, sgnrt=1.) : print """Test plot for beta angle""" import pyimgalgos.GlobalGraphics as gg phi = 0 fancy_plt = funcy_l1_v1 #fancy_plt = funcy_l1_v0 if sgnrt > 0 : cmt = 'POS' #'-B -/+ sqrt(B*B-C)' cmt = '%s-DoR-%.3f' % (cmt, DoR) xarr = np.linspace(-0.29,0.29,60) y_000 = [fancy_plt(x, phi, 0, DoR, sgnrt) for x in xarr] y_m05 = [fancy_plt(x, phi, -5, DoR, sgnrt) for x in xarr] y_m09 = [fancy_plt(x, phi, -9, DoR, sgnrt) for x in xarr] y_m13 = [fancy_plt(x, phi, -13.3, DoR, sgnrt) for x in xarr] y_m18 = [fancy_plt(x, phi, -18, DoR, sgnrt) for x in xarr] y_m20 = [fancy_plt(x, phi, -20, DoR, sgnrt) for x in xarr] fig2, ax2 = gg.plotGraph(xarr, y_000, pfmt='k-', figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80), lw=2) ax2.plot(xarr, y_000,'k-', label=' 0') ax2.plot(xarr, y_m05,'g.', label=' -5') ax2.plot(xarr, y_m09,'y.', label=' -9') ax2.plot(xarr, y_m13,'r-.', label='-13') ax2.plot(xarr, y_m18,'c.', label='-18') ax2.plot(xarr, y_m20,'b.', label='-20') ax2.set_title('%s: phi=%.1f, beta=[-20,0]' % (cmt,phi), color='k', fontsize=20) ax2.legend(loc='upper center') if sgnrt < 0 : cmt = 'NEG' #'-B -/+ sqrt(B*B-C)' cmt = '%s-DoR-%.3f' % (cmt, DoR) xarr = np.linspace(-1,1,50) y_m20 = [fancy_plt(x, phi, -20, DoR, sgnrt) for x in xarr] y_m23 = [fancy_plt(x, phi, -23, DoR, sgnrt) for x in xarr] y_m25 = [fancy_plt(x, phi, -25, DoR, sgnrt) for x in xarr] y_m27 = [fancy_plt(x, phi, -27, DoR, sgnrt) for x in xarr] y_m30 = [fancy_plt(x, phi, -30, DoR, sgnrt) for x in xarr] y_m35 = [fancy_plt(x, phi, -35, DoR, sgnrt) for x in xarr] y_m40 = [fancy_plt(x, phi, -40, DoR, sgnrt) for x in xarr] y_m60 = [fancy_plt(x, phi, -60, DoR, sgnrt) for x in xarr] fig2, ax2 = gg.plotGraph(xarr, y_m25, pfmt='k-', figsize=(10,5), window=(0.15, 0.10, 0.78, 0.80), lw=2) ax2.plot(xarr, y_m20,'g+-', label='-20') ax2.plot(xarr, y_m23,'m-', label='-23') ax2.plot(xarr, y_m25,'k-', label='-25') ax2.plot(xarr, y_m27,'b.', label='-27') ax2.plot(xarr, y_m30,'y.', label='-30') ax2.plot(xarr, y_m35,'r.', label='-35') ax2.plot(xarr, y_m40,'c.', label='-40') ax2.plot(xarr, y_m60,'+', label='-60') ax2.set_title('%s: phi=%.1f, beta=[-60,-20]' % (cmt,phi), color='k', fontsize=20) ax2.legend(loc='lower right') ax2.set_xlabel('x', fontsize=14) ax2.set_ylabel('y', fontsize=14) gg.savefig('test-plot-beta-l1-%s-zoomed.png' % cmt) 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,\ hmin=None, kmin=None, lmin=None, title_add='') : """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 pyimgalgos.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, hmin, kmin, lmin) x.shape = (x.size,) y.shape = (y.size,) z.shape = (z.size,) 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.17, 0.10, 0.78, 0.84), 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,11,10) #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, qt, ql = q_components(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') tit = 'beta=%.0f omega=%.0f' % (beta_deg, omega_deg) if title_add : tit += ' %s' % (title_add) ax.set_title(tit, color='k', fontsize=12) 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, '%slattice-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 %slattice-rotated-beta*.png movie.gif' % (delay, prefix) print 'Wait for completion of the command: %s' % cmd os.system(cmd) print 'DONE!' gg.show()