source: sasview/park_integration/Loader.py @ 5b0c2cb

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 5b0c2cb was 4408fb0, checked in by Gervaise Alina <gervyh@…>, 16 years ago

files moved

  • Property mode set to 100644
File size: 2.5 KB
Line 
1# class Loader  to load any king of file
2import wx
3import string,numpy
4class Load:
5    """
6        This class is loading values from given file or value giving by the user
7    """
8   
9    def _init_(self,x=None,y=None,dx=None,dy=None):
10        # variable to store loaded values
11        self.x = x
12        self.y = y
13        self.dx = dx
14        self.dy = dy
15        self.filename = None
16       
17    def set_filename(self,path=None):
18        """
19            Store path into a variable.If the user doesn't give a path as a parameter a pop-up
20            window appears to select the file.
21            @param path: the path given by the user
22        """
23        self.filename = path
24       
25
26    def get_filename(self):
27        """ return the file's path"""
28        return self.filename
29   
30    def set_values(self):
31        """ Store the values loaded from file in local variables """
32        if not self.filename == None:
33            input_f =  open(self.filename,'r')
34            buff = input_f.read()
35            lines = buff.split('\n')
36            self.x=[]
37            self.y=[]
38            self.dx = [] 
39            self.dy=[]
40            for line in lines:
41                try:
42                    toks = line.split()
43                    x = float(toks[0])
44                    y = float(toks[1])
45                    dy = float(toks[2])
46                   
47                    self.x.append(x)
48                    self.y.append(y)
49                    self.dy.append(dy)
50                    self.dx = numpy.zeros(len(self.x))
51                except:
52                    print "READ ERROR", line
53           
54           
55            # Sanity check
56            if not len(self.x) == len(self.dx):
57                raise ValueError, "x and dx have different length"
58            if not len(self.y) == len(self.dy):
59                raise ValueError, "y and dy have different length"
60           
61           
62    def get_values(self):
63        """ Return x, y, dx, dy """
64        return self.x,self.y,self.dx,self.dy
65   
66    def load_data(self,data):
67        """ Return plottable """
68        #load data
69        data.x = self.x
70        data.y = self.y
71        data.dx = self.dx
72        data.dy =self.dy
73        #Load its View class
74        #plottable.reset_view()
75       
76   
77if __name__ == "__main__": 
78    load= Load()
79    load.set_filename("testdata_line.txt")
80    print load.get_filename() 
81    load.set_values()
82    print load.get_values()
83   
84           
Note: See TracBrowser for help on using the repository browser.