def test_plot_phi() : print """Test plot for phi angle""" import algos.graph.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_cspad2x2() : """ Test cspad2x2 geometry table """ ## MecTargetChamber.0:Cspad2x2.1 basedir = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-01-2013-02-13/' fname_geometry = basedir + 'calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.1/geometry/0-end.data' fname_data = basedir + 'cspad2x2.1-ndarr-ave-meca6113-r0028.dat' ## MecTargetChamber.0:Cspad2x2.2 #basedir = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-02-2013-02-13/' #fname_geometry = basedir + 'calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.2/geometry/0-end.data' #fname_data = basedir + 'cspad2x2.2-ndarr-ave-meca6113-r0028.dat' geometry = GeometryAccess(fname_geometry, 0377) amp_range = (0,15000) # get pixel coordinate index arrays: #xyc = xc, yc = 1000, 1000 #iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=xyc) iX, iY = geometry.get_pixel_coord_indexes(do_tilt=True) 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= (185,388,2) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX,iY,W=arr) axim = gg.plotImageLarge(img,amp_range=amp_range) 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 test_cspad_xy_at_z() : """ Test cspad geometry table """ ## 'CxiDs1.0:Cspad.0)' or 'DscCsPad' basedir = '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera1-2014-09-24/' fname_geometry = basedir + '2016-06-03-geometry-cxi06216-r25-camera1-z175mm.txt' fname_data = basedir + '2016-06-03-chun-cxi06216-0025-DscCsPad-max.txt' geometry = GeometryAccess(fname_geometry, 0377) # get pixel coordinate index arrays: xyc = xc, yc = 1000, 1000 #iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=xyc) #iX, iY = geometry.get_pixel_coord_indexes(do_tilt=True) #iX, iY = geometry.get_pixel_xy_inds_at_z(zplane=None, xy0_off_pix=xyc) iX, iY = geometry.get_pixel_xy_inds_at_z(zplane=150000) root, ext = os.path.splitext(fname_data) arr = np.load(fname_data) if ext == '.npy' else np.loadtxt(fname_data, dtype=np.float) #print 'arr.shape=', arr.shape arr.shape= (32,185,388) #ave, rms = arr.mean(), arr.std() #amp_range = (ave-rms, ave+3*rms) amp_range = (0, 1000) print 'amp_range', amp_range print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX,iY,W=arr) axim = gg.plotImageLarge(img,amp_range=amp_range) gg.move(500,10) gg.show()
def test_epix100a() : """ Test test_epix100a geometry table """ basedir = '/reg/g/psdm/detector/alignment/cspad/calib-cxi-ds1-2014-05-15/' fname_geometry = basedir + 'calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/geometry/2-end.data' fname_data = basedir + 'cspad-arr-cxid2714-r0023-lysozyme-rings.txt' #basedir = '/reg/neh/home1/dubrovin/LCLS/GeometryCalib/calib-xpp-Epix100a-2014-11-05/' #fname_geometry = basedir + 'calib/Epix100a::CalibV1/NoDetector.0:Epix100a.0/geometry/0-end.data' #fname_data = basedir + 'epix100a-ndarr-ave-clb-xppi0614-r0073.dat' geometry = GeometryAccess(fname_geometry, 0177777) amp_range = (-4,10) iX, iY = geometry.get_pixel_coord_indexes() root, ext = os.path.splitext(fname_data) arr = np.load(fname_data) if ext == '.npy' else np.loadtxt(fname_data, dtype=np.float) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX,iY,W=arr) axim = gg.plotImageLarge(img,amp_range=amp_range) 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 example_varsize() : print """Test HSpectrum for variable size bins""" from time import time edges = (0, 30, 40, 50, 60, 70, 100) # array of bin edges mu, sigma = 50, 10 # parameters of random Gaussian distribution of intensities nevts = 10 # number of events in this test ashape = (32,185,388) # data array shape spec = HSpectrum(edges, pbits=0377) for ev in range(nevts) : arr = random_standard_array(ashape, mu, sigma) t0_sec = time() spec.fill(arr) print 'Event:%3d, t = %10.6f sec' % (ev, time()-t0_sec) if True : import algos.graph.GlobalGraphics as gg histarr, edges, nbins = spec.spectrum() #gg.plotImageLarge(arr, amp_range=(vmin,vmax), title='random') gg.plotImageLarge(histarr[0:500,:], amp_range=(0,nevts/3), title='indexes') gg.show()
def test_2x2_img_easy() : pc2x2 = SegGeometryEpix100V1(use_wide_pix_center=False) X,Y = pc2x2.get_seg_xy_maps_pix_with_offset() iX, iY = (X+0.25).astype(int), (Y+0.25).astype(int) img = gg.getImageFromIndexArrays(iX,iY,iX+iY) gg.plotImageLarge(img, amp_range=(0, 1500), figsize=(8,10)) gg.show()
def test_cspad2x2(): """ Test cspad2x2 geometry table """ ## MecTargetChamber.0:Cspad2x2.1 basedir = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-01-2013-02-13/' fname_geometry = basedir + 'calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.1/geometry/0-end.data' fname_data = basedir + 'cspad2x2.1-ndarr-ave-meca6113-r0028.dat' ## MecTargetChamber.0:Cspad2x2.2 #basedir = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-02-2013-02-13/' #fname_geometry = basedir + 'calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.2/geometry/0-end.data' #fname_data = basedir + 'cspad2x2.2-ndarr-ave-meca6113-r0028.dat' geometry = GeometryAccess(fname_geometry, 0377) amp_range = (0, 15000) # get pixel coordinate index arrays: #xyc = xc, yc = 1000, 1000 #iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=xyc) iX, iY = geometry.get_pixel_coord_indexes(do_tilt=True) 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 = (185, 388, 2) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX, iY, W=arr) axim = gg.plotImageLarge(img, amp_range=amp_range) gg.move(500, 10) gg.show()
def test_cspad_xy_at_z(): """ Test cspad geometry table """ ## 'CxiDs1.0:Cspad.0)' or 'DscCsPad' basedir = '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera1-2014-09-24/' fname_geometry = basedir + '2016-06-03-geometry-cxi06216-r25-camera1-z175mm.txt' fname_data = basedir + '2016-06-03-chun-cxi06216-0025-DscCsPad-max.txt' geometry = GeometryAccess(fname_geometry, 0377) # get pixel coordinate index arrays: xyc = xc, yc = 1000, 1000 #iX, iY = geometry.get_pixel_coord_indexes(xy0_off_pix=xyc) #iX, iY = geometry.get_pixel_coord_indexes(do_tilt=True) #iX, iY = geometry.get_pixel_xy_inds_at_z(zplane=None, xy0_off_pix=xyc) iX, iY = geometry.get_pixel_xy_inds_at_z(zplane=150000) root, ext = os.path.splitext(fname_data) arr = np.load(fname_data) if ext == '.npy' else np.loadtxt(fname_data, dtype=np.float) #print 'arr.shape=', arr.shape arr.shape = (32, 185, 388) #ave, rms = arr.mean(), arr.std() #amp_range = (ave-rms, ave+3*rms) amp_range = (0, 1000) print 'amp_range', amp_range print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX, iY, W=arr) axim = gg.plotImageLarge(img, amp_range=amp_range) gg.move(500, 10) gg.show()
def test_epix100a(): """ Test test_epix100a geometry table """ basedir = '/reg/g/psdm/detector/alignment/cspad/calib-cxi-ds1-2014-05-15/' fname_geometry = basedir + 'calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/geometry/2-end.data' fname_data = basedir + 'cspad-arr-cxid2714-r0023-lysozyme-rings.txt' #basedir = '/reg/neh/home1/dubrovin/LCLS/GeometryCalib/calib-xpp-Epix100a-2014-11-05/' #fname_geometry = basedir + 'calib/Epix100a::CalibV1/NoDetector.0:Epix100a.0/geometry/0-end.data' #fname_data = basedir + 'epix100a-ndarr-ave-clb-xppi0614-r0073.dat' geometry = GeometryAccess(fname_geometry, 0177777) amp_range = (-4, 10) iX, iY = geometry.get_pixel_coord_indexes() root, ext = os.path.splitext(fname_data) arr = np.load(fname_data) if ext == '.npy' else np.loadtxt(fname_data, dtype=np.float) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX, iY, W=arr) axim = gg.plotImageLarge(img, amp_range=amp_range) gg.move(500, 10) gg.show()
def test_plot_beta_l0(): print """Test plot for beta angle""" import algos.graph.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_img() : t0_sec = time() w = SegGeometryMatrixV1() print 'Consumed time for coordinate arrays (sec) =', time()-t0_sec X,Y = w.get_seg_xy_maps_pix() w.print_seg_info(0377) #print 'X(pix) :\n', X print 'X.shape =', X.shape xmin, ymin, zmin = w.get_xyz_min_um() xmax, ymax, zmax = w.get_xyz_max_um() xmin /= w.pixel_scale_size() xmax /= w.pixel_scale_size() ymin /= w.pixel_scale_size() ymax /= w.pixel_scale_size() xsize = xmax - xmin + 1 ysize = ymax - ymin + 1 print 'xsize =', xsize # 391.0 print 'ysize =', ysize # 185.0 H, Xedges, Yedges = np.histogram2d(X.flatten(), Y.flatten(), bins=[xsize,ysize], range=[[xmin, xmax], [ymin, ymax]], normed=False, weights=X.flatten()+Y.flatten()) print 'Xedges:', Xedges print 'Yedges:', Yedges print 'H.shape:', H.shape gg.plotImageLarge(H, amp_range=(0, 1100), figsize=(8,10)) # range=(-1, 2), gg.show()
def test_plot_phi(): print """Test plot for phi angle""" import algos.graph.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() : print """Test plot for beta angle""" import algos.graph.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_2x2_img_easy(): pc2x2 = SegGeometryEpix100V1(use_wide_pix_center=False) X, Y = pc2x2.get_seg_xy_maps_pix_with_offset() iX, iY = (X + 0.25).astype(int), (Y + 0.25).astype(int) img = gg.getImageFromIndexArrays(iX, iY, iX + iY) gg.plotImageLarge(img, amp_range=(0, 1500), figsize=(8, 10)) gg.show()
def test_mask(mbits=0377) : pc2x1 = SegGeometryMatrixV1() X, Y = pc2x1.get_seg_xy_maps_pix_with_offset() mask = pc2x1.pixel_mask_array(mbits) iX, iY = (X+0.25).astype(int), (Y+0.25).astype(int) img = gg.getImageFromIndexArrays(iX,iY,mask) gg.plotImageLarge(img, amp_range=(-1, 2), figsize=(8,10)) gg.show()
def test_mask(mbits=0377): pc2x1 = SegGeometryMatrixV1() X, Y = pc2x1.get_seg_xy_maps_pix_with_offset() mask = pc2x1.pixel_mask_array(mbits) iX, iY = (X + 0.25).astype(int), (Y + 0.25).astype(int) img = gg.getImageFromIndexArrays(iX, iY, mask) gg.plotImageLarge(img, amp_range=(-1, 2), figsize=(8, 10)) gg.show()
def test_img_easy(): pc2x1 = SegGeometryMatrixV1() #X,Y = pc2x1.get_seg_xy_maps_pix() X, Y = pc2x1.get_seg_xy_maps_pix_with_offset() iX, iY = (X + 0.25).astype(int), (Y + 0.25).astype(int) img = gg.getImageFromIndexArrays(iX, iY, iX + iY) gg.plotImageLarge(img, amp_range=(0, 1100), figsize=(8, 10)) gg.show()
def test_img_easy() : pc2x1 = SegGeometryMatrixV1() #X,Y = pc2x1.get_seg_xy_maps_pix() X,Y = pc2x1.get_seg_xy_maps_pix_with_offset() iX, iY = (X+0.25).astype(int), (Y+0.25).astype(int) img = gg.getImageFromIndexArrays(iX,iY,iX+iY) gg.plotImageLarge(img, amp_range=(0, 1100), figsize=(8,10)) gg.show()
def test01(ntest, prefix='fig-v01') : """Test for radial 1-d binning of entire image. """ from time import time import algos.graph.GlobalGraphics as gg from PSCalib.GeometryAccess import img_from_pixel_arrays arr, geo = data_geo(ntest) t0_sec = time() iX, iY = geo.get_pixel_coord_indexes() X, Y, Z = geo.get_pixel_coords() mask = geo.get_pixel_mask(mbits=0377).flatten() print 'Time to retrieve geometry %.3f sec' % (time()-t0_sec) t0_sec = time() hp = HPolar(X, Y, mask, nradbins=500, nphibins=1) # v1 print 'HPolar initialization time %.3f sec' % (time()-t0_sec) t0_sec = time() nda, title = arr, None if ntest == 1 : nda, title = arr, 'averaged data' elif ntest == 2 : nda, title = hp.pixel_rad(), 'pixel radius value' elif ntest == 3 : nda, title = hp.pixel_phi(), 'pixel phi value' elif ntest == 4 : nda, title = hp.pixel_irad() + 2, 'pixel radial bin index' elif ntest == 5 : nda, title = hp.pixel_iphi() + 2, 'pixel phi bin index' elif ntest == 6 : nda, title = hp.pixel_iseq() + 2, 'pixel sequential (rad and phi) bin index' elif ntest == 7 : nda, title = mask, 'mask' elif ntest == 8 : nda, title = hp.pixel_avrg(nda), 'averaged radial intensity' elif ntest == 9 : nda, title = hp.pixel_avrg_interpol(arr) * mask , 'interpolated radial intensity' else : print 'Test %d is not implemented' % ntest return print 'Get %s n-d array time %.3f sec' % (title, time()-t0_sec) img = img_from_pixel_arrays(iX, iY, nda) if not ntest in (21,) else nda[100:300,:] da, ds = None, None colmap = 'jet' # 'cubehelix' 'cool' 'summer' 'jet' 'winter' if ntest in (2,3,4,5,6,7) : da = ds = (nda.min()-1., nda.max()+1.) else : ave, rms = nda.mean(), nda.std() da = ds = (ave-2*rms, ave+3*rms) gg.plotImageLarge(img, amp_range=da, figsize=(14,12), title=title, cmap=colmap) gg.save('%s-%02d-img.png' % (prefix, ntest)) gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \ figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \ title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title) gg.save('%s-%02d-his.png' % (prefix, ntest)) gg.show() print 'End of test for %s' % title
def test_2x2_mask(mbits=0377): pc2x2 = SegGeometryEpix100V1(use_wide_pix_center=False) X, Y = pc2x2.get_seg_xy_maps_pix_with_offset() mask = pc2x2.pixel_mask_array(mbits) mask[mask == 0] = 3 iX, iY = (X + 0.25).astype(int), (Y + 0.25).astype(int) img = gg.getImageFromIndexArrays(iX, iY, mask) gg.plotImageLarge(img, amp_range=(-1, 2), figsize=(8, 10)) gg.show()
def test_2x2_mask(mbits=0377) : pc2x2 = SegGeometryEpix100V1(use_wide_pix_center=False) X, Y = pc2x2.get_seg_xy_maps_pix_with_offset() mask = pc2x2.pixel_mask_array(mbits) mask[mask==0]=3 iX, iY = (X+0.25).astype(int), (Y+0.25).astype(int) img = gg.getImageFromIndexArrays(iX,iY,mask) gg.plotImageLarge(img, amp_range=(-1, 2), figsize=(8,10)) gg.show()
def test_plot_beta_l0() : print """Test plot for beta angle""" import algos.graph.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_2x1_mask(mbits=0377) : pc2x1 = SegGeometryCspad2x1V1(use_wide_pix_center=False) X, Y = pc2x1.get_seg_xy_maps_pix_with_offset() mask = pc2x1.pixel_mask_array(mbits) print 'mask:\n%s' % mask print 'mask.shape: ', mask.shape iX, iY = (X+0.25).astype(int), (Y+0.25).astype(int) img = gg.getImageFromIndexArrays(iX,iY,mask) gg.plotImageLarge(img, amp_range=(-1, 2), figsize=(8,10)) gg.show()
def test_xyz_maps() : w = SegGeometryMatrixV1() w.print_maps_seg_um() titles = ['X map','Y map'] #for i,arr2d in enumerate([w.x_pix_arr,w.y_pix_arr]) : for i,arr2d in enumerate( w.get_seg_xy_maps_pix() ) : amp_range = (arr2d.min(), arr2d.max()) gg.plotImageLarge(arr2d, amp_range=amp_range, figsize=(10,5), title=titles[i]) gg.move(200*i,100*i) gg.show()
def test_plot_beta_l1(DoR=0.4292, sgnrt=1.): print """Test plot for beta angle""" import algos.graph.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_xyz_maps(): w = SegGeometryMatrixV1() w.print_maps_seg_um() titles = ['X map', 'Y map'] #for i,arr2d in enumerate([w.x_pix_arr,w.y_pix_arr]) : for i, arr2d in enumerate(w.get_seg_xy_maps_pix()): amp_range = (arr2d.min(), arr2d.max()) gg.plotImageLarge(arr2d, amp_range=amp_range, figsize=(10, 5), title=titles[i]) gg.move(200 * i, 100 * i) gg.show()
def test_plot_quad(geometry) : """ Tests geometry acess methods of the class GeometryAccess object for CSPAD quad """ ## get index arrays iX, iY = geometry.get_pixel_coord_indexes('QUAD:V1', 1, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True) # get intensity array arr = tig.cspad_nparr(n2x1=iX.shape[0]) arr.shape = (8,185,388) amp_range = (0,185+388) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX,iY,W=arr) gg.plotImageLarge(img,amp_range=amp_range) gg.move(500,10) gg.show()
def test_mask_quad(geometry, mbits) : """ Tests geometry acess methods of the class GeometryAccess object for CSPAD quad """ ## get index arrays iX, iY = geometry.get_pixel_coord_indexes('QUAD:V1', 1, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True) # get intensity array arr = geometry.get_pixel_mask('QUAD:V1', 1, mbits) arr.shape = (8,185,388) amp_range = (-1,2) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX, iY, W=arr, vbase=0.5) gg.plotImageLarge(img,amp_range=amp_range) gg.move(500,10) gg.show()
def test_plot_beta_l1(DoR=0.4292, sgnrt=1.) : print """Test plot for beta angle""" import algos.graph.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_mask_quad(geometry, mbits): """ Tests geometry acess methods of the class GeometryAccess object for CSPAD quad """ ## get index arrays iX, iY = geometry.get_pixel_coord_indexes('QUAD:V1', 1, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True) # get intensity array arr = geometry.get_pixel_mask('QUAD:V1', 1, mbits) arr.shape = (8, 185, 388) amp_range = (-1, 2) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX, iY, W=arr, vbase=0.5) gg.plotImageLarge(img, amp_range=amp_range) gg.move(500, 10) gg.show()
def test_plot_quad(geometry): """ Tests geometry acess methods of the class GeometryAccess object for CSPAD quad """ ## get index arrays iX, iY = geometry.get_pixel_coord_indexes('QUAD:V1', 1, pix_scale_size_um=None, xy0_off_pix=None, do_tilt=True) # get intensity array arr = tig.cspad_nparr(n2x1=iX.shape[0]) arr.shape = (8, 185, 388) amp_range = (0, 185 + 388) print 'iX, iY, W shape:', iX.shape, iY.shape, arr.shape img = img_from_pixel_arrays(iX, iY, W=arr) gg.plotImageLarge(img, amp_range=amp_range) gg.move(500, 10) gg.show()
def test_08() : from time import time import algos.graph.GlobalGraphics as gg from algos.core.NDArrGenerators import random_standard print '%s\n%s\n' % (80*'_','Test method locxymax(nda, order, mode):') #data = random_standard(shape=(32,185,388), mu=0, sigma=10) data = random_standard(shape=(2,185,388), mu=0, sigma=10) t0_sec = time() mask = locxymax(data, order=1, mode='clip') print 'Consumed t = %10.6f sec' % (time()-t0_sec) if True : img = data if len(data.shape)==2 else reshape_to_2d(data) msk = mask if len(mask.shape)==2 else reshape_to_2d(mask) ave, rms = img.mean(), img.std() amin, amax = ave-2*rms, ave+2*rms gg.plotImageLarge(img, amp_range=(amin, amax), title='random') gg.plotImageLarge(msk, amp_range=(0, 1), title='mask loc max') gg.show()
def test_img(): t0_sec = time() w = SegGeometryMatrixV1() print 'Consumed time for coordinate arrays (sec) =', time() - t0_sec X, Y = w.get_seg_xy_maps_pix() w.print_seg_info(0377) #print 'X(pix) :\n', X print 'X.shape =', X.shape xmin, ymin, zmin = w.get_xyz_min_um() xmax, ymax, zmax = w.get_xyz_max_um() xmin /= w.pixel_scale_size() xmax /= w.pixel_scale_size() ymin /= w.pixel_scale_size() ymax /= w.pixel_scale_size() xsize = xmax - xmin + 1 ysize = ymax - ymin + 1 print 'xsize =', xsize # 391.0 print 'ysize =', ysize # 185.0 H, Xedges, Yedges = np.histogram2d(X.flatten(), Y.flatten(), bins=[xsize, ysize], range=[[xmin, xmax], [ymin, ymax]], normed=False, weights=X.flatten() + Y.flatten()) print 'Xedges:', Xedges print 'Yedges:', Yedges print 'H.shape:', H.shape gg.plotImageLarge(H, amp_range=(0, 1100), figsize=(8, 10)) # range=(-1, 2), gg.show()
def test_plot_beta(): print """Test plot for beta angle""" import algos.graph.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 test02(ntest, prefix='fig-v01') : """Test for 2-d (default) binning of the rad-phi range of entire image """ #from Detector.GlobalUtils import print_ndarr from time import time import algos.graph.GlobalGraphics as gg from PSCalib.GeometryAccess import img_from_pixel_arrays arr, geo = data_geo(ntest) iX, iY = geo.get_pixel_coord_indexes() X, Y, Z = geo.get_pixel_coords() mask = geo.get_pixel_mask(mbits=0377).flatten() t0_sec = time() rb = RadialBkgd(X, Y, mask) # v0 #rb = RadialBkgd(X, Y, mask, nradbins=500) # , nphibins=8, phiedges=(-20, 240), radedges=(10000,80000)) print 'RadialBkgd initialization time %.3f sec' % (time()-t0_sec) #print 'npixels_per_bin:', rb.npixels_per_bin() #print 'intensity_per_bin:', rb.intensity_per_bin(arr) #print 'average_per_bin:', rb.average_per_bin(arr) t0_sec = time() nda, title = arr, None if ntest == 21 : nda, title = arr, 'averaged data' elif ntest == 22 : nda, title = rb.pixel_rad(), 'pixel radius value' elif ntest == 23 : nda, title = rb.pixel_phi(), 'pixel phi value' elif ntest == 24 : nda, title = rb.pixel_irad() + 2, 'pixel radial bin index' elif ntest == 25 : nda, title = rb.pixel_iphi() + 2, 'pixel phi bin index' elif ntest == 26 : nda, title = rb.pixel_iseq() + 2, 'pixel sequential (rad and phi) bin index' elif ntest == 27 : nda, title = mask, 'mask' elif ntest == 28 : nda, title = rb.pixel_avrg(nda), 'averaged radial background' elif ntest == 29 : nda, title = rb.subtract_bkgd(nda) * mask, 'background-subtracted data' elif ntest == 30 : nda, title = rb.bin_avrg_rad_phi(nda),'r-phi' elif ntest == 31 : nda, title = rb.pixel_avrg_interpol(nda), 'averaged radial interpolated background' elif ntest == 32 : nda, title = rb.subtract_bkgd_interpol(nda, method='linear', verb=True) * mask, 'interpol-background-subtracted data' else : print 'Test %d is not implemented' % ntest return print 'Get %s n-d array time %.3f sec' % (title, time()-t0_sec) img = img_from_pixel_arrays(iX, iY, nda) if not ntest in (30,) else nda # [100:300,:] colmap = 'jet' # 'cubehelix' 'cool' 'summer' 'jet' 'winter' 'gray' da = (nda.min()-1, nda.max()+1) ds = da if ntest in (21,28,29,30,31) : ave, rms = nda.mean(), nda.std() da = ds = (ave-2*rms, ave+3*rms) elif ntest in (32,) : colmap = 'gray' ds = da = (-20, 20) gg.plotImageLarge(img, amp_range=da, figsize=(14,12), title=title, cmap=colmap) gg.save('%s-%02d-img.png' % (prefix, ntest)) gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \ figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \ title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title) gg.save('%s-%02d-his.png' % (prefix, ntest)) gg.show() print 'End of test for %s' % title
def test01(ntest, prefix='fig-v01'): """Test for radial 1-d binning of entire image. """ from time import time import algos.graph.GlobalGraphics as gg from PSCalib.GeometryAccess import img_from_pixel_arrays arr, geo = data_geo(ntest) t0_sec = time() iX, iY = geo.get_pixel_coord_indexes() X, Y, Z = geo.get_pixel_coords() mask = geo.get_pixel_mask(mbits=0377).flatten() print 'Time to retrieve geometry %.3f sec' % (time() - t0_sec) t0_sec = time() hp = HPolar(X, Y, mask, nradbins=500, nphibins=1) # v1 print 'HPolar initialization time %.3f sec' % (time() - t0_sec) t0_sec = time() nda, title = arr, None if ntest == 1: nda, title = arr, 'averaged data' elif ntest == 2: nda, title = hp.pixel_rad(), 'pixel radius value' elif ntest == 3: nda, title = hp.pixel_phi(), 'pixel phi value' elif ntest == 4: nda, title = hp.pixel_irad() + 2, 'pixel radial bin index' elif ntest == 5: nda, title = hp.pixel_iphi() + 2, 'pixel phi bin index' elif ntest == 6: nda, title = hp.pixel_iseq( ) + 2, 'pixel sequential (rad and phi) bin index' elif ntest == 7: nda, title = mask, 'mask' elif ntest == 8: nda, title = hp.pixel_avrg(nda), 'averaged radial intensity' elif ntest == 9: nda, title = hp.pixel_avrg_interpol( arr) * mask, 'interpolated radial intensity' else: print 'Test %d is not implemented' % ntest return print 'Get %s n-d array time %.3f sec' % (title, time() - t0_sec) img = img_from_pixel_arrays( iX, iY, nda) if not ntest in (21, ) else nda[100:300, :] da, ds = None, None colmap = 'jet' # 'cubehelix' 'cool' 'summer' 'jet' 'winter' if ntest in (2, 3, 4, 5, 6, 7): da = ds = (nda.min() - 1., nda.max() + 1.) else: ave, rms = nda.mean(), nda.std() da = ds = (ave - 2 * rms, ave + 3 * rms) gg.plotImageLarge(img, amp_range=da, figsize=(14, 12), title=title, cmap=colmap) gg.save('%s-%02d-img.png' % (prefix, ntest)) gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \ figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \ title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title) gg.save('%s-%02d-his.png' % (prefix, ntest)) gg.show() print 'End of test for %s' % title
def test_plot_beta_l1_zoom(DoR=0.4292, sgnrt=1.): print """Test plot for beta angle""" import algos.graph.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 test03(ntest, prefix='fig-v01'): """Test for 2-d binning of the restricted rad-phi range of entire image """ from time import time import algos.graph.GlobalGraphics as gg from PSCalib.GeometryAccess import img_from_pixel_arrays arr, geo = data_geo(ntest) iX, iY = geo.get_pixel_coord_indexes() X, Y, Z = geo.get_pixel_coords() mask = geo.get_pixel_mask(mbits=0377).flatten() t0_sec = time() #hp = HPolar(X, Y, mask, nradbins=5, nphibins=8, phiedges=(-20, 240), radedges=(10000,80000)) hp = HPolar(X, Y, mask, nradbins=3, nphibins=8, phiedges=(240, -20), radedges=(80000, 10000)) # v3 print 'HPolar initialization time %.3f sec' % (time() - t0_sec) #print 'bin_number_of_pixels:', hp.bin_number_of_pixels() #print 'bin_intensity:', hp.bin_intensity(arr) #print 'bin_avrg:', hp.bin_avrg(arr) t0_sec = time() nda, title = arr, None if ntest == 41: nda, title = arr, 'averaged data' elif ntest == 44: nda, title = hp.pixel_irad() + 2, 'pixel radial bin index' elif ntest == 45: nda, title = hp.pixel_iphi() + 2, 'pixel phi bin index' elif ntest == 46: nda, title = hp.pixel_iseq( ) + 2, 'pixel sequential (rad and phi) bin index' #elif ntest == 47 : nda, title = mask, 'mask' elif ntest == 48: nda, title = hp.pixel_avrg(nda), 'averaged radial intensity' elif ntest == 49: nda, title = hp.pixel_avrg_interpol( nda), 'averaged radial interpolated intensity' elif ntest == 50: nda, title = hp.bin_avrg_rad_phi(nda), 'r-phi' else: print 'Test %d is not implemented' % ntest return print 'Get %s n-d array time %.3f sec' % (title, time() - t0_sec) img = img_from_pixel_arrays( iX, iY, nda) if not ntest in (50, ) else nda # [100:300,:] colmap = 'jet' # 'cubehelix' 'cool' 'summer' 'jet' 'winter' 'gray' da = (nda.min() - 1, nda.max() + 1) ds = da if ntest in (41, 48, 49, 50): ave, rms = nda.mean(), nda.std() da = ds = (ave - 2 * rms, ave + 3 * rms) gg.plotImageLarge(img, amp_range=da, figsize=(14, 12), title=title, cmap=colmap) gg.save('%s-%02d-img.png' % (prefix, ntest)) gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \ figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \ title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title) gg.save('%s-%02d-his.png' % (prefix, ntest)) gg.show() print 'End of test for %s' % title
def test_img_default(): """ Test default image """ axim = gg.plotImageLarge(img_default()) gg.move(500, 10) gg.show()
def test03(ntest, prefix='fig-v01') : """Test for 2-d binning of the restricted rad-phi range of entire image """ from time import time import algos.graph.GlobalGraphics as gg from PSCalib.GeometryAccess import img_from_pixel_arrays arr, geo = data_geo(ntest) iX, iY = geo.get_pixel_coord_indexes() X, Y, Z = geo.get_pixel_coords() mask = geo.get_pixel_mask(mbits=0377).flatten() t0_sec = time() #hp = HPolar(X, Y, mask, nradbins=5, nphibins=8, phiedges=(-20, 240), radedges=(10000,80000)) hp = HPolar(X, Y, mask, nradbins=3, nphibins=8, phiedges=(240, -20), radedges=(80000,10000)) # v3 print 'HPolar initialization time %.3f sec' % (time()-t0_sec) #print 'bin_number_of_pixels:', hp.bin_number_of_pixels() #print 'bin_intensity:', hp.bin_intensity(arr) #print 'bin_avrg:', hp.bin_avrg(arr) t0_sec = time() nda, title = arr, None if ntest == 41 : nda, title = arr, 'averaged data' elif ntest == 44 : nda, title = hp.pixel_irad() + 2, 'pixel radial bin index' elif ntest == 45 : nda, title = hp.pixel_iphi() + 2, 'pixel phi bin index' elif ntest == 46 : nda, title = hp.pixel_iseq() + 2, 'pixel sequential (rad and phi) bin index' #elif ntest == 47 : nda, title = mask, 'mask' elif ntest == 48 : nda, title = hp.pixel_avrg(nda), 'averaged radial intensity' elif ntest == 49 : nda, title = hp.pixel_avrg_interpol(nda), 'averaged radial interpolated intensity' elif ntest == 50 : nda, title = hp.bin_avrg_rad_phi(nda),'r-phi' else : print 'Test %d is not implemented' % ntest return print 'Get %s n-d array time %.3f sec' % (title, time()-t0_sec) img = img_from_pixel_arrays(iX, iY, nda) if not ntest in (50,) else nda # [100:300,:] colmap = 'jet' # 'cubehelix' 'cool' 'summer' 'jet' 'winter' 'gray' da = (nda.min()-1, nda.max()+1) ds = da if ntest in (41,48,49,50) : ave, rms = nda.mean(), nda.std() da = ds = (ave-2*rms, ave+3*rms) gg.plotImageLarge(img, amp_range=da, figsize=(14,12), title=title, cmap=colmap) gg.save('%s-%02d-img.png' % (prefix, ntest)) gg.hist1d(nda, bins=None, amp_range=ds, weights=None, color=None, show_stat=True, log=False, \ figsize=(6,5), axwin=(0.18, 0.12, 0.78, 0.80), \ title=None, xlabel='Pixel value', ylabel='Number of pixels', titwin=title) gg.save('%s-%02d-his.png' % (prefix, ntest)) gg.show() print 'End of test for %s' % title
def test_img_default() : """ Test default image """ axim = gg.plotImageLarge( img_default() ) 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 make_index_table(prefix='./v01-'): from algos.core.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 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, cdtype=np.float32) lattice_node_radius(b1, b2, b3, hmax, kmax, lmax, cdtype=np.float32) lattice_node_radius(b1, b2, b3, hmax, kmax, 1, cdtype=np.float32) #------------------------------ #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(b1, b2, b3, hmax, kmax, lmax, np.float32, evald_rad, sigma_ql, sigma_qt, fout, bpq, bpomega, bpbeta) lut2 = make_lookup_table(b1, b2, b3, hmax, kmax, lmax, np.float32, evald_rad, sigma_ql, sigma_qt, fout, bpq, bpomega, bpbeta2) fout.close() print '\nIndexing lookup table is saved in the file: %s' % fname #------------------------------ # produce and save plots import algos.graph.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 test_plot_beta_l1_zoom(DoR=0.4292, sgnrt=1.) : print """Test plot for beta angle""" import algos.graph.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 make_index_table(prefix='./v01-') : from algos.core.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 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, cdtype=np.float32) lattice_node_radius(b1, b2, b3, hmax, kmax, lmax, cdtype=np.float32) lattice_node_radius(b1, b2, b3, hmax, kmax, 1, cdtype=np.float32) #------------------------------ #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(b1, b2, b3, hmax, kmax, lmax, np.float32, evald_rad, sigma_ql, sigma_qt, fout, bpq, bpomega, bpbeta) lut2 = make_lookup_table(b1, b2, b3, hmax, kmax, lmax, np.float32, evald_rad, sigma_ql, sigma_qt, fout, bpq, bpomega, bpbeta2) fout.close() print '\nIndexing lookup table is saved in the file: %s' % fname #------------------------------ # produce and save plots import algos.graph.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) : """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()