Changeset de1da34 in sasview for DataLoader
- Timestamp:
- Mar 10, 2009 9:47:19 AM (16 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/ascii_reader.py
rca10d8e rde1da34 52 52 y = numpy.zeros(0) 53 53 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) 55 63 self.filename = output.filename = basename 56 64 … … 71 79 # The first good line of data will define whether 72 80 # we have 2-column or 3-column ascii 73 has_error = None 81 has_error_dx = None 82 has_error_dy = None 74 83 75 84 for line in lines: … … 102 111 # If we haven't set the 3rd column 103 112 # 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 106 133 107 134 x = numpy.append(x, _x) 108 135 y = numpy.append(y, _y) 109 if has_error == True:136 if has_error_dy == True: 110 137 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) 111 148 112 149 except: … … 116 153 117 154 # 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): 119 158 raise RuntimeError, "ascii_reader: y and dy have different length" 120 159 … … 123 162 if len(x)==0: 124 163 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 126 175 output.x = x 127 176 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 129 180 if data_conv_q is not None: 130 181 output.xaxis("\\rm{Q}", output.x_unit)
Note: See TracChangeset
for help on using the changeset viewer.