import time from calcthread import CalcThread import sys class Calc2D_all(CalcThread): """ Compute 2D model This calculation assumes a 2-fold symmetry of the model where points are computed for one half of the detector and I(qx, qy) = I(-qx, -qy) is assumed. """ def __init__(self, x, y, model, completefn = None, updatefn = None, yieldtime = 0.01, worktime = 0.01 ): CalcThread.__init__(self,completefn, updatefn, yieldtime, worktime) self.x = x self.y = y self.model = model self.starttime = 0 def isquit(self): try: CalcThread.isquit(self) except KeyboardInterrupt: wx.PostEvent(self.parent, StatusEvent(status=\ "Calc %s interrupted" % self.model.name)) raise KeyboardInterrupt def compute(self): import numpy x = self.x y = self.y output = numpy.zeros((len(x),len(y))) self.starttime = time.time() lx = len(self.x) #for i_x in range(int(len(self.x)/2)): for i_x in range(len(self.x)): if i_x%2==1: continue # Check whether we need to bail out self.update(output=output) self.isquit() for i_y in range(len(self.y)): value = self.model.runXY([self.x[i_x], self.y[i_y]]) output[i_y][i_x] = value #output[lx-i_y-1][lx-i_x-1] = value if lx%2==1: i_x = int(len(self.x)/2) for i_y in range(len(self.y)): value = self.model.runXY([self.x[i_x], self.y[i_y]]) output[i_y][i_x] = value #for i_x in range(int(len(self.x)/2)): for i_x in range(len(self.x)): if not i_x%2==1: continue # Check whether we need to bail out self.update(output=output) self.isquit() for i_y in range(len(self.y)): value = self.model.runXY([self.x[i_x], self.y[i_y]]) output[i_y][i_x] = value #output[lx-i_y-1][lx-i_x-1] = value elapsed = time.time()-self.starttime self.complete(output=output, elapsed=elapsed) class Calc2D(CalcThread): """ Compute 2D model This calculation assumes a 2-fold symmetry of the model where points are computed for one half of the detector and I(qx, qy) = I(-qx, -qy) is assumed. """ def __init__(self, x, y, data,model,qmin, qmax,qstep, completefn = None, updatefn = None, yieldtime = 0.01, worktime = 0.01 ): CalcThread.__init__(self,completefn, updatefn, yieldtime, worktime) self.qmin= qmin self.qmax= qmax self.qstep= qstep self.x = x self.y = y self.data= data ## the model on to calculate self.model = model self.starttime = 0 def isquit(self): try: CalcThread.isquit(self) except KeyboardInterrupt: wx.PostEvent(self.parent, StatusEvent(status=\ "Calc %s interrupted" % self.model.name)) raise KeyboardInterrupt def compute(self): """ Compute the data given a model function """ import numpy x = self.x y = self.y output = numpy.zeros((len(x),len(y))) if self.qmin==None: self.qmin = 0 if self.qmax== None: if data ==None: return newx= math.pow(max(math.fabs(data.xmax),math.fabs(data.xmin)),2) newy= math.pow(max(math.fabs(data.ymax),math.fabs(data.ymin)),2) self.qmax=math.sqrt( newx + newy ) self.starttime = time.time() lx = len(self.x) for i_x in range(len(self.x)): # Check whether we need to bail out self.update(output=output ) self.isquit() for i_y in range(int(len(self.y))): radius = self.x[i_x]*self.x[i_x]+self.y[i_y]*self.y[i_y] if self.qmin <= radius or radius<= self.qmax: value = self.model.runXY( [self.x[i_x], self.y[i_y]] ) output[i_x] [i_y]=value else: output[i_x] [i_y]=0 elapsed = time.time()-self.starttime self.complete( image = output, data = self.data , model = self.model, elapsed = elapsed, qmin = self.qmin, qmax =self.qmax, qstep = self.qstep ) class Calc2D_4fold(CalcThread): """ Compute 2D model This calculation assumes a 4-fold symmetry of the model. Really is the same calculation time since we have to calculate points for 0