Changeset bb03739 in sasview
- Timestamp:
- Jul 1, 2008 7:01:30 PM (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:
- cbe6dbe
- Parents:
- 2a92852
- Location:
- DataLoader
- Files:
-
- 7 added
- 1 deleted
- 6 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/loader.py
r11a0319 rbb03739 1 1 from register import ExtensionRegistry 2 import TXT3_Reader, TXT2_Reader,DataReader 3 import danse_reader 4 import tiff_reader 2 5 3 #import tiff_reader 6 4 class Loader: … … 8 6 """ init method""" 9 7 self.reg=ExtensionRegistry() 8 10 9 def setFormat(self,ext,reader): 11 10 """ … … 27 26 except ValueError,msg: 28 27 print msg 29 30 28 def getActiveReader(self,path): 29 return self.reg.getAcTReader(path) 31 30 def getextension(self,name=False,ext=True): 32 31 """ return list of readers""" 33 32 return self.reg.formats(name,ext) 34 def test():35 L=Loader()36 37 read1=TXT2_Reader.Reader()38 read2=TXT3_Reader.Reader()39 read3=DataReader.DataReader()40 read4=danse_reader.DataReader()41 read5=tiff_reader.DataReader()42 43 L.setFormat('.txt',read1)44 L.setFormat('.txt',read2)45 46 L.setFormat('.dat',read2)47 L.setFormat('.dat',read1)48 49 L.setFormat('.ASC',read3)50 L.setFormat('.sans',read4)51 L.setFormat('.sans',read5)52 L.setFormat('.tif',read5)53 L.setFormat('.jpg',read5)54 L.setFormat('.png',read5)55 L.setFormat('.jpeg',read5)56 L.setFormat('.gif',read5)57 L.setFormat('.bmp',read5)58 59 60 61 print L.loadData('testdata_line.txt')62 print L.loadData('test.dat')63 print L.loadData('test.date')64 print L.loadData('MAR07232_rest.ASC')65 print L.loadData('AR07232_rest.ASC')66 print L.loadData('MP_New.sans')67 print L.loadData('P_New.sans')68 print L.loadData('angles_flat.png')69 70 71 72 73 74 if __name__ == "__main__": test() -
DataLoader/readers/DataReader.py
r11a0319 rbb03739 3 3 from copy import deepcopy 4 4 import math 5 class DataReader:5 class Reader: 6 6 """ Simple data reader for Igor data files """ 7 7 -
DataLoader/readers/TXT3_Reader.py
r11a0319 rbb03739 15 15 self.filename = filename 16 16 17 17 18 def read(self,path, format=None): 18 19 """ Store the values loaded from file in local variables 19 20 can read 3 columns of data 20 21 """ 22 21 23 if not path == None: 22 input_f = open(path,'r') 23 buff = input_f.read() 24 lines = buff.split('\n') 25 self.x=[] 26 self.y=[] 27 self.dx = [] 28 self.dy=[] 29 value="can't read" 30 for line in lines: 31 toks = line.split() 32 try: 33 x = float(toks[0]) 34 y = float(toks[1]) 35 dy = float(toks[2]) 36 37 self.x.append(x) 38 self.y.append(y) 39 self.dy.append(dy) 40 41 except: 42 print "READ ERROR", line 43 44 self.dx = numpy.zeros(len(self.x)) 45 # Sanity check 46 if not len(self.x) == len(self.dx): 47 raise ValueError, "x and dx have different length" 48 if not len(self.y) == len(self.dy): 49 raise ValueError, "y and dy have different length" 50 51 if (self.x==[] or self.y==[])and (self.dy==[]): 24 read_it = False 25 ext=['.txt','.dat'] 26 for item in ext: 27 if path.lower().find(item)>=0: 28 read_it = True 29 print "this is the flag",read_it, path.lower() 30 if read_it==False: 52 31 raise ValueError, "txtReader can't read" 53 32 else: 54 #msg="txtReader Reading:\n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n" 55 #return msg 56 print "TXT3_Reader reading: \n" 57 return self.x,self.y,self.dy 33 input_f = open(path,'r') 34 buff = input_f.read() 35 lines = buff.split('\n') 36 self.x=[] 37 self.y=[] 38 self.dx = [] 39 self.dy=[] 40 value="can't read" 41 for line in lines: 42 toks = line.split() 43 try: 44 x = float(toks[0]) 45 y = float(toks[1]) 46 dy = float(toks[2]) 47 48 self.x.append(x) 49 self.y.append(y) 50 self.dy.append(dy) 51 52 except: 53 print "READ ERROR", line 54 55 self.dx = numpy.zeros(len(self.x)) 56 # Sanity check 57 if not len(self.x) == len(self.dx): 58 raise ValueError, "x and dx have different length" 59 if not len(self.y) == len(self.dy): 60 raise ValueError, "y and dy have different length" 61 62 if (self.x==[] or self.y==[])and (self.dy==[]): 63 raise ValueError, "txtReader can't read" 64 else: 65 #msg="txtReader Reading:\n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n" 66 #return msg 67 print "TXT3_Reader reading: \n" 68 return self.x,self.y,self.dy 58 69 59 70 -
DataLoader/readers/danse_reader.py
r11a0319 rbb03739 40 40 ## Error on each pixel 41 41 error = None 42 class DataReader:42 class Reader: 43 43 """ 44 44 Example data manipulation -
DataLoader/readers/tiff_reader.py
r11a0319 rbb03739 36 36 error = None 37 37 38 class DataReader:38 class Reader: 39 39 """ 40 40 Example data manipulation -
DataLoader/register.py
r11a0319 rbb03739 53 53 def __init__(self): 54 54 self.loaders = {} 55 self.reader=None 55 56 def __setitem__(self, ext, loader): 56 57 if ext not in self.loaders: … … 104 105 try: 105 106 value=fn.read(path) 107 self.reader= fn 106 108 return value 107 109 except ValueError,msg: 108 110 #pass 109 111 print str(msg) 110 112 def getAcTReader(self,path): 113 return self.reader 111 114 def load(self, path, format=None): 112 115 """ … … 123 126 for fn in loaders: 124 127 try: 125 return fn.read(path) 128 value=fn.read(path) 129 self.reader= fn.__class__ 130 return value 126 131 #value=fn.read(path) 127 132 #return value
Note: See TracChangeset
for help on using the changeset viewer.