Changeset 7241d56 in sasview


Ignore:
Timestamp:
Dec 21, 2010 9:46:10 AM (13 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:
98eefdb
Parents:
7342634
Message:

improved edge behavior of Qsmearer

Location:
DataLoader
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/extensions/smearer.cpp

    rf867cd9 r7241d56  
    285285                // Normalize counts 
    286286                iq_out[q_i] = (counts>0.0) ? sum/counts : 0; 
    287                 //printf("\n iii=%g,%g ",iq_out[q_i], q_i); 
    288287        } 
    289288} 
  • DataLoader/qsmearing.py

    rf867cd9 r7241d56  
    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 
     
    175175                                                        first_bin, last_bin) 
    176176            iq_in_low = self.model.evalDistribution( \ 
    177                                             self.qvalues[0:self.nbins_low]) 
     177                                    numpy.fabs(self.qvalues[0:self.nbins_low])) 
    178178            iq_in_high = self.model.evalDistribution( \ 
    179179                                            self.qvalues[(len(self.qvalues) - \ 
    180                                             self.nbins_high - 1): -1]) 
     180                                            self.nbins_high - 1):]) 
     181            # Todo: find out who is sending iq[last_poin] = 0. 
     182            if iq_in[len(iq_in) - 1] == 0: 
     183                iq_in[len(iq_in) - 1] = iq_in_high[0] 
     184            # Append the extrapolated points to the data points 
    181185            if self.nbins_low > 0:                              
    182186                iq_in_temp = numpy.append(iq_in_low, iq_in) 
    183187            if self.nbins_high > 0: 
    184                 iq_in_temp = numpy.append(iq_in_temp, iq_in_high) 
     188                iq_in_temp = numpy.append(iq_in_temp, iq_in_high[1:]) 
    185189        else: 
    186190            temp_first = first_bin 
    187191            temp_last = last_bin 
    188192            iq_in_temp = iq_in 
     193         
    189194        # Sanity check 
    190195        if len(iq_in_temp) != self.nbins: 
     
    203208            msg = "_BaseSmearer: could not smear, code = %g" % smear_output 
    204209            raise RuntimeError, msg 
    205          
    206          
     210 
    207211        temp_first += self.nbins_low 
    208         temp_last = self.nbins - (self.nbins_high + 1) 
    209  
    210         return iq_out[temp_first: (temp_last + 1)] 
     212        temp_last = self.nbins - self.nbins_high 
     213         
     214        return iq_out[temp_first: temp_last] 
    211215     
    212216    def _initialize_smearer(self): 
     
    256260        """ 
    257261        #  For the first bin 
    258         if first_bin > 0: 
    259             # In the case that doesn't need lower q extrapolation data  
    260             first_bin +=  self.nbins_low 
    261         else: 
    262             # In the case that needs low extrapolation data 
    263             first_bin = 0 
     262        # In the case that needs low extrapolation data 
     263        first_bin = 0 
    264264        # For last bin 
    265265        if last_bin >= self.nbins - (self.nbins_high + self.nbins_low + 1): 
     
    489489    # Length of the width 
    490490    length = len(width) 
    491     max_width = max(width) 
     491    width_low = math.fabs(width[0]) 
     492    width_high = math.fabs(width[length -1]) 
    492493    # Find bin sizes 
    493494    bin_size_low = math.fabs(data_x[1] - data_x[0]) 
    494     bin_size_high = math.fabs(data_x[length -1] - data_x[length -2]) 
     495    bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2]) 
     496    # Compare width(dQ) to the data bin size and take smaller one as the bin  
     497    # 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 
     503         
    495504    # Number of q points required below the 1st data point in order to extend 
    496505    # them 3 times of the width (std) 
    497     nbins_low = math.ceil(3 * max_width / bin_size_low) 
     506    nbins_low = math.ceil(3 * width_low / bin_size_low) 
    498507    # Number of q points required above the last data point 
    499     nbins_high = math.ceil(3 * max_width / (bin_size_high)) 
     508    nbins_high = math.ceil(3 * width_high / (bin_size_high)) 
    500509    # Make null q points         
    501510    extra_low = numpy.zeros(nbins_low) 
     
    509518        ind += 1 
    510519    # Remove the points <= 0 
    511     extra_low = extra_low[extra_low > 0] 
    512     nbins_low = len(extra_low) 
     520    #extra_low = extra_low[extra_low > 0] 
     521    #nbins_low = len(extra_low) 
    513522    # Reset ind for another extrapolation 
    514523    ind = 0 
     
    521530    data_x_ext = numpy.append(extra_low, data_x) 
    522531    data_x_ext = numpy.append(data_x_ext, extra_high) 
     532     
    523533    # Redefine extra_low and high based on corrected nbins   
    524534    # And note that it is not necessary for extra_width to be a non-zero       
Note: See TracChangeset for help on using the changeset viewer.