Changeset 7d6351e in sasview for sansdataloader/src/sans/dataloader/readers/IgorReader.py
- Timestamp:
- Apr 27, 2012 11:22:31 AM (12 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:
- 4a96b8b
- Parents:
- f60a8c2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansdataloader/src/sans/dataloader/readers/IgorReader.py
rad8034f r7d6351e 1 1 """ 2 IGOR 2D reduced file reader 3 """ 2 4 ############################################################################ 3 5 #This software was developed by the University of Tennessee as part of the … … 10 12 #copyright 2008, University of Tennessee 11 13 ############################################################################# 12 13 """14 IGOR 2D reduced file reader15 """16 17 14 import os 18 #import sys19 15 import numpy 20 16 import math … … 31 27 has_converter = False 32 28 29 33 30 class Reader: 34 31 """ Simple data reader for Igor data files """ 35 32 ## File type 36 type_name = "IGOR 2D" 33 type_name = "IGOR 2D" 37 34 ## Wildcards 38 35 type = ["IGOR 2D files (*.ASC)|*.ASC"] … … 40 37 ext=['.ASC', '.asc'] 41 38 42 def read(self, filename=None):39 def read(self, filename=None): 43 40 """ Read file """ 44 41 if not os.path.isfile(filename): … … 47 44 48 45 # Read file 49 f = open(filename, 'r')46 f = open(filename, 'r') 50 47 buf = f.read() 51 48 … … 54 51 output.filename = os.path.basename(filename) 55 52 detector = Detector() 56 if len(output.detector)>0: print str(output.detector[0]) 53 if len(output.detector) > 0: 54 print str(output.detector[0]) 57 55 output.detector.append(detector) 58 56 59 57 # Get content 60 58 dataStarted = False 61 62 59 63 60 lines = buf.split('\n') … … 91 88 data_conv_i = Converter('1/cm') 92 89 # Test it 93 data_conv_i(1.0, output.I_unit) 90 data_conv_i(1.0, output.I_unit) 94 91 95 92 for line in lines: … … 117 114 118 115 i_tot_row += 1 119 i_tot_row =math.ceil(math.sqrt(i_tot_row))-1116 i_tot_row = math.ceil(math.sqrt(i_tot_row)) - 1 120 117 #print "i_tot", i_tot_row 121 size_x = i_tot_row #192#128122 size_y = i_tot_row #192#128123 output.data = numpy.zeros([size_x, size_y])124 output.err_data = numpy.zeros([size_x, size_y])118 size_x = i_tot_row # 192#128 119 size_y = i_tot_row # 192#128 120 output.data = numpy.zeros([size_x, size_y]) 121 output.err_data = numpy.zeros([size_x, size_y]) 125 122 126 123 #Read Header and 2D data … … 151 148 raise ValueError, msg 152 149 153 if line.count("LAMBDA") >0:150 if line.count("LAMBDA") > 0: 154 151 isInfo = True 155 152 156 153 # Find center info line 157 154 if isCenter: 158 isCenter = False 155 isCenter = False 159 156 line_toks = line.split() 160 157 161 # Center in bin number: Must substrate 1 because 158 # Center in bin number: Must substrate 1 because 162 159 #the index starts from 1 163 center_x = float(line_toks[0]) -1164 center_y = float(line_toks[1]) -1165 166 if line.count("BCENT") >0:160 center_x = float(line_toks[0]) - 1 161 center_y = float(line_toks[1]) - 1 162 163 if line.count("BCENT") > 0: 167 164 isCenter = True 168 165 169 170 166 # Find data start 171 167 if line.count("***")>0: … … 188 184 189 185 # Get bin number 190 if math.fmod(itot, i_tot_row) ==0:186 if math.fmod(itot, i_tot_row) == 0: 191 187 i_x = 0 192 188 i_y += 1 … … 195 191 196 192 output.data[i_y][i_x] = value 197 ncounts += 1 193 ncounts += 1 198 194 199 195 # Det 640 x 640 mm 200 196 # Q = 4pi/lambda sin(theta/2) 201 197 # Bin size is 0.5 cm 202 #REmoved +1 from theta = (i_x-center_x+1)*0.5 / distance 198 #REmoved +1 from theta = (i_x-center_x+1)*0.5 / distance 203 199 # / 100.0 and 204 200 #REmoved +1 from theta = (i_y-center_y+1)*0.5 / … … 206 202 #ToDo: Need complete check if the following 207 203 # covert process is consistent with fitting.py. 208 theta = (i_x -center_x)*0.5 / distance / 100.0209 qx = 4.0 *math.pi/wavelength * math.sin(theta/2.0)204 theta = (i_x - center_x) * 0.5 / distance / 100.0 205 qx = 4.0 * math.pi / wavelength * math.sin(theta/2.0) 210 206 211 207 if has_converter == True and output.Q_unit != '1/A': 212 208 qx = data_conv_q(qx, units=output.Q_unit) 213 209 214 if xmin ==None or qx<xmin:210 if xmin == None or qx < xmin: 215 211 xmin = qx 216 if xmax ==None or qx>xmax:212 if xmax == None or qx > xmax: 217 213 xmax = qx 218 214 219 theta = (i_y -center_y)*0.5 / distance / 100.0220 qy = 4.0 *math.pi/wavelength * math.sin(theta/2.0)215 theta = (i_y - center_y) * 0.5 / distance / 100.0 216 qy = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 221 217 222 218 if has_converter == True and output.Q_unit != '1/A': 223 219 qy = data_conv_q(qy, units=output.Q_unit) 224 220 225 if ymin ==None or qy<ymin:221 if ymin == None or qy < ymin: 226 222 ymin = qy 227 if ymax ==None or qy>ymax:223 if ymax == None or qy > ymax: 228 224 ymax = qy 229 225 … … 237 233 238 234 theta = 0.25 / distance / 100.0 239 xstep = 4.0 *math.pi/wavelength * math.sin(theta/2.0)235 xstep = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 240 236 241 237 theta = 0.25 / distance / 100.0 242 ystep = 4.0 *math.pi/wavelength * math.sin(theta/2.0)238 ystep = 4.0 * math.pi/ wavelength * math.sin(theta / 2.0) 243 239 244 240 # Store all data ###################################### 245 241 # Store wavelength 246 if has_converter ==True and output.source.wavelength_unit != 'A':242 if has_converter == True and output.source.wavelength_unit != 'A': 247 243 conv = Converter('A') 248 244 wavelength = conv(wavelength, units=output.source.wavelength_unit) … … 250 246 251 247 # Store distance 252 if has_converter ==True and detector.distance_unit != 'm':248 if has_converter == True and detector.distance_unit != 'm': 253 249 conv = Converter('m') 254 250 distance = conv(distance, units=detector.distance_unit) … … 260 256 # Store pixel size 261 257 pixel = 5.0 262 if has_converter ==True and detector.pixel_size_unit != 'mm':258 if has_converter == True and detector.pixel_size_unit != 'mm': 263 259 conv = Converter('mm') 264 260 pixel = conv(pixel, units=detector.pixel_size_unit) … … 267 263 268 264 # Store beam center in distance units 269 detector.beam_center.x = center_x*pixel 270 detector.beam_center.y = center_y*pixel 271 265 detector.beam_center.x = center_x * pixel 266 detector.beam_center.y = center_y * pixel 272 267 273 268 # Store limits of the image (2D array) 274 xmin =xmin-xstep/2.0275 xmax =xmax+xstep/2.0276 ymin =ymin-ystep/2.0277 ymax =ymax+ystep/2.0269 xmin = xmin - xstep / 2.0 270 xmax = xmax + xstep / 2.0 271 ymin = ymin - ystep / 2.0 272 ymax = ymax + ystep / 2.0 278 273 if has_converter == True and output.Q_unit != '1/A': 279 274 xmin = data_conv_q(xmin, units=output.Q_unit) … … 287 282 288 283 # Store x and y axis bin centers 289 output.x_bins 290 output.y_bins 284 output.x_bins = x 285 output.y_bins = y 291 286 292 287 # Units … … 301 296 output.zaxis("\\rm{Intensity}", output.I_unit) 302 297 else: 303 output.zaxis("\\rm{Intensity}", "cm^{-1}")298 output.zaxis("\\rm{Intensity}", "cm^{-1}") 304 299 305 300 # Store loading process information … … 308 303 309 304 return output 310 311 if __name__ == "__main__":312 reader = Reader()313 print reader.read("../test/MAR07232_rest.ASC")314
Note: See TracChangeset
for help on using the changeset viewer.