Changeset e4f421c in sasview for src/sas/dataloader/data_info.py


Ignore:
Timestamp:
Mar 2, 2015 2:55:36 PM (9 years ago)
Author:
Doucet, Mathieu <doucetm@…>
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:
e3f77d8b
Parents:
c43e875
Message:

pylint fixes

File:
1 edited

Legend:

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

    r5e326a6 re4f421c  
    22    Module that contains classes to hold information read from 
    33    reduced data files. 
    4      
     4 
    55    A good description of the data members can be found in 
    66    the CanSAS 1D XML data format: 
    7      
     7 
    88    http://www.smallangles.net/wgwiki/index.php/cansas1d_documentation 
    99""" 
     
    2626import math 
    2727 
    28 class plottable_sesans1D: 
     28class plottable_sesans1D(object): 
    2929    """ 
    3030    SESANS is a place holder for 1D SESANS plottables. 
    31      
     31 
    3232    #TODO: This was directly copied from the plottables_1D. Modified Somewhat. 
    3333    #Class has been updated. 
     
    4545    ## Slit smearing width 
    4646    dxw = None 
    47      
     47 
    4848    # Units 
    4949    _xaxis = '' 
     
    5151    _yaxis = '' 
    5252    _yunit = '' 
    53      
     53 
    5454    def __init__(self, x, y, lam, dx=None, dy=None, dlam=None): 
    5555#        print "SESANS plottable working" 
     
    6363        if dlam is not None: 
    6464            self.dlam = numpy.asarray(dlam) 
    65 #        if dxl is not None: 
    66 #            self.dxl = numpy.asarray(dxl) 
    67 #        if dxw is not None:  
    68 #            self.dxw = numpy.asarray(dxw) 
    69 #        print "SESANS plottable init fin" 
     65 
    7066    def xaxis(self, label, unit): 
    7167        """ 
     
    7470        self._xaxis = label 
    7571        self._xunit = unit 
    76         print "xaxis active" 
    77         print label 
    78         print unit 
     72 
    7973    def yaxis(self, label, unit): 
    8074        """ 
    8175        set the y axis label and unit 
    8276        """ 
    83         print "yaxis active" 
    84         print label 
    85         print unit 
    86          
    8777        self._yaxis = label 
    8878        self._yunit = unit 
    8979 
    9080 
    91 class plottable_1D: 
     81class plottable_1D(object): 
    9282    """ 
    9383    Data1D is a place holder for 1D plottables. 
     
    10393    ## Slit smearing width 
    10494    dxw = None 
    105      
     95 
    10696    # Units 
    10797    _xaxis = '' 
     
    10999    _yaxis = '' 
    110100    _yunit = '' 
    111      
     101 
    112102    def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None): 
    113103        self.x = numpy.asarray(x) 
     
    119109        if dxl is not None: 
    120110            self.dxl = numpy.asarray(dxl) 
    121         if dxw is not None:  
     111        if dxw is not None: 
    122112            self.dxw = numpy.asarray(dxw) 
    123113 
     
    128118        self._xaxis = label 
    129119        self._xunit = unit 
    130          
     120 
    131121    def yaxis(self, label, unit): 
    132122        """ 
     
    137127 
    138128 
    139 class plottable_2D: 
     129class plottable_2D(object): 
    140130    """ 
    141131    Data2D is a place holder for 2D plottables. 
     
    153143    dqy_data = None 
    154144    mask = None 
    155      
     145 
    156146    # Units 
    157147    _xaxis = '' 
     
    161151    _zaxis = '' 
    162152    _zunit = '' 
    163      
     153 
    164154    def __init__(self, data=None, err_data=None, qx_data=None, 
    165155                 qy_data=None, q_data=None, mask=None, 
     
    172162        self.err_data = numpy.asarray(err_data) 
    173163        if dqx_data is not None: 
    174             self.dqx_data = numpy.asarray(dqx_data)  
     164            self.dqx_data = numpy.asarray(dqx_data) 
    175165        if dqy_data is not None: 
    176             self.dqy_data = numpy.asarray(dqy_data)  
    177                 
     166            self.dqy_data = numpy.asarray(dqy_data) 
     167 
    178168    def xaxis(self, label, unit): 
    179169        """ 
     
    182172        self._xaxis = label 
    183173        self._xunit = unit 
    184          
     174 
    185175    def yaxis(self, label, unit): 
    186176        """ 
     
    189179        self._yaxis = label 
    190180        self._yunit = unit 
    191              
     181 
    192182    def zaxis(self, label, unit): 
    193183        """ 
     
    197187        self._zunit = unit 
    198188 
    199              
    200 class Vector: 
     189 
     190class Vector(object): 
    201191    """ 
    202192    Vector class to hold multi-dimensional objects 
     
    208198    ## z component 
    209199    z = None 
    210      
     200 
    211201    def __init__(self, x=None, y=None, z=None): 
    212202        """ 
    213203        Initialization. Components that are not 
    214204        set a set to None by default. 
    215          
     205 
    216206        :param x: x component 
    217207        :param y: y component 
    218208        :param z: z component 
    219          
    220209        """ 
    221210        self.x = x 
    222211        self.y = y 
    223212        self.z = z 
    224          
     213 
    225214    def __str__(self): 
    226215        msg = "x = %s\ty = %s\tz = %s" % (str(self.x), str(self.y), str(self.z)) 
    227216        return msg 
    228          
    229  
    230 class Detector: 
     217 
     218 
     219class Detector(object): 
    231220    """ 
    232221    Class to hold detector information 
     
    255244    slit_length = None 
    256245    slit_length_unit = 'mm' 
    257      
     246 
    258247    def __init__(self): 
    259248        """ 
    260          
    261249        Initialize class attribute that are objects... 
    262          
    263         """ 
    264         self.offset      = Vector() 
     250        """ 
     251        self.offset = Vector() 
    265252        self.orientation = Vector() 
    266253        self.beam_center = Vector() 
    267         self.pixel_size  = Vector() 
    268          
     254        self.pixel_size = Vector() 
     255 
    269256    def __str__(self): 
    270         _str  = "Detector:\n" 
     257        _str = "Detector:\n" 
    271258        _str += "   Name:         %s\n" % self.name 
    272259        _str += "   Distance:     %s [%s]\n" % \ 
     
    285272 
    286273 
    287 class Aperture: 
     274class Aperture(object): 
    288275    ## Name 
    289276    name = None 
     
    298285    distance = None 
    299286    distance_unit = 'mm' 
    300      
     287 
    301288    def __init__(self): 
    302289        self.size = Vector() 
    303      
    304      
    305 class Collimation: 
     290 
     291 
     292class Collimation(object): 
    306293    """ 
    307294    Class to hold collimation information 
     
    314301    ## Aperture 
    315302    aperture = None 
    316      
     303 
    317304    def __init__(self): 
    318305        self.aperture = [] 
    319      
     306 
    320307    def __str__(self): 
    321308        _str = "Collimation:\n" 
     
    330317 
    331318 
    332 class Source: 
     319class Source(object): 
    333320    """ 
    334321    Class to hold source information 
     
    357344    wavelength_spread = None 
    358345    wavelength_spread_unit = 'percent' 
    359      
     346 
    360347    def __init__(self): 
    361348        self.beam_size = Vector() 
    362          
     349 
    363350    def __str__(self): 
    364         _str  = "Source:\n" 
     351        _str = "Source:\n" 
    365352        _str += "   Radiation:    %s\n" % str(self.radiation) 
    366353        _str += "   Shape:        %s\n" % str(self.beam_shape) 
     
    376363            (str(self.beam_size), str(self.beam_size_unit)) 
    377364        return _str 
    378      
    379      
     365 
     366 
    380367""" 
    381368Definitions of radiation types 
    382369""" 
    383 NEUTRON  = 'neutron' 
    384 XRAY     = 'x-ray' 
    385 MUON     = 'muon' 
     370NEUTRON = 'neutron' 
     371XRAY = 'x-ray' 
     372MUON = 'muon' 
    386373ELECTRON = 'electron' 
    387      
    388      
    389 class Sample: 
     374 
     375 
     376class Sample(object): 
    390377    """ 
    391378    Class to hold the sample description 
     
    411398    ## Details 
    412399    details = None 
    413      
     400 
    414401    def __init__(self): 
    415         self.position    = Vector() 
     402        self.position = Vector() 
    416403        self.orientation = Vector() 
    417         self.details     = [] 
    418      
     404        self.details = [] 
     405 
    419406    def __str__(self): 
    420         _str  = "Sample:\n" 
     407        _str = "Sample:\n" 
    421408        _str += "   ID:           %s\n" % str(self.ID) 
    422409        _str += "   Transmission: %s\n" % str(self.transmission) 
     
    429416        _str += "   Orientation:  %s [%s]\n" % \ 
    430417            (str(self.orientation), str(self.orientation_unit)) 
    431          
     418 
    432419        _str += "   Details:\n" 
    433420        for item in self.details: 
    434421            _str += "      %s\n" % item 
    435              
     422 
    436423        return _str 
    437    
    438    
    439 class Process: 
     424 
     425 
     426class Process(object): 
    440427    """ 
    441428    Class that holds information about the processes 
     
    447434    term = None 
    448435    notes = None 
    449      
     436 
    450437    def __init__(self): 
    451438        self.term = [] 
    452439        self.notes = [] 
    453      
     440 
    454441    def __str__(self): 
    455         _str  = "Process:\n" 
     442        _str = "Process:\n" 
    456443        _str += "   Name:         %s\n" % self.name 
    457444        _str += "   Date:         %s\n" % self.date 
     
    462449            _str += "   Note:         %s\n" % item 
    463450        return _str 
    464      
    465 class TransmissionSpectrum: 
     451 
     452 
     453class TransmissionSpectrum(object): 
    466454    """ 
    467455    Class that holds information about transmission spectrum 
     
    479467    transmission_deviation = None 
    480468    transmission_deviation_unit = '' 
    481      
     469 
    482470    def __init__(self): 
    483471        self.wavelength = [] 
    484472        self.transmission = [] 
    485473        self.transmission_deviation = [] 
    486      
     474 
    487475    def __str__(self): 
    488         _str  = "Transmission Spectrum:\n" 
     476        _str = "Transmission Spectrum:\n" 
    489477        _str += "   Name:             \t{0}\n".format(self.name) 
    490478        _str += "   Timestamp:        \t{0}\n".format(self.timestamp) 
     
    497485        _str += "   Number of Pts:    \t{0}\n".format(max(length_list)) 
    498486        return _str 
    499      
    500    
    501 class DataInfo: 
     487 
     488 
     489class DataInfo(object): 
    502490    """ 
    503491    Class to hold the data read from a file. 
     
    507495    """ 
    508496    ## Title 
    509     title      = '' 
     497    title = '' 
    510498    ## Run number 
    511     run        = None 
     499    run = None 
    512500    ## Run name 
    513     run_name   = None 
     501    run_name = None 
    514502    ## File name 
    515     filename   = '' 
     503    filename = '' 
    516504    ## Notes 
    517     notes      = None 
     505    notes = None 
    518506    ## Processes (Action on the data) 
    519     process    = None 
     507    process = None 
    520508    ## Instrument name 
    521509    instrument = '' 
    522510    ## Detector information 
    523     detector   = None 
     511    detector = None 
    524512    ## Sample information 
    525     sample     = None 
     513    sample = None 
    526514    ## Source information 
    527     source     = None 
     515    source = None 
    528516    ## Collimation information 
    529517    collimation = None 
     
    531519    trans_spectrum = None 
    532520    ## Additional meta-data 
    533     meta_data  = None 
     521    meta_data = None 
    534522    ## Loading errors 
    535523    errors = None 
    536              
     524 
    537525    def __init__(self): 
    538526        """ 
    539527        Initialization 
    540528        """ 
    541         ## Title  
    542         self.title      = '' 
     529        ## Title 
     530        self.title = '' 
    543531        ## Run number 
    544         self.run        = [] 
    545         self.run_name   = {} 
     532        self.run = [] 
     533        self.run_name = {} 
    546534        ## File name 
    547         self.filename   = '' 
     535        self.filename = '' 
    548536        ## Notes 
    549         self.notes      = [] 
     537        self.notes = [] 
    550538        ## Processes (Action on the data) 
    551         self.process    = [] 
     539        self.process = [] 
    552540        ## Instrument name 
    553541        self.instrument = '' 
    554542        ## Detector information 
    555         self.detector   = [] 
     543        self.detector = [] 
    556544        ## Sample information 
    557         self.sample     = Sample() 
     545        self.sample = Sample() 
    558546        ## Source information 
    559         self.source     = Source() 
     547        self.source = Source() 
    560548        ## Collimation information 
    561549        self.collimation = [] 
     
    563551        self.trans_spectrum = [] 
    564552        ## Additional meta-data 
    565         self.meta_data  = {} 
     553        self.meta_data = {} 
    566554        ## Loading errors 
    567555        self.errors = [] 
    568          
     556 
    569557    def append_empty_process(self): 
    570558        """ 
    571559        """ 
    572560        self.process.append(Process()) 
    573          
     561 
    574562    def add_notes(self, message=""): 
    575563        """ 
     
    577565        """ 
    578566        self.notes.append(message) 
    579          
     567 
    580568    def __str__(self): 
    581569        """ 
    582570        Nice printout 
    583571        """ 
    584         _str =  "File:            %s\n" % self.filename 
     572        _str = "File:            %s\n" % self.filename 
    585573        _str += "Title:           %s\n" % self.title 
    586574        _str += "Run:             %s\n" % str(self.run) 
     
    599587            _str += "%s\n" % str(item) 
    600588        return _str 
    601              
     589 
    602590    # Private method to perform operation. Not implemented for DataInfo, 
    603591    # but should be implemented for each data class inherited from DataInfo 
     
    610598        """ 
    611599        return NotImplemented 
    612      
     600 
    613601    def _perform_union(self, other): 
    614602        """ 
     
    622610        """ 
    623611        Add two data sets 
    624          
     612 
    625613        :param other: data set to add to the current one 
    626614        :return: new data set 
     
    630618            return a + b 
    631619        return self._perform_operation(other, operation) 
    632          
     620 
    633621    def __radd__(self, other): 
    634622        """ 
    635623        Add two data sets 
    636          
     624 
    637625        :param other: data set to add to the current one 
    638          
    639626        :return: new data set 
    640          
    641627        :raise ValueError: raised when two data sets are incompatible 
    642          
    643628        """ 
    644629        def operation(a, b): 
    645630            return b + a 
    646631        return self._perform_operation(other, operation) 
    647          
     632 
    648633    def __sub__(self, other): 
    649634        """ 
    650635        Subtract two data sets 
    651          
     636 
    652637        :param other: data set to subtract from the current one 
    653          
    654638        :return: new data set 
    655          
    656639        :raise ValueError: raised when two data sets are incompatible 
    657          
    658640        """ 
    659641        def operation(a, b): 
    660642            return a - b 
    661643        return self._perform_operation(other, operation) 
    662          
     644 
    663645    def __rsub__(self, other): 
    664646        """ 
    665647        Subtract two data sets 
    666          
     648 
    667649        :param other: data set to subtract from the current one 
    668          
    669650        :return: new data set 
    670          
    671651        :raise ValueError: raised when two data sets are incompatible 
    672          
    673652        """ 
    674653        def operation(a, b): 
    675654            return b - a 
    676655        return self._perform_operation(other, operation) 
    677          
     656 
    678657    def __mul__(self, other): 
    679658        """ 
    680659        Multiply two data sets 
    681          
     660 
    682661        :param other: data set to subtract from the current one 
    683          
    684662        :return: new data set 
    685          
    686663        :raise ValueError: raised when two data sets are incompatible 
    687          
    688664        """ 
    689665        def operation(a, b): 
    690666            return a * b 
    691667        return self._perform_operation(other, operation) 
    692          
     668 
    693669    def __rmul__(self, other): 
    694670        """ 
    695671        Multiply two data sets 
    696          
     672 
    697673        :param other: data set to subtract from the current one 
    698          
    699674        :return: new data set 
    700          
    701675        :raise ValueError: raised when two data sets are incompatible 
    702676        """ 
     
    704678            return b * a 
    705679        return self._perform_operation(other, operation) 
    706          
     680 
    707681    def __div__(self, other): 
    708682        """ 
    709683        Divided a data set by another 
    710          
     684 
    711685        :param other: data set that the current one is divided by 
    712          
    713686        :return: new data set 
    714          
    715687        :raise ValueError: raised when two data sets are incompatible 
    716          
    717688        """ 
    718689        def operation(a, b): 
    719690            return a/b 
    720691        return self._perform_operation(other, operation) 
    721          
     692 
    722693    def __rdiv__(self, other): 
    723694        """ 
    724695        Divided a data set by another 
    725          
     696 
    726697        :param other: data set that the current one is divided by 
    727          
    728698        :return: new data set 
    729          
    730699        :raise ValueError: raised when two data sets are incompatible 
    731          
    732700        """ 
    733701        def operation(a, b): 
    734702            return b/a 
    735703        return self._perform_operation(other, operation) 
    736              
    737          
     704 
    738705    def __or__(self, other): 
    739706        """ 
    740707        Union a data set with another 
    741          
     708 
    742709        :param other: data set to be unified 
    743          
    744710        :return: new data set 
    745          
    746711        :raise ValueError: raised when two data sets are incompatible 
    747          
    748712        """ 
    749713        return self._perform_union(other) 
    750          
     714 
    751715    def __ror__(self, other): 
    752716        """ 
    753717        Union a data set with another 
    754          
     718 
    755719        :param other: data set to be unified 
    756          
    757720        :return: new data set 
    758          
    759721        :raise ValueError: raised when two data sets are incompatible 
    760          
    761722        """ 
    762723        return self._perform_union(other) 
    763    
     724 
    764725class SESANSData1D(plottable_sesans1D, DataInfo): 
    765726    """ 
     
    768729    x_unit = 'nm' 
    769730    y_unit = 'a.u.' 
    770      
     731 
    771732    def __init__(self, x=None, y=None, lam=None, dy=None, dx=None, dlam=None): 
    772 #        print "dat init" 
    773733        DataInfo.__init__(self) 
    774 #        print "dat init fin" 
    775734        plottable_sesans1D.__init__(self, x, y, lam, dx, dy, dlam) 
    776 #        print "SESANSdata1D init" 
     735 
    777736    def __str__(self): 
    778737        """ 
    779738        Nice printout 
    780739        """ 
    781 #        print "string printer active" 
    782         _str =  "%s\n" % DataInfo.__str__(self) 
    783      
     740        _str = "%s\n" % DataInfo.__str__(self) 
    784741        _str += "Data:\n" 
    785742        _str += "   Type:         %s\n" % self.__class__.__name__ 
     
    787744        _str += "   Y-axis:       %s\t[%s]\n" % (self._yaxis, self._yunit) 
    788745        _str += "   Length:       %g\n" % len(self.x) 
    789 #        print _str 
    790746        return _str 
    791 # 
    792 #    def is_slit_smeared(self): 
    793 #        """ 
    794 #        Check whether the data has slit smearing information 
    795 #         
    796 #        :return: True is slit smearing info is present, False otherwise 
    797 #         
    798 #        """ 
    799 #        def _check(v): 
    800 #            if (v.__class__ == list or v.__class__ == numpy.ndarray) \ 
    801 #                and len(v) > 0 and min(v) > 0: 
    802 #                return True 
    803 #             
    804 #            return False 
    805 #         
    806 #        return _check(self.dxl) or _check(self.dxw) 
    807          
     747 
    808748    def clone_without_data(self, length=0, clone=None): 
    809749        """ 
     
    811751        will be filled out by a subsequent operation). 
    812752        The data arrays will be initialized to zero. 
    813          
     753 
    814754        :param length: length of the data array to be initialized 
    815755        :param clone: if provided, the data will be copied to clone 
    816756        """ 
    817757        from copy import deepcopy 
    818 #        print " SESANS data 1D clone active" 
    819758        if clone is None or not issubclass(clone.__class__, Data1D): 
    820             x  = numpy.zeros(length) 
     759            x = numpy.zeros(length) 
    821760            dx = numpy.zeros(length) 
    822             lam  = numpy.zeros(length) 
    823             dlam = numpy.zeros(length) 
    824             y  = numpy.zeros(length) 
     761            y = numpy.zeros(length) 
    825762            dy = numpy.zeros(length) 
    826763            clone = Data1D(x, y, dx=dx, dy=dy) 
    827          
    828         clone.title          = self.title 
    829         clone.run            = self.run 
    830         clone.filename       = self.filename 
    831         clone.instrument     = self.instrument 
    832         clone.notes          = deepcopy(self.notes) 
    833         clone.process        = deepcopy(self.process) 
    834         clone.detector       = deepcopy(self.detector) 
    835         clone.sample         = deepcopy(self.sample) 
    836         clone.source         = deepcopy(self.source) 
    837         clone.collimation    = deepcopy(self.collimation) 
     764 
     765        clone.title = self.title 
     766        clone.run = self.run 
     767        clone.filename = self.filename 
     768        clone.instrument = self.instrument 
     769        clone.notes = deepcopy(self.notes) 
     770        clone.process = deepcopy(self.process) 
     771        clone.detector = deepcopy(self.detector) 
     772        clone.sample = deepcopy(self.sample) 
     773        clone.source = deepcopy(self.source) 
     774        clone.collimation = deepcopy(self.collimation) 
    838775        clone.trans_spectrum = deepcopy(self.trans_spectrum) 
    839         clone.meta_data      = deepcopy(self.meta_data) 
    840         clone.errors         = deepcopy(self.errors) 
    841 #        print "SESANS Data 1Dclone done" 
     776        clone.meta_data = deepcopy(self.meta_data) 
     777        clone.errors = deepcopy(self.errors) 
     778 
    842779        return clone 
    843                
     780 
    844781class Data1D(plottable_1D, DataInfo): 
    845782    """ 
     
    848785    x_unit = '1/A' 
    849786    y_unit = '1/cm' 
    850      
     787 
    851788    def __init__(self, x, y, dx=None, dy=None): 
    852789        DataInfo.__init__(self) 
    853790        plottable_1D.__init__(self, x, y, dx, dy) 
    854          
     791 
    855792    def __str__(self): 
    856793        """ 
    857794        Nice printout 
    858795        """ 
    859         _str =  "%s\n" % DataInfo.__str__(self) 
    860      
     796        _str = "%s\n" % DataInfo.__str__(self) 
    861797        _str += "Data:\n" 
    862798        _str += "   Type:         %s\n" % self.__class__.__name__ 
     
    864800        _str += "   Y-axis:       %s\t[%s]\n" % (self._yaxis, self._yunit) 
    865801        _str += "   Length:       %g\n" % len(self.x) 
    866  
    867802        return _str 
    868803 
     
    870805        """ 
    871806        Check whether the data has slit smearing information 
    872          
    873807        :return: True is slit smearing info is present, False otherwise 
    874          
    875808        """ 
    876809        def _check(v): 
     
    878811                and len(v) > 0 and min(v) > 0: 
    879812                return True 
    880              
    881813            return False 
    882          
    883814        return _check(self.dxl) or _check(self.dxw) 
    884          
     815 
    885816    def clone_without_data(self, length=0, clone=None): 
    886817        """ 
     
    888819        will be filled out by a subsequent operation). 
    889820        The data arrays will be initialized to zero. 
    890          
     821 
    891822        :param length: length of the data array to be initialized 
    892823        :param clone: if provided, the data will be copied to clone 
    893824        """ 
    894825        from copy import deepcopy 
    895          
     826 
    896827        if clone is None or not issubclass(clone.__class__, Data1D): 
    897             x  = numpy.zeros(length) 
     828            x = numpy.zeros(length) 
    898829            dx = numpy.zeros(length) 
    899             y  = numpy.zeros(length) 
     830            y = numpy.zeros(length) 
    900831            dy = numpy.zeros(length) 
    901832            clone = Data1D(x, y, dx=dx, dy=dy) 
    902          
    903         clone.title          = self.title 
    904         clone.run            = self.run 
    905         clone.filename       = self.filename 
    906         clone.instrument     = self.instrument 
    907         clone.notes          = deepcopy(self.notes) 
    908         clone.process        = deepcopy(self.process) 
    909         clone.detector       = deepcopy(self.detector) 
    910         clone.sample         = deepcopy(self.sample) 
    911         clone.source         = deepcopy(self.source) 
    912         clone.collimation    = deepcopy(self.collimation) 
     833 
     834        clone.title = self.title 
     835        clone.run = self.run 
     836        clone.filename = self.filename 
     837        clone.instrument = self.instrument 
     838        clone.notes = deepcopy(self.notes) 
     839        clone.process = deepcopy(self.process) 
     840        clone.detector = deepcopy(self.detector) 
     841        clone.sample = deepcopy(self.sample) 
     842        clone.source = deepcopy(self.source) 
     843        clone.collimation = deepcopy(self.collimation) 
    913844        clone.trans_spectrum = deepcopy(self.trans_spectrum) 
    914         clone.meta_data      = deepcopy(self.meta_data) 
    915         clone.errors         = deepcopy(self.errors) 
    916          
     845        clone.meta_data = deepcopy(self.meta_data) 
     846        clone.errors = deepcopy(self.errors) 
     847 
    917848        return clone 
    918849 
     
    924855        errors vectors if they were present or vectors 
    925856        of zeros when none was found. 
    926          
     857 
    927858        :param other: other data set for operation 
    928          
    929859        :return: dy for self, dy for other [numpy arrays] 
    930          
    931860        :raise ValueError: when lengths are not compatible 
    932          
    933861        """ 
    934862        dy_other = None 
     
    939867                msg = "Unable to perform operation: data length are not equal" 
    940868                raise ValueError, msg 
    941              
    942869            # Here we could also extrapolate between data points 
    943870            ZERO = 1.0e-12 
     
    946873                    msg = "Incompatible data sets: x-values do not match" 
    947874                    raise ValueError, msg 
    948                 """ 
    949                 if self.dxl != None and other.dxl == None: 
    950                     msg = "Incompatible data sets: dxl-values do not match" 
    951                     raise ValueError, msg 
    952                 if self.dxl == None and other.dxl != None: 
    953                     msg = "Incompatible data sets: dxl-values do not match" 
    954                     raise ValueError, msg 
    955                 if self.dxw != None and other.dxw == None: 
    956                     msg = "Incompatible data sets: dxw-values do not match" 
    957                     raise ValueError, msg 
    958                 if self.dxw == None and other.dxw != None: 
    959                     msg = "Incompatible data sets: dxw-values do not match" 
    960                     raise ValueError, msg 
    961                 """ 
     875 
    962876            # Check that the other data set has errors, otherwise 
    963877            # create zero vector 
     
    965879            if other.dy == None or (len(other.dy) != len(other.y)): 
    966880                dy_other = numpy.zeros(len(other.y)) 
    967              
     881 
    968882        # Check that we have errors, otherwise create zero vector 
    969883        dy = self.dy 
    970884        if self.dy == None or (len(self.dy) != len(self.y)): 
    971885            dy = numpy.zeros(len(self.y)) 
    972              
     886 
    973887        return dy, dy_other 
    974888 
     
    996910            if self.dxl is not None and len(self.x) == len(self.dxl): 
    997911                result.dxl[i] = self.dxl[i] 
    998              
     912 
    999913            a = Uncertainty(self.y[i], dy[i]**2) 
    1000914            if isinstance(other, Data1D): 
     
    1012926            else: 
    1013927                b = other 
    1014              
     928 
    1015929            output = operation(a, b) 
    1016930            result.y[i] = output.x 
    1017931            result.dy[i] = math.sqrt(math.fabs(output.variance)) 
    1018932        return result 
    1019      
     933 
    1020934    def _validity_check_union(self, other): 
    1021935        """ 
     
    1025939        errors vectors if they were present or vectors 
    1026940        of zeros when none was found. 
    1027          
     941 
    1028942        :param other: other data set for operation 
    1029          
    1030943        :return: bool 
    1031          
    1032944        :raise ValueError: when data types are not compatible 
    1033          
    1034945        """ 
    1035946        if not isinstance(other, Data1D): 
    1036947            msg = "Unable to perform operation: different types of data set" 
    1037             raise ValueError, msg    
     948            raise ValueError, msg 
    1038949        return True 
    1039950 
     
    1080991            result.dxl = result.dxl[ind] 
    1081992        return result 
    1082          
    1083          
     993 
     994 
    1084995class Data2D(plottable_2D, DataInfo): 
    1085996    """ 
     
    1088999    ## Units for Q-values 
    10891000    Q_unit = '1/A' 
    1090      
    10911001    ## Units for I(Q) values 
    10921002    I_unit = '1/cm' 
    1093      
    10941003    ## Vector of Q-values at the center of each bin in x 
    10951004    x_bins = None 
    1096      
    10971005    ## Vector of Q-values at the center of each bin in y 
    10981006    y_bins = None 
    1099      
     1007 
    11001008    def __init__(self, data=None, err_data=None, qx_data=None, 
    11011009                 qy_data=None, q_data=None, mask=None, 
     
    11111019    def __str__(self): 
    11121020        _str = "%s\n" % DataInfo.__str__(self) 
    1113          
    11141021        _str += "Data:\n" 
    11151022        _str += "   Type:         %s\n" % self.__class__.__name__ 
    11161023        _str += "   X- & Y-axis:  %s\t[%s]\n" % (self._yaxis, self._yunit) 
    11171024        _str += "   Z-axis:       %s\t[%s]\n" % (self._zaxis, self._zunit) 
    1118         #leny = 0 
    1119         #if len(self.data) > 0: 
    1120         #    leny = len(self.data) 
    11211025        _str += "   Length:       %g \n" % (len(self.data)) 
    1122          
    11231026        return _str 
    1124    
     1027 
    11251028    def clone_without_data(self, length=0, clone=None): 
    11261029        """ 
     
    11281031        will be filled out by a subsequent operation). 
    11291032        The data arrays will be initialized to zero. 
    1130          
     1033 
    11311034        :param length: length of the data array to be initialized 
    11321035        :param clone: if provided, the data will be copied to clone 
    11331036        """ 
    11341037        from copy import deepcopy 
    1135          
     1038 
    11361039        if clone is None or not issubclass(clone.__class__, Data2D): 
    11371040            data = numpy.zeros(length) 
     
    11431046            dqx_data = None 
    11441047            dqy_data = None 
    1145             clone = Data2D(data=data, err_data=err_data,  
    1146                            qx_data=qx_data, qy_data=qy_data,  
     1048            clone = Data2D(data=data, err_data=err_data, 
     1049                           qx_data=qx_data, qy_data=qy_data, 
    11471050                           q_data=q_data, mask=mask) 
    11481051 
    1149         clone.title       = self.title 
    1150         clone.run         = self.run 
    1151         clone.filename    = self.filename 
    1152         clone.instrument  = self.instrument 
    1153         clone.notes       = deepcopy(self.notes) 
    1154         clone.process     = deepcopy(self.process) 
    1155         clone.detector    = deepcopy(self.detector) 
    1156         clone.sample      = deepcopy(self.sample) 
    1157         clone.source      = deepcopy(self.source) 
     1052        clone.title = self.title 
     1053        clone.run = self.run 
     1054        clone.filename = self.filename 
     1055        clone.instrument = self.instrument 
     1056        clone.notes = deepcopy(self.notes) 
     1057        clone.process = deepcopy(self.process) 
     1058        clone.detector = deepcopy(self.detector) 
     1059        clone.sample = deepcopy(self.sample) 
     1060        clone.source = deepcopy(self.source) 
    11581061        clone.collimation = deepcopy(self.collimation) 
    1159         clone.meta_data   = deepcopy(self.meta_data) 
    1160         clone.errors      = deepcopy(self.errors) 
    1161          
     1062        clone.meta_data = deepcopy(self.meta_data) 
     1063        clone.errors = deepcopy(self.errors) 
     1064 
    11621065        return clone 
    1163    
     1066 
    11641067    def _validity_check(self, other): 
    11651068        """ 
     
    11691072        errors vectors if they were present or vectors 
    11701073        of zeros when none was found. 
    1171          
     1074 
    11721075        :param other: other data set for operation 
    1173          
    11741076        :return: dy for self, dy for other [numpy arrays] 
    1175          
    11761077        :raise ValueError: when lengths are not compatible 
    1177          
    11781078        """ 
    11791079        err_other = None 
     
    11851085                msg = "Unable to perform operation: data length are not equal" 
    11861086                raise ValueError, msg 
    1187             #if len(self.data) < 1: 
    1188             #    msg = "Incompatible data sets: I-values do not match" 
    1189             #    raise ValueError, msg  
    11901087            for ind in range(len(self.data)): 
    11911088                if self.qx_data[ind] != other.qx_data[ind]: 
     
    11951092                    msg = "Incompatible data sets: qy-values do not match" 
    11961093                    raise ValueError, msg 
    1197                     
     1094 
    11981095            # Check that the scales match 
    11991096            err_other = other.err_data 
     
    12011098                (len(other.err_data) != len(other.data)): 
    12021099                err_other = numpy.zeros(len(other.data)) 
    1203              
     1100 
    12041101        # Check that we have errors, otherwise create zero vector 
    12051102        err = self.err_data 
     
    12071104            (len(self.err_data) != len(self.data)): 
    12081105            err = numpy.zeros(len(other.data)) 
    1209              
    12101106        return err, err_other 
    1211    
     1107 
    12121108    def _perform_operation(self, other, operation): 
    12131109        """ 
    12141110        Perform 2D operations between data sets 
    1215          
     1111 
    12161112        :param other: other data set 
    12171113        :param operation: function defining the operation 
    1218          
    12191114        """ 
    12201115        # First, check the data compatibility 
     
    12311126            if self.err_data is not None and \ 
    12321127                numpy.size(self.data) == numpy.size(self.err_data): 
    1233                 result.err_data[i] = self.err_data[i]     
     1128                result.err_data[i] = self.err_data[i] 
    12341129            if self.dqx_data is not None: 
    12351130                result.dqx_data[i] = self.dqx_data[i] 
     
    12401135            result.q_data[i] = self.q_data[i] 
    12411136            result.mask[i] = self.mask[i] 
    1242              
     1137 
    12431138            a = Uncertainty(self.data[i], dy[i]**2) 
    12441139            if isinstance(other, Data2D): 
     
    12491144                    result.dqx_data[i] += (other.dqx_data[i]**2) 
    12501145                    result.dqx_data[i] /= 2 
    1251                     result.dqx_data[i] = math.sqrt(result.dqx_data[i])      
     1146                    result.dqx_data[i] = math.sqrt(result.dqx_data[i]) 
    12521147                if other.dqy_data is not None and \ 
    12531148                        result.dqy_data is not None: 
     
    12581153            else: 
    12591154                b = other 
    1260              
    12611155            output = operation(a, b) 
    12621156            result.data[i] = output.x 
    12631157            result.err_data[i] = math.sqrt(math.fabs(output.variance)) 
    12641158        return result 
    1265      
     1159 
    12661160    def _validity_check_union(self, other): 
    12671161        """ 
     
    12711165        errors vectors if they were present or vectors 
    12721166        of zeros when none was found. 
    1273          
     1167 
    12741168        :param other: other data set for operation 
    1275          
    12761169        :return: bool 
    1277          
    12781170        :raise ValueError: when data types are not compatible 
    1279          
    12801171        """ 
    12811172        if not isinstance(other, Data2D): 
    12821173            msg = "Unable to perform operation: different types of data set" 
    1283             raise ValueError, msg    
     1174            raise ValueError, msg 
    12841175        return True 
    1285      
     1176 
    12861177    def _perform_union(self, other): 
    12871178        """ 
    12881179        Perform 2D operations between data sets 
    1289          
     1180 
    12901181        :param other: other data set 
    12911182        :param operation: function defining the operation 
    1292          
    12931183        """ 
    12941184        # First, check the data compatibility 
     
    13011191        result.ymax = self.ymax 
    13021192        if self.dqx_data == None or self.dqy_data == None or \ 
    1303                 other.dqx_data == None or other.dqy_data == None : 
     1193                other.dqx_data == None or other.dqy_data == None: 
    13041194            result.dqx_data = None 
    13051195            result.dqy_data = None 
     
    13091199            result.dqy_data = numpy.zeros(len(self.data) + \ 
    13101200                                         numpy.size(other.data)) 
    1311          
     1201 
    13121202        result.data = numpy.append(self.data, other.data) 
    13131203        result.qx_data = numpy.append(self.qx_data, other.qx_data) 
Note: See TracChangeset for help on using the changeset viewer.