def make_index_table(prefix='./v01-') : from pyimgalgos.GlobalUtils import str_tstamp fname = '%s**t-cxif5315-r0169-%s.txt' % (prefix, str_tstamp()) fout = open(fname,'w') fout.write('# file name: %s\n' % fname) #------------------------------ # Photon energy Egamma_eV = 6003.1936 # eV SIOC:SYS0:ML00:AO541 wavelen_nm = wavelength_nm_from_energy_ev(Egamma_eV) # nm evald_rad = wave_vector_value(Egamma_eV) # 1/A #------- sigma_ql = 0.002 * evald_rad sigma_qt = 0.002 * evald_rad #------- rec = '\n# photon energy = %.4f eV' % (Egamma_eV)\ + '\n# wavelength = %.4f A' % (wavelen_nm*10)\ + '\n# wave number/Evald radius k = 1/lambda = %.6f 1/A' % (evald_rad)\ + '\n# sigma_ql = %.6f 1/A (approximately = k * <pixel size>/' % (sigma_ql)\ + '\n# sigma_qt = %.6f 1/A (approximately = k * <pixel size>/' % (sigma_qt)\ + '<sample-to-detector distance> = k*100um/100mm)'\ + '\n# 3*sigma_ql = %.6f 1/A\n' % (3*sigma_ql)\ + '\n# 3*sigma_qt = %.6f 1/A\n' % (3*sigma_qt) print rec fout.write(rec) #------------------------------ # Lattice parameters # from previous analysis note: #a, b, c = 18.36, 26.65, 4.81 # Angstrom #alpha, beta, gamma = 90, 90, 77.17 # 180 - 102.83 degree a= 18.55 # Angstrom b, c = 1.466*a, 0.262*a # Angstrom alpha, beta, gamma = 90, 90, 78.47 # 180 - 101.53 degree hmax, kmax, lmax = 4, 6, 0 # size of lattice to consider #hmin, kmin, lmin =-4,-6, 0 # size of lattice to consider hmin, kmin, lmin = None, None, None # default [-hmax,hmax], [-kmax,kmax], a1, a2, a3 = triclinic_primitive_vectors(a, b, c, alpha, beta, gamma) b1, b2, b3 = reciprocal_from_bravias(a1, a2, a3) msg1 = '\n# Triclinic crystal cell parameters:'\ + '\n# a = %.2f A\n# b = %.2f A\n# c = %.2f A' % (a, b, c)\ + '\n# alpha = %.2f deg\n# beta = %.2f deg\n# gamma = %.2f deg' % (alpha, beta, gamma) msg2 = '\n# 3-d space primitive vectors:\n# a1 = %s\n# a2 = %s\n# a3 = %s' %\ (str(a1), str(a2), str(a3)) msg3 = '\n# reciprocal space primitive vectors:\n# b1 = %s\n# b2 = %s\n# b3 = %s' %\ (str(b1), str(b2), str(b3)) rec = '%s\n%s\n%s\n' % (msg1, msg2, msg3) print rec fout.write(rec) fout.write('\n# %s\n\n' % (89*'_')) #for line in triclinic_primitive_vectors.__doc__.split('\n') : fout.write('\n# %s' % line) test_lattice (b1, b2, b3, hmax, kmax, lmax, np.float32, hmin, kmin, lmin) lattice_node_radius(b1, b2, b3, hmax, kmax, lmax, np.float32, '%10.6f', hmin, kmin, lmin) lattice_node_radius(b1, b2, b3, hmax, kmax, 1, np.float32, '%10.6f', hmin, kmin, lmin) #------------------------------ #return #------------------------------ # binning for look-up table and plots # bin parameters for q in units of k = Evald's sphere radius [1/A] bpq = BinPars((-0.25, 0.25), 1000, vtype=np.float32, endpoint=False) # bin parameters for omega [degree] - fiber rotation angle around axis bpomega = BinPars((0., 180.), 360, vtype=np.float32, endpoint=False) # bin parameters for beta [degree] - fiber axis tilt angle #bpbeta = BinPars((15., 195.), 2, vtype=np.float32, endpoint=True) #bpbeta = BinPars((15., 15.), 1, vtype=np.float32, endpoint=False) #bpbeta = BinPars((5., 25.), 2, vtype=np.float32, endpoint=True) bpbeta = BinPars((0., 50.), 11, vtype=np.float32, endpoint=True) bpbeta2 = BinPars((180., 230.), 11, vtype=np.float32, endpoint=True) str_beta = 'for-beta:%s' % (bpbeta.strrange) print '\n%s\nIndexing lookup table\n' % (91*'_') lut = make_lookup_table_v2(b1, b2, b3, hmax, kmax, lmax, np.float32, evald_rad, sigma_ql, sigma_qt, fout, bpq, bpomega, bpbeta, hmin, kmin, lmin) lut2 = make_lookup_table_v2(b1, b2, b3, hmax, kmax, lmax, np.float32, evald_rad, sigma_ql, sigma_qt, fout, bpq, bpomega, bpbeta2, hmin, kmin, lmin) fout.close() print '\nIndexing lookup table is saved in the file: %s' % fname #------------------------------ # produce and save plots import pyimgalgos.GlobalGraphics as gg img = lut # or lut2 img = lut + lut2 img_range = (bpq.vmin, bpq.vmax, bpomega.vmax, bpomega.vmin) axim = gg.plotImageLarge(lut, img_range=img_range, amp_range=None, figsize=(15,13),\ title='Non-symmetrized for beta', origin='upper', window=(0.05, 0.06, 0.94, 0.94)) axim.set_xlabel('$q_{H}$ ($1/\AA$)', fontsize=18) axim.set_ylabel('$\omega$ (degree)', fontsize=18) gg.save('%splot-img-prob-omega-vs-qh-%s.png' % (prefix, str_beta), pbits=1) axim = gg.plotImageLarge(img, img_range=img_range, amp_range=None, figsize=(15,13),\ title='Symmetrized for beta (beta, beta+pi)', origin='upper', window=(0.05, 0.06, 0.94, 0.94)) axim.set_xlabel('$q_{H}$ ($1/\AA$)', fontsize=18) axim.set_ylabel('$\omega$ (degree)', fontsize=18) gg.save('%splot-img-prob-omega-vs-qh-sym-%s.png' % (prefix, str_beta), pbits=1) arrhi = np.sum(img,0) fighi, axhi, hi = gg.hist1d(bpq.binedges, bins=bpq.nbins-1, amp_range=(bpq.vmin, bpq.vmax), weights=arrhi,\ color='b', show_stat=True, log=False,\ figsize=(15,5), axwin=(0.05, 0.12, 0.85, 0.80),\ title=None, xlabel='$q_{H}$ ($1/\AA$)', ylabel='Intensity', titwin=None) gg.show() gg.save_fig(fighi, '%splot-his-prob-vs-qh-%s.png' % (prefix, str_beta), pbits=1) qh_weight = zip(bpq.bincenters, arrhi) fname = '%sarr-qh-weight-%s.npy' % (prefix, str_beta) print 'Save qh:weigt array in file %s' % fname np.save(fname, qh_weight)
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()