Changeset 535752b in sasview


Ignore:
Timestamp:
Jan 6, 2011 2:45:07 PM (14 years ago)
Author:
Jae Cho <jhjcho@…>
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:
d6da3b1
Parents:
1cc23fd
Message:

Added extrapolation for SlitSmearer?

Location:
DataLoader
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/extensions/smearer.hh

    ra378756 r535752b  
    6161protected: 
    6262    // Number of points used in the smearing computation 
    63     static const int npts   = 1000; 
     63    static const int npts   = 2000; 
    6464 
    6565public: 
  • DataLoader/qsmearing.py

    r7241d56 r535752b  
    7979    # If we found slit smearing data, return a slit smearer 
    8080    if _found_slit == True: 
    81         return SlitSmearer(data1D) 
     81        return SlitSmearer(data1D, model) 
    8282    return None 
    8383             
     
    167167        if first_bin < 0: 
    168168            first_bin = 0 
    169          
     169 
    170170        # With a model given, compute I for the extrapolated points and append 
    171171        # to the iq_in 
    172         #iq_in_temp = iq_in 
     172        iq_in_temp = iq_in 
    173173        if self.model != None: 
    174174            temp_first, temp_last = self._get_extrapolated_bin( \ 
    175175                                                        first_bin, last_bin) 
    176             iq_in_low = self.model.evalDistribution( \ 
     176            if self.nbins_low > 1: 
     177                iq_in_low = self.model.evalDistribution( \ 
    177178                                    numpy.fabs(self.qvalues[0:self.nbins_low])) 
    178179            iq_in_high = self.model.evalDistribution( \ 
     
    190191            temp_first = first_bin 
    191192            temp_last = last_bin 
    192             iq_in_temp = iq_in 
     193            #iq_in_temp = iq_in 
    193194         
    194195        # Sanity check 
     
    211212        temp_first += self.nbins_low 
    212213        temp_last = self.nbins - self.nbins_high 
    213          
    214         return iq_out[temp_first: temp_last] 
     214        out = iq_out[temp_first: temp_last] 
     215 
     216        return out 
    215217     
    216218    def _initialize_smearer(self): 
     
    218220        """ 
    219221        return NotImplemented 
    220      
    221     def set_model(self, model): 
    222         """ 
    223         Set model 
    224         """ 
    225         if model != None: 
    226             self.model = model 
    227222             
    228223     
     
    300295        self.nbins  = nbins 
    301296        ## Number of points used in the smearing computation 
    302         self.npts   = 1000 
     297        self.npts   = 2000 
    303298        ## Smearing matrix 
    304299        self._weights = None 
     
    335330    Adaptor for slit smearing class and SANS data 
    336331    """ 
    337     def __init__(self, data1D): 
     332    def __init__(self, data1D, model = None): 
    338333        """ 
    339334        Assumption: equally spaced bins of increasing q-values. 
     
    348343        self.nbins_low = 0 
    349344        self.nbins_high = 0 
     345        self.model = model 
    350346        if data1D.dxw is not None and len(data1D.dxw) == len(data1D.x): 
    351347            self.width = data1D.dxw[0] 
     
    366362                    msg += " the same for all data" 
    367363                    raise RuntimeError, msg 
    368          
     364        # If a model is given, get the q extrapolation 
     365        if self.model == None: 
     366            data1d_x = data1D.x 
     367        else: 
     368            # Take larger sigma 
     369            if self.height > self.width: 
     370                # The denominator (2.0) covers all the possible w^2 + h^2 range 
     371                sigma_in = data1D.dxl / 2.0 
     372            elif self.width > 0: 
     373                sigma_in = data1D.dxw / 2.0 
     374            else: 
     375                sigma_in = [] 
     376 
     377            self.nbins_low, self.nbins_high, _, data1d_x = \ 
     378                                get_qextrapolate(sigma_in, data1D.x) 
     379 
    369380        ## Number of Q bins 
    370         self.nbins = len(data1D.x) 
     381        self.nbins = len(data1d_x) 
    371382        ## Minimum Q  
    372         self.min = min(data1D.x) 
     383        self.min = min(data1d_x) 
    373384        ## Maximum 
    374         self.max = max(data1D.x) 
     385        self.max = max(data1d_x) 
    375386        ## Q-values 
    376         self.qvalues = data1D.x 
     387        self.qvalues = data1d_x 
    377388         
    378389 
     
    491502    width_low = math.fabs(width[0]) 
    492503    width_high = math.fabs(width[length -1]) 
    493     # Find bin sizes 
    494     bin_size_low = math.fabs(data_x[1] - data_x[0]) 
    495     bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2]) 
     504     
    496505    # Compare width(dQ) to the data bin size and take smaller one as the bin  
    497506    # size of the extrapolation; this will correct some weird behavior  
    498     # at the edge 
    499     if width_low < (bin_size_low): 
    500         bin_size_low = width_low / 2.0 
    501     if width_high < (bin_size_high): 
    502         bin_size_high = width_high / 2.0 
     507    # at the edge: This method was out (commented)  
     508    # because it becomes very expansive when 
     509    # bin size is very small comparing to the width. 
     510    # Now on, we will just give the bin size of the extrapolated points  
     511    # based on the width. 
     512    # Find bin sizes 
     513    #bin_size_low = math.fabs(data_x[1] - data_x[0]) 
     514    #bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2]) 
     515    # Let's set the bin size 1/3 of the width(sigma), it is good as long as 
     516    # the scattering is monotonous. 
     517    #if width_low < (bin_size_low): 
     518    bin_size_low = width_low / 10.0 
     519    #if width_high < (bin_size_high): 
     520    bin_size_high = width_high / 10.0 
    503521         
    504522    # Number of q points required below the 1st data point in order to extend 
    505523    # them 3 times of the width (std) 
    506     nbins_low = math.ceil(3 * width_low / bin_size_low) 
     524    nbins_low = math.ceil(3.0 * width_low / bin_size_low) 
    507525    # Number of q points required above the last data point 
    508     nbins_high = math.ceil(3 * width_high / (bin_size_high)) 
     526    nbins_high = math.ceil(3.0 * width_high / (bin_size_high)) 
    509527    # Make null q points         
    510528    extra_low = numpy.zeros(nbins_low) 
     
    513531    ind = 0 
    514532    qvalue = data_x[0] - bin_size_low 
     533    #if qvalue > 0: 
    515534    while(ind < nbins_low): 
    516535        extra_low[nbins_low - (ind + 1)] = qvalue 
    517536        qvalue -= bin_size_low 
    518537        ind += 1 
    519     # Remove the points <= 0 
    520     #extra_low = extra_low[extra_low > 0] 
    521     #nbins_low = len(extra_low) 
     538        #if qvalue <= 0: 
     539        #    break 
     540    # Redefine nbins_low 
     541    nbins_low = ind 
    522542    # Reset ind for another extrapolation 
    523543    ind = 0 
     
    528548        ind += 1 
    529549    # Make a new qx array 
    530     data_x_ext = numpy.append(extra_low, data_x) 
     550    if nbins_low > 0:   
     551        data_x_ext = numpy.append(extra_low, data_x) 
     552    else: 
     553        data_x_ext = data_x 
    531554    data_x_ext = numpy.append(data_x_ext, extra_high) 
    532555     
    533556    # Redefine extra_low and high based on corrected nbins   
    534     # And note that it is not necessary for extra_width to be a non-zero       
    535     extra_low = numpy.zeros(nbins_low) 
     557    # And note that it is not necessary for extra_width to be a non-zero  
     558    if nbins_low > 0:      
     559        extra_low = numpy.zeros(nbins_low) 
    536560    extra_high = numpy.zeros(nbins_high)  
    537561    # Make new width array 
    538562    new_width = numpy.append(extra_low, width) 
    539563    new_width = numpy.append(new_width, extra_high) 
    540  
    541     return  nbins_low, nbins_high, new_width, data_x_ext 
     564     
     565    # nbins corrections due to the negative q value 
     566    nbins_low = nbins_low - len(data_x_ext[data_x_ext<0]) 
     567    return  nbins_low, nbins_high, \ 
     568             new_width[data_x_ext>0], data_x_ext[data_x_ext>0] 
    542569     
    543570if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.