00001
00002
00003 """ SegGeometry - abstract class with interface description.
00004
00005 Methods of this class should be re-implemented in derived classes with name pattern SegGeometry<SensorVers>
00006 for pixel geometry description of all sensors.
00007 For example, CSPAD 2x1 sensor is implemented in class :py:class:`PSCalib.SegGeometryCspad2x1V1`.
00008 Access to all implemented sensors is available through the factory method in class :py:class:`PSCalib.SegGeometryStore`.
00009
00010
00011 Usage of interface methods::
00012
00013 from SegGeometryCspad2x1V1 import cspad2x1_one as sg
00014
00015 sg.print_seg_info(pbits=0377)
00016 size_arr = sg.size()
00017 rows = sg.rows()
00018 cols = sg.cols()
00019 shape = sg.shape()
00020 pix_size = sg.pixel_scale_size()
00021 area = sg.pixel_area_array()
00022 mask = sg.pixel_mask(mbits=0377)
00023 sizeX = sg.pixel_size_array('X')
00024 sizeX, sizeY, sizeZ = sg.pixel_size_array()
00025 X = sg.pixel_coord_array('X')
00026 X,Y,Z = sg.pixel_coord_array()
00027 xmin = sg.pixel_coord_min('X')
00028 ymax = sg.pixel_coord_max('Y')
00029 xmin, ymin, zmin = sg.pixel_coord_min()
00030 xmax, ymax, zmax = sg.pixel_coord_mas()
00031 ...
00032 print 'X.shape =', X.shape
00033
00034
00035 @see :py:class:`PSCalib.SegGeometry`, :py:class:`PSCalib.SegGeometryCspad2x1V1`, :py:class:`PSCalib.SegGeometryStore`
00036
00037 This software was developed for the SIT project.
00038 If you use all or part of it, please give an appropriate acknowledgment.
00039
00040 Revision: $Revision: 10629 $
00041
00042 @version $Id: SegGeometry.py 10629 2015-08-27 23:05:30Z dubrovin@SLAC.STANFORD.EDU $
00043
00044 @author Mikhail S. Dubrovin
00045 """
00046
00047 __version__ = "$Revision: 10629 $"
00048
00049
00050 import sys
00051
00052
00053
00054
00055
00056
00057 def rotation(X, Y, C, S) :
00058 """For numpy arrays X and Y returns the numpy arrays of Xrot and Yrot
00059 """
00060 Xrot = X*C - Y*S
00061 Yrot = Y*C + X*S
00062 return Xrot, Yrot
00063
00064
00065
00066 class SegGeometry :
00067 AXIS = ['X', 'Y', 'Z']
00068 DIC_AXIS = {'X':0, 'Y':1, 'Z':2}
00069 wmsg = 'WARNING! %s - interface method from the base class \nneeds to be re-implemented in the derived class'
00070
00071 def __init__(self) :
00072 pass
00073
00074
00075
00076 def print_seg_info(self, pbits=0) :
00077 """ Prints segment info for selected bits
00078 """
00079 print self.wmsg % 'print_seg_info(pbits=0)'
00080
00081 def size(self) :
00082 """ Returns segment size - total number of pixels in segment
00083 """
00084 print self.wmsg % 'size()'
00085
00086 def rows(self) :
00087 """ Returns number of rows in segment
00088 """
00089 print self.wmsg % 'rows()'
00090
00091 def cols(self) :
00092 """ Returns number of cols in segment
00093 """
00094 print self.wmsg % 'cols()'
00095
00096 def shape(self) :
00097 """ Returns shape of the segment [rows, cols]
00098 """
00099 print self.wmsg % 'shape()'
00100
00101 def pixel_scale_size(self) :
00102 """ Returns pixel size in um for indexing
00103 """
00104 print self.wmsg % 'pixel_scale_size()'
00105
00106 def pixel_area_array(self) :
00107 """ Returns array of pixel relative areas of shape=[rows, cols]
00108 """
00109 print self.wmsg % 'pixel_area_array()'
00110
00111 def pixel_size_array(self, axis) :
00112 """ Returns array of pixel size in um for AXIS
00113 """
00114 print self.wmsg % 'pixel_size_array(axis)'
00115
00116 def pixel_coord_array(self, axis) :
00117 """ Returns array of segment pixel coordinates in um for AXIS
00118 """
00119 print self.wmsg % 'pixel_coord_array(axis)'
00120
00121 def pixel_coord_min(self, axis) :
00122 """ Returns minimal value in the array of segment pixel coordinates in um for AXIS
00123 """
00124 print self.wmsg % 'pixel_coord_min(axis)'
00125
00126 def pixel_coord_max(self, axis) :
00127 """ Returns maximal value in the array of segment pixel coordinates in um for AXIS
00128 """
00129 print self.wmsg % 'pixel_coord_max(axis)'
00130
00131 def pixel_mask_array(self, mbits) :
00132 """ Returns array of masked pixels which content depends on bontrol bitword mbits
00133 """
00134 print self.wmsg % 'pixel_mask_array(mask_bits)'
00135
00136 def return_switch(sp, meth, axis=None) :
00137 """ Returns three x,y,z arrays if axis=None, or single array for specified axis
00138 """
00139 if axis is None : return meth()
00140 else : return dict( zip( sp.AXIS, meth() ))[axis]
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 if __name__ == "__main__" :
00155 print 'Module %s describes interface methods for segment pixel geometry' % sys.argv[0]
00156
00157 sg = SegGeometry()
00158 sg.print_seg_info()
00159 sg.size()
00160 sys.exit ('End of %s' % sys.argv[0])
00161
00162
00163
00164
00165
00166