Changeset b99ac227 in sasview for DataLoader/readers
- Timestamp:
- Aug 6, 2008 8:54:02 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:
- 17a6843
- Parents:
- 99d1af6
- Location:
- DataLoader/readers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/IgorReader.py
r68f6ae2 rb99ac227 1 """ 2 IGOR 2D reduced file reader 3 """ 4 5 """ 6 This software was developed by the University of Tennessee as part of the 7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 8 project funded by the US National Science Foundation. 9 10 If you use DANSE applications to do scientific research that leads to 11 publication, we ask that you acknowledge the use of the software with the 12 following sentence: 13 14 "This work benefited from DANSE software developed under NSF award DMR-0520547." 15 16 copyright 2008, University of Tennessee 17 """ 18 1 19 import os, sys 2 import pylab 3 from copy import deepcopy 4 import math,logging 20 import numpy 21 import math, logging 22 from DataLoader.data_info import Data2D, Detector 23 24 # Look for unit converter 25 has_converter = True 26 try: 27 from data_util.nxsunit import Converter 28 except: 29 has_converter = False 30 5 31 class Reader: 6 32 """ Simple data reader for Igor data files """ 7 ext=['.ASC'] 8 def __init__(self, filename=None): 9 """ Init 10 @param filename: Name of Igor data file to read 11 """ 12 self.file = filename 13 self.x = [] 14 self.y = [] 15 self.image = [] 16 17 # Detector info 18 self.wavelength = 0.0 19 self.distance = 0.0 20 self.center_x = 63.5 21 self.center_y = 63.5 22 33 ## File type 34 type = ["IGOR 2D files (*.ASC)|*.ASC"] 35 ## Extension 36 ext=['.ASC', '.asc'] 37 23 38 def read(self,filename=None): 24 39 """ Read file """ 25 # Check if the file is there 26 self.file=filename 27 if not os.path.isfile(self.file): 40 if not os.path.isfile(filename): 28 41 raise ValueError, \ 29 "Specified file %s is not a regular file" % self.file42 "Specified file %s is not a regular file" % filename 30 43 31 44 # Read file 32 f = open( self.file,'r')45 f = open(filename,'r') 33 46 buf = f.read() 47 48 # Instantiate data object 49 output = Data2D() 50 output.filename = os.path.basename(filename) 51 detector = Detector() 52 if len(output.detector)>0: print str(output.detector[0]) 53 output.detector.append(detector) 54 55 size_x = 128 56 size_y = 128 57 output.data = numpy.zeros([size_x,size_y]) 58 output.err_data = numpy.zeros([size_x,size_y]) 59 60 data_conv_q = None 61 data_conv_i = None 62 63 if has_converter == True and output.Q_unit != '1/A': 64 data_conv_q = Converter('1/A') 65 # Test it 66 data_conv_q(1.0, output.Q_unit) 67 68 if has_converter == True and output.I_unit != '1/cm': 69 data_conv_i = Converter('1/cm') 70 # Test it 71 data_conv_i(1.0, output.I_unit) 72 34 73 35 74 # Get content … … 39 78 lines = buf.split('\n') 40 79 itot = 0 41 self.x = [] 42 self.y = [] 43 self.image = [] 80 x = [] 81 y = [] 44 82 45 83 ncounts = 0 46 47 #x = pylab.arange(0, 128, 1)48 #y = pylab.arange(0, 128, 1)49 x = pylab.arange(-.5, .5, 1.0/128)50 y = pylab.arange(-.5, .5, 1.0/128)51 X, Y = pylab.meshgrid(x, y)52 Z = deepcopy(X)53 84 54 85 xmin = None … … 79 110 raise ValueError,"IgorReader: can't read this file, missing distance" 80 111 112 # Distance in meters 113 try: 114 transmission = float(line_toks[4]) 115 except: 116 raise ValueError,"IgorReader: can't read this file, missing transmission" 117 81 118 if line.count("LAMBDA")>0: 82 119 isInfo = True … … 109 146 value = float(line) 110 147 except: 148 # Found a non-float entry, skip it 111 149 continue 112 150 … … 118 156 i_x += 1 119 157 120 Z[i_y][i_x] = value158 output.data[i_y][i_x] = value 121 159 ncounts += 1 122 160 … … 126 164 theta = (i_x-center_x+1)*0.5 / distance / 100.0 127 165 qx = 4.0*math.pi/wavelength * math.sin(theta/2.0) 166 167 if has_converter == True and output.Q_unit != '1/A': 168 qx = data_conv_q(qx, units=output.Q_unit) 169 128 170 if xmin==None or qx<xmin: 129 171 xmin = qx … … 133 175 theta = (i_y-center_y+1)*0.5 / distance / 100.0 134 176 qy = 4.0*math.pi/wavelength * math.sin(theta/2.0) 177 178 if has_converter == True and output.Q_unit != '1/A': 179 qy = data_conv_q(qy, units=output.Q_unit) 180 135 181 if ymin==None or qy<ymin: 136 182 ymin = qy … … 138 184 ymax = qy 139 185 140 141 if not qx in self.x: 142 self.x.append(qx) 143 if not qy in self.y: 144 self.y.append(qy) 186 if not qx in x: 187 x.append(qx) 188 if not qy in y: 189 y.append(qy) 145 190 146 191 itot += 1 … … 153 198 ystep = 4.0*math.pi/wavelength * math.sin(theta/2.0) 154 199 155 # Store q max 156 if xmax>ymax: 157 self.qmax = xmax 200 # Store all data ###################################### 201 # Store wavelength 202 if has_converter==True and output.source.wavelength_unit != 'A': 203 conv = Converter('A') 204 wavelength = conv(wavelength, units=output.source.wavelength_unit) 205 output.source.wavelength = wavelength 206 207 # Store distance 208 if has_converter==True and detector.distance_unit != 'm': 209 conv = Converter('m') 210 distance = conv(distance, units=detector.distance_unit) 211 detector.distance = distance 212 213 # Store transmission 214 output.sample.transmission = transmission 215 216 # Store pixel size 217 pixel = 5.0 218 if has_converter==True and detector.pixel_size_unit != 'mm': 219 conv = Converter('mm') 220 pixel = conv(pixel, units=detector.pixel_size_unit) 221 detector.pixel_size.x = pixel 222 detector.pixel_size.y = pixel 223 224 # Store beam center in distance units 225 detector.beam_center.x = center_x*pixel 226 detector.beam_center.y = center_y*pixel 227 228 229 # Store limits of the image (2D array) 230 xmin =xmin-xstep/2.0 231 xmax =xmax+xstep/2.0 232 ymin =ymin-ystep/2.0 233 ymax =ymax+ystep/2.0 234 if has_converter == True and output.Q_unit != '1/A': 235 xmin = data_conv_q(xmin, units=output.Q_unit) 236 xmax = data_conv_q(xmax, units=output.Q_unit) 237 ymin = data_conv_q(ymin, units=output.Q_unit) 238 ymax = data_conv_q(ymax, units=output.Q_unit) 239 output.xmin = xmin 240 output.xmax = xmax 241 output.ymin = ymin 242 output.ymax = ymax 243 244 # Store x and y axis bin centers 245 output.x_bins = x 246 output.y_bins = y 247 248 # Units 249 if data_conv_q is not None: 250 output.xaxis("\\rm{Q}", output.Q_unit) 251 output.yaxis("\\rm{Q}", output.Q_unit) 158 252 else: 159 self.qmax = ymax 160 161 #config.printEVT("Read %g points from file %s" % (ncounts, self.file)) 162 163 self.wavelength = wavelength 164 self.distance = distance*1000.0 165 self.center_x = center_x 166 self.center_y = center_y 167 168 from readInfo import ReaderInfo 169 output = ReaderInfo() 170 output.Z=Z 171 output.xmin =xmin-xstep/2.0 172 output.xmax = xmax+xstep/2.0 173 output.ymin =ymin-ystep/2.0 174 output.ymax =ymax+ystep/2.0 175 output.x = x 176 output.y = y 177 output.wavelength = wavelength 178 output.distance = distance*1000.0 179 output.center_x = center_x 180 output.center_y = center_y 181 output.type ="2D" 182 183 logging.info("IgorReader reading %s"%self.file) 253 output.xaxis("\\rm{Q}", 'A^{-1}') 254 output.yaxis("\\rm{Q}", 'A^{-1}') 255 256 if data_conv_i is not None: 257 output.zaxis("\\{I(Q)}", output.I_unit) 258 else: 259 output.zaxis("\\rm{I(Q)}","cm^{-1}") 260 261 184 262 return output 185 263 264 if __name__ == "__main__": 265 reader = Reader() 266 print reader.read("../test/MAR07232_rest.ASC") 267 -
DataLoader/readers/abs_reader.py
r99d1af6 rb99ac227 53 53 detector = Detector() 54 54 output.detector.append(detector) 55 self.filename =output.filename = basename55 output.filename = basename 56 56 57 57 is_info = False … … 111 111 try: 112 112 value = float(line_toks[5]) 113 if has_converter==True and output.sample.thickness_unit != ' mm':114 conv = Converter(' mm')113 if has_converter==True and output.sample.thickness_unit != 'cm': 114 conv = Converter('cm') 115 115 output.sample.thickness = conv(value, units=output.sample.thickness_unit) 116 116 else: -
DataLoader/readers/danse_reader.py
r99d1af6 rb99ac227 1 1 """ 2 2 DANSE/SANS file reader 3 """ 4 5 """ 6 This software was developed by the University of Tennessee as part of the 7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 8 project funded by the US National Science Foundation. 9 10 If you use DANSE applications to do scientific research that leads to 11 publication, we ask that you acknowledge the use of the software with the 12 following sentence: 13 14 "This work benefited from DANSE software developed under NSF award DMR-0520547." 15 16 copyright 2008, University of Tennessee 3 17 """ 4 18 … … 24 38 type = ["DANSE files (*.sans)|*.sans"] 25 39 ## Extension 26 ext = ['.sans' ]40 ext = ['.sans', '.SANS'] 27 41 28 42 def read(self, filename=None): … … 140 154 xmax = None 141 155 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)147 itot = 0148 i_x = 0149 i_y = 0150 151 156 # Qx and Qy vectors 152 157 for i_x in range(size_x): … … 179 184 180 185 # Store the data in the 2D array 186 itot = 0 187 i_x = 0 188 i_y = -1 189 181 190 for i_pt in range(len(data)): 182 191 try: … … 188 197 189 198 # Get bin number 190 if math.fmod(i tot, size_x)==0:199 if math.fmod(i_pt, size_x)==0: 191 200 i_x = 0 192 201 i_y += 1 … … 194 203 i_x += 1 195 204 196 output.data[size_y-1-i_y][i_x] = value 205 output.data[i_y][i_x] = value 206 #output.data[size_y-1-i_y][i_x] = value 197 207 if fversion>1.0: 198 output.err_data[ size_y-1-i_y][i_x] = error[i_pt]199 200 itot += 1208 output.err_data[i_y][i_x] = error[i_pt] 209 #output.err_data[size_y-1-i_y][i_x] = error[i_pt] 210 201 211 202 212 # Store all data ######################################
Note: See TracChangeset
for help on using the changeset viewer.