Changeset 99d1af6 in sasview for DataLoader/readers
- Timestamp:
- Aug 5, 2008 8:25:15 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:
- b99ac227
- Parents:
- 37d9521
- Location:
- DataLoader/readers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/abs_reader.py
r8780e9a r99d1af6 11 11 import numpy 12 12 import os 13 from DataLoader.data_info import Data1D 14 13 from DataLoader.data_info import Data1D, Detector 14 15 has_converter = True 16 try: 17 from data_util.nxsunit import Converter 18 except: 19 has_converter = False 20 15 21 class Reader: 16 22 """ … … 45 51 dy = numpy.zeros(0) 46 52 output = Data1D(x, y, dy=dy) 53 detector = Detector() 54 output.detector.append(detector) 47 55 self.filename = output.filename = basename 48 56 … … 50 58 is_center = False 51 59 is_data_started = False 60 61 data_conv_q = None 62 data_conv_i = None 63 64 if has_converter == True and output.x_unit != '1/A': 65 data_conv_q = Converter('1/A') 66 # Test it 67 data_conv_q(1.0, output.x_unit) 68 69 if has_converter == True and output.y_unit != '1/cm': 70 data_conv_i = Converter('1/cm') 71 # Test it 72 data_conv_i(1.0, output.y_unit) 52 73 53 74 for line in lines: … … 60 81 # Wavelength in Angstrom 61 82 try: 62 output.source.wavelength = float(line_toks[1]) 83 value = float(line_toks[1]) 84 if has_converter==True and output.source.wavelength_unit != 'A': 85 conv = Converter('A') 86 output.source.wavelength = conv(value, units=output.source.wavelength_unit) 87 else: 88 output.source.wavelength = value 63 89 except: 64 90 raise ValueError,"IgorReader: can't read this file, missing wavelength" … … 66 92 # Distance in meters 67 93 try: 68 output.detector.distance = float(line_toks[3])*1000.0 94 value = float(line_toks[3]) 95 if has_converter==True and detector.distance_unit != 'm': 96 conv = Converter('m') 97 detector.distance = conv(value, units=detector.distance_unit) 98 else: 99 detector.distance = value 69 100 except: 70 101 raise ValueError,"IgorReader: can't read this file, missing distance" 71 102 72 # Transmission 103 # Transmission 73 104 try: 74 105 output.sample.transmission = float(line_toks[4]) … … 77 108 pass 78 109 79 # Thickness 80 try: 81 output.sample.thickness = float(line_toks[5]) 110 # Thickness in mm 111 try: 112 value = float(line_toks[5]) 113 if has_converter==True and output.sample.thickness_unit != 'mm': 114 conv = Converter('mm') 115 output.sample.thickness = conv(value, units=output.sample.thickness_unit) 116 else: 117 output.sample.thickness = value 82 118 except: 83 119 # Thickness is not a mandatory entry … … 95 131 center_x = float(line_toks[0]) 96 132 center_y = float(line_toks[1]) 97 output.detector.beam_center.x = center_x 98 output.detector.beam_center.y = center_y 133 134 # Bin size 135 if has_converter==True and detector.pixel_size_unit != 'mm': 136 conv = Converter('mm') 137 detector.pixel_size.x = conv(5.0, units=detector.pixel_size_unit) 138 detector.pixel_size.y = conv(5.0, units=detector.pixel_size_unit) 139 else: 140 detector.pixel_size.x = 5.0 141 detector.pixel_size.y = 5.0 142 143 # Store beam center in distance units 144 # Det 640 x 640 mm 145 if has_converter==True and detector.beam_center_unit != 'mm': 146 conv = Converter('mm') 147 detector.beam_center.x = conv(center_x*5.0, units=detector.beam_center_unit) 148 detector.beam_center.y = conv(center_y*5.0, units=detector.beam_center_unit) 149 else: 150 detector.beam_center.x = center_x*5.0 151 detector.beam_center.y = center_y*5.0 99 152 100 153 # Detector type 101 154 try: 102 output.detector.name = line_toks[7]155 detector.name = line_toks[7] 103 156 except: 104 157 # Detector name is not a mandatory entry … … 116 169 _y = float(toks[1]) 117 170 _dy = float(toks[2]) 171 172 if data_conv_q is not None: 173 _x = data_conv_q(_x, units=output.x_unit) 174 175 if data_conv_i is not None: 176 _y = data_conv_i(_y, units=output.y_unit) 177 _dy = data_conv_i(_dy, units=output.y_unit) 118 178 119 179 x = numpy.append(x, _x) … … 142 202 output.y = y 143 203 output.dy = dy 144 output.xaxis("\\rm{Q}", 'A^{-1}') 145 output.yaxis("\\rm{I(Q)}","cm^{-1}") 204 if data_conv_q is not None: 205 output.xaxis("\\rm{Q}", output.x_unit) 206 else: 207 output.xaxis("\\rm{Q}", 'A^{-1}') 208 if data_conv_i is not None: 209 output.yaxis("\\{I(Q)}", output.y_unit) 210 else: 211 output.yaxis("\\rm{I(Q)}","cm^{-1}") 146 212 147 213 return output -
DataLoader/readers/ascii_reader.py
r4d2a0d1 r99d1af6 12 12 import os 13 13 from DataLoader.data_info import Data1D 14 15 has_converter = True 16 try: 17 from data_util.nxsunit import Converter 18 except: 19 has_converter = False 14 20 15 21 class Reader: … … 47 53 output = Data1D(x, y, dy=dy) 48 54 self.filename = output.filename = basename 55 56 data_conv_q = None 57 data_conv_i = None 58 59 if has_converter == True and output.x_unit != '1/A': 60 data_conv_q = Converter('1/A') 61 # Test it 62 data_conv_q(1.0, output.x_unit) 63 64 if has_converter == True and output.y_unit != '1/cm': 65 data_conv_i = Converter('1/cm') 66 # Test it 67 data_conv_i(1.0, output.y_unit) 68 49 69 50 70 # The first good line of data will define whether … … 58 78 _y = float(toks[1]) 59 79 80 if data_conv_q is not None: 81 _x = data_conv_q(_x, units=output.x_unit) 82 83 if data_conv_i is not None: 84 _y = data_conv_i(_y, units=output.y_unit) 85 60 86 # If we have an extra token, check 61 87 # whether it can be interpreted as a … … 65 91 try: 66 92 _dy = float(toks[2]) 93 94 if data_conv_i is not None: 95 _dy = data_conv_i(_dy, units=output.y_unit) 96 67 97 except: 68 98 # The third column is not a float, skip it. … … 96 126 output.y = y 97 127 output.dy = dy if has_error == True else None 98 output.xaxis("\\rm{Q}", 'A^{-1}') 99 output.yaxis("\\rm{I(Q)}","cm^{-1}") 100 128 if data_conv_q is not None: 129 output.xaxis("\\rm{Q}", output.x_unit) 130 else: 131 output.xaxis("\\rm{Q}", 'A^{-1}') 132 if data_conv_i is not None: 133 output.yaxis("\\{I(Q)}", output.y_unit) 134 else: 135 output.yaxis("\\rm{I(Q)}","cm^{-1}") 101 136 102 137 return output -
DataLoader/readers/cansas_reader.py
rb39c817 r99d1af6 426 426 data_info.dx = dx 427 427 data_info.dy = dy 428 data_info.xaxis("\\rm{Q}", 'A^{-1}') 429 data_info.yaxis("\\rm{I(Q)}","cm^{-1}") 430 428 if data_conv_q is not None: 429 data_info.xaxis("\\rm{Q}", output.x_unit) 430 else: 431 data_info.xaxis("\\rm{Q}", 'A^{-1}') 432 if data_conv_i is not None: 433 data_info.yaxis("\\{I(Q)}", output.y_unit) 434 else: 435 data_info.yaxis("\\rm{I(Q)}","cm^{-1}") 436 431 437 return data_info 432 438 -
DataLoader/readers/danse_reader.py
r68f6ae2 r99d1af6 1 1 """ 2 Test plug-in2 DANSE/SANS file reader 3 3 """ 4 4 5 5 import math 6 import pylab6 import os 7 7 import copy 8 8 import numpy 9 9 import logging 10 from DataLoader.data_info import Data2D, Detector 11 12 # Look for unit converter 13 has_converter = True 14 try: 15 from data_util.nxsunit import Converter 16 except: 17 has_converter = False 10 18 11 19 class Reader: … … 54 62 fversion = 1.0 55 63 64 output = Data2D() 65 output.filename = os.path.basename(filename) 66 detector = Detector() 67 output.detector.append(detector) 68 69 output.data = numpy.zeros([size_x,size_y]) 70 output.err_data = numpy.zeros([size_x,size_y]) 71 72 data_conv_q = None 73 data_conv_i = None 74 75 if has_converter == True and output.Q_unit != '1/A': 76 data_conv_q = Converter('1/A') 77 # Test it 78 data_conv_q(1.0, output.Q_unit) 79 80 if has_converter == True and output.I_unit != '1/cm': 81 data_conv_i = Converter('1/cm') 82 # Test it 83 data_conv_i(1.0, output.I_unit) 84 56 85 read_on = True 57 86 while read_on: … … 63 92 if toks[0]=="FORMATVERSION": 64 93 fversion = float(toks[1]) 65 if toks[0]=="WAVELENGTH": 66 wavelength = float(toks[1]) 94 if toks[0]=="WAVELENGTH": 95 wavelength = float(toks[1]) 67 96 elif toks[0]=="DISTANCE": 68 97 distance = float(toks[1]) … … 95 124 val = float(toks[0]) 96 125 err = float(toks[1]) 126 if data_conv_i is not None: 127 val = data_conv_i(val, units=output.y_unit) 128 err = data_conv_i(err, units=output.y_unit) 97 129 data.append(val) 98 130 error.append(err) 99 131 except: 100 132 logging.info("Skipping line:%s,%s" %( data_str,sys.exc_value)) 101 #print "Skipping line:%s" % data_str102 #print sys.exc_value103 133 104 134 # Initialize … … 109 139 xmin = None 110 140 xmax = None 111 Z = None 112 113 114 x = numpy.zeros(size_x) 115 y = numpy.zeros(size_y) 116 X, Y = pylab.meshgrid(x, y) 117 Z = copy.deepcopy(X) 118 E = copy.deepcopy(X) 141 142 #x = numpy.zeros(size_x) 143 #y = numpy.zeros(size_y) 144 #X, Y = pylab.meshgrid(x, y) 145 #Z = copy.deepcopy(X) 146 #E = copy.deepcopy(X) 119 147 itot = 0 120 148 i_x = 0 … … 125 153 theta = (i_x-center_x+1)*pixel / distance / 100.0 126 154 qx = 4.0*math.pi/wavelength * math.sin(theta/2.0) 155 156 if has_converter == True and output.Q_unit != '1/A': 157 qx = data_conv_q(qx, units=output.Q_unit) 158 127 159 x_vals.append(qx) 128 160 if xmin==None or qx<xmin: … … 136 168 theta = (i_y-center_y+1)*pixel / distance / 100.0 137 169 qy = 4.0*math.pi/wavelength * math.sin(theta/2.0) 170 171 if has_converter == True and output.Q_unit != '1/A': 172 qy = data_conv_q(qy, units=output.Q_unit) 173 138 174 y_vals.append(qy) 139 175 if ymin==None or qy<ymin: … … 142 178 ymax = qy 143 179 180 # Store the data in the 2D array 144 181 for i_pt in range(len(data)): 145 val = data[i_pt]146 182 try: 147 value = float( val)183 value = float(data[i_pt]) 148 184 except: 149 continue 185 # For version 1.0, the data were still 186 # stored as strings at this point. 187 logging.info("Skipping entry (v1.0):%s,%s" %(str(data[i_pt]), sys.exc_value)) 150 188 151 189 # Get bin number … … 156 194 i_x += 1 157 195 158 Z[size_y-1-i_y][i_x] = value196 output.data[size_y-1-i_y][i_x] = value 159 197 if fversion>1.0: 160 E[size_y-1-i_y][i_x] = error[i_pt]198 output.err_data[size_y-1-i_y][i_x] = error[i_pt] 161 199 162 200 itot += 1 163 from readInfo import ReaderInfo 164 output = ReaderInfo() 165 output.wavelength = wavelength 166 output.xbins = size_x 167 output.ybins = size_y 168 output.center_x = center_x 169 output.center_y = center_y 170 # Store the distance in [mm] 171 output.distance = distance*1000.0 172 output.x_vals = x_vals 173 output.y_vals = y_vals 174 output.xmin = xmin 175 output.xmax = xmax 176 output.ymin = ymin 177 output.ymax = ymax 178 output.pixel_size = pixel 179 output.image = Z 180 output.x = x_vals 181 output.y = y_vals 182 output.type = "2D " 201 202 # Store all data ###################################### 203 # Store wavelength 204 if has_converter==True and output.source.wavelength_unit != 'A': 205 conv = Converter('A') 206 wavelength = conv(wavelength, units=output.source.wavelength_unit) 207 output.source.wavelength = wavelength 208 209 # Store distance 210 if has_converter==True and detector.distance_unit != 'm': 211 conv = Converter('m') 212 distance = conv(distance, units=detector.distance_unit) 213 detector.distance = distance 214 215 # Store pixel size 216 if has_converter==True and detector.pixel_size_unit != 'mm': 217 conv = Converter('mm') 218 pixel = conv(pixel, units=detector.pixel_size_unit) 219 detector.pixel_size.x = pixel 220 detector.pixel_size.y = pixel 221 222 # Store beam center in distance units 223 detector.beam_center.x = center_x*pixel 224 detector.beam_center.y = center_y*pixel 225 226 # Store limits of the image (2D array) 227 if has_converter == True and output.Q_unit != '1/A': 228 xmin = data_conv_q(xmin, units=output.Q_unit) 229 xmax = data_conv_q(xmax, units=output.Q_unit) 230 ymin = data_conv_q(ymin, units=output.Q_unit) 231 ymax = data_conv_q(ymax, units=output.Q_unit) 232 output.xmin = xmin 233 output.xmax = xmax 234 output.ymin = ymin 235 output.ymax = ymax 236 237 # Store x and y axis bin centers 238 output.x_bins = x_vals 239 output.y_bins = y_vals 240 241 # Units 242 if data_conv_q is not None: 243 output.xaxis("\\rm{Q}", output.Q_unit) 244 output.yaxis("\\rm{Q}", output.Q_unit) 245 else: 246 output.xaxis("\\rm{Q}", 'A^{-1}') 247 output.yaxis("\\rm{Q}", 'A^{-1}') 248 249 if data_conv_i is not None: 250 output.zaxis("\\{I(Q)}", output.I_unit) 251 else: 252 output.zaxis("\\rm{I(Q)}","cm^{-1}") 183 253 184 254 if not fversion>=1.0: 185 #output.error = E186 255 raise ValueError,"Danse_reader can't read this file %s"%filename 187 256 else: … … 190 259 191 260 return None 261 262 if __name__ == "__main__": 263 reader = Reader() 264 print reader.read("../test/MP_New.sans") 265
Note: See TracChangeset
for help on using the changeset viewer.