import time from data_util.calcthread import CalcThread import sys import numpy,math 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 compute(self): 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 compute(self): """ Compute the data given a model function """ output = numpy.zeros((len(self.x),len(self.y))) if self.qmin==None: self.qmin = 0 if self.qmax== None: if self.data !=None: newx= math.pow(max(math.fabs(self.data.xmax),math.fabs(self.data.xmin)),2) newy= math.pow(max(math.fabs(self.data.ymax),math.fabs(self.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 = math.sqrt(self.x[i_x]*self.x[i_x]+self.y[i_y]*self.y[i_y]) ## for data ignore the qmax if self.data == None: if self.qmin <= radius : value = self.model.runXY( [self.x[i_x], self.y[i_y]] ) output[i_y][i_x] =value else: output[i_y][i_x] =0 else: if self.qmin <= radius and radius<= self.qmax: value = self.model.runXY( [self.x[i_x], self.y[i_y]] ) output[i_y][i_x] =value else: output[i_y][i_x] =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