##// END OF EJS Templates
-Actualización de los nombres de los objetos systemHeader y radaraControllerHeader...
Miguel Valdez -
r148:1305f08c51fd
parent child
Show More
@@ -1,227 +1,227
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import copy
9 9 import numpy
10 10
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from IO.JROHeaderIO import SystemHeader, RadarControllerHeader
15 15
16 16 class JROData:
17 17
18 18 # m_BasicHeader = BasicHeader()
19 19 # m_ProcessingHeader = ProcessingHeader()
20 20
21 21 systemHeaderObj = SystemHeader()
22 22
23 23 radarControllerHeaderObj = RadarControllerHeader()
24 24
25 25 # data = None
26 26
27 27 type = None
28 28
29 29 dtype = None
30 30
31 31 nChannels = None
32 32
33 33 nHeights = None
34 34
35 35 nProfiles = None
36 36
37 37 heightList = None
38 38
39 39 channelList = None
40 40
41 41 channelIndexList = None
42 42
43 43 flagNoData = False
44 44
45 45 flagTimeBlock = False
46 46
47 47 dataUtcTime = None
48 48
49 49 nCode = None
50 50
51 51 nBaud = None
52 52
53 53 code = None
54 54
55 55 flagDecodeData = True #asumo q la data esta decodificada
56 56
57 57 flagDeflipData = True #asumo q la data esta sin flip
58 58
59 59 flagShiftFFT = False
60 60
61 61 ippSeconds = None
62 62
63 63
64 64 def __init__(self):
65 65
66 66 raise ValueError, "This class has not been implemented"
67 67
68 68 def copy(self, inputObj=None):
69 69
70 70 if inputObj == None:
71 71 return copy.deepcopy(self)
72 72
73 73 for key in inputObj.__dict__.keys():
74 74 self.__dict__[key] = inputObj.__dict__[key]
75 75
76 76 def deepcopy(self):
77 77
78 78 return copy.deepcopy(self)
79 79
80 80 class Voltage(JROData):
81 81
82 82 nCohInt = None
83 83
84 84 #data es un numpy array de 2 dmensiones (canales, alturas)
85 85 data = None
86 86
87 87 def __init__(self):
88 88 '''
89 89 Constructor
90 90 '''
91 91
92 self.m_RadarControllerHeader = RadarControllerHeader()
92 self.radarControllerHeaderObj = RadarControllerHeader()
93 93
94 self.m_SystemHeader = SystemHeader()
94 self.systemHeaderObj = SystemHeader()
95 95
96 96 self.type = "Voltage"
97 97
98 98 self.data = None
99 99
100 100 self.dtype = None
101 101
102 102 self.nChannels = 0
103 103
104 104 self.nHeights = 0
105 105
106 106 self.nProfiles = None
107 107
108 108 self.heightList = None
109 109
110 110 self.channelList = None
111 111
112 112 self.channelIndexList = None
113 113
114 114 self.flagNoData = True
115 115
116 116 self.flagTimeBlock = False
117 117
118 118 self.dataUtcTime = None
119 119
120 120 self.nCohInt = None
121 121
122 122 class Spectra(JROData):
123 123
124 124 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
125 125 data_spc = None
126 126
127 127 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
128 128 data_cspc = None
129 129
130 130 #data es un numpy array de 2 dmensiones (canales, alturas)
131 131 data_dc = None
132 132
133 133 nFFTPoints = None
134 134
135 135 nPairs = None
136 136
137 137 pairsList = None
138 138
139 139 nIncohInt = None
140 140
141 141 def __init__(self):
142 142 '''
143 143 Constructor
144 144 '''
145 145
146 self.m_RadarControllerHeader = RadarControllerHeader()
146 self.radarControllerHeaderObj = RadarControllerHeader()
147 147
148 self.m_SystemHeader = SystemHeader()
148 self.systemHeaderObj = SystemHeader()
149 149
150 150 self.type = "Spectra"
151 151
152 152 # self.data = None
153 153
154 154 self.dtype = None
155 155
156 156 self.nChannels = 0
157 157
158 158 self.nHeights = 0
159 159
160 160 self.nProfiles = None
161 161
162 162 self.heightList = None
163 163
164 164 self.channelList = None
165 165
166 166 self.channelIndexList = None
167 167
168 168 self.flagNoData = True
169 169
170 170 self.flagTimeBlock = False
171 171
172 172 self.dataUtcTime = None
173 173
174 174 self.nIncohInt = None
175 175
176 176
177 177 class SpectraHeis(JROData):
178 178
179 179 data_spc = None
180 180
181 181 data_cspc = None
182 182
183 183 data_dc = None
184 184
185 185 nFFTPoints = None
186 186
187 187 nPairs = None
188 188
189 189 pairsList = None
190 190
191 191 def __init__(self):
192 192
193 self.m_RadarControllerHeader = RadarControllerHeader()
193 self.radarControllerHeaderObj = RadarControllerHeader()
194 194
195 self.m_SystemHeader = SystemHeader()
195 self.systemHeaderObj = SystemHeader()
196 196
197 197 self.type = "SpectraHeis"
198 198
199 199 self.dataType = None
200 200
201 201 self.nHeights = 0
202 202
203 203 self.nChannels = 0
204 204
205 205 self.channelList = None
206 206
207 207 self.heightList = None
208 208
209 209 self.flagNoData = True
210 210
211 211 self.flagResetProcessing = False
212 212
213 213
214 214 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
215 215 self.data_spc = None
216 216
217 217 self.data_cspc = None
218 218
219 219 self.data_dc = None
220 220
221 221 self.nFFTPoints = None
222 222
223 223 self.nAvg = None
224 224
225 225 self.nPairs = 0
226 226
227 227 self.pairsList = None
@@ -1,1211 +1,1211
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @autor $Author: dsuarez $
5 5 @version $Id: BaseGraph.py 117 2012-09-04 21:16:59Z dsuarez $
6 6
7 7 '''
8 8 #from __future__ import division
9 9 #import os
10 10 import numpy
11 11 #import sys
12 12 import time
13 13 import datetime
14 14
15 15 #import plplot
16 16 import matplotlib as mpl
17 mpl.use('TKAgg')
17 #mpl.use('TKAgg')
18 18 import matplotlib.pyplot as plt
19 19
20 import scitools.numpyutils as sn
20 #import scitools.numpyutils as sn
21 21
22 22 def cmap1_init(colormap='gray'):
23 23
24 24 # if colormap == None:
25 25 # return
26 26 #
27 27 # ncolor = None
28 28 # rgb_lvl = None
29 29 #
30 30 # # Routine for defining a specific color map 1 in HLS space.
31 31 # # if gray is true, use basic grayscale variation from half-dark to light.
32 32 # # otherwise use false color variation from blue (240 deg) to red (360 deg).
33 33 #
34 34 # # Independent variable of control points.
35 35 # i = numpy.array((0., 1.))
36 36 # if colormap=='gray':
37 37 # ncolor = 256
38 38 # # Hue for control points. Doesn't matter since saturation is zero.
39 39 # h = numpy.array((0., 0.))
40 40 # # Lightness ranging from half-dark (for interest) to light.
41 41 # l = numpy.array((0.5, 1.))
42 42 # # Gray scale has zero saturation
43 43 # s = numpy.array((0., 0.))
44 44 #
45 45 # # number of cmap1 colours is 256 in this case.
46 46 # plplot.plscmap1n(ncolor)
47 47 # # Interpolate between control points to set up cmap1.
48 48 # plplot.plscmap1l(0, i, h, l, s)
49 49 #
50 50 # return None
51 51 #
52 52 # if colormap == 'jet':
53 53 # ncolor = 256
54 54 # pos = numpy.zeros((ncolor))
55 55 # r = numpy.zeros((ncolor))
56 56 # g = numpy.zeros((ncolor))
57 57 # b = numpy.zeros((ncolor))
58 58 #
59 59 # for i in range(ncolor):
60 60 # if(i <= 35.0/100*(ncolor-1)): rf = 0.0
61 61 # elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
62 62 # elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
63 63 # else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
64 64 #
65 65 # if(i <= 12.0/100*(ncolor-1)): gf = 0.0
66 66 # elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
67 67 # elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
68 68 # elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
69 69 # else: gf = 0.0
70 70 #
71 71 # if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
72 72 # elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
73 73 # elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
74 74 # else: bf = 0
75 75 #
76 76 # r[i] = rf
77 77 # g[i] = gf
78 78 # b[i] = bf
79 79 #
80 80 # pos[i] = float(i)/float(ncolor-1)
81 81 #
82 82 #
83 83 # plplot.plscmap1n(ncolor)
84 84 # plplot.plscmap1l(1, pos, r, g, b)
85 85 #
86 86 #
87 87 #
88 88 # if colormap=='br_green':
89 89 # ncolor = 256
90 90 # # Hue ranges from blue (240 deg) to red (0 or 360 deg)
91 91 # h = numpy.array((240., 0.))
92 92 # # Lightness and saturation are constant (values taken from C example).
93 93 # l = numpy.array((0.6, 0.6))
94 94 # s = numpy.array((0.8, 0.8))
95 95 #
96 96 # # number of cmap1 colours is 256 in this case.
97 97 # plplot.plscmap1n(ncolor)
98 98 # # Interpolate between control points to set up cmap1.
99 99 # plplot.plscmap1l(0, i, h, l, s)
100 100 #
101 101 # return None
102 102 #
103 103 # if colormap=='tricolor':
104 104 # ncolor = 3
105 105 # # Hue ranges from blue (240 deg) to red (0 or 360 deg)
106 106 # h = numpy.array((240., 0.))
107 107 # # Lightness and saturation are constant (values taken from C example).
108 108 # l = numpy.array((0.6, 0.6))
109 109 # s = numpy.array((0.8, 0.8))
110 110 #
111 111 # # number of cmap1 colours is 256 in this case.
112 112 # plplot.plscmap1n(ncolor)
113 113 # # Interpolate between control points to set up cmap1.
114 114 # plplot.plscmap1l(0, i, h, l, s)
115 115 #
116 116 # return None
117 117 #
118 118 # if colormap == 'rgb' or colormap == 'rgb666':
119 119 #
120 120 # color_sz = 6
121 121 # ncolor = color_sz*color_sz*color_sz
122 122 # pos = numpy.zeros((ncolor))
123 123 # r = numpy.zeros((ncolor))
124 124 # g = numpy.zeros((ncolor))
125 125 # b = numpy.zeros((ncolor))
126 126 # ind = 0
127 127 # for ri in range(color_sz):
128 128 # for gi in range(color_sz):
129 129 # for bi in range(color_sz):
130 130 # r[ind] = ri/(color_sz-1.0)
131 131 # g[ind] = gi/(color_sz-1.0)
132 132 # b[ind] = bi/(color_sz-1.0)
133 133 # pos[ind] = ind/(ncolor-1.0)
134 134 # ind += 1
135 135 # rgb_lvl = [6,6,6] #Levels for RGB colors
136 136 #
137 137 # if colormap == 'rgb676':
138 138 # ncolor = 6*7*6
139 139 # pos = numpy.zeros((ncolor))
140 140 # r = numpy.zeros((ncolor))
141 141 # g = numpy.zeros((ncolor))
142 142 # b = numpy.zeros((ncolor))
143 143 # ind = 0
144 144 # for ri in range(8):
145 145 # for gi in range(8):
146 146 # for bi in range(4):
147 147 # r[ind] = ri/(6-1.0)
148 148 # g[ind] = gi/(7-1.0)
149 149 # b[ind] = bi/(6-1.0)
150 150 # pos[ind] = ind/(ncolor-1.0)
151 151 # ind += 1
152 152 # rgb_lvl = [6,7,6] #Levels for RGB colors
153 153 #
154 154 # if colormap == 'rgb685':
155 155 # ncolor = 6*8*5
156 156 # pos = numpy.zeros((ncolor))
157 157 # r = numpy.zeros((ncolor))
158 158 # g = numpy.zeros((ncolor))
159 159 # b = numpy.zeros((ncolor))
160 160 # ind = 0
161 161 # for ri in range(8):
162 162 # for gi in range(8):
163 163 # for bi in range(4):
164 164 # r[ind] = ri/(6-1.0)
165 165 # g[ind] = gi/(8-1.0)
166 166 # b[ind] = bi/(5-1.0)
167 167 # pos[ind] = ind/(ncolor-1.0)
168 168 # ind += 1
169 169 # rgb_lvl = [6,8,5] #Levels for RGB colors
170 170 #
171 171 # if colormap == 'rgb884':
172 172 # ncolor = 8*8*4
173 173 # pos = numpy.zeros((ncolor))
174 174 # r = numpy.zeros((ncolor))
175 175 # g = numpy.zeros((ncolor))
176 176 # b = numpy.zeros((ncolor))
177 177 # ind = 0
178 178 # for ri in range(8):
179 179 # for gi in range(8):
180 180 # for bi in range(4):
181 181 # r[ind] = ri/(8-1.0)
182 182 # g[ind] = gi/(8-1.0)
183 183 # b[ind] = bi/(4-1.0)
184 184 # pos[ind] = ind/(ncolor-1.0)
185 185 # ind += 1
186 186 # rgb_lvl = [8,8,4] #Levels for RGB colors
187 187 #
188 188 # if ncolor == None:
189 189 # raise ValueError, 'The colormap selected is not valid'
190 190 #
191 191 # plplot.plscmap1n(ncolor)
192 192 # plplot.plscmap1l(1, pos, r, g, b)
193 193 #
194 194 # return rgb_lvl
195 195 pass
196 196
197 197 def setColormap(colormap='jet'):
198 198 # cmap1_init(colormap)
199 199 pass
200 200
201 201 def savePlplot(filename,width,height):
202 202 # curr_strm = plplot.plgstrm()
203 203 # save_strm = plplot.plmkstrm()
204 204 # plplot.plsetopt('geometry', '%dx%d'%(width,height))
205 205 # plplot.plsdev('png')
206 206 # plplot.plsfnam(filename)
207 207 # plplot.plcpstrm(curr_strm,0)
208 208 # plplot.plreplot()
209 209 # plplot.plend1()
210 210 # plplot.plsstrm(curr_strm)
211 211 pass
212 212
213 213 def initMatplotlib(indexFig,ncol,nrow,winTitle,width,height):
214 214
215 215 plt.ioff()
216 216 fig = plt.figure(indexFig)
217 217 fig.canvas.manager.set_window_title(winTitle)
218 218 fig.canvas.manager.resize(width,height)
219 219 # fig.add_subplot(nrow,ncol,1)
220 220 plt.ion()
221 221
222 222 def setNewPage():
223 223 # plplot.plbop()
224 224 # plplot.pladv(0)
225 225 plt.clf()
226 226
227 227 def closePage():
228 228 # plplot.pleop()
229 229 pass
230 230
231 231 def clearData(objGraph):
232 232 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bc', 'bc')
233 233
234 234 objGraph.setColor(15) #Setting Line Color to White
235 235
236 236 if objGraph.datatype == 'complex':
237 237 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real)
238 238 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag)
239 239
240 240 if objGraph.datatype == 'real':
241 241 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata)
242 242
243 243 objGraph.setColor(1) #Setting Line Color to Black
244 244 # objGraph.setLineStyle(2)
245 245 # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bcntg', 'bc')
246 246 # objGraph.setLineStyle(1)
247 247
248 248 def setFigure(indexFig):
249 249 # plplot.plsstrm(indexFig)
250 250 plt.figure(indexFig)
251 251
252 252 def refresh():
253 253 # plplot.refresh()
254 254 plt.draw()
255 255
256 256 def show():
257 257 # plplot.plspause(True)
258 258 # plplot.plend()
259 259 plt.ioff()
260 260 plt.show()
261 261 plt.ion()
262 262
263 263 def setPlTitle(pltitle,color, szchar=0.7):
264 264 # setSubpages(1, 0)
265 265 # plplot.pladv(0)
266 266 # plplot.plvpor(0., 1., 0., 1.)
267 267 #
268 268 # if color == 'black':
269 269 # plplot.plcol0(1)
270 270 # if color == 'white':
271 271 # plplot.plcol0(15)
272 272 #
273 273 # plplot.plschr(0.0,szchar)
274 274 # plplot.plmtex('t',-1., 0.5, 0.5, pltitle)
275 275 pass
276 276
277 277 def setSubpages(ncol,nrow):
278 278 # plplot.plssub(ncol,nrow)
279 279 pass
280 280
281 281 class BaseGraph:
282 282
283 283 __name = None
284 284 __xpos = None
285 285 __ypos = None
286 286 __subplot = None
287 287 __xg = None
288 288 __yg = None
289 289 __axesId = None
290 290 xdata = None
291 291 ydata = None
292 292 getGrid = True
293 293 xaxisIsTime = False
294 294 deltax = None
295 295 xmin = None
296 296 xmax = None
297 297
298 298 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
299 299
300 300 self.setName(name)
301 301 self.setScreenPos(xpos, ypos)
302 302 self.setSubPlot(subplot)
303 303 self.setXYZrange(xrange,yrange,zrange)
304 304 self.setSizeOfChar(szchar)
305 305 self.setLabels(xlabel,ylabel,title)
306 306 self.getGrid = True
307 307 self.xaxisIsTime = False
308 308 self.deltax = deltax
309 309 pass
310 310
311 311 def makeAxes(self,indexFig,nrow,ncol,subplot):
312 312 fig = plt.figure(indexFig)
313 313 self.__axesId = fig.add_subplot(nrow,ncol,subplot)
314 314
315 315 def setParentAxesId(self,parent):
316 316 self.__axesId = parent.__axesId
317 317
318 318 def setName(self, name):
319 319 self.__name = name
320 320
321 321 def setScreenPos(self,xpos,ypos):
322 322 self.__xpos = xpos
323 323 self.__ypos = ypos
324 324
325 325 def setSubPlot(self,subplot):
326 326 self.__subplot = subplot
327 327
328 328 def setXYZrange(self,xrange,yrange,zrange):
329 329 self.xrange = xrange
330 330 self.yrange = yrange
331 331 self.zrange = zrange
332 332
333 333 def setSizeOfChar(self,szchar):
334 334 self.__szchar = szchar
335 335
336 336 def setLabels(self,xlabel=None,ylabel=None,title=None):
337 337 if xlabel != None: self.xlabel = xlabel
338 338 if ylabel != None: self.ylabel = ylabel
339 339 if title != None: self.title = title
340 340
341 341 def setXYData(self,xdata=None,ydata=None,datatype='real'):
342 342 if ((xdata != None) and (ydata != None)):
343 343 self.xdata = xdata
344 344 self.ydata = ydata
345 345 self.datatype = datatype
346 346 if ((self.xdata == None) and (self.ydata == None)):
347 347 return None
348 348 return 1
349 349
350 350 def setLineStyle(self, style):
351 351 # plplot.pllsty(style)
352 352 pass
353 353
354 354 def setColor(self, color):
355 355 # plplot.plcol0(color)
356 356 pass
357 357
358 358 def setXAxisAsTime(self, value=False):
359 359 self.xaxisIsTime = value
360 360
361 361 def basicLineTimePlot(self, x, y, colline=1):
362 362 # plplot.plcol0(colline)
363 363 # plplot.plline(x, y)
364 364 # plplot.plcol0(1)
365 365 ax = self.__axesId
366 366 if self.setXYData() == None:
367 367 ax.plot(x,y)
368 368 else:
369 369 ax.lines[0].set_data(x,y)
370 370
371 371 def basicXYPlot(self, x, y):
372 372 # plplot.plline(x, y)
373 373 ax = self.__axesId
374 374 if self.setXYData() == None:
375 375 ax.plot(x,y)
376 376 else:
377 377 ax.lines[0].set_data(x,y)
378 378
379 379 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
380 380 #
381 381 # if xmin == None: xmin = x[0]
382 382 # if xmax == None: xmax = x[-1]
383 383 # if ymin == None: ymin = y[0]
384 384 # if ymax == None: ymax = y[-1]
385 385 # if zmin == None: zmin = numpy.nanmin(data)
386 386 # if zmax == None: zmax = numpy.nanmax(data)
387 387 #
388 388 # plplot.plimage(data,
389 389 # float(x[0]),
390 390 # float(x[-1]),
391 391 # float(y[0]),
392 392 # float(y[-1]),
393 393 # float(zmin),
394 394 # float(zmax),
395 395 # float(xmin),
396 396 # float(xmax),
397 397 # float(ymin),
398 398 # float(ymax)
399 399 # )
400 400 pass
401 401
402 402 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
403 403
404 404 # if not(len(x)>0 and len(y)>0):
405 405 # raise ValueError, 'x axis and y axis are empty'
406 406 #
407 407 # if deltax == None: deltax = x[-1] - x[-2]
408 408 # if deltay == None: deltay = y[-1] - y[-2]
409 409 #
410 410 # x1 = numpy.append(x, x[-1] + deltax)
411 411 # y1 = numpy.append(y, y[-1] + deltay)
412 412 #
413 413 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
414 414 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
415 415 #
416 416 # self.__xg = xg
417 417 # self.__yg = yg
418 418 #
419 419 # return xg, yg
420 420 pass
421 421
422 422 def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
423 423 # if getGrid:
424 424 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
425 425 # else:
426 426 # xg = self.__xg
427 427 # yg = self.__yg
428 428 #
429 429 # plplot.plimagefr(data,
430 430 # float(xmin),
431 431 # float(xmax),
432 432 # float(ymin),
433 433 # float(ymax),
434 434 # 0.,
435 435 # 0.,
436 436 # float(zmin),
437 437 # float(zmax),
438 438 # plplot.pltr2,
439 439 # xg,
440 440 # yg)
441 441
442 442 ax = self.__axesId
443 443 # if self.setXYData() == None:
444 444 ax.pcolormesh(x,y,data.T,vmin=zmin,vmax=zmax)
445 445 # else:
446 446 # ax.lines[0].set_data(x,y)
447 447
448 448
449 449 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
450 450 # data = numpy.arange(256)
451 451 # data = numpy.reshape(data, (1,-1))
452 452 # plplot.plimage(data,
453 453 # float(xmin),
454 454 # float(xmax),
455 455 # float(ymin),
456 456 # float(ymax),
457 457 # 0.,
458 458 # 255.,
459 459 # float(xmin),
460 460 # float(xmax),
461 461 # float(ymin),
462 462 # float(ymax))
463 463 ax = self.__axesId
464 464 cax, kw = mpl.colorbar.make_axes(ax)
465 465 norm = mpl.colors.Normalize(vmin=ymin, vmax=ymax)
466 466 cb = mpl.colorbar.ColorbarBase(cax,norm=norm,**kw)
467 467 self.__colorbarId = cb
468 468 cb.set_label(self.title)
469 469
470 470 def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False):
471 471
472 472 # plplot.plschr(0.0,self.__szchar-0.05)
473 473 # plplot.pladv(self.__subplot)
474 474 # plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
475 475 # plplot.plwind(float(xmin), # self.xrange[0]
476 476 # float(xmax), # self.xrange[1]
477 477 # float(ymin), # self.yrange[0]
478 478 # float(ymax) # self.yrange[1]
479 479 # )
480 480 #
481 481 #
482 482 #
483 483 # if self.xaxisIsTime:
484 484 # plplot.pltimefmt('%H:%M')
485 485 # timedelta = (xmax - xmin + 1)/8.
486 486 # plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
487 487 # else:
488 488 # plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
489 489 #
490 490 #
491 491 # if not(nolabels):
492 492 # plplot.pllab(self.xlabel, self.ylabel, self.title)
493 493
494 494 ax = self.__axesId
495 495 ax.set_xlim([xmin,xmax])
496 496 ax.set_ylim([ymin,ymax])
497 497
498 498 if not(nolabels):
499 499 ax.set_xlabel(self.xlabel)
500 500 ax.set_ylabel(self.ylabel)
501 501 ax.set_title(self.title)
502 502
503 503 # fig = plt.gcf()
504 504 # nrows = self.
505 505 # fig.add_subplot
506 506 # print
507 507 pass
508 508
509 509 def delLabels(self):
510 510 # self.setColor(15) #Setting Line Color to White
511 511 # plplot.pllab(self.xlabel, self.ylabel, self.title)
512 512 # self.setColor(1) #Setting Line Color to Black
513 513 pass
514 514
515 515 def plotImage(self,x,y,z,xrange,yrange,zrange):
516 516 # xi = x[0]
517 517 # xf = x[-1]
518 518 # yi = y[0]
519 519 # yf = y[-1]
520 520 #
521 521 # plplot.plimage(z,
522 522 # float(xi),
523 523 # float(xf),
524 524 # float(yi),
525 525 # float(yf),
526 526 # float(zrange[0]),
527 527 # float(zrange[1]),
528 528 # float(xi),
529 529 # float(xf),
530 530 # float(yrange[0]),
531 531 # yrange[1])
532 532 pass
533 533
534 534 class LinearPlot:
535 535
536 536 linearObjDic = {}
537 537 __xpos = None
538 538 __ypos = None
539 539
540 540 def __init__(self,indexFig,nsubplot,winTitle):
541 541 self.width = 700
542 542 self.height = 150
543 543 self.indexFig = indexFig
544 544 self.ncol = 1
545 545 self.nrow = nsubplot
546 546 initMatplotlib(indexFig,self.ncol,self.nrow,winTitle,self.width,self.height)
547 547
548 548 def setFigure(self,indexFig):
549 549 setFigure(indexFig)
550 550
551 551 def setPosition(self):
552 552
553 553 xi = 0.07; xf = 0.9 #0.8,0.7,0.5
554 554 yi = 0.15; yf = 0.8
555 555
556 556 xpos = [xi,xf]
557 557 ypos = [yi,yf]
558 558
559 559 self.__xpos = xpos
560 560 self.__ypos = ypos
561 561
562 562 return xpos,ypos
563 563
564 564 def show(self):
565 565 show()
566 566
567 567 def refresh(self):
568 568 refresh()
569 569
570 570 def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel):
571 571 szchar = 1.10
572 572 name = 'linear'
573 573 key = name + '%d'%subplot
574 574 xrange = [xmin,xmax]
575 575 yrange = [ymin,ymax]
576 576
577 577 xpos,ypos = self.setPosition()
578 578 linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange)
579 579 linearObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
580 580 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcnst', 'bcnstv')
581 581 self.linearObjDic[key] = linearObj
582 582
583 583
584 584 def plot(self,subplot,x,y,type='abs'):
585 585 name = 'linear'
586 586 key = name + '%d'%subplot
587 587
588 588 linearObj = self.linearObjDic[key]
589 589 #linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcst', 'bcst')
590 590
591 591 # if linearObj.setXYData() != None:
592 592 # clearData(linearObj)
593 593 # else:
594 594 # if type.lower() == 'simple':
595 595 # linearObj.setXYData(x,y,'real')
596 596 # if type.lower() == 'power':
597 597 # linearObj.setXYData(x,abs(y),'real')
598 598 # if type.lower() == 'iq':
599 599 # linearObj.setXYData(x,y,'complex')
600 600
601 601 if type.lower() == 'simple':
602 602 colline = 9
603 603 linearObj.basicLineTimePlot(x, y)
604 604 linearObj.setXYData(x,y,'real')
605 605
606 606 if type.lower() == 'abs':
607 607 colline = 9
608 608 linearObj.basicLineTimePlot(x, abs(y), colline)
609 609 linearObj.setXYData(x,abs(y),'real')
610 610
611 611 if type.lower() == 'iq':
612 612 colline = 9
613 613 linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline)
614 614 colline = 13
615 615 linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline)
616 616 linearObj.setXYData(x,y,'complex')
617 617
618 618 # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcst', 'bcst')
619 619
620 620 pass
621 621
622 622
623 623 class PcolorPlot:
624 624
625 625 pcolorObjDic = {}
626 626 colorbarObjDic = {}
627 627 pwprofileObjDic = {}
628 628 showColorbar = None
629 629 showPowerProfile = None
630 630 XAxisAsTime = None
631 631 width = None
632 632 height = None
633 633 __spcxpos = None
634 634 __spcypos = None
635 635 __cmapxpos = None
636 636 __cmapypos = None
637 637 __profxpos = None
638 638 __profypos = None
639 639 __lastTitle = None
640 640
641 641 def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
642 642
643 643 self.width = 460
644 644 self.height = 300
645 645 self.showColorbar = showColorbar
646 646 self.showPowerProfile = showPowerProfile
647 647 self.XAxisAsTime = XAxisAsTime
648 648
649 649 ncol = int(numpy.sqrt(nsubplot)+0.9)
650 650 nrow = int(nsubplot*1./ncol + 0.9)
651 651
652 652 self.ncol = ncol
653 653 self.nrow = nrow
654 654 self.indexFig = indexFig
655 655
656 656 initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height)
657 657 setColormap(colormap)
658 658
659 659 def setFigure(self,indexFig):
660 660 setFigure(indexFig)
661 661
662 662 def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile
663 663 if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075
664 664 else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5
665 665 yi = 0.15; yf = 0.80
666 666
667 667 xpos = [xi,xf]
668 668 ypos = [yi,yf]
669 669
670 670 self.__spcxpos = xpos
671 671 self.__spcypos = ypos
672 672
673 673 return xpos,ypos
674 674
675 675 def setColorbarScreenPos(self):
676 676
677 677 xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03
678 678 yi = self.__spcypos[0]; yf = self.__spcypos[1]
679 679
680 680 xpos = [xi,xf]
681 681 ypos = [yi,yf]
682 682
683 683 self.__cmapxpos = xpos
684 684 self.__cmapypos = ypos
685 685
686 686 return xpos,ypos
687 687
688 688 def setPowerprofileScreenPos(self):
689 689
690 690 xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25
691 691 yi = self.__spcypos[0]; yf = self.__spcypos[1]
692 692
693 693 xpos = [xi,xf]
694 694 ypos = [yi,yf]
695 695
696 696 self.__profxpos = [xi,xf]
697 697 self.__profypos = [yi,yf]
698 698
699 699 return xpos,ypos
700 700
701 701 def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
702 702
703 703 '''
704 704 Crea los objetos necesarios para un subplot
705 705 '''
706 706
707 707 # Config Spectra plot
708 708
709 709 szchar = 0.7
710 710 name = 'spc'
711 711 key = name + '%d'%subplot
712 712 xrange = [xmin,xmax]
713 713 yrange = [ymin,ymax]
714 714 zrange = [zmin,zmax]
715 715
716 716 xpos,ypos = self.setSpectraPos()
717 717 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
718 718 #pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
719 719 self.pcolorObjDic[key] = pcolorObj
720 720
721 721 # Config Colorbar
722 722 if self.showColorbar:
723 723 szchar = 0.65
724 724 name = 'colorbar'
725 725 key = name + '%d'%subplot
726 726
727 727 xpos,ypos = self.setColorbarScreenPos()
728 728 xrange = [0.,1.]
729 729 yrange = [zmin,zmax]
730 730 cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange)
731 731 self.colorbarObjDic[key] = cmapObj
732 732
733 733 # Config Power profile
734 734 if self.showPowerProfile:
735 735 szchar = 0.55
736 736 name = 'pwprofile'
737 737 key = name + '%d'%subplot
738 738
739 739 xpos,ypos = self.setPowerprofileScreenPos()
740 740 xrange = [zmin,zmax]
741 741 yrange = [ymin,ymax]
742 742 powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange)
743 743 #powObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
744 744 self.pwprofileObjDic[key] = powObj
745 745
746 746 def setNewPage(self, pltitle='No title'):
747 747 szchar = 0.7
748 748 setNewPage()
749 749 setPlTitle(pltitle,'black', szchar=szchar)
750 750 setSubpages(self.ncol, self.nrow)
751 751
752 752 def closePage(self):
753 753 closePage()
754 754
755 755 def show(self):
756 756 show()
757 757
758 758 def iniPlot(self,subplot):
759 759 '''
760 760 Inicializa los subplots con su frame, titulo, etc
761 761 '''
762 762
763 763 # Config Spectra plot
764 764 name = 'spc'
765 765 key = name + '%d'%subplot
766 766
767 767 pcolorObj = self.pcolorObjDic[key]
768 768 pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
769 769 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcnst', 'bcnstv')
770 770
771 771 # Config Colorbar
772 772 if self.showColorbar:
773 773 name = 'colorbar'
774 774 key = name + '%d'%subplot
775 775
776 776 cmapObj = self.colorbarObjDic[key]
777 777 cmapObj.setParentAxesId(pcolorObj)
778 778 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
779 779 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
780 780 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
781 781
782 782 # Config Power profile
783 783 if self.showPowerProfile:
784 784 name = 'pwprofile'
785 785 key = name + '%d'%subplot
786 786
787 787 powObj = self.pwprofileObjDic[key]
788 788 powObj.setLineStyle(2)
789 789 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
790 790 powObj.setLineStyle(1)
791 791 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
792 792
793 793 def printTitle(self,pltitle):
794 794 # if self.__lastTitle != None:
795 795 # setPlTitle(self.__lastTitle,'white')
796 796 #
797 797 # self.__lastTitle = pltitle
798 798
799 799 setPlTitle(pltitle,'black')
800 800
801 801 # setSubpages(self.ncol,self.nrow)
802 802
803 803 def plot(self,subplot,x,y,z,subtitle=''):
804 804 # Spectra plot
805 805
806 806 name = 'spc'
807 807 key = name + '%d'%subplot
808 808
809 809 # newx = [x[0],x[-1]]
810 810 pcolorObj = self.pcolorObjDic[key]
811 811 # pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst')
812 812
813 813 #pcolorObj.delLabels()
814 814 pcolorObj.setLabels(title=subtitle)
815 815
816 816 deltax = None; deltay = None
817 817
818 818 pcolorObj.advPcolorPlot(z,
819 819 x,
820 820 y,
821 821 xmin=pcolorObj.xrange[0],
822 822 xmax=pcolorObj.xrange[1],
823 823 ymin=pcolorObj.yrange[0],
824 824 ymax=pcolorObj.yrange[1],
825 825 zmin=pcolorObj.zrange[0],
826 826 zmax=pcolorObj.zrange[1],
827 827 deltax=deltax,
828 828 deltay=deltay,
829 829 getGrid=pcolorObj.getGrid)
830 830
831 831 #Solo se calcula la primera vez que se ingresa a la funcion
832 832 pcolorObj.getGrid = False
833 833
834 834 #pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst', nolabels=True)
835 835
836 836 # Power Profile
837 837 if self.showPowerProfile:
838 838 power = numpy.average(z, axis=0)
839 839 name = 'pwprofile'
840 840 key = name + '%d'%subplot
841 841 powObj = self.pwprofileObjDic[key]
842 842
843 843 if powObj.setXYData() != None:
844 844 #clearData(powObj)
845 845 powObj.setLineStyle(2)
846 846 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
847 847 powObj.setLineStyle(1)
848 848 else:
849 849 powObj.setXYData(power,y)
850 850
851 851 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
852 852 powObj.basicXYPlot(power,y)
853 853 powObj.setXYData(power,y)
854 854
855 855 def savePlot(self,indexFig,filename):
856 856
857 857 width = self.width*self.ncol
858 858 hei = self.height*self.nrow
859 859 savePlplot(filename,width,hei)
860 860
861 861 def refresh(self):
862 862 refresh()
863 863
864 864
865 865 class RtiPlot:
866 866
867 867 pcolorObjDic = {}
868 868 colorbarObjDic = {}
869 869 pwprofileObjDic = {}
870 870 showColorbar = None
871 871 showPowerProfile = None
872 872 XAxisAsTime = None
873 873 widht = None
874 874 height = None
875 875 __rtixpos = None
876 876 __rtiypos = None
877 877 __cmapxpos = None
878 878 __cmapypos = None
879 879 __profxpos = None
880 880 __profypos = None
881 881
882 882 def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
883 883 self.width = 700
884 884 self.height = 150
885 885 self.showColorbar = showColorbar
886 886 self.showPowerProfile = showPowerProfile
887 887 self.XAxisAsTime = XAxisAsTime
888 888
889 889 ncol = 1
890 890 nrow = nsubplot
891 891 initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height)
892 892 setColormap(colormap)
893 893 self.ncol = ncol
894 894 self.nrow = nrow
895 895
896 896 def setFigure(self,indexFig):
897 897 setFigure(indexFig)
898 898
899 899 def setRtiScreenPos(self):
900 900
901 901 if self.showPowerProfile: xi = 0.07; xf = 0.65
902 902 else: xi = 0.07; xf = 0.9
903 903 yi = 0.15; yf = 0.80
904 904
905 905 xpos = [xi,xf]
906 906 ypos = [yi,yf]
907 907
908 908 self.__rtixpos = xpos
909 909 self.__rtiypos = ypos
910 910
911 911 return xpos,ypos
912 912
913 913 def setColorbarScreenPos(self):
914 914
915 915 xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03
916 916
917 917 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
918 918
919 919 xpos = [xi,xf]
920 920 ypos = [yi,yf]
921 921
922 922 self.__cmapxpos = xpos
923 923 self.__cmapypos = ypos
924 924
925 925 return xpos,ypos
926 926
927 927 def setPowerprofileScreenPos(self):
928 928
929 929 xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20
930 930
931 931 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
932 932
933 933 xpos = [xi,xf]
934 934 ypos = [yi,yf]
935 935
936 936 self.__profxpos = [xi,xf]
937 937 self.__profypos = [yi,yf]
938 938
939 939 return xpos,ypos
940 940
941 941 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone='lt',npoints=100):
942 942 # Config Rti plot
943 943 szchar = 1.10
944 944 name = 'rti'
945 945 key = name + '%d'%subplot
946 946
947 947 # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal]
948 948 thisDateTime = datetime.datetime.fromtimestamp(timedata)
949 949 startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0)
950 950 endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59)
951 951 deltaTime = 0
952 952 if timezone == 'lt':
953 953 deltaTime = time.timezone
954 954 startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime
955 955 endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime
956 956
957 957 xrange = [startTimeInSecs,endTimeInSecs]
958 958 totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1.
959 959 deltax = totalTimeInXrange / npoints
960 960
961 961 yrange = [ymin,ymax]
962 962 zrange = [zmin,zmax]
963 963
964 964 xpos,ypos = self.setRtiScreenPos()
965 965 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax)
966 966 if self.XAxisAsTime:
967 967 pcolorObj.setXAxisAsTime(self.XAxisAsTime)
968 968 xopt = 'bcnstd'
969 969 yopt = 'bcnstv'
970 970 else:
971 971 xopt = 'bcnst'
972 972 yopt = 'bcnstv'
973 973
974 974 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
975 975 self.pcolorObjDic[key] = pcolorObj
976 976
977 977
978 978 # Config Colorbar
979 979 if self.showColorbar:
980 980 szchar = 0.9
981 981 name = 'colorbar'
982 982 key = name + '%d'%subplot
983 983
984 984 xpos,ypos = self.setColorbarScreenPos()
985 985 xrange = [0.,1.]
986 986 yrange = [zmin,zmax]
987 987 cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange)
988 988 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcm')
989 989 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
990 990 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
991 991 self.colorbarObjDic[key] = cmapObj
992 992
993 993
994 994 # Config Power profile
995 995 if self.showPowerProfile:
996 996 szchar = 0.8
997 997 name = 'pwprofile'
998 998 key = name + '%d'%subplot
999 999
1000 1000 xpos,ypos = self.setPowerprofileScreenPos()
1001 1001 xrange = [zmin,zmax]
1002 1002 yrange = [ymin,ymax]
1003 1003 powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange)
1004 1004 powObj.setLineStyle(2)
1005 1005 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
1006 1006 powObj.setLineStyle(1)
1007 1007 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
1008 1008 self.pwprofileObjDic[key] = powObj
1009 1009
1010 1010
1011 1011 def plot(self,subplot,x,y,z):
1012 1012 # RTI plot
1013 1013 name = 'rti'
1014 1014 key = name + '%d'%subplot
1015 1015
1016 1016 data = numpy.reshape(z, (1,-1))
1017 1017 data = numpy.abs(data)
1018 1018 data = 10*numpy.log10(data)
1019 1019 newx = [x,x+1]
1020 1020
1021 1021 pcolorObj = self.pcolorObjDic[key]
1022 1022
1023 1023 if pcolorObj.xaxisIsTime:
1024 1024 xopt = 'bcstd'
1025 1025 yopt = 'bcst'
1026 1026 else:
1027 1027 xopt = 'bcst'
1028 1028 yopt = 'bcst'
1029 1029
1030 1030 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
1031 1031
1032 1032 deltax = pcolorObj.deltax
1033 1033 deltay = None
1034 1034
1035 1035 if pcolorObj.xmin == None and pcolorObj.xmax == None:
1036 1036 pcolorObj.xmin = x
1037 1037 pcolorObj.xmax = x
1038 1038
1039 1039 if x >= pcolorObj.xmax:
1040 1040 xmin = x
1041 1041 xmax = x + deltax
1042 1042 x = [x]
1043 1043 pcolorObj.advPcolorPlot(data,
1044 1044 x,
1045 1045 y,
1046 1046 xmin=xmin,
1047 1047 xmax=xmax,
1048 1048 ymin=pcolorObj.yrange[0],
1049 1049 ymax=pcolorObj.yrange[1],
1050 1050 zmin=pcolorObj.zrange[0],
1051 1051 zmax=pcolorObj.zrange[1],
1052 1052 deltax=deltax,
1053 1053 deltay=deltay,
1054 1054 getGrid=pcolorObj.getGrid)
1055 1055
1056 1056 pcolorObj.xmin = xmin
1057 1057 pcolorObj.xmax = xmax
1058 1058
1059 1059
1060 1060 # Power Profile
1061 1061 if self.showPowerProfile:
1062 1062 data = numpy.reshape(data,(numpy.size(data)))
1063 1063 name = 'pwprofile'
1064 1064 key = name + '%d'%subplot
1065 1065 powObj = self.pwprofileObjDic[key]
1066 1066
1067 1067 if powObj.setXYData() != None:
1068 1068 clearData(powObj)
1069 1069 powObj.setLineStyle(2)
1070 1070 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
1071 1071 powObj.setLineStyle(1)
1072 1072 else:
1073 1073 powObj.setXYData(data,y)
1074 1074
1075 1075 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
1076 1076 powObj.basicXYPlot(data,y)
1077 1077 powObj.setXYData(data,y)
1078 1078
1079 1079 def savePlot(self,indexFig,filename):
1080 1080
1081 1081 width = self.width*self.ncol
1082 1082 hei = self.height*self.nrow
1083 1083 savePlplot(filename,width,hei)
1084 1084
1085 1085 def refresh(self):
1086 1086 refresh()
1087 1087
1088 1088
1089 1089 if __name__ == '__main__':
1090 1090
1091 1091 """
1092 1092 Ejemplo1
1093 1093 """
1094 1094 #Setting the signal
1095 1095 fs = 8000
1096 1096 f0 = 200
1097 1097 f1 = 400
1098 1098 T = 1./fs
1099 1099 x = numpy.arange(160)
1100 1100 y1 = numpy.sin(2*numpy.pi*f0*x*T)
1101 1101 y2 = numpy.sin(2*numpy.pi*f1*x*T)
1102 1102 signalList = [y1,y2]
1103 1103
1104 1104 xmin = numpy.min(x)
1105 1105 xmax = numpy.max(x)
1106 1106 ymin = numpy.min(y1)
1107 1107 ymax = numpy.max(y1)
1108 1108
1109 1109 # Creating Object
1110 1110 indexPlot = 1
1111 1111 nsubplot = 2
1112 1112 winTitle = "mi grafico v1"
1113 1113
1114 1114 subplotTitle = "subplot - No."
1115 1115 xlabel = ""
1116 1116 ylabel = ""
1117 1117
1118 1118 linearObj = LinearPlot(indexPlot,nsubplot,winTitle)
1119 1119
1120 1120 #Config SubPlots
1121 1121 for subplot in range(nsubplot):
1122 1122 indexplot = subplot + 1
1123 1123 title = subplotTitle + '%d'%indexplot
1124 1124 linearObj.setup(indexplot, xmin, xmax, ymin, ymax, title, xlabel, ylabel)
1125 1125
1126 1126 #Plotting
1127 1127 type = "simple"
1128 1128 for subplot in range(nsubplot):
1129 1129 indexplot = subplot + 1
1130 1130 y = signalList[subplot]
1131 1131 linearObj.plot(indexplot, x, y, type)
1132 1132
1133 1133 linearObj.refresh()
1134 1134 linearObj.show()
1135 1135
1136 1136
1137 1137 # """
1138 1138 # Ejemplo2
1139 1139 # """
1140 1140 #
1141 1141 # # make these smaller to increase the resolution
1142 1142 # dx, dy = 0.05, 0.05
1143 1143 # x = numpy.arange(-3.0, 3.0001, dx)
1144 1144 # y = numpy.arange(-2.0, 2.0001, dy)
1145 1145 ## X,Y = numpy.meshgrid(x, y)
1146 1146 # X,Y = sn.ndgrid(x, y)
1147 1147 # Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2)
1148 1148 #
1149 1149 # # Creating Object
1150 1150 # indexPlot = 2
1151 1151 # nsubplot = 1
1152 1152 # winTitle = "mi grafico pcolor"
1153 1153 # colormap = "br_green"
1154 1154 # showColorbar = True
1155 1155 # showPowerProfile = False
1156 1156 # XAxisAsTime = False
1157 1157 #
1158 1158 # subplotTitle = "subplot no. "
1159 1159 # xlabel = ""
1160 1160 # ylabel = ""
1161 1161 #
1162 1162 # xmin = -3.0
1163 1163 # xmax = 3.0
1164 1164 # ymin = -2.0
1165 1165 # ymax = 2.0
1166 1166 # zmin = -0.3
1167 1167 # zmax = 1.0
1168 1168 #
1169 1169 # isPlotIni = False
1170 1170 # isPlotConfig = False
1171 1171 # ntimes = 10
1172 1172 #
1173 1173 #
1174 1174 # for i in range(ntimes):
1175 1175 #
1176 1176 # # Instancia del objeto
1177 1177 # if not(isPlotConfig):
1178 1178 # pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime)
1179 1179 # isPlotConfig = True
1180 1180 #
1181 1181 # # Crea los subplots
1182 1182 # if not(isPlotIni):
1183 1183 # for index in range(nsubplot):
1184 1184 # indexplot = index + 1
1185 1185 # title = subplotTitle + '%d'%indexplot
1186 1186 # subplot = index
1187 1187 # pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
1188 1188 # isPlotIni = True
1189 1189 #
1190 1190 # # Inicializa el grafico en cada iteracion
1191 1191 # pcolorObj.setFigure(indexPlot)
1192 1192 # pcolorObj.setNewPage("")
1193 1193 #
1194 1194 # for index in range(nsubplot):
1195 1195 # subplot = index
1196 1196 # pcolorObj.iniPlot(subplot+1)
1197 1197 #
1198 1198 # #plotea los datos
1199 1199 # for channel in range(nsubplot):
1200 1200 # data = Z+0.1*numpy.random.randn(len(x),len(y))
1201 1201 # pcolorObj.plot(channel+1, x, y, data)
1202 1202 #
1203 1203 # pcolorObj.refresh()
1204 1204 #
1205 1205 ## pcolorObj.closePage() #descomentar esta linea para mas iteraciones
1206 1206 #
1207 1207 # time.sleep(1)
1208 1208 #
1209 1209 # pcolorObj.show()
1210 1210 #
1211 1211 # print "end" No newline at end of file
@@ -1,505 +1,505
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import numpy
8 8 import copy
9 9
10 10 class Header:
11 11
12 12 def __init__(self):
13 13 raise
14 14
15 15 def copy(self):
16 16 return copy.deepcopy(self)
17 17
18 18 def read():
19 19 pass
20 20
21 21 def write():
22 22 pass
23 23
24 24 class BasicHeader(Header):
25 25
26 26 size = None
27 27 version = None
28 28 dataBlock = None
29 29 utc = None
30 30 miliSecond = None
31 31 timeZone = None
32 32 dstFlag = None
33 33 errorCount = None
34 34 struct = None
35 35
36 36 def __init__(self):
37 37
38 38 self.size = 0
39 39 self.version = 0
40 40 self.dataBlock = 0
41 41 self.utc = 0
42 42 self.miliSecond = 0
43 43 self.timeZone = 0
44 44 self.dstFlag = 0
45 45 self.errorCount = 0
46 46 self.struct = numpy.dtype([
47 47 ('nSize','<u4'),
48 48 ('nVersion','<u2'),
49 49 ('nDataBlockId','<u4'),
50 50 ('nUtime','<u4'),
51 51 ('nMilsec','<u2'),
52 52 ('nTimezone','<i2'),
53 53 ('nDstflag','<i2'),
54 54 ('nErrorCount','<u4')
55 55 ])
56 56
57 57
58 58 def read(self, fp):
59 59 try:
60 60 header = numpy.fromfile(fp, self.struct,1)
61 61 self.size = header['nSize'][0]
62 62 self.version = header['nVersion'][0]
63 63 self.dataBlock = header['nDataBlockId'][0]
64 64 self.utc = header['nUtime'][0]
65 65 self.miliSecond = header['nMilsec'][0]
66 66 self.timeZone = header['nTimezone'][0]
67 67 self.dstFlag = header['nDstflag'][0]
68 68 self.errorCount = header['nErrorCount'][0]
69 69 except:
70 70 return 0
71 71
72 72 return 1
73 73
74 74 def write(self, fp):
75 75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
76 76 header = numpy.array(headerTuple,self.struct)
77 77 header.tofile(fp)
78 78
79 79 return 1
80 80
81 81 class SystemHeader(Header):
82 82
83 83 size = None
84 84 nSamples = None
85 85 nProfiles = None
86 86 nChannels = None
87 87 adcResolution = None
88 88 pciDioBusWidth = None
89 89 struct = None
90 90
91 91 def __init__(self):
92 92 self.size = 0
93 93 self.nSamples = 0
94 94 self.nProfiles = 0
95 95 self.nChannels = 0
96 96 self.adcResolution = 0
97 97 self.pciDioBusWidth = 0
98 98 self.struct = numpy.dtype([
99 99 ('nSize','<u4'),
100 100 ('nNumSamples','<u4'),
101 101 ('nNumProfiles','<u4'),
102 102 ('nNumChannels','<u4'),
103 103 ('nADCResolution','<u4'),
104 104 ('nPCDIOBusWidth','<u4'),
105 105 ])
106 106
107 107
108 108 def read(self, fp):
109 109 try:
110 110 header = numpy.fromfile(fp,self.struct,1)
111 111 self.size = header['nSize'][0]
112 112 self.nSamples = header['nNumSamples'][0]
113 113 self.nProfiles = header['nNumProfiles'][0]
114 114 self.nChannels = header['nNumChannels'][0]
115 115 self.adcResolution = header['nADCResolution'][0]
116 116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
117 117 except:
118 118 return 0
119 119
120 120 return 1
121 121
122 122 def write(self, fp):
123 123 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
124 124 header = numpy.array(headerTuple,self.struct)
125 125 header.tofile(fp)
126 126
127 127 return 1
128 128
129 129 class RadarControllerHeader(Header):
130 130
131 131 size = None
132 132 expType = None
133 133 nTx = None
134 134 ipp = None
135 135 txA = None
136 136 txB = None
137 137 nWindows = None
138 138 numTaus = None
139 139 codeType = None
140 140 line6Function = None
141 141 line5Function = None
142 142 fClock = None
143 143 prePulseBefore = None
144 144 prePulserAfter = None
145 145 rangeIpp = None
146 146 rangeTxA = None
147 147 rangeTxB = None
148 148 struct = None
149 149
150 150 def __init__(self):
151 151 self.size = 0
152 152 self.expType = 0
153 153 self.nTx = 0
154 154 self.ipp = 0
155 155 self.txA = 0
156 156 self.txB = 0
157 157 self.nWindows = 0
158 158 self.numTaus = 0
159 159 self.codeType = 0
160 160 self.line6Function = 0
161 161 self.line5Function = 0
162 162 self.fClock = 0
163 163 self.prePulseBefore = 0
164 164 self.prePulserAfter = 0
165 165 self.rangeIpp = 0
166 166 self.rangeTxA = 0
167 167 self.rangeTxB = 0
168 168 self.struct = numpy.dtype([
169 169 ('nSize','<u4'),
170 170 ('nExpType','<u4'),
171 171 ('nNTx','<u4'),
172 172 ('fIpp','<f4'),
173 173 ('fTxA','<f4'),
174 174 ('fTxB','<f4'),
175 175 ('nNumWindows','<u4'),
176 176 ('nNumTaus','<u4'),
177 177 ('nCodeType','<u4'),
178 178 ('nLine6Function','<u4'),
179 179 ('nLine5Function','<u4'),
180 180 ('fClock','<f4'),
181 181 ('nPrePulseBefore','<u4'),
182 182 ('nPrePulseAfter','<u4'),
183 183 ('sRangeIPP','<a20'),
184 184 ('sRangeTxA','<a20'),
185 185 ('sRangeTxB','<a20'),
186 186 ])
187 187
188 188 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
189 189
190 190 self.samplingWindow = None
191 191 self.nHeights = None
192 192 self.firstHeight = None
193 193 self.deltaHeight = None
194 194 self.samplesWin = None
195 195
196 196 self.nCode = None
197 197 self.nBaud = None
198 198 self.code = None
199 199 self.flip1 = None
200 200 self.flip2 = None
201 201
202 202 self.dynamic = numpy.array([],numpy.dtype('byte'))
203 203
204 204
205 205 def read(self, fp):
206 206 try:
207 207 startFp = fp.tell()
208 208 header = numpy.fromfile(fp,self.struct,1)
209 209 self.size = header['nSize'][0]
210 210 self.expType = header['nExpType'][0]
211 211 self.nTx = header['nNTx'][0]
212 212 self.ipp = header['fIpp'][0]
213 213 self.txA = header['fTxA'][0]
214 214 self.txB = header['fTxB'][0]
215 215 self.nWindows = header['nNumWindows'][0]
216 216 self.numTaus = header['nNumTaus'][0]
217 217 self.codeType = header['nCodeType'][0]
218 218 self.line6Function = header['nLine6Function'][0]
219 219 self.line5Function = header['nLine5Function'][0]
220 220 self.fClock = header['fClock'][0]
221 221 self.prePulseBefore = header['nPrePulseBefore'][0]
222 222 self.prePulserAfter = header['nPrePulseAfter'][0]
223 223 self.rangeIpp = header['sRangeIPP'][0]
224 224 self.rangeTxA = header['sRangeTxA'][0]
225 225 self.rangeTxB = header['sRangeTxB'][0]
226 226 # jump Dynamic Radar Controller Header
227 227 jumpFp = self.size - 116
228 228 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
229 229 #pointer backward to dynamic header and read
230 230 backFp = fp.tell() - jumpFp
231 231 fp.seek(backFp)
232 232
233 233 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
234 234 self.nHeights = numpy.sum(self.samplingWindow['nsa'])
235 235 self.firstHeight = self.samplingWindow['h0']
236 236 self.deltaHeight = self.samplingWindow['dh']
237 237 self.samplesWin = self.samplingWindow['nsa']
238 238
239 239 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
240 240
241 241 if self.codeType != 0:
242 242 self.nCode = numpy.fromfile(fp,'<u4',1)
243 243 self.nBaud = numpy.fromfile(fp,'<u4',1)
244 244 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
245 245 tempList = []
246 246 for ic in range(self.nCode):
247 247 temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.))
248 248 tempList.append(temp)
249 249 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
250 250 self.code = 2.0*self.code - 1.0
251 251
252 252 if self.line5Function == RCfunction.FLIP:
253 253 self.flip1 = numpy.fromfile(fp,'<u4',1)
254 254
255 255 if self.line6Function == RCfunction.FLIP:
256 256 self.flip2 = numpy.fromfile(fp,'<u4',1)
257 257
258 258 endFp = self.size + startFp
259 259 jumpFp = endFp - fp.tell()
260 260 if jumpFp > 0:
261 261 fp.seek(jumpFp)
262 262
263 263 except:
264 264 return 0
265 265
266 266 return 1
267 267
268 268 def write(self, fp):
269 269 headerTuple = (self.size,
270 270 self.expType,
271 271 self.nTx,
272 272 self.ipp,
273 273 self.txA,
274 274 self.txB,
275 275 self.nWindows,
276 276 self.numTaus,
277 277 self.codeType,
278 278 self.line6Function,
279 279 self.line5Function,
280 280 self.fClock,
281 281 self.prePulseBefore,
282 282 self.prePulserAfter,
283 283 self.rangeIpp,
284 284 self.rangeTxA,
285 285 self.rangeTxB)
286 286
287 287 header = numpy.array(headerTuple,self.struct)
288 288 header.tofile(fp)
289 289
290 290 dynamic = self.dynamic
291 291 dynamic.tofile(fp)
292 292
293 293 return 1
294 294
295 295
296 296
297 297 class ProcessingHeader(Header):
298 298
299 299 size = None
300 300 dtype = None
301 301 blockSize = None
302 302 profilesPerBlock = None
303 303 dataBlocksPerFile = None
304 304 nWindows = None
305 305 processFlags = None
306 306 nCohInt = None
307 307 nIncohInt = None
308 308 totalSpectra = None
309 309 struct = None
310 310 flag_dc = None
311 311 flag_cspc = None
312 312
313 313 def __init__(self):
314 314 self.size = 0
315 self.dataType = 0
315 self.dtype = 0
316 316 self.blockSize = 0
317 317 self.profilesPerBlock = 0
318 318 self.dataBlocksPerFile = 0
319 319 self.nWindows = 0
320 320 self.processFlags = 0
321 321 self.nCohInt = 0
322 322 self.nIncohInt = 0
323 323 self.totalSpectra = 0
324 324 self.struct = numpy.dtype([
325 325 ('nSize','<u4'),
326 326 ('nDataType','<u4'),
327 327 ('nSizeOfDataBlock','<u4'),
328 328 ('nProfilesperBlock','<u4'),
329 329 ('nDataBlocksperFile','<u4'),
330 330 ('nNumWindows','<u4'),
331 331 ('nProcessFlags','<u4'),
332 332 ('nCoherentIntegrations','<u4'),
333 333 ('nIncoherentIntegrations','<u4'),
334 334 ('nTotalSpectra','<u4')
335 335 ])
336 336 self.samplingWindow = 0
337 337 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
338 338 self.nHeights = 0
339 339 self.firstHeight = 0
340 340 self.deltaHeight = 0
341 341 self.samplesWin = 0
342 342 self.spectraComb = 0
343 343 self.nCode = None
344 344 self.code = None
345 345 self.nBaud = None
346 346 self.shif_fft = False
347 347 self.flag_dc = False
348 348 self.flag_cspc = False
349 349
350 350 def read(self, fp):
351 351 try:
352 352 header = numpy.fromfile(fp,self.struct,1)
353 353 self.size = header['nSize'][0]
354 self.dataType = header['nDataType'][0]
354 self.dtype = header['nDataType'][0]
355 355 self.blockSize = header['nSizeOfDataBlock'][0]
356 356 self.profilesPerBlock = header['nProfilesperBlock'][0]
357 357 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
358 358 self.nWindows = header['nNumWindows'][0]
359 359 self.processFlags = header['nProcessFlags']
360 360 self.nCohInt = header['nCoherentIntegrations'][0]
361 361 self.nIncohInt = header['nIncoherentIntegrations'][0]
362 362 self.totalSpectra = header['nTotalSpectra'][0]
363 363 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
364 364 self.nHeights = numpy.sum(self.samplingWindow['nsa'])
365 365 self.firstHeight = self.samplingWindow['h0'][0]
366 366 self.deltaHeight = self.samplingWindow['dh'][0]
367 367 self.samplesWin = self.samplingWindow['nsa']
368 368 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
369 369
370 370 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
371 371 self.nCode = numpy.fromfile(fp,'<u4',1)
372 372 self.nBaud = numpy.fromfile(fp,'<u4',1)
373 373 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
374 374
375 375 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
376 376 self.shif_fft = True
377 377 else:
378 378 self.shif_fft = False
379 379
380 380 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
381 381 self.flag_dc = True
382 382
383 383 nChannels = 0
384 384 nPairs = 0
385 385 pairList = []
386 386
387 387 for i in range( 0, self.totalSpectra*2, 2 ):
388 388 if self.spectraComb[i] == self.spectraComb[i+1]:
389 389 nChannels = nChannels + 1 #par de canales iguales
390 390 else:
391 391 nPairs = nPairs + 1 #par de canales diferentes
392 392 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
393 393
394 394 self.flag_cspc = False
395 395 if nPairs > 0:
396 396 self.flag_cspc = True
397 397
398 398 except:
399 399 return 0
400 400
401 401 return 1
402 402
403 403 def write(self, fp):
404 404 headerTuple = (self.size,
405 self.dataType,
405 self.dtype,
406 406 self.blockSize,
407 407 self.profilesPerBlock,
408 408 self.dataBlocksPerFile,
409 409 self.nWindows,
410 410 self.processFlags,
411 411 self.nCohInt,
412 412 self.nIncohInt,
413 413 self.totalSpectra)
414 414
415 415 header = numpy.array(headerTuple,self.struct)
416 416 header.tofile(fp)
417 417
418 418 if self.nWindows != 0:
419 419 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
420 420 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
421 421 samplingWindow.tofile(fp)
422 422
423 423
424 424 if self.totalSpectra != 0:
425 425 spectraComb = numpy.array([],numpy.dtype('u1'))
426 426 spectraComb = self.spectraComb
427 427 spectraComb.tofile(fp)
428 428
429 429
430 430 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
431 431 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
432 432 nCode.tofile(fp)
433 433
434 434 nBaud = self.nBaud
435 435 nBaud.tofile(fp)
436 436
437 437 code = self.code.reshape(nCode*nBaud)
438 438 code.tofile(fp)
439 439
440 440 return 1
441 441
442 442 class RCfunction:
443 443 NONE=0
444 444 FLIP=1
445 445 CODE=2
446 446 SAMPLING=3
447 447 LIN6DIV256=4
448 448 SYNCHRO=5
449 449
450 450 class nCodeType:
451 451 NONE=0
452 452 USERDEFINE=1
453 453 BARKER2=2
454 454 BARKER3=3
455 455 BARKER4=4
456 456 BARKER5=5
457 457 BARKER7=6
458 458 BARKER11=7
459 459 BARKER13=8
460 460 AC128=9
461 461 COMPLEMENTARYCODE2=10
462 462 COMPLEMENTARYCODE4=11
463 463 COMPLEMENTARYCODE8=12
464 464 COMPLEMENTARYCODE16=13
465 465 COMPLEMENTARYCODE32=14
466 466 COMPLEMENTARYCODE64=15
467 467 COMPLEMENTARYCODE128=16
468 468 CODE_BINARY28=17
469 469
470 470 class PROCFLAG:
471 471 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
472 472 DECODE_DATA = numpy.uint32(0x00000002)
473 473 SPECTRA_CALC = numpy.uint32(0x00000004)
474 474 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
475 475 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
476 476 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
477 477
478 478 DATATYPE_CHAR = numpy.uint32(0x00000040)
479 479 DATATYPE_SHORT = numpy.uint32(0x00000080)
480 480 DATATYPE_LONG = numpy.uint32(0x00000100)
481 481 DATATYPE_INT64 = numpy.uint32(0x00000200)
482 482 DATATYPE_FLOAT = numpy.uint32(0x00000400)
483 483 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
484 484
485 485 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
486 486 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
487 487 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
488 488
489 489 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
490 490 DEFLIP_DATA = numpy.uint32(0x00010000)
491 491 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
492 492
493 493 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
494 494 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
495 495 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
496 496 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
497 497 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
498 498
499 499 EXP_NAME_ESP = numpy.uint32(0x00200000)
500 500 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
501 501
502 502 OPERATION_MASK = numpy.uint32(0x0000003F)
503 503 DATATYPE_MASK = numpy.uint32(0x00000FC0)
504 504 DATAARRANGE_MASK = numpy.uint32(0x00007000)
505 505 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
@@ -1,516 +1,530
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import time
10 10 import datetime
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Data.JROData import SpectraHeis
15 15 from IO.SpectraIO import SpectraWriter
16 16 #from Graphics.schainPlotTypes import SpcFigure
17 17 #from JRONoise import Noise
18 18
19 19 class SpectraProcessor:
20 20 '''
21 21 classdocs
22 22 '''
23 23
24 24 dataInObj = None
25 25
26 26 dataOutObj = None
27 27
28 28 noiseObj = None
29 29
30 30 integratorObjList = []
31 31
32 32 writerObjList = []
33 33
34 34 integratorObjIndex = None
35 35
36 36 writerObjIndex = None
37 37
38 38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39 39
40 40
41 41 def __init__(self):
42 42 '''
43 43 Constructor
44 44 '''
45 45
46 46 self.integratorObjIndex = None
47 47 self.writerObjIndex = None
48 48 self.plotObjIndex = None
49 49 self.integratorOst = []
50 50 self.plotObjList = []
51 51 self.noiseObj = bjList = []
52 52 self.writerObjLiNone
53 53 self.buffer = None
54 54 self.profIndex = 0
55 55
56 56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
57 57
58 58 if dataInObj == None:
59 59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60 60
61 61 if dataInObj.type == "Voltage":
62 62 if nFFTPoints == None:
63 63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64 64 else:
65 65 nFFTPoints = dataInObj.nFFTPoints
66 66
67 67 self.dataInObj = dataInObj
68 68
69 69 if dataOutObj == None:
70 70 dataOutObj = Spectra()
71 71
72 72 self.dataOutObj = dataOutObj
73 73
74 74 return self.dataOutObj
75 75
76 76 def init(self):
77 77
78 78 self.integratorObjIndex = 0
79 79 self.writerObjIndex = 0
80 80 self.plotObjIndex = 0
81 81 if self.dataInObj.type == "Voltage":
82 82
83 83 if self.buffer == None:
84 84 self.buffer = numpy.zeros((self.nChannels,
85 85 self.nFFTPoints,
86 86 self.dataInObj.nHeights),
87 87 dtype='complex')
88 88
89 89 self.buffer[:,self.profIndex,:] = self.dataInObj.data
90 90 self.profIndex += 1
91 91
92 92 if self.profIndex == self.nFFTPoints:
93 93 self.__getFft()
94 94 self.dataOutObj.flagNoData = False
95 95
96 96 self.buffer = None
97 97 self.profIndex = 0
98 98 return
99 99
100 100 self.dataOutObj.flagNoData = True
101 101
102 102 return
103 103
104 104 #Other kind of data
105 105 if self.dataInObj.type == "Spectra":
106 106 self.dataOutObj.copy(self.dataInObj)
107 107 self.dataOutObj.flagNoData = False
108 108 return
109 109
110 raise ValueError, "The datatype is not valid"
110 raise ValueError, "The dtype is not valid"
111 111
112 112 def __getFft(self):
113 113 """
114 114 Convierte valores de Voltaje a Spectra
115 115
116 116 Affected:
117 117 self.dataOutObj.data_spc
118 118 self.dataOutObj.data_cspc
119 119 self.dataOutObj.data_dc
120 120 self.dataOutObj.heightList
121 121 self.dataOutObj.m_BasicHeader
122 122 self.dataOutObj.m_ProcessingHeader
123 self.dataOutObj.m_RadarControllerHeader
124 self.dataOutObj.m_SystemHeader
123 self.dataOutObj.radarControllerHeaderObj
124 self.dataOutObj.systemHeaderObj
125 125 self.profIndex
126 126 self.buffer
127 127 self.dataOutObj.flagNoData
128 self.dataOutObj.dataType
128 self.dataOutObj.dtype
129 129 self.dataOutObj.nPairs
130 130 self.dataOutObj.nChannels
131 131 self.dataOutObj.nProfiles
132 self.dataOutObj.m_SystemHeader.numChannels
132 self.dataOutObj.systemHeaderObj.numChannels
133 133 self.dataOutObj.m_ProcessingHeader.totalSpectra
134 134 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
135 135 self.dataOutObj.m_ProcessingHeader.numHeights
136 136 self.dataOutObj.m_ProcessingHeader.spectraComb
137 137 self.dataOutObj.m_ProcessingHeader.shif_fft
138 138 """
139 139
140 140 if self.dataInObj.flagNoData:
141 141 return 0
142 142
143 143 fft_volt = numpy.fft.fft(self.buffer,axis=1)
144 144 dc = fft_volt[:,0,:]
145 145
146 146 #calculo de self-spectra
147 147 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
148 148 spc = fft_volt * numpy.conjugate(fft_volt)
149 149 spc = spc.real
150 150
151 151 blocksize = 0
152 152 blocksize += dc.size
153 153 blocksize += spc.size
154 154
155 155 cspc = None
156 156 pairIndex = 0
157 157 if self.pairList != None:
158 158 #calculo de cross-spectra
159 159 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
160 160 for pair in self.pairList:
161 161 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
162 162 pairIndex += 1
163 163 blocksize += cspc.size
164 164
165 165 self.dataOutObj.data_spc = spc
166 166 self.dataOutObj.data_cspc = cspc
167 167 self.dataOutObj.data_dc = dc
168 168 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
169 169 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
170 170
171 171 # self.getNoise()
172 172
173 173 def addWriter(self, wrpath, blocksPerFile):
174 174 objWriter = SpectraWriter(self.dataOutObj)
175 175 objWriter.setup(wrpath, blocksPerFile)
176 176 self.writerObjList.append(objWriter)
177 177
178 178 def addIntegrator(self,N,timeInterval):
179 179
180 180 objIncohInt = IncoherentIntegration(N,timeInterval)
181 181 self.integratorObjList.append(objIncohInt)
182 182
183 183 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
184 184 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
185 185 self.plotObjList.append(spcObj)
186 186
187 187 def plotSpc(self, idfigure=None,
188 188 xmin=None,
189 189 xmax=None,
190 190 ymin=None,
191 191 ymax=None,
192 192 minvalue=None,
193 193 maxvalue=None,
194 194 wintitle='',
195 195 driver='plplot',
196 196 colormap='br_greeen',
197 197 colorbar=True,
198 198 showprofile=False,
199 199 save=False,
200 200 gpath=None):
201 201
202 202 if self.dataOutObj.flagNoData:
203 203 return 0
204 204
205 205 nframes = len(self.dataOutObj.channelList)
206 206
207 207 if len(self.plotObjList) <= self.plotObjIndex:
208 208 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
209 209
210 210 x = numpy.arange(self.dataOutObj.nFFTPoints)
211 211
212 212 y = self.dataOutObj.heightList
213 213
214 214 channelList = self.dataOutObj.channelList
215 215
216 216 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
217 217 # noisedB = 10.*numpy.log10(noise)
218 218 noisedB = numpy.arange(len(channelList)+1)
219 219 noisedB = noisedB *1.2
220 220 titleList = []
221 221 for i in range(len(noisedB)):
222 222 title = "%.2f"%noisedB[i]
223 223 titleList.append(title)
224 224
225 225 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
226 226 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
227 227 figuretitle = "Spc Radar Data: %s"%dateTime
228 228
229 229 cleardata = True
230 230
231 231 plotObj = self.plotObjList[self.plotObjIndex]
232 232
233 233 plotObj.plotPcolor(data,
234 234 x,
235 235 y,
236 236 channelList,
237 237 xmin,
238 238 xmax,
239 239 ymin,
240 240 ymax,
241 241 minvalue,
242 242 maxvalue,
243 243 figuretitle,
244 244 None,
245 245 save,
246 246 gpath,
247 247 cleardata,
248 248 titleList)
249 249
250 250 self.plotObjIndex += 1
251 251
252 252
253 253 def writeData(self, wrpath, blocksPerFile):
254 254 if self.dataOutObj.flagNoData:
255 255 return 0
256 256
257 257 if len(self.writerObjList) <= self.writerObjIndex:
258 258 self.addWriter(wrpath, blocksPerFile)
259 259
260 260 self.writerObjList[self.writerObjIndex].putData()
261 261
262 262 self.writerObjIndex += 1
263 263
264 264 def integrator(self, N=None, timeInterval=None):
265 265
266 266 if self.dataOutObj.flagNoData:
267 267 return 0
268 268
269 269 if len(self.integratorObjList) <= self.integratorObjIndex:
270 270 self.addIntegrator(N,timeInterval)
271 271
272 272 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
273 273 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
274 274
275 275 if myIncohIntObj.isReady:
276 276 self.dataOutObj.data_spc = myIncohIntObj.data
277 277 self.dataOutObj.nAvg = myIncohIntObj.navg
278 278 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
279 279 self.dataOutObj.flagNoData = False
280 280
281 281 """Calcular el ruido"""
282 282 self.getNoise()
283 283 else:
284 284 self.dataOutObj.flagNoData = True
285 285
286 286 self.integratorObjIndex += 1
287 287
288 288
289 289 class SpectraHeisProcessor:
290
290 291 def __init__(self):
292
291 293 self.integratorObjIndex = None
292 294 self.writerObjIndex = None
293 295 self.plotterObjIndex = None
294 296 self.integratorObjList = []
295 297 self.writerObjList = []
296 298 self.plotterObjList = []
297 299 #self.noiseObj = Noise()
298 300
299 def setup(self,dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
300 if dataInObj == None:
301 raise ValueError, ""
301 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
302 302
303 303 if nFFTPoints == None:
304 raise ValueError, ""
304 nFFTPoints = self.dataInObj.nHeights
305 305
306 306 self.dataInObj = dataInObj
307 307
308 308 if dataOutObj == None:
309 309 dataOutObj = SpectraHeis()
310 310
311 311 self.dataOutObj = dataOutObj
312 312 # self.noiseObj = Noise()
313 313
314 314 ##########################################
315 315 self.nFFTPoints = nFFTPoints
316 316 self.nChannels = self.dataInObj.nChannels
317 317 self.nHeights = self.dataInObj.nHeights
318 318 self.pairList = pairList
319
319 320 if pairList != None:
320 321 self.nPairs = len(pairList)
321 322 else:
322 323 self.nPairs = 0
323 324
324 self.dataOutObj.heightList = self.dataInObj.heightList
325 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
326 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
327 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
325 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
326 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
327
328 self.dataOutObj.type = "SpectraHeis"
329
330 self.dataOutObj.dtype = self.dataInObj.dtype
328 331
329 self.dataOutObj.dataType = self.dataInObj.dataType
330 self.dataOutObj.nPairs = self.nPairs
331 332 self.dataOutObj.nChannels = self.nChannels
332 self.dataOutObj.nProfiles = self.nFFTPoints
333
333 334 self.dataOutObj.nHeights = self.nHeights
334 self.dataOutObj.nFFTPoints = self.nFFTPoints
335 #self.dataOutObj.data = None
336 335
337 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
338 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
336 self.dataOutObj.nProfiles = self.nFFTPoints
339 337
340 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
341 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
342 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
343 self.dataOutObj.m_ProcessingHeader.shif_fft = True
338 self.dataOutObj.heightList = None
344 339
345 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
346 k = 0
347 for i in range( 0,self.nChannels*2,2 ):
348 spectraComb[i] = k
349 spectraComb[i+1] = k
350 k += 1
340 self.dataOutObj.channelList = None
351 341
352 k *= 2
342 self.dataOutObj.channelIndexList = None
353 343
354 if self.pairList != None:
344 self.dataOutObj.flagNoData = False
355 345
356 for pair in self.pairList:
357 spectraComb[k] = pair[0]
358 spectraComb[k+1] = pair[1]
359 k += 2
346 self.dataOutObj.flagTimeBlock = False
347
348 self.dataOutObj.dataUtcTime = None
349
350 self.dataOutObj.nCode = None
351
352 self.dataOutObj.nBaud = None
353
354 self.dataOutObj.code = None
355
356 self.dataOutObj.flagDecodeData = True #asumo q la data esta decodificada
357
358 self.dataOutObj.flagDeflipData = True #asumo q la data esta sin flip
359
360 self.dataOutObj.flagShiftFFT = False
361
362 self.dataOutObj.ippSeconds = None
363
364 self.dataOutObjdata_spc = None
365
366 self.dataOutObjdata_cspc = None
367
368 self.dataOutObjdata_dc = None
369
370 self.dataOutObjnFFTPoints = None
371
372 self.dataOutObjnPairs = None
373
374 self.dataOutObjpairsList = None
360 375
361 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
362 376
363 377 return self.dataOutObj
364 378
365 379 def init(self):
366 380 self.integratorObjIndex = 0
367 381 self.writerObjIndex = 0
368 382 self.plotterObjIndex = 0
369 383
370 384 if self.dataInObj.type == "Voltage":
371 385 self.__getFft()
372 386 self.dataOutObj.flagNoData = False
373 387 return
374 388
375 389 #Other kind of data
376 390 if self.dataInObj.type == "SpectraHeis":
377 391 self.dataOutObj.copy(self.dataInObj)
378 392 self.dataOutObj.flagNoData = False
379 393 return
380 394
381 raise ValueError, "The datatype is not valid"
395 raise ValueError, "The type is not valid"
382 396
383 397 def __getFft(self):
384 398 if self.dataInObj.flagNoData:
385 399 return 0
386 400
387 401 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
388 402 #print fft_volt
389 403 #calculo de self-spectra
390 404 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
391 405
392 406 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
393 407 self.dataOutObj.data_spc = spc
394 408 #print spc
395 409
396 410 def getSpectra(self):
397 411
398 412 return self.dataOutObj.data_spc
399 413
400 414 def getFrecuencies(self):
401 415
402 416 print self.nFFTPoints
403 417 return numpy.arange(int(self.nFFTPoints))
404 418
405 419 def addIntegrator(self,N,timeInterval):
406 420 objIncohInt = IncoherentIntegration(N,timeInterval)
407 421 self.integratorObjList.append(objIncohInt)
408 422
409 423 def integrator(self, N=None, timeInterval=None):
410 424 if self.dataOutObj.flagNoData:
411 425 return 0
412 426
413 427 if len(self.integratorObjList) <= self.integratorObjIndex:
414 428 self.addIntegrator(N,timeInterval)
415 429
416 430 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
417 431 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
418 432
419 433 if myIncohIntObj.isReady:
420 434 self.dataOutObj.data_spc = myIncohIntObj.data
421 435 self.dataOutObj.nAvg = myIncohIntObj.navg
422 436 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
423 437 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
424 438 self.dataOutObj.flagNoData = False
425 439
426 440 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
427 441 # self.getNoise(type="sort", parm=16)
428 442
429 443 else:
430 444 self.dataOutObj.flagNoData = True
431 445
432 446 self.integratorObjIndex += 1
433 447
434 448
435 449
436 450 class IncoherentIntegration:
437 451
438 452 integ_counter = None
439 453 data = None
440 454 navg = None
441 455 buffer = None
442 456 nIncohInt = None
443 457
444 458 def __init__(self, N = None, timeInterval = None):
445 459 """
446 460 N
447 461 timeInterval - interval time [min], integer value
448 462 """
449 463
450 464 self.data = None
451 465 self.navg = None
452 466 self.buffer = None
453 467 self.timeOut = None
454 468 self.exitCondition = False
455 469 self.isReady = False
456 470 self.nIncohInt = N
457 471 self.integ_counter = 0
458 472 if timeInterval!=None:
459 473 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
460 474
461 475 if ((timeInterval==None) and (N==None)):
462 476 print 'N = None ; timeInterval = None'
463 477 sys.exit(0)
464 478 elif timeInterval == None:
465 479 self.timeFlag = False
466 480 else:
467 481 self.timeFlag = True
468 482
469 483
470 484 def exe(self,data,timeOfData):
471 485 """
472 486 data
473 487
474 488 timeOfData [seconds]
475 489 """
476 490
477 491 if self.timeFlag:
478 492 if self.timeOut == None:
479 493 self.timeOut = timeOfData + self.timeIntervalInSeconds
480 494
481 495 if timeOfData < self.timeOut:
482 496 if self.buffer == None:
483 497 self.buffer = data
484 498 else:
485 499 self.buffer = self.buffer + data
486 500 self.integ_counter += 1
487 501 else:
488 502 self.exitCondition = True
489 503
490 504 else:
491 505 if self.integ_counter < self.nIncohInt:
492 506 if self.buffer == None:
493 507 self.buffer = data
494 508 else:
495 509 self.buffer = self.buffer + data
496 510
497 511 self.integ_counter += 1
498 512
499 513 if self.integ_counter == self.nIncohInt:
500 514 self.exitCondition = True
501 515
502 516 if self.exitCondition:
503 517 self.data = self.buffer
504 518 self.navg = self.integ_counter
505 519 self.isReady = True
506 520 self.buffer = None
507 521 self.timeOut = None
508 522 self.integ_counter = 0
509 523 self.exitCondition = False
510 524
511 525 if self.timeFlag:
512 526 self.buffer = data
513 527 self.timeOut = timeOfData + self.timeIntervalInSeconds
514 528 else:
515 529 self.isReady = False
516 530 No newline at end of file
@@ -1,372 +1,372
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os
8 8 import sys
9 9 import numpy
10 10 import datetime
11 11 import time
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from Data.JROData import Voltage
17 17 from IO.VoltageIO import VoltageWriter
18 18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
19 19
20 20 class VoltageProcessor:
21 21
22 22 dataInObj = None
23 23 dataOutObj = None
24 24 integratorObjIndex = None
25 25 writerObjIndex = None
26 26 integratorObjList = None
27 27 writerObjList = None
28 28
29 29 def __init__(self):
30 30 self.integratorObjIndex = None
31 31 self.writerObjIndex = None
32 32 self.plotObjIndex = None
33 33 self.integratorObjList = []
34 34 self.writerObjList = []
35 35 self.plotObjList = []
36 36
37 37 def setup(self,dataInObj=None,dataOutObj=None):
38 38 self.dataInObj = dataInObj
39 39
40 40 if self.dataOutObj == None:
41 41 dataOutObj = Voltage()
42 42
43 43 self.dataOutObj = dataOutObj
44 44
45 45 return self.dataOutObj
46 46
47 47 def init(self):
48 48 self.integratorObjIndex = 0
49 49 self.writerObjIndex = 0
50 50 self.plotObjIndex = 0
51 51
52 52 if not(self.dataInObj.flagNoData):
53 53 self.dataOutObj.copy(self.dataInObj)
54 54 # No necesita copiar en cada init() los atributos de dataInObj
55 55 # la copia deberia hacerse por cada nuevo bloque de datos
56 56
57 57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
58 58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
59 59 self.plotObjList.append(rtiObj)
60 60
61 61 def plotRti(self, idfigure=None,
62 62 starttime=None,
63 63 endtime=None,
64 64 rangemin=None,
65 65 rangemax=None,
66 66 minvalue=None,
67 67 maxvalue=None,
68 68 wintitle='',
69 69 driver='plplot',
70 70 colormap='br_greeen',
71 71 colorbar=True,
72 72 showprofile=False,
73 73 xrangestep=None,
74 74 save=False,
75 75 gpath=None):
76 76
77 77 if self.dataOutObj.flagNoData:
78 78 return 0
79 79
80 80 nframes = len(self.dataOutObj.channelList)
81 81
82 82 if len(self.plotObjList) <= self.plotObjIndex:
83 83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84 84
85 85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
86 86 data = 10*numpy.log10(data.real)
87 87
88 88 # currenttime = self.dataOutObj.dataUtcTime
89 89 # if timezone == "lt":
90 90 currenttime = self.dataOutObj.dataUtcTime - time.timezone
91 91
92 92 range = self.dataOutObj.heightList
93 93
94 94 channelList = self.dataOutObj.channelList
95 95
96 96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
97 97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
98 98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
99 99
100 100 figuretitle = "RTI Plot Radar Data" #+ date
101 101
102 102 plotObj = self.plotObjList[self.plotObjIndex]
103 103
104 104 cleardata = False
105 105
106 106 plotObj.plotPcolor(data,
107 107 currenttime,
108 108 range,
109 109 channelList,
110 110 starttime,
111 111 endtime,
112 112 rangemin,
113 113 rangemax,
114 114 minvalue,
115 115 maxvalue,
116 116 figuretitle,
117 117 xrangestep,
118 118 save,
119 119 gpath,
120 120 cleardata)
121 121
122 122 self.plotObjIndex += 1
123 123
124 124 def addScope(self, idfigure, nframes, wintitle, driver):
125 125 if idfigure==None:
126 126 idfigure = self.plotObjIndex
127 127
128 128 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
129 129 self.plotObjList.append(scopeObj)
130 130
131 131 def plotScope(self,
132 132 idfigure=None,
133 133 minvalue=None,
134 134 maxvalue=None,
135 135 xmin=None,
136 136 xmax=None,
137 137 wintitle='',
138 138 driver='plplot',
139 139 save=False,
140 140 gpath=None,
141 141 titleList=None,
142 142 xlabelList=None,
143 143 ylabelList=None,
144 144 type="power"):
145 145
146 146 if self.dataOutObj.flagNoData:
147 147 return 0
148 148
149 149 nframes = len(self.dataOutObj.channelList)
150 150
151 151 if len(self.plotObjList) <= self.plotObjIndex:
152 152 self.addScope(idfigure, nframes, wintitle, driver)
153 153
154 154
155 155 if type=="power":
156 156 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
157 157 data1D = data1D.real
158 158
159 159 if type =="iq":
160 160 data1D = self.dataOutObj.data
161 161
162 162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
163 163
164 164 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
165 165 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
166 166
167 167 figureTitle = "Scope Plot Radar Data: " + date
168 168
169 169 plotObj = self.plotObjList[self.plotObjIndex]
170 170
171 171 plotObj.plot1DArray(data1D,
172 172 self.dataOutObj.heightList,
173 173 self.dataOutObj.channelList,
174 174 xmin,
175 175 xmax,
176 176 minvalue,
177 177 maxvalue,
178 178 figureTitle,
179 179 save,
180 180 gpath)
181 181
182 182 self.plotObjIndex += 1
183 183
184 184
185 185 def addIntegrator(self, *args):
186 186 objCohInt = CoherentIntegrator(*args)
187 187 self.integratorObjList.append(objCohInt)
188 188
189 189 def addWriter(self, *args):
190 190 writerObj = VoltageWriter(self.dataOutObj)
191 191 writerObj.setup(*args)
192 192 self.writerObjList.append(writerObj)
193 193
194 194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
195 195
196 196 if self.dataOutObj.flagNoData:
197 197 return 0
198 198
199 199 if len(self.writerObjList) <= self.writerObjIndex:
200 200 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
201 201
202 202 self.writerObjList[self.writerObjIndex].putData()
203 203
204 204 self.writerObjIndex += 1
205 205
206 206 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
207 207
208 208 if self.dataOutObj.flagNoData:
209 209 return 0
210 210
211 211 if len(self.integratorObjList) <= self.integratorObjIndex:
212 212 self.addIntegrator(nCohInt, timeInterval, overlapping)
213 213
214 214 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
215 215 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
216 216
217 217 self.dataOutObj.flagNoData = True
218 218
219 219 if myCohIntObj.isReady:
220 220 self.dataOutObj.flagNoData = False
221 221
222 222
223 223
224 224 class CoherentIntegrator:
225 225
226 226
227 227 __profIndex = 0
228 228 __withOverapping = False
229 229
230 230 __isByTime = False
231 231 __initime = None
232 232 __integrationtime = None
233 233
234 234 __buffer = None
235 235
236 236 isReady = False
237 237 nCohInt = None
238 238
239 239
240 240 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
241 241
242 242 """
243 243 Set the parameters of the integration class.
244 244
245 245 Inputs:
246 246
247 247 nCohInt : Number of coherent integrations
248 248 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
249 249 overlapping :
250 250
251 251 """
252 252
253 253 self.__buffer = None
254 254 self.isReady = False
255 255
256 256 if nCohInt == None and timeInterval == None:
257 257 raise ValueError, "nCohInt or timeInterval should be specified ..."
258 258
259 259 if nCohInt != None:
260 260 self.nCohInt = nCohInt
261 261 self.__isByTime = False
262 262 else:
263 263 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
264 264 self.__isByTime = True
265 265
266 266 if overlapping:
267 267 self.__withOverapping = True
268 268 self.__buffer = None
269 269 else:
270 270 self.__withOverapping = False
271 271 self.__buffer = 0
272 272
273 273 self.__profIndex = 0
274 274
275 275 def putData(self, data):
276 276
277 277 """
278 278 Add a profile to the __buffer and increase in one the __profileIndex
279 279
280 280 """
281 281 if not self.__withOverapping:
282 282 self.__buffer += data
283 283 self.__profIndex += 1
284 284 return
285 285
286 286 #Overlapping data
287 nChannels, nProfiles = data.shape
288 data = numpy.reshape(data, (1, nChannels, nProfiles))
287 nChannels, nHeis = data.shape
288 data = numpy.reshape(data, (1, nChannels, nHeis))
289 289
290 290 if self.__buffer == None:
291 291 self.__buffer = data
292 292 self.__profIndex += 1
293 293 return
294 294
295 295 if self.__profIndex < self.nCohInt:
296 296 self.__buffer = numpy.vstack((self.__buffer, data))
297 297 self.__profIndex += 1
298 298 return
299 299
300 300 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
301 301 self.__buffer[self.nCohInt-1] = data
302 302 #self.__profIndex = self.nCohInt
303 303 return
304 304
305 305
306 306 def pushData(self):
307 307 """
308 308 Return the sum of the last profiles and the profiles used in the sum.
309 309
310 310 Affected:
311 311
312 312 self.__profileIndex
313 313
314 314 """
315 315
316 316 if not self.__withOverapping:
317 317 data = self.__buffer
318 318 nCohInt = self.__profIndex
319 319
320 320 self.__buffer = 0
321 321 self.__profIndex = 0
322 322
323 323 return data, nCohInt
324 324
325 325 #Overlapping data
326 326 data = numpy.sum(self.__buffer, axis=0)
327 327 nCohInt = self.__profIndex
328 328
329 329 return data, nCohInt
330 330
331 331 def byProfiles(self, data):
332 332
333 333 self.isReady = False
334 334 avg_data = None
335 335
336 336 self.putData(data)
337 337
338 338 if self.__profIndex == self.nCohInt:
339 339 avg_data, nCohInt = self.pushData()
340 340 self.isReady = True
341 341
342 342 return avg_data
343 343
344 344 def byTime(self, data, datatime):
345 345
346 346 self.isReady = False
347 347 avg_data = None
348 348
349 349 if self.__initime == None:
350 350 self.__initime = datatime
351 351
352 352 self.putData(data)
353 353
354 354 if (datatime - self.__initime) >= self.__integrationtime:
355 355 avg_data, nCohInt = self.pushData()
356 356 self.nCohInt = nCohInt
357 357 self.isReady = True
358 358
359 359 return avg_data
360 360
361 361 def exe(self, data, datatime=None):
362 362
363 363 if not self.__isByTime:
364 364 avg_data = self.byProfiles(data)
365 365 else:
366 366 avg_data = self.byTime(data, datatime)
367 367
368 368 self.data = avg_data
369 369
370 370 return avg_data
371 371
372 372
@@ -1,159 +1,160
1 1 '''
2 2 Created on Jul 31, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import time, datetime
10 10 #import pylab as pl
11 11
12 12 from Data.JROData import Voltage
13 13 from IO.VoltageIO import *
14 14
15 15 from Data.JROData import SpectraHeis
16 16 from IO.SpectraIO import *
17 17
18 18 from Processing.VoltageProcessor import *
19 19 from Processing.SpectraProcessor import *
20 20
21 21 from Graphics.BaseGraph_mpl import LinearPlot
22 22
23 23 class TestHeis():
24 24 i=None
25 25 def __init__(self):
26 26 self.setValues()
27 27 self.createObjects()
28 28 self.testSChain()
29 29 self.i=0
30
30 31 def setValues( self ):
31 32
32 33 self.path="C:\data2"
33 34 self.startDate = datetime.date(2012,4,1)
34 35 self.endDate = datetime.date(2012,6,30)
35 36
36 37 self.startTime = datetime.time(0,0,0)
37 38 self.endTime = datetime.time(23,0,0)
38 39 #self.N = 4
39 40 #self.npts = 8
40 41
41 42 def createObjects( self ):
42 43
43 44 self.readerObj = VoltageReader()
44 45 self.specProcObj = SpectraHeisProcessor()
45 46
46 47 self.voltObj1 = self.readerObj.setup(
47 48 path = self.path,
48 49 startDate = self.startDate,
49 50 endDate = self.endDate,
50 51 startTime = self.startTime,
51 52 endTime = self.endTime,
52 53 expLabel = '',
53 54 online = 0)
54 55
55 56 if not(self.voltObj1):
56 57 sys.exit(0)
57 58
58 59 print "voltaje o alturas: %03d"%(self.voltObj1.nHeights)
59 60 #print "perfiles: %03d"%(self.voltObj1.nProfiles)
60 61 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights)
61 62
62 63
63 64
64 65 print "nChannels: %03d"%(self.specObj1.nChannels)
65 66 print "nHeights: %03d"%( self.specObj1.nHeights)
66 67 print "nFFTPoints: %03d"% int(self.specObj1.nFFTPoints)
67 68
68 69
69 70 def testSChain( self ):
70 71
71 72 ini = time.time()
72 73
73 74 while(True):
74 75 self.readerObj.getData()
75 76 #print self.readerObj.datablock
76 77 #self.voltProcObj.init()
77 78 self.specProcObj.init()
78 79
79 80 self.specProcObj.integrator(N=32) ## return self.dataOutObj
80 81
81 82 self.plot()
82 83 #print self.readerObj.dataOutObj.data
83 84
84 85 #CON TODO ESTO PLoTEO
85 86 #freq = self.specProcObj.getFrecuencies()
86 87 #spc = self.specProcObj.getSpectra()
87 88 # print freq
88 89 # print spc, spc.shape
89 90 # pl.plot(freq, spc[2])
90 91 # pl.show()
91 92
92 93 if self.readerObj.flagNoMoreFiles:
93 94 break
94 95
95 96 if self.readerObj.flagIsNewBlock:
96 97 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
97 98 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
98 99
99 100
100 101 def plot(self):
101 102
102 103 # x = self.specProcObj.getFrecuencies()
103 104 x = numpy.arange(self.specObj1.nFFTPoints)
104 105 spc = self.specObj1.data_spc
105 106 # spc = self.specProcObj.getSpectra()
106 107 nchannels = self.specObj1.nChannels
107 108
108 109 # y1=spc[0]
109 110 # y2=spc[1]
110 111 # y3=spc[2]
111 112 # y4=spc[3]
112 113
113 114 # signalList=[y1,y2,y3,y4]
114 115 # xmin = numpy.min(x)
115 116 # xmax = numpy.max(x)
116 117
117 118 #Creating Object
118 119 indexPlot = 1
119 120 nsubplot = nchannels
120 121 #nsubplot = 1
121 122 print "nsubplot:%d"%(nsubplot)
122 123 winTitle = "mi grafico de Espectrov1"
123 124
124 125 subplotTitle = "subplot-Espectro - No Channel."
125 126 xlabel = ""
126 127 ylabel = ""
127 128
128 129 linearObj = LinearPlot(indexPlot,nsubplot,winTitle)
129 130
130 131 #Config SubPlots
131 132 print "ConfigSubPlots"
132 133 print "nsubplot: %d "%nsubplot
133 134 for subplot in range(nsubplot):
134 135 indexplot = subplot + 1
135 136 name=subplot+1
136 137 print "Channel: %d"%(name)
137 138 title = subplotTitle + '%d'%name
138 139 xmin = numpy.min(x)
139 140 xmax = numpy.max(x)
140 141 ymin = numpy.min(spc[subplot])
141 142 ymax = numpy.max(spc[subplot])
142 143 linearObj.setup(indexplot, xmin, xmax, ymin, ymax, title, xlabel, ylabel)
143 144
144 145 #Plotting
145 146 type = "simple"
146 147 print "Ploteando"
147 148 print "nsubplot: %d "%nsubplot
148 149 for subplot in range(nsubplot):
149 150 indexplot = subplot + 1
150 151 y = spc[subplot,:]
151 152 linearObj.plot(indexplot, x, y, type)
152 153
153 154 linearObj.refresh()
154 155 linearObj.show()
155 156
156 157 if __name__ == '__main__':
157 158 TestHeis()
158 159
159 160 No newline at end of file
@@ -1,92 +1,86
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6 import os, sys
7 7 import time, datetime
8 8
9 9 path = os.path.split(os.getcwd())[0]
10 10 sys.path.append(path)
11 11
12 from Data.Voltage import Voltage
12 from Data.JROData import Voltage
13 13 from IO.VoltageIO import *
14 14
15 15 from Processing.VoltageProcessor import *
16 16
17 17
18 18 class TestSChain():
19 19
20 20 def __init__(self):
21 21 self.setValues()
22 22 self.createObjects()
23 23 self.testSChain()
24 24
25 25 def setValues(self):
26 self.path = "/home/dsuarez/RadarData/EW_DRIFTS"
27 self.startDate = datetime.date(2012,6,1)
28 self.endDate = datetime.date(2012,7,30)
29
30 # self.path = "/Users/danielangelsuarezmunoz/Data/Imaging_rawdata"
31 # self.startDate = datetime.date(2011,10,4)
32 # self.endDate = datetime.date(2011,10,4)
26 self.path = "/home/roj-idl71/Data/RAWDATA/Meteors"
33 27
34 # Probando los escritos por Signal Chain
35 # self.path = "/home/dsuarez/RadaData"
36 # self.startDate = datetime.date(2011,11,28)
37 # self.endDate = datetime.date(2011,11,30)
28 self.startDate = datetime.date(2005,1,1)
29 self.endDate = datetime.date(2012,7,30)
38 30
39 31 self.startTime = datetime.time(0,0,0)
40 32 self.endTime = datetime.time(23,59,59)
41 33
42 self.wrpath = "/home/dsuarez/RadarData"
34 self.wrpath = "/home/roj-idl71/tmp/results"
43 35 self.profilesPerBlock = 40
44 36 self.blocksPerFile = 50
45 37
46 38 def createObjects(self):
47 39
48 40 self.readerObj = VoltageReader()
41 self.voltProcObj = VoltageProcessor()
42 self.specProcObj = SpectraProcessor()
49 43
50 44 self.voltObj1 = self.readerObj.setup(
51 45 path = self.path,
52 46 startDate = self.startDate,
53 47 endDate = self.endDate,
54 48 startTime = self.startTime,
55 49 endTime = self.endTime,
56 50 expLabel = '',
57 51 online = 0)
58 52
59 self.voltObjProc = VoltageProcessor()
60
61 self.voltObj2 = self.voltObjProc.setup(dataInObj = self.voltObj1)
53 self.voltObj2 = self.voltProcObj.setup(dataInObj = self.voltObj1)
62 54
63 55 def testSChain(self):
64 56
65 57 ini = time.time()
66 58
67 59 while(True):
68 60 self.readerObj.getData()
69 61
70 self.voltObjProc.init()
62 self.voltProcObj.init()
63
64 self.voltProcObj.integrator(1000, overlapping=True)
71 65 #
72 # self.voltObjProc.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile)
66 # self.voltProcObj.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile)
73 67
74 68
75 self.voltObjProc.plotScope(idfigure=1,
69 self.voltProcObj.plotScope(idfigure=1,
76 70 wintitle='test plot library',
77 71 driver='plplot',
78 72 save=False,
79 73 gpath=None,
80 74 type="power")
81 75
82 76 if self.readerObj.flagNoMoreFiles:
83 77 break
84 78
85 79 if self.readerObj.flagIsNewBlock:
86 80 # print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),)
87 81 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
88 82 datetime.datetime.utcfromtimestamp(self.readerObj.basicHeaderObj.utc + self.readerObj.basicHeaderObj.miliSecond/1000.0),)
89 83
90 84
91 85 if __name__ == '__main__':
92 86 TestSChain() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now