source: sasview/DataLoader/loader.py @ bd30f4a5

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since bd30f4a5 was 11a0319, checked in by Gervaise Alina <gervyh@…>, 17 years ago

dataloader is added.need plugins…

  • Property mode set to 100644
File size: 2.0 KB
Line 
1from register import ExtensionRegistry
2import TXT3_Reader, TXT2_Reader,DataReader
3import danse_reader
4import tiff_reader
5#import tiff_reader
6class Loader:
7    def __init__(self):
8        """ init method"""
9        self.reg=ExtensionRegistry()
10    def setFormat(self,ext,reader):
11        """
12            Load the available reader with file extensions
13            @param ext:file extension
14            @param reader: instance of a reader
15        """
16        #self.reg[ext]=reader
17        self.reg.__setitem__(ext, reader)
18    def getReader(self,ext):
19        return self.reg.__getitem__( ext)
20       
21   
22    def loadData(self,path,format=None):
23        """ Read a file and save values"""
24        self.reg.lookup(path)
25        try: 
26            return self.reg.load(path,format)
27        except ValueError,msg:
28            print msg
29       
30       
31    def getextension(self,name=False,ext=True):
32        """ return list of readers"""
33        return self.reg.formats(name,ext) 
34def 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
74if __name__ == "__main__": test()
Note: See TracBrowser for help on using the repository browser.