def test_cspad2x2_image_with_data() : """ Example showing how to get calibration, coordinate objects, get pedestals and data arrays and plot image. 1. get calibration and pixel coordinate objects 2. get pedestals from calibration 3. get data for one event from hdf5 file and subtract pedestal array 4. convert data to image using coord.get_cspad2x2_image(data) 5. plot image """ path = '/reg/d/psdm/mec/mec73313/calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.5/' run = 180 calib = calpars.CSPAD2x2CalibPars(path, run) coord = pixcoor.CSPAD2x2PixCoords(calib) peds = calib.getCalibPars('pedestals', run) fname = '/reg/neh/home1/dubrovin/LCLS/HDF5Analysis-v01/PyCSPadImage/src/mec73313-r%04d.h5' % run dsname= '/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1/MecTargetChamber.0:Cspad2x2.5/data' data = hm.getDataSetForOneEvent(fname, dsname, event=0) - peds print 'data.shape =', data.shape img2d = coord.get_cspad2x2_image(data) print 'img2d.shape =', img2d.shape gg.plotImageLarge(img2d, amp_range=(-10, 40), figsize=(12,11)) gg.show()
def main_example_CSpad2x2() : print 'Start test in main_example_CSpad2x2()' fname = '/reg/d/psdm/xpp/xppi0212/hdf5/xppi0212-r0046.h5' dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1/XppGon.0:Cspad2x2.0/data' event = 0 h5file = hm.hdf5mets.open_hdf5_file(fname) #grp = hm.hdf5mets.get_dataset_from_hdf5_file('/') grp = hm.hdf5mets.get_dataset_from_hdf5_file('/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1') hm.print_hdf5_item_structure(grp) arrevts = hm.hdf5mets.get_dataset_from_hdf5_file(dsname) arr1ev = arrevts[event] hm.hdf5mets.close_hdf5_file() #print 'arr1ev=\n', arr1ev print 'arr1ev.shape=\n', arr1ev.shape #arr = arr1ev[:,:,0] cspadimg = cip.CSPadImageProducer() arr = cspadimg.getImageArrayForCSpad2x2Element( arr1ev ) AmpRange = (0,1200) gg.plotImage(arr,range=AmpRange,figsize=(11.6,10)) gg.move(300,100) gg.plotSpectrum(arr,range=AmpRange) gg.move(10,100) gg.show()
def test_plot_for_cspad2x2_coords(calib_path='.', run_num=0): #calib_path = '/reg/d/psdm/xpp/xpptut13/calib/CsPad2x2::CalibV1/XppGon.0:Cspad2x2.1/' #run_num = 123 #calib = CSPAD2x2CalibPars(calib_path, run_num) #coord = CSPAD2x2PixCoords(calib) coord = CSPAD2x2PixCoords() #coord.print_cspad2x2_geometry_pars() iX, iY = coord.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix() raw_arr = np.arange(185 * 388 * 2) # np.zeros((sp.sects,sp.rows,sp.cols) raw_arr.shape = (185, 388, 2) img2d = gg.getImageFromIndexArrays(iX, iY, raw_arr) gg.plotImageLarge(img2d, amp_range=(-1, 185 * 388 * 2), figsize=(12, 11)) gg.show()
def test_plot_for_cspad2x2_coords(calib_path='.', run_num=0) : #calib_path = '/reg/d/psdm/xpp/xpptut13/calib/CsPad2x2::CalibV1/XppGon.0:Cspad2x2.1/' #run_num = 123 #calib = CSPAD2x2CalibPars(calib_path, run_num) #coord = CSPAD2x2PixCoords(calib) coord = CSPAD2x2PixCoords() #coord.print_cspad2x2_geometry_pars() iX,iY = coord.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix () raw_arr = np.arange(185*388*2) # np.zeros((sp.sects,sp.rows,sp.cols) raw_arr.shape = (185,388,2) img2d = gg.getImageFromIndexArrays(iX,iY,raw_arr) gg.plotImageLarge(img2d, amp_range=(-1, 185*388*2), figsize=(12,11)) gg.show()
def get_cspad2x2_non_corrected_image_for_raw_data_array(arr): if arr.shape != (185, 388, 2): msg = 'Non-expected array shape for cspad2x2: %s' % arr.shape print msg return None coord = CSPAD2x2PixCoords() iX, iY = coord.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix() img2d = gg.getImageFromIndexArrays(iX, iY, arr) return img2d
def get_cspad2x2_non_corrected_image_for_raw_data_array(arr) : if arr.shape != (185,388,2) : msg = 'Non-expected array shape for cspad2x2: %s' % arr.shape print msg return None coord = CSPAD2x2PixCoords() iX,iY = coord.get_cspad2x2_pix_coordinate_arrays_shapeed_as_data_pix () img2d = gg.getImageFromIndexArrays(iX,iY,arr) return img2d
def test_CSPAD2x2PixCoords() : """Test demonstration of how to work with CSPAD2x2CalibPars and CSPAD2x2PixCoords modules """ #======= Define input parameters Ndet = 5 run = 180 path = '/reg/d/psdm/mec/mec73313/calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.%1d/' % Ndet #path = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-0%1d-2013-02-13/' % Ndet #fname = '/reg/d/psdm/mec/mec73313/hdf5/mec73313-r%04d.h5' % run fname = '/reg/neh/home1/dubrovin/LCLS/HDF5Analysis-v01/PyCSPadImage/src/mec73313-r%04d.h5' % run dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1/MecTargetChamber.0:Cspad2x2.%1d/data' % Ndet list_of_clib_types = ['center', 'tilt', 'pedestals'] #======= Get calibration object calib = calpars.CSPAD2x2CalibPars(path, run, list_of_clib_types) #======= Get CSPAD2x2 pixel coordinate arrays, shaped as (2, 185, 388) coord = pixcoor.CSPAD2x2PixCoords(calib) X,Y = coord.get_cspad2x2_pix_coordinate_arrays_pix() #======= Get CSPAD2x2 pedestals array, shaped as (185, 388, 2) peds_arr = calib.getCalibPars('pedestals', run) #======= Get data array from hdf5 dataset, shaped as (185, 388, 2) data_arr = hm.getDataSetForOneEvent(fname, dsname, event=0) - peds_arr #======= Convert shape from (185, 388, 2) to (2, 185, 388) ord_arr = calpars.data2x2ToTwo2x1(data_arr) #======= Compose and plot CSPAD2x2 image from coordinate and intensity arrays img2d = gg.getImageFromIndexArrays(X,Y,ord_arr) #======= Print for test purpose calib.printCalibParsStatus() #print 'pedestals:\n', calib.getCalibPars('pedestals') print 'center:\n', calib.getCalibPars('center') print 'tilt:\n', calib.getCalibPars('tilt') print 'peds_arr.shape:', peds_arr.shape # = (185, 388, 2) print 'Get data array from file: ' + fname print 'data_arr.shape:', data_arr.shape print 'ord_arr.shape:', ord_arr.shape print 'img2d.shape:', img2d.shape #======= Plot image and spectrum my_range = (-10,40) # None gg.plotImageLarge(img2d, amp_range=my_range) gg.plotSpectrum(img2d, amp_range=my_range) gg.show()
def main_alignment_test() : print 'Start test in main_alignment_test()' #path_calib = '/reg/d/psdm/CXI/cxi80410/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' # 2011-05-25 #path_calib = '/reg/d/psdm/CXI/cxi37411/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' # 2011-08-10 #path_calib = '/reg/d/psdm/CXI/cxi35711/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' # 2011-10-18 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi43312-Dsd' # 2012-01-12 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi80410-r1150-Ds1' # 2012-01-18 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi39112-r0009-Ds1' # 2012-02-17 #path_calib = '/reg/d/psdm/CXI/cxi39112/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' # 2012-02-17 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-xpp-2012-02-26' # 2012-02-26 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi49812-r0073-Ds1' # 2012-03-08 #path_calib = '/reg/d/psdm/CXI/cxi49812/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' # 2012-03-08 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi49012-r0020-Ds1' # 2012-03-14 #path_calib = '/reg/d/psdm/CXI/cxi49012/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' # 2012-03-14 #path_calib = '/reg/d/psdm/XPP/xppcom10/calib/CsPad::CalibV1/XppGon.0:Cspad.0' # 2012-03-23 check #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-xpp-2013-01-24' # 2013-01-24 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi64813-r0058-Ds1' # 2013-01-31 #path_calib = '/reg/d/psdm/cxi/cxi64813/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0' path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-xpp-2013-01-29' # 2013-01-29 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi-ds1-2013-01-31' # 2013-02-21 #path_calib = '/reg/neh/home1/dubrovin/LCLS/CSPadAlignment-v01/calib-cxi80410-r1458-Ds1' # 2013-02-21 identic to calib-cxi-ds1-2013-01-31 #fname, runnum = '/reg/d/psdm/CXI/cxi35711/hdf5/cxi35711-r0009.h5', 9 #fname, runnum = '/reg/d/psdm/CXI/cxi37411/hdf5/cxi37411-r0080.h5', 80 #fname, runnum = '/reg/d/psdm/CXI/cxi37411/hdf5/cxi37411-r0039.h5', 39 #fname, runnum = '/reg/d/psdm/CXI/cxi80410/hdf5/cxi80410-r1150.h5', 1150 #fname, runnum = '/reg/d/psdm/CXI/cxi39112/hdf5/cxi39112-r0009.h5', 9 #fname, runnum = '/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r1437.h5', 1437 #fname, runnum = '/reg/d/psdm/CXI/cxi49812/hdf5/cxi49812-r0073.h5', 73 #fname, runnum = '/reg/d/psdm/CXI/cxi49012/hdf5/cxi49012-r0020-raw.h5', 20 #fname, runnum = '/reg/d/psdm/CXI/cxi80410/hdf5/cxi80410-r0628.h5', 628 #fname, runnum = '/reg/d/psdm/xpp/xppcom13/hdf5/xppcom13-r0066.h5', 66 #fname, runnum = '/reg/d/psdm/CXI/cxi64813/hdf5/cxi64813-r0058.h5', 58 #fname, runnum = '/reg/d/psdm/CXI/cxi80410/hdf5/cxi80410-r1458.h5', 1458 fname, runnum = '/reg/d/psdm/xpp/xpp66213/hdf5/xpp66213-r0150.h5', 150 dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad::ElementV2/XppGon.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/CxiDs1.0:Cspad.0/data' event = 0 print 'Load calibration parameters from', path_calib #calibpars = calp.calibpars.setCalibParsForPath ( run=runnum, path=path_calib ) calibpars = calp.CalibPars( path=path_calib, run=runnum ) print 'center_global:\n', calibpars.getCalibPars('center_global') #print 'offset:\n', calibpars.getCalibPars('offset') #calp.calibpars.printCalibPars() #calp.calibpars.printCalibFiles () #calp.calibpars.printListOfCalibTypes() #cald.calibparsdefault.printListOfCalibTypes() #cald.calibparsdefault.printCalibParsDefault() #cald.calibparsdefault.printCalibParsDefault('center_global') print 'Get raw CSPad event %d from file %s \ndataset %s' % (event, fname, dsname) ds1ev = hm.getOneCSPadEventForTest( fname, dsname, event ) #ds1ev = hm.getAverageCSPadEvent( fname, dsname, event=200, nevents=500 ) #ds1ev = hm.getAverageCSPadEvent( fname, dsname, event, nevents=10 ) #print 'ds1ev.shape = ',ds1ev.shape # should be (32, 185, 388) #print 'ds1ev = ',ds1ev[1,:] #print 'Subtract pedestals' #ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-cxi49812-r0072.dat' # shape = (5920, 388) #ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-cxi49012-r0008.dat' # shape = (5920, 388) #ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-cxi49012-r0038.dat' # shape = (5920, 388) #ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-cxi49012-r0027.dat' # shape = (5920, 388) #ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-xppcom10-r1435.dat' # shape = (5920, 388) low gain #ped_fname = '/reg/d/psdm/CXI/cxi49012/calib/CsPad::CalibV1/CxiDs1.0:Cspad.0/pedestals/9-37.data' # shape = (5920, 388) #ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-cxi80410-r1453.dat' # shape = (5920, 388) ped_fname = '/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-xpp66213-r0149.dat' # shape = (5920, 388) #ds1ev = gm.getCSPadArrayFromFile(ped_fname) #ds1ev -= gm.getCSPadArrayFromFile('/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-cxi49012-r0027.dat') #ds1ev -= gm.getCSPadArrayFromFile('/reg/neh/home1/dubrovin/LCLS/CSPadPedestals/cspad-pedestals-xppcom10-r1442.dat') ds1ev -= gm.getCSPadArrayFromFile(ped_fname) print 'ds1ev.shape = ',ds1ev.shape # should be (32, 185, 388) print 'Make the CSPad image from raw array' #cspadimg = cip.CSPadImageProducer(rotation=0, tiltIsOn=True)#, mirror=True) cspadimg = cip.CSPadImageProducer(calibpars, rotation=0, tiltIsOn=True)#, mirror=True) #cspadimg.printInputPars() #cspadimg.printGeometryPars() #arr = cspadimg.getImageArrayForCSPadElement( ds1ev ) arr = cspadimg.getCSPadImage( ds1ev ) print 'Plot CSPad image' #AmpRange = (800, 1300) # for cxi AmpRange = (0, 10) # for cxi #AmpRange = (-10, 50) # for xpp #gg.plotImage(arr,range=AmpRange,figsize=(1.16*12,12)) gg.plotImageLarge(arr,range=AmpRange,figsize=(1.15*12,12)) gg.move(200,100) gg.plotSpectrum(arr,range=AmpRange) gg.move(50,50) #gg.plotImageAndSpectrum(arr,range=(1,2001)) print 'To EXIT the test click on "x" in the top-right corner of each plot window.' gg.show()