00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 """
00011 :py:class:`PSCalib.CalibParsStore` - is a factory class/method to switch between different device-dependent
00012 segments/sensors to access their pixel geometry uling :py:class:`PSCalib.SegGeometry` interface.
00013
00014 Usage::
00015
00016 # Import
00017 from PSCalib.CalibParsStore import cps
00018 from PSCalib.GlobalUtils import *
00019
00020 # Initialization
00021 calibdir = env.calibDir() # or e.g. '/reg/d/psdm/<INS>/<experiment>/calib'
00022 group = None # or e.g. 'CsPad::CalibV1'
00023 source = 'Camp.0:pnCCD.1'
00024 runnum = 10 # or e.g. evt.run()
00025 pbits = 255
00026 o = cps.Create(calibdir, group, source, runnum, pbits)
00027
00028 # or using different list of parameters to access calibration from hdf5 DCS file:
00029 o = cps.CreateForEvtEnv(self, calibdir, group, source, evt, env, pbits=0)
00030
00031 # Access methods
00032 nda = o.pedestals()
00033 nda = o.pixel_status()
00034 nda = o.pixel_rms()
00035 nda = o.pixel_mask()
00036 nda = o.pixel_gain()
00037 nda = o.pixel_bkgd()
00038 nda = o.common_mode()
00039
00040 status = o.status(ctype=PEDESTALS) # see list of ctypes in :py:class:`PSCalib.GlobalUtils`
00041 shape = o.shape(ctype)
00042 size = o.size(ctype)
00043 ndim = o.ndim(ctype)
00044
00045 @see
00046 :py:class:`PSCalib.GenericCalibPars`
00047 :py:class:`PSCalib.GlobalUtils`
00048 :py:class:`PSCalib.CalibPars`
00049 :py:class:`PSCalib.CalibParsStore`
00050 :py:class:`PSCalib.CalibParsBaseAndorV1`
00051 :py:class:`PSCalib.CalibParsBaseAndor3dV1`
00052 :py:class:`PSCalib.CalibParsBaseCameraV1`
00053 :py:class:`PSCalib.CalibParsBaseCSPad2x2V1`
00054 :py:class:`PSCalib.CalibParsBaseCSPadV1`
00055 :py:class:`PSCalib.CalibParsBaseEpix100aV1`
00056 :py:class:`PSCalib.CalibParsBasePnccdV1`
00057 :py:class:`PSCalib.CalibParsBasePrincetonV1`
00058 :py:class:`PSCalib.CalibParsBaseAcqirisV1`
00059 :py:class:`PSCalib.CalibParsBaseImpV1`
00060
00061 This software was developed for the SIT project. If you use all or
00062 part of it, please give an appropriate acknowledgment.
00063
00064 @version $Id: 2013-03-08$
00065
00066 @author Mikhail S. Dubrovin
00067 """
00068
00069
00070
00071
00072 __version__ = "$Revision: 12930 $"
00073
00074
00075
00076 import sys
00077
00078
00079
00080
00081
00082
00083 import PSCalib.GlobalUtils as gu
00084 from PSCalib.GenericCalibPars import GenericCalibPars
00085
00086 from PSCalib.CalibParsBaseAndorV1 import CalibParsBaseAndorV1
00087 from PSCalib.CalibParsBaseAndor3dV1 import CalibParsBaseAndor3dV1
00088 from PSCalib.CalibParsBaseCameraV1 import CalibParsBaseCameraV1
00089 from PSCalib.CalibParsBaseCSPad2x2V1 import CalibParsBaseCSPad2x2V1
00090 from PSCalib.CalibParsBaseCSPadV1 import CalibParsBaseCSPadV1
00091 from PSCalib.CalibParsBaseEpix100aV1 import CalibParsBaseEpix100aV1
00092 from PSCalib.CalibParsBasePnccdV1 import CalibParsBasePnccdV1
00093 from PSCalib.CalibParsBasePrincetonV1 import CalibParsBasePrincetonV1
00094 from PSCalib.CalibParsBaseAcqirisV1 import CalibParsBaseAcqirisV1
00095 from PSCalib.CalibParsBaseImpV1 import CalibParsBaseImpV1
00096
00097
00098
00099 class CalibParsStore() :
00100 """Factory class for CalibPars object of different detectors"""
00101
00102
00103
00104 def __init__(self) :
00105 self.name = self.__class__.__name__
00106 self.fnexpc = None
00107 self.fnrepo = None
00108 self.tsec = None
00109
00110
00111
00112
00113
00114 def Create(self, calibdir, group, source, runnum, pbits=0) :
00115 """ Factory method
00116
00117 Parameters
00118
00119 calibdir : string - calibration directory, ex: /reg/d/psdm/AMO/amoa1214/calib
00120 group : string - group, ex: PNCCD::CalibV1
00121 source : string - data source, ex: Camp.0:pnCCD.0
00122 runnum : int - run number, ex: 10
00123 pbits=0 : int - print control bits, ex: 255
00124 """
00125
00126 dettype = gu.det_type_from_source(source)
00127 grp = group if group is not None else gu.dic_det_type_to_calib_group[dettype]
00128
00129 if pbits : print '%s: Detector type = %d: %s' % (self.name, dettype, gu.dic_det_type_to_name[dettype])
00130
00131 cbase = None
00132 if dettype == gu.CSPAD : cbase = CalibParsBaseCSPadV1()
00133 elif dettype == gu.CSPAD2X2 : cbase = CalibParsBaseCSPad2x2V1()
00134 elif dettype == gu.PNCCD : cbase = CalibParsBasePnccdV1()
00135 elif dettype == gu.PRINCETON : cbase = CalibParsBasePrincetonV1()
00136 elif dettype == gu.ANDOR3D : cbase = CalibParsBaseAndor3dV1()
00137 elif dettype == gu.ANDOR : cbase = CalibParsBaseAndorV1()
00138 elif dettype == gu.EPIX100A : cbase = CalibParsBaseEpix100aV1()
00139 elif dettype == gu.ACQIRIS : cbase = CalibParsBaseAcqirisV1()
00140 elif dettype == gu.IMP : cbase = CalibParsBaseImpV1()
00141 elif dettype in (gu.OPAL1000,\
00142 gu.OPAL2000,\
00143 gu.OPAL4000,\
00144 gu.OPAL8000,\
00145 gu.TM6740,\
00146 gu.ORCAFL40,\
00147 gu.FCCD960,\
00148 gu.QUARTZ4A150,\
00149 gu.RAYONIX,\
00150 gu.FCCD,\
00151 gu.TIMEPIX,\
00152 gu.FLI,\
00153 gu.PIMAX) : cbase = CalibParsBaseCameraV1()
00154
00155 else :
00156 print 'Calibration parameters for source: %s are not implemented in class %s' % (source, self.__class__.__name__)
00157
00158 return GenericCalibPars(cbase, calibdir, grp, source, runnum, pbits, self.fnexpc, self.fnrepo, tsec=self.tsec)
00159
00160
00161
00162 def CreateForEvtEnv(self, calibdir, group, source, evt, env, pbits=0) :
00163 """ Factory method
00164 This method makes access to the calibration store with fallback access to hdf5 file.
00165
00166 Parameters
00167
00168 calibdir : string - calibration directory, ex: /reg/d/psdm/AMO/amoa1214/calib
00169 group : string - group, ex: PNCCD::CalibV1
00170 source : string - data source, ex: Camp.0:pnCCD.0
00171 evt : psana.Event - event object - is used to get event time to retrieve DCRange
00172 env : psana.Env - environment object - is used to retrieve file name
00173 pbits=0 : int - print control bits, ex: 255
00174 """
00175
00176 runnum = evt if isinstance(evt, int) else evt.run()
00177
00178 if not isinstance(evt, int) :
00179
00180 from PSCalib.DCFileName import DCFileName
00181 from PSCalib.DCUtils import evt_time
00182
00183 ofn = DCFileName(env, source, calibdir)
00184 if pbits & 512 : ofn.print_attrs()
00185 self.fnexpc = ofn.calib_file_path()
00186 self.fnrepo = ofn.calib_file_path_repo()
00187 self.tsec = evt_time(evt)
00188
00189
00190 if pbits :
00191 print '%s.CreateForEvtEnv: for tsec: %s' % (self.name, str(self.tsec))
00192 print ' expected hdf5 file name local: %s' % (self.fnexpc)
00193 print ' expected hdf5 file name repo : %s' % (self.fnrepo)
00194
00195 return self.Create(calibdir, group, source, runnum, pbits)
00196
00197
00198
00199 cps = CalibParsStore()
00200
00201
00202
00203
00204
00205
00206
00207 import numpy as np
00208
00209 def print_nda(nda, cmt='') :
00210 arr = nda if isinstance(nda, np.ndarray) else np.array(nda)
00211 str_arr = str(arr) if arr.size<5 else str(arr.flatten()[0:5])
00212 print '%s %s: shape=%s, size=%d, dtype=%s, data=%s' % \
00213 (cmt, type(nda), str(arr.shape), arr.size, str(arr.dtype), str_arr)
00214
00215
00216
00217 def test_cps() :
00218
00219 if len(sys.argv)==1 : print 'For test(s) use command: python %s <test-number=1-3>' % sys.argv[0]
00220
00221 calibdir = '/reg/d/psdm/CXI/cxif5315/calib'
00222 group = None
00223 source = 'CxiDs2.0:Cspad.0'
00224 runnum = 60
00225 pbits = 0
00226
00227 if(sys.argv[1]=='1') :
00228 cp = cps.Create(calibdir, group, source, runnum, pbits)
00229 cp.print_attrs()
00230
00231 print_nda(cp.pedestals(), 'pedestals')
00232 print_nda(cp.pixel_rms(), 'pixel_rms')
00233 print_nda(cp.pixel_mask(), 'pixel_mask')
00234 print_nda(cp.pixel_status(), 'pixel_status')
00235 print_nda(cp.pixel_gain(), 'pixel_gain')
00236 print_nda(cp.common_mode(), 'common_mode')
00237 print_nda(cp.pixel_bkgd(), 'pixel_bkgd')
00238 print_nda(cp.shape(), 'shape')
00239
00240 print 'size=%d' % cp.size()
00241 print 'ndim=%d' % cp.ndim()
00242
00243 statval = cp.status(gu.PEDESTALS)
00244 print 'status(PEDESTALS)=%d: %s' % (statval, gu.dic_calib_status_value_to_name[statval])
00245
00246 statval = cp.status(gu.PIXEL_GAIN)
00247 print 'status(PIXEL_GAIN)=%d: %s' % (statval, gu.dic_calib_status_value_to_name[statval])
00248
00249 else : print 'Non-expected arguments: sys.argv = %s use 1,2,...' % sys.argv
00250
00251
00252
00253 if __name__ == "__main__" :
00254 test_cps()
00255 sys.exit( 'End of %s test.' % sys.argv[0])
00256
00257