Changeset 8ba103f in sasview


Ignore:
Timestamp:
Apr 17, 2009 10:21:13 AM (15 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:
5ee2306
Parents:
c16557c
Message:

fixed circular average bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/manipulations.py

    ree3b2c0c r8ba103f  
    167167                    err_y[i_q] += frac * frac * data2D.err_data[j][i] * data2D.err_data[j][i] 
    168168                y_counts[i_q]  += frac 
    169  
     169                 
    170170        # Average the sums 
    171171        for i in range(nbins): 
     
    378378        det_dist    = data2D.detector[0].distance 
    379379        wavelength  = data2D.source.wavelength 
    380         center_x    = data2D.detector[0].beam_center.x/pixel_width_x 
    381         center_y    = data2D.detector[0].beam_center.y/pixel_width_y 
     380        center_x    = data2D.detector[0].beam_center.x/pixel_width_x+0.5 
     381        center_y    = data2D.detector[0].beam_center.y/pixel_width_y+0.5 
    382382         
    383383        # Find out the maximum Q range 
    384         xwidth = numpy.size(data2D.data,1)*pixel_width_x 
     384        xwidth = (numpy.size(data2D.data,1))*pixel_width_x 
    385385        dx_max = xwidth - data2D.detector[0].beam_center.x 
    386386        if xwidth-dx_max>dx_max: 
    387387            dx_max = xwidth-dx_max 
    388388             
    389         ywidth = numpy.size(data2D.data,0)*pixel_width_y 
     389        ywidth = (numpy.size(data2D.data,0))*pixel_width_y 
    390390        dy_max = ywidth - data2D.detector[0].beam_center.y 
    391391        if ywidth-dy_max>dy_max: 
     
    441441 
    442442                i_q = int(math.ceil((q_value-self.r_min)/self.bin_width)) - 1 
    443              
     443                if q_value > qmax or q_value < self.r_min: 
     444                    continue 
     445                     
    444446                x[i_q]          = q_value 
    445447                y[i_q]         += frac * data2D.data[j][i] 
     
    449451                    err_y[i_q] += frac * frac * data2D.err_data[j][i] * data2D.err_data[j][i] 
    450452                y_counts[i_q]  += frac 
    451          
     453                 
    452454        # Average the sums 
     455        nzero = 0 
    453456        for i in range(nbins): 
    454457            if y_counts[i]>0: 
    455458                err_y[i] = math.sqrt(err_y[i])/y_counts[i] 
    456459                y[i]     = y[i]/y_counts[i] 
    457          
    458         return Data1D(x=x, y=y, dy=err_y) 
     460            else: 
     461                nzero += 1 
     462        ## Get rid of NULL points         
     463        tx  = numpy.zeros(nbins-nzero) 
     464        ty  = numpy.zeros(nbins-nzero) 
     465        terr_y = numpy.zeros(nbins-nzero) 
     466        j=0 
     467        for i in range(nbins): 
     468            if err_y[i] != 0 : 
     469                tx[j]  = x[i] 
     470                ty[j]  = y[i] 
     471                terr_y[j] = err_y[i] 
     472                j+=1 
     473                 
     474        return Data1D(x=tx, y=ty, dy=terr_y) 
    459475     
    460476 
     
    480496        self.center_y = center_y 
    481497        # Number of angular bins 
    482         self.nbins_phi = nbins_phi 
     498        self.nbins_phi = nbins 
    483499         
    484500    def __call__(self, data2D): 
     
    856872                    self.phi_max=self.phi_max+2*math.pi 
    857873                 
    858                 #In case of two ROI (symmetric major and minor regions)(for 'q2') 
     874                #In case of two ROI (symmetric major and minor wings)(for 'q2') 
    859875                if run.lower()=='q2': 
    860876                    if ((self.phi_max>=0 and self.phi_max<math.pi)and (self.phi_min>=0 and self.phi_min<math.pi)): 
     
    904920            qmax=temp 
    905921        #Beam center is already corrected, but the calculation below assumed it was not. 
    906         # Thus Beam center shifted back to uncorrected value. ToDo: cleanup this codes. 
     922        # Thus Beam center shifted back to uncorrected value. ToDo: cleanup the mess. 
    907923        center_x=center_x+0.5  
    908924        center_y=center_y+0.5          
Note: See TracChangeset for help on using the changeset viewer.