def test_of_coord_arrs(coord, calib=None) : """ Test of coordinate arrays, plot image map. """ #coord.print_cspad2x2_coordinate_arrays() #iX,iY = coord.get_cspad2x2_pix_coordinate_arrays_pix () iX,iY = coord.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix () W = None amp_range = (-1, 2) if calib != None : W = calib.getCalibPars('pedestals') print ' W.shape =', W.shape # W.shape = (185, 388, 2 ) amp_range = (200,600) print 'iX.shape =', iX.shape print 'iY.shape =', iY.shape t0_sec = time() #img2d = gg.getImageAs2DHist(X,Y,W=None) img2d = gg.getImageFromIndexArrays(iX,iY,W) print 'Consumed time to create image (sec) =', time()-t0_sec #gg.plotImageLarge(img2d, amp_range=(-1, 2), figsize=(12,11)) gg.plotImageLarge(img2d, amp_range = amp_range, figsize=(12,11)) gg.show()
def test_2x1_img() : t0_sec = time() w = PixCoords2x1(use_wide_pix_center=False) #w = PixCoords2x1(use_wide_pix_center=True) print 'Consumed time for coordinate arrays (sec) =', time()-t0_sec X,Y = w.get_cspad2x1_xy_maps_pix() w.print_xy_arr_um() w.print_xy_arr_pix() w.print_xy_min_max_um() w.print_xy_min_max_pix() #print 'X(pix) :\n', X print 'X.shape =', X.shape xmin, ymin = w.get_xy_min_pix() xmax, ymax = w.get_xy_max_pix() xmin-=0.5; xmax+=0.5; ymin-=0.5; ymax+=0.5; xsize = xmax - xmin ysize = ymax - ymin 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=(-250, 250), figsize=(8,10)) # range=(-1, 2), gg.show()
def test_2x1_img_easy() : pc2x1 = PixCoords2x1(use_wide_pix_center=False) #X,Y = pc2x1.get_cspad2x1_xy_maps_pix() X,Y = pc2x1.get_cspad2x1_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, 500), figsize=(8,10)) gg.show()
def test_cspadpixcoords_3() : """Test of instantiation with external parameters. """ coord = test_cspadpixcoords_instantiation_1() img2d = coord.get_cspad_image(None) print 'img2d.shape =', img2d.shape gg.plotImageLarge(img2d, amp_range=(-1, 2), figsize=(12,11)) gg.show()
def plot_img(img_arr) : """Plot image for test purpose""" print 'img_arr.shape=', img_arr.shape gg.plotImageLarge(img_arr) #, img_range=None, amp_range=None, ... gg.savefig('cspad-arr-img.png') gg.move(500,10) gg.show()
def main_test_cspad() : xc_um = np.array( [[ 473.38, 685.26, 155.01, 154.08, 266.81, 53.95, 583.04, 582.15], [ 989.30, 987.12, 1096.93, 884.11, 1413.16, 1414.94, 1500.83, 1288.02], [1142.59, 930.23, 1459.44, 1460.67, 1347.57, 1559.93, 1032.27, 1033.44], [ 626.78, 627.42, 516.03, 729.15, 198.28, 198.01, 115.31, 327.66]]) * 109.92 yc_um = np.array( [[1028.07, 1026.28, 1139.46, 926.91, 1456.78, 1457.35, 1539.71, 1327.89], [1180.51, 967.36, 1497.74, 1498.54, 1385.08, 1598.19, 1069.65, 1069.93], [ 664.89, 666.83, 553.60, 765.91, 237.53, 236.06, 152.17, 365.47], [ 510.38, 722.95, 193.33, 193.41, 308.04, 95.25, 625.28, 624.14]]) * 109.92 orient_deg = np.array( [[ 90., 90., 0., 0., 270., 270., 0., 0.], [ 0., 0., 270., 270., 180., 180., 270., 270.], [ 90., 90., 0., 0., 270., 270., 0., 0.], [ 0., 0., 270., 270., 180., 180., 270., 270.]]) tilt_deg = np.array( [[0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.]]) print 'xc_um:\n', xc_um print 'yc_um:\n', yc_um print 'orient_deg:\n', orient_deg print 'tilt_deg:\n', tilt_deg w = CSPadPixCoordsWODB(xc_um, yc_um, orient_deg, tilt_deg) #w.make_cspad_pix_coordinate_arrays (xc_um, yc_um, orient_deg, tilt_deg) w.print_cspad_coordinate_arrays() X,Y = w.get_cspad_pix_coordinate_arrays_pix () print 'X(pix) :\n', X print 'X.shape =\n', X.shape xsize = X.max() + 1 ysize = Y.max() + 1 H,Xedges,Yedges = np.histogram2d(X.flatten(), Y.flatten(), bins=[xsize,ysize], range=[[0,xsize],[0,ysize]], normed=False, weights=None) range = (-5, 5) gg.plotImageLarge(H, range=(-1, 2), figsize=(12,11)) gg.show()
def get_cspad_image(sp, data_arr=None, config=None) : # preferable data_arr.shape=(32,185,388) like in data """ Test of coordinate arrays, plot image map. """ iX,iY = sp.get_cspad_pix_coordinate_arrays_pix(config) data = data_arr #if data_arr != None and data.shape != (4,8,185,388) : # data.shape == (4,8,185,388) if data_arr != None : data = data_arr.flatten() return gg.getImageFromIndexArrays(iX.flatten(),iY.flatten(),data) # All arrays should have the same shape
def test_of_image(coord, calib=None) : """ Test of coordinate arrays, plot image map. """ #fname = '/reg/d/psdm/xpp/xpptut13/hdf5/xppi0513-r0008.h5' fname = '/reg/d/psdm/xpp/xppi0513/hdf5/xppi0513-r0008.h5' dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1/XppGon.0:Cspad2x2.1/data' run = 123 dset = hm.getDataSetForOneEvent( fname, dsname, event = 0 ) iX,iY = coord.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix () #dset = calib.getCalibPars('pedestals') print ' dset.shape =', dset.shape # dset.shape = (185, 388, 2 ) t0_sec = time() img2d = gg.getImageFromIndexArrays(iX,iY,dset) print 'Consumed time to create image (sec) =', time()-t0_sec gg.plotImageLarge(img2d, amp_range=None, figsize=(12,11)) gg.show()
def test_of_coord_arrs(coord, config=None) : """ Test of coordinate arrays, plot image map. """ iX,iY = coord.get_cspad_pix_coordinate_arrays_pix (config) print 'iX.shape =', iX.shape print 'iY.shape =', iY.shape weights = get_test_cspad_pix_arr(config) t0_sec = time() #img2d = gg.getImageAs2DHist(iX,iY,W=None) img2d = gg.getImageFromIndexArrays(iX,iY,W=weights) print 'Consumed time to create image (sec) =', time()-t0_sec #gg.plotImageLarge(img2d, amp_range=(-1, 32), figsize=(12,11)) #amp_range=(0, 2000) gg.plotImageLarge(img2d, amp_range=None, figsize=(12,11)) #amp_range=(0, 2000) gg.show()
def get_cspad2x2_image(sp, data_arr=None) : # preferable data_arr.shape=(185,388,2) like in data """ Test of coordinate arrays, plot image map. """ iX,iY = sp.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix () data = data_arr if data_arr != None and data_arr.shape == (2,185,388) : data = two2x1ToData2x2(data_arr) #if data_arr != None and data_arr.shape == (185,388,2) : # data = data2x2ToTwo2x1(data_arr) #print 'data.shape for image =', data.shape return gg.getImageFromIndexArrays(iX,iY,data) # All arrays should have the same shape
def main_test_2x1() : w = CSPadPixCoordsWODB() w.make_maps_of_2x1_pix_coordinates() w.print_maps_2x1() for i,arr2d in enumerate([w.x_map2x1,w.y_map2x1]) : range = (arr2d.min(), arr2d.max()) gg.plotImage(arr2d, range, figsize=(10,5)) gg.move(200*i,100*i) gg.show()
def test_2x1_xy_maps() : w = PixCoords2x1() w.print_maps_2x1_um() titles = ['X map','Y map'] #for i,arr2d in enumerate([w.x_map2x1,w.y_map2x1]) : for i,arr2d in enumerate( w.get_cspad2x1_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 main_calib() : print 'Start test in main_calib()' #calp.calibpars.setCalibPars( run = 9, # calibdir = '/reg/d/psdm/CXI/cxi35711/calib', # group = 'CsPad::CalibV1', # source = 'CxiDs1.0:Cspad.0' ) runnum=0 #path_calib = '/reg/neh/home/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi37411-r0039-Dsd/' #path_calib = '/reg/neh/home/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi37411-r0080-Ds1' #path_calib = '/reg/neh/home/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi35711-r0009-det' #path_calib = '/reg/d/psdm/CXI/cxi37411/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' #path_calib = '/reg/d/psdm/CXI/cxi35711/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' #path_calib = '/reg/d/psdm/CXI/cxi37411/calib/CsPad::CalibV1/CxiDsd.0:Cspad.0' path_calib = '/reg/d/psdm/xpp/xpp47712/calib/CsPad::CalibV1/XppGon.0:Cspad.0' #fname = '/reg/d/psdm/CXI/cxi35711/hdf5/cxi35711-r0009.h5' #fname = '/reg/d/psdm/CXI/cxi37411/hdf5/cxi37411-r0080.h5' #fname = '/reg/d/psdm/CXI/cxi37411/hdf5/cxi37411-r0039.h5' #fname = '/reg/d/psdm/XPP/xpp47712/hdf5/xpp47712-r0043.h5' #fname = '/reg/d/psdm/CXI/cxi80410/hdf5/cxi80410-r0628.h5' fname, runnum = '/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r1437.h5', 1437 #dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDs1.0:Cspad.0/data' #dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/CxiDsd.0:Cspad.0/data' dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.0:Cspad.0/data' event = 0 print 'Load calibration parameters from', path_calib calp.calibpars.setCalibParsForPath ( run=runnum, path=path_calib ) print 'Get raw CSPad event %d from file %s \ndataset %s' % (event, fname, dsname) ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event ) print 'ds1ev.shape = ',ds1ev.shape print 'Make the CSPad image from raw array' #cspadimg = CSPadImageProducer(rotation=3, tiltIsOn=False, mirror=False) cspadimg = CSPadImageProducer(rotation=0, tiltIsOn=False, mirror=False) cspadimg.printInputPars() cspadimg.printGeometryPars() #arr = cspadimg.getImageArrayForPair( ds1ev, pairNum=3 ) #arr = cspadimg.getImageArrayForQuad( ds1ev, quadNum=2 ) #arr = cspadimg.getImageArrayForCSPadElement( ds1ev ) arr = cspadimg.getCSPadImage( ds1ev ) #print 'arr = \n',arr AmpRange = (1700,2000) #AmpRange = (0, 100) print 'Plot CSPad image' gg.plotImage(arr,range=AmpRange,figsize=(11.6,10)) gg.move(200,100) #gg.plotImageAndSpectrum(arr,range=(1,2001)) gg.plotSpectrum(arr,range=AmpRange) gg.move(50,50) print 'To EXIT the test click on "x" in the top-right corner of each plot window.' gg.show()