source: sasview/park_integration/Loader.py @ 7406040

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 7406040 was 89f3b66, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working pylint

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