Changeset e2605a5 in sasview for sansdataloader/src/sans/dataloader


Ignore:
Timestamp:
May 23, 2012 3:41:29 PM (12 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:
0c24e98
Parents:
d56fc67
Message:

trying to make data operation work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansdataloader/src/sans/dataloader/data_info.py

    rf60a8c2 re2605a5  
    728728                    msg = "Incompatible data sets: x-values do not match" 
    729729                    raise ValueError, msg 
     730                if self.dxl != None and other.dxl == None: 
     731                    msg = "Incompatible data sets: dxl-values do not match" 
     732                    raise ValueError, msg 
     733                if self.dxl == None and other.dxl != None: 
     734                    msg = "Incompatible data sets: dxl-values do not match" 
     735                    raise ValueError, msg 
     736                if self.dxw != None and other.dxw == None: 
     737                    msg = "Incompatible data sets: dxw-values do not match" 
     738                    raise ValueError, msg 
     739                if self.dxw == None and other.dxw != None: 
     740                    msg = "Incompatible data sets: dxw-values do not match" 
     741                    raise ValueError, msg 
    730742             
    731743            # Check that the other data set has errors, otherwise 
     
    748760        dy, dy_other = self._validity_check(other) 
    749761        result = self.clone_without_data(len(self.x)) 
    750          
     762        if self.dxw == None: 
     763            result.dxw = None 
     764        else: 
     765            result.dxw = numpy.zeros(len(self.x)) 
     766        if self.dxl == None: 
     767            result.dxl = None 
     768        else: 
     769            result.dxl = numpy.zeros(len(self.x)) 
     770 
    751771        for i in range(len(self.x)): 
    752772            result.x[i] = self.x[i] 
    753773            if self.dx is not None and len(self.x) == len(self.dx): 
    754774                result.dx[i] = self.dx[i] 
     775            if self.dxw is not None and len(self.x) == len(self.dxw): 
     776                result.dxw[i] = self.dxw[i] 
     777            if self.dxl is not None and len(self.x) == len(self.dxl): 
     778                result.dxl[i] = self.dxl[i] 
    755779             
    756780            a = Uncertainty(self.y[i], dy[i]**2) 
    757781            if isinstance(other, Data1D): 
    758782                b = Uncertainty(other.y[i], dy_other[i]**2) 
     783                if other.dx is not None: 
     784                    result.dx[i] *= self.dx[i] 
     785                    result.dx[i] += (other.dx[i]**2) 
     786                    result.dx[i] /= 2 
     787                    result.dx[i] = math.sqrt(result.dx[i]) 
     788                if result.dxl is not None and other.dxl is not None: 
     789                    result.dxl[i] *= self.dxl[i] 
     790                    other.dxl[i] += (other.dxl[i]**2) 
     791                    result.dxl[i] /= 2 
     792                    result.dxl[i] = math.sqrt(result.dxl[i]) 
     793                if result.dxw is not None and self.dxw is not None: 
     794                    result.dxw[i] *= self.dxw[i] 
     795                    other.dxw[i] += (other.dxw[i]**2) 
     796                    result.dxw[i] /= 2 
     797                    result.dxw[i] = math.sqrt(result.dxw[i]) 
    759798            else: 
    760799                b = other 
     
    866905                msg = "Unable to perform operation: data length are not equal" 
    867906                raise ValueError, msg 
    868                 
     907            if numpy.size(self.qx_data) != numpy.size(other.qx_data): 
     908                msg = "Unable to perform operation: data length are not equal" 
     909                raise ValueError, msg 
     910            if numpy.size(self.qy_data) != numpy.size(other.qy_data): 
     911                msg = "Unable to perform operation: data length are not equal" 
     912                raise ValueError, msg 
     913            # Here we could also extrapolate between data points 
     914            for i in range(len(self.data)): 
     915                if self.qx_data[i] != other.qx_data[i]: 
     916                    msg = "Incompatible data sets: qx-values do not match" 
     917                    raise ValueError, msg 
     918                if self.qy_data[i] != other.qy_data[i]: 
     919                    msg = "Incompatible data sets: qy-values do not match" 
     920                    raise ValueError, msg 
     921                    
    869922            # Check that the scales match 
    870             #TODO: matching scales? 
    871              
    872             # Check that the other data set has errors, otherwise 
    873             # create zero vector 
    874             #TODO: test this 
    875923            err_other = other.err_data 
    876924            if other.err_data == None or \ 
    877925                (numpy.size(other.err_data) != numpy.size(other.data)): 
    878                 err_other = numpy.zeros([numpy.size(other.data, 0), 
    879                                           numpy.size(other.data, 1)]) 
     926                err_other = numpy.zeros(numpy.size(other.data)) 
    880927             
    881928        # Check that we have errors, otherwise create zero vector 
     
    883930        if self.err_data == None or \ 
    884931            (numpy.size(self.err_data) != numpy.size(self.data)): 
    885             err = numpy.zeros([numpy.size(self.data, 0), 
    886                                 numpy.size(self.data, 1)]) 
     932            err = numpy.zeros(numpy.size(other.data)) 
    887933             
    888934        return err, err_other 
     
    898944        # First, check the data compatibility 
    899945        dy, dy_other = self._validity_check(other) 
    900      
    901         result = self.clone_without_data([numpy.size(self.data, 0), 
    902                                           numpy.size(self.data, 1)]) 
    903          
    904         for i in range(numpy.size(self.data, 0)): 
    905             for j in range(numpy.size(self.data, 1)): 
    906                 result.data[i][j] = self.data[i][j] 
    907                 if self.err_data is not None and \ 
    908                     numpy.size(self.data) == numpy.size(self.err_data): 
    909                     result.err_data[i][j] = self.err_data[i][j] 
    910                  
    911                 a = Uncertainty(self.data[i][j], dy[i][j]**2) 
    912                 if isinstance(other, Data2D): 
    913                     b = Uncertainty(other.data[i][j], dy_other[i][j]**2) 
    914                 else: 
    915                     b = other 
    916                  
    917                 output = operation(a, b) 
    918                 result.data[i][j] = output.x 
    919                 result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 
     946        result = self.clone_without_data(numpy.size(self.data)) 
     947        result.xmin = self.xmin 
     948        result.xmax = self.xmax 
     949        result.ymin = self.ymin 
     950        result.ymax = self.ymax 
     951        if self.dqx_data == None or self.dqy_data == None: 
     952            result.dqx_data = None 
     953            result.dqy_data = None 
     954        else: 
     955            result.dqx_data = numpy.zeros(len(self.data)) 
     956            result.dqy_data = numpy.zeros(len(self.data)) 
     957        for i in range(numpy.size(self.data)): 
     958            result.data[i] = self.data[i] 
     959            if self.err_data is not None and \ 
     960                numpy.size(self.data) == numpy.size(self.err_data): 
     961                result.err_data[i] = self.err_data[i]     
     962            if self.dqx_data is not None: 
     963                result.dqx_data[i] = self.dqx_data[i] 
     964            if self.dqy_data is not None: 
     965                result.dqy_data[i] = self.dqy_data[i] 
     966            result.qx_data[i] = self.qx_data[i] 
     967            result.qy_data[i] = self.qy_data[i] 
     968            result.q_data[i] = self.q_data[i] 
     969            result.mask[i] = self.mask[i] 
     970             
     971            a = Uncertainty(self.data[i], dy[i]**2) 
     972            if isinstance(other, Data2D): 
     973                b = Uncertainty(other.data[i], dy_other[i]**2) 
     974                if other.dqx_data is not None and \ 
     975                        result.dqx_data is not None: 
     976                    result.dqx_data[i] *= self.dqx_data[i] 
     977                    result.dqx_data[i] += (other.dqx_data[i]**2) 
     978                    result.dqx_data[i] /= 2 
     979                    result.dqx_data[i] = math.sqrt(result.dqx_data[i])      
     980                if other.dqy_data is not None and \ 
     981                        result.dqy_data is not None: 
     982                    result.dqy_data[i] *= self.dqy_data[i] 
     983                    result.dqy_data[i] += (other.dqy_data[i]**2) 
     984                    result.dqy_data[i] /= 2 
     985                    result.dqy_data[i] = math.sqrt(result.dqy_data[i]) 
     986            else: 
     987                b = other 
     988             
     989            output = operation(a, b) 
     990            result.data[i] = output.x 
     991            result.err_data[i] = math.sqrt(math.fabs(output.variance)) 
    920992        return result 
Note: See TracChangeset for help on using the changeset viewer.