Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/dataFitting.py

    r9b6d62d r7988501  
    1717    """ 
    1818    """ 
    19     def __init__(self, x=None, y=None, dx=None, dy=None): 
     19    def __init__(self, x=None, y=None, dx=None, dy=None, lam=None, dlam=None): 
    2020        """ 
    2121        """ 
     
    2424        if y is None: 
    2525            y = [] 
    26         PlotData1D.__init__(self, x, y, dx, dy) 
    27         LoadData1D.__init__(self, x, y, dx, dy) 
     26        PlotData1D.__init__(self, x, y, lam, dx, dy, dlam) 
     27        LoadData1D.__init__(self, x, y, lam, dx, dy, dlam) 
    2828        self.id = None 
    2929        self.list_group_id = [] 
     
    6868        # First, check the data compatibility 
    6969        dy, dy_other = self._validity_check(other) 
    70         result = Data1D(x=[], y=[], dx=None, dy=None) 
     70        result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=None) 
    7171        result.clone_without_data(length=len(self.x), clone=self) 
    7272        result.copy_from_datainfo(data1d=self) 
     
    115115        # First, check the data compatibility 
    116116        self._validity_check_union(other) 
    117         result = Data1D(x=[], y=[], dx=None, dy=None) 
     117        result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=None) 
    118118        tot_length = len(self.x) + len(other.x) 
    119119        result = self.clone_without_data(length=tot_length, clone=result) 
     120        if self.dlam == None or other.dlam is None: 
     121            result.dlam = None 
     122        else: 
     123            result.dlam = numpy.zeros(tot_length) 
    120124        if self.dy == None or other.dy is None: 
    121125            result.dy = None 
     
    141145        result.y = numpy.append(self.y, other.y) 
    142146        result.y = result.y[ind] 
     147        result.lam = numpy.append(self.lam, other.lam) 
     148        result.lam = result.lam[ind] 
     149        if result.dlam != None: 
     150            result.dlam = numpy.append(self.dlam, other.dlam) 
     151            result.dlam = result.dlam[ind] 
    143152        if result.dy != None: 
    144153            result.dy = numpy.append(self.dy, other.dy) 
     
    260269        # First, check the data compatibility 
    261270        self._validity_check_union(other) 
    262         result = Data1D(x=[], y=[], dx=None, dy=None) 
     271        result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=[]) 
    263272        tot_length = len(self.x)+len(other.x) 
    264273        result.clone_without_data(length=tot_length, clone=self) 
     274        if self.dlam == None or other.dlam is None: 
     275            result.dlam = None 
     276        else: 
     277            result.dlam = numpy.zeros(tot_length) 
    265278        if self.dy == None or other.dy is None: 
    266279            result.dy = None 
     
    285298        result.y = numpy.append(self.y, other.y) 
    286299        result.y = result.y[ind] 
     300        result.lam = numpy.append(self.lam, other.lam) 
     301        result.lam = result.lam[ind] 
    287302        if result.dy != None: 
    288303            result.dy = numpy.append(self.dy, other.dy) 
     
    363378        _str = "%s\n" % LoadData2D.__str__(self) 
    364379        return _str  
    365  
     380     
     381    def _validity_check(self, other): 
     382        """ 
     383        Checks that the data lengths are compatible. 
     384        Checks that the x vectors are compatible. 
     385        Returns errors vectors equal to original 
     386        errors vectors if they were present or vectors 
     387        of zeros when none was found. 
     388         
     389        :param other: other data set for operation 
     390         
     391        :return: dy for self, dy for other [numpy arrays] 
     392         
     393        :raise ValueError: when lengths are not compatible 
     394         
     395        """ 
     396        err_other = None 
     397        if isinstance(other, Data2D): 
     398            # Check that data lengths are the same 
     399            if len(self.data) != len(other.data) or \ 
     400                len(self.qx_data) != len(other.qx_data) or \ 
     401                len(self.qy_data) != len(other.qy_data): 
     402                msg = "Unable to perform operation: data length are not equal" 
     403                raise ValueError, msg 
     404            #if len(self.data) < 1: 
     405            #    msg = "Incompatible data sets: I-values do not match" 
     406            #    raise ValueError, msg  
     407            for ind in range(len(self.data)): 
     408                if self.qx_data[ind] != other.qx_data[ind]: 
     409                    msg = "Incompatible data sets: qx-values do not match" 
     410                    raise ValueError, msg 
     411                if self.qy_data[ind] != other.qy_data[ind]: 
     412                    msg = "Incompatible data sets: qy-values do not match" 
     413                    raise ValueError, msg 
     414                    
     415            # Check that the scales match 
     416            err_other = other.err_data 
     417            if other.err_data == None or \ 
     418                (len(other.err_data) != len(other.data)): 
     419                err_other = numpy.zeros(len(other.data)) 
     420             
     421        # Check that we have errors, otherwise create zero vector 
     422        err = self.err_data 
     423        if self.err_data == None or \ 
     424            (len(self.err_data) != len(self.data)): 
     425            err = numpy.zeros(len(other.data)) 
     426             
     427        return err, err_other 
     428 
     429    def _validity_check_union(self, other): 
     430        """ 
     431        Checks that the data lengths are compatible. 
     432        Checks that the x vectors are compatible. 
     433        Returns errors vectors equal to original 
     434        errors vectors if they were present or vectors 
     435        of zeros when none was found. 
     436         
     437        :param other: other data set for operation 
     438         
     439        :return: bool 
     440         
     441        :raise ValueError: when data types are not compatible 
     442         
     443        """ 
     444        if not isinstance(other, Data2D): 
     445            msg = "Unable to perform operation: different types of data set" 
     446            raise ValueError, msg    
     447        return True 
     448     
    366449    def _perform_operation(self, other, operation): 
    367450        """ 
Note: See TracChangeset for help on using the changeset viewer.