@@ -0,0 +1,220 | |||
|
1 | import numpy | |
|
2 | import plplot | |
|
3 | ||
|
4 | class BasicGraph: | |
|
5 | """ | |
|
6 | ||
|
7 | """ | |
|
8 | ||
|
9 | hasRange = False | |
|
10 | ||
|
11 | xrange = None | |
|
12 | yrange = None | |
|
13 | zrange = None | |
|
14 | ||
|
15 | xlabel = None | |
|
16 | ylabel = None | |
|
17 | title = None | |
|
18 | ||
|
19 | legends = None | |
|
20 | ||
|
21 | __name = None | |
|
22 | __subpage = None | |
|
23 | __szchar = None | |
|
24 | ||
|
25 | __colormap = None | |
|
26 | __colbox = None | |
|
27 | __colleg = None | |
|
28 | ||
|
29 | __xpos = None | |
|
30 | __ypos = None | |
|
31 | ||
|
32 | __xopt = None #"bcnst" | |
|
33 | __yopt = None #"bcnstv" | |
|
34 | ||
|
35 | __xlpos = None | |
|
36 | __ylpos = None | |
|
37 | ||
|
38 | __xrangeIsTime = None | |
|
39 | ||
|
40 | #Advanced | |
|
41 | __xg = None | |
|
42 | __yg = None | |
|
43 | ||
|
44 | def __init__(self): | |
|
45 | """ | |
|
46 | ||
|
47 | """ | |
|
48 | pass | |
|
49 | ||
|
50 | def hasNotXrange(self): | |
|
51 | ||
|
52 | if self.xrange == None: | |
|
53 | return 1 | |
|
54 | ||
|
55 | return 0 | |
|
56 | ||
|
57 | def hasNotYrange(self): | |
|
58 | ||
|
59 | if self.yrange == None: | |
|
60 | return 1 | |
|
61 | ||
|
62 | return 0 | |
|
63 | ||
|
64 | def hasNotZrange(self): | |
|
65 | ||
|
66 | if self.zrange == None: | |
|
67 | return 1 | |
|
68 | ||
|
69 | return 0 | |
|
70 | def setName(self, name): | |
|
71 | self.__name = name | |
|
72 | ||
|
73 | def setScreenPos(self, xpos, ypos): | |
|
74 | self.__xpos = xpos | |
|
75 | self.__ypos = ypos | |
|
76 | ||
|
77 | def setScreenPosbyWidth(self, xoff, yoff, xw, yw): | |
|
78 | self.__xpos = [xoff, xoff + xw] | |
|
79 | self.__ypos = [yoff, yoff + yw] | |
|
80 | ||
|
81 | def setSubpage(self, subpage): | |
|
82 | self.__subpage = subpage | |
|
83 | ||
|
84 | def setSzchar(self, szchar): | |
|
85 | self.__szchar = szchar | |
|
86 | ||
|
87 | def setOpt(self, xopt, yopt): | |
|
88 | self.__xopt = xopt | |
|
89 | self.__yopt = yopt | |
|
90 | ||
|
91 | def setRanges(self, xrange, yrange, zrange=None): | |
|
92 | """ | |
|
93 | """ | |
|
94 | self.xrange = xrange | |
|
95 | ||
|
96 | self.yrange = yrange | |
|
97 | ||
|
98 | if zrange != None: | |
|
99 | self.zrange = zrange | |
|
100 | ||
|
101 | def setColormap(self, colormap=None): | |
|
102 | ||
|
103 | if colormap == None: | |
|
104 | colormap = self.__colormap | |
|
105 | ||
|
106 | cmap1_init(colormap) | |
|
107 | ||
|
108 | def plotBox(self): | |
|
109 | """ | |
|
110 | ||
|
111 | """ | |
|
112 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |
|
113 | plplot.plwind(self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1]) | |
|
114 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) | |
|
115 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
|
116 | ||
|
117 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): | |
|
118 | """ | |
|
119 | """ | |
|
120 | self.title = title | |
|
121 | self.xlabel = xlabel | |
|
122 | self.ylabel = ylabel | |
|
123 | self.__colormap = colormap | |
|
124 | ||
|
125 | def initSubpage(self): | |
|
126 | ||
|
127 | if plplot.plgdev() == '': | |
|
128 | raise ValueError, "Plot device has not been initialize" | |
|
129 | ||
|
130 | plplot.pladv(self.__subpage) | |
|
131 | plplot.plschr(0.0, self.__szchar) | |
|
132 | ||
|
133 | if self.__xrangeIsTime: | |
|
134 | plplot.pltimefmt("%H:%M") | |
|
135 | ||
|
136 | self.setColormap() | |
|
137 | self.initPlot() | |
|
138 | ||
|
139 | def initPlot(self): | |
|
140 | """ | |
|
141 | ||
|
142 | """ | |
|
143 | if plplot.plgdev() == '': | |
|
144 | raise ValueError, "Plot device has not been initialize" | |
|
145 | ||
|
146 | xrange = self.xrange | |
|
147 | if xrange == None: | |
|
148 | xrange = [0., 1.] | |
|
149 | ||
|
150 | yrange = self.yrange | |
|
151 | if yrange == None: | |
|
152 | yrange = [0., 1.] | |
|
153 | ||
|
154 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |
|
155 | plplot.plwind(xrange[0], xrange[1], yrange[0], yrange[1]) | |
|
156 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) | |
|
157 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
|
158 | ||
|
159 | def colorbarPlot(self): | |
|
160 | data = numpy.arange(256) | |
|
161 | data = numpy.reshape(data, (1,-1)) | |
|
162 | ||
|
163 | self.plotBox() | |
|
164 | plplot.plimage(data, | |
|
165 | self.xrange[0], | |
|
166 | self.xrange[1], | |
|
167 | self.yrange[0], | |
|
168 | self.yrange[1], | |
|
169 | 0., | |
|
170 | 255., | |
|
171 | self.xrange[0], | |
|
172 | self.xrange[1], | |
|
173 | self.yrange[0], | |
|
174 | self.yrange[1],) | |
|
175 | ||
|
176 | def basicXYPlot(self, x, y): | |
|
177 | self.plotBox() | |
|
178 | plplot.plline(x, y) | |
|
179 | ||
|
180 | def basicXYwithErrorPlot(self): | |
|
181 | pass | |
|
182 | ||
|
183 | def basicLineTimePlot(self): | |
|
184 | pass | |
|
185 | ||
|
186 | def basicPcolorPlot(self, data, xmin, xmax, ymin, ymax, zmin, zmax): | |
|
187 | """ | |
|
188 | """ | |
|
189 | ||
|
190 | self.plotBox() | |
|
191 | plplot.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, xmin, xmax, ymin, ymax) | |
|
192 | ||
|
193 | ||
|
194 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |
|
195 | ||
|
196 | if not(len(x)>1 and len(y)>1): | |
|
197 | raise ValueError, "x axis and y axis are empty" | |
|
198 | ||
|
199 | if deltax == None: deltax = x[-1] - x[-2] | |
|
200 | if deltay == None: deltay = y[-1] - y[-2] | |
|
201 | ||
|
202 | x1 = numpy.append(x, x[-1] + deltax) | |
|
203 | y1 = numpy.append(y, y[-1] + deltay) | |
|
204 | ||
|
205 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
|
206 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
|
207 | ||
|
208 | self.__xg = xg | |
|
209 | self.__yg = yg | |
|
210 | ||
|
211 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): | |
|
212 | """ | |
|
213 | """ | |
|
214 | ||
|
215 | if self.__xg == None and self.__yg == None: | |
|
216 | self.__getBoxpltr(x, y) | |
|
217 | ||
|
218 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) | |
|
219 | ||
|
220 |
@@ -0,0 +1,182 | |||
|
1 | import numpy | |
|
2 | import plplot | |
|
3 | ||
|
4 | from BasicGraph import * | |
|
5 | ||
|
6 | class Spectrum(): | |
|
7 | ||
|
8 | graphObjDict = {} | |
|
9 | showColorbar = False | |
|
10 | showPowerProfile = True | |
|
11 | ||
|
12 | __szchar = 0.7 | |
|
13 | ||
|
14 | def __init__(self): | |
|
15 | ||
|
16 | key = "spec" | |
|
17 | ||
|
18 | specObj = BasicGraph() | |
|
19 | specObj.setName(key) | |
|
20 | ||
|
21 | self.graphObjDict[key] = specObj | |
|
22 | ||
|
23 | ||
|
24 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False): | |
|
25 | """ | |
|
26 | """ | |
|
27 | ||
|
28 | xi = 0.12; xw = 0.78; xf = xi + xw | |
|
29 | yi = 0.14; yw = 0.80; yf = yi + yw | |
|
30 | ||
|
31 | xcmapi = xcmapf = 0.; xpowi = xpowf = 0. | |
|
32 | ||
|
33 | key = "spec" | |
|
34 | specObj = self.graphObjDict[key] | |
|
35 | specObj.setSubpage(subpage) | |
|
36 | specObj.setSzchar(self.__szchar) | |
|
37 | specObj.setOpt("bcnts","bcnts") | |
|
38 | specObj.setup(title, | |
|
39 | xlabel, | |
|
40 | ylabel, | |
|
41 | colormap) | |
|
42 | ||
|
43 | if showColorbar: | |
|
44 | key = "colorbar" | |
|
45 | ||
|
46 | cmapObj = BasicGraph() | |
|
47 | cmapObj.setName(key) | |
|
48 | cmapObj.setSubpage(subpage) | |
|
49 | cmapObj.setSzchar(self.__szchar) | |
|
50 | cmapObj.setOpt("bc","bcmt") | |
|
51 | cmapObj.setup(title="dBs", | |
|
52 | xlabel="", | |
|
53 | ylabel="", | |
|
54 | colormap=colormap) | |
|
55 | ||
|
56 | self.graphObjDict[key] = cmapObj | |
|
57 | ||
|
58 | xcmapi = 0. | |
|
59 | xcmapw = 0.05 | |
|
60 | xw -= xcmapw | |
|
61 | ||
|
62 | if showPowerProfile: | |
|
63 | key = "powerprof" | |
|
64 | ||
|
65 | powObj = BasicGraph() | |
|
66 | powObj.setName(key) | |
|
67 | powObj.setSubpage(subpage) | |
|
68 | powObj.setSzchar(self.__szchar) | |
|
69 | plplot.pllsty(2) | |
|
70 | powObj.setOpt("bcntg","bc") | |
|
71 | plplot.pllsty(1) | |
|
72 | powObj.setup(title="Power Profile", | |
|
73 | xlabel="dBs", | |
|
74 | ylabel="") | |
|
75 | ||
|
76 | self.graphObjDict[key] = powObj | |
|
77 | ||
|
78 | xpowi = 0. | |
|
79 | xpoww = 0.24 | |
|
80 | xw -= xpoww | |
|
81 | ||
|
82 | xf = xi + xw | |
|
83 | yf = yi + yw | |
|
84 | xcmapf = xf | |
|
85 | ||
|
86 | specObj.setScreenPos([xi, xf], [yi, yf]) | |
|
87 | ||
|
88 | if showColorbar: | |
|
89 | xcmapi = xf + 0.02 | |
|
90 | xcmapf = xcmapi + xcmapw | |
|
91 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
|
92 | ||
|
93 | if showPowerProfile: | |
|
94 | xpowi = xcmapf + 0.06 | |
|
95 | xpowf = xpowi + xpoww | |
|
96 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
|
97 | ||
|
98 | ||
|
99 | # specObj.initSubpage() | |
|
100 | # | |
|
101 | # if showColorbar: | |
|
102 | # cmapObj.initPlot() | |
|
103 | # | |
|
104 | # if showPowerProfile: | |
|
105 | # powObj.initPlot() | |
|
106 | ||
|
107 | self.showColorbar = showColorbar | |
|
108 | self.showPowerProfile = showPowerProfile | |
|
109 | ||
|
110 | def setRanges(self, xrange, yrange, zrange): | |
|
111 | ||
|
112 | key = "spec" | |
|
113 | specObj = self.graphObjDict[key] | |
|
114 | specObj.setRanges(xrange, yrange, zrange) | |
|
115 | ||
|
116 | keyList = self.graphObjDict.keys() | |
|
117 | ||
|
118 | key = "colorbar" | |
|
119 | if key in keyList: | |
|
120 | cmapObj = self.graphObjDict[key] | |
|
121 | cmapObj.setRanges([0., 1.], zrange) | |
|
122 | ||
|
123 | key = "powerprof" | |
|
124 | if key in keyList: | |
|
125 | powObj = self.graphObjDict[key] | |
|
126 | powObj.setRanges(zrange, yrange) | |
|
127 | ||
|
128 | def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
|
129 | ||
|
130 | key = "spec" | |
|
131 | specObj = self.graphObjDict[key] | |
|
132 | specObj.initSubpage() | |
|
133 | ||
|
134 | if xmin == None: | |
|
135 | xmin = 0. | |
|
136 | ||
|
137 | if xmax == None: | |
|
138 | xmax = 1. | |
|
139 | ||
|
140 | if ymin == None: | |
|
141 | ymin = 0. | |
|
142 | ||
|
143 | if ymax == None: | |
|
144 | ymax = 1. | |
|
145 | ||
|
146 | if zmin == None: | |
|
147 | zmin = numpy.nanmin(data) | |
|
148 | ||
|
149 | if zmax == None: | |
|
150 | zmax = numpy.nanmax(data) | |
|
151 | ||
|
152 | if not(specObj.hasRange): | |
|
153 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) | |
|
154 | ||
|
155 | specObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, specObj.zrange[0], specObj.zrange[1]) | |
|
156 | ||
|
157 | if self.showColorbar: | |
|
158 | key = "colorbar" | |
|
159 | cmapObj = self.graphObjDict[key] | |
|
160 | cmapObj.colorbarPlot() | |
|
161 | ||
|
162 | if self.showPowerProfile: | |
|
163 | power = numpy.average(data, axis=1) | |
|
164 | ||
|
165 | step = (ymax - ymin)/(power.shape[0]-1) | |
|
166 | heis = numpy.arange(ymin, ymax + step, step) | |
|
167 | ||
|
168 | key = "powerprof" | |
|
169 | powObj = self.graphObjDict[key] | |
|
170 | powObj.basicXYPlot(power, heis) | |
|
171 | ||
|
172 | class CrossSpectrum(): | |
|
173 | ||
|
174 | def __init__(self): | |
|
175 | pass | |
|
176 | ||
|
177 | def setup(self): | |
|
178 | pass | |
|
179 | ||
|
180 | def plotData(self): | |
|
181 | pass | |
|
182 | No newline at end of file |
@@ -0,0 +1,1 | |||
|
1 |
@@ -0,0 +1,16 | |||
|
1 | ''' | |
|
2 | Created on 23/01/2012 | |
|
3 | ||
|
4 | @author: danielangelsuarezmunoz | |
|
5 | ''' | |
|
6 | ||
|
7 | from Data import DataReader | |
|
8 | from Data import DataWriter | |
|
9 | ||
|
10 | class CorrelationReader(DataReader): | |
|
11 | def __init__(self): | |
|
12 | pass | |
|
13 | ||
|
14 | class CorrelationWriter(DataWriter): | |
|
15 | def __init__(self): | |
|
16 | pass No newline at end of file |
@@ -0,0 +1,19 | |||
|
1 | ''' | |
|
2 | Created on 23/01/2012 | |
|
3 | ||
|
4 | @author: danielangelsuarezmunoz | |
|
5 | ''' | |
|
6 | ||
|
7 | from Header import * | |
|
8 | from Data import DataReader | |
|
9 | from Data import DataWriter | |
|
10 | ||
|
11 | ||
|
12 | class SpectraReader(DataReader): | |
|
13 | def __init__(self): | |
|
14 | pass | |
|
15 | ||
|
16 | class SpectraWriter(DataWriter): | |
|
17 | def __init__(self): | |
|
18 | pass | |
|
19 |
@@ -0,0 +1,375 | |||
|
1 | ''' | |
|
2 | Created on 23/01/2012 | |
|
3 | ||
|
4 | @author: danielangelsuarezmunoz | |
|
5 | ''' | |
|
6 | ||
|
7 | import numpy | |
|
8 | import os.path | |
|
9 | import glob | |
|
10 | import fnmatch | |
|
11 | import time | |
|
12 | import datetime | |
|
13 | ||
|
14 | from Header import * | |
|
15 | from Data import DataReader | |
|
16 | from Data import DataWriter | |
|
17 | ||
|
18 | class VoltageReader(DataReader): | |
|
19 | # Este flag indica que la data leida no es continua | |
|
20 | __jumpDataFlag = False | |
|
21 | ||
|
22 | __idFile = 0 | |
|
23 | ||
|
24 | __fp = 0 | |
|
25 | ||
|
26 | __startDateTime = 0 | |
|
27 | ||
|
28 | __endDateTime = 0 | |
|
29 | ||
|
30 | __dataType = 0 | |
|
31 | ||
|
32 | __sizeOfFileByHeader = 0 | |
|
33 | ||
|
34 | __pathList = [] | |
|
35 | ||
|
36 | filenameList = [] | |
|
37 | ||
|
38 | __lastUTTime = 0 | |
|
39 | ||
|
40 | __maxTimeStep = 5 | |
|
41 | ||
|
42 | __flagResetProcessing = 0 | |
|
43 | ||
|
44 | __flagIsNewFile = 0 | |
|
45 | ||
|
46 | noMoreFiles = 0 | |
|
47 | ||
|
48 | online = 0 | |
|
49 | ||
|
50 | filename = '' | |
|
51 | ||
|
52 | fileSize = 0 | |
|
53 | ||
|
54 | firstHeaderSize = 0 | |
|
55 | ||
|
56 | basicHeaderSize = 24 | |
|
57 | ||
|
58 | objBasicHeader = BasicHeader() | |
|
59 | ||
|
60 | objSystemHeader = SystemHeader() | |
|
61 | ||
|
62 | objRadarControllerHeader = RadarControllerHeader() | |
|
63 | ||
|
64 | objProcessingHeader = ProcessingHeader() | |
|
65 | ||
|
66 | __buffer = 0 | |
|
67 | ||
|
68 | __buffer_id = 9999 | |
|
69 | m_Voltage= Voltage() | |
|
70 | ||
|
71 | ||
|
72 | def __init__(self): | |
|
73 | pass | |
|
74 | ||
|
75 | def __rdSystemHeader(self,fp=None): | |
|
76 | if fp == None: | |
|
77 | fp = self.__fp | |
|
78 | ||
|
79 | self.objSystemHeader.read(fp) | |
|
80 | ||
|
81 | def __rdRadarControllerHeader(self,fp=None): | |
|
82 | if fp == None: | |
|
83 | fp = self.__fp | |
|
84 | ||
|
85 | self.objRadarControllerHeader.read(fp) | |
|
86 | ||
|
87 | def __rdProcessingHeader(self,fp=None): | |
|
88 | if fp == None: | |
|
89 | fp = self.__fp | |
|
90 | ||
|
91 | self.objProcessingHeader.read(fp) | |
|
92 | ||
|
93 | def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = "*.r"): | |
|
94 | ||
|
95 | startUtSeconds = time.mktime(startDateTime.timetuple()) | |
|
96 | endUtSeconds = time.mktime(endDateTime.timetuple()) | |
|
97 | ||
|
98 | startYear = startDateTime.timetuple().tm_year | |
|
99 | endYear = endDateTime.timetuple().tm_year | |
|
100 | ||
|
101 | startDoy = startDateTime.timetuple().tm_yday | |
|
102 | endDoy = endDateTime.timetuple().tm_yday | |
|
103 | ||
|
104 | rangeOfYears = range(startYear,endYear+1) | |
|
105 | ||
|
106 | listOfListDoys = [] | |
|
107 | if startYear == endYear: | |
|
108 | doyList = range(startDoy,endDoy+1) | |
|
109 | else: | |
|
110 | for year in rangeOfYears: | |
|
111 | if (year == startYear): | |
|
112 | listOfListDoys.append(range(startDoy,365+1)) | |
|
113 | elif (year == endYear): | |
|
114 | listOfListDoys.append(range(1,endDoy+1)) | |
|
115 | else: | |
|
116 | listOfListDoys.append(range(1,365+1)) | |
|
117 | doyList = [] | |
|
118 | for list in listOfListDoys: | |
|
119 | doyList = doyList + list | |
|
120 | ||
|
121 | folders = [] | |
|
122 | for thisPath in os.listdir(path): | |
|
123 | if os.path.isdir(os.path.join(path,thisPath)): | |
|
124 | #folders.append(os.path.join(path,thisPath)) | |
|
125 | folders.append(thisPath) | |
|
126 | ||
|
127 | pathList = [] | |
|
128 | dicOfPath = {} | |
|
129 | for year in rangeOfYears: | |
|
130 | for doy in doyList: | |
|
131 | tmp = fnmatch.filter(folders, 'D' + '%4.4d%3.3d' % (year,doy)) | |
|
132 | if len(tmp) == 0: | |
|
133 | continue | |
|
134 | if expLabel == '': | |
|
135 | pathList.append(os.path.join(path,tmp[0])) | |
|
136 | dicOfPath.setdefault(os.path.join(path,tmp[0])) | |
|
137 | dicOfPath[os.path.join(path,tmp[0])] = [] | |
|
138 | else: | |
|
139 | pathList.append(os.path.join(path,os.path.join(tmp[0],expLabel))) | |
|
140 | dicOfPath.setdefault(os.path.join(path,os.path.join(tmp[0],expLabel))) | |
|
141 | dicOfPath[os.path.join(path,os.path.join(tmp[0],expLabel))] = [] | |
|
142 | ||
|
143 | ||
|
144 | filenameList = [] | |
|
145 | for thisPath in pathList: | |
|
146 | fileList = glob.glob1(thisPath, ext) | |
|
147 | #dicOfPath[thisPath].append(fileList) | |
|
148 | fileList.sort() | |
|
149 | for file in fileList: | |
|
150 | filename = os.path.join(thisPath,file) | |
|
151 | if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
|
152 | filenameList.append(filename) | |
|
153 | ||
|
154 | self.filenameList = filenameList | |
|
155 | ||
|
156 | return pathList, filenameList | |
|
157 | ||
|
158 | def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None): | |
|
159 | ||
|
160 | try: | |
|
161 | fp = open(filename,'rb') | |
|
162 | except: | |
|
163 | raise IOError, "The file %s can't be opened" %(filename) | |
|
164 | ||
|
165 | if startUTSeconds==None: | |
|
166 | startUTSeconds = self.startUTCSeconds | |
|
167 | ||
|
168 | if endUTSeconds==None: | |
|
169 | endUTSeconds = self.endUTCSeconds | |
|
170 | ||
|
171 | objBasicHeader = BasicHeader() | |
|
172 | ||
|
173 | if not(objBasicHeader.read(fp)): | |
|
174 | return 0 | |
|
175 | ||
|
176 | fp.close() | |
|
177 | ||
|
178 | if not ((startUTSeconds <= objBasicHeader.utc) and (endUTSeconds >= objBasicHeader.utc)): | |
|
179 | return 0 | |
|
180 | ||
|
181 | return 1 | |
|
182 | ||
|
183 | def __readBasicHeader(self, fp=None): | |
|
184 | ||
|
185 | if fp == None: | |
|
186 | fp = self.__fp | |
|
187 | ||
|
188 | self.objBasicHeader.read(fp) | |
|
189 | ||
|
190 | def __readFirstHeader(self): | |
|
191 | ||
|
192 | self.__readBasicHeader() | |
|
193 | self.__rdSystemHeader() | |
|
194 | self.__rdRadarControllerHeader() | |
|
195 | self.__rdProcessingHeader() | |
|
196 | self.firstHeaderSize = self.objBasicHeader.size | |
|
197 | ||
|
198 | data_type=int(numpy.log2((self.objProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
|
199 | if data_type == 0: | |
|
200 | tmp=numpy.dtype([('real','<i1'),('imag','<i1')]) | |
|
201 | elif data_type == 1: | |
|
202 | tmp=numpy.dtype([('real','<i2'),('imag','<i2')]) | |
|
203 | elif data_type == 2: | |
|
204 | tmp=numpy.dtype([('real','<i4'),('imag','<i4')]) | |
|
205 | elif data_type == 3: | |
|
206 | tmp=numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
207 | elif data_type == 4: | |
|
208 | tmp=numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
209 | elif data_type == 5: | |
|
210 | tmp=numpy.dtype([('real','<f8'),('imag','<f8')]) | |
|
211 | else: | |
|
212 | print 'no define data type' | |
|
213 | tmp = 0 | |
|
214 | ||
|
215 | self.__flagIsNewFile = 0 | |
|
216 | self.__dataType = tmp | |
|
217 | self.__sizeOfFileByHeader = self.objProcessingHeader.dataBlocksPerFile * self.objProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.objProcessingHeader.dataBlocksPerFile - 1) | |
|
218 | ||
|
219 | def __setNextFileOnline(self): | |
|
220 | return 0 | |
|
221 | ||
|
222 | def __setNextFileOffline(self): | |
|
223 | ||
|
224 | idFile = self.__idFile | |
|
225 | while(True): | |
|
226 | ||
|
227 | idFile += 1 | |
|
228 | ||
|
229 | if not(idFile < len(self.filenameList)): | |
|
230 | self.noMoreFiles = 1 | |
|
231 | return 0 | |
|
232 | ||
|
233 | filename = self.filenameList[idFile] | |
|
234 | fileSize = os.path.getsize(filename) | |
|
235 | fp = open(filename,'rb') | |
|
236 | ||
|
237 | currentSize = fileSize - fp.tell() | |
|
238 | neededSize = self.objProcessingHeader.blockSize + self.firstHeaderSize | |
|
239 | ||
|
240 | if (currentSize < neededSize): | |
|
241 | continue | |
|
242 | ||
|
243 | break | |
|
244 | ||
|
245 | self.__flagIsNewFile = 1 | |
|
246 | self.__idFile = idFile | |
|
247 | self.filename = filename | |
|
248 | self.fileSize = fileSize | |
|
249 | self.__fp = fp | |
|
250 | ||
|
251 | print 'Setting the file: %s'%self.filename | |
|
252 | ||
|
253 | return 1 | |
|
254 | ||
|
255 | def __setNextFile(self): | |
|
256 | ||
|
257 | if self.online: | |
|
258 | return self.__setNextFileOnline() | |
|
259 | else: | |
|
260 | return self.__setNextFileOffline() | |
|
261 | ||
|
262 | def __setNewBlock(self): | |
|
263 | ||
|
264 | currentSize = self.fileSize - self.__fp.tell() | |
|
265 | neededSize = self.objProcessingHeader.blockSize + self.basicHeaderSize | |
|
266 | ||
|
267 | # Bloque Completo | |
|
268 | if (currentSize >= neededSize): | |
|
269 | self.__readBasicHeader() | |
|
270 | return 1 | |
|
271 | ||
|
272 | self.__setNextFile() | |
|
273 | self.__readFirstHeader() | |
|
274 | ||
|
275 | deltaTime = self.objBasicHeader.utc - self.__lastUTTime # check this | |
|
276 | if deltaTime > self.__maxTimeStep: | |
|
277 | self.__flagResetProcessing = 1 | |
|
278 | ||
|
279 | return 1 | |
|
280 | ||
|
281 | def __readBlock(self): | |
|
282 | """Lee el bloque de datos desde la posicion actual del puntero del archivo y | |
|
283 | actualiza todos los parametros relacionados al bloque de datos (data, time, | |
|
284 | etc). La data leida es almacenada en el buffer y el contador de datos leidos es | |
|
285 | seteado a 0 | |
|
286 | """ | |
|
287 | ||
|
288 | pts2read = self.objProcessingHeader.profilesPerBlock*self.objProcessingHeader.numHeights*self.objSystemHeader.numChannels | |
|
289 | ||
|
290 | data = numpy.fromfile(self.__fp,self.__dataType,pts2read) | |
|
291 | ||
|
292 | data = data.reshape((self.objProcessingHeader.profilesPerBlock, self.objProcessingHeader.numHeights, self.objSystemHeader.numChannels)) | |
|
293 | ||
|
294 | self.__buffer = data | |
|
295 | ||
|
296 | self.__buffer_id = 0 | |
|
297 | ||
|
298 | def readNextBlock(self): | |
|
299 | ||
|
300 | self.__setNewBlock() | |
|
301 | ||
|
302 | self.__readBlock() | |
|
303 | ||
|
304 | self.__lastUTTime = self.objBasicHeader.utc | |
|
305 | ||
|
306 | def __hasNotDataInBuffer(self): | |
|
307 | if self.__buffer_id >= self.objProcessingHeader.profilesPerBlock: | |
|
308 | return 1 | |
|
309 | ||
|
310 | return 0 | |
|
311 | ||
|
312 | def getData(self): | |
|
313 | """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Data" | |
|
314 | con todos los parametros asociados a este. cuando no hay datos en el buffer de | |
|
315 | lectura es necesario hacer una nueva lectura de los bloques de datos | |
|
316 | "__readBlock" | |
|
317 | """ | |
|
318 | ||
|
319 | if self.__hasNotDataInBuffer(): | |
|
320 | self.readNextBlock() | |
|
321 | ||
|
322 | if self.noMoreFiles == 1: | |
|
323 | print 'read finished' | |
|
324 | return None | |
|
325 | ||
|
326 | data = self.__buffer[self.__buffer_id,:,:] | |
|
327 | ||
|
328 | #print self.__buffer_id | |
|
329 | ||
|
330 | self.__buffer_id += 1 | |
|
331 | ||
|
332 | #call setData - to Data Object | |
|
333 | ||
|
334 | return data | |
|
335 | ||
|
336 | ||
|
337 | def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0): | |
|
338 | ||
|
339 | if online == 0: | |
|
340 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) | |
|
341 | ||
|
342 | if len(filenameList) == 0: | |
|
343 | print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime()) | |
|
344 | return 0 | |
|
345 | ||
|
346 | # for thisFile in filenameList: | |
|
347 | # print thisFile | |
|
348 | ||
|
349 | self.__idFile = -1 | |
|
350 | ||
|
351 | if not(self.__setNextFile()): | |
|
352 | print "No more files" | |
|
353 | return 0 | |
|
354 | ||
|
355 | self.__readFirstHeader() | |
|
356 | ||
|
357 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |
|
358 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) | |
|
359 | ||
|
360 | self.startYear = startDateTime.timetuple().tm_year | |
|
361 | self.endYear = endDateTime.timetuple().tm_year | |
|
362 | ||
|
363 | self.startDoy = startDateTime.timetuple().tm_yday | |
|
364 | self.endDoy = endDateTime.timetuple().tm_yday | |
|
365 | #call fillHeaderValues() - to Data Object | |
|
366 | ||
|
367 | self.__pathList = pathList | |
|
368 | self.filenameList = filenameList | |
|
369 | self.online = online | |
|
370 | ||
|
371 | class VoltageWriter(DataWriter): | |
|
372 | ||
|
373 | def __init__(self): | |
|
374 | pass | |
|
375 | No newline at end of file |
@@ -0,0 +1,1 | |||
|
1 |
@@ -0,0 +1,1 | |||
|
1 |
@@ -9,4 +9,10 class DataReader: | |||
|
9 | 9 | __buffer = 0 |
|
10 | 10 | __buffer_count = 0 |
|
11 | 11 | def __init__(self): |
|
12 | pass | |
|
13 | ||
|
14 | class DataWriter: | |
|
15 | __buffer = 0 | |
|
16 | __buffer_count = 0 | |
|
17 | def __init__(self): | |
|
12 | 18 | pass No newline at end of file |
@@ -1,18 +1,3 | |||
|
1 | ''' | |
|
2 | Created on 23/01/2012 | |
|
3 | ||
|
4 | @author: danielangelsuarezmunoz | |
|
5 | ''' | |
|
6 | ||
|
7 | from DataReader import DataReader | |
|
8 | ||
|
9 | import numpy | |
|
10 | import os.path | |
|
11 | import glob | |
|
12 | import fnmatch | |
|
13 | import time | |
|
14 | import datetime | |
|
15 | ||
|
16 | 1 |
|
|
17 | 2 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
18 | 3 | DECODE_DATA = numpy.uint32(0x00000002) |
@@ -50,7 +35,7 class PROCFLAG: | |||
|
50 | 35 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
51 | 36 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
52 | 37 | |
|
53 |
class BasicHeader |
|
|
38 | class BasicHeader: | |
|
54 | 39 | |
|
55 | 40 | size = 0 |
|
56 | 41 | version = 0 |
@@ -88,7 +73,7 class BasicHeader(): | |||
|
88 | 73 | |
|
89 | 74 | return 1 |
|
90 | 75 | |
|
91 |
class SystemHeader |
|
|
76 | class SystemHeader: | |
|
92 | 77 | size = 0 |
|
93 | 78 | numSamples = 0 |
|
94 | 79 | numProfiles = 0 |
@@ -119,7 +104,7 class SystemHeader(): | |||
|
119 | 104 | |
|
120 | 105 | return 1 |
|
121 | 106 | |
|
122 |
class RadarControllerHeader |
|
|
107 | class RadarControllerHeader: | |
|
123 | 108 | size = 0 |
|
124 | 109 | expType = 0 |
|
125 | 110 | nTx = 0 |
@@ -186,7 +171,7 class RadarControllerHeader(): | |||
|
186 | 171 | |
|
187 | 172 | return 1 |
|
188 | 173 | |
|
189 |
class ProcessingHeader |
|
|
174 | class ProcessingHeader: | |
|
190 | 175 | size = 0 |
|
191 | 176 | dataType = 0 |
|
192 | 177 | blockSize = 0 |
@@ -247,355 +232,4 class ProcessingHeader(): | |||
|
247 | 232 | self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode) |
|
248 | 233 | |
|
249 | 234 | |
|
250 |
return 1 |
|
|
251 | ||
|
252 | class VoltageReader(DataReader): | |
|
253 | # Este flag indica que la data leida no es continua | |
|
254 | __jumpDataFlag = False | |
|
255 | ||
|
256 | __idFile = 0 | |
|
257 | ||
|
258 | __fp = 0 | |
|
259 | ||
|
260 | __startDateTime = 0 | |
|
261 | ||
|
262 | __endDateTime = 0 | |
|
263 | ||
|
264 | __dataType = 0 | |
|
265 | ||
|
266 | __sizeOfFileByHeader = 0 | |
|
267 | ||
|
268 | __pathList = [] | |
|
269 | ||
|
270 | filenameList = [] | |
|
271 | ||
|
272 | __lastUTTime = 0 | |
|
273 | ||
|
274 | __maxTimeStep = 5 | |
|
275 | ||
|
276 | __flagResetProcessing = 0 | |
|
277 | ||
|
278 | __flagIsNewFile = 0 | |
|
279 | ||
|
280 | noMoreFiles = 0 | |
|
281 | ||
|
282 | online = 0 | |
|
283 | ||
|
284 | filename = '' | |
|
285 | ||
|
286 | fileSize = 0 | |
|
287 | ||
|
288 | firstHeaderSize = 0 | |
|
289 | ||
|
290 | basicHeaderSize = 24 | |
|
291 | ||
|
292 | objBasicHeader = BasicHeader() | |
|
293 | ||
|
294 | objSystemHeader = SystemHeader() | |
|
295 | ||
|
296 | objRadarControllerHeader = RadarControllerHeader() | |
|
297 | ||
|
298 | objProcessingHeader = ProcessingHeader() | |
|
299 | ||
|
300 | __buffer = 0 | |
|
301 | ||
|
302 | __buffer_id = 9999 | |
|
303 | ||
|
304 | def __init__(self): | |
|
305 | pass | |
|
306 | ||
|
307 | def __rdSystemHeader(self,fp=None): | |
|
308 | if fp == None: | |
|
309 | fp = self.__fp | |
|
310 | ||
|
311 | self.objSystemHeader.read(fp) | |
|
312 | ||
|
313 | def __rdRadarControllerHeader(self,fp=None): | |
|
314 | if fp == None: | |
|
315 | fp = self.__fp | |
|
316 | ||
|
317 | self.objRadarControllerHeader.read(fp) | |
|
318 | ||
|
319 | def __rdProcessingHeader(self,fp=None): | |
|
320 | if fp == None: | |
|
321 | fp = self.__fp | |
|
322 | ||
|
323 | self.objProcessingHeader.read(fp) | |
|
324 | ||
|
325 | def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = "*.r"): | |
|
326 | ||
|
327 | startUtSeconds = time.mktime(startDateTime.timetuple()) | |
|
328 | endUtSeconds = time.mktime(endDateTime.timetuple()) | |
|
329 | ||
|
330 | startYear = startDateTime.timetuple().tm_year | |
|
331 | endYear = endDateTime.timetuple().tm_year | |
|
332 | ||
|
333 | startDoy = startDateTime.timetuple().tm_yday | |
|
334 | endDoy = endDateTime.timetuple().tm_yday | |
|
335 | ||
|
336 | rangeOfYears = range(startYear,endYear+1) | |
|
337 | ||
|
338 | listOfListDoys = [] | |
|
339 | if startYear == endYear: | |
|
340 | doyList = range(startDoy,endDoy+1) | |
|
341 | else: | |
|
342 | for year in rangeOfYears: | |
|
343 | if (year == startYear): | |
|
344 | listOfListDoys.append(range(startDoy,365+1)) | |
|
345 | elif (year == endYear): | |
|
346 | listOfListDoys.append(range(1,endDoy+1)) | |
|
347 | else: | |
|
348 | listOfListDoys.append(range(1,365+1)) | |
|
349 | doyList = [] | |
|
350 | for list in listOfListDoys: | |
|
351 | doyList = doyList + list | |
|
352 | ||
|
353 | folders = [] | |
|
354 | for thisPath in os.listdir(path): | |
|
355 | if os.path.isdir(os.path.join(path,thisPath)): | |
|
356 | #folders.append(os.path.join(path,thisPath)) | |
|
357 | folders.append(thisPath) | |
|
358 | ||
|
359 | pathList = [] | |
|
360 | dicOfPath = {} | |
|
361 | for year in rangeOfYears: | |
|
362 | for doy in doyList: | |
|
363 | tmp = fnmatch.filter(folders, 'D' + '%4.4d%3.3d' % (year,doy)) | |
|
364 | if len(tmp) == 0: | |
|
365 | continue | |
|
366 | if expLabel == '': | |
|
367 | pathList.append(os.path.join(path,tmp[0])) | |
|
368 | dicOfPath.setdefault(os.path.join(path,tmp[0])) | |
|
369 | dicOfPath[os.path.join(path,tmp[0])] = [] | |
|
370 | else: | |
|
371 | pathList.append(os.path.join(path,os.path.join(tmp[0],expLabel))) | |
|
372 | dicOfPath.setdefault(os.path.join(path,os.path.join(tmp[0],expLabel))) | |
|
373 | dicOfPath[os.path.join(path,os.path.join(tmp[0],expLabel))] = [] | |
|
374 | ||
|
375 | ||
|
376 | filenameList = [] | |
|
377 | for thisPath in pathList: | |
|
378 | fileList = glob.glob1(thisPath, ext) | |
|
379 | #dicOfPath[thisPath].append(fileList) | |
|
380 | fileList.sort() | |
|
381 | for file in fileList: | |
|
382 | filename = os.path.join(thisPath,file) | |
|
383 | if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
|
384 | filenameList.append(filename) | |
|
385 | ||
|
386 | self.filenameList = filenameList | |
|
387 | ||
|
388 | return pathList, filenameList | |
|
389 | ||
|
390 | def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None): | |
|
391 | ||
|
392 | try: | |
|
393 | fp = open(filename,'rb') | |
|
394 | except: | |
|
395 | raise IOError, "The file %s can't be opened" %(filename) | |
|
396 | ||
|
397 | if startUTSeconds==None: | |
|
398 | startUTSeconds = self.startUTCSeconds | |
|
399 | ||
|
400 | if endUTSeconds==None: | |
|
401 | endUTSeconds = self.endUTCSeconds | |
|
402 | ||
|
403 | objBasicHeader = BasicHeader() | |
|
404 | ||
|
405 | if not(objBasicHeader.read(fp)): | |
|
406 | return 0 | |
|
407 | ||
|
408 | fp.close() | |
|
409 | ||
|
410 | if not ((startUTSeconds <= objBasicHeader.utc) and (endUTSeconds >= objBasicHeader.utc)): | |
|
411 | return 0 | |
|
412 | ||
|
413 | return 1 | |
|
414 | ||
|
415 | def __readBasicHeader(self, fp=None): | |
|
416 | ||
|
417 | if fp == None: | |
|
418 | fp = self.__fp | |
|
419 | ||
|
420 | self.objBasicHeader.read(fp) | |
|
421 | ||
|
422 | def __readFirstHeader(self): | |
|
423 | ||
|
424 | self.__readBasicHeader() | |
|
425 | self.__rdSystemHeader() | |
|
426 | self.__rdRadarControllerHeader() | |
|
427 | self.__rdProcessingHeader() | |
|
428 | self.firstHeaderSize = self.objBasicHeader.size | |
|
429 | ||
|
430 | data_type=int(numpy.log2((self.objProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
|
431 | if data_type == 0: | |
|
432 | tmp=numpy.dtype([('real','<i1'),('imag','<i1')]) | |
|
433 | elif data_type == 1: | |
|
434 | tmp=numpy.dtype([('real','<i2'),('imag','<i2')]) | |
|
435 | elif data_type == 2: | |
|
436 | tmp=numpy.dtype([('real','<i4'),('imag','<i4')]) | |
|
437 | elif data_type == 3: | |
|
438 | tmp=numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
439 | elif data_type == 4: | |
|
440 | tmp=numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
441 | elif data_type == 5: | |
|
442 | tmp=numpy.dtype([('real','<f8'),('imag','<f8')]) | |
|
443 | else: | |
|
444 | print 'no define data type' | |
|
445 | tmp = 0 | |
|
446 | ||
|
447 | self.__flagIsNewFile = 0 | |
|
448 | self.__dataType = tmp | |
|
449 | self.__sizeOfFileByHeader = self.objProcessingHeader.dataBlocksPerFile * self.objProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.objProcessingHeader.dataBlocksPerFile - 1) | |
|
450 | ||
|
451 | def __setNextFileOnline(self): | |
|
452 | return 0 | |
|
453 | ||
|
454 | def __setNextFileOffline(self): | |
|
455 | ||
|
456 | idFile = self.__idFile | |
|
457 | while(True): | |
|
458 | ||
|
459 | idFile += 1 | |
|
460 | ||
|
461 | if not(idFile < len(self.filenameList)): | |
|
462 | self.noMoreFiles = 1 | |
|
463 | return 0 | |
|
464 | ||
|
465 | filename = self.filenameList[idFile] | |
|
466 | fileSize = os.path.getsize(filename) | |
|
467 | fp = open(filename,'rb') | |
|
468 | ||
|
469 | currentSize = fileSize - fp.tell() | |
|
470 | neededSize = self.objProcessingHeader.blockSize + self.firstHeaderSize | |
|
471 | ||
|
472 | if (currentSize < neededSize): | |
|
473 | continue | |
|
474 | ||
|
475 | break | |
|
476 | ||
|
477 | self.__flagIsNewFile = 1 | |
|
478 | self.__idFile = idFile | |
|
479 | self.filename = filename | |
|
480 | self.fileSize = fileSize | |
|
481 | self.__fp = fp | |
|
482 | ||
|
483 | print 'Setting the file: %s'%self.filename | |
|
484 | ||
|
485 | return 1 | |
|
486 | ||
|
487 | def __setNextFile(self): | |
|
488 | ||
|
489 | if self.online: | |
|
490 | return self.__setNextFileOnline() | |
|
491 | else: | |
|
492 | return self.__setNextFileOffline() | |
|
493 | ||
|
494 | def __setNewBlock(self): | |
|
495 | ||
|
496 | currentSize = self.fileSize - self.__fp.tell() | |
|
497 | neededSize = self.objProcessingHeader.blockSize + self.basicHeaderSize | |
|
498 | ||
|
499 | # Bloque Completo | |
|
500 | if (currentSize >= neededSize): | |
|
501 | self.__readBasicHeader() | |
|
502 | return 1 | |
|
503 | ||
|
504 | self.__setNextFile() | |
|
505 | self.__readFirstHeader() | |
|
506 | ||
|
507 | deltaTime = self.objBasicHeader.utc - self.__lastUTTime # check this | |
|
508 | if deltaTime > self.__maxTimeStep: | |
|
509 | self.__flagResetProcessing = 1 | |
|
510 | ||
|
511 | return 1 | |
|
512 | ||
|
513 | def __readBlock(self): | |
|
514 | """Lee el bloque de datos desde la posicion actual del puntero del archivo y | |
|
515 | actualiza todos los parametros relacionados al bloque de datos (data, time, | |
|
516 | etc). La data leida es almacenada en el buffer y el contador de datos leidos es | |
|
517 | seteado a 0 | |
|
518 | """ | |
|
519 | ||
|
520 | pts2read = self.objProcessingHeader.profilesPerBlock*self.objProcessingHeader.numHeights*self.objSystemHeader.numChannels | |
|
521 | ||
|
522 | data = numpy.fromfile(self.__fp,self.__dataType,pts2read) | |
|
523 | ||
|
524 | data = data.reshape((self.objProcessingHeader.profilesPerBlock, self.objProcessingHeader.numHeights, self.objSystemHeader.numChannels)) | |
|
525 | ||
|
526 | self.__buffer = data | |
|
527 | ||
|
528 | self.__buffer_id = 0 | |
|
529 | ||
|
530 | def readNextBlock(self): | |
|
531 | ||
|
532 | self.__setNewBlock() | |
|
533 | ||
|
534 | self.__readBlock() | |
|
535 | ||
|
536 | self.__lastUTTime = self.objBasicHeader.utc | |
|
537 | ||
|
538 | def __hasNotDataInBuffer(self): | |
|
539 | if self.__buffer_id >= self.objProcessingHeader.profilesPerBlock: | |
|
540 | return 1 | |
|
541 | ||
|
542 | return 0 | |
|
543 | ||
|
544 | def getData(self): | |
|
545 | """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Data" | |
|
546 | con todos los parametros asociados a este. cuando no hay datos en el buffer de | |
|
547 | lectura es necesario hacer una nueva lectura de los bloques de datos | |
|
548 | "__readBlock" | |
|
549 | """ | |
|
550 | ||
|
551 | if self.__hasNotDataInBuffer(): | |
|
552 | self.readNextBlock() | |
|
553 | ||
|
554 | if self.noMoreFiles == 1: | |
|
555 | print 'read finished' | |
|
556 | return None | |
|
557 | ||
|
558 | data = self.__buffer[self.__buffer_id,:,:] | |
|
559 | ||
|
560 | #print self.__buffer_id | |
|
561 | ||
|
562 | self.__buffer_id += 1 | |
|
563 | ||
|
564 | #call setData - to Data Object | |
|
565 | ||
|
566 | return data | |
|
567 | ||
|
568 | ||
|
569 | def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0): | |
|
570 | ||
|
571 | if online == 0: | |
|
572 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) | |
|
573 | ||
|
574 | if len(filenameList) == 0: | |
|
575 | print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime()) | |
|
576 | return 0 | |
|
577 | ||
|
578 | # for thisFile in filenameList: | |
|
579 | # print thisFile | |
|
580 | ||
|
581 | self.__idFile = -1 | |
|
582 | ||
|
583 | if not(self.__setNextFile()): | |
|
584 | print "No more files" | |
|
585 | return 0 | |
|
586 | ||
|
587 | self.__readFirstHeader() | |
|
588 | ||
|
589 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |
|
590 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) | |
|
591 | ||
|
592 | self.startYear = startDateTime.timetuple().tm_year | |
|
593 | self.endYear = endDateTime.timetuple().tm_year | |
|
594 | ||
|
595 | self.startDoy = startDateTime.timetuple().tm_yday | |
|
596 | self.endDoy = endDateTime.timetuple().tm_yday | |
|
597 | #call fillHeaderValues() - to Data Object | |
|
598 | ||
|
599 | self.__pathList = pathList | |
|
600 | self.filenameList = filenameList | |
|
601 | self.online = online | |
|
235 | return 1 No newline at end of file |
@@ -11,8 +11,8 import time | |||
|
11 | 11 | objReader = VoltageReader.VoltageReader() |
|
12 | 12 | |
|
13 | 13 | path = '/Users/danielangelsuarezmunoz/Documents/Projects' |
|
14 |
startDateTime = datetime.datetime(2007, |
|
|
15 |
endDateTime = datetime.datetime(2007, |
|
|
14 | startDateTime = datetime.datetime(2007,1,1,16,0,0) | |
|
15 | endDateTime = datetime.datetime(2007,12,1,17,1,0) | |
|
16 | 16 | set = None |
|
17 | 17 | expLabel = '' |
|
18 | 18 | ext = '*.r' |
@@ -25,7 +25,7 print time.time() - t0 | |||
|
25 | 25 | while(not(objReader.noMoreFiles)): |
|
26 | 26 | |
|
27 | 27 | objReader.getData() |
|
28 |
print objReader.obj |
|
|
28 | #print objReader.objStructShortHeader.dataBlock | |
|
29 | 29 | #print time.localtime(objReader.objStructShortHeader.universalTime) |
|
30 | 30 | |
|
31 | 31 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now