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 8bd8ea4 was
16d8e5f,
checked in by Gervaise Alina <gervyh@…>, 16 years ago
|
ReadInfo? module added in readers….every reader should return a read info object
|
-
Property mode set to
100644
|
File size:
3.7 KB
|
Line | |
---|
1 | # class Loader to load any king of file |
---|
2 | import wx |
---|
3 | import string,numpy |
---|
4 | import logging |
---|
5 | class ReaderInfo: |
---|
6 | """ |
---|
7 | This class is a container of data. It stores values read from files |
---|
8 | """ |
---|
9 | ## Wavelength [A] |
---|
10 | wavelength = 0.0 |
---|
11 | ## Number of x bins |
---|
12 | xbins = 128 |
---|
13 | ## Number of y bins |
---|
14 | ybins = 128 |
---|
15 | ## Beam center X [pixel number] |
---|
16 | center_x = 65 |
---|
17 | ## Beam center Y [pixel number] |
---|
18 | center_y = 65 |
---|
19 | ## Distance from sample to detector [m] |
---|
20 | distance = 11.0 |
---|
21 | ## Qx values [A-1] |
---|
22 | x_vals = [] |
---|
23 | ## Qy xalues [A-1] |
---|
24 | y_vals = [] |
---|
25 | ## Qx min |
---|
26 | xmin = 0.0 |
---|
27 | ## Qx max |
---|
28 | xmax = 1.0 |
---|
29 | ## Qy min |
---|
30 | ymin = 0.0 |
---|
31 | ## Qy max |
---|
32 | ymax = 1.0 |
---|
33 | ## Image |
---|
34 | image = None |
---|
35 | ## Pixel size |
---|
36 | pixel_size = 0.5 |
---|
37 | ## x coordinate |
---|
38 | x=[] |
---|
39 | ##y coordinate |
---|
40 | y=[] |
---|
41 | ##dx error on y |
---|
42 | dx=None |
---|
43 | ## dy error on y |
---|
44 | dy=None |
---|
45 | ## Error on each pixel |
---|
46 | error = None |
---|
47 | ##type of data |
---|
48 | type="" |
---|
49 | ##z |
---|
50 | Z=None |
---|
51 | |
---|
52 | class Reader: |
---|
53 | """ |
---|
54 | This class is loading values from given file or value giving by the user |
---|
55 | should be able to read only 2 columns of data |
---|
56 | """ |
---|
57 | ext=['.txt','.dat'] |
---|
58 | def _init_(self,x=None,y=None,dx=None,dy=None): |
---|
59 | # variable to store loaded values |
---|
60 | self.x = x |
---|
61 | self.y = y |
---|
62 | self.dx = dx |
---|
63 | self.dy = dy |
---|
64 | |
---|
65 | def read(self,path, format=None): |
---|
66 | """ Store the values loaded from file in local variables """ |
---|
67 | if not path == None: |
---|
68 | read_it = False |
---|
69 | |
---|
70 | for item in self.ext: |
---|
71 | if path.lower().find(item)>=0: |
---|
72 | read_it = True |
---|
73 | #print "this is the flag",read_it, path.lower() |
---|
74 | if read_it==False: |
---|
75 | return None |
---|
76 | else: |
---|
77 | try: |
---|
78 | input_f = open(path,'r') |
---|
79 | except : |
---|
80 | raise RuntimeError,"TXT2_Reader cannot open %s"%(path) |
---|
81 | buff = input_f.read() |
---|
82 | lines = buff.split('\n') |
---|
83 | self.x=[] |
---|
84 | self.y=[] |
---|
85 | self.dx = [] |
---|
86 | self.dy=[] |
---|
87 | for line in lines: |
---|
88 | toks = line.split() |
---|
89 | try: |
---|
90 | x = float(toks[0]) |
---|
91 | self.x.append(x) |
---|
92 | except: |
---|
93 | pass |
---|
94 | #print "READ ERROR", line |
---|
95 | try: |
---|
96 | y = float(toks[1]) |
---|
97 | self.y.append(y) |
---|
98 | except: |
---|
99 | pass |
---|
100 | #print "READ ERROR", line |
---|
101 | try: |
---|
102 | dy=float(toks[2]) |
---|
103 | self.dy.append(dy) |
---|
104 | |
---|
105 | except: |
---|
106 | pass |
---|
107 | #print "READ ERROR", line |
---|
108 | |
---|
109 | if(( self.x==[])or (self.y==[])) or (self.dy !=[]): |
---|
110 | #print "went here" |
---|
111 | #return value |
---|
112 | raise ValueError, "TXT2_Reader can't read %s"%path |
---|
113 | else: |
---|
114 | #msg="R1 reading: \n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n" |
---|
115 | #return msg |
---|
116 | logging.info("TXT2_Reader reading %s\n" %path) |
---|
117 | output = ReaderInfo() |
---|
118 | output.x = self.x |
---|
119 | output.y = self.y |
---|
120 | output.type = "1D" |
---|
121 | |
---|
122 | return output |
---|
123 | return None |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | if __name__ == "__main__": |
---|
128 | read= Reader() |
---|
129 | read.load("testdata_line.txt") |
---|
130 | |
---|
131 | |
---|
Note: See
TracBrowser
for help on using the repository browser.