Detector/examples/ex_all_dets.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import psana
00005 from time import time
00006 from Detector.GlobalUtils import print_ndarr
00007 import PSCalib.GlobalUtils as gu
00008 
00009 ##-----------------------------
00010 
00011 ntest = int(sys.argv[1]) if len(sys.argv)>1 else 1
00012 print 'Test # %d' % ntest
00013 
00014 ##-----------------------------
00015 dsname, src = None, None
00016 
00017 if ntest==1 : # dsname, src = 'exp=cxif5315:run=169', 'CxiDs2.0:Cspad.0'
00018     dsname, src = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc',  'CxiDs2.0:Cspad.0'
00019     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera2-2015-01-20/calib')
00020 
00021 elif ntest==2 : # dsname, src = 'exp=meca1113:run=376', 'MecTargetChamber.0:Cspad2x2.1'
00022     dsname = '/reg/g/psdm/detector/data_test/types/0004-MecTargetChamber.0-Cspad.0-three-quads.xtc'
00023     src = 'MecTargetChamber.0:Cspad2x2.1'
00024     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad2x2/calib-cspad2x2-01-2013-02-13/calib')
00025 
00026 elif ntest==3 : #dsname, src = 'exp=amob5114:run=403', 'Camp.0:pnCCD.0'
00027     dsname, src = '/reg/g/psdm/detector/data_test/types/0010-Camp.0-pnCCD.0.xtc', 'Camp.0:pnCCD.0'
00028     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/pnccd/amo86615-pnccd-2015-09-09/calib')
00029 
00030 elif ntest==4 : #dsname, src = 'exp=xppi0614:run=74',  'NoDetector.0:Epix100a.0'
00031     dsname, src = '/reg/g/psdm/detector/data_test/types/0007-NoDetector.0-Epix100a.0.xtc', 'NoDetector.0:Epix100a.0'
00032     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/epix100/xpp-epix100a-2014-12-04/calib')
00033 
00034 elif ntest==5 :
00035     #dsname, src = 'exp=sxrg3715:run=46',  'SxrEndstation.0:Andor.2'
00036     dsname, src = '/reg/g/psdm/detector/data_test/types/0013-SxrEndstation.0-Andor.0.xtc', 'SxrEndstation.0:Andor.0' 
00037     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/andor/calib')
00038 
00039 #elif ntest==6 : dsname, src = 'exp=sxrf9414:run=72',  'SxrEndstation.0:Fccd960.0'
00040 
00041 elif ntest==7 : #dsname, src = 'exp=xcsi0112:run=15',  'XcsBeamline.0:Princeton.0'
00042     dsname, src = '/reg/g/psdm/detector/data_test/types/0012-XcsBeamline.0-Princeton.0.xtc', 'XcsBeamline.0:Princeton.0'
00043     psana.setOption('psana.calib-dir', '/reg/d/psdm/xcs/xcsi0112/calib')
00044 
00045 elif ntest==8 : #dsname, src = 'exp=amo42112:run=120', 'AmoBPS.0:Opal1000.0'
00046     dsname, src = '/reg/g/psdm/detector/data_test/types/0013-SxrBeamline.0-Opal1000.1.xtc', 'SxrBeamline.0:Opal1000.1'
00047 
00048 elif ntest==9 : #dsname, src = 'exp=cxib2313:run=46',  'CxiDg2.0:Tm6740.0'
00049     dsname, src = '/reg/g/psdm/detector/data_test/types/0015-Pulnix_TM6740ConfigV2.xtc', 'CxiSc1.0:Tm6740.0'
00050 
00051 elif ntest==10 : # dsname, src = 'exp=amo86615:run=4',   'Camp.0:pnCCD.0'
00052     dsname, src = '/reg/g/psdm/detector/data_test/types/0008-Camp.0-pnCCD.1.xtc', 'Camp.0:pnCCD.1'
00053     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/pnccd/amo86615-pnccd-2015-09-09/calib')
00054 
00055 elif ntest==11 : # dsname, src = 'exp=cxif5315:run=169', 'CxiDs2.0:Cspad.0' # string
00056     dsname, src = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc',  'CxiDs2.0:Cspad.0'
00057     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera2-2015-01-20/calib')
00058 
00059 elif ntest==12 : # dsname, src = 'exp=cxif5315:run=169', 'DsaCsPad'  # alias
00060     dsname, src = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc',  'DsaCsPad'
00061     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera2-2015-01-20/calib')
00062 
00063 #elif ntest==15 : dsname, src = 'exp=cxii8715:run=14',  'CxiEndstation.0:Quartz4A150.0' # alias='Sc1Questar'
00064 elif ntest==15 :
00065     dsname, src = '/reg/g/psdm/detector/data_test/types/0016-CxiEndstation.0-Quartz4A150.0.xtc', 'CxiEndstation.0:Quartz4A150.0'
00066     psana.setOption('psana.calib-dir', '/reg/d/psdm/cxi/cxii8715/calib')
00067 
00068 #elif ntest==16 : #dsname, src = 'exp=xppc0115:run=305', 'XppEndstation.0:Rayonix.0' # alias='rayonix'
00069 #elif ntest==16 : #dsname, src = 'exp=xppc0115:run=335', 'XppEndstation.0:Rayonix.0' # alias='rayonix'
00070 #    dsname, src = '/reg/g/psdm/detector/data_test/types/0011-XppEndstation.0-Rayonix.0.xtc', 'XppEndstation.0:Rayonix.0'
00071 #    # JUST A SUBSTITUTE FOR calib directory
00072 #    psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera2-2015-01-20/calib')
00073 
00074 elif ntest==16 : #dsname, src = 'exp=xppc0115:run=335', 'XppEndstation.0:Rayonix.0'
00075     dsname, src = '/reg/g/psdm/detector/data_test/types/0011-XppEndstation.0-Rayonix.0.xtc', 'XppEndstation.0:Rayonix.0'
00076     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/rayonix/calib')
00077 
00078 elif ntest==17 : # dsname, src = 'exp=amoj5415:run=49',  'pnccdFront'
00079     dsname, src = '/reg/g/psdm/detector/data_test/types/0009-pnccdFront.xtc', 'pnccdFront'
00080     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/pnccd/amo06516-pnccd-2016-04-14/calib')
00081 
00082 elif ntest==18 :
00083     dsname, src = '/reg/g/psdm/detector/data_test/types/0002-MecTargetChamber.0-Cspad.0-two-quads.xtc', 'MecTargetChamber.0:Cspad.0'
00084     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-mec-2015-06-08/calib')
00085 
00086 elif ntest==19 :
00087     dsname, src = '/reg/g/psdm/detector/data_test/types/0004-MecTargetChamber.0-Cspad.0-three-quads.xtc', 'MecTargetChamber.0:Cspad.0'
00088     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-mec-2015-06-08/calib')
00089 
00090 elif ntest==20 :   #The same as 'exp=cxif5315:run=169' but geometry is different
00091     dsname, src = '/reg/g/psdm/detector/data_test/types/0003-CxiDs2.0-Cspad.0-fiber-data.xtc',  'CxiDs2.0:Cspad.0'
00092     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/cspad/calib-cxi-camera2-2015-01-20/calib')
00093 
00094 elif ntest==21 : # dsname, src = 'exp=sxrk4816:run=3',  'SxrEndstation.0:DualAndor.0'
00095     dsname = '/reg/g/psdm/detector/data_test/types/0005-SxrEndstation.0-DualAndor.0.xtc' # exp=sxrk4816:run=3
00096     src = 'SxrEndstation.0:DualAndor.0'# or alias='andorDual'
00097     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/andor3d/calib-andor3d-2016-02-09/calib')
00098 
00099 elif ntest==22 : # dsname, src = 'exp=sxrk4816:run=7',  'SxrEndstation.0:DualAndor.0'
00100     dsname = '/reg/g/psdm/detector/data_test/types/0006-SxrEndstation.0-DualAndor.0.xtc' # exp=sxrk4816:run=7
00101     src = 'SxrEndstation.0:DualAndor.0'# or alias='andorDual'
00102     psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/andor3d/calib-andor3d-2016-02-09/calib')
00103 
00104 elif ntest==23 : #dsname, src = 'exp=mfxn8316:run=11',  'MfxEndstation.0:Epix100a.0'
00105     psana.setOption('psana.calib-dir', './calib') # dark exp=mfxn8316:run=9
00106     dsname, src = '/reg/g/psdm/detector/data_test/types/0021-MfxEndstation.0-Epix100a.0.xtc', 'MfxEndstation.0:Epix100a.0'
00107 
00108 else :
00109     print 'Example for\n dataset: %s\n source : %s \nis not implemented' % (dsname, src)
00110     sys.exit(0)
00111 
00112 #psana.setOption('psana.calib-dir', './calib')
00113 #psana.setOption('psana.calib-dir', './empty/calib')
00114 
00115 ds  = psana.DataSource(dsname)
00116 evt = ds.events().next()
00117 env = ds.env()
00118 nrun = evt.run()
00119 print 'Run number %d' % nrun
00120 
00121 for key in evt.keys() : print key
00122 
00123 ##-----------------------------
00124 
00125 par = nrun # evt or nrun
00126 par = evt
00127 det = psana.Detector(src, env)
00128 
00129 ins = det.instrument()
00130 print 80*'_', '\nInstrument: ', ins
00131 
00132 #det.set_print_bits(511)
00133 #det.set_def_value(-5.)
00134 #det.set_mode(1)
00135 #det.set_do_offset(True) # works for ex. Opal1000
00136 det.print_attributes()
00137 
00138 shape_nda = det.shape(par)
00139 print_ndarr(shape_nda, 'shape of ndarray')
00140 
00141 print 'size of ndarray: %d' % det.size(par)
00142 print 'ndim of ndarray: %d' % det.ndim(par)
00143 
00144 peds = det.pedestals(par)
00145 print_ndarr(peds, 'pedestals')
00146 
00147 rms = det.rms(par)
00148 print_ndarr(rms, 'rms')
00149 
00150 mask = det.mask(par, calib=False, status=True, edges=False, central=False, unbond=False, unbondnbrs=False)
00151 print_ndarr(mask, 'mask')
00152 
00153 gain = det.gain(par)
00154 print_ndarr(gain, 'gain')
00155 
00156 bkgd = det.bkgd(par)
00157 print_ndarr(bkgd, 'bkgd')
00158 
00159 status = det.status(par)
00160 print_ndarr(status, 'status')
00161 
00162 status_mask = det.status_as_mask(par)
00163 print_ndarr(status_mask, 'status_mask')
00164 
00165 cmod = det.common_mode(par)
00166 print_ndarr(cmod, 'common_mod')
00167 
00168 i=0
00169 nda_raw = None
00170 evt = None
00171 for i, evt in enumerate(ds.events()) :
00172     t0_sec = time()
00173     nda_raw = det.raw(evt)
00174     if nda_raw is not None :
00175         dt_sec = time()-t0_sec
00176         print 'Detector data found in event %d'\
00177               ' consumed time for det.raw(evt) = %7.3f sec' % (i, time()-t0_sec)
00178         break
00179 
00180 print_ndarr(nda_raw, 'raw data')
00181 
00182 if nda_raw is None :
00183     print 'Detector data IS NOT FOUND in %d events' % i
00184     sys.exit('FURTHER TEST IS TERMINATED')
00185 
00186 ##-----------------------------
00187 
00188 if peds is not None and nda_raw is not None : peds.shape = nda_raw.shape 
00189 
00190 data_sub_peds = nda_raw - peds if peds is not None else nda_raw
00191 print_ndarr(data_sub_peds, 'data - peds')
00192 
00193 nda_cdata = det.calib(evt)
00194 print_ndarr(nda_cdata, 'calibrated data')
00195 
00196 if det.dettype == gu.CSPAD \
00197 or det.dettype == gu.CSPAD2X2 :
00198     t0_sec = time()
00199     nda_cdata_ub = det.calib(evt, cmpars=(5,50))
00200     print_ndarr(nda_cdata_ub, 'calibrated cspad(2x2) data with unbond pixel common mode correction')
00201     print 'Consumed time for det.calib(evt) = %7.3f sec' % (time()-t0_sec)
00202 
00203 coords_x = det.coords_x(par)
00204 print_ndarr(coords_x, 'coords_x')
00205 
00206 ##-----------------------------
00207 #sys.exit('TEST EXIT')
00208 ##-----------------------------
00209 
00210 areas = det.areas(par)
00211 print_ndarr(areas, 'area')
00212 
00213 mask_geo = det.mask_geo(par)
00214 print_ndarr(mask_geo, 'mask_geo')
00215 
00216 #mask_geo.shape = (32,185,388)
00217 #print mask_geo
00218 
00219 pixel_size = det.pixel_size(par)
00220 print '%s\npixel size: %s' % (80*'_', str(pixel_size))
00221 
00222 ipx, ipy = det.point_indexes(par) # , pxy_um=(0,0)) 
00223 print 'Detector origin indexes: ix, iy:', ipx, ipy
00224 ##-----------------------------
00225 
00226 img_arr = data_sub_peds
00227 #img_arr = nda_cdata if nda_cdata is not None else nda_raw
00228 img = None
00229 
00230 # Image producer is different for 3-d and 2-d arrays 
00231 if len(nda_raw.shape) > 2 or det.dettype == gu.EPIX100A :
00232     #img = det.image(evt)
00233     
00234     t0_sec = time()
00235     #img = det.image(evt)
00236     img = det.image(evt, img_arr)
00237     print 'Consumed time for det.image(evt) = %7.3f sec (for 1st event!)' % (time()-t0_sec)
00238 else :
00239     img = img_arr
00240     img.shape = nda_raw.shape
00241 
00242 print_ndarr(img, 'image (calibrated data or raw)')
00243 
00244 print 80*'_'
00245 
00246 ##-----------------------------
00247 
00248 if img is None :
00249     sys.exit('Image is not available. FURTHER TEST IS TERMINATED')
00250 
00251 import pyimgalgos.GlobalGraphics as gg
00252 
00253 ave, rms = img.mean(), img.std()
00254 gg.plotImageLarge(img, amp_range=(ave-1*rms, ave+2*rms))
00255 gg.show()
00256 
00257 ##-----------------------------
00258 
00259 print_ndarr(det.image_xaxis(par), 'image_xaxis')
00260 print_ndarr(det.image_yaxis(par), 'image_yaxis')
00261 
00262 ##-----------------------------
00263 print 80*'_','\nTest do_reshape_2d_to_3d'
00264 
00265 print_ndarr(det.pedestals(par), 'pedestals w/o reshape')
00266 det.do_reshape_2d_to_3d(flag=True)
00267 print_ndarr(det.pedestals(par), 'pedestals reshaped to 3d')
00268 
00269 print_ndarr(img, 'img')
00270 print_ndarr(det.ndarray_from_image(par, img), 'nda_from_img')
00271 
00272 print 'det.shape_config(env): ', det.shape_config(env)
00273 print_ndarr(det.photons(evt), 'photons')
00274          
00275 ##-----------------------------
00276 
00277 sys.exit(0)
00278 
00279 ##-----------------------------

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7