<commit_before>import time
from data_util.calcthread import CalcThread
import sys
import numpy,math

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
        # Reshape dimensions of x and y to call evalDistribution
        #self.x_array = numpy.reshape(x,[len(x),1])
        #self.y_array = numpy.reshape(y,[1,len(y)])
        self.x_array = numpy.reshape(x,[1,len(x)])
        self.y_array = numpy.reshape(y,[len(y),1])
        # Numpy array of dimensions 1 used for model.run method
        self.x= numpy.array(x)
        self.y= numpy.array(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
        """
        self.starttime = time.time()
        # Determine appropriate q range
        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 )
        # Define matrix where data will be plotted        
        radius= numpy.sqrt( self.x_array**2 + self.y_array**2 )
        index_data= (self.qmin<= radius)
        index_model = (self.qmin <= radius)&(radius<= self.qmax)
       
        output = numpy.zeros((len(self.x),len(self.y)))
     
        ## receive only list of 2 numpy array 
        ## One must reshape to vertical and the other to horizontal
        value = self.model.evalDistribution([self.x_array,self.y_array] )
        ## for data ignore the qmax 
        if self.data == None:
            # Only qmin value will be consider for the detector
            output = value *index_data  
        else:
            # The user can define qmin and qmax for the detector
            output = index_model*value
      
        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 Calc1D(CalcThread):
    """Compute 1D data"""
    
    def __init__(self, x, model,
                 data=None,
                 qmin=None,
                 qmax=None,
                 smearer=None,
                 completefn = None,
                 updatefn   = None,
                 yieldtime  = 0.01,
                 worktime   = 0.01
                 ):
        CalcThread.__init__(self,completefn,
                 updatefn,
                 yieldtime,
                 worktime)
        self.x = numpy.array(x)
        self.data= data
        self.qmin= qmin
        self.qmax= qmax
        self.model = model
        self.smearer= smearer
        self.starttime = 0
        
    def compute(self):
        """
            Compute model 1d value given qmin , qmax , x value 
        """
        
        self.starttime = time.time()
        output = numpy.zeros((len(self.x)))
        index= (self.qmin <= self.x)& (self.x <= self.qmax)
        output[index] = self.model.evalDistribution(self.x[index])
     
        ##smearer the ouput of the plot    
        if self.smearer!=None:
            first_bin, last_bin = self.smearer.get_bin_range(self.qmin, self.qmax)
            output = self.smearer(output, first_bin, last_bin) 
         
        elapsed = time.time()-self.starttime
       
        self.complete(x= self.x[index], y= output[index], 
                      elapsed=elapsed, model= self.model, data=self.data)
        
 
                
class CalcCommandline:
    def __init__(self, n=20000):
        #print thread.get_ident()
        from sans.models.CylinderModel import CylinderModel
        
        model = CylinderModel()
        
         
        print model.runXY([0.01, 0.02])<commit_msg>sansview: fix plotting of smeared model <commit_after>import time
from data_util.calcthread import CalcThread
import sys
import numpy,math

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
        # Reshape dimensions of x and y to call evalDistribution
        #self.x_array = numpy.reshape(x,[len(x),1])
        #self.y_array = numpy.reshape(y,[1,len(y)])
        self.x_array = numpy.reshape(x,[1,len(x)])
        self.y_array = numpy.reshape(y,[len(y),1])
        # Numpy array of dimensions 1 used for model.run method
        self.x= numpy.array(x)
        self.y= numpy.array(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
        """
        self.starttime = time.time()
        # Determine appropriate q range
        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 )
        # Define matrix where data will be plotted        
        radius= numpy.sqrt( self.x_array**2 + self.y_array**2 )
        index_data= (self.qmin<= radius)
        index_model = (self.qmin <= radius)&(radius<= self.qmax)
       
        output = numpy.zeros((len(self.x),len(self.y)))
     
        ## receive only list of 2 numpy array 
        ## One must reshape to vertical and the other to horizontal
        value = self.model.evalDistribution([self.x_array,self.y_array] )
        ## for data ignore the qmax 
        if self.data == None:
            # Only qmin value will be consider for the detector
            output = value *index_data  
        else:
            # The user can define qmin and qmax for the detector
            output = index_model*value
      
        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 Calc1D(CalcThread):
    """Compute 1D data"""
    
    def __init__(self, x, model,
                 data=None,
                 qmin=None,
                 qmax=None,
                 smearer=None,
                 completefn = None,
                 updatefn   = None,
                 yieldtime  = 0.01,
                 worktime   = 0.01
                 ):
        CalcThread.__init__(self,completefn,
                 updatefn,
                 yieldtime,
                 worktime)
        self.x = numpy.array(x)
        self.data= data
        self.qmin= qmin
        self.qmax= qmax
        self.model = model
        self.smearer= smearer
        self.starttime = 0
        
    def compute(self):
        """
            Compute model 1d value given qmin , qmax , x value 
        """
        
        self.starttime = time.time()
        output = numpy.zeros((len(self.x)))
        index= (self.qmin <= self.x)& (self.x <= self.qmax)
     
        ##smearer the ouput of the plot    
        if self.smearer!=None:
            first_bin, last_bin = self.smearer.get_bin_range(self.qmin, self.qmax)
            output[first_bin:last_bin] = self.model.evalDistribution(self.x[first_bin:last_bin])
            output = self.smearer(output, first_bin, last_bin) 
        else:
            output[index] = self.model.evalDistribution(self.x[index])
         
        elapsed = time.time()-self.starttime
       
        self.complete(x= self.x[index], y= output[index], 
                      elapsed=elapsed, model= self.model, data=self.data)
        
 
                
class CalcCommandline:
    def __init__(self, n=20000):
        #print thread.get_ident()
        from sans.models.CylinderModel import CylinderModel
        
        model = CylinderModel()
        
         
        print model.runXY([0.01, 0.02])
{'fraction_non_alphanumeric': 0.0993280134397312, 'fraction_numerical': 0.00881982360352793, 'mean_word_length': 1.4947616553169198, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1206464', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2803, 'n_words': 668}