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/IgorReader.py

    rad8034f r7d6351e  
    1  
     1""" 
     2    IGOR 2D reduced file reader 
     3""" 
    24############################################################################ 
    35#This software was developed by the University of Tennessee as part of the 
     
    1012#copyright 2008, University of Tennessee 
    1113############################################################################# 
    12  
    13 """ 
    14     IGOR 2D reduced file reader 
    15 """ 
    16  
    1714import os 
    18 #import sys 
    1915import numpy 
    2016import math 
     
    3127    has_converter = False 
    3228 
     29 
    3330class Reader: 
    3431    """ Simple data reader for Igor data files """ 
    3532    ## File type 
    36     type_name = "IGOR 2D"    
     33    type_name = "IGOR 2D" 
    3734    ## Wildcards 
    3835    type = ["IGOR 2D files (*.ASC)|*.ASC"] 
     
    4037    ext=['.ASC', '.asc'] 
    4138 
    42     def read(self,filename=None): 
     39    def read(self, filename=None): 
    4340        """ Read file """ 
    4441        if not os.path.isfile(filename): 
     
    4744         
    4845        # Read file 
    49         f = open(filename,'r') 
     46        f = open(filename, 'r') 
    5047        buf = f.read() 
    5148         
     
    5451        output.filename = os.path.basename(filename) 
    5552        detector = Detector() 
    56         if len(output.detector)>0: print str(output.detector[0]) 
     53        if len(output.detector) > 0: 
     54            print str(output.detector[0]) 
    5755        output.detector.append(detector) 
    5856                 
    5957        # Get content 
    6058        dataStarted = False 
    61          
    6259         
    6360        lines = buf.split('\n') 
     
    9188            data_conv_i = Converter('1/cm') 
    9289            # Test it 
    93             data_conv_i(1.0, output.I_unit)             
     90            data_conv_i(1.0, output.I_unit) 
    9491          
    9592        for line in lines: 
     
    117114                 
    118115            i_tot_row += 1 
    119         i_tot_row=math.ceil(math.sqrt(i_tot_row))-1  
     116        i_tot_row = math.ceil(math.sqrt(i_tot_row)) - 1 
    120117        #print "i_tot", i_tot_row 
    121         size_x = i_tot_row#192#128 
    122         size_y = i_tot_row#192#128 
    123         output.data = numpy.zeros([size_x,size_y]) 
    124         output.err_data = numpy.zeros([size_x,size_y]) 
     118        size_x = i_tot_row  # 192#128 
     119        size_y = i_tot_row  # 192#128 
     120        output.data = numpy.zeros([size_x, size_y]) 
     121        output.err_data = numpy.zeros([size_x, size_y]) 
    125122      
    126123        #Read Header and 2D data 
     
    151148                    raise ValueError, msg 
    152149                                             
    153             if line.count("LAMBDA")>0: 
     150            if line.count("LAMBDA") > 0: 
    154151                isInfo = True 
    155152                 
    156153            # Find center info line 
    157154            if isCenter: 
    158                 isCenter = False                 
     155                isCenter = False 
    159156                line_toks = line.split() 
    160157                 
    161                 # Center in bin number: Must substrate 1 because  
     158                # Center in bin number: Must substrate 1 because 
    162159                #the index starts from 1 
    163                 center_x = float(line_toks[0])-1 
    164                 center_y = float(line_toks[1])-1 
    165  
    166             if line.count("BCENT")>0: 
     160                center_x = float(line_toks[0]) - 1 
     161                center_y = float(line_toks[1]) - 1 
     162 
     163            if line.count("BCENT") > 0: 
    167164                isCenter = True 
    168165                 
    169          
    170166            # Find data start 
    171167            if line.count("***")>0: 
     
    188184                 
    189185                # Get bin number 
    190                 if math.fmod(itot, i_tot_row)==0: 
     186                if math.fmod(itot, i_tot_row) == 0: 
    191187                    i_x = 0 
    192188                    i_y += 1 
     
    195191                     
    196192                output.data[i_y][i_x] = value 
    197                 ncounts += 1  
     193                ncounts += 1 
    198194                 
    199195                # Det 640 x 640 mm 
    200196                # Q = 4pi/lambda sin(theta/2) 
    201197                # Bin size is 0.5 cm  
    202                 #REmoved +1 from theta = (i_x-center_x+1)*0.5 / distance  
     198                #REmoved +1 from theta = (i_x-center_x+1)*0.5 / distance 
    203199                # / 100.0 and  
    204200                #REmoved +1 from theta = (i_y-center_y+1)*0.5 / 
     
    206202                #ToDo: Need  complete check if the following 
    207203                # covert process is consistent with fitting.py. 
    208                 theta = (i_x-center_x)*0.5 / distance / 100.0 
    209                 qx = 4.0*math.pi/wavelength * math.sin(theta/2.0) 
     204                theta = (i_x - center_x) * 0.5 / distance / 100.0 
     205                qx = 4.0 * math.pi / wavelength * math.sin(theta/2.0) 
    210206 
    211207                if has_converter == True and output.Q_unit != '1/A': 
    212208                    qx = data_conv_q(qx, units=output.Q_unit) 
    213209 
    214                 if xmin==None or qx<xmin: 
     210                if xmin == None or qx < xmin: 
    215211                    xmin = qx 
    216                 if xmax==None or qx>xmax: 
     212                if xmax == None or qx > xmax: 
    217213                    xmax = qx 
    218214                 
    219                 theta = (i_y-center_y)*0.5 / distance / 100.0 
    220                 qy = 4.0*math.pi/wavelength * math.sin(theta/2.0) 
     215                theta = (i_y - center_y) * 0.5 / distance / 100.0 
     216                qy = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 
    221217 
    222218                if has_converter == True and output.Q_unit != '1/A': 
    223219                    qy = data_conv_q(qy, units=output.Q_unit) 
    224220                 
    225                 if ymin==None or qy<ymin: 
     221                if ymin == None or qy < ymin: 
    226222                    ymin = qy 
    227                 if ymax==None or qy>ymax: 
     223                if ymax == None or qy > ymax: 
    228224                    ymax = qy 
    229225                 
     
    237233                   
    238234        theta = 0.25 / distance / 100.0 
    239         xstep = 4.0*math.pi/wavelength * math.sin(theta/2.0) 
     235        xstep = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 
    240236         
    241237        theta = 0.25 / distance / 100.0 
    242         ystep = 4.0*math.pi/wavelength * math.sin(theta/2.0) 
     238        ystep = 4.0 * math.pi/ wavelength * math.sin(theta / 2.0) 
    243239         
    244240        # Store all data ###################################### 
    245241        # Store wavelength 
    246         if has_converter==True and output.source.wavelength_unit != 'A': 
     242        if has_converter == True and output.source.wavelength_unit != 'A': 
    247243            conv = Converter('A') 
    248244            wavelength = conv(wavelength, units=output.source.wavelength_unit) 
     
    250246 
    251247        # Store distance 
    252         if has_converter==True and detector.distance_unit != 'm': 
     248        if has_converter == True and detector.distance_unit != 'm': 
    253249            conv = Converter('m') 
    254250            distance = conv(distance, units=detector.distance_unit) 
     
    260256        # Store pixel size 
    261257        pixel = 5.0 
    262         if has_converter==True and detector.pixel_size_unit != 'mm': 
     258        if has_converter == True and detector.pixel_size_unit != 'mm': 
    263259            conv = Converter('mm') 
    264260            pixel = conv(pixel, units=detector.pixel_size_unit) 
     
    267263   
    268264        # Store beam center in distance units 
    269         detector.beam_center.x = center_x*pixel 
    270         detector.beam_center.y = center_y*pixel 
    271    
     265        detector.beam_center.x = center_x * pixel 
     266        detector.beam_center.y = center_y * pixel 
    272267         
    273268        # Store limits of the image (2D array) 
    274         xmin    =xmin-xstep/2.0 
    275         xmax    =xmax+xstep/2.0 
    276         ymin    =ymin-ystep/2.0 
    277         ymax    =ymax+ystep/2.0 
     269        xmin = xmin - xstep / 2.0 
     270        xmax = xmax + xstep / 2.0 
     271        ymin = ymin - ystep / 2.0 
     272        ymax = ymax + ystep / 2.0 
    278273        if has_converter == True and output.Q_unit != '1/A': 
    279274            xmin = data_conv_q(xmin, units=output.Q_unit) 
     
    287282         
    288283        # Store x and y axis bin centers 
    289         output.x_bins     = x 
    290         output.y_bins     = y 
     284        output.x_bins = x 
     285        output.y_bins = y 
    291286         
    292287        # Units 
     
    301296            output.zaxis("\\rm{Intensity}", output.I_unit) 
    302297        else: 
    303             output.zaxis("\\rm{Intensity}","cm^{-1}") 
     298            output.zaxis("\\rm{Intensity}", "cm^{-1}") 
    304299     
    305300        # Store loading process information 
     
    308303 
    309304        return output 
    310      
    311 if __name__ == "__main__":  
    312     reader = Reader() 
    313     print reader.read("../test/MAR07232_rest.ASC")  
    314      
Note: See TracChangeset for help on using the changeset viewer.