Ignore:
Timestamp:
Apr 7, 2017 7:51:47 AM (7 years ago)
Author:
Ricardo Ferraz Leal <ricleal@…>
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
168d359
Parents:
ccc7192
Message:

Refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/manipulations.py

    rccc7192 rfa4af76  
     1from __future__ import division 
    12""" 
    23Data manipulations for 2D data sets. 
     
    560561 
    561562        dq_data = None 
    562         if data2D.dqx_data != None and data2D.dqy_data != None: 
     563        if data2D.dqx_data is not None and data2D.dqy_data is not None: 
    563564            dq_data = get_dq_data(data2D) 
    564565 
    565566        #q_data_max = np.max(q_data) 
    566         if len(data2D.q_data) == None: 
     567        if len(data2D.q_data) is None: 
    567568            msg = "Circular averaging: invalid q_data: %g" % data2D.q_data 
    568569            raise RuntimeError(msg) 
     
    610611            else: 
    611612                err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] 
    612             if dq_data != None: 
     613            if dq_data is not None: 
    613614                # To be consistent with dq calculation in 1d reduction, 
    614615                # we need just the averages (not quadratures) because 
     
    625626                err_y[n] = -err_y[n] 
    626627            err_y[n] = math.sqrt(err_y[n]) 
    627             # if err_x != None: 
     628            # if err_x is not None: 
    628629            #    err_x[n] = math.sqrt(err_x[n]) 
    629630 
     
    634635        idx = (np.isfinite(y)) & (np.isfinite(x)) 
    635636 
    636         if err_x != None: 
     637        if err_x is not None: 
    637638            d_x = err_x[idx] / y_counts[idx] 
    638639        else: 
     
    791792 
    792793        dq_data = None 
    793         if data2D.dqx_data != None and data2D.dqy_data != None: 
     794        if data2D.dqx_data is not None and data2D.dqy_data is not None: 
    794795            dq_data = get_dq_data(data2D) 
    795796 
     
    799800        y_err = np.zeros(self.nbins) 
    800801        x_err = np.zeros(self.nbins) 
    801         y_counts = np.zeros(self.nbins) 
     802        y_counts = np.zeros(self.nbins) # Cycle counts (for the mean) 
    802803 
    803804        # Get the min and max into the region: 0 <= phi < 2Pi 
     
    817818            phi_value = math.atan2(qy_data[n], qx_data[n]) + math.pi 
    818819 
    819             # No need to calculate the frac when all data are within range 
     820            # No need to calculate: data outside of the radius 
    820821            if self.r_min > q_value or q_value > self.r_max: 
    821822                continue 
     
    844845                                  phi_value < phi_max) 
    845846 
     847            # data oustide of the phi range 
    846848            if not is_in: 
    847849                continue 
     850         
    848851            # Check which type of averaging we need 
    849852            if run.lower() == 'phi': 
    850853                temp_x = (self.nbins) * (phi_value - self.phi_min) 
    851854                temp_y = (self.phi_max - self.phi_min) 
    852                 i_bin = int(math.floor(temp_x / temp_y)) 
    853855            else: 
    854856                temp_x = (self.nbins) * (q_value - self.r_min) 
    855857                temp_y = (self.r_max - self.r_min) 
    856                 i_bin = int(math.floor(temp_x / temp_y)) 
     858            # Bin index calulation 
     859            i_bin = int(math.floor(temp_x / temp_y)) 
    857860 
    858861            # Take care of the edge case at phi = 2pi. 
     
    863866            y[i_bin] += data_n 
    864867            x[i_bin] += q_value 
    865             if err_data[n] == None or err_data[n] == 0.0: 
     868            if err_data[n] is None or err_data[n] == 0.0: 
    866869                if data_n < 0: 
    867870                    data_n = -data_n 
    868                 y_err[i_bin] +=  data_n 
     871                y_err[i_bin] += data_n 
    869872            else: 
    870                 y_err[i_bin] += err_data[n] * err_data[n] 
    871  
    872             if dq_data != None: 
     873                y_err[i_bin] += err_data[n]**2 
     874 
     875            if dq_data is not None: 
    873876                # To be consistent with dq calculation in 1d reduction, 
    874877                # we need just the averages (not quadratures) because 
     
    900903        y_err[y_err == 0] = np.average(y_err) 
    901904        idx = (np.isfinite(y) & np.isfinite(y_err)) 
    902         if x_err != None: 
     905        if x_err is not None: 
    903906            d_x = x_err[idx] / y_counts[idx] 
    904907        else: 
Note: See TracChangeset for help on using the changeset viewer.