Detector/examples/ex_andor3d.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 
00008 #------------------------------
00009 
00010 ntest = int(sys.argv[1]) if len(sys.argv)>1 else 1
00011 print 'Test # %d' % ntest
00012 
00013 #------------------------------
00014 
00015 src = 'SxrEndstation.0:DualAndor.0' # or alias='andorDual'
00016 
00017 # (2,512,512)
00018 #dsname = 'exp=sxrk4816:run=7'
00019 dsname = '/reg/g/psdm/detector/data_test/types/0006-SxrEndstation.0-DualAndor.0.xtc'
00020 
00021 if ntest == 2 :
00022     # (2,2048,2048)
00023     #dsname = 'exp=sxrk4816:run=3'
00024     dsname = '/reg/g/psdm/detector/data_test/types/0005-SxrEndstation.0-DualAndor.0.xtc'
00025 
00026 psana.setOption('psana.calib-dir', '/reg/g/psdm/detector/alignment/andor3d/calib-andor3d-2016-02-09/calib')
00027 
00028 ds  = psana.DataSource(dsname)
00029 env = ds.env()
00030 nrun = ds.runs().next().run()
00031 
00032 print 'Example for\n  dataset: %s\n  source : %s\n  run number : %d\n  calib dir : %s'%\
00033       (dsname, src, nrun, env.calibDir())
00034 
00035 #------------------------------
00036 
00037 det = psana.Detector(src, env)
00038 
00039 print_ndarr(det.pedestals(nrun), '%s\npedestals' % (80*'_'))
00040 print 80*'_'
00041 
00042 i, evt, nda = 0, None, None
00043 
00044 for i, evt in enumerate(ds.events()) :
00045     #nda = det.raw(evt)
00046     nda = det.calib(evt)
00047     if nda is not None :
00048         for key in evt.keys() : print key
00049         print 'Detector data found in the event # %d' % i
00050         break
00051 
00052 print_ndarr(nda, 'nda')
00053 
00054 if nda is None :
00055     print 'Detector data IS NOT FOUND in %d events' % i
00056     sys.exit('FURTHER TEST IS TERMINATED')
00057 
00058 #------------------------------
00059 #print 'env.experiment(): ', env.experiment()
00060 #print 'env.instrument(): ', env.instrument()
00061 
00062 fname = 'nda-andor3d-%s-r%04d-%s.txt' % (env.experiment(), nrun, src.replace(":","-").replace(".","-"))
00063 det.save_txtnda(fname, nda, verbos=True)
00064 
00065 img = det.image(evt, nda)
00066 print_ndarr(img, '%s\nimage (calibrated data or raw)' % (80*'_') )
00067 
00068 #------------------------------
00069 import pyimgalgos.GlobalGraphics as gg
00070 
00071 ave, rms = img.mean(), img.std()
00072 gg.plotImageLarge(img, amp_range=(ave-1*rms, ave+2*rms), figsize=(16,7), window=(0.05,  0.05, 0.94, 0.92))
00073 gg.show()
00074 
00075 #------------------------------
00076 
00077 sys.exit('End of test.')
00078 
00079 #------------------------------

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7