Ignore:
Timestamp:
Apr 27, 2012 10:42:24 AM (12 years ago)
Author:
Mathieu Doucet <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:
7d6351e
Parents:
10bfeb3
Message:

Pep-8-ification

File:
1 edited

Legend:

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

    re38e335 rf60a8c2  
    11""" 
    2     Module that contains classes to hold information read from  
     2    Module that contains classes to hold information read from 
    33    reduced data files. 
    44     
    5     A good description of the data members can be found in  
     5    A good description of the data members can be found in 
    66    the CanSAS 1D XML data format: 
    77     
    88    http://www.smallangles.net/wgwiki/index.php/cansas1d_documentation 
    99""" 
    10  
    11  
     10##################################################################### 
    1211#This software was developed by the University of Tennessee as part of the 
    1312#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    14 #project funded by the US National Science Foundation.  
    15 #If you use DANSE applications to do scientific research that leads to  
    16 #publication, we ask that you acknowledge the use of the software with the  
    17 #following sentence: 
    18 #This work benefited from DANSE software developed under NSF award DMR-0520547. 
     13#project funded by the US National Science Foundation. 
     14#See the license text in license.txt 
    1915#copyright 2008, University of Tennessee 
     16###################################################################### 
    2017 
    2118 
     
    2825import numpy 
    2926import math 
     27 
    3028 
    3129class plottable_1D: 
     
    5452        self.y = numpy.asarray(y) 
    5553        if dx is not None: 
    56              self.dx = numpy.asarray(dx) 
    57         if dy is not None:  
     54            self.dx = numpy.asarray(dx) 
     55        if dy is not None: 
    5856            self.dy = numpy.asarray(dy) 
    59         if dxl is not None:  
     57        if dxl is not None: 
    6058            self.dxl = numpy.asarray(dxl) 
    6159        if dxw is not None:  
     
    7573        self._yaxis = label 
    7674        self._yunit = unit 
     75 
    7776 
    7877class plottable_2D: 
     
    8584    ymax = None 
    8685    data = None 
    87     qx_data     = None 
    88     qy_data     = None 
    89     q_data      = None 
    90     err_data    = None 
    91     dqx_data    = None 
    92     dqy_data    = None 
    93     mask        = None 
     86    qx_data = None 
     87    qy_data = None 
     88    q_data = None 
     89    err_data = None 
     90    dqx_data = None 
     91    dqy_data = None 
     92    mask = None 
    9493     
    9594    # Units 
     
    102101     
    103102    def __init__(self, data=None, err_data=None, qx_data=None, 
    104                   qy_data=None, q_data=None, mask=None, 
    105                    dqx_data=None, dqy_data=None): 
     103                 qy_data=None, q_data=None, mask=None, 
     104                 dqx_data=None, dqy_data=None): 
    106105        self.data = numpy.asarray(data) 
    107106        self.qx_data = numpy.asarray(qx_data) 
     
    110109        self.mask = numpy.asarray(mask) 
    111110        self.err_data = numpy.asarray(err_data) 
    112         if dqx_data is not None: self.dqx_data = numpy.asarray(dqx_data)  
    113         if dqy_data is not None: self.dqy_data = numpy.asarray(dqy_data)  
     111        if dqx_data is not None: 
     112            self.dqx_data = numpy.asarray(dqx_data)  
     113        if dqy_data is not None: 
     114            self.dqy_data = numpy.asarray(dqy_data)  
    114115                
    115116    def xaxis(self, label, unit): 
     
    174175    distance = None 
    175176    distance_unit = 'mm' 
    176     ## Offset of this detector position in X, Y,  
    177     #(and Z if necessary) [Vector] [mm]  
     177    ## Offset of this detector position in X, Y, 
     178    #(and Z if necessary) [Vector] [mm] 
    178179    offset = None 
    179180    offset_unit = 'm' 
     
    182183    orientation = None 
    183184    orientation_unit = 'degree' 
    184     ## Center of the beam on the detector in X and Y  
     185    ## Center of the beam on the detector in X and Y 
    185186    #(and Z if necessary) [Vector] [mm] 
    186187    beam_center = None 
     
    204205        self.pixel_size  = Vector() 
    205206         
    206      
    207207    def __str__(self): 
    208208        _str  = "Detector:\n" 
     
    222222        return _str 
    223223 
     224 
    224225class Aperture: 
    225226    ## Name 
     
    239240        self.size = Vector() 
    240241     
     242     
    241243class Collimation: 
    242244    """ 
     
    265267        return _str 
    266268 
     269 
    267270class Source: 
    268271    """ 
    269272    Class to hold source information 
    270     """   
     273    """ 
    271274    ## Name 
    272275    name = None 
     
    296299        self.beam_size = Vector() 
    297300         
    298      
    299301    def __str__(self): 
    300302        _str  = "Source:\n" 
     
    314316     
    315317     
    316 """  
     318""" 
    317319Definitions of radiation types 
    318320""" 
     
    321323MUON     = 'muon' 
    322324ELECTRON = 'electron' 
     325     
    323326     
    324327class Sample: 
     
    371374        return _str 
    372375   
     376   
    373377class Process: 
    374378    """ 
     
    405409    the data itself and any other meta data. 
    406410    """ 
    407     ## Title  
     411    ## Title 
    408412    title      = '' 
    409413    ## Run number 
     
    460464        self.meta_data  = {} 
    461465        ## Loading errors 
    462         self.errors = []         
     466        self.errors = [] 
    463467         
    464468    def append_empty_process(self): 
     
    497501    # but should be implemented for each data class inherited from DataInfo 
    498502    # that holds actual data (ex.: Data1D) 
    499     def _perform_operation(self, other, operation):  
     503    def _perform_operation(self, other, operation): 
    500504        """ 
    501505        Private method to perform operation. Not implemented for DataInfo, 
     
    619623        def operation(a, b): 
    620624            return b/a 
    621         return self._perform_operation(other, operation)             
     625        return self._perform_operation(other, operation) 
     626             
    622627             
    623628class Data1D(plottable_1D, DataInfo): 
     
    631636        DataInfo.__init__(self) 
    632637        plottable_1D.__init__(self, x, y, dx, dy) 
    633          
    634638         
    635639    def __str__(self): 
     
    654658         
    655659        """ 
    656         def _check(v):             
     660        def _check(v): 
    657661            if (v.__class__ == list or v.__class__ == numpy.ndarray) \ 
    658662                and len(v) > 0 and min(v) > 0: 
     
    675679         
    676680        if clone is None or not issubclass(clone.__class__, Data1D): 
    677             x  = numpy.zeros(length)  
    678             dx = numpy.zeros(length)  
    679             y  = numpy.zeros(length)  
    680             dy = numpy.zeros(length)  
     681            x  = numpy.zeros(length) 
     682            dx = numpy.zeros(length) 
     683            y  = numpy.zeros(length) 
     684            dy = numpy.zeros(length) 
    681685            clone = Data1D(x, y, dx=dx, dy=dy) 
    682686         
     
    684688        clone.run         = self.run 
    685689        clone.filename    = self.filename 
    686         clone.instrument   = self.instrument 
    687         clone.notes       = deepcopy(self.notes)  
    688         clone.process     = deepcopy(self.process)  
    689         clone.detector    = deepcopy(self.detector)  
    690         clone.sample      = deepcopy(self.sample)  
    691         clone.source      = deepcopy(self.source)  
    692         clone.collimation = deepcopy(self.collimation)  
    693         clone.meta_data   = deepcopy(self.meta_data)  
    694         clone.errors      = deepcopy(self.errors)  
     690        clone.instrument  = self.instrument 
     691        clone.notes       = deepcopy(self.notes) 
     692        clone.process     = deepcopy(self.process) 
     693        clone.detector    = deepcopy(self.detector) 
     694        clone.sample      = deepcopy(self.sample) 
     695        clone.source      = deepcopy(self.source) 
     696        clone.collimation = deepcopy(self.collimation) 
     697        clone.meta_data   = deepcopy(self.meta_data) 
     698        clone.errors      = deepcopy(self.errors) 
    695699         
    696700        return clone 
     
    716720            if len(self.x) != len(other.x) or \ 
    717721                len(self.y) != len(other.y): 
    718                 msg =  "Unable to perform operation: data length are not equal" 
     722                msg = "Unable to perform operation: data length are not equal" 
    719723                raise ValueError, msg 
    720724             
     
    734738        dy = self.dy 
    735739        if self.dy == None or (len(self.dy) != len(self.y)): 
    736             dy = numpy.zeros(len(self.y))             
     740            dy = numpy.zeros(len(self.y)) 
    737741             
    738742        return dy, dy_other 
     
    761765        return result 
    762766         
     767         
    763768class Data2D(plottable_2D, DataInfo): 
    764769    """ 
     
    777782    y_bins = None 
    778783     
    779      
    780784    def __init__(self, data=None, err_data=None, qx_data=None, 
    781                   qy_data=None, q_data=None, mask=None,  
    782                   dqx_data=None, dqy_data=None): 
     785                 qy_data=None, q_data=None, mask=None, 
     786                 dqx_data=None, dqy_data=None): 
    783787        self.y_bins = [] 
    784788        self.x_bins = [] 
    785789        DataInfo.__init__(self) 
    786790        plottable_2D.__init__(self, data, err_data, qx_data, 
    787                               qy_data, q_data,mask, dqx_data, dqy_data) 
     791                              qy_data, q_data, mask, dqx_data, dqy_data) 
    788792        if len(self.detector) > 0: 
    789793            raise RuntimeError, "Data2D: Detector bank already filled at init" 
    790794 
    791795    def __str__(self): 
    792         _str =  "%s\n" % DataInfo.__str__(self) 
     796        _str = "%s\n" % DataInfo.__str__(self) 
    793797         
    794798        _str += "Data:\n" 
     
    814818        from copy import deepcopy 
    815819         
    816         if clone is None or not issubclass(clone.__class__, Data2D):   
    817             data     = numpy.zeros(length)  
    818             err_data = numpy.zeros(length)  
     820        if clone is None or not issubclass(clone.__class__, Data2D): 
     821            data = numpy.zeros(length) 
     822            err_data = numpy.zeros(length) 
    819823            qx_data = numpy.zeros(length) 
    820824            qy_data = numpy.zeros(length) 
     
    824828            dqy_data = None 
    825829            clone = Data2D(data, err_data, qx_data, qy_data, 
    826                             q_data,mask, dqx_data=dqx_data, dqy_data=dqy_data) 
     830                            q_data, mask, dqx_data=dqx_data, dqy_data=dqy_data) 
    827831 
    828832        clone.title       = self.title 
     
    830834        clone.filename    = self.filename 
    831835        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)  
    838         clone.meta_data   = deepcopy(self.meta_data)  
    839         clone.errors      = deepcopy(self.errors)  
     836        clone.notes       = deepcopy(self.notes) 
     837        clone.process     = deepcopy(self.process) 
     838        clone.detector    = deepcopy(self.detector) 
     839        clone.sample      = deepcopy(self.sample) 
     840        clone.source      = deepcopy(self.source) 
     841        clone.collimation = deepcopy(self.collimation) 
     842        clone.meta_data   = deepcopy(self.meta_data) 
     843        clone.errors      = deepcopy(self.errors) 
    840844         
    841845        return clone 
    842    
    843846   
    844847    def _validity_check(self, other): 
     
    865868                
    866869            # Check that the scales match 
    867             #TODO: matching scales?      
     870            #TODO: matching scales? 
    868871             
    869872            # Check that the other data set has errors, otherwise 
     
    885888        return err, err_other 
    886889   
    887    
    888890    def _perform_operation(self, other, operation): 
    889891        """ 
     
    897899        dy, dy_other = self._validity_check(other) 
    898900     
    899         result = self.clone_without_data([numpy.size(self.data, 0),  
     901        result = self.clone_without_data([numpy.size(self.data, 0), 
    900902                                          numpy.size(self.data, 1)]) 
    901903         
     
    917919                result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 
    918920        return result 
    919      
    920    
    921   
Note: See TracChangeset for help on using the changeset viewer.