Ignore:
Timestamp:
Apr 27, 2012 11:22:31 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:
4a96b8b
Parents:
f60a8c2
Message:

Pep-8-ification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansdataloader/src/sans/dataloader/readers/abs_reader.py

    raac129aa r7d6351e  
    44#This software was developed by the University of Tennessee as part of the 
    55#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    6 #project funded by the US National Science Foundation.  
     6#project funded by the US National Science Foundation. 
    77#See the license text in license.txt 
    88#copyright 2008, University of Tennessee 
     
    2020    has_converter = False 
    2121     
     22     
    2223class Reader: 
    2324    """ 
     
    2526    """ 
    2627    ## File type 
    27     type_name = "IGOR 1D"    
     28    type_name = "IGOR 1D" 
    2829    ## Wildcards 
    2930    type = ["IGOR 1D files (*.abs)|*.abs"] 
    3031    ## List of allowed extensions 
    31     ext = ['.abs', '.ABS']   
     32    ext = ['.abs', '.ABS'] 
    3233     
    3334    def read(self, path): 
     
    4344        """ 
    4445        if os.path.isfile(path): 
    45             basename  = os.path.basename(path) 
     46            basename = os.path.basename(path) 
    4647            root, extension = os.path.splitext(basename) 
    4748            if extension.lower() in self.ext: 
    4849                try: 
    49                     input_f =  open(path,'r') 
    50                 except : 
     50                    input_f = open(path,'r') 
     51                except: 
    5152                    raise  RuntimeError, "abs_reader: cannot open %s" % path 
    5253                buff = input_f.read() 
     
    9192                                output.source.wavelength_unit != 'A': 
    9293                                conv = Converter('A') 
    93                                 output.source.wavelength = conv(value,  
     94                                output.source.wavelength = conv(value, 
    9495                                        units=output.source.wavelength_unit) 
    9596                            else: 
     
    99100                            msg = "abs_reader: cannot open %s" % path 
    100101                            raise  RuntimeError, msg 
    101                             #raise ValueError,"IgorReader: can't read this file, 
    102                             # missing wavelength" 
    103102                         
    104103                        # Distance in meters 
     
    108107                                detector.distance_unit != 'm': 
    109108                                conv = Converter('m') 
    110                                 detector.distance = conv(value,  
     109                                detector.distance = conv(value, 
    111110                                                units=detector.distance_unit) 
    112111                            else: 
     
    116115                            msg = "abs_reader: cannot open %s" % path 
    117116                            raise  RuntimeError, msg 
    118                         # Transmission  
     117                        # Transmission 
    119118                        try: 
    120119                            output.sample.transmission = float(line_toks[4]) 
     
    129128                                output.sample.thickness_unit != 'cm': 
    130129                                conv = Converter('cm') 
    131                                 output.sample.thickness = conv(value,  
     130                                output.sample.thickness = conv(value, 
    132131                                            units=output.sample.thickness_unit) 
    133132                            else: 
     
    144143                    # Find center info line 
    145144                    if is_center == True: 
    146                         is_center = False                 
     145                        is_center = False 
    147146                        line_toks = line.split() 
    148147                        # Center in bin number 
     
    154153                            detector.pixel_size_unit != 'mm': 
    155154                            conv = Converter('mm') 
    156                             detector.pixel_size.x = conv(5.0,  
     155                            detector.pixel_size.x = conv(5.0, 
    157156                                                units=detector.pixel_size_unit) 
    158157                            detector.pixel_size.y = conv(5.0, 
     
    164163                        # Store beam center in distance units 
    165164                        # Det 640 x 640 mm 
    166                         if has_converter==True and \ 
     165                        if has_converter == True and \ 
    167166                            detector.beam_center_unit != 'mm': 
    168167                            conv = Converter('mm') 
    169168                            detector.beam_center.x = conv(center_x * 5.0, 
    170169                                             units=detector.beam_center_unit) 
    171                             detector.beam_center.y = conv(center_y * 5.0,  
     170                            detector.beam_center.y = conv(center_y * 5.0, 
    172171                                            units=detector.beam_center_unit) 
    173172                        else: 
     
    182181                            pass 
    183182                     
    184                     #BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L  
    185                     #  BSTOP(mm)   DET_TYP  
     183                    #BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L 
     184                    #  BSTOP(mm)   DET_TYP 
    186185                    if line.count("BCENT") > 0: 
    187186                        is_center = True 
     
    191190                        toks = line.split() 
    192191 
    193                         try:   
     192                        try: 
    194193                            _x  = float(toks[0]) 
    195                             _y  = float(toks[1])  
     194                            _y  = float(toks[1]) 
    196195                            _dy = float(toks[2]) 
    197196                            _dx = float(toks[3]) 
     
    205204                                _dy = data_conv_i(_dy, units=output.y_unit) 
    206205                            
    207                             x  = numpy.append(x,   _x)  
    208                             y  = numpy.append(y,  _y) 
     206                            x = numpy.append(x, _x) 
     207                            y = numpy.append(y, _y) 
    209208                            dy = numpy.append(dy, _dy) 
    210                             dx  = numpy.append(dx, _dx) 
     209                            dx = numpy.append(dx, _dx) 
    211210                             
    212211                        except: 
     
    218217                    #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. 
    219218                    # I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 
    220                     if line.count("The 6 columns")>0: 
     219                    if line.count("The 6 columns") > 0: 
    221220                        is_data_started = True 
    222221             
     
    230229                    raise ValueError, "ascii_reader: could not load file" 
    231230                 
    232                 output.x = x[x!=0] 
    233                 output.y = y[x!=0] 
    234                 output.dy = dy[x!=0] 
    235                 output.dx = dx[x!=0] 
     231                output.x = x[x != 0] 
     232                output.y = y[x != 0] 
     233                output.dy = dy[x != 0] 
     234                output.dx = dx[x != 0] 
    236235                if data_conv_q is not None: 
    237236                    output.xaxis("\\rm{Q}", output.x_unit) 
     
    241240                    output.yaxis("\\rm{Intensity}", output.y_unit) 
    242241                else: 
    243                     output.yaxis("\\rm{Intensity}","cm^{-1}") 
     242                    output.yaxis("\\rm{Intensity}", "cm^{-1}") 
    244243                     
    245244                # Store loading process information 
    246                 output.meta_data['loader'] = self.type_name                        
     245                output.meta_data['loader'] = self.type_name 
    247246                return output 
    248247        else: 
    249248            raise RuntimeError, "%s is not a file" % path 
    250249        return None 
    251      
    252 if __name__ == "__main__":  
    253     reader = Reader() 
    254     print reader.read("../test/jan08002.ABS") 
    255      
    256      
    257              
Note: See TracChangeset for help on using the changeset viewer.