@@ -1,340 +1,344 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | from schainPlotLib import Driver |
|
3 | from schainPlotLib import Driver | |
4 |
|
4 | |||
5 | class Figure: |
|
5 | class Figure: | |
6 | __isDriverOpen = False |
|
6 | __isDriverOpen = False | |
7 | __isFigureOpen = False |
|
7 | __isFigureOpen = False | |
8 | __isConfig = False |
|
8 | __isConfig = False | |
9 | drvObj = None |
|
9 | drvObj = None | |
10 | idfigure = None |
|
10 | idfigure = None | |
11 | nframes = None |
|
11 | nframes = None | |
12 | wintitle = None |
|
12 | wintitle = None | |
13 | colormap = None |
|
13 | colormap = None | |
14 | driver = None |
|
14 | driver = None | |
15 | overplot = None |
|
15 | overplot = None | |
16 | xmin = None |
|
16 | xmin = None | |
17 | xmax = None |
|
17 | xmax = None | |
18 | ymin = None |
|
18 | ymin = None | |
19 | ymax = None |
|
19 | ymax = None | |
20 | minvalue = None |
|
20 | minvalue = None | |
21 | maxvalue = None |
|
21 | maxvalue = None | |
22 | deltax = None |
|
22 | deltax = None | |
23 | deltay = None |
|
23 | deltay = None | |
24 | frameObjList = [] |
|
24 | frameObjList = [] | |
25 | figuretitle = "" |
|
25 | figuretitle = "" | |
26 | xrangestep = None |
|
26 | xrangestep = None | |
27 |
|
27 | |||
28 |
def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True |
|
28 | def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args): | |
|
29 | ||||
|
30 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar) | |||
|
31 | self.driver = driver | |||
29 | self.idfigure = idfigure |
|
32 | self.idfigure = idfigure | |
30 | self.nframes = nframes |
|
|||
31 | self.wintitle = wintitle |
|
|||
32 | self.xw = xw |
|
33 | self.xw = xw | |
33 | self.yw = yw |
|
34 | self.yw = yw | |
|
35 | self.nframes = nframes | |||
|
36 | self.wintitle = wintitle | |||
|
37 | self.colormap = colormap | |||
34 | self.overplot = overplot |
|
38 | self.overplot = overplot | |
35 | self.colorbar = colorbar |
|
39 | self.colorbar = colorbar | |
36 |
self. |
|
40 | # self.showGraph1 = args[0] | |
37 | #esta seccion deberia ser dinamica de acuerdo a len(args) |
|
41 | # self.showGraph2 = args[1] | |
38 | self.showGraph1 = args[0] |
|
|||
39 | self.showGraph2 = args[1] |
|
|||
40 |
|
||||
41 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap) |
|
|||
42 |
|
42 | |||
43 | self.drvObj.driver.setFigure() |
|
43 | self.drvObj.driver.setFigure() | |
44 | self.drvObj.driver.setColormap(colormap) |
|
44 | self.drvObj.driver.setColormap(colormap) | |
45 |
|
45 | |||
46 |
|
46 | |||
|
47 | ||||
47 | def __openDriver(self): |
|
48 | def __openDriver(self): | |
48 | self.drvObj.driver.openDriver() |
|
49 | self.drvObj.driver.openDriver() | |
49 |
|
50 | |||
50 | # def __openFigure(self): |
|
|||
51 | # nrows, ncolumns = self.getSubplots() |
|
|||
52 | # self.drvObj.driver.openFigure() |
|
|||
53 | # self.drvObj.driver.setTitleFig(title) |
|
|||
54 | # self.drvObj.driver.setSubPlots(nrows, ncolumns) |
|
|||
55 |
|
||||
56 | def __initFigure(self): |
|
51 | def __initFigure(self): | |
57 | nrows, ncolumns = self.getSubplots() |
|
52 | nrows, ncolumns = self.getSubplots() | |
58 | self.drvObj.driver.openFigure() |
|
53 | self.drvObj.driver.openFigure() | |
59 | self.drvObj.driver.setFigTitle(self.figuretitle) |
|
54 | self.drvObj.driver.setFigTitle(self.figuretitle) | |
60 | self.drvObj.driver.setSubPlots(nrows, ncolumns) |
|
55 | self.drvObj.driver.setSubPlots(nrows, ncolumns) | |
61 |
|
56 | |||
62 | def __isOutOfXRange(self,x): |
|
57 | def __isOutOfXRange(self,x): | |
63 |
|
58 | try: | ||
64 | if ((x>=self.xmin) and (x<self.xmax)): |
|
59 | if ((x>=self.xmin) and (x<self.xmax)): | |
65 | return 0 |
|
60 | return 0 | |
|
61 | except: | |||
|
62 | return 0 | |||
66 |
|
63 | |||
67 | return 1 |
|
64 | return 1 | |
68 |
|
65 | |||
69 | def changeXRange(self,x): |
|
66 | def changeXRange(self,x): | |
70 |
|
67 | |||
71 | pass |
|
68 | pass | |
72 |
|
69 | |||
73 | def __refresh(self): |
|
70 | def __refresh(self): | |
74 | self.drvObj.driver.refresh() |
|
71 | self.drvObj.driver.refresh() | |
75 |
|
72 | |||
76 | def createFrames(self): |
|
73 | def createFrames(self): | |
77 | raise ValueError, "No implemented" |
|
74 | raise ValueError, "No implemented" | |
78 |
|
75 | |||
79 | def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'): |
|
76 | def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'): | |
80 |
|
77 | |||
81 | nx, ny = data1D.shape |
|
78 | nx, ny = data1D.shape | |
82 |
|
79 | |||
83 | if channelList == None: |
|
80 | if channelList == None: | |
84 | channelList = range(nx) |
|
81 | channelList = range(nx) | |
85 |
|
82 | |||
86 | if x == None: |
|
83 | if x == None: | |
87 | x = numpy.arange(data1D.size) |
|
84 | x = numpy.arange(data1D.size) | |
88 |
|
85 | |||
89 | if figuretitle == None: |
|
86 | if figuretitle == None: | |
90 | self.figuretitle = "" |
|
87 | self.figuretitle = "" | |
91 | else: |
|
88 | else: | |
92 | self.figuretitle = figuretitle |
|
89 | self.figuretitle = figuretitle | |
93 |
|
90 | |||
94 | if not(self.__isDriverOpen): |
|
91 | if not(self.__isDriverOpen): | |
95 | self.__openDriver() |
|
92 | self.__openDriver() | |
96 | self.__isDriverOpen = True |
|
93 | self.__isDriverOpen = True | |
97 |
|
94 | |||
98 | if not(self.__isConfig): |
|
95 | if not(self.__isConfig): | |
99 | self.xmin = xmin |
|
96 | self.xmin = xmin | |
100 | self.xmax = xmax |
|
97 | self.xmax = xmax | |
101 | self.minvalue = minvalue |
|
98 | self.minvalue = minvalue | |
102 | self.maxvalue = maxvalue |
|
99 | self.maxvalue = maxvalue | |
103 |
|
100 | |||
104 | if self.xmin == None: self.xmin = numpy.min(x) |
|
101 | if self.xmin == None: self.xmin = numpy.min(x) | |
105 | if self.xmax == None: self.xmax = numpy.max(x) |
|
102 | if self.xmax == None: self.xmax = numpy.max(x) | |
106 | if self.minvalue == None: self.minvalue = numpy.min(data1D) |
|
103 | if self.minvalue == None: self.minvalue = numpy.min(data1D) | |
107 | if self.maxvalue == None: self.maxvalue = numpy.max(data1D) |
|
104 | if self.maxvalue == None: self.maxvalue = numpy.max(data1D) | |
108 |
|
105 | |||
109 | self.createFrames() |
|
106 | self.createFrames() | |
110 | self.__isConfig = True |
|
107 | self.__isConfig = True | |
111 |
|
108 | |||
112 | if not(self.__isOutOfXRange(x)): |
|
109 | if not(self.__isOutOfXRange(x)): | |
113 |
self. |
|
110 | self.changeXRange(x) | |
114 |
|
111 | |||
115 | if self.__isFigureOpen: |
|
112 | if self.__isFigureOpen: | |
116 | self.driverObj.closePage() |
|
113 | self.driverObj.closePage() | |
117 | self.__isFigureOpen = False |
|
114 | self.__isFigureOpen = False | |
118 |
|
115 | |||
119 |
|
116 | |||
120 | self.__initFigure() |
|
117 | self.__initFigure() | |
121 |
|
118 | |||
122 | for channel in channelList: |
|
119 | for channel in channelList: | |
123 | frameObj = self.frameObjList[channel] |
|
120 | frameObj = self.frameObjList[channel] | |
124 | frameObj.init(xmin=self.xmin, |
|
121 | frameObj.init(xmin=self.xmin, | |
125 | xmax=self.xmax, |
|
122 | xmax=self.xmax, | |
126 | ymin=self.minvalue, |
|
123 | ymin=self.minvalue, | |
127 | ymax=self.maxvalue, |
|
124 | ymax=self.maxvalue, | |
128 | minvalue=self.minvalue, |
|
125 | minvalue=self.minvalue, | |
129 | maxvalue=self.maxvalue) |
|
126 | maxvalue=self.maxvalue) | |
130 |
|
127 | |||
131 | for channel in channelList: |
|
128 | for channel in channelList: | |
132 | dataCh = data1D[channel,:] |
|
129 | dataCh = data1D[channel,:] | |
133 | frameObj = self.frameObjList[channel] |
|
130 | frameObj = self.frameObjList[channel] | |
134 | # frameObj.clearData() |
|
131 | # frameObj.clearData() | |
135 | frameObj.plot(x, dataCh) |
|
132 | frameObj.plot(x, dataCh) | |
136 |
|
133 | |||
137 | # frameObj.refresh() |
|
134 | # frameObj.refresh() | |
138 | self.__refresh() |
|
135 | self.__refresh() | |
139 |
|
136 | |||
140 |
|
137 | |||
141 | # |
|
138 | # | |
142 | # if save: |
|
139 | # if save: | |
143 | # self.colorplotObj.setFigure(indexPlot) |
|
140 | # self.colorplotObj.setFigure(indexPlot) | |
144 | # path = "/home/roj-idl71/tmp/" |
|
141 | # path = "/home/roj-idl71/tmp/" | |
145 | # now = datetime.datetime.now().timetuple() |
|
142 | # now = datetime.datetime.now().timetuple() | |
146 | # file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5]) |
|
143 | # file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5]) | |
147 | # filename = os.path.join(path,file) |
|
144 | # filename = os.path.join(path,file) | |
148 | # self.colorplotObj.savePlot(indexPlot, filename) |
|
145 | # self.colorplotObj.savePlot(indexPlot, filename) | |
149 | # |
|
146 | # | |
150 | # self.colorplotObj.closePage() |
|
147 | # self.colorplotObj.closePage() | |
151 |
|
148 | |||
152 |
|
149 | |||
153 | def plotPcolor(self,data, |
|
150 | def plotPcolor(self,data, | |
154 | x=None, |
|
151 | x=None, | |
155 | y=None, |
|
152 | y=None, | |
156 | channelList=None, |
|
153 | channelList=None, | |
157 | xmin=None, |
|
154 | xmin=None, | |
158 | xmax=None, |
|
155 | xmax=None, | |
159 | ymin=None, |
|
156 | ymin=None, | |
160 | ymax=None, |
|
157 | ymax=None, | |
161 | minvalue=None, |
|
158 | minvalue=None, | |
162 | maxvalue=None, |
|
159 | maxvalue=None, | |
163 | figuretitle=None, |
|
160 | figuretitle=None, | |
164 | xrangestep=None, |
|
161 | xrangestep=None, | |
165 | save=False, |
|
162 | save=False, | |
166 |
gpath='./' |
|
163 | gpath='./', | |
|
164 | clearData=False, | |||
|
165 | *args): | |||
167 |
|
166 | |||
168 |
|
167 | |||
169 | if figuretitle == None: |
|
168 | if figuretitle == None: | |
170 | self.figuretitle = "" |
|
169 | self.figuretitle = "" | |
171 | else: |
|
170 | else: | |
172 | self.figuretitle = figuretitle |
|
171 | self.figuretitle = figuretitle | |
173 |
|
172 | |||
174 |
|
173 | |||
175 |
|
174 | |||
176 | if not(self.__isDriverOpen): |
|
175 | if not(self.__isDriverOpen): | |
177 | self.__openDriver() |
|
176 | self.__openDriver() | |
178 | self.__isDriverOpen = True |
|
177 | self.__isDriverOpen = True | |
179 |
|
178 | |||
180 | if not(self.__isConfig): |
|
179 | if not(self.__isConfig): | |
181 |
|
180 | |||
182 | self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep) |
|
181 | self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep) | |
183 |
|
182 | |||
184 | self.createFrames() |
|
183 | self.createFrames() | |
185 | self.__isConfig = True |
|
184 | self.__isConfig = True | |
186 |
|
185 | |||
187 | if (self.__isOutOfXRange(x)): |
|
186 | if (self.__isOutOfXRange(x)): | |
188 |
|
187 | |||
189 | if not(self.changeXRange(x)): |
|
188 | if not(self.changeXRange(x)): | |
190 | return 0 |
|
189 | return 0 | |
191 |
|
190 | |||
192 | self.__isFigureOpen = False |
|
191 | self.__isFigureOpen = False | |
193 |
|
|
192 | ||
194 | # if self.__isFigureOpen: |
|
|||
195 | # self.driverObj.closePage() |
|
|||
196 | # self.__isFigureOpen = False |
|
|||
197 |
|
||||
198 | if not(self.__isFigureOpen): |
|
193 | if not(self.__isFigureOpen): | |
199 |
|
194 | |||
200 |
|
195 | |||
201 | self.__initFigure() |
|
196 | self.__initFigure() | |
202 | self.__isFigureOpen = True |
|
197 | self.__isFigureOpen = True | |
203 |
|
198 | |||
204 | for channel in channelList: |
|
199 | for channel in channelList: | |
|
200 | if len(args) != 0: value = args[0][channel] | |||
|
201 | else: value = args | |||
|
202 | ||||
205 | frameObj = self.frameObjList[channel] |
|
203 | frameObj = self.frameObjList[channel] | |
206 |
frameObj.init( |
|
204 | frameObj.init(self.xmin, | |
207 |
|
|
205 | self.xmax, | |
208 |
|
|
206 | self.ymin, | |
209 |
|
|
207 | self.ymax, | |
210 |
|
|
208 | self.minvalue, | |
211 |
|
|
209 | self.maxvalue, | |
212 |
|
|
210 | self.deltax, | |
213 |
|
|
211 | self.deltay, | |
|
212 | self.colorbar, | |||
|
213 | value) | |||
214 |
|
214 | |||
215 | for channel in channelList: |
|
215 | for channel in channelList: | |
216 | dataCh = data[channel,:] |
|
216 | dataCh = data[channel,:] | |
217 | frameObj = self.frameObjList[channel] |
|
217 | frameObj = self.frameObjList[channel] | |
218 | # frameObj.clearData() |
|
|||
219 | frameObj.plot(x, y, dataCh) |
|
218 | frameObj.plot(x, y, dataCh) | |
220 |
|
219 | |||
221 | # frameObj.refresh() |
|
220 | ||
222 | self.__refresh() |
|
221 | self.__refresh() | |
|
222 | if clearData == True: | |||
|
223 | self.__isFigureOpen = False | |||
223 |
|
224 | |||
224 |
|
225 | |||
225 |
|
226 | |||
226 | class Frame: |
|
227 | class Frame: | |
227 | nplots = None |
|
228 | nplots = None | |
228 | plotObjList = [] |
|
229 | plotObjList = [] | |
229 | title = "" |
|
230 | title = "" | |
230 |
|
231 | |||
231 | def __init__(self,drvObj, idframe): |
|
232 | def __init__(self,drvObj, idframe): | |
232 | self.drvObj = drvObj |
|
233 | self.drvObj = drvObj | |
233 | self.idframe = idframe |
|
234 | self.idframe = idframe | |
234 | self.createPlots() |
|
235 | self.createPlots() | |
235 |
|
236 | |||
236 | def createPlots(self): |
|
237 | def createPlots(self): | |
237 | raise ValueError, "No implemented" |
|
238 | raise ValueError, "No implemented" | |
238 |
|
239 | |||
239 | def getScreenPosMainPlot(self): |
|
240 | def getScreenPosMainPlot(self): | |
240 | raise ValueError, "No implemented" |
|
241 | raise ValueError, "No implemented" | |
241 |
|
242 | |||
242 | def getScreenPosGraph1(self): |
|
243 | def getScreenPosGraph1(self): | |
243 | raise ValueError, "No implemented" |
|
244 | raise ValueError, "No implemented" | |
244 |
|
245 | |||
245 | def getScreenPos(self, nplot): |
|
246 | def getScreenPos(self, nplot): | |
246 |
|
247 | |||
247 | if nplot == 0: |
|
248 | if nplot == 0: | |
248 | xi, yi, xw, yw = self.getScreenPosMainPlot() |
|
249 | xi, yi, xw, yw = self.getScreenPosMainPlot() | |
249 |
|
250 | |||
250 | if nplot == 1: |
|
251 | if nplot == 1: | |
251 | xi, yi, xw, yw = self.getScreenPosGraph1() |
|
252 | xi, yi, xw, yw = self.getScreenPosGraph1() | |
252 |
|
253 | |||
253 | return xi, yi, xw, yw |
|
254 | return xi, yi, xw, yw | |
254 |
|
255 | |||
255 |
|
256 | |||
256 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None): |
|
257 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args): | |
257 |
|
258 | |||
258 | for plotObj in self.plotObjList: |
|
259 | for plotObj in self.plotObjList: | |
259 |
plotObj. |
|
260 | plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args) | |
|
261 | plotObj.plotBox() | |||
|
262 | ||||
260 |
|
263 | |||
261 |
|
264 | |||
262 | class Plot: |
|
265 | class Plot: | |
263 | title = "" |
|
266 | title = "" | |
264 | xlabel = "" |
|
267 | xlabel = "" | |
265 | ylabel = "" |
|
268 | ylabel = "" | |
266 | xaxisastime = None |
|
269 | xaxisastime = None | |
267 | timefmt = None |
|
270 | timefmt = None | |
268 | xopt = "" |
|
271 | xopt = "" | |
269 | yopt = "" |
|
272 | yopt = "" | |
270 | xpos = None |
|
273 | xpos = None | |
271 | ypos = None |
|
274 | ypos = None | |
272 | szchar = None |
|
275 | szchar = None | |
273 | idframe = None |
|
276 | idframe = None | |
274 | idplot = None |
|
277 | idplot = None | |
|
278 | colorbar = None | |||
|
279 | cbxpos = None | |||
|
280 | cbypos = None | |||
275 |
|
281 | |||
276 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): |
|
282 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): | |
277 | self.drvObj = drvObj |
|
283 | self.drvObj = drvObj | |
278 | self.idframe = idframe |
|
284 | self.idframe = idframe | |
279 | self.idplot = idplot |
|
285 | self.idplot = idplot | |
280 | self.xi = xi |
|
286 | self.xi = xi | |
281 | self.yi = yi |
|
287 | self.yi = yi | |
282 | self.xw = xw |
|
288 | self.xw = xw | |
283 | self.yw = yw |
|
289 | self.yw = yw | |
284 |
|
290 | |||
285 | def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): |
|
291 | ||
286 | self.xmin = xmin |
|
292 | def plotBox(self): | |
287 | self.xmax = xmax |
|
|||
288 | self.ymin = ymin |
|
|||
289 | self.ymax = ymax |
|
|||
290 | self.minvalue = minvalue |
|
|||
291 | self.maxvalue = maxvalue |
|
|||
292 |
|
293 | |||
293 | self.drvObj.driver.plotBox(self.idframe, |
|
294 | self.drvObj.driver.plotBox(self.idframe, | |
294 | self.xpos, |
|
295 | self.xpos, | |
295 | self.ypos, |
|
296 | self.ypos, | |
296 | self.xmin, |
|
297 | self.xmin, | |
297 | self.xmax, |
|
298 | self.xmax, | |
298 | self.ymin, |
|
299 | self.ymin, | |
299 | self.ymax, |
|
300 | self.ymax, | |
300 | self.minvalue, |
|
301 | self.minvalue, | |
301 | self.maxvalue, |
|
302 | self.maxvalue, | |
302 | self.xopt, |
|
303 | self.xopt, | |
303 | self.yopt, |
|
304 | self.yopt, | |
304 | self.szchar, |
|
305 | self.szchar, | |
305 | self.xaxisastime, |
|
306 | self.xaxisastime, | |
306 | self.timefmt) |
|
307 | self.timefmt) | |
307 |
|
308 | |||
308 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) |
|
309 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) | |
309 |
|
310 | |||
|
311 | if self.colorbar: | |||
|
312 | self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos) | |||
|
313 | ||||
310 | def plotPcolor(self, x, y, z, deltax, deltay, getGrid): |
|
314 | def plotPcolor(self, x, y, z, deltax, deltay, getGrid): | |
311 |
|
315 | |||
312 | self.drvObj.driver.pcolor(self.idframe, |
|
316 | self.drvObj.driver.pcolor(self.idframe, | |
313 | self.xpos, |
|
317 | self.xpos, | |
314 | self.ypos, |
|
318 | self.ypos, | |
315 | z, |
|
319 | z, | |
316 | x, |
|
320 | x, | |
317 | y, |
|
321 | y, | |
318 | self.xmin, |
|
322 | self.xmin, | |
319 | self.xmax, |
|
323 | self.xmax, | |
320 | self.ymin, |
|
324 | self.ymin, | |
321 | self.ymax, |
|
325 | self.ymax, | |
322 | self.minvalue, |
|
326 | self.minvalue, | |
323 | self.maxvalue, |
|
327 | self.maxvalue, | |
324 | deltax, |
|
328 | deltax, | |
325 | deltay, |
|
329 | deltay, | |
326 | getGrid, |
|
330 | getGrid, | |
327 | self.xaxisastime, |
|
331 | self.xaxisastime, | |
328 | self.timefmt) |
|
332 | self.timefmt) | |
329 |
|
333 | |||
330 | def plotBasicLine(self,x, y, color): |
|
334 | def plotBasicLine(self,x, y, color): | |
331 | """ |
|
335 | """ | |
332 | Inputs: |
|
336 | Inputs: | |
333 | x: |
|
337 | x: | |
334 |
|
338 | |||
335 | y: |
|
339 | y: | |
336 |
|
340 | |||
337 | color: |
|
341 | color: | |
338 | """ |
|
342 | """ | |
339 | self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color) |
|
343 | self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color) | |
340 | No newline at end of file |
|
344 |
@@ -1,412 +1,415 | |||||
1 | import plplot |
|
1 | import plplot | |
2 | import numpy |
|
2 | import numpy | |
3 | import sys |
|
3 | import sys | |
4 | import plplot #condicional |
|
4 | import plplot #condicional | |
5 |
|
5 | |||
6 | class Driver: |
|
6 | class Driver: | |
7 | def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): |
|
7 | def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): | |
8 | if driver == "plplot": |
|
8 | if driver == "plplot": | |
9 | self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) |
|
9 | self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) | |
10 | elif driver == "mpl": |
|
10 | elif driver == "mpl": | |
11 | self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) |
|
11 | self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) | |
12 | else: |
|
12 | else: | |
13 | raise ValueError, "The driver: %s is not defined"%driver |
|
13 | raise ValueError, "The driver: %s is not defined"%driver | |
14 |
|
14 | |||
15 | class PlplotDriver: |
|
15 | class PlplotDriver: | |
16 |
|
16 | |||
17 | __isDriverOpen = False |
|
17 | __isDriverOpen = False | |
18 | pldriver = None |
|
18 | pldriver = None | |
19 | __xg = None |
|
19 | __xg = None | |
20 | __yg = None |
|
20 | __yg = None | |
21 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): |
|
21 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): | |
22 |
|
22 | |||
23 | if idfigure == None: |
|
23 | if idfigure == None: | |
24 | raise ValueError, 'idfigure input must be defined' |
|
24 | raise ValueError, 'idfigure input must be defined' | |
25 |
|
25 | |||
26 | self.idfigure = idfigure |
|
26 | self.idfigure = idfigure | |
27 | self.xw = xw |
|
27 | self.xw = xw | |
28 | self.yw = yw |
|
28 | self.yw = yw | |
29 | self.wintitle = wintitle |
|
29 | self.wintitle = wintitle | |
30 | self.overplot = overplot |
|
30 | self.overplot = overplot | |
31 | self.colormap = colormap |
|
31 | self.colormap = colormap | |
32 | self.colorbar = colorbar |
|
32 | self.colorbar = colorbar | |
33 |
|
33 | |||
34 | def setFigure(self): |
|
34 | def setFigure(self): | |
35 | """ |
|
35 | """ | |
36 | previous configuration to open(init) the plplot driver |
|
36 | previous configuration to open(init) the plplot driver | |
37 | """ |
|
37 | """ | |
38 | plplot.plsstrm(self.idfigure) |
|
38 | plplot.plsstrm(self.idfigure) | |
39 | plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL) |
|
39 | plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL) | |
40 | plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw)) |
|
40 | plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw)) | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | def openDriver(self, pldriver=None): |
|
43 | def openDriver(self, pldriver=None): | |
44 | if pldriver == None: |
|
44 | if pldriver == None: | |
45 | if sys.platform == "linux": |
|
45 | if sys.platform == "linux": | |
46 | pldriver = "xcairo" |
|
46 | pldriver = "xcairo" | |
47 |
|
47 | |||
48 | if sys.platform == "linux2": |
|
48 | if sys.platform == "linux2": | |
49 | pldriver = "xcairo" |
|
49 | pldriver = "xcairo" | |
50 |
|
50 | |||
51 | elif sys.platform == "darwin": |
|
51 | elif sys.platform == "darwin": | |
52 | pldriver = "xwin" |
|
52 | pldriver = "xwin" | |
53 |
|
53 | |||
54 | else: |
|
54 | else: | |
55 | pldriver = "" |
|
55 | pldriver = "" | |
56 |
|
56 | |||
57 | plplot.plsdev("xwin") #para pruebas |
|
57 | plplot.plsdev("xwin") #para pruebas | |
58 | plplot.plscolbg(255,255,255) |
|
58 | plplot.plscolbg(255,255,255) | |
59 | plplot.plscol0(1,0,0,0) |
|
59 | plplot.plscol0(1,0,0,0) | |
60 | plplot.plinit() |
|
60 | plplot.plinit() | |
61 | plplot.plspause(False) |
|
61 | plplot.plspause(False) | |
62 |
|
62 | |||
63 | self.pldriver = pldriver |
|
63 | self.pldriver = pldriver | |
64 |
|
64 | |||
65 | def closeDriver(self): |
|
65 | def closeDriver(self): | |
66 | pass |
|
66 | pass | |
67 |
|
67 | |||
68 | def openPage(self): |
|
68 | def openPage(self): | |
69 | plplot.plbop() |
|
69 | plplot.plbop() | |
70 | plplot.pladv(0) |
|
70 | plplot.pladv(0) | |
71 |
|
71 | |||
72 | def closePage(self): |
|
72 | def closePage(self): | |
73 | plplot.pleop() |
|
73 | plplot.pleop() | |
74 |
|
74 | |||
75 | def openFigure(self): |
|
75 | def openFigure(self): | |
76 | plplot.plbop() |
|
76 | plplot.plbop() | |
77 | plplot.pladv(0) |
|
77 | plplot.pladv(0) | |
78 |
|
78 | |||
79 | def closeFigure(self): |
|
79 | def closeFigure(self): | |
80 | plplot.pleop() |
|
80 | plplot.pleop() | |
81 |
|
81 | |||
82 | def setSubPlots(self,nrows, ncolumns): |
|
82 | def setSubPlots(self,nrows, ncolumns): | |
83 | plplot.plssub(ncolumns,nrows) |
|
83 | plplot.plssub(ncolumns,nrows) | |
84 |
|
84 | |||
85 | def setPlotLabels(self, xlabel, ylabel, title): |
|
85 | def setPlotLabels(self, xlabel, ylabel, title): | |
86 | plplot.pllab(xlabel, ylabel, title) |
|
86 | plplot.pllab(xlabel, ylabel, title) | |
87 |
|
87 | |||
88 | def setFigTitle(self, title,color="black", szchar=0.55): |
|
88 | def setFigTitle(self, title,color="black", szchar=0.55): | |
89 | self.setSubPlots(1, 0) |
|
89 | self.setSubPlots(1, 0) | |
90 | plplot.pladv(0) |
|
90 | plplot.pladv(0) | |
91 | plplot.plvpor(0., 1., 0., 1.) |
|
91 | plplot.plvpor(0., 1., 0., 1.) | |
92 |
|
92 | |||
93 | if color == "black": |
|
93 | if color == "black": | |
94 | plplot.plcol0(1) |
|
94 | plplot.plcol0(1) | |
95 | if color == "white": |
|
95 | if color == "white": | |
96 | plplot.plcol0(15) |
|
96 | plplot.plcol0(15) | |
97 |
|
97 | |||
98 | plplot.plschr(0.0,szchar) |
|
98 | plplot.plschr(0.0,szchar) | |
99 | plplot.plmtex("t",-1., 0.5, 0.5, title) |
|
99 | plplot.plmtex("t",-1., 0.5, 0.5, title) | |
100 |
|
100 | |||
101 | def plotColorbar(self, minvalue, maxvalue, xpos, ypos): |
|
101 | def plotColorbar(self, minvalue, maxvalue, xpos, ypos): | |
102 | # plplot.pladv(id) |
|
102 | # plplot.pladv(id) | |
103 | # plplot.plschr(0.0,szchar-0.05) |
|
103 | # plplot.plschr(0.0,szchar-0.05) | |
104 | xmin = 0; xmax = 1 |
|
104 | xmin = 0; xmax = 1 | |
105 | ymin = minvalue; ymax = maxvalue |
|
105 | ymin = minvalue; ymax = maxvalue | |
106 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
106 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
107 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) |
|
107 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) | |
108 | plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0) |
|
108 | plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0) | |
109 |
|
109 | |||
110 | data = numpy.arange(256) |
|
110 | data = numpy.arange(256) | |
111 | data = numpy.reshape(data, (1,-1)) |
|
111 | data = numpy.reshape(data, (1,-1)) | |
112 |
|
112 | |||
113 | plplot.plimage(data, |
|
113 | plplot.plimage(data, | |
114 | float(xmin), |
|
114 | float(xmin), | |
115 | float(xmax), |
|
115 | float(xmax), | |
116 | float(ymin), |
|
116 | float(ymin), | |
117 | float(ymax), |
|
117 | float(ymax), | |
118 | 0., |
|
118 | 0., | |
119 | 255., |
|
119 | 255., | |
120 | float(xmin), |
|
120 | float(xmin), | |
121 | float(xmax), |
|
121 | float(xmax), | |
122 | float(ymin), |
|
122 | float(ymin), | |
123 | float(ymax)) |
|
123 | float(ymax)) | |
124 |
|
124 | |||
125 |
|
125 | |||
126 | def __getGrid(self, x, y, deltax=None, deltay=None): |
|
126 | def __getGrid(self, x, y, deltax=None, deltay=None): | |
127 |
|
127 | |||
128 | if not(len(x)>0 and len(y)>0): |
|
128 | if not(len(x)>0 and len(y)>0): | |
129 | raise ValueError, "x axis and y axis are empty" |
|
129 | raise ValueError, "x axis and y axis are empty" | |
130 |
|
130 | |||
131 | if deltax == None: deltax = x[-1] - x[-2] |
|
131 | if deltax == None: deltax = x[-1] - x[-2] | |
132 | if deltay == None: deltay = y[-1] - y[-2] |
|
132 | if deltay == None: deltay = y[-1] - y[-2] | |
133 |
|
133 | |||
134 | x1 = numpy.append(x, x[-1] + deltax) |
|
134 | x1 = numpy.append(x, x[-1] + deltax) | |
135 | y1 = numpy.append(y, y[-1] + deltay) |
|
135 | y1 = numpy.append(y, y[-1] + deltay) | |
136 |
|
136 | |||
137 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
137 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
138 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
138 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
139 |
|
139 | |||
140 | return xg, yg |
|
140 | return xg, yg | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"): |
|
143 | def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"): | |
144 |
|
144 | |||
145 | plplot.pladv(id) |
|
145 | plplot.pladv(id) | |
146 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
146 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
147 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) |
|
147 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) | |
148 |
|
148 | |||
149 | if xaxisastime: |
|
149 | if xaxisastime: | |
150 | timedelta = (xmax - xmin + 1)/8. |
|
150 | timedelta = (xmax - xmin + 1)/8. | |
151 |
|
151 | |||
152 | if getGrid: |
|
152 | if getGrid: | |
153 | self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay) |
|
153 | self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay) | |
154 |
|
154 | |||
|
155 | if deltax == None: deltax = x[-1] - x[0] | |||
|
156 | # if deltay == None: deltay = y[-1] - y[-2] | |||
|
157 | ||||
155 | xmin = x[0] |
|
158 | xmin = x[0] | |
156 | xmax = xmin + deltax |
|
159 | xmax = xmin + deltax | |
157 |
|
160 | |||
158 | plplot.plimagefr(data, |
|
161 | plplot.plimagefr(data, | |
159 | float(xmin), |
|
162 | float(xmin), | |
160 | float(xmax), |
|
163 | float(xmax), | |
161 | float(ymin), |
|
164 | float(ymin), | |
162 | float(ymax), |
|
165 | float(ymax), | |
163 | 0., |
|
166 | 0., | |
164 | 0., |
|
167 | 0., | |
165 | float(zmin), |
|
168 | float(zmin), | |
166 | float(zmax), |
|
169 | float(zmax), | |
167 | plplot.pltr2, |
|
170 | plplot.pltr2, | |
168 | self.__xg, |
|
171 | self.__xg, | |
169 | self.__yg) |
|
172 | self.__yg) | |
170 |
|
173 | |||
171 | if xaxisastime: |
|
174 | if xaxisastime: | |
172 | plplot.pltimefmt(timefmt) |
|
175 | plplot.pltimefmt(timefmt) | |
173 | xopt = "bcstd" |
|
176 | xopt = "bcstd" | |
174 | yopt = "bcst" |
|
177 | yopt = "bcst" | |
175 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) |
|
178 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | |
176 | else: |
|
179 | else: | |
177 | xopt = "bcst" |
|
180 | xopt = "bcst" | |
178 | yopt = "bcst" |
|
181 | yopt = "bcst" | |
179 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
182 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |
180 |
|
183 | |||
181 |
|
184 | |||
182 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): |
|
185 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): | |
183 | """ |
|
186 | """ | |
184 | xopt, yopt: entradas que no se aplican en MPL |
|
187 | xopt, yopt: entradas que no se aplican en MPL | |
185 | """ |
|
188 | """ | |
186 | plplot.pladv(id) |
|
189 | plplot.pladv(id) | |
187 | plplot.plschr(0.0,szchar-0.05) |
|
190 | plplot.plschr(0.0,szchar-0.05) | |
188 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
191 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
189 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) |
|
192 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) | |
190 | if xaxisastime: |
|
193 | if xaxisastime: | |
191 | plplot.pltimefmt(timefmt) |
|
194 | plplot.pltimefmt(timefmt) | |
192 | timedelta = (xmax - xmin + 1)/8. |
|
195 | timedelta = (xmax - xmin + 1)/8. | |
193 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) |
|
196 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | |
194 | else: |
|
197 | else: | |
195 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
198 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |
196 |
|
199 | |||
197 | def refresh(self): |
|
200 | def refresh(self): | |
198 | plplot.plflush() |
|
201 | plplot.plflush() | |
199 |
|
202 | |||
200 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): |
|
203 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): | |
201 |
|
204 | |||
202 | """ |
|
205 | """ | |
203 | Inputs: |
|
206 | Inputs: | |
204 | x: datos en el eje x |
|
207 | x: datos en el eje x | |
205 |
|
208 | |||
206 | y: datos en el eje y |
|
209 | y: datos en el eje y | |
207 |
|
210 | |||
208 | xmin, xmax: intervalo de datos en el eje x |
|
211 | xmin, xmax: intervalo de datos en el eje x | |
209 |
|
212 | |||
210 | ymin, ymax: intervalo de datos en el eje y |
|
213 | ymin, ymax: intervalo de datos en el eje y | |
211 |
|
214 | |||
212 | color: color de la linea a dibujarse |
|
215 | color: color de la linea a dibujarse | |
213 |
|
216 | |||
214 | id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada |
|
217 | id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada | |
215 | plot esta definido por xpos, ypos. |
|
218 | plot esta definido por xpos, ypos. | |
216 |
|
219 | |||
217 | xpos,ypos: coordenadas que indican la posicion del plot en el frame |
|
220 | xpos,ypos: coordenadas que indican la posicion del plot en el frame | |
218 |
|
221 | |||
219 | """ |
|
222 | """ | |
220 |
|
223 | |||
221 | plplot.pladv(id) |
|
224 | plplot.pladv(id) | |
222 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
225 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
223 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) |
|
226 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) | |
224 |
|
227 | |||
225 | if color == "blue": |
|
228 | if color == "blue": | |
226 | colline = 9 |
|
229 | colline = 9 | |
227 | if color == "green": |
|
230 | if color == "green": | |
228 | colline = 3 |
|
231 | colline = 3 | |
229 |
|
232 | |||
230 | plplot.plcol0(colline) |
|
233 | plplot.plcol0(colline) | |
231 | plplot.plline(x, y) |
|
234 | plplot.plline(x, y) | |
232 | plplot.plcol0(1) |
|
235 | plplot.plcol0(1) | |
233 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) |
|
236 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) | |
234 |
|
237 | |||
235 | def setColormap(self, colormap="gray"): |
|
238 | def setColormap(self, colormap="gray"): | |
236 |
|
239 | |||
237 | if colormap == None: |
|
240 | if colormap == None: | |
238 | return |
|
241 | return | |
239 |
|
242 | |||
240 | ncolor = None |
|
243 | ncolor = None | |
241 | rgb_lvl = None |
|
244 | rgb_lvl = None | |
242 |
|
245 | |||
243 | # Routine for defining a specific color map 1 in HLS space. |
|
246 | # Routine for defining a specific color map 1 in HLS space. | |
244 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
247 | # if gray is true, use basic grayscale variation from half-dark to light. | |
245 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
248 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |
246 |
|
249 | |||
247 | # Independent variable of control points. |
|
250 | # Independent variable of control points. | |
248 | i = numpy.array((0., 1.)) |
|
251 | i = numpy.array((0., 1.)) | |
249 | if colormap=="gray": |
|
252 | if colormap=="gray": | |
250 | ncolor = 256 |
|
253 | ncolor = 256 | |
251 | # Hue for control points. Doesn't matter since saturation is zero. |
|
254 | # Hue for control points. Doesn't matter since saturation is zero. | |
252 | h = numpy.array((0., 0.)) |
|
255 | h = numpy.array((0., 0.)) | |
253 | # Lightness ranging from half-dark (for interest) to light. |
|
256 | # Lightness ranging from half-dark (for interest) to light. | |
254 | l = numpy.array((0.5, 1.)) |
|
257 | l = numpy.array((0.5, 1.)) | |
255 | # Gray scale has zero saturation |
|
258 | # Gray scale has zero saturation | |
256 | s = numpy.array((0., 0.)) |
|
259 | s = numpy.array((0., 0.)) | |
257 |
|
260 | |||
258 | # number of cmap1 colours is 256 in this case. |
|
261 | # number of cmap1 colours is 256 in this case. | |
259 | plplot.plscmap1n(ncolor) |
|
262 | plplot.plscmap1n(ncolor) | |
260 | # Interpolate between control points to set up cmap1. |
|
263 | # Interpolate between control points to set up cmap1. | |
261 | plplot.plscmap1l(0, i, h, l, s) |
|
264 | plplot.plscmap1l(0, i, h, l, s) | |
262 |
|
265 | |||
263 | return None |
|
266 | return None | |
264 |
|
267 | |||
265 | if colormap == 'jet': |
|
268 | if colormap == 'jet': | |
266 | ncolor = 256 |
|
269 | ncolor = 256 | |
267 | pos = numpy.zeros((ncolor)) |
|
270 | pos = numpy.zeros((ncolor)) | |
268 | r = numpy.zeros((ncolor)) |
|
271 | r = numpy.zeros((ncolor)) | |
269 | g = numpy.zeros((ncolor)) |
|
272 | g = numpy.zeros((ncolor)) | |
270 | b = numpy.zeros((ncolor)) |
|
273 | b = numpy.zeros((ncolor)) | |
271 |
|
274 | |||
272 | for i in range(ncolor): |
|
275 | for i in range(ncolor): | |
273 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 |
|
276 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 | |
274 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 |
|
277 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 | |
275 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 |
|
278 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 | |
276 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 |
|
279 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 | |
277 |
|
280 | |||
278 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 |
|
281 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 | |
279 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 |
|
282 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 | |
280 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 |
|
283 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 | |
281 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 |
|
284 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 | |
282 | else: gf = 0.0 |
|
285 | else: gf = 0.0 | |
283 |
|
286 | |||
284 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 |
|
287 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 | |
285 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 |
|
288 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 | |
286 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 |
|
289 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 | |
287 | else: bf = 0 |
|
290 | else: bf = 0 | |
288 |
|
291 | |||
289 | r[i] = rf |
|
292 | r[i] = rf | |
290 | g[i] = gf |
|
293 | g[i] = gf | |
291 | b[i] = bf |
|
294 | b[i] = bf | |
292 |
|
295 | |||
293 | pos[i] = float(i)/float(ncolor-1) |
|
296 | pos[i] = float(i)/float(ncolor-1) | |
294 |
|
297 | |||
295 |
|
298 | |||
296 | plplot.plscmap1n(ncolor) |
|
299 | plplot.plscmap1n(ncolor) | |
297 | plplot.plscmap1l(1, pos, r, g, b) |
|
300 | plplot.plscmap1l(1, pos, r, g, b) | |
298 |
|
301 | |||
299 |
|
302 | |||
300 |
|
303 | |||
301 | if colormap=="br_green": |
|
304 | if colormap=="br_green": | |
302 | ncolor = 256 |
|
305 | ncolor = 256 | |
303 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
306 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
304 | h = numpy.array((240., 0.)) |
|
307 | h = numpy.array((240., 0.)) | |
305 | # Lightness and saturation are constant (values taken from C example). |
|
308 | # Lightness and saturation are constant (values taken from C example). | |
306 | l = numpy.array((0.6, 0.6)) |
|
309 | l = numpy.array((0.6, 0.6)) | |
307 | s = numpy.array((0.8, 0.8)) |
|
310 | s = numpy.array((0.8, 0.8)) | |
308 |
|
311 | |||
309 | # number of cmap1 colours is 256 in this case. |
|
312 | # number of cmap1 colours is 256 in this case. | |
310 | plplot.plscmap1n(ncolor) |
|
313 | plplot.plscmap1n(ncolor) | |
311 | # Interpolate between control points to set up cmap1. |
|
314 | # Interpolate between control points to set up cmap1. | |
312 | plplot.plscmap1l(0, i, h, l, s) |
|
315 | plplot.plscmap1l(0, i, h, l, s) | |
313 |
|
316 | |||
314 | return None |
|
317 | return None | |
315 |
|
318 | |||
316 | if colormap=="tricolor": |
|
319 | if colormap=="tricolor": | |
317 | ncolor = 3 |
|
320 | ncolor = 3 | |
318 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
321 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
319 | h = numpy.array((240., 0.)) |
|
322 | h = numpy.array((240., 0.)) | |
320 | # Lightness and saturation are constant (values taken from C example). |
|
323 | # Lightness and saturation are constant (values taken from C example). | |
321 | l = numpy.array((0.6, 0.6)) |
|
324 | l = numpy.array((0.6, 0.6)) | |
322 | s = numpy.array((0.8, 0.8)) |
|
325 | s = numpy.array((0.8, 0.8)) | |
323 |
|
326 | |||
324 | # number of cmap1 colours is 256 in this case. |
|
327 | # number of cmap1 colours is 256 in this case. | |
325 | plplot.plscmap1n(ncolor) |
|
328 | plplot.plscmap1n(ncolor) | |
326 | # Interpolate between control points to set up cmap1. |
|
329 | # Interpolate between control points to set up cmap1. | |
327 | plplot.plscmap1l(0, i, h, l, s) |
|
330 | plplot.plscmap1l(0, i, h, l, s) | |
328 |
|
331 | |||
329 | return None |
|
332 | return None | |
330 |
|
333 | |||
331 | if colormap == 'rgb' or colormap == 'rgb666': |
|
334 | if colormap == 'rgb' or colormap == 'rgb666': | |
332 |
|
335 | |||
333 | color_sz = 6 |
|
336 | color_sz = 6 | |
334 | ncolor = color_sz*color_sz*color_sz |
|
337 | ncolor = color_sz*color_sz*color_sz | |
335 | pos = numpy.zeros((ncolor)) |
|
338 | pos = numpy.zeros((ncolor)) | |
336 | r = numpy.zeros((ncolor)) |
|
339 | r = numpy.zeros((ncolor)) | |
337 | g = numpy.zeros((ncolor)) |
|
340 | g = numpy.zeros((ncolor)) | |
338 | b = numpy.zeros((ncolor)) |
|
341 | b = numpy.zeros((ncolor)) | |
339 | ind = 0 |
|
342 | ind = 0 | |
340 | for ri in range(color_sz): |
|
343 | for ri in range(color_sz): | |
341 | for gi in range(color_sz): |
|
344 | for gi in range(color_sz): | |
342 | for bi in range(color_sz): |
|
345 | for bi in range(color_sz): | |
343 | r[ind] = ri/(color_sz-1.0) |
|
346 | r[ind] = ri/(color_sz-1.0) | |
344 | g[ind] = gi/(color_sz-1.0) |
|
347 | g[ind] = gi/(color_sz-1.0) | |
345 | b[ind] = bi/(color_sz-1.0) |
|
348 | b[ind] = bi/(color_sz-1.0) | |
346 | pos[ind] = ind/(ncolor-1.0) |
|
349 | pos[ind] = ind/(ncolor-1.0) | |
347 | ind += 1 |
|
350 | ind += 1 | |
348 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
351 | rgb_lvl = [6,6,6] #Levels for RGB colors | |
349 |
|
352 | |||
350 | if colormap == 'rgb676': |
|
353 | if colormap == 'rgb676': | |
351 | ncolor = 6*7*6 |
|
354 | ncolor = 6*7*6 | |
352 | pos = numpy.zeros((ncolor)) |
|
355 | pos = numpy.zeros((ncolor)) | |
353 | r = numpy.zeros((ncolor)) |
|
356 | r = numpy.zeros((ncolor)) | |
354 | g = numpy.zeros((ncolor)) |
|
357 | g = numpy.zeros((ncolor)) | |
355 | b = numpy.zeros((ncolor)) |
|
358 | b = numpy.zeros((ncolor)) | |
356 | ind = 0 |
|
359 | ind = 0 | |
357 | for ri in range(8): |
|
360 | for ri in range(8): | |
358 | for gi in range(8): |
|
361 | for gi in range(8): | |
359 | for bi in range(4): |
|
362 | for bi in range(4): | |
360 | r[ind] = ri/(6-1.0) |
|
363 | r[ind] = ri/(6-1.0) | |
361 | g[ind] = gi/(7-1.0) |
|
364 | g[ind] = gi/(7-1.0) | |
362 | b[ind] = bi/(6-1.0) |
|
365 | b[ind] = bi/(6-1.0) | |
363 | pos[ind] = ind/(ncolor-1.0) |
|
366 | pos[ind] = ind/(ncolor-1.0) | |
364 | ind += 1 |
|
367 | ind += 1 | |
365 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
368 | rgb_lvl = [6,7,6] #Levels for RGB colors | |
366 |
|
369 | |||
367 | if colormap == 'rgb685': |
|
370 | if colormap == 'rgb685': | |
368 | ncolor = 6*8*5 |
|
371 | ncolor = 6*8*5 | |
369 | pos = numpy.zeros((ncolor)) |
|
372 | pos = numpy.zeros((ncolor)) | |
370 | r = numpy.zeros((ncolor)) |
|
373 | r = numpy.zeros((ncolor)) | |
371 | g = numpy.zeros((ncolor)) |
|
374 | g = numpy.zeros((ncolor)) | |
372 | b = numpy.zeros((ncolor)) |
|
375 | b = numpy.zeros((ncolor)) | |
373 | ind = 0 |
|
376 | ind = 0 | |
374 | for ri in range(8): |
|
377 | for ri in range(8): | |
375 | for gi in range(8): |
|
378 | for gi in range(8): | |
376 | for bi in range(4): |
|
379 | for bi in range(4): | |
377 | r[ind] = ri/(6-1.0) |
|
380 | r[ind] = ri/(6-1.0) | |
378 | g[ind] = gi/(8-1.0) |
|
381 | g[ind] = gi/(8-1.0) | |
379 | b[ind] = bi/(5-1.0) |
|
382 | b[ind] = bi/(5-1.0) | |
380 | pos[ind] = ind/(ncolor-1.0) |
|
383 | pos[ind] = ind/(ncolor-1.0) | |
381 | ind += 1 |
|
384 | ind += 1 | |
382 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
385 | rgb_lvl = [6,8,5] #Levels for RGB colors | |
383 |
|
386 | |||
384 | if colormap == 'rgb884': |
|
387 | if colormap == 'rgb884': | |
385 | ncolor = 8*8*4 |
|
388 | ncolor = 8*8*4 | |
386 | pos = numpy.zeros((ncolor)) |
|
389 | pos = numpy.zeros((ncolor)) | |
387 | r = numpy.zeros((ncolor)) |
|
390 | r = numpy.zeros((ncolor)) | |
388 | g = numpy.zeros((ncolor)) |
|
391 | g = numpy.zeros((ncolor)) | |
389 | b = numpy.zeros((ncolor)) |
|
392 | b = numpy.zeros((ncolor)) | |
390 | ind = 0 |
|
393 | ind = 0 | |
391 | for ri in range(8): |
|
394 | for ri in range(8): | |
392 | for gi in range(8): |
|
395 | for gi in range(8): | |
393 | for bi in range(4): |
|
396 | for bi in range(4): | |
394 | r[ind] = ri/(8-1.0) |
|
397 | r[ind] = ri/(8-1.0) | |
395 | g[ind] = gi/(8-1.0) |
|
398 | g[ind] = gi/(8-1.0) | |
396 | b[ind] = bi/(4-1.0) |
|
399 | b[ind] = bi/(4-1.0) | |
397 | pos[ind] = ind/(ncolor-1.0) |
|
400 | pos[ind] = ind/(ncolor-1.0) | |
398 | ind += 1 |
|
401 | ind += 1 | |
399 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
402 | rgb_lvl = [8,8,4] #Levels for RGB colors | |
400 |
|
403 | |||
401 | if ncolor == None: |
|
404 | if ncolor == None: | |
402 | raise ValueError, "The colormap selected is not valid" |
|
405 | raise ValueError, "The colormap selected is not valid" | |
403 |
|
406 | |||
404 | plplot.plscmap1n(ncolor) |
|
407 | plplot.plscmap1n(ncolor) | |
405 | plplot.plscmap1l(1, pos, r, g, b) |
|
408 | plplot.plscmap1l(1, pos, r, g, b) | |
406 |
|
409 | |||
407 | return rgb_lvl |
|
410 | return rgb_lvl | |
408 |
|
411 | |||
409 |
|
412 | |||
410 | class MplDriver: |
|
413 | class MplDriver: | |
411 | def __init__(self): |
|
414 | def __init__(self): | |
412 | pass No newline at end of file |
|
415 | pass |
@@ -1,373 +1,529 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import time |
|
3 | import time | |
4 | from schainPlot import * |
|
4 | from schainPlot import * | |
5 | #from schainPlotLib import Driver |
|
5 | ||
|
6 | class SpcFigure(Figure): | |||
|
7 | overplot = 0 | |||
|
8 | xw = 800 | |||
|
9 | yw = 650 | |||
|
10 | showprofile = False | |||
|
11 | ||||
|
12 | def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |||
|
13 | Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar) | |||
|
14 | ||||
|
15 | self.showprofile = showprofile | |||
|
16 | ||||
|
17 | def getSubplots(self): | |||
|
18 | ncolumns = int(numpy.sqrt(self.nframes)+0.9) | |||
|
19 | nrows = int(self.nframes*1./ncolumns + 0.9) | |||
|
20 | ||||
|
21 | return nrows, ncolumns | |||
|
22 | ||||
|
23 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): | |||
|
24 | ||||
|
25 | if xmin == None: xmin = numpy.min(x) | |||
|
26 | if xmax == None: xmax = numpy.max(x) | |||
|
27 | if ymin == None: ymin = numpy.min(y) | |||
|
28 | if ymax == None: ymax = numpy.max(y) | |||
|
29 | if minvalue == None: minvalue = 20. | |||
|
30 | if maxvalue == None: maxvalue = 90. | |||
|
31 | ||||
|
32 | self.xmin = xmin | |||
|
33 | self.xmax = xmax | |||
|
34 | self.minrange = ymin | |||
|
35 | self.maxrange = ymax | |||
|
36 | self.ymin = ymin | |||
|
37 | self.ymax = ymax | |||
|
38 | self.minvalue = minvalue | |||
|
39 | self.maxvalue = maxvalue | |||
|
40 | ||||
|
41 | ||||
|
42 | def changeXRange(self, *args): | |||
|
43 | pass | |||
|
44 | ||||
|
45 | def createFrames(self): | |||
|
46 | for frame in range(self.nframes): | |||
|
47 | frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) | |||
|
48 | self.frameObjList.append(frameObj) | |||
|
49 | ||||
|
50 | class SpcFrame(Frame): | |||
|
51 | def __init__(self,drvObj,idframe,colorbar,showprofile): | |||
|
52 | self.drvObj = drvObj | |||
|
53 | self.idframe = idframe | |||
|
54 | self.nplots = 1 | |||
|
55 | ||||
|
56 | if showprofile: | |||
|
57 | self.nplots += 1 | |||
|
58 | ||||
|
59 | self.colorbar = colorbar | |||
|
60 | self.showprofile = showprofile | |||
|
61 | self.createPlots() | |||
|
62 | ||||
|
63 | def createPlots(self): | |||
|
64 | plotObjList = [] | |||
|
65 | idplot = 0 | |||
|
66 | xi, yi, xw, yw = self.getScreenPos(idplot) | |||
|
67 | plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) | |||
|
68 | plotObjList.append(plotObj) | |||
|
69 | ||||
|
70 | if self.showprofile: | |||
|
71 | idplot = 1 | |||
|
72 | xi, yi, xw, yw = self.getScreenPos(idplot) | |||
|
73 | type = "pwbox" | |||
|
74 | title = "" | |||
|
75 | xlabel = "dB" | |||
|
76 | ylabel = "" | |||
|
77 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) | |||
|
78 | plotObjList.append(plotObj) | |||
|
79 | ||||
|
80 | self.plotObjList = plotObjList | |||
|
81 | ||||
|
82 | def getScreenPosMainPlot(self): | |||
|
83 | xi = 0.15 | |||
|
84 | ||||
|
85 | if self.showprofile: | |||
|
86 | xw = 0.65 | |||
|
87 | ||||
|
88 | else: | |||
|
89 | xw = 0.75 | |||
|
90 | ||||
|
91 | if self.colorbar: | |||
|
92 | xw = xw - 0.06 | |||
|
93 | ||||
|
94 | yi = 0.20; yw = 0.75 | |||
|
95 | ||||
|
96 | return xi, yi, xw, yw | |||
|
97 | ||||
|
98 | def getScreenPosGraph1(self): | |||
|
99 | if self.colorbar: | |||
|
100 | xi = 0.65 + 0.08 | |||
|
101 | else: | |||
|
102 | xi = 0.75 + 0.05 | |||
|
103 | ||||
|
104 | xw = xi + 0.2 | |||
|
105 | ||||
|
106 | yi = 0.2; yw = 0.75 | |||
|
107 | ||||
|
108 | return xi, yi, xw, yw | |||
|
109 | ||||
|
110 | def plot(self,x, y, data): | |||
|
111 | plotObj = self.plotObjList[0] | |||
|
112 | plotObj.plot(x,y,data) | |||
|
113 | ||||
|
114 | if self.showprofile: | |||
|
115 | plotObj = self.plotObjList[1] | |||
|
116 | plotObj.plot(data,y) | |||
|
117 | ||||
|
118 | class SpcPlot(Plot): | |||
|
119 | ||||
|
120 | getGrid = True | |||
|
121 | ||||
|
122 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar): | |||
|
123 | self.drvObj = drvObj | |||
|
124 | self.idframe = idframe | |||
|
125 | self.idplot = idplot | |||
|
126 | self.xi = xi | |||
|
127 | self.yi = yi | |||
|
128 | self.xw = xw | |||
|
129 | self.yw = yw | |||
|
130 | self.colorbar = colorbar | |||
|
131 | ||||
|
132 | if self.colorbar: | |||
|
133 | cbxi = xw + 0.03 | |||
|
134 | cbxw = cbxi + 0.03 | |||
|
135 | cbyi = yi | |||
|
136 | cbyw = yw | |||
|
137 | self.cbxpos = [cbxi,cbxw] | |||
|
138 | self.cbypos = [cbyi,cbyw] | |||
|
139 | ||||
|
140 | self.xpos = [self.xi,self.xw] | |||
|
141 | self.ypos = [self.yi,self.yw] | |||
|
142 | self.xaxisastime = False | |||
|
143 | self.timefmt = None | |||
|
144 | self.xopt = "bcnst" | |||
|
145 | self.yopt = "bcnstv" | |||
|
146 | ||||
|
147 | self.szchar = 0.8 | |||
|
148 | self.strforchannel = "Channel %d"%self.idframe | |||
|
149 | self.xlabel = "m/s" | |||
|
150 | self.ylabel = "Range (Km)" | |||
|
151 | ||||
|
152 | def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): | |||
|
153 | self.xmin = xmin | |||
|
154 | self.xmax = xmax | |||
|
155 | self.ymin = ymin | |||
|
156 | self.ymax = ymax | |||
|
157 | self.minvalue = minvalue | |||
|
158 | self.maxvalue = maxvalue | |||
|
159 | self.colorbar = args[2] | |||
|
160 | self.title = "%s - %s"%(self.strforchannel,args[3]) | |||
|
161 | ||||
|
162 | ||||
|
163 | ||||
|
164 | def plot(self, x, y, data): | |||
|
165 | z = data | |||
|
166 | deltax = None | |||
|
167 | deltay = None | |||
|
168 | self.plotPcolor(x, y, z, deltax, deltay, self.getGrid) | |||
|
169 | self.getGrid = False | |||
6 |
|
170 | |||
7 |
|
171 | |||
8 | class RTIFigure(Figure): |
|
172 | class RTIFigure(Figure): | |
9 | overplot = 1 |
|
173 | overplot = 1 | |
10 | xw = 700 |
|
174 | xw = 700 | |
11 | yw = 650 |
|
175 | yw = 650 | |
12 | showprofile = False |
|
176 | showprofile = False | |
13 | starttime = None |
|
177 | starttime = None | |
14 | endtime = None |
|
178 | endtime = None | |
15 | minrange = None |
|
179 | minrange = None | |
16 | maxrange = None |
|
180 | maxrange = None | |
17 | minvalue = None |
|
181 | minvalue = None | |
18 | maxvalue = None |
|
182 | maxvalue = None | |
19 | xrangestepinsecs = None |
|
183 | xrangestepinsecs = None | |
20 |
|
184 | |||
21 |
|
185 | |||
22 | def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): |
|
186 | def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): | |
23 | self.idfigure = idfigure |
|
187 | Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar) | |
24 | self.nframes = nframes |
|
188 | ||
25 | self.wintitle = wintitle |
|
|||
26 | self.colormap = colormap |
|
|||
27 | self.colorbar = colorbar |
|
|||
28 | self.showprofile = showprofile |
|
189 | self.showprofile = showprofile | |
29 | self.driver = driver |
|
|||
30 | self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) |
|
|||
31 | self.drvObj.driver.setFigure() |
|
|||
32 | self.drvObj.driver.setColormap(colormap) |
|
|||
33 |
|
190 | |||
34 | def getSubplots(self): |
|
191 | def getSubplots(self): | |
35 | nrows = self.nframes |
|
192 | nrows = self.nframes | |
36 | ncolumns = 1 |
|
193 | ncolumns = 1 | |
37 | return nrows, ncolumns |
|
194 | return nrows, ncolumns | |
38 |
|
195 | |||
39 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep): |
|
196 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep): | |
40 |
|
197 | |||
41 | self.starttime = xmin |
|
198 | self.starttime = xmin | |
42 | self.endtime = xmax |
|
199 | self.endtime = xmax | |
43 |
|
200 | |||
44 |
cdatetime = datetime.datetime.utcfromtimestamp(x) |
|
201 | cdatetime = datetime.datetime.utcfromtimestamp(x) | |
45 |
|
202 | |||
46 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) |
|
203 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) | |
47 | if ((xrangestep == 0) or (xrangestep == None)): |
|
204 | if ((xrangestep == 0) or (xrangestep == None)): | |
48 | maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second) |
|
205 | maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second) | |
49 | self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple()) |
|
206 | self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple()) | |
50 | npoints = 1000. |
|
207 | npoints = 1000. | |
51 | if xrangestep == 1: |
|
208 | if xrangestep == 1: | |
52 | maxdatetime = mindatetime + datetime.timedelta(hours=1) |
|
209 | maxdatetime = mindatetime + datetime.timedelta(hours=1) | |
53 | self.xrangestepinsecs = 60*60. |
|
210 | self.xrangestepinsecs = 60*60. | |
54 | npoints = 500. |
|
211 | npoints = 500. | |
55 | if xrangestep == 2: |
|
212 | if xrangestep == 2: | |
56 | maxdatetime = mindatetime + datetime.timedelta(minutes=1) |
|
213 | maxdatetime = mindatetime + datetime.timedelta(minutes=1) | |
57 | self.xrangestepinsecs = 60. |
|
214 | self.xrangestepinsecs = 60. | |
58 | npoints = 250. |
|
215 | npoints = 250. | |
59 | if xrangestep == 3: |
|
216 | if xrangestep == 3: | |
60 | maxdatetime = mindatetime + datetime.timedelta(seconds=1) |
|
217 | maxdatetime = mindatetime + datetime.timedelta(seconds=1) | |
61 | self.xrangestepinsecs = 1. |
|
218 | self.xrangestepinsecs = 1. | |
62 | npoints = 125. |
|
219 | npoints = 125. | |
63 |
|
220 | |||
64 | xmin = time.mktime(mindatetime.timetuple()) |
|
221 | xmin = time.mktime(mindatetime.timetuple()) | |
65 | xmax = time.mktime(maxdatetime.timetuple()) |
|
222 | xmax = time.mktime(maxdatetime.timetuple()) | |
66 |
|
223 | |||
67 | deltax = (xmax-xmin) / npoints |
|
224 | deltax = (xmax-xmin) / npoints | |
68 |
|
225 | |||
69 |
|
226 | |||
70 | if ymin == None: ymin = numpy.min(y) |
|
227 | if ymin == None: ymin = numpy.min(y) | |
71 | if ymax == None: ymax = numpy.max(y) |
|
228 | if ymax == None: ymax = numpy.max(y) | |
72 |
|
229 | |||
73 | if minvalue == None: minvalue = 0. |
|
230 | if minvalue == None: minvalue = 0. | |
74 | if maxvalue == None: maxvalue = 50. |
|
231 | if maxvalue == None: maxvalue = 50. | |
75 |
|
232 | |||
76 | self.xmin = xmin |
|
233 | self.xmin = xmin | |
77 | self.xmax = xmax |
|
234 | self.xmax = xmax | |
78 | self.minrange = ymin |
|
235 | self.minrange = ymin | |
79 | self.maxrange = ymax |
|
236 | self.maxrange = ymax | |
80 | self.ymin = ymin |
|
237 | self.ymin = ymin | |
81 | self.ymax = ymax |
|
238 | self.ymax = ymax | |
82 | self.minvalue = minvalue |
|
239 | self.minvalue = minvalue | |
83 | self.maxvalue = maxvalue |
|
240 | self.maxvalue = maxvalue | |
84 | self.xrangestep = xrangestep |
|
241 | self.xrangestep = xrangestep | |
85 | self.deltax = deltax |
|
242 | self.deltax = deltax | |
86 |
|
243 | |||
87 |
|
||||
88 | def changeXRange(self,x): |
|
244 | def changeXRange(self,x): | |
89 |
|
245 | |||
90 |
cdatetime = datetime.datetime.utcfromtimestamp(x) |
|
246 | cdatetime = datetime.datetime.utcfromtimestamp(x) | |
91 |
|
247 | |||
92 | if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)): |
|
248 | if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)): | |
93 | if self.xrangestep == 1: |
|
249 | if self.xrangestep == 1: | |
94 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second) |
|
250 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second) | |
95 |
|
251 | |||
96 | if self.xrangestep == 2: |
|
252 | if self.xrangestep == 2: | |
97 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second) |
|
253 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second) | |
98 |
|
254 | |||
99 | if self.xrangestep == 3: |
|
255 | if self.xrangestep == 3: | |
100 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second) |
|
256 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second) | |
101 |
|
257 | |||
102 | # mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) |
|
|||
103 | self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone |
|
258 | self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone | |
104 | self.xmax = self.xmin + self.xrangestepinsecs |
|
259 | self.xmax = self.xmin + self.xrangestepinsecs | |
105 |
|
260 | |||
106 |
self.figuretitle = "%s |
|
261 | self.figuretitle = "%s %s : %s"%(self.figuretitle, | |
107 | datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"), |
|
262 | datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"), | |
108 | datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S")) |
|
263 | datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S")) | |
109 |
|
||||
110 |
|
||||
111 | return 1 |
|
264 | return 1 | |
112 |
|
265 | |||
113 | return 0 |
|
266 | return 0 | |
114 |
|
|
267 | ||
115 |
|
||||
116 | def createFrames(self): |
|
268 | def createFrames(self): | |
117 | for frame in range(self.nframes): |
|
269 | for frame in range(self.nframes): | |
118 | frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) |
|
270 | frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) | |
119 | self.frameObjList.append(frameObj) |
|
271 | self.frameObjList.append(frameObj) | |
120 |
|
272 | |||
121 | class RTIFrame(Frame): |
|
273 | class RTIFrame(Frame): | |
122 | def __init__(self,drvObj,idframe,colorbar,showprofile): |
|
274 | def __init__(self,drvObj,idframe,colorbar,showprofile): | |
123 | self.drvObj = drvObj |
|
275 | self.drvObj = drvObj | |
124 | self.idframe = idframe |
|
276 | self.idframe = idframe | |
125 | self.nplots = 1 |
|
277 | self.nplots = 1 | |
126 |
|
278 | |||
127 | if showprofile: |
|
279 | if showprofile: | |
128 | self.nplots += 1 |
|
280 | self.nplots += 1 | |
129 |
|
281 | |||
130 | self.colorbar = colorbar |
|
282 | self.colorbar = colorbar | |
131 | self.showprofile = showprofile |
|
283 | self.showprofile = showprofile | |
132 | self.createPlots() |
|
284 | self.createPlots() | |
133 |
|
285 | |||
134 | def createPlots(self): |
|
286 | def createPlots(self): | |
135 | plotObjList = [] |
|
287 | plotObjList = [] | |
136 |
|
288 | |||
137 | idplot = 0 |
|
289 | idplot = 0 | |
138 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
290 | xi, yi, xw, yw = self.getScreenPos(idplot) | |
|
291 | ||||
139 | plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) |
|
292 | plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) | |
140 | plotObjList.append(plotObj) |
|
293 | plotObjList.append(plotObj) | |
141 |
|
294 | |||
142 | if self.showprofile: |
|
295 | if self.showprofile: | |
143 | idplot = 1 |
|
296 | idplot = 1 | |
144 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
297 | xi, yi, xw, yw = self.getScreenPos(idplot) | |
145 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw) |
|
298 | type = "pwbox" | |
|
299 | title = "" | |||
|
300 | xlabel = "dB" | |||
|
301 | ylabel = "" | |||
|
302 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) | |||
146 | plotObjList.append(plotObj) |
|
303 | plotObjList.append(plotObj) | |
147 |
|
304 | |||
148 | self.plotObjList = plotObjList |
|
305 | self.plotObjList = plotObjList | |
149 |
|
306 | |||
150 | def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots |
|
307 | def getScreenPosMainPlot(self): | |
151 | xi = 0.07 |
|
308 | xi = 0.07 | |
152 |
|
||||
153 | if self.showprofile: |
|
309 | if self.showprofile: | |
154 | xw = 0.65 |
|
310 | xw = 0.65 | |
155 |
|
||||
156 | else: |
|
311 | else: | |
157 | xw = 0.9 |
|
312 | xw = 0.9 | |
158 |
|
313 | |||
159 | if self.colorbar: |
|
314 | if self.colorbar: | |
160 | xw = xw - 0.06 |
|
315 | xw = xw - 0.06 | |
161 |
|
316 | |||
162 | yi = 0.20; yw = 0.75 |
|
317 | yi = 0.20; yw = 0.75 | |
163 |
|
318 | |||
164 | return xi, yi, xw, yw |
|
319 | return xi, yi, xw, yw | |
165 |
|
320 | |||
166 | def getScreenPosGraph1(self): |
|
321 | def getScreenPosGraph1(self): | |
167 | if self.colorbar: |
|
322 | if self.colorbar: | |
168 |
xi = 0.65 + 0.0 |
|
323 | xi = 0.65 + 0.08 | |
169 | else: |
|
324 | else: | |
170 | xi = 0.9 + 0.05 |
|
325 | xi = 0.9 + 0.05 | |
171 |
|
326 | |||
172 | xw = xi + 0.2 |
|
327 | xw = xi + 0.2 | |
173 |
|
328 | |||
174 | yi = 0.2; yw = 0.75 |
|
329 | yi = 0.2; yw = 0.75 | |
175 |
|
330 | |||
176 | return xi, yi, xw, yw |
|
331 | return xi, yi, xw, yw | |
177 |
|
332 | |||
178 | def plot(self, currenttime, range, data): |
|
333 | def plot(self, currenttime, range, data): | |
179 | # for plotObj in self.plotObjList: |
|
|||
180 | # plotObj.plot(currenttime, range, data) |
|
|||
181 |
|
||||
182 | plotObj = self.plotObjList[0] |
|
334 | plotObj = self.plotObjList[0] | |
183 | plotObj.plot(currenttime,range,data) |
|
335 | plotObj.plot(currenttime,range,data) | |
184 |
|
336 | |||
185 | if self.showprofile: |
|
337 | if self.showprofile: | |
186 | plotObj = self.plotObjList[1] |
|
338 | plotObj = self.plotObjList[1] | |
187 | plotObj.plot(data,range) |
|
339 | plotObj.plot(data,range) | |
188 |
|
340 | |||
189 |
|
341 | |||
190 | class RTIPlot(Plot): |
|
342 | class RTIPlot(Plot): | |
191 | deltax = None |
|
343 | deltax = None | |
192 | deltay = None |
|
344 | deltay = None | |
193 | xrange = [None,None] |
|
345 | xrange = [None,None] | |
194 | xminpos = None |
|
346 | xminpos = None | |
195 | xmaxpos = None |
|
347 | xmaxpos = None | |
196 | xg = None |
|
348 | xg = None | |
197 | yg = None |
|
349 | yg = None | |
198 |
|
350 | |||
199 | def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar): |
|
351 | def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar): | |
200 | self.drvObj = drvObj |
|
352 | self.drvObj = drvObj | |
201 | self.idframe = idframe |
|
353 | self.idframe = idframe | |
202 | self.idplot = idplot |
|
354 | self.idplot = idplot | |
203 | self.xi = xi |
|
355 | self.xi = xi | |
204 | self.yi = yi |
|
356 | self.yi = yi | |
205 | self.xw = xw |
|
357 | self.xw = xw | |
206 | self.yw = yw |
|
358 | self.yw = yw | |
207 | self.colorbar = colorbar |
|
359 | self.colorbar = colorbar | |
208 |
|
360 | |||
209 | if self.colorbar: |
|
361 | if self.colorbar: | |
210 | cbxi = xw + 0.03 |
|
362 | cbxi = xw + 0.03 | |
211 | cbxw = cbxi + 0.03 |
|
363 | cbxw = cbxi + 0.03 | |
212 | cbyi = yi |
|
364 | cbyi = yi | |
213 | cbyw = yw |
|
365 | cbyw = yw | |
214 | self.cbxpos = [cbxi,cbxw] |
|
366 | self.cbxpos = [cbxi,cbxw] | |
215 | self.cbypos = [cbyi,cbyw] |
|
367 | self.cbypos = [cbyi,cbyw] | |
216 |
|
368 | |||
217 | self.xpos = [self.xi,self.xw] |
|
369 | self.xpos = [self.xi,self.xw] | |
218 | self.ypos = [self.yi,self.yw] |
|
370 | self.ypos = [self.yi,self.yw] | |
219 | self.xaxisastime = True |
|
371 | self.xaxisastime = True | |
220 | self.timefmt = "%H:%M" |
|
372 | self.timefmt = "%H:%M" | |
221 | self.xopt = "bcnstd" |
|
373 | self.xopt = "bcnstd" | |
222 | self.yopt = "bcnstv" |
|
374 | self.yopt = "bcnstv" | |
223 |
|
375 | |||
224 | self.szchar = 1.0 |
|
376 | self.szchar = 1.0 | |
225 | self.title = "Channel %d"%self.idframe |
|
377 | self.title = "Channel %d"%self.idframe | |
226 | self.xlabel = "Local Time" |
|
378 | self.xlabel = "Local Time" | |
227 | self.ylabel = "Range (Km)" |
|
379 | self.ylabel = "Range (Km)" | |
228 |
|
380 | |||
229 |
|
381 | |||
230 |
def |
|
382 | def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args): | |
231 | self.xmin = xmin |
|
383 | self.xmin = xmin | |
232 | self.xmax = xmax |
|
384 | self.xmax = xmax | |
233 | self.ymin = ymin |
|
385 | self.ymin = ymin | |
234 | self.ymax = ymax |
|
386 | self.ymax = ymax | |
235 | self.minvalue = minvalue |
|
387 | self.minvalue = minvalue | |
236 | self.maxvalue = maxvalue |
|
388 | self.maxvalue = maxvalue | |
237 | self.deltax = deltax |
|
389 | self.deltax = deltax | |
238 | self.deltay = deltay |
|
390 | self.deltay = deltay | |
239 |
|
391 | self.colorbar = colorbar | ||
240 | self.drvObj.driver.plotBox(self.idframe, |
|
|||
241 | self.xpos, |
|
|||
242 | self.ypos, |
|
|||
243 | self.xmin, |
|
|||
244 | self.xmax, |
|
|||
245 | self.ymin, |
|
|||
246 | self.ymax, |
|
|||
247 | self.minvalue, |
|
|||
248 | self.maxvalue, |
|
|||
249 | self.xopt, |
|
|||
250 | self.yopt, |
|
|||
251 | self.szchar, |
|
|||
252 | self.xaxisastime, |
|
|||
253 | self.timefmt) |
|
|||
254 |
|
||||
255 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) |
|
|||
256 |
|
||||
257 | if self.colorbar: |
|
|||
258 | self.drvObj.driver.plotColorbar(minvalue, maxvalue, self.cbxpos,self.cbypos) |
|
|||
259 |
|
||||
260 |
|
||||
261 |
|
392 | |||
262 | def plot(self, currenttime, range, data): |
|
393 | def plot(self, currenttime, range, data): | |
263 |
|
394 | |||
264 | if self.xmaxpos == None: |
|
395 | if self.xmaxpos == None: | |
265 | self.xmaxpos = currenttime |
|
396 | self.xmaxpos = currenttime | |
266 |
|
397 | |||
267 | if currenttime >= self.xmaxpos: |
|
398 | if currenttime >= self.xmaxpos: | |
268 |
|
399 | |||
269 | self.xminpos = currenttime |
|
400 | self.xminpos = currenttime | |
270 | self.xmaxpos = currenttime + self.deltax |
|
401 | self.xmaxpos = currenttime + self.deltax | |
271 | x = [currenttime] |
|
402 | x = [currenttime] | |
272 | y = range |
|
403 | y = range | |
273 | z = numpy.reshape(data, (1,-1)) |
|
404 | z = numpy.reshape(data, (1,-1)) | |
274 | getGrid = True |
|
405 | getGrid = True | |
275 |
|
406 | |||
276 | self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid) |
|
407 | self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid) | |
277 |
|
408 | |||
278 |
|
409 | |||
279 | class ScopeFigure(Figure): |
|
410 | class ScopeFigure(Figure): | |
280 | overplot = 0 |
|
411 | overplot = 0 | |
281 | xw = 700 |
|
412 | xw = 700 | |
282 | yw = 650 |
|
413 | yw = 650 | |
283 | colorbar = None |
|
414 | colorbar = None | |
284 |
|
415 | |||
285 | def __init__(self,idfigure,nframes,wintitle,driver): |
|
416 | def __init__(self,idfigure,nframes,wintitle,driver): | |
286 | colormap = None |
|
417 | colormap = None | |
287 | colorbar = False |
|
418 | colorbar = False | |
288 |
|
419 | |||
289 | self.idfigure = idfigure |
|
420 | self.idfigure = idfigure | |
290 | self.nframes = nframes |
|
421 | self.nframes = nframes | |
291 | self.wintitle = wintitle |
|
422 | self.wintitle = wintitle | |
292 |
|
423 | |||
293 | self.colormap = colormap |
|
424 | self.colormap = colormap | |
294 | self.colorbar = colorbar |
|
425 | self.colorbar = colorbar | |
295 | self.driver = driver |
|
426 | self.driver = driver | |
296 | self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) |
|
427 | self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) | |
297 | self.drvObj.driver.setFigure() |
|
428 | self.drvObj.driver.setFigure() | |
298 |
|
429 | |||
299 | # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args) |
|
430 | # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args) | |
300 |
|
431 | |||
301 | def getSubplots(self): |
|
432 | def getSubplots(self): | |
302 | nrows = self.nframes |
|
433 | nrows = self.nframes | |
303 | ncolumns = 1 |
|
434 | ncolumns = 1 | |
304 | return nrows, ncolumns |
|
435 | return nrows, ncolumns | |
305 |
|
436 | |||
306 | def createFrames(self): |
|
437 | def createFrames(self): | |
307 | for frame in range(self.nframes): |
|
438 | for frame in range(self.nframes): | |
308 | frameObj = ScopeFrame(self.drvObj,frame + 1) |
|
439 | frameObj = ScopeFrame(self.drvObj,frame + 1) | |
309 | self.frameObjList.append(frameObj) |
|
440 | self.frameObjList.append(frameObj) | |
310 |
|
441 | |||
311 |
|
442 | |||
312 | class ScopeFrame(Frame): |
|
443 | class ScopeFrame(Frame): | |
313 | # plotObjList = [] |
|
444 | # plotObjList = [] | |
314 | xlabel = "" |
|
445 | xlabel = "" | |
315 | ylabel = "" |
|
446 | ylabel = "" | |
316 | title = "" |
|
447 | title = "" | |
317 | def __init__(self,drvObj,idframe): |
|
448 | def __init__(self,drvObj,idframe): | |
318 | self.drvObj = drvObj |
|
449 | self.drvObj = drvObj | |
319 | self.idframe = idframe |
|
450 | self.idframe = idframe | |
320 | self.nplots = 1 #nplots/frame |
|
451 | self.nplots = 1 #nplots/frame | |
321 | self.createPlots() |
|
452 | self.createPlots() | |
322 | # Frame.__init__(self, drvObj, idframe) |
|
453 | # Frame.__init__(self, drvObj, idframe) | |
323 |
|
454 | |||
324 | def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots |
|
455 | def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots | |
325 | xi = 0.07; xw = 0.9 |
|
456 | xi = 0.07; xw = 0.9 | |
326 | yi = 0.20; yw = 0.75 |
|
457 | yi = 0.20; yw = 0.75 | |
327 | return xi,yi,xw,yw |
|
458 | return xi,yi,xw,yw | |
328 |
|
459 | |||
329 | def createPlots(self): |
|
460 | def createPlots(self): | |
330 | plotObjList = [] |
|
461 | plotObjList = [] | |
331 | for idplot in range(self.nplots): |
|
462 | for idplot in range(self.nplots): | |
332 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
463 | xi, yi, xw, yw = self.getScreenPos(idplot) | |
333 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw) |
|
464 | type = "scopebox" | |
|
465 | title = "Channel %d"%self.idframe | |||
|
466 | xlabel = "range (Km)" | |||
|
467 | ylabel = "intensity" | |||
|
468 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) | |||
334 | plotObjList.append(plotObj) |
|
469 | plotObjList.append(plotObj) | |
335 | self.plotObjList = plotObjList |
|
470 | self.plotObjList = plotObjList | |
336 | # self.plotObjList.append(plotObj) |
|
471 | # self.plotObjList.append(plotObj) | |
337 |
|
472 | |||
338 | def plot(self, x, y, z=None): |
|
473 | def plot(self, x, y, z=None): | |
339 | for plotObj in self.plotObjList: |
|
474 | for plotObj in self.plotObjList: | |
340 | plotObj.plot(x, y) |
|
475 | plotObj.plot(x, y) | |
341 |
|
476 | |||
342 |
|
477 | |||
343 | class Plot1D(Plot): |
|
478 | class Plot1D(Plot): | |
344 |
|
479 | # type, title, xlabel, ylabel | ||
345 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): |
|
480 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel): | |
346 | self.drvObj = drvObj |
|
481 | self.drvObj = drvObj | |
347 | self.idframe = idframe |
|
482 | self.idframe = idframe | |
348 | self.idplot = idplot |
|
483 | self.idplot = idplot | |
349 | self.xi = xi |
|
484 | self.xi = xi | |
350 | self.yi = yi |
|
485 | self.yi = yi | |
351 | self.xw = xw |
|
486 | self.xw = xw | |
352 | self.yw = yw |
|
487 | self.yw = yw | |
353 | self.xpos = [self.xi,self.xw] |
|
488 | self.xpos = [self.xi,self.xw] | |
354 | self.ypos = [self.yi,self.yw] |
|
489 | self.ypos = [self.yi,self.yw] | |
355 | self.xaxisastime = False |
|
490 | self.xaxisastime = False | |
356 | self.timefmt = None |
|
491 | self.timefmt = None | |
357 | self.xopt = "bcnst" |
|
492 | self.xopt = "bcnst" | |
358 | self.yopt = "bcnstv" |
|
493 | self.yopt = "bcnstv" | |
359 | self.szchar = 1.0 |
|
494 | self.szchar = 1.0 | |
360 | self.title = "Channel %d"%self.idframe |
|
495 | self.type = type | |
361 |
self. |
|
496 | self.title = title | |
362 |
self. |
|
497 | self.xlabel = xlabel | |
|
498 | self.ylabel = ylabel | |||
|
499 | ||||
|
500 | ||||
|
501 | ||||
|
502 | def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): | |||
|
503 | if self.type == "pwbox": | |||
|
504 | self.xmin = minvalue | |||
|
505 | self.xmax = maxvalue | |||
|
506 | self.ymin = ymin | |||
|
507 | self.ymax = ymax | |||
|
508 | self.minvalue = minvalue | |||
|
509 | self.maxvalue = maxvalue | |||
|
510 | ||||
|
511 | else: | |||
|
512 | self.xmin = xmin | |||
|
513 | self.xmax = xmax | |||
|
514 | self.ymin = ymin | |||
|
515 | self.ymax = ymax | |||
|
516 | self.minvalue = minvalue | |||
|
517 | self.maxvalue = maxvalue | |||
363 |
|
518 | |||
|
519 | self.colorbar = False | |||
364 |
|
520 | |||
365 | def plot(self,x,y): |
|
521 | def plot(self,x,y): | |
366 | if y.dtype == "complex128": |
|
522 | if y.dtype == "complex128": | |
367 | color="blue" |
|
523 | color="blue" | |
368 | self.plotBasicLine(x, y.real, color) |
|
524 | self.plotBasicLine(x, y.real, color) | |
369 | color="red" |
|
525 | color="red" | |
370 | self.plotBasicLine(x, y.imag, color) |
|
526 | self.plotBasicLine(x, y.imag, color) | |
371 | else: |
|
527 | else: | |
372 | color="blue" |
|
528 | color="blue" | |
373 | self.plotBasicLine(x, y, color) |
|
529 | self.plotBasicLine(x, y, color) |
@@ -1,388 +1,371 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import time |
|
9 | import time | |
10 |
|
10 | import datetime | ||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Data.JROData import Spectra |
|
14 | from Data.JROData import Spectra | |
15 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter | |
16 |
|
|
16 | from Graphics.schainPlotTypes import SpcFigure | |
17 | #from JRONoise import Noise |
|
17 | #from JRONoise import Noise | |
18 |
|
18 | |||
19 | class SpectraProcessor: |
|
19 | class SpectraProcessor: | |
20 | ''' |
|
20 | ''' | |
21 | classdocs |
|
21 | classdocs | |
22 | ''' |
|
22 | ''' | |
23 |
|
23 | |||
24 | dataInObj = None |
|
24 | dataInObj = None | |
25 |
|
25 | |||
26 | dataOutObj = None |
|
26 | dataOutObj = None | |
27 |
|
27 | |||
28 | noiseObj = None |
|
28 | noiseObj = None | |
29 |
|
29 | |||
30 | integratorObjList = [] |
|
30 | integratorObjList = [] | |
31 |
|
31 | |||
32 | writerObjList = [] |
|
32 | writerObjList = [] | |
33 |
|
33 | |||
34 | integratorObjIndex = None |
|
34 | integratorObjIndex = None | |
35 |
|
35 | |||
36 | writerObjIndex = None |
|
36 | writerObjIndex = None | |
37 |
|
37 | |||
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage | |
39 |
|
39 | |||
40 | # integratorObjList = [] |
|
|||
41 | # |
|
|||
42 | # decoderObjList = [] |
|
|||
43 | # |
|
|||
44 | # writerObjList = [] |
|
|||
45 | # |
|
|||
46 | # plotterObjList = [] |
|
|||
47 | # |
|
|||
48 | # integratorObjIndex = None |
|
|||
49 | # |
|
|||
50 | # decoderObjIndex = None |
|
|||
51 | # |
|
|||
52 | # writerObjIndex = None |
|
|||
53 | # |
|
|||
54 | # plotterObjIndex = None |
|
|||
55 | # |
|
|||
56 | # buffer = None |
|
|||
57 | # |
|
|||
58 | # profIndex = 0 |
|
|||
59 | # |
|
|||
60 | # nFFTPoints = None |
|
|||
61 | # |
|
|||
62 | # nChannels = None |
|
|||
63 | # |
|
|||
64 | # nHeights = None |
|
|||
65 | # |
|
|||
66 | # nPairs = None |
|
|||
67 | # |
|
|||
68 | # pairList = None |
|
|||
69 |
|
||||
70 |
|
40 | |||
71 | def __init__(self): |
|
41 | def __init__(self): | |
72 | ''' |
|
42 | ''' | |
73 | Constructor |
|
43 | Constructor | |
74 | ''' |
|
44 | ''' | |
75 |
|
45 | |||
76 | self.integratorObjIndex = None |
|
46 | self.integratorObjIndex = None | |
77 | self.writerObjIndex = None |
|
47 | self.writerObjIndex = None | |
|
48 | self.plotObjIndex = None | |||
78 | self.integratorObjList = [] |
|
49 | self.integratorObjList = [] | |
79 | self.writerObjList = [] |
|
50 | self.writerObjList = [] | |
|
51 | self.plotObjList = [] | |||
80 | self.noiseObj = None |
|
52 | self.noiseObj = None | |
81 | self.buffer = None |
|
53 | self.buffer = None | |
82 | self.profIndex = 0 |
|
54 | self.profIndex = 0 | |
83 |
|
55 | |||
84 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): | |
85 |
|
57 | |||
86 | if dataInObj == None: |
|
58 | if dataInObj == None: | |
87 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" | |
88 |
|
60 | |||
89 | if dataInObj.type == "Voltage": |
|
61 | if dataInObj.type == "Voltage": | |
90 | if nFFTPoints == None: |
|
62 | if nFFTPoints == None: | |
91 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" | |
92 | else: |
|
64 | else: | |
93 | nFFTPoints = dataInObj.nFFTPoints |
|
65 | nFFTPoints = dataInObj.nFFTPoints | |
94 |
|
66 | |||
95 | self.dataInObj = dataInObj |
|
67 | self.dataInObj = dataInObj | |
96 |
|
68 | |||
97 | if dataOutObj == None: |
|
69 | if dataOutObj == None: | |
98 | dataOutObj = Spectra() |
|
70 | dataOutObj = Spectra() | |
99 |
|
71 | |||
100 | self.dataOutObj = dataOutObj |
|
72 | self.dataOutObj = dataOutObj | |
101 |
|
73 | |||
102 | # self.noiseObj = Noise() #aun no se incluye el objeto Noise() |
|
|||
103 |
|
||||
104 | ########################################## |
|
|||
105 | # self.nFFTPoints = nFFTPoints |
|
|||
106 | # self.nChannels = self.dataInObj.nChannels |
|
|||
107 | # self.nHeights = self.dataInObj.nHeights |
|
|||
108 | # self.pairList = pairList |
|
|||
109 | # if pairList != None: |
|
|||
110 | # self.nPairs = len(pairList) |
|
|||
111 | # else: |
|
|||
112 | # self.nPairs = 0 |
|
|||
113 | # |
|
|||
114 | # self.dataOutObj.heightList = self.dataInObj.heightList |
|
|||
115 | # self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
|||
116 | # self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
|||
117 | # self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
|||
118 | # self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
|||
119 | # self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
|||
120 | # |
|
|||
121 | # self.dataOutObj.dataType = self.dataInObj.dataType |
|
|||
122 | # self.dataOutObj.nPairs = self.nPairs |
|
|||
123 | # self.dataOutObj.nChannels = self.nChannels |
|
|||
124 | # self.dataOutObj.nProfiles = self.nFFTPoints |
|
|||
125 | # self.dataOutObj.nHeights = self.nHeights |
|
|||
126 | # self.dataOutObj.nFFTPoints = self.nFFTPoints |
|
|||
127 | # #self.dataOutObj.data = None |
|
|||
128 | # |
|
|||
129 | # self.dataOutObj.m_SystemHeader.numChannels = self.nChannels |
|
|||
130 | # self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints |
|
|||
131 | # |
|
|||
132 | # self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs |
|
|||
133 | # self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints |
|
|||
134 | # self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights |
|
|||
135 | # self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
|||
136 | # |
|
|||
137 | # spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) |
|
|||
138 | # k = 0 |
|
|||
139 | # for i in range( 0,self.nChannels*2,2 ): |
|
|||
140 | # spectraComb[i] = k |
|
|||
141 | # spectraComb[i+1] = k |
|
|||
142 | # k += 1 |
|
|||
143 | # |
|
|||
144 | # k *= 2 |
|
|||
145 | # |
|
|||
146 | # if self.pairList != None: |
|
|||
147 | # |
|
|||
148 | # for pair in self.pairList: |
|
|||
149 | # spectraComb[k] = pair[0] |
|
|||
150 | # spectraComb[k+1] = pair[1] |
|
|||
151 | # k += 2 |
|
|||
152 | # |
|
|||
153 | # self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
|||
154 |
|
||||
155 | return self.dataOutObj |
|
74 | return self.dataOutObj | |
156 |
|
75 | |||
157 | def init(self): |
|
76 | def init(self): | |
158 | # |
|
|||
159 | # self.nHeights = self.dataInObj.nHeights |
|
|||
160 | # self.dataOutObj.nHeights = self.nHeights |
|
|||
161 | # self.dataOutObj.heightList = self.dataInObj.heightList |
|
|||
162 | # |
|
|||
163 |
|
77 | |||
164 | self.integratorObjIndex = 0 |
|
78 | self.integratorObjIndex = 0 | |
165 | self.writerObjIndex = 0 |
|
79 | self.writerObjIndex = 0 | |
166 |
|
80 | self.plotObjIndex = 0 | ||
167 | if self.dataInObj.type == "Voltage": |
|
81 | if self.dataInObj.type == "Voltage": | |
168 |
|
82 | |||
169 | if self.buffer == None: |
|
83 | if self.buffer == None: | |
170 | self.buffer = numpy.zeros((self.nChannels, |
|
84 | self.buffer = numpy.zeros((self.nChannels, | |
171 | self.nFFTPoints, |
|
85 | self.nFFTPoints, | |
172 | self.dataInObj.nHeights), |
|
86 | self.dataInObj.nHeights), | |
173 | dtype='complex') |
|
87 | dtype='complex') | |
174 |
|
88 | |||
175 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
89 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
176 | self.profIndex += 1 |
|
90 | self.profIndex += 1 | |
177 |
|
91 | |||
178 | if self.profIndex == self.nFFTPoints: |
|
92 | if self.profIndex == self.nFFTPoints: | |
179 | self.__getFft() |
|
93 | self.__getFft() | |
180 | self.dataOutObj.flagNoData = False |
|
94 | self.dataOutObj.flagNoData = False | |
181 |
|
95 | |||
182 | self.buffer = None |
|
96 | self.buffer = None | |
183 | self.profIndex = 0 |
|
97 | self.profIndex = 0 | |
184 | return |
|
98 | return | |
185 |
|
99 | |||
186 | self.dataOutObj.flagNoData = True |
|
100 | self.dataOutObj.flagNoData = True | |
187 |
|
101 | |||
188 | return |
|
102 | return | |
189 |
|
103 | |||
190 | #Other kind of data |
|
104 | #Other kind of data | |
191 | if self.dataInObj.type == "Spectra": |
|
105 | if self.dataInObj.type == "Spectra": | |
192 | self.dataOutObj.copy(self.dataInObj) |
|
106 | self.dataOutObj.copy(self.dataInObj) | |
193 | self.dataOutObj.flagNoData = False |
|
107 | self.dataOutObj.flagNoData = False | |
194 | return |
|
108 | return | |
195 |
|
109 | |||
196 | raise ValueError, "The datatype is not valid" |
|
110 | raise ValueError, "The datatype is not valid" | |
197 |
|
111 | |||
198 | def __getFft(self): |
|
112 | def __getFft(self): | |
199 | """ |
|
113 | """ | |
200 | Convierte valores de Voltaje a Spectra |
|
114 | Convierte valores de Voltaje a Spectra | |
201 |
|
115 | |||
202 | Affected: |
|
116 | Affected: | |
203 | self.dataOutObj.data_spc |
|
117 | self.dataOutObj.data_spc | |
204 | self.dataOutObj.data_cspc |
|
118 | self.dataOutObj.data_cspc | |
205 | self.dataOutObj.data_dc |
|
119 | self.dataOutObj.data_dc | |
206 | self.dataOutObj.heightList |
|
120 | self.dataOutObj.heightList | |
207 | self.dataOutObj.m_BasicHeader |
|
121 | self.dataOutObj.m_BasicHeader | |
208 | self.dataOutObj.m_ProcessingHeader |
|
122 | self.dataOutObj.m_ProcessingHeader | |
209 | self.dataOutObj.m_RadarControllerHeader |
|
123 | self.dataOutObj.m_RadarControllerHeader | |
210 | self.dataOutObj.m_SystemHeader |
|
124 | self.dataOutObj.m_SystemHeader | |
211 | self.profIndex |
|
125 | self.profIndex | |
212 | self.buffer |
|
126 | self.buffer | |
213 | self.dataOutObj.flagNoData |
|
127 | self.dataOutObj.flagNoData | |
214 | self.dataOutObj.dataType |
|
128 | self.dataOutObj.dataType | |
215 | self.dataOutObj.nPairs |
|
129 | self.dataOutObj.nPairs | |
216 | self.dataOutObj.nChannels |
|
130 | self.dataOutObj.nChannels | |
217 | self.dataOutObj.nProfiles |
|
131 | self.dataOutObj.nProfiles | |
218 | self.dataOutObj.m_SystemHeader.numChannels |
|
132 | self.dataOutObj.m_SystemHeader.numChannels | |
219 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
133 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
220 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
134 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
221 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
135 | self.dataOutObj.m_ProcessingHeader.numHeights | |
222 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
136 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
223 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
137 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
224 | """ |
|
138 | """ | |
225 |
|
139 | |||
226 | if self.dataInObj.flagNoData: |
|
140 | if self.dataInObj.flagNoData: | |
227 | return 0 |
|
141 | return 0 | |
228 |
|
142 | |||
229 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
143 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
230 | dc = fft_volt[:,0,:] |
|
144 | dc = fft_volt[:,0,:] | |
231 |
|
145 | |||
232 | #calculo de self-spectra |
|
146 | #calculo de self-spectra | |
233 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
147 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
234 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
148 | spc = fft_volt * numpy.conjugate(fft_volt) | |
235 | spc = spc.real |
|
149 | spc = spc.real | |
236 |
|
150 | |||
237 | blocksize = 0 |
|
151 | blocksize = 0 | |
238 | blocksize += dc.size |
|
152 | blocksize += dc.size | |
239 | blocksize += spc.size |
|
153 | blocksize += spc.size | |
240 |
|
154 | |||
241 | cspc = None |
|
155 | cspc = None | |
242 | pairIndex = 0 |
|
156 | pairIndex = 0 | |
243 | if self.pairList != None: |
|
157 | if self.pairList != None: | |
244 | #calculo de cross-spectra |
|
158 | #calculo de cross-spectra | |
245 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
159 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') | |
246 | for pair in self.pairList: |
|
160 | for pair in self.pairList: | |
247 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
161 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
248 | pairIndex += 1 |
|
162 | pairIndex += 1 | |
249 | blocksize += cspc.size |
|
163 | blocksize += cspc.size | |
250 |
|
164 | |||
251 | self.dataOutObj.data_spc = spc |
|
165 | self.dataOutObj.data_spc = spc | |
252 | self.dataOutObj.data_cspc = cspc |
|
166 | self.dataOutObj.data_cspc = cspc | |
253 | self.dataOutObj.data_dc = dc |
|
167 | self.dataOutObj.data_dc = dc | |
254 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
168 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
255 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
169 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc | |
256 |
|
170 | |||
257 | # self.getNoise() |
|
171 | # self.getNoise() | |
258 |
|
172 | |||
259 | def addWriter(self, wrpath, blocksPerFile): |
|
173 | def addWriter(self, wrpath, blocksPerFile): | |
260 | objWriter = SpectraWriter(self.dataOutObj) |
|
174 | objWriter = SpectraWriter(self.dataOutObj) | |
261 | objWriter.setup(wrpath, blocksPerFile) |
|
175 | objWriter.setup(wrpath, blocksPerFile) | |
262 | self.writerObjList.append(objWriter) |
|
176 | self.writerObjList.append(objWriter) | |
263 |
|
177 | |||
264 | def addIntegrator(self,N,timeInterval): |
|
178 | def addIntegrator(self,N,timeInterval): | |
265 |
|
179 | |||
266 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
180 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
267 | self.integratorObjList.append(objIncohInt) |
|
181 | self.integratorObjList.append(objIncohInt) | |
268 |
|
182 | |||
|
183 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |||
|
184 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |||
|
185 | self.plotObjList.append(spcObj) | |||
|
186 | ||||
|
187 | def plotSpc(self, idfigure=None, | |||
|
188 | xmin=None, | |||
|
189 | xmax=None, | |||
|
190 | ymin=None, | |||
|
191 | ymax=None, | |||
|
192 | minvalue=None, | |||
|
193 | maxvalue=None, | |||
|
194 | wintitle='', | |||
|
195 | driver='plplot', | |||
|
196 | colormap='br_greeen', | |||
|
197 | colorbar=True, | |||
|
198 | showprofile=False, | |||
|
199 | save=False, | |||
|
200 | gpath=None): | |||
|
201 | ||||
|
202 | if self.dataOutObj.flagNoData: | |||
|
203 | return 0 | |||
|
204 | ||||
|
205 | nframes = len(self.dataOutObj.channelList) | |||
|
206 | ||||
|
207 | if len(self.plotObjList) <= self.plotObjIndex: | |||
|
208 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |||
|
209 | ||||
|
210 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |||
|
211 | ||||
|
212 | y = self.dataOutObj.heightList | |||
|
213 | ||||
|
214 | channelList = self.dataOutObj.channelList | |||
|
215 | ||||
|
216 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |||
|
217 | # noisedB = 10.*numpy.log10(noise) | |||
|
218 | noisedB = numpy.arange(len(channelList)+1) | |||
|
219 | noisedB = noisedB *1.2 | |||
|
220 | titleList = [] | |||
|
221 | for i in range(len(noisedB)): | |||
|
222 | title = "%.2f"%noisedB[i] | |||
|
223 | titleList.append(title) | |||
|
224 | ||||
|
225 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) | |||
|
226 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
227 | figuretitle = "Spc Radar Data: %s"%dateTime | |||
|
228 | ||||
|
229 | cleardata = True | |||
|
230 | ||||
|
231 | plotObj = self.plotObjList[self.plotObjIndex] | |||
|
232 | ||||
|
233 | plotObj.plotPcolor(data, | |||
|
234 | x, | |||
|
235 | y, | |||
|
236 | channelList, | |||
|
237 | xmin, | |||
|
238 | xmax, | |||
|
239 | ymin, | |||
|
240 | ymax, | |||
|
241 | minvalue, | |||
|
242 | maxvalue, | |||
|
243 | figuretitle, | |||
|
244 | None, | |||
|
245 | save, | |||
|
246 | gpath, | |||
|
247 | cleardata, | |||
|
248 | titleList) | |||
|
249 | ||||
|
250 | self.plotObjIndex += 1 | |||
|
251 | ||||
|
252 | ||||
269 | def writeData(self, wrpath, blocksPerFile): |
|
253 | def writeData(self, wrpath, blocksPerFile): | |
270 | if self.dataOutObj.flagNoData: |
|
254 | if self.dataOutObj.flagNoData: | |
271 | return 0 |
|
255 | return 0 | |
272 |
|
256 | |||
273 | if len(self.writerObjList) <= self.writerObjIndex: |
|
257 | if len(self.writerObjList) <= self.writerObjIndex: | |
274 | self.addWriter(wrpath, blocksPerFile) |
|
258 | self.addWriter(wrpath, blocksPerFile) | |
275 |
|
259 | |||
276 | self.writerObjList[self.writerObjIndex].putData() |
|
260 | self.writerObjList[self.writerObjIndex].putData() | |
277 |
|
261 | |||
278 | self.writerObjIndex += 1 |
|
262 | self.writerObjIndex += 1 | |
279 |
|
263 | |||
280 | def integrator(self, N=None, timeInterval=None): |
|
264 | def integrator(self, N=None, timeInterval=None): | |
281 |
|
265 | |||
282 | if self.dataOutObj.flagNoData: |
|
266 | if self.dataOutObj.flagNoData: | |
283 | return 0 |
|
267 | return 0 | |
284 |
|
268 | |||
285 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
269 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
286 | self.addIntegrator(N,timeInterval) |
|
270 | self.addIntegrator(N,timeInterval) | |
287 |
|
271 | |||
288 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
272 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
289 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
273 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) | |
290 |
|
274 | |||
291 | if myIncohIntObj.isReady: |
|
275 | if myIncohIntObj.isReady: | |
292 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
276 | self.dataOutObj.data_spc = myIncohIntObj.data | |
293 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
277 | self.dataOutObj.nAvg = myIncohIntObj.navg | |
294 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
278 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg | |
295 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg |
|
|||
296 | self.dataOutObj.flagNoData = False |
|
279 | self.dataOutObj.flagNoData = False | |
297 |
|
280 | |||
298 | """Calcular el ruido""" |
|
281 | """Calcular el ruido""" | |
299 | self.getNoise() |
|
282 | self.getNoise() | |
300 | else: |
|
283 | else: | |
301 | self.dataOutObj.flagNoData = True |
|
284 | self.dataOutObj.flagNoData = True | |
302 |
|
285 | |||
303 | self.integratorObjIndex += 1 |
|
286 | self.integratorObjIndex += 1 | |
304 |
|
287 | |||
305 |
|
288 | |||
306 |
|
289 | |||
307 |
|
290 | |||
308 | class IncoherentIntegration: |
|
291 | class IncoherentIntegration: | |
309 |
|
292 | |||
310 | integ_counter = None |
|
293 | integ_counter = None | |
311 | data = None |
|
294 | data = None | |
312 | navg = None |
|
295 | navg = None | |
313 | buffer = None |
|
296 | buffer = None | |
314 | nIncohInt = None |
|
297 | nIncohInt = None | |
315 |
|
298 | |||
316 | def __init__(self, N = None, timeInterval = None): |
|
299 | def __init__(self, N = None, timeInterval = None): | |
317 | """ |
|
300 | """ | |
318 | N |
|
301 | N | |
319 | timeInterval - interval time [min], integer value |
|
302 | timeInterval - interval time [min], integer value | |
320 | """ |
|
303 | """ | |
321 |
|
304 | |||
322 | self.data = None |
|
305 | self.data = None | |
323 | self.navg = None |
|
306 | self.navg = None | |
324 | self.buffer = None |
|
307 | self.buffer = None | |
325 | self.timeOut = None |
|
308 | self.timeOut = None | |
326 | self.exitCondition = False |
|
309 | self.exitCondition = False | |
327 | self.isReady = False |
|
310 | self.isReady = False | |
328 | self.nIncohInt = N |
|
311 | self.nIncohInt = N | |
329 | self.integ_counter = 0 |
|
312 | self.integ_counter = 0 | |
330 | if timeInterval!=None: |
|
313 | if timeInterval!=None: | |
331 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
314 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
332 |
|
315 | |||
333 | if ((timeInterval==None) and (N==None)): |
|
316 | if ((timeInterval==None) and (N==None)): | |
334 | print 'N = None ; timeInterval = None' |
|
317 | print 'N = None ; timeInterval = None' | |
335 | sys.exit(0) |
|
318 | sys.exit(0) | |
336 | elif timeInterval == None: |
|
319 | elif timeInterval == None: | |
337 | self.timeFlag = False |
|
320 | self.timeFlag = False | |
338 | else: |
|
321 | else: | |
339 | self.timeFlag = True |
|
322 | self.timeFlag = True | |
340 |
|
323 | |||
341 |
|
324 | |||
342 | def exe(self,data,timeOfData): |
|
325 | def exe(self,data,timeOfData): | |
343 | """ |
|
326 | """ | |
344 | data |
|
327 | data | |
345 |
|
328 | |||
346 | timeOfData [seconds] |
|
329 | timeOfData [seconds] | |
347 | """ |
|
330 | """ | |
348 |
|
331 | |||
349 | if self.timeFlag: |
|
332 | if self.timeFlag: | |
350 | if self.timeOut == None: |
|
333 | if self.timeOut == None: | |
351 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
334 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
352 |
|
335 | |||
353 | if timeOfData < self.timeOut: |
|
336 | if timeOfData < self.timeOut: | |
354 | if self.buffer == None: |
|
337 | if self.buffer == None: | |
355 | self.buffer = data |
|
338 | self.buffer = data | |
356 | else: |
|
339 | else: | |
357 | self.buffer = self.buffer + data |
|
340 | self.buffer = self.buffer + data | |
358 | self.integ_counter += 1 |
|
341 | self.integ_counter += 1 | |
359 | else: |
|
342 | else: | |
360 | self.exitCondition = True |
|
343 | self.exitCondition = True | |
361 |
|
344 | |||
362 | else: |
|
345 | else: | |
363 | if self.integ_counter < self.nIncohInt: |
|
346 | if self.integ_counter < self.nIncohInt: | |
364 | if self.buffer == None: |
|
347 | if self.buffer == None: | |
365 | self.buffer = data |
|
348 | self.buffer = data | |
366 | else: |
|
349 | else: | |
367 | self.buffer = self.buffer + data |
|
350 | self.buffer = self.buffer + data | |
368 |
|
351 | |||
369 | self.integ_counter += 1 |
|
352 | self.integ_counter += 1 | |
370 |
|
353 | |||
371 | if self.integ_counter == self.nIncohInt: |
|
354 | if self.integ_counter == self.nIncohInt: | |
372 | self.exitCondition = True |
|
355 | self.exitCondition = True | |
373 |
|
356 | |||
374 | if self.exitCondition: |
|
357 | if self.exitCondition: | |
375 | self.data = self.buffer |
|
358 | self.data = self.buffer | |
376 | self.navg = self.integ_counter |
|
359 | self.navg = self.integ_counter | |
377 | self.isReady = True |
|
360 | self.isReady = True | |
378 | self.buffer = None |
|
361 | self.buffer = None | |
379 | self.timeOut = None |
|
362 | self.timeOut = None | |
380 | self.integ_counter = 0 |
|
363 | self.integ_counter = 0 | |
381 | self.exitCondition = False |
|
364 | self.exitCondition = False | |
382 |
|
365 | |||
383 | if self.timeFlag: |
|
366 | if self.timeFlag: | |
384 | self.buffer = data |
|
367 | self.buffer = data | |
385 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
368 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
386 | else: |
|
369 | else: | |
387 | self.isReady = False |
|
370 | self.isReady = False | |
388 | No newline at end of file |
|
371 |
@@ -1,287 +1,288 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os |
|
7 | import os | |
8 | import sys |
|
8 | import sys | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 | import time |
|
11 | import time | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from Data.JROData import Voltage |
|
16 | from Data.JROData import Voltage | |
17 | from IO.VoltageIO import VoltageWriter |
|
17 | from IO.VoltageIO import VoltageWriter | |
18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure |
|
18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure | |
19 |
|
19 | |||
20 | class VoltageProcessor: |
|
20 | class VoltageProcessor: | |
21 |
|
21 | |||
22 | dataInObj = None |
|
22 | dataInObj = None | |
23 | dataOutObj = None |
|
23 | dataOutObj = None | |
24 | integratorObjIndex = None |
|
24 | integratorObjIndex = None | |
25 | writerObjIndex = None |
|
25 | writerObjIndex = None | |
26 | integratorObjList = None |
|
26 | integratorObjList = None | |
27 | writerObjList = None |
|
27 | writerObjList = None | |
28 |
|
28 | |||
29 | def __init__(self): |
|
29 | def __init__(self): | |
30 | self.integratorObjIndex = None |
|
30 | self.integratorObjIndex = None | |
31 | self.writerObjIndex = None |
|
31 | self.writerObjIndex = None | |
32 | self.plotObjIndex = None |
|
32 | self.plotObjIndex = None | |
33 | self.integratorObjList = [] |
|
33 | self.integratorObjList = [] | |
34 | self.writerObjList = [] |
|
34 | self.writerObjList = [] | |
35 | self.plotObjList = [] |
|
35 | self.plotObjList = [] | |
36 |
|
36 | |||
37 | def setup(self,dataInObj=None,dataOutObj=None): |
|
37 | def setup(self,dataInObj=None,dataOutObj=None): | |
38 | self.dataInObj = dataInObj |
|
38 | self.dataInObj = dataInObj | |
39 |
|
39 | |||
40 | if self.dataOutObj == None: |
|
40 | if self.dataOutObj == None: | |
41 | dataOutObj = Voltage() |
|
41 | dataOutObj = Voltage() | |
42 |
|
42 | |||
43 | self.dataOutObj = dataOutObj |
|
43 | self.dataOutObj = dataOutObj | |
44 |
|
44 | |||
45 | return self.dataOutObj |
|
45 | return self.dataOutObj | |
46 |
|
46 | |||
47 | def init(self): |
|
47 | def init(self): | |
48 | self.integratorObjIndex = 0 |
|
48 | self.integratorObjIndex = 0 | |
49 | self.writerObjIndex = 0 |
|
49 | self.writerObjIndex = 0 | |
50 | self.plotObjIndex = 0 |
|
50 | self.plotObjIndex = 0 | |
51 |
|
51 | |||
52 | if not(self.dataInObj.flagNoData): |
|
52 | if not(self.dataInObj.flagNoData): | |
53 | self.dataOutObj.copy(self.dataInObj) |
|
53 | self.dataOutObj.copy(self.dataInObj) | |
54 | # No necesita copiar en cada init() los atributos de dataInObj |
|
54 | # No necesita copiar en cada init() los atributos de dataInObj | |
55 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
55 | # la copia deberia hacerse por cada nuevo bloque de datos | |
56 |
|
56 | |||
57 |
def addRti(self, idfigure, nframes, wintitle, driver, color |
|
57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
58 |
rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, color |
|
58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
59 | self.plotObjList.append(rtiObj) |
|
59 | self.plotObjList.append(rtiObj) | |
60 |
|
60 | |||
61 | def plotRti(self, idfigure=None, |
|
61 | def plotRti(self, idfigure=None, | |
62 | starttime=None, |
|
62 | starttime=None, | |
63 | endtime=None, |
|
63 | endtime=None, | |
64 | rangemin=None, |
|
64 | rangemin=None, | |
65 | rangemax=None, |
|
65 | rangemax=None, | |
66 | minvalue=None, |
|
66 | minvalue=None, | |
67 | maxvalue=None, |
|
67 | maxvalue=None, | |
68 | wintitle='', |
|
68 | wintitle='', | |
69 | driver='plplot', |
|
69 | driver='plplot', | |
70 | colormap='br_greeen', |
|
70 | colormap='br_greeen', | |
71 | colorbar=True, |
|
71 | colorbar=True, | |
72 | showprofile=False, |
|
72 | showprofile=False, | |
73 | xrangestep=None, |
|
73 | xrangestep=None, | |
74 | save=False, |
|
74 | save=False, | |
75 | gpath=None): |
|
75 | gpath=None): | |
76 |
|
76 | |||
77 | if self.dataOutObj.flagNoData: |
|
77 | if self.dataOutObj.flagNoData: | |
78 | return 0 |
|
78 | return 0 | |
79 |
|
79 | |||
80 | nframes = len(self.dataOutObj.channelList) |
|
80 | nframes = len(self.dataOutObj.channelList) | |
81 |
|
81 | |||
82 | if len(self.plotObjList) <= self.plotObjIndex: |
|
82 | if len(self.plotObjList) <= self.plotObjIndex: | |
83 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
83 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
84 |
|
84 | |||
85 | data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
85 | data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) | |
86 | data = 10*numpy.log10(data.real) |
|
86 | data = 10*numpy.log10(data.real) | |
87 |
|
87 | |||
88 | # currenttime = self.dataOutObj.dataUtcTime |
|
88 | # currenttime = self.dataOutObj.dataUtcTime | |
89 | # if timezone == "lt": |
|
89 | # if timezone == "lt": | |
90 | currenttime = self.dataOutObj.dataUtcTime - time.timezone |
|
90 | currenttime = self.dataOutObj.dataUtcTime - time.timezone | |
91 |
|
91 | |||
92 |
|
||||
93 |
|
||||
94 | range = self.dataOutObj.heightList |
|
92 | range = self.dataOutObj.heightList | |
95 |
|
93 | |||
96 | channelList = self.dataOutObj.channelList |
|
94 | channelList = self.dataOutObj.channelList | |
97 |
|
95 | |||
98 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) |
|
96 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) | |
99 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
97 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
100 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
98 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) | |
101 |
|
99 | |||
102 | figuretitle = "RTI Plot Radar Data" #+ date |
|
100 | figuretitle = "RTI Plot Radar Data" #+ date | |
103 |
|
101 | |||
104 | plotObj = self.plotObjList[self.plotObjIndex] |
|
102 | plotObj = self.plotObjList[self.plotObjIndex] | |
105 |
|
103 | |||
|
104 | cleardata = False | |||
|
105 | ||||
106 | plotObj.plotPcolor(data, |
|
106 | plotObj.plotPcolor(data, | |
107 | currenttime, |
|
107 | currenttime, | |
108 | range, |
|
108 | range, | |
109 | channelList, |
|
109 | channelList, | |
110 | starttime, |
|
110 | starttime, | |
111 | endtime, |
|
111 | endtime, | |
112 | rangemin, |
|
112 | rangemin, | |
113 | rangemax, |
|
113 | rangemax, | |
114 | minvalue, |
|
114 | minvalue, | |
115 | maxvalue, |
|
115 | maxvalue, | |
116 | figuretitle, |
|
116 | figuretitle, | |
117 | xrangestep, |
|
117 | xrangestep, | |
118 | save, |
|
118 | save, | |
119 |
gpath |
|
119 | gpath, | |
|
120 | cleardata) | |||
120 |
|
121 | |||
121 | self.plotObjIndex += 1 |
|
122 | self.plotObjIndex += 1 | |
122 |
|
123 | |||
123 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
124 | def addScope(self, idfigure, nframes, wintitle, driver): | |
124 | if idfigure==None: |
|
125 | if idfigure==None: | |
125 | idfigure = self.plotObjIndex |
|
126 | idfigure = self.plotObjIndex | |
126 |
|
127 | |||
127 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
128 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |
128 | self.plotObjList.append(scopeObj) |
|
129 | self.plotObjList.append(scopeObj) | |
129 |
|
130 | |||
130 | def plotScope(self, |
|
131 | def plotScope(self, | |
131 | idfigure=None, |
|
132 | idfigure=None, | |
132 | minvalue=None, |
|
133 | minvalue=None, | |
133 | maxvalue=None, |
|
134 | maxvalue=None, | |
134 | xmin=None, |
|
135 | xmin=None, | |
135 | xmax=None, |
|
136 | xmax=None, | |
136 | wintitle='', |
|
137 | wintitle='', | |
137 | driver='plplot', |
|
138 | driver='plplot', | |
138 | save=False, |
|
139 | save=False, | |
139 | gpath=None, |
|
140 | gpath=None, | |
140 | titleList=None, |
|
141 | titleList=None, | |
141 | xlabelList=None, |
|
142 | xlabelList=None, | |
142 | ylabelList=None, |
|
143 | ylabelList=None, | |
143 | type="power"): |
|
144 | type="power"): | |
144 |
|
145 | |||
145 | if self.dataOutObj.flagNoData: |
|
146 | if self.dataOutObj.flagNoData: | |
146 | return 0 |
|
147 | return 0 | |
147 |
|
148 | |||
148 | nframes = len(self.dataOutObj.channelList) |
|
149 | nframes = len(self.dataOutObj.channelList) | |
149 |
|
150 | |||
150 | if len(self.plotObjList) <= self.plotObjIndex: |
|
151 | if len(self.plotObjList) <= self.plotObjIndex: | |
151 | self.addScope(idfigure, nframes, wintitle, driver) |
|
152 | self.addScope(idfigure, nframes, wintitle, driver) | |
152 |
|
153 | |||
153 |
|
154 | |||
154 | if type=="power": |
|
155 | if type=="power": | |
155 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
156 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) | |
156 | data1D = data1D.real |
|
157 | data1D = data1D.real | |
157 |
|
158 | |||
158 | if type =="iq": |
|
159 | if type =="iq": | |
159 | data1D = self.dataOutObj.data |
|
160 | data1D = self.dataOutObj.data | |
160 |
|
161 | |||
161 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) |
|
162 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) | |
162 |
|
163 | |||
163 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
164 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
164 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
165 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
165 |
|
166 | |||
166 | figureTitle = "Scope Plot Radar Data: " + date |
|
167 | figureTitle = "Scope Plot Radar Data: " + date | |
167 |
|
168 | |||
168 | plotObj = self.plotObjList[self.plotObjIndex] |
|
169 | plotObj = self.plotObjList[self.plotObjIndex] | |
169 |
|
170 | |||
170 | plotObj.plot1DArray(data1D, |
|
171 | plotObj.plot1DArray(data1D, | |
171 | self.dataOutObj.heightList, |
|
172 | self.dataOutObj.heightList, | |
172 | self.dataOutObj.channelList, |
|
173 | self.dataOutObj.channelList, | |
173 | xmin, |
|
174 | xmin, | |
174 | xmax, |
|
175 | xmax, | |
175 | minvalue, |
|
176 | minvalue, | |
176 | maxvalue, |
|
177 | maxvalue, | |
177 | figureTitle, |
|
178 | figureTitle, | |
178 | save, |
|
179 | save, | |
179 | gpath) |
|
180 | gpath) | |
180 |
|
181 | |||
181 | self.plotObjIndex += 1 |
|
182 | self.plotObjIndex += 1 | |
182 |
|
183 | |||
183 |
|
184 | |||
184 | def addIntegrator(self,N,timeInterval): |
|
185 | def addIntegrator(self,N,timeInterval): | |
185 | objCohInt = CoherentIntegrator(N,timeInterval) |
|
186 | objCohInt = CoherentIntegrator(N,timeInterval) | |
186 | self.integratorObjList.append(objCohInt) |
|
187 | self.integratorObjList.append(objCohInt) | |
187 |
|
188 | |||
188 | def addWriter(self, wrpath, blocksPerFile, profilesPerBlock): |
|
189 | def addWriter(self, wrpath, blocksPerFile, profilesPerBlock): | |
189 | writerObj = VoltageWriter(self.dataOutObj) |
|
190 | writerObj = VoltageWriter(self.dataOutObj) | |
190 | writerObj.setup(wrpath,blocksPerFile,profilesPerBlock) |
|
191 | writerObj.setup(wrpath,blocksPerFile,profilesPerBlock) | |
191 | self.writerObjList.append(writerObj) |
|
192 | self.writerObjList.append(writerObj) | |
192 |
|
193 | |||
193 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
194 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): | |
194 |
|
195 | |||
195 | if self.dataOutObj.flagNoData: |
|
196 | if self.dataOutObj.flagNoData: | |
196 | return 0 |
|
197 | return 0 | |
197 |
|
198 | |||
198 | if len(self.writerObjList) <= self.writerObjIndex: |
|
199 | if len(self.writerObjList) <= self.writerObjIndex: | |
199 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
200 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) | |
200 |
|
201 | |||
201 | self.writerObjList[self.writerObjIndex].putData() |
|
202 | self.writerObjList[self.writerObjIndex].putData() | |
202 |
|
203 | |||
203 | self.writerObjIndex += 1 |
|
204 | self.writerObjIndex += 1 | |
204 |
|
205 | |||
205 | def integrator(self, N=None, timeInterval=None): |
|
206 | def integrator(self, N=None, timeInterval=None): | |
206 | if self.dataOutObj.flagNoData: |
|
207 | if self.dataOutObj.flagNoData: | |
207 | return 0 |
|
208 | return 0 | |
208 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
209 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
209 | self.addIntegrator(N,timeInterval) |
|
210 | self.addIntegrator(N,timeInterval) | |
210 |
|
211 | |||
211 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
212 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
212 | myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None) |
|
213 | myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None) | |
213 |
|
214 | |||
214 |
|
215 | |||
215 |
|
216 | |||
216 | class CoherentIntegrator: |
|
217 | class CoherentIntegrator: | |
217 |
|
218 | |||
218 | integ_counter = None |
|
219 | integ_counter = None | |
219 | data = None |
|
220 | data = None | |
220 | navg = None |
|
221 | navg = None | |
221 | buffer = None |
|
222 | buffer = None | |
222 | nCohInt = None |
|
223 | nCohInt = None | |
223 |
|
224 | |||
224 | def __init__(self, N=None,timeInterval=None): |
|
225 | def __init__(self, N=None,timeInterval=None): | |
225 |
|
226 | |||
226 | self.data = None |
|
227 | self.data = None | |
227 | self.navg = None |
|
228 | self.navg = None | |
228 | self.buffer = None |
|
229 | self.buffer = None | |
229 | self.timeOut = None |
|
230 | self.timeOut = None | |
230 | self.exitCondition = False |
|
231 | self.exitCondition = False | |
231 | self.isReady = False |
|
232 | self.isReady = False | |
232 | self.nCohInt = N |
|
233 | self.nCohInt = N | |
233 | self.integ_counter = 0 |
|
234 | self.integ_counter = 0 | |
234 | if timeInterval!=None: |
|
235 | if timeInterval!=None: | |
235 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
236 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
236 |
|
237 | |||
237 | if ((timeInterval==None) and (N==None)): |
|
238 | if ((timeInterval==None) and (N==None)): | |
238 | raise ValueError, "N = None ; timeInterval = None" |
|
239 | raise ValueError, "N = None ; timeInterval = None" | |
239 |
|
240 | |||
240 | if timeInterval == None: |
|
241 | if timeInterval == None: | |
241 | self.timeFlag = False |
|
242 | self.timeFlag = False | |
242 | else: |
|
243 | else: | |
243 | self.timeFlag = True |
|
244 | self.timeFlag = True | |
244 |
|
245 | |||
245 | def exe(self, data, timeOfData): |
|
246 | def exe(self, data, timeOfData): | |
246 |
|
247 | |||
247 | if self.timeFlag: |
|
248 | if self.timeFlag: | |
248 | if self.timeOut == None: |
|
249 | if self.timeOut == None: | |
249 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
250 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
250 |
|
251 | |||
251 | if timeOfData < self.timeOut: |
|
252 | if timeOfData < self.timeOut: | |
252 | if self.buffer == None: |
|
253 | if self.buffer == None: | |
253 | self.buffer = data |
|
254 | self.buffer = data | |
254 | else: |
|
255 | else: | |
255 | self.buffer = self.buffer + data |
|
256 | self.buffer = self.buffer + data | |
256 | self.integ_counter += 1 |
|
257 | self.integ_counter += 1 | |
257 | else: |
|
258 | else: | |
258 | self.exitCondition = True |
|
259 | self.exitCondition = True | |
259 |
|
260 | |||
260 | else: |
|
261 | else: | |
261 | if self.integ_counter < self.nCohInt: |
|
262 | if self.integ_counter < self.nCohInt: | |
262 | if self.buffer == None: |
|
263 | if self.buffer == None: | |
263 | self.buffer = data |
|
264 | self.buffer = data | |
264 | else: |
|
265 | else: | |
265 | self.buffer = self.buffer + data |
|
266 | self.buffer = self.buffer + data | |
266 |
|
267 | |||
267 | self.integ_counter += 1 |
|
268 | self.integ_counter += 1 | |
268 |
|
269 | |||
269 | if self.integ_counter == self.nCohInt: |
|
270 | if self.integ_counter == self.nCohInt: | |
270 | self.exitCondition = True |
|
271 | self.exitCondition = True | |
271 |
|
272 | |||
272 | if self.exitCondition: |
|
273 | if self.exitCondition: | |
273 | self.data = self.buffer |
|
274 | self.data = self.buffer | |
274 | self.navg = self.integ_counter |
|
275 | self.navg = self.integ_counter | |
275 | self.isReady = True |
|
276 | self.isReady = True | |
276 | self.buffer = None |
|
277 | self.buffer = None | |
277 | self.timeOut = None |
|
278 | self.timeOut = None | |
278 | self.integ_counter = 0 |
|
279 | self.integ_counter = 0 | |
279 | self.exitCondition = False |
|
280 | self.exitCondition = False | |
280 |
|
281 | |||
281 | if self.timeFlag: |
|
282 | if self.timeFlag: | |
282 | self.buffer = data |
|
283 | self.buffer = data | |
283 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
284 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
284 | else: |
|
285 | else: | |
285 | self.isReady = False |
|
286 | self.isReady = False | |
286 |
|
287 | |||
287 |
|
288 |
General Comments 0
You need to be logged in to leave comments.
Login now