Changeset 470bf7e in sasview


Ignore:
Timestamp:
Apr 2, 2009 11:32:32 AM (15 years ago)
Author:
Jae Cho <jhjcho@…>
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:
954c045
Parents:
89ef796
Message:

ACS reads abs files when errored from abs reader

Location:
DataLoader/readers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/readers/abs_reader.py

    r148ad64 r470bf7e  
    5959                is_center = False 
    6060                is_data_started = False 
    61                 right_line_is = -2 
    62                 line_n = 0 
    63                 col = 0 
    6461                 
    6562                data_conv_q = None 
     
    7774                 
    7875                for line in lines: 
    79                     #print "line",line 
     76                     
    8077                    # Information line 1 
    8178                    if is_info==True: 
     
    9289                                output.source.wavelength = value 
    9390                        except: 
    94                             pass 
     91                            #goes to ASC reader 
     92                            raise  RuntimeError, "abs_reader: cannot open %s" % path 
    9593                            #raise ValueError,"IgorReader: can't read this file, missing wavelength" 
    9694                         
     
    104102                                detector.distance = value 
    105103                        except: 
    106                             pass 
    107                             #raise ValueError,"IgorReader: can't read this file, missing distance" 
     104                            #goes to ASC reader 
     105                            raise  RuntimeError, "abs_reader: cannot open %s" % path 
    108106                         
    109107                        # Transmission  
     
    125123                            # Thickness is not a mandatory entry 
    126124                            pass 
    127                          
    128                         #MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP 
    129                         if line.count("LAMBDA")>0: 
    130                             is_info = True 
     125                     
     126                    #MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP 
     127                    if line.count("LAMBDA")>0: 
     128                        is_info = True 
     129                         
     130                    # Find center info line 
     131                    if is_center==True: 
     132                        is_center = False                 
     133                        line_toks = line.split() 
     134                        # Center in bin number 
     135                        center_x = float(line_toks[0]) 
     136                        center_y = float(line_toks[1]) 
     137                         
     138                        # Bin size 
     139                        if has_converter==True and detector.pixel_size_unit != 'mm': 
     140                            conv = Converter('mm') 
     141                            detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 
     142                            detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 
     143                        else: 
     144                            detector.pixel_size.x = 5.0 
     145                            detector.pixel_size.y = 5.0 
     146                         
     147                        # Store beam center in distance units 
     148                        # Det 640 x 640 mm 
     149                        if has_converter==True and detector.beam_center_unit != 'mm': 
     150                            conv = Converter('mm') 
     151                            detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 
     152                            detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 
     153                        else: 
     154                            detector.beam_center.x = center_x*5.0 
     155                            detector.beam_center.y = center_y*5.0 
     156                         
     157                        # Detector type 
     158                        try: 
     159                            detector.name = line_toks[7] 
     160                        except: 
     161                            # Detector name is not a mandatory entry 
     162                            pass 
     163                     
     164                    #BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP  
     165                    if line.count("BCENT")>0: 
     166                        is_center = True 
     167                         
     168                    # Parse the data 
     169                    if is_data_started==True: 
     170                        toks = line.split() 
     171 
     172                        try:   
     173                            _x  = float(toks[0]) 
     174                            _y  = float(toks[1])  
     175                            _dy = float(toks[2]) 
     176                            _dx = float(toks[3]) 
    131177                             
    132                         # Find center info line 
    133                         if is_center==True: 
    134                             is_center = False                 
    135                             line_toks = line.split() 
    136                             # Center in bin number 
    137                             center_x = float(line_toks[0]) 
    138                             center_y = float(line_toks[1]) 
     178                            if data_conv_q is not None: 
     179                                _x = data_conv_q(_x, units=output.x_unit) 
     180                                _dx = data_conv_i(_dx, units=output.x_unit) 
     181                                 
     182                            if data_conv_i is not None: 
     183                                _y = data_conv_i(_y, units=output.y_unit) 
     184                                _dy = data_conv_i(_dy, units=output.y_unit) 
     185                            
     186                            x  = numpy.append(x,   _x)  
     187                            y  = numpy.append(y,   _y) 
     188                            dy = numpy.append(dy, _dy) 
     189                            dx  = numpy.append(dx, _dx) 
    139190                             
    140                             # Bin size 
    141                             if has_converter==True and detector.pixel_size_unit != 'mm': 
    142                                 conv = Converter('mm') 
    143                                 detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 
    144                                 detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 
    145                             else: 
    146                                 detector.pixel_size.x = 5.0 
    147                                 detector.pixel_size.y = 5.0 
     191                        except: 
     192                            # Could not read this data line. If we are here 
     193                            # it is because we are in the data section. Just 
     194                            # skip it. 
     195                            pass 
    148196                             
    149                             # Store beam center in distance units 
    150                             # Det 640 x 640 mm 
    151                             if has_converter==True and detector.beam_center_unit != 'mm': 
    152                                 conv = Converter('mm') 
    153                                 detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 
    154                                 detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 
    155                             else: 
    156                                 detector.beam_center.x = center_x*5.0 
    157                                 detector.beam_center.y = center_y*5.0 
    158                              
    159                             # Detector type 
    160                             try: 
    161                                 detector.name = line_toks[7] 
    162                             except: 
    163                                 # Detector name is not a mandatory entry 
    164                                 pass 
    165                          
    166                         #BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP  
    167                         if line.count("BCENT")>0: 
    168                             is_center = True 
    169                          
    170                     # Parse the data                     
    171                     # Specify one line of data 
    172                     if len(lines)<2: 
    173                         colnum = 6 
    174                     else: 
    175                         colnum = len(line.split()) 
    176                          
    177                     #If # of row = # of data points 
    178                     if colnum == 0: 
    179                         rangeiter = 0 
    180                     #If # of row = 1 
    181                     else: 
    182                         rangeiter=numpy.ceil(len(line.split())/colnum) 
    183                          
    184                     #If all data is in one line, chop the line by every 6 columns and read x, y, dy, dx data                          
    185                     for col in range(0,rangeiter): 
    186                         #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 
    187                         #Check the file format whether or not  it read all header lines and if it has a header 
    188                         if line.count("The 6 columns")>0 or (output.source.wavelength==None): 
    189                             #if  it has a full header 
    190                             if line.count("The 6 columns")>0: 
    191                                 right_line_is = line_n  
    192                             #If no header in the file 
    193                             else: 
    194                                 right_line_is = 0  
    195                             is_data_started = True 
    196                              
    197                          
    198                         # If on the of data, not header, read data 
    199                         if is_data_started==True and right_line_is >= 0: #and line_n > right_line_is 
    200                             #print "col",col 
    201                             toks = line.split() 
    202                             try:   
    203                                  
    204                                 if float(toks[col*6+0]) > 1: 
    205                                      continue 
    206                                 else: 
    207                                     not_data_line = False 
    208                                      
    209                                 _x  = float(toks[col*6+0]) 
    210                                 _y  = float(toks[col*6+1])  
    211                                 _dy = float(toks[col*6+2]) 
    212                                 _dx = float(toks[col*6+3]) 
    213                                  
    214                                  
    215                                 if data_conv_q is not None: 
    216                                     _x = data_conv_q(_x, units=output.x_unit) 
    217                                     _dx = data_conv_i(_dx, units=output.x_unit) 
    218                                      
    219                                 if data_conv_i is not None: 
    220                                     _y = data_conv_i(_y, units=output.y_unit) 
    221                                     _dy = data_conv_i(_dy, units=output.y_unit) 
    222  
    223                                 x  =numpy.append(x,   _x)  
    224                                 y  = numpy.append(y,   _y) 
    225                                 dy  = numpy.append(dy, _dy) 
    226                                 dx  = numpy.append(dx, _dx) 
    227  
    228                             except: 
    229                                 # Could not read this data line. If we are here 
    230                                 # it is because we are in the data section. Just 
    231                                 # skip it. 
    232                                 pass 
    233                              
    234                         line_n = line_n +1 
     197                    #The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor| 
     198                    if line.count("The 6 columns")>0: 
     199                        is_data_started = True 
     200             
    235201                # Sanity check 
    236202                if not len(y) == len(dy): 
    237203                    raise ValueError, "abs_reader: y and dy have different length" 
    238                 if not len(x) == len(dx): 
    239                     raise ValueError, "abs_reader: x and dx have different length" 
    240204 
    241205                # If the data length is zero, consider this as 
     
    256220                else: 
    257221                    output.yaxis("\\rm{I(Q)}","cm^{-1}") 
    258                 #print " x,y,dx,dy", output.x,output.y,output.dy,output.dx 
    259222                return output 
    260223        else: 
     
    264227if __name__ == "__main__":  
    265228    reader = Reader() 
    266     #print reader.read("../test/jan08002.ABS") 
     229    print reader.read("../test/jan08002.ABS") 
    267230     
    268231     
  • DataLoader/readers/ascii_reader.py

    rde1da34 r470bf7e  
    2626    ## File type 
    2727    type = ["ASCII files (*.txt)|*.txt", 
    28             "ASCII files (*.dat)|*.dat"] 
     28            "ASCII files (*.dat)|*.dat", 
     29            "ASCII files (*.abs)|*.abs"] 
    2930    ## List of allowed extensions 
    30     ext=['.txt', '.TXT', '.dat', '.DAT' 
     31    ext=['.txt', '.TXT', '.dat', '.DAT', '.abs', '.ABS' 
    3132     
    3233    def read(self, path): 
     
    4950                buff = input_f.read() 
    5051                lines = buff.split('\n') 
     52                 
     53                # some ascii data has \r line separator, try it when it has only one line 
     54                if len(lines) < 2 :  
     55                    lines = buff.split('\r') 
     56                  
    5157                x  = numpy.zeros(0) 
    5258                y  = numpy.zeros(0) 
     
    163169                    raise RuntimeError, "ascii_reader: could not load file" 
    164170                 
    165                 #Let's reoder the data 
     171                #Let's re-order the data to make cal. curve look better some cases 
    166172                ind = numpy.lexsort((ty,tx)) 
    167173                for i in ind: 
     
    186192                else: 
    187193                    output.yaxis("\\rm{I(Q)}","cm^{-1}") 
    188                  
     194 
    189195                return output 
    190196        else: 
Note: See TracChangeset for help on using the changeset viewer.