Changeset 1b001a7 in sasview for sansview/perspectives/fitting
- Timestamp:
- Aug 6, 2009 10:18:36 AM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 30d103a
- Parents:
- 5b56b7a
- Location:
- sansview/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitting.py
r5612152 r1b001a7 1209 1209 1210 1210 except: 1211 msg= " Error occurred when drawing %s Model 2D: "%model.name 1212 msg+= " %s"%sys.exc_value 1213 wx.PostEvent( self.parent, StatusEvent(status= msg )) 1214 return 1211 raise 1212 #msg= " Error occurred when drawing %s Model 2D: "%model.name 1213 #msg+= " %s"%sys.exc_value 1214 #wx.PostEvent( self.parent, StatusEvent(status= msg )) 1215 #return 1215 1216 1216 1217 def _draw_model1D(self, model, data=None, smearer= None, … … 1262 1263 return 1263 1264 1264 1265 1266 def profile(fn, *args, **kw): 1267 import cProfile, pstats, os 1268 global call_result 1269 def call(): 1270 global call_result 1271 call_result = fn(*args, **kw) 1272 cProfile.runctx('call()', dict(call=call), {}, 'profile.out') 1273 stats = pstats.Stats('profile.out') 1274 stats.sort_stats('time') 1275 #stats.sort_stats('calls') 1276 stats.print_stats() 1277 os.unlink('profile.out') 1278 return call_result 1265 1279 if __name__ == "__main__": 1266 1280 i = Plugin() -
sansview/perspectives/fitting/model_thread.py
rf50330b7 r1b001a7 3 3 import sys 4 4 import numpy,math 5 6 class Calc2D_all(CalcThread):7 """8 Compute 2D model9 This calculation assumes a 2-fold symmetry of the model10 where points are computed for one half of the detector11 and I(qx, qy) = I(-qx, -qy) is assumed.12 """13 14 def __init__(self, x, y, model,15 completefn = None,16 updatefn = None,17 yieldtime = 0.01,18 worktime = 0.0119 ):20 CalcThread.__init__(self,completefn,21 updatefn,22 yieldtime,23 worktime)24 25 self.x = x26 self.y = y27 self.model = model28 self.starttime = 029 30 def compute(self):31 x = self.x32 y = self.y33 output = numpy.zeros((len(x),len(y)))34 35 self.starttime = time.time()36 lx = len(self.x)37 38 #for i_x in range(int(len(self.x)/2)):39 for i_x in range(len(self.x)):40 if i_x%2==1:41 continue42 43 # Check whether we need to bail out44 self.update(output=output)45 self.isquit()46 47 for i_y in range(len(self.y)):48 value = self.model.runXY([self.x[i_x], self.y[i_y]])49 output[i_y][i_x] = value50 #output[lx-i_y-1][lx-i_x-1] = value51 52 if lx%2==1:53 i_x = int(len(self.x)/2)54 for i_y in range(len(self.y)):55 value = self.model.runXY([self.x[i_x], self.y[i_y]])56 output[i_y][i_x] = value57 58 #for i_x in range(int(len(self.x)/2)):59 for i_x in range(len(self.x)):60 if not i_x%2==1:61 continue62 63 # Check whether we need to bail out64 self.update(output=output)65 self.isquit()66 67 for i_y in range(len(self.y)):68 value = self.model.runXY([self.x[i_x], self.y[i_y]])69 output[i_y][i_x] = value70 #output[lx-i_y-1][lx-i_x-1] = value71 72 elapsed = time.time()-self.starttime73 self.complete(output=output, elapsed=elapsed)74 75 5 76 6 class Calc2D(CalcThread): … … 95 25 self.qmax= qmax 96 26 self.qstep= qstep 97 self.x = x 98 self.y = y 27 # Reshape dimensions of x and y to call evalDistribution 28 self.x_array = numpy.reshape(x,[1,len(x)]) 29 self.y_array = numpy.reshape(y,[len(y),1]) 30 # Numpy array of dimensions 1 used for model.run method 31 self.x= numpy.array(x) 32 self.y= numpy.array(y) 99 33 self.data= data 100 # #the model on to calculate34 # the model on to calculate 101 35 self.model = model 102 36 self.starttime = 0 … … 106 40 Compute the data given a model function 107 41 """ 108 109 output = numpy.zeros((len(self.x),len(self.y)))42 self.starttime = time.time() 43 # Determine appropriate q range 110 44 if self.qmin==None: 111 45 self.qmin = 0 … … 115 49 newy= math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2) 116 50 self.qmax=math.sqrt( newx + newy ) 117 118 119 self.starttime = time.time() 120 lx = len(self.x) 51 # Define matrix where data will be plotted 52 radius= numpy.sqrt(self.x_array**2 + self.y_array**2) 53 index_data= (self.qmin<= radius) 54 index_model = (self.qmin <= radius)&(radius<= self.qmax) 55 56 try: 57 ## receive only list of 2 numpy array 58 ## One must reshape to vertical and the other to horizontal 59 value = self.model.evalDistribution([self.y_array,self.x_array] ) 60 ## for data ignore the qmax 61 if self.data == None: 62 # Only qmin value will be consider for the detector 63 output = value *index_data 64 else: 65 # The user can define qmin and qmax for the detector 66 output = value*index_model 67 except: 68 ## looping trough all x and y points 69 output= self.compute_point() 70 71 elapsed = time.time()-self.starttime 72 self.complete( image = output, 73 data = self.data , 74 model = self.model, 75 elapsed = elapsed, 76 qmin = self.qmin, 77 qmax =self.qmax, 78 qstep = self.qstep ) 79 80 def compute_point(self): 81 """ 82 Compute the data given a model function. Loop through each point 83 of x and y to compute the model 84 @return output : is a matrix of size x*y 85 """ 86 output = numpy.zeros((len(self.x),len(self.y))) 87 121 88 for i_x in range(len(self.x)): 122 89 # Check whether we need to bail out … … 138 105 output[i_y][i_x] =value 139 106 else: 140 output[i_y][i_x] =0 141 142 elapsed = time.time()-self.starttime 143 self.complete( image = output, 144 data = self.data , 145 model = self.model, 146 elapsed = elapsed, 147 qmin = self.qmin, 148 qmax =self.qmax, 149 qstep = self.qstep ) 150 151 152 class Calc2D_4fold(CalcThread): 153 """ 154 Compute 2D model 155 This calculation assumes a 4-fold symmetry of the model. 156 Really is the same calculation time since we have to 157 calculate points for 0<phi<pi anyway. 158 """ 159 160 def __init__(self, x, y, model, 161 completefn = None, 162 updatefn = None, 163 yieldtime = 0.01, 164 worktime = 0.01 165 ): 166 CalcThread.__init__(self,completefn, 167 updatefn, 168 yieldtime, 169 worktime) 170 self.x = x 171 self.y = y 172 self.model = model 173 self.starttime = 0 174 175 def compute(self): 176 x = self.x 177 y = self.y 178 output = numpy.zeros((len(x),len(y))) 179 180 self.starttime = time.time() 181 lx = len(self.x) 182 183 for i_x in range(int(len(self.x)/2)): 184 if i_x%2==1: 185 continue 186 187 # Check whether we need to bail out 188 self.update(output=output) 189 self.isquit() 190 191 for i_y in range(int(len(self.y)/2)): 192 value1 = self.model.runXY([self.x[i_x], self.y[i_y]]) 193 value2 = self.model.runXY([self.x[i_x], self.y[lx-i_y-1]]) 194 output[i_y][i_x] = value1 + value2 195 output[lx-i_y-1][lx-i_x-1] = value1 + value2 196 output[lx-i_y-1][i_x] = value1 + value2 197 output[i_y][lx-i_x-1] = value1 + value2 198 199 if lx%2==1: 200 i_x = int(len(self.x)/2) 201 for i_y in range(int(len(self.y)/2)): 202 value1 = self.model.runXY([self.x[i_x], self.y[i_y]]) 203 value2 = self.model.runXY([self.x[i_x], self.y[lx-i_y-1]]) 204 output[i_y][i_x] = value1 + value2 205 output[lx-i_y-1][lx-i_x-1] = value1 + value2 206 output[lx-i_y-1][i_x] = value1 + value2 207 output[i_y][lx-i_x-1] = value1 + value2 208 209 for i_x in range(int(len(self.x)/2)): 210 if not i_x%2==1: 211 continue 212 213 # Check whether we need to bail out 214 self.update(output=output) 215 self.isquit() 216 217 for i_y in range(int(len(self.y)/2)): 218 value1 = self.model.runXY([self.x[i_x], self.y[i_y]]) 219 value2 = self.model.runXY([self.x[i_x], self.y[lx-i_y-1]]) 220 output[i_y][i_x] = value1 + value2 221 output[lx-i_y-1][lx-i_x-1] = value1 + value2 222 output[lx-i_y-1][i_x] = value1 + value2 223 output[i_y][lx-i_x-1] = value1 + value2 224 225 elapsed = time.time()-self.starttime 226 self.complete(output=output, elapsed=elapsed) 227 228 107 output[i_y][i_x] =0 108 return output 109 110 229 111 230 112 class Calc1D(CalcThread): … … 245 127 yieldtime, 246 128 worktime) 247 self.x = x129 self.x = numpy.array(x) 248 130 self.data= data 249 131 self.qmin= qmin … … 257 139 Compute model 1d value given qmin , qmax , x value 258 140 """ 259 output = numpy.zeros(len(self.x)) 260 141 261 142 self.starttime = time.time() 262 143 144 try: 145 index= (self.qmin <= self.x)& (self.x <= self.qmax) 146 output = self.model.evalDistribution(self.x[index]) 147 except: 148 output= compute_point() 149 150 ##smearer the ouput of the plot 151 if self.smearer!=None: 152 output = self.smearer(output) #Todo: Why always output[0]=0??? 153 154 ######Temp. FIX for Qrange w/ smear. #ToDo: Should not pass all the data to 'run' or 'smear'... 155 new_index = (self.qmin > self.x) |(self.x > self.qmax) 156 output[new_index] = None 157 158 elapsed = time.time()-self.starttime 159 160 self.complete(x= self.x, y= output, 161 elapsed=elapsed, model= self.model, data=self.data) 162 163 def compute_point(self): 164 """ 165 Compute the data given a model function. Loop through each point 166 of x compute the model 167 @return output : is a numpy vector of size x 168 """ 169 output = numpy.zeros(len(self.x)) 170 # Loop through each q of data.x 263 171 for i_x in range(len(self.x)): 264 172 self.update(x= self.x, output=output ) … … 268 176 value = self.model.run(self.x[i_x]) 269 177 output[i_x] = value 270 271 ##smearer the ouput of the plot 272 if self.smearer!=None: 273 output = self.smearer(output) #Todo: Why always output[0]=0??? 274 275 ######Temp. FIX for Qrange w/ smear. #ToDo: Should not pass all the data to 'run' or 'smear'... 276 for i_x in range(len(self.x)): 277 if self.qmin > self.x[i_x] or self.x[i_x] > self.qmax: 278 output[i_x] = None 279 280 elapsed = time.time()-self.starttime 281 self.complete(x= self.x, y= output, 282 elapsed=elapsed, model= self.model, data=self.data) 283 284 285 178 179 return output 180 181 286 182 class CalcCommandline: 287 183 def __init__(self, n=20000): -
sansview/perspectives/fitting/models.py
r2b687dc r1b001a7 125 125 from sans.models.ParallelepipedModel import ParallelepipedModel 126 126 self.shape_list.append(ParallelepipedModel) 127 #self.multiplication_factor.append(ParallelepipedModel)128 127 129 128 from sans.models.CoreShellModel import CoreShellModel
Note: See TracChangeset
for help on using the changeset viewer.