- Timestamp:
- 03/26/12 13:32:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/image_extractors.py
r13182 r13229 42 42 43 43 """ 44 def __init__(self ):44 def __init__(self, source_pos = (0,0)): 45 45 self.coordinator = Coordinator() 46 self. chid2coor = self.coordinator.chid2coor_np47 pass46 self._chid2coor = self.coordinator.chid2coor_np 47 self.source_pos = source_pos 48 48 49 49 def __call__(self, survivors, amplitude): … … 53 53 self._CalculateSize() 54 54 self._CalculateCOG() 55 self._CaluculateCovarianceMatrix() 55 self._CalculateHillas() 56 57 return self.__dict__ 56 58 57 59 def _CalculateSize(self): … … 70 72 survivors = self.survivors 71 73 amplitude = self.amplitude 72 chid2coor = self. chid2coor74 chid2coor = self._chid2coor 73 75 center = self.coordinator.center 74 76 ex = np.array(self.coordinator.ex) … … 87 89 88 90 89 def _Cal uculateCovarianceMatrix(self):90 """ calculates the covariance matrix91 def _CalculateHillas(self): 92 """ calculates Hillas parameters as explained in TBs dissertation on page: 42 91 93 """ 92 # shortcuts94 # define a few shortcuts 93 95 survivors = self.survivors 94 96 amplitude = self.amplitude 95 chid2coor = self. chid2coor97 chid2coor = self._chid2coor 96 98 cog_euc = self.cog_euc 97 99 S = self.size … … 99 101 ex = np.array(self.coordinator.ex) 100 102 ey = np.array(self.coordinator.ey) 103 source_pos = self.source_pos 101 104 102 # make new 2x2 covarianz matrix 103 cov = np.zeros( (2,2) ) 105 # calculate matrix elements 106 107 Mxx = 0. 108 Myy = 0. 109 Mxy = 0. 104 110 for pixel in survivors: 105 111 # hex coordinates … … 109 115 rel_coor = coor - cog_euc 110 116 111 # make new 2x2 matrix 112 mi = np.ones( (2,2) ) 113 # ugly ! ... 114 mi[0][0] = rel_coor[0] * rel_coor[0] 115 mi[0][1] = rel_coor[0] * rel_coor[1] 116 mi[1][0] = rel_coor[1] * rel_coor[0] 117 mi[1][1] = rel_coor[1] * rel_coor[1] 118 mi *= amplitude[pixel] 119 #print mi , amplitude[pixel] 120 cov += mi 121 self.cov = cov 122 123 #more funny shortcuts 124 Mxx = cov[0][0] 125 Myy = cov[1][1] 126 Mxy = cov[0][1] 127 128 #print 'corariance matrix' 129 #print cov 117 118 mxx = rel_coor[0] * rel_coor[0] * amplitude[pixel] 119 mxy = rel_coor[0] * rel_coor[1] * amplitude[pixel] 120 myy = rel_coor[1] * rel_coor[1] * amplitude[pixel] 121 122 Mxx += mxx 123 Myy += myy 124 Mxy += mxy 125 self.Mxx = Mxx 126 self.Mxy = Mxy 127 self.Myy = Myy 128 129 130 130 # use the covariance matrix to calulate the number TB also cals in his thesis 131 131 radicand = (Myy-Mxx)**2 + 4*Mxy**2 132 132 k = np.sqrt(radicand) + (Myy - Mxx) 133 print 'k:',k133 self.k = k 134 134 tan_delta = k / (2*Mxy ) 135 135 if tan_delta > 0: … … 138 138 delta_in_rad = np.arctan ( tan_delta ) + np.pi 139 139 delta_in_deg = delta_in_rad / np.pi * 180 140 print 'delta_in_rad' , delta_in_rad 141 print 'delta_in_deg' , delta_in_deg 140 #print 'delta_in_rad' , delta_in_rad 141 #print 'delta_in_deg' , delta_in_deg 142 self.delta = delta_in_rad 142 143 143 144 # width … … 145 146 denominiator = (tan_delta**2 + 1) * S 146 147 width = np.sqrt(numerator / denominiator) 148 self.width = width 147 149 148 150 #length … … 150 152 denominiator = (tan_delta**2 + 1) * S 151 153 length = np.sqrt(numerator / denominiator) 154 self.length = length 152 155 153 156 # make strange rotation matrix .. called capital R in TBs diss … … 155 158 d = delta_in_rad 156 159 R = np.array( ((np.cos(d), np.sin(d)),(-np.sin(d), np.cos(d))) ) 157 160 self.R = R 158 161 # calculate vector v between COG of shower and source position 159 162 # currently I don't know the cource position, so I use the center of the camera 160 v = cog_euc - np.array( [0,10] ) 163 164 v = cog_euc - source_pos 161 165 # and calculate some strange vertor r = R v 162 166 r = (R*v).sum(axis=1) 163 print 'r',r 164 167 #print 'r',r 168 self.v = v 169 self.r = r 165 170 #dist 166 171 dist = np.sqrt( v[0]**2 + v[1]**2 ) 167 print 'dist', dist 172 self.dist = dist 173 #print 'dist', dist 168 174 169 175 #alpha 170 176 alpha = np.arcsin( r[1] / dist) 171 177 alpha_in_deg = alpha / np.pi * 180 172 print 'alpha', alpha 173 print 'alpha_in_deg ', alpha_in_deg 178 self.alpha = alpha 179 #print 'alpha', alpha 180 #print 'alpha_in_deg ', alpha_in_deg 174 181 182 area = np.pi * width * length 183 self.area = area 175 184 176 185 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.