Changeset 28caa03 in sasview


Ignore:
Timestamp:
Apr 4, 2009 3:17:43 PM (15 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:
07f8d9a
Parents:
0f5fe6b
Message:

Improved hierarchical reader structure, put back reader plugin, minor fixes.

Location:
DataLoader/readers
Files:
2 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/readers/IgorReader.py

    r0e2aa40 r28caa03  
    3232    """ Simple data reader for Igor data files """ 
    3333    ## File type 
     34    type_name = "IGOR 2D"    
     35    ## Wildcards 
    3436    type = ["IGOR 2D files (*.ASC)|*.ASC"] 
    3537    ## Extension 
  • DataLoader/readers/__init__.py

    rbbc8013 r28caa03  
    1 import abs_reader 
    2 import cansas_reader 
    3 import ascii_reader 
    4 import cansas_reader 
    5 import danse_reader 
    6 import hfir1d_reader 
    7 import IgorReader 
    8 import tiff_reader 
     1# Backward compatibility with the previous implementation of the default readers 
     2from associations import register_readers 
    93 
    10 def register_readers(registry_function): 
    11     """ 
    12         Function called by the registry/loader object to register 
    13         all default readers using a call back function. 
    14      
    15         @param registry_function: function to be called to register each reader 
    16     """ 
    17     registry_function(abs_reader) 
    18     registry_function(cansas_reader) 
    19     registry_function(ascii_reader) 
    20     registry_function(cansas_reader) 
    21     registry_function(danse_reader) 
    22     registry_function(hfir1d_reader) 
    23     registry_function(IgorReader) 
    24     registry_function(tiff_reader) 
    25      
     4# Method to associate extensions to default readers  
     5from associations import read_associations 
  • DataLoader/readers/abs_reader.py

    r0e2aa40 r28caa03  
    2424    """ 
    2525    ## File type 
     26    type_name = "IGOR 1D"    
     27    ## Wildcards 
    2628    type = ["IGOR 1D files (*.abs)|*.abs"] 
    2729    ## List of allowed extensions 
  • DataLoader/readers/ascii_reader.py

    r0e2aa40 r28caa03  
    2525    """ 
    2626    ## File type 
     27    type_name = "ASCII" 
     28     
     29    ## Wildcards 
    2730    type = ["ASCII files (*.txt)|*.txt", 
    2831            "ASCII files (*.dat)|*.dat", 
  • DataLoader/readers/cansas_reader.py

    r0e2aa40 r28caa03  
    196196    version = '1.0' 
    197197    ## File type 
     198    type_name = "CanSAS 1D" 
     199    ## Wildcards 
    198200    type = ["CanSAS 1D files (*.xml)|*.xml"] 
    199201    ## List of allowed extensions 
  • DataLoader/readers/danse_reader.py

    r0e2aa40 r28caa03  
    3636    """ 
    3737    ## File type 
     38    type_name = "DANSE"    
     39    ## Wildcards 
    3840    type = ["DANSE files (*.sans)|*.sans"] 
    3941    ## Extension 
  • DataLoader/readers/hfir1d_reader.py

    r0e2aa40 r28caa03  
    2525    """ 
    2626    ## File type 
     27    type_name = "HFIR 1D"    
     28    ## Wildcards 
    2729    type = ["HFIR 1D files (*.d1d)|*.d1d"] 
    2830    ## List of allowed extensions 
  • DataLoader/readers/tiff_reader.py

    r9d4e502 r28caa03  
    2323    """ 
    2424    ## File type 
     25    type_name = "TIF"    
     26    ## Wildcards 
    2527    type = ["TIF files (*.tif)|*.tif", 
    26             "JPG files (*.jpg)|*.jpg", 
    27             "JPEG files (*.jpeg)|*.jpeg", 
    28             "PNG files (*.png)|*.png", 
    2928            "TIFF files (*.tiff)|*.tiff", 
    30             "BMP files (*.bmp)|*.bmp", 
    31             "GIF files (*.gif)|*.gif", 
    3229            ] 
    3330    ## Extension 
    34     ext  = ['.tif','.TIF', 
    35              '.jpg','.JPG', 
    36               '.png','.PNG', 
    37                '.jpeg','.JPEG', 
    38                 '.tiff','.TIFF', 
    39                  '.gif','.GIF', 
    40                   '.bmp', '.BMP']     
     31    ext  = ['.tif', '.tiff']     
    4132         
    4233    def read(self, filename=None): 
     
    5950        except : 
    6051            raise  RuntimeError,"cannot open %s"%(filename) 
    61         predata = im.load() 
     52        data = im.getdata() 
    6253 
    63         x_range = im.size[0] 
    64         y_range = im.size[1] 
     54        # Initiazed the output data object 
     55        output.data = numpy.zeros([im.size[0],im.size[1]]) 
     56        output.err_data = numpy.zeros([im.size[0],im.size[1]]) 
    6557         
    66         # Initiazed the output data object 
    67         output.data = numpy.zeros([y_range,x_range]) 
    68         output.err_data = numpy.zeros([y_range,x_range]) 
    6958        # Initialize  
    7059        x_vals = [] 
     
    7261 
    7362        # x and y vectors 
    74         for i_x in range(x_range): 
     63        for i_x in range(im.size[0]): 
    7564            x_vals.append(i_x) 
    7665             
    77          
    78         for i_y in range(y_range): 
     66        itot = 0 
     67        for i_y in range(im.size[1]): 
    7968            y_vals.append(i_y) 
    80          
    81         for i_x in range(x_range): 
    82             for i_y in range(y_range): 
     69 
     70        for val in data: 
     71            try: 
     72                value = float(val) 
     73            except: 
     74                logging.error("tiff_reader: had to skip a non-float point") 
     75                continue 
    8376             
    84                 try: 
    85                     if predata[i_x,i_y].__class__.__name__=="tuple":                      
    86                          
    87                         if len(predata[i_x,i_y]) == 3:    
    88                             R,G,B= predata[i_x,i_y] 
    89                         elif len(predata[i_x,i_y]) == 4:    
    90                             R,G,B,I = predata[i_x,i_y] 
    91                         #Converting to L Mode: uses the ITU-R 601-2 luma transform. 
    92                         value = float(R * 299/1000 + G * 587/1000 + B * 114/1000)  
    93                           
    94                     else: 
    95                         #Take it as Intensity 
    96                         value = float(predata[i_x,i_y]) 
    97                 except: 
    98                     logging.error("tiff_reader: had to skip a non-float point") 
    99                     continue 
     77            # Get bin number 
     78            if math.fmod(itot, im.size[0])==0: 
     79                i_x = 0 
     80                i_y += 1 
     81            else: 
     82                i_x += 1 
    10083                 
    101                    
    102                 output.data[y_range-i_y-1,i_x] = value 
    103          
    104         output.xbins      = x_range 
    105         output.ybins      = y_range 
     84            output.data[im.size[1]-1-i_y][i_x] = value 
     85             
     86            itot += 1 
     87                 
     88        output.xbins      = im.size[0] 
     89        output.ybins      = im.size[1] 
    10690        output.x_bins     = x_vals 
    10791        output.y_bins     = y_vals 
    10892        output.xmin       = 0 
    109         output.xmax       = x_range-1 
     93        output.xmax       = im.size[0]-1 
    11094        output.ymin       = 0 
    111         output.ymax       = y_range-1 
     95        output.ymax       = im.size[0]-1 
    11296         
    11397        return output 
    11498         
     99 
     100if __name__ == "__main__":  
     101    reader = Reader() 
     102    print reader.read("../test/MP_New.sans") 
     103     
     104 
Note: See TracChangeset for help on using the changeset viewer.