Changeset 892f246 in sasview


Ignore:
Timestamp:
Apr 9, 2009 9:23:01 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:
b570686
Parents:
7c845cb
Message:

enabled to read data only with more than 3 continuous lines unless that is the only data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/readers/ascii_reader.py

    r28caa03 r892f246  
    5454                lines = buff.split('\n') 
    5555                 
     56                #Jae could not find python universal line spliter: keep the below for now 
    5657                # some ascii data has \r line separator, try it when it has only one line 
    5758                if len(lines) < 2 :  
     
    9192                has_error_dy = None 
    9293                 
     94                #Initialize counters for data lines and header lines. 
     95                is_data = False #Has more than 3 lines 
     96                mum_data_lines = 3 # More than "3" lines of data is considered as actual data unless there is only less lines of data 
     97 
     98                i=-1  # To count # of current data candidate lines 
     99                i1=-1 # To count total # of previous data candidate lines 
     100                j=-1  # To count # of header lines 
     101                j1=-1 # Helps to count # of header lines 
     102                 
    93103                for line in lines: 
    94104                    toks = line.split() 
     105                     
    95106                    try: 
     107                         
    96108                        _x = float(toks[0]) 
    97109                        _y = float(toks[1]) 
    98110                         
     111                        #Reset the header line counters 
     112                        if j == j1: 
     113                            j = 0 
     114                            j1 = 0 
     115                             
     116                        if i > 1: 
     117                            is_data = True 
     118                             
    99119                        if data_conv_q is not None: 
    100120                            _x = data_conv_q(_x, units=output.x_unit) 
     
    140160                        if has_error_dx == None: 
    141161                            has_error_dx = False if _dx == None else True 
    142  
     162                         
     163                        #Delete the previously stored lines of data candidates if is not data. 
     164                        if i < 0 and -1< i1 < mum_data_lines and is_data == False: 
     165                            try: 
     166                                x= numpy.zeros(0) 
     167                                y= numpy.zeros(0) 
     168                                 
     169                            except: 
     170                                pass 
     171                             
    143172                        x  = numpy.append(x,   _x)  
    144173                        y  = numpy.append(y,   _y) 
     174                         
    145175                        if has_error_dy == True: 
     176                            #Delete the previously stored lines of data candidates if is not data. 
     177                            if i < 0 and -1< i1 < mum_data_lines and is_data== False: 
     178                                try: 
     179                                    dy = numpy.zeros(0)   
     180                                except: 
     181                                    pass                                                                
    146182                            dy = numpy.append(dy, _dy) 
     183                             
    147184                        if has_error_dx == True: 
     185                            #Delete the previously stored lines of data candidates if is not data. 
     186                            if i < 0 and -1< i1 < mum_data_lines and is_data== False: 
     187                                try: 
     188                                    dx = numpy.zeros(0)                             
     189                                except: 
     190                                    pass                                                                
    148191                            dx = numpy.append(dx, _dx) 
    149192                             
    150193                        #Same for temp. 
     194                        #Delete the previously stored lines of data candidates if is not data. 
     195                        if i < 0 and -1< i1 < mum_data_lines and is_data== False: 
     196                            try: 
     197                                tx = numpy.zeros(0) 
     198                                ty = numpy.zeros(0) 
     199                            except: 
     200                                pass                                                                
     201 
    151202                        tx  = numpy.append(tx,   _x)  
    152203                        ty  = numpy.append(ty,   _y) 
     204                         
    153205                        if has_error_dy == True: 
     206                            #Delete the previously stored lines of data candidates if is not data. 
     207                            if i < 0 and -1<i1 < mum_data_lines and is_data== False: 
     208                                try: 
     209                                    tdy = numpy.zeros(0) 
     210                                except: 
     211                                    pass                                                                                                                 
    154212                            tdy = numpy.append(tdy, _dy) 
    155213                        if has_error_dx == True: 
     214                            #Delete the previously stored lines of data candidates if is not data. 
     215                            if i < 0 and -1< i1 < mum_data_lines and is_data== False: 
     216                                try: 
     217                                    tdx = numpy.zeros(0) 
     218                                except: 
     219                                    pass                                                                                                              
    156220                            tdx = numpy.append(tdx, _dx) 
    157221                         
     222                        #Reset # of header lines and counts # of data candidate lines     
     223                        if j == 0 and j1 ==0: 
     224                            i1 = i + 1                             
     225                        i+=1 
     226                         
    158227                    except: 
     228 
     229                        # It is data and meet non - number, then stop reading 
     230                        if is_data == True: 
     231                            break     
     232                        #Counting # of header lines                     
     233                        j+=1 
     234                        if j == j1+1: 
     235                            j1 = j                             
     236                        else:                             
     237                            j = -1 
     238                        #Reset # of lines of data candidates 
     239                        i = -1 
     240                         
    159241                        # Couldn't parse this line, skip it  
    160242                        pass 
    161                           
     243                     
     244     
    162245                      
    163246                # Sanity check 
     
    181264                    if has_error_dx == True: 
    182265                        dx[i] = tdx[ind[i]] 
    183                      
     266                 
     267                #Data     
    184268                output.x = x 
    185269                output.y = y 
     
    197281 
    198282                return output 
     283             
    199284        else: 
    200285            raise RuntimeError, "%s is not a file" % path 
Note: See TracChangeset for help on using the changeset viewer.