Ignore:
File:
1 edited

Legend:

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

    rdeaa0c6 re090ba90  
    2626import numpy as np 
    2727import math 
     28from math import fabs 
    2829 
    2930class plottable_1D(object): 
     
    656657        return self._perform_operation(other, operation) 
    657658 
    658     def __div__(self, other): 
     659    def __truediv__(self, other): 
    659660        """ 
    660661        Divided a data set by another 
     
    667668            return a/b 
    668669        return self._perform_operation(other, operation) 
    669  
    670     def __rdiv__(self, other): 
     670    __div__ = __truediv__ 
     671 
     672    def __rtruediv__(self, other): 
    671673        """ 
    672674        Divided a data set by another 
     
    679681            return b/a 
    680682        return self._perform_operation(other, operation) 
     683    __rdiv__ = __rtruediv__ 
    681684 
    682685    def __or__(self, other): 
     
    716719                self.y_unit = '1/cm' 
    717720        except: # the data is not recognized/supported, and the user is notified 
    718             raise(TypeError, 'data not recognized, check documentation for supported 1D data formats') 
     721            raise TypeError('data not recognized, check documentation for supported 1D data formats') 
    719722 
    720723    def __str__(self): 
     
    796799                len(self.y) != len(other.y): 
    797800                msg = "Unable to perform operation: data length are not equal" 
    798                 raise ValueError, msg 
     801                raise ValueError(msg) 
    799802            # Here we could also extrapolate between data points 
    800803            TOLERANCE = 0.01 
    801804            for i in range(len(self.x)): 
    802                 if math.fabs((self.x[i] - other.x[i])/self.x[i]) > TOLERANCE: 
     805                if fabs(self.x[i] - other.x[i]) > self.x[i]*TOLERANCE: 
    803806                    msg = "Incompatible data sets: x-values do not match" 
    804                     raise ValueError, msg 
     807                    raise ValueError(msg) 
    805808 
    806809            # Check that the other data set has errors, otherwise 
     
    876879        if not isinstance(other, Data1D): 
    877880            msg = "Unable to perform operation: different types of data set" 
    878             raise ValueError, msg 
     881            raise ValueError(msg) 
    879882        return True 
    880883 
     
    948951 
    949952        if len(self.detector) > 0: 
    950             raise RuntimeError, "Data2D: Detector bank already filled at init" 
     953            raise RuntimeError("Data2D: Detector bank already filled at init") 
    951954 
    952955    def __str__(self): 
     
    10201023                len(self.qy_data) != len(other.qy_data): 
    10211024                msg = "Unable to perform operation: data length are not equal" 
    1022                 raise ValueError, msg 
     1025                raise ValueError(msg) 
    10231026            for ind in range(len(self.data)): 
    1024                 if math.fabs((self.qx_data[ind] - other.qx_data[ind])/self.qx_data[ind]) > TOLERANCE: 
     1027                if fabs(self.qx_data[ind] - other.qx_data[ind]) > fabs(self.qx_data[ind])*TOLERANCE: 
    10251028                    msg = "Incompatible data sets: qx-values do not match: %s %s" % (self.qx_data[ind], other.qx_data[ind]) 
    1026                     raise ValueError, msg 
    1027                 if math.fabs((self.qy_data[ind] - other.qy_data[ind])/self.qy_data[ind]) > TOLERANCE: 
     1029                    raise ValueError(msg) 
     1030                if fabs(self.qy_data[ind] - other.qy_data[ind]) > fabs(self.qy_data[ind])*TOLERANCE: 
    10281031                    msg = "Incompatible data sets: qy-values do not match: %s %s" % (self.qy_data[ind], other.qy_data[ind]) 
    1029                     raise ValueError, msg 
     1032                    raise ValueError(msg) 
    10301033 
    10311034            # Check that the scales match 
     
    11081111        if not isinstance(other, Data2D): 
    11091112            msg = "Unable to perform operation: different types of data set" 
    1110             raise ValueError, msg 
     1113            raise ValueError(msg) 
    11111114        return True 
    11121115 
Note: See TracChangeset for help on using the changeset viewer.