Changeset de1da34 in sasview


Ignore:
Timestamp:
Mar 10, 2009 7:47:19 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:
148ad64
Parents:
aae8d23
Message:

Added load-ability to get dQ (for smear) if exists, and capability to sort the data by Q as a key

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/readers/ascii_reader.py

    rca10d8e rde1da34  
    5252                y  = numpy.zeros(0) 
    5353                dy = numpy.zeros(0) 
    54                 output = Data1D(x, y, dy=dy) 
     54                dx = numpy.zeros(0) 
     55                 
     56               #temp. space to sort data 
     57                tx  = numpy.zeros(0) 
     58                ty  = numpy.zeros(0) 
     59                tdy = numpy.zeros(0) 
     60                tdx = numpy.zeros(0) 
     61                 
     62                output = Data1D(x, y, dy=dy, dx=dx) 
    5563                self.filename = output.filename = basename 
    5664            
     
    7179                # The first good line of data will define whether 
    7280                # we have 2-column or 3-column ascii 
    73                 has_error = None 
     81                has_error_dx = None 
     82                has_error_dy = None 
    7483                 
    7584                for line in lines: 
     
    102111                        # If we haven't set the 3rd column 
    103112                        # flag, set it now. 
    104                         if has_error == None: 
    105                             has_error = False if _dy == None else True 
     113                        if has_error_dy == None: 
     114                            has_error_dy = False if _dy == None else True 
     115                             
     116                        #Check for dx 
     117                        _dx = None 
     118                        if len(toks)>3: 
     119                            try: 
     120                                _dx = float(toks[3]) 
     121                                 
     122                                if data_conv_i is not None: 
     123                                    _dx = data_conv_i(_dx, units=output.x_unit) 
     124                                 
     125                            except: 
     126                                # The 4th column is not a float, skip it. 
     127                                pass 
     128                             
     129                        # If we haven't set the 3rd column 
     130                        # flag, set it now. 
     131                        if has_error_dx == None: 
     132                            has_error_dx = False if _dx == None else True 
    106133 
    107134                        x  = numpy.append(x,   _x)  
    108135                        y  = numpy.append(y,   _y) 
    109                         if has_error == True: 
     136                        if has_error_dy == True: 
    110137                            dy = numpy.append(dy, _dy) 
     138                        if has_error_dx == True: 
     139                            dx = numpy.append(dx, _dx) 
     140                             
     141                        #Same for temp. 
     142                        tx  = numpy.append(tx,   _x)  
     143                        ty  = numpy.append(ty,   _y) 
     144                        if has_error_dy == True: 
     145                            tdy = numpy.append(tdy, _dy) 
     146                        if has_error_dx == True: 
     147                            tdx = numpy.append(tdx, _dx) 
    111148                         
    112149                    except: 
     
    116153                      
    117154                # Sanity check 
    118                 if has_error == True and not len(y) == len(dy): 
     155                if has_error_dy == True and not len(y) == len(dy): 
     156                    raise RuntimeError, "ascii_reader: y and dy have different length" 
     157                if has_error_dx == True and not len(x) == len(dx): 
    119158                    raise RuntimeError, "ascii_reader: y and dy have different length" 
    120159 
     
    123162                if len(x)==0: 
    124163                    raise RuntimeError, "ascii_reader: could not load file" 
    125                 
     164                 
     165                #Let's reoder the data 
     166                ind = numpy.lexsort((ty,tx)) 
     167                for i in ind: 
     168                    x[i] = tx[ind[i]] 
     169                    y[i] = ty[ind[i]] 
     170                    if has_error_dy == True: 
     171                        dy[i] = tdy[ind[i]] 
     172                    if has_error_dx == True: 
     173                        dx[i] = tdx[ind[i]] 
     174                     
    126175                output.x = x 
    127176                output.y = y 
    128                 output.dy = dy if has_error == True else None 
     177                output.dy = dy if has_error_dy == True else None 
     178                output.dx = dx if has_error_dx == True else None 
     179                 
    129180                if data_conv_q is not None: 
    130181                    output.xaxis("\\rm{Q}", output.x_unit) 
Note: See TracChangeset for help on using the changeset viewer.