Changeset 5062bbf in sasview for sansview/perspectives/fitting/model_thread.py
- Timestamp:
- Jun 7, 2010 10:26:43 AM (14 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:
- b94945d
- Parents:
- 79ac6f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/model_thread.py
rf72333f r5062bbf 1 2 1 3 import time 2 4 from data_util.calcthread import CalcThread … … 4 6 import numpy,math 5 7 from DataLoader.smearing_2d import Smearer2D 6 import fitpage 8 7 9 class Calc2D(CalcThread): 8 10 """ 9 Compute 2D model 10 This calculation assumes a 2-fold symmetry of the model 11 where points are computed for one half of the detector 12 and I(qx, qy) = I(-qx, -qy) is assumed. 13 """ 14 11 Compute 2D model 12 This calculation assumes a 2-fold symmetry of the model 13 where points are computed for one half of the detector 14 and I(qx, qy) = I(-qx, -qy) is assumed. 15 """ 15 16 def __init__(self, x, y, data,model,smearer,qmin, qmax,qstep, 16 17 completefn = None, … … 37 38 def compute(self): 38 39 """ 39 40 Compute the data given a model function 40 41 """ 41 42 self.starttime = time.time() … … 125 126 126 127 class Calc1D(CalcThread): 127 """Compute 1D data""" 128 128 """ 129 Compute 1D data 130 """ 129 131 def __init__(self, x, model, 130 132 data=None, … … 137 139 worktime = 0.01 138 140 ): 141 """ 142 """ 139 143 CalcThread.__init__(self,completefn, 140 144 updatefn, … … 151 155 def compute(self): 152 156 """ 153 Compute model 1d value given qmin , qmax , x value 154 """ 155 157 Compute model 1d value given qmin , qmax , x value 158 """ 156 159 self.starttime = time.time() 157 160 output = numpy.zeros((len(self.x))) … … 166 169 output[index] = self.model.evalDistribution(self.x[index]) 167 170 168 elapsed = time.time() -self.starttime171 elapsed = time.time() - self.starttime 169 172 170 self.complete(x= self.x[index], y=output[index],171 elapsed=elapsed,index=index, model= self.model, data=self.data)172 173 self.complete(x=self.x[index], y=output[index], 174 elapsed=elapsed,index=index, model=self.model, 175 data=self.data) 173 176 174 177 def results(self): 175 178 """ 176 179 Send resuts of the computation 177 180 """ 178 181 return [self.out, self.index] 179 180 class CalcCommandline: 181 def __init__(self, n=20000): 182 #print thread.get_ident() 183 from sans.models.CylinderModel import CylinderModel 184 185 model = CylinderModel() 186 182 183 """ 184 Example: :: 185 186 class CalcCommandline: 187 def __init__(self, n=20000): 188 #print thread.get_ident() 189 from sans.models.CylinderModel import CylinderModel 190 191 model = CylinderModel() 192 193 194 print model.runXY([0.01, 0.02]) 195 196 qmax = 0.01 197 qstep = 0.0001 198 self.done = False 199 200 x = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 201 y = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 202 203 204 calc_thread_2D = Calc2D(x, y, None, model.clone(),None, 205 -qmax, qmax,qstep, 206 completefn=self.complete, 207 updatefn=self.update , 208 yieldtime=0.0) 187 209 188 print model.runXY([0.01, 0.02]) 189 190 qmax = 0.01 191 qstep = 0.0001 192 self.done = False 193 194 x = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 195 y = numpy.arange(-qmax, qmax+qstep*0.01, qstep) 210 calc_thread_2D.queue() 211 calc_thread_2D.ready(2.5) 212 213 while not self.done: 214 time.sleep(1) 196 215 216 def update(self,output): 217 print "update" 197 218 198 calc_thread_2D = Calc2D(x, y, None, model.clone(),-qmax, qmax,qstep, 199 completefn=self.complete, 200 updatefn=self.update , 201 yieldtime=0.0) 202 203 calc_thread_2D.queue() 204 calc_thread_2D.ready(2.5) 205 206 while not self.done: 207 time.sleep(1) 208 209 def update(self,output): 210 print "update" 211 212 def complete(self, image, data, model, elapsed, qmin, qmax, qstep ): 213 print "complete" 214 self.done = True 215 216 if __name__ == "__main__": 217 CalcCommandline() 218 219 def complete(self, image, data, model, elapsed, qmin, qmax,index, qstep ): 220 print "complete" 221 self.done = True 222 223 if __name__ == "__main__": 224 CalcCommandline() 225 """
Note: See TracChangeset
for help on using the changeset viewer.