##// END OF EJS Templates
actualizacion para SpectraHeis
Alexander Valdez -
r171:51b2ad4fcfc8
parent child
Show More
@@ -1,244 +1,248
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 = True
44 44
45 45 flagTimeBlock = False
46 46
47 47 utctime = None
48 48
49 49 blocksize = None
50 50
51 51 nCode = None
52 52
53 53 nBaud = None
54 54
55 55 code = None
56 56
57 57 flagDecodeData = True #asumo q la data esta decodificada
58 58
59 59 flagDeflipData = True #asumo q la data esta sin flip
60 60
61 61 flagShiftFFT = False
62 62
63 63 ippSeconds = None
64 64
65 65 timeInterval = None
66
67 set=None
68
69 deltaHeight = None
66 70
67 71 def __init__(self):
68 72
69 73 raise ValueError, "This class has not been implemented"
70 74
71 75 def copy(self, inputObj=None):
72 76
73 77 if inputObj == None:
74 78 return copy.deepcopy(self)
75 79
76 80 for key in inputObj.__dict__.keys():
77 81 self.__dict__[key] = inputObj.__dict__[key]
78 82
79 83 def deepcopy(self):
80 84
81 85 return copy.deepcopy(self)
82 86
83 87 class Voltage(JROData):
84 88
85 89 nCohInt = None
86 90
87 91 #data es un numpy array de 2 dmensiones (canales, alturas)
88 92 data = None
89 93
90 94 def __init__(self):
91 95 '''
92 96 Constructor
93 97 '''
94 98
95 99 self.radarControllerHeaderObj = RadarControllerHeader()
96 100
97 101 self.systemHeaderObj = SystemHeader()
98 102
99 103 self.type = "Voltage"
100 104
101 105 self.data = None
102 106
103 107 self.dtype = None
104 108
105 109 self.nChannels = 0
106 110
107 111 self.nHeights = 0
108 112
109 113 self.nProfiles = None
110 114
111 115 self.heightList = None
112 116
113 117 self.channelList = None
114 118
115 119 self.channelIndexList = None
116 120
117 121 self.flagNoData = True
118 122
119 123 self.flagTimeBlock = False
120 124
121 125 self.utctime = None
122 126
123 127 self.nCohInt = None
124 128
125 129 self.blocksize = None
126 130
127 131 class Spectra(JROData):
128 132
129 133 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
130 134 data_spc = None
131 135
132 136 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
133 137 data_cspc = None
134 138
135 139 #data es un numpy array de 2 dmensiones (canales, alturas)
136 140 data_dc = None
137 141
138 142 nFFTPoints = None
139 143
140 144 nPairs = None
141 145
142 146 pairsList = None
143 147
144 148 nIncohInt = None
145 149
146 150 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
147 151
148 152 nCohInt = None #se requiere para determinar el valor de timeInterval
149 153
150 154 def __init__(self):
151 155 '''
152 156 Constructor
153 157 '''
154 158
155 159 self.radarControllerHeaderObj = RadarControllerHeader()
156 160
157 161 self.systemHeaderObj = SystemHeader()
158 162
159 163 self.type = "Spectra"
160 164
161 165 # self.data = None
162 166
163 167 self.dtype = None
164 168
165 169 self.nChannels = 0
166 170
167 171 self.nHeights = 0
168 172
169 173 self.nProfiles = None
170 174
171 175 self.heightList = None
172 176
173 177 self.channelList = None
174 178
175 179 self.channelIndexList = None
176 180
177 181 self.flagNoData = True
178 182
179 183 self.flagTimeBlock = False
180 184
181 185 self.utctime = None
182 186
183 187 self.nIncohInt = None
184 188
185 189 self.blocksize = None
186 190
187 191 self.nFFTPoints = None
188 192
189 193 self.wavelength = None
190 194
191 195 def getFrequencies(self):
192 196
193 197 xrange = numpy.arange(self.nFFTPoints)
194 198 xrange = xrange
195 199 return None
196 200
197 201
198 202 class SpectraHeis(JROData):
199 203
200 204 data_spc = None
201 205
202 206 data_cspc = None
203 207
204 208 data_dc = None
205 209
206 210 nFFTPoints = None
207 211
208 212 nPairs = None
209 213
210 214 pairsList = None
211 215
212 216 nIncohInt = None
213 217
214 218 def __init__(self):
215 219
216 220 self.radarControllerHeaderObj = RadarControllerHeader()
217 221
218 222 self.systemHeaderObj = SystemHeader()
219 223
220 224 self.type = "SpectraHeis"
221 225
222 226 self.dtype = None
223 227
224 228 self.nChannels = 0
225 229
226 230 self.nHeights = 0
227 231
228 232 self.nProfiles = None
229 233
230 234 self.heightList = None
231 235
232 236 self.channelList = None
233 237
234 238 self.channelIndexList = None
235 239
236 240 self.flagNoData = True
237 241
238 242 self.flagTimeBlock = False
239 243
240 244 self.nPairs = 0
241 245
242 246 self.utctime = None
243 247
244 248 self.blocksize = None
@@ -1,883 +1,883
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @autor $Author$
5 5 @version $Id$
6 6
7 7 '''
8 8
9 9 import numpy
10 10
11 11 import time
12 12 import datetime
13 13
14 14
15 15 import matplotlib as mpl
16 16 mpl.use('TKAgg')
17 17 import matplotlib.pyplot as plt
18 18
19 19 import scitools.numpyutils as sn
20 20
21 21 def cmap1_init(colormap='gray'):
22 22 pass
23 23
24 24 def setColormap(colormap='jet'):
25 25 pass
26 26
27 27 def savePlplot(filename,width,height):
28 28 pass
29 29
30 30 def initMatplotlib(indexFig,ncol,nrow,winTitle,width,height):
31 31
32 32 plt.ioff()
33 33 fig = plt.figure(indexFig)
34 34 fig.canvas.manager.set_window_title(winTitle)
35 35 fig.canvas.manager.resize(width,height)
36 36 # fig.add_subplot(nrow,ncol,1)
37 37 plt.ion()
38 38
39 39 def setNewPage():
40 40 plt.clf()
41 41
42 42 def closePage():
43 43 pass
44 44
45 45 def clearData(objGraph):
46 46 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bc', 'bc')
47 47
48 48 objGraph.setColor(15) #Setting Line Color to White
49 49
50 50 if objGraph.datatype == 'complex':
51 51 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real)
52 52 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag)
53 53
54 54 if objGraph.datatype == 'real':
55 55 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata)
56 56
57 57 objGraph.setColor(1)
58 58
59 59 def setFigure(indexFig):
60 60 plt.figure(indexFig)
61 61
62 62 def refresh():
63 63 plt.draw()
64 64
65 65 def show():
66 66 plt.ioff()
67 67 plt.show()
68 68 plt.ion()
69 69
70 70 def setPlTitle(pltitle,color, szchar=0.7):
71 71 pass
72 72
73 73 def setSubpages(ncol,nrow):
74 74 pass
75 75
76 76 class BaseGraph:
77 77
78 78 __name = None
79 79 __xpos = None
80 80 __ypos = None
81 81 __subplot = None
82 82 __xg = None
83 83 __yg = None
84 84 __axesId = None
85 85 xdata = None
86 86 ydata = None
87 87 getGrid = True
88 88 xaxisIsTime = False
89 89 deltax = None
90 90 xmin = None
91 91 xmax = None
92 92
93 93 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
94 94
95 95 self.setName(name)
96 96 self.setScreenPos(xpos, ypos)
97 97 self.setSubPlot(subplot)
98 98 self.setXYZrange(xrange,yrange,zrange)
99 99 self.setSizeOfChar(szchar)
100 100 self.setLabels(xlabel,ylabel,title)
101 101 self.getGrid = True
102 102 self.xaxisIsTime = False
103 103 self.deltax = deltax
104 104 pass
105 105
106 106 def makeAxes(self,indexFig,nrow,ncol,subplot):
107 107 fig = plt.figure(indexFig)
108 108 self.__axesId = fig.add_subplot(nrow,ncol,subplot)
109 109
110 110 def setParentAxesId(self,parent):
111 111 self.__axesId = parent.__axesId
112 112
113 113 def setName(self, name):
114 114 self.__name = name
115 115
116 116 def setScreenPos(self,xpos,ypos):
117 117 self.__xpos = xpos
118 118 self.__ypos = ypos
119 119
120 120 def setSubPlot(self,subplot):
121 121 self.__subplot = subplot
122 122
123 123 def setXYZrange(self,xrange,yrange,zrange):
124 124 self.xrange = xrange
125 125 self.yrange = yrange
126 126 self.zrange = zrange
127 127
128 128 def setSizeOfChar(self,szchar):
129 129 self.__szchar = szchar
130 130
131 131 def setLabels(self,xlabel=None,ylabel=None,title=None):
132 132 if xlabel != None: self.xlabel = xlabel
133 133 if ylabel != None: self.ylabel = ylabel
134 134 if title != None: self.title = title
135 135
136 136 def setXYData(self,xdata=None,ydata=None,datatype='real'):
137 137 if ((xdata != None) and (ydata != None)):
138 138 self.xdata = xdata
139 139 self.ydata = ydata
140 140 self.datatype = datatype
141 141 if ((self.xdata == None) and (self.ydata == None)):
142 142 return None
143 143 return 1
144 144
145 145 def setLineStyle(self, style):
146 146 pass
147 147
148 148 def setColor(self, color):
149 149 pass
150 150
151 151 def setXAxisAsTime(self, value=False):
152 152 self.xaxisIsTime = value
153 153
154 154 def basicLineTimePlot(self, x, y, colline=1):
155 155 ax = self.__axesId
156 156 if self.setXYData() == None:
157 157 ax.plot(x,y)
158 158 plt.tight_layout()
159 159 else:
160 160 ax.lines[0].set_data(x,y)
161 161
162 162 def basicXYPlot(self, x, y):
163 163 ax = self.__axesId
164 164 if self.setXYData() == None:
165 165 ax.plot(x,y)
166 166 else:
167 167 ax.lines[0].set_data(x,y)
168 168
169 169 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
170 170 pass
171 171
172 172 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
173 173 pass
174 174
175 175 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):
176 176 ax = self.__axesId
177 177 ax.pcolormesh(x,y,data.T,vmin=zmin,vmax=zmax)
178 178
179 179 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
180 180 ax = self.__axesId
181 181 cax, kw = mpl.colorbar.make_axes(ax)
182 182 norm = mpl.colors.Normalize(vmin=ymin, vmax=ymax)
183 183 cb = mpl.colorbar.ColorbarBase(cax,norm=norm,**kw)
184 184 self.__colorbarId = cb
185 185 cb.set_label(self.title)
186 186
187 187 def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False):
188 188 ax = self.__axesId
189 189 ax.set_xlim([xmin,xmax])
190 190 ax.set_ylim([ymin,ymax])
191 191
192 192 if not(nolabels):
193 193 ax.set_xlabel(self.xlabel)
194 194 ax.set_ylabel(self.ylabel)
195 195 ax.set_title(self.title)
196 196
197 197 def delLabels(self):
198 198 pass
199 199
200 200 def plotImage(self,x,y,z,xrange,yrange,zrange):
201 201 pass
202 202
203 203
204 204 class LinearPlot():
205 205 linearObjDic = {}
206 206 __xpos = None
207 207 __ypos = None
208 208 isPlotIni = None
209 209
210 210 def __init__(self, indexFig,nsubplot,winTitle):
211 211 self.width = 700
212 self.height = 150
212 self.height = 800
213 213 self.indexFig = indexFig
214 214 self.ncol = 1
215 215 self.nrow = nsubplot
216 216 initMatplotlib(indexFig,self.ncol,self.nrow,winTitle,self.width,self.height)
217 217
218 218 self.isPlotIni = False
219 219
220 220
221 221 def setFigure(self,indexFig):
222 222 setFigure(indexFig)
223 223
224 224 def setNewPage(self, pltitle='No title'):
225 225 szchar = 0.7
226 226 # setNewPage()
227 227 setPlTitle(pltitle,'black', szchar=szchar)
228 228 setSubpages(self.ncol, self.nrow)
229 229
230 230 def setPosition(self):
231 231 xi = 0.07; xf = 0.9
232 232 yi = 0.15; yf = 0.8
233 233
234 234 xpos = [xi,xf]
235 235 ypos = [yi,yf]
236 236
237 237 self.__xpos = xpos
238 238 self.__ypos = ypos
239 239
240 240 return xpos,ypos
241 241
242 242 def createObjects(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel):
243 243 szchar = 0.7
244 244 name = 'linear'
245 245 key = name + '%d'%subplot
246 246 xrange = [xmin,xmax]
247 247 yrange = [ymin,ymax]
248 248
249 249 xpos,ypos = self.setPosition()
250 250 linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange)
251 251 self.linearObjDic[key] = linearObj
252 252
253 253 def iniPlot(self,subplot):
254 254 name = 'linear'
255 255 key = name + '%d'%subplot
256 256
257 257 linearObj = self.linearObjDic[key]
258 258 linearObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
259 259 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcnst', 'bcnstv')
260 260
261 261
262 262 def plot(self,subplot,x,y,type='abs'):
263 263 name = 'linear'
264 264 key = name + '%d'%subplot
265 265
266 266 linearObj = self.linearObjDic[key]
267 267
268 268 if type.lower() == 'simple':
269 269 colline = 9
270 270 linearObj.basicLineTimePlot(x, y)
271 271 linearObj.setXYData(x,y,'real')
272 272
273 273 def refresh(self):
274 274 refresh()
275 275
276 276 def show(self):
277 277 show()
278 278
279 279 class PcolorPlot:
280 280
281 281 pcolorObjDic = {}
282 282 colorbarObjDic = {}
283 283 pwprofileObjDic = {}
284 284 showColorbar = None
285 285 showPowerProfile = None
286 286 XAxisAsTime = None
287 287 width = None
288 288 height = None
289 289 __spcxpos = None
290 290 __spcypos = None
291 291 __cmapxpos = None
292 292 __cmapypos = None
293 293 __profxpos = None
294 294 __profypos = None
295 295 __lastTitle = None
296 296
297 297 def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
298 298
299 299 self.width = 460
300 300 self.height = 300
301 301 self.showColorbar = showColorbar
302 302 self.showPowerProfile = showPowerProfile
303 303 self.XAxisAsTime = XAxisAsTime
304 304
305 305 ncol = int(numpy.sqrt(nsubplot)+0.9)
306 306 nrow = int(nsubplot*1./ncol + 0.9)
307 307
308 308 self.ncol = ncol
309 309 self.nrow = nrow
310 310 self.indexFig = indexFig
311 311
312 312 initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height)
313 313 setColormap(colormap)
314 314
315 315 def setFigure(self,indexFig):
316 316 setFigure(indexFig)
317 317
318 318 def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile
319 319 if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075
320 320 else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5
321 321 yi = 0.15; yf = 0.80
322 322
323 323 xpos = [xi,xf]
324 324 ypos = [yi,yf]
325 325
326 326 self.__spcxpos = xpos
327 327 self.__spcypos = ypos
328 328
329 329 return xpos,ypos
330 330
331 331 def setColorbarScreenPos(self):
332 332
333 333 xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03
334 334 yi = self.__spcypos[0]; yf = self.__spcypos[1]
335 335
336 336 xpos = [xi,xf]
337 337 ypos = [yi,yf]
338 338
339 339 self.__cmapxpos = xpos
340 340 self.__cmapypos = ypos
341 341
342 342 return xpos,ypos
343 343
344 344 def setPowerprofileScreenPos(self):
345 345
346 346 xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25
347 347 yi = self.__spcypos[0]; yf = self.__spcypos[1]
348 348
349 349 xpos = [xi,xf]
350 350 ypos = [yi,yf]
351 351
352 352 self.__profxpos = [xi,xf]
353 353 self.__profypos = [yi,yf]
354 354
355 355 return xpos,ypos
356 356
357 357 def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
358 358
359 359 '''
360 360 Crea los objetos necesarios para un subplot
361 361 '''
362 362
363 363 # Config Spectra plot
364 364
365 365 szchar = 0.7
366 366 name = 'spc'
367 367 key = name + '%d'%subplot
368 368 xrange = [xmin,xmax]
369 369 yrange = [ymin,ymax]
370 370 zrange = [zmin,zmax]
371 371
372 372 xpos,ypos = self.setSpectraPos()
373 373 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
374 374 #pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
375 375 self.pcolorObjDic[key] = pcolorObj
376 376
377 377 # Config Colorbar
378 378 if self.showColorbar:
379 379 szchar = 0.65
380 380 name = 'colorbar'
381 381 key = name + '%d'%subplot
382 382
383 383 xpos,ypos = self.setColorbarScreenPos()
384 384 xrange = [0.,1.]
385 385 yrange = [zmin,zmax]
386 386 cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange)
387 387 self.colorbarObjDic[key] = cmapObj
388 388
389 389 # Config Power profile
390 390 if self.showPowerProfile:
391 391 szchar = 0.55
392 392 name = 'pwprofile'
393 393 key = name + '%d'%subplot
394 394
395 395 xpos,ypos = self.setPowerprofileScreenPos()
396 396 xrange = [zmin,zmax]
397 397 yrange = [ymin,ymax]
398 398 powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange)
399 399 #powObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
400 400 self.pwprofileObjDic[key] = powObj
401 401
402 402 def setNewPage(self, pltitle='No title'):
403 403 szchar = 0.7
404 404 setNewPage()
405 405 setPlTitle(pltitle,'black', szchar=szchar)
406 406 setSubpages(self.ncol, self.nrow)
407 407
408 408 def closePage(self):
409 409 closePage()
410 410
411 411 def show(self):
412 412 show()
413 413
414 414 def iniPlot(self,subplot):
415 415 '''
416 416 Inicializa los subplots con su frame, titulo, etc
417 417 '''
418 418
419 419 # Config Spectra plot
420 420 name = 'spc'
421 421 key = name + '%d'%subplot
422 422
423 423 pcolorObj = self.pcolorObjDic[key]
424 424 pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
425 425 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcnst', 'bcnstv')
426 426
427 427 # Config Colorbar
428 428 if self.showColorbar:
429 429 name = 'colorbar'
430 430 key = name + '%d'%subplot
431 431
432 432 cmapObj = self.colorbarObjDic[key]
433 433 cmapObj.setParentAxesId(pcolorObj)
434 434 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
435 435 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
436 436 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
437 437
438 438 # Config Power profile
439 439 if self.showPowerProfile:
440 440 name = 'pwprofile'
441 441 key = name + '%d'%subplot
442 442
443 443 powObj = self.pwprofileObjDic[key]
444 444 powObj.setLineStyle(2)
445 445 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
446 446 powObj.setLineStyle(1)
447 447 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
448 448
449 449 def printTitle(self,pltitle):
450 450
451 451 setPlTitle(pltitle,'black')
452 452
453 453 def plot(self,subplot,x,y,z,subtitle=''):
454 454 # Spectra plot
455 455
456 456 name = 'spc'
457 457 key = name + '%d'%subplot
458 458
459 459 # newx = [x[0],x[-1]]
460 460 pcolorObj = self.pcolorObjDic[key]
461 461 # pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst')
462 462
463 463 #pcolorObj.delLabels()
464 464 pcolorObj.setLabels(title=subtitle)
465 465
466 466 deltax = None; deltay = None
467 467
468 468 pcolorObj.advPcolorPlot(z,
469 469 x,
470 470 y,
471 471 xmin=pcolorObj.xrange[0],
472 472 xmax=pcolorObj.xrange[1],
473 473 ymin=pcolorObj.yrange[0],
474 474 ymax=pcolorObj.yrange[1],
475 475 zmin=pcolorObj.zrange[0],
476 476 zmax=pcolorObj.zrange[1],
477 477 deltax=deltax,
478 478 deltay=deltay,
479 479 getGrid=pcolorObj.getGrid)
480 480
481 481 #Solo se calcula la primera vez que se ingresa a la funcion
482 482 pcolorObj.getGrid = False
483 483
484 484 #pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst', nolabels=True)
485 485
486 486 # Power Profile
487 487 if self.showPowerProfile:
488 488 power = numpy.average(z, axis=0)
489 489 name = 'pwprofile'
490 490 key = name + '%d'%subplot
491 491 powObj = self.pwprofileObjDic[key]
492 492
493 493 if powObj.setXYData() != None:
494 494 #clearData(powObj)
495 495 powObj.setLineStyle(2)
496 496 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
497 497 powObj.setLineStyle(1)
498 498 else:
499 499 powObj.setXYData(power,y)
500 500
501 501 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
502 502 powObj.basicXYPlot(power,y)
503 503 powObj.setXYData(power,y)
504 504
505 505 def savePlot(self,indexFig,filename):
506 506
507 507 width = self.width*self.ncol
508 508 hei = self.height*self.nrow
509 509 savePlplot(filename,width,hei)
510 510
511 511 def refresh(self):
512 512 refresh()
513 513
514 514 class RtiPlot:
515 515
516 516 pcolorObjDic = {}
517 517 colorbarObjDic = {}
518 518 pwprofileObjDic = {}
519 519 showColorbar = None
520 520 showPowerProfile = None
521 521 XAxisAsTime = None
522 522 widht = None
523 523 height = None
524 524 __rtixpos = None
525 525 __rtiypos = None
526 526 __cmapxpos = None
527 527 __cmapypos = None
528 528 __profxpos = None
529 529 __profypos = None
530 530
531 531 def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
532 532 self.width = 700
533 533 self.height = 150
534 534 self.showColorbar = showColorbar
535 535 self.showPowerProfile = showPowerProfile
536 536 self.XAxisAsTime = XAxisAsTime
537 537
538 538 ncol = 1
539 539 nrow = nsubplot
540 540 initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height)
541 541 setColormap(colormap)
542 542 self.ncol = ncol
543 543 self.nrow = nrow
544 544
545 545 def setFigure(self,indexFig):
546 546 setFigure(indexFig)
547 547
548 548 def setRtiScreenPos(self):
549 549
550 550 if self.showPowerProfile: xi = 0.07; xf = 0.65
551 551 else: xi = 0.07; xf = 0.9
552 552 yi = 0.15; yf = 0.80
553 553
554 554 xpos = [xi,xf]
555 555 ypos = [yi,yf]
556 556
557 557 self.__rtixpos = xpos
558 558 self.__rtiypos = ypos
559 559
560 560 return xpos,ypos
561 561
562 562 def setColorbarScreenPos(self):
563 563
564 564 xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03
565 565
566 566 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
567 567
568 568 xpos = [xi,xf]
569 569 ypos = [yi,yf]
570 570
571 571 self.__cmapxpos = xpos
572 572 self.__cmapypos = ypos
573 573
574 574 return xpos,ypos
575 575
576 576 def setPowerprofileScreenPos(self):
577 577
578 578 xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20
579 579
580 580 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
581 581
582 582 xpos = [xi,xf]
583 583 ypos = [yi,yf]
584 584
585 585 self.__profxpos = [xi,xf]
586 586 self.__profypos = [yi,yf]
587 587
588 588 return xpos,ypos
589 589
590 590 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone='lt',npoints=100):
591 591 # Config Rti plot
592 592 szchar = 1.10
593 593 name = 'rti'
594 594 key = name + '%d'%subplot
595 595
596 596 # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal]
597 597 thisDateTime = datetime.datetime.fromtimestamp(timedata)
598 598 startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0)
599 599 endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59)
600 600 deltaTime = 0
601 601 if timezone == 'lt':
602 602 deltaTime = time.timezone
603 603 startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime
604 604 endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime
605 605
606 606 xrange = [startTimeInSecs,endTimeInSecs]
607 607 totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1.
608 608 deltax = totalTimeInXrange / npoints
609 609
610 610 yrange = [ymin,ymax]
611 611 zrange = [zmin,zmax]
612 612
613 613 xpos,ypos = self.setRtiScreenPos()
614 614 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax)
615 615 if self.XAxisAsTime:
616 616 pcolorObj.setXAxisAsTime(self.XAxisAsTime)
617 617 xopt = 'bcnstd'
618 618 yopt = 'bcnstv'
619 619 else:
620 620 xopt = 'bcnst'
621 621 yopt = 'bcnstv'
622 622
623 623 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
624 624 self.pcolorObjDic[key] = pcolorObj
625 625
626 626
627 627 # Config Colorbar
628 628 if self.showColorbar:
629 629 szchar = 0.9
630 630 name = 'colorbar'
631 631 key = name + '%d'%subplot
632 632
633 633 xpos,ypos = self.setColorbarScreenPos()
634 634 xrange = [0.,1.]
635 635 yrange = [zmin,zmax]
636 636 cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange)
637 637 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcm')
638 638 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
639 639 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
640 640 self.colorbarObjDic[key] = cmapObj
641 641
642 642
643 643 # Config Power profile
644 644 if self.showPowerProfile:
645 645 szchar = 0.8
646 646 name = 'pwprofile'
647 647 key = name + '%d'%subplot
648 648
649 649 xpos,ypos = self.setPowerprofileScreenPos()
650 650 xrange = [zmin,zmax]
651 651 yrange = [ymin,ymax]
652 652 powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange)
653 653 powObj.setLineStyle(2)
654 654 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
655 655 powObj.setLineStyle(1)
656 656 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
657 657 self.pwprofileObjDic[key] = powObj
658 658
659 659
660 660 def plot(self,subplot,x,y,z):
661 661 # RTI plot
662 662 name = 'rti'
663 663 key = name + '%d'%subplot
664 664
665 665 data = numpy.reshape(z, (1,-1))
666 666 data = numpy.abs(data)
667 667 data = 10*numpy.log10(data)
668 668 newx = [x,x+1]
669 669
670 670 pcolorObj = self.pcolorObjDic[key]
671 671
672 672 if pcolorObj.xaxisIsTime:
673 673 xopt = 'bcstd'
674 674 yopt = 'bcst'
675 675 else:
676 676 xopt = 'bcst'
677 677 yopt = 'bcst'
678 678
679 679 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
680 680
681 681 deltax = pcolorObj.deltax
682 682 deltay = None
683 683
684 684 if pcolorObj.xmin == None and pcolorObj.xmax == None:
685 685 pcolorObj.xmin = x
686 686 pcolorObj.xmax = x
687 687
688 688 if x >= pcolorObj.xmax:
689 689 xmin = x
690 690 xmax = x + deltax
691 691 x = [x]
692 692 pcolorObj.advPcolorPlot(data,
693 693 x,
694 694 y,
695 695 xmin=xmin,
696 696 xmax=xmax,
697 697 ymin=pcolorObj.yrange[0],
698 698 ymax=pcolorObj.yrange[1],
699 699 zmin=pcolorObj.zrange[0],
700 700 zmax=pcolorObj.zrange[1],
701 701 deltax=deltax,
702 702 deltay=deltay,
703 703 getGrid=pcolorObj.getGrid)
704 704
705 705 pcolorObj.xmin = xmin
706 706 pcolorObj.xmax = xmax
707 707
708 708
709 709 # Power Profile
710 710 if self.showPowerProfile:
711 711 data = numpy.reshape(data,(numpy.size(data)))
712 712 name = 'pwprofile'
713 713 key = name + '%d'%subplot
714 714 powObj = self.pwprofileObjDic[key]
715 715
716 716 if powObj.setXYData() != None:
717 717 clearData(powObj)
718 718 powObj.setLineStyle(2)
719 719 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
720 720 powObj.setLineStyle(1)
721 721 else:
722 722 powObj.setXYData(data,y)
723 723
724 724 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
725 725 powObj.basicXYPlot(data,y)
726 726 powObj.setXYData(data,y)
727 727
728 728 def savePlot(self,indexFig,filename):
729 729
730 730 width = self.width*self.ncol
731 731 hei = self.height*self.nrow
732 732 savePlplot(filename,width,hei)
733 733
734 734 def refresh(self):
735 735 refresh()
736 736
737 737
738 738 if __name__ == '__main__':
739 739
740 740 """
741 741 Ejemplo1
742 742 """
743 743 #Setting the signal
744 744 fs = 8000
745 745 f0 = 200
746 746 f1 = 400
747 747 T = 1./fs
748 748 x = numpy.arange(160)
749 749 y1 = numpy.sin(2*numpy.pi*f0*x*T)
750 750 y2 = numpy.sin(2*numpy.pi*f1*x*T)
751 751 signalList = [y1,y2]
752 752
753 753 xmin = numpy.min(x)
754 754 xmax = numpy.max(x)
755 755 ymin = numpy.min(y1) - 10
756 756 ymax = numpy.max(y1) + 10
757 757
758 758 subplotTitle = "subplot no. "
759 759 xlabel = ""
760 760 ylabel = ""
761 761
762 762 indexFig = 1
763 nsubplot = 2
763 nsubplot = 6
764 764 winTitle = "figura"
765 765
766 766 isPlotIni = False
767 767 isPlotConfig = False
768 ntimes = 10
768 ntimes = 100
769 769
770 770
771 771 # Instancia del objeto
772 772 linearObj = LinearPlot(indexFig,nsubplot,winTitle)
773 773
774 774
775 775 for i in range(ntimes):
776 776 # Crea los subplots
777 777 if not(linearObj.isPlotIni):
778 778 for index in range(nsubplot):
779 779 indexplot = index + 1
780 780 title = subplotTitle + '%d'%indexplot
781 781 linearObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel)
782 782 linearObj.isPlotIni = True
783 783
784 784 # Inicializa el grafico en cada iteracion
785 785 linearObj.setFigure(indexFig)
786 786 linearObj.setNewPage("")
787 787
788 788 for index in range(nsubplot):
789 789 subplot = index
790 790 linearObj.iniPlot(subplot+1)
791 791
792 792 #plotea los datos
793 793 for channel in range(nsubplot):
794 794 data = y1 + numpy.random.rand(len(y1))
795 795 linearObj.plot(channel+1, x, data, type='simple')
796 796
797 797 linearObj.refresh()
798 798
799 799 # linearObj.closePage() #descomentar esta linea para mas iteraciones
800 800
801 801 time.sleep(0.05)
802 802
803 803 linearObj.show()
804 804
805 805 print "example 1 completed"
806 806
807 807
808 808
809 809 """
810 810 Ejemplo2
811 811 """
812 812
813 813 # make these smaller to increase the resolution
814 814 dx, dy = 0.05, 0.05
815 815 x = numpy.arange(-3.0, 3.0001, dx)
816 816 y = numpy.arange(-2.0, 2.0001, dy)
817 817 # X,Y = numpy.meshgrid(x, y)
818 818 X,Y = sn.ndgrid(x, y)
819 819 Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2)
820 820
821 821 # Creating Object
822 822 indexPlot = 2
823 823 nsubplot = 1
824 824 winTitle = "mi grafico pcolor"
825 825 colormap = "br_green"
826 826 showColorbar = True
827 827 showPowerProfile = False
828 828 XAxisAsTime = False
829 829
830 830 subplotTitle = "subplot no. "
831 831 xlabel = ""
832 832 ylabel = ""
833 833
834 834 xmin = -3.0
835 835 xmax = 3.0
836 836 ymin = -2.0
837 837 ymax = 2.0
838 838 zmin = -0.3
839 839 zmax = 1.0
840 840
841 841 isPlotIni = False
842 842 isPlotConfig = False
843 843 ntimes = 10
844 844
845 845
846 846 for i in range(ntimes):
847 847
848 848 # Instancia del objeto
849 849 if not(isPlotConfig):
850 850 pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime)
851 851 isPlotConfig = True
852 852
853 853 # Crea los subplots
854 854 if not(isPlotIni):
855 855 for index in range(nsubplot):
856 856 indexplot = index + 1
857 857 title = subplotTitle + '%d'%indexplot
858 858 subplot = index
859 859 pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
860 860 isPlotIni = True
861 861
862 862 # Inicializa el grafico en cada iteracion
863 863 pcolorObj.setFigure(indexPlot)
864 864 pcolorObj.setNewPage("")
865 865
866 866 for index in range(nsubplot):
867 867 subplot = index
868 868 pcolorObj.iniPlot(subplot+1)
869 869
870 870 #plotea los datos
871 871 for channel in range(nsubplot):
872 872 data = Z+0.1*numpy.random.randn(len(x),len(y))
873 873 pcolorObj.plot(channel+1, x, y, data)
874 874
875 875 pcolorObj.refresh()
876 876
877 877 # pcolorObj.closePage() #descomentar esta linea para mas iteraciones
878 878
879 879 time.sleep(1)
880 880
881 881 pcolorObj.show()
882 882
883 883 print "example 2 completed" No newline at end of file
@@ -1,1047 +1,1049
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import glob
9 9 import time
10 10 import numpy
11 11 import fnmatch
12 12 import time, datetime
13 13
14 14 path = os.path.split(os.getcwd())[0]
15 15 sys.path.append(path)
16 16
17 17 from JROHeaderIO import *
18 18 from Data.JROData import JROData
19 19
20 20 def isNumber(str):
21 21 """
22 22 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
23 23
24 24 Excepciones:
25 25 Si un determinado string no puede ser convertido a numero
26 26 Input:
27 27 str, string al cual se le analiza para determinar si convertible a un numero o no
28 28
29 29 Return:
30 30 True : si el string es uno numerico
31 31 False : no es un string numerico
32 32 """
33 33 try:
34 34 float( str )
35 35 return True
36 36 except:
37 37 return False
38 38
39 39 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
40 40 """
41 41 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
42 42
43 43 Inputs:
44 44 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
45 45
46 46 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
47 47 segundos contados desde 01/01/1970.
48 48 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
49 49 segundos contados desde 01/01/1970.
50 50
51 51 Return:
52 52 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
53 53 fecha especificado, de lo contrario retorna False.
54 54
55 55 Excepciones:
56 56 Si el archivo no existe o no puede ser abierto
57 57 Si la cabecera no puede ser leida.
58 58
59 59 """
60 60 basicHeaderObj = BasicHeader()
61 61
62 62 try:
63 63 fp = open(filename,'rb')
64 64 except:
65 65 raise IOError, "The file %s can't be opened" %(filename)
66 66
67 67 sts = basicHeaderObj.read(fp)
68 68 fp.close()
69 69
70 70 if not(sts):
71 71 print "Skipping the file %s because it has not a valid header" %(filename)
72 72 return 0
73 73
74 74 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
75 75 return 0
76 76
77 77 return 1
78 78
79 79 def getlastFileFromPath(path, ext):
80 80 """
81 81 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
82 82 al final de la depuracion devuelve el ultimo file de la lista que quedo.
83 83
84 84 Input:
85 85 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
86 86 ext : extension de los files contenidos en una carpeta
87 87
88 88 Return:
89 89 El ultimo file de una determinada carpeta, no se considera el path.
90 90 """
91 91 validFilelist = []
92 92 fileList = os.listdir(path)
93 93
94 94 # 0 1234 567 89A BCDE
95 95 # H YYYY DDD SSS .ext
96 96
97 97 for file in fileList:
98 98 try:
99 99 year = int(file[1:5])
100 100 doy = int(file[5:8])
101 101
102 102 if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue
103 103 except:
104 104 continue
105 105
106 106 validFilelist.append(file)
107 107
108 108 if validFilelist:
109 109 validFilelist = sorted( validFilelist, key=str.lower )
110 110 return validFilelist[-1]
111 111
112 112 return None
113 113
114 114 def checkForRealPath(path, year, doy, set, ext):
115 115 """
116 116 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
117 117 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
118 118 el path exacto de un determinado file.
119 119
120 120 Example :
121 121 nombre correcto del file es .../.../D2009307/P2009307367.ext
122 122
123 123 Entonces la funcion prueba con las siguientes combinaciones
124 124 .../.../x2009307/y2009307367.ext
125 125 .../.../x2009307/Y2009307367.ext
126 126 .../.../X2009307/y2009307367.ext
127 127 .../.../X2009307/Y2009307367.ext
128 128 siendo para este caso, la ultima combinacion de letras, identica al file buscado
129 129
130 130 Return:
131 131 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
132 132 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
133 133 para el filename
134 134 """
135 135 filepath = None
136 136 find_flag = False
137 137 filename = None
138 138
139 139 if ext.lower() == ".r": #voltage
140 140 header1 = "dD"
141 141 header2 = "dD"
142 142 elif ext.lower() == ".pdata": #spectra
143 143 header1 = "dD"
144 144 header2 = "pP"
145 145 else:
146 146 return None, filename
147 147
148 148 for dir in header1: #barrido por las dos combinaciones posibles de "D"
149 149 for fil in header2: #barrido por las dos combinaciones posibles de "D"
150 150 doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D)
151 151 filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
152 152 filepath = os.path.join( path, doypath, filename ) #formo el path completo
153 153 if os.path.exists( filepath ): #verifico que exista
154 154 find_flag = True
155 155 break
156 156 if find_flag:
157 157 break
158 158
159 159 if not(find_flag):
160 160 return None, filename
161 161
162 162 return filepath, filename
163 163
164 164 class JRODataIO:
165 165
166 166 c = 3E8
167 167
168 168 basicHeaderObj = BasicHeader()
169 169
170 170 systemHeaderObj = SystemHeader()
171 171
172 172 radarControllerHeaderObj = RadarControllerHeader()
173 173
174 174 processingHeaderObj = ProcessingHeader()
175 175
176 176 online = 0
177 177
178 178 dtype = None
179 179
180 180 pathList = []
181 181
182 182 filenameList = []
183 183
184 184 filename = None
185 185
186 186 ext = None
187 187
188 188 flagNoMoreFiles = 0
189 189
190 190 flagIsNewFile = 1
191 191
192 192 flagTimeBlock = 0
193 193
194 194 flagIsNewBlock = 0
195 195
196 196 fp = None
197 197
198 198 firstHeaderSize = 0
199 199
200 200 basicHeaderSize = 24
201 201
202 202 versionFile = 1103
203 203
204 204 fileSize = None
205 205
206 206 ippSeconds = None
207 207
208 208 fileSizeByHeader = None
209 209
210 210 fileIndex = None
211 211
212 212 profileIndex = None
213 213
214 214 blockIndex = None
215 215
216 216 nTotalBlocks = None
217 217
218 218 maxTimeStep = 30
219 219
220 220 lastUTTime = None
221 221
222 222 datablock = None
223 223
224 224 dataOutObj = None
225 225
226 226 blocksize = None
227 227
228 set = None
229
228 230 def __init__(self):
229 231 pass
230 232
231 233 class JRODataReader(JRODataIO):
232 234
233 235 nReadBlocks = 0
234 236
235 237 delay = 60 #number of seconds waiting a new file
236 238
237 239 nTries = 3 #quantity tries
238 240
239 241 nFiles = 3 #number of files for searching
240 242
241 243
242 244 def __init__(self):
243 245
244 246 pass
245 247
246 248 def createObjByDefault(self):
247 249 """
248 250
249 251 """
250 252 raise ValueError, "This method has not been implemented"
251 253
252 254 def getBlockDimension(self):
253 255
254 256 raise ValueError, "No implemented"
255 257
256 258 def __searchFilesOffLine(self,
257 259 path,
258 260 startDate,
259 261 endDate,
260 262 startTime=datetime.time(0,0,0),
261 263 endTime=datetime.time(23,59,59),
262 264 set=None,
263 265 expLabel="",
264 266 ext=".r"):
265 267 dirList = []
266 268 for thisPath in os.listdir(path):
267 269 if os.path.isdir(os.path.join(path,thisPath)):
268 270 dirList.append(thisPath)
269 271
270 272 if not(dirList):
271 273 return None, None
272 274
273 275 pathList = []
274 276 dateList = []
275 277
276 278 thisDate = startDate
277 279
278 280 while(thisDate <= endDate):
279 281 year = thisDate.timetuple().tm_year
280 282 doy = thisDate.timetuple().tm_yday
281 283
282 284 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
283 285 if len(match) == 0:
284 286 thisDate += datetime.timedelta(1)
285 287 continue
286 288
287 289 pathList.append(os.path.join(path,match[0],expLabel))
288 290 dateList.append(thisDate)
289 291 thisDate += datetime.timedelta(1)
290 292
291 293 filenameList = []
292 294 for index in range(len(pathList)):
293 295
294 296 thisPath = pathList[index]
295 297 fileList = glob.glob1(thisPath, "*%s" %ext)
296 298 fileList.sort()
297 299
298 300 #Busqueda de datos en el rango de horas indicados
299 301 thisDate = dateList[index]
300 302 startDT = datetime.datetime.combine(thisDate, startTime)
301 303 endDT = datetime.datetime.combine(thisDate, endTime)
302 304
303 305 startUtSeconds = time.mktime(startDT.timetuple())
304 306 endUtSeconds = time.mktime(endDT.timetuple())
305 307
306 308 for file in fileList:
307 309
308 310 filename = os.path.join(thisPath,file)
309 311
310 312 if isThisFileinRange(filename, startUtSeconds, endUtSeconds):
311 313 filenameList.append(filename)
312 314
313 315 if not(filenameList):
314 316 return None, None
315 317
316 318 self.filenameList = filenameList
317 319
318 320 return pathList, filenameList
319 321
320 322 def __searchFilesOnLine(self, path, startDate=None, endDate=None, startTime=None, endTime=None, expLabel = "", ext = None):
321 323
322 324 """
323 325 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
324 326 devuelve el archivo encontrado ademas de otros datos.
325 327
326 328 Input:
327 329 path : carpeta donde estan contenidos los files que contiene data
328 330
329 331 startDate : Fecha inicial. Rechaza todos los directorios donde
330 332 file end time < startDate (obejto datetime.date)
331 333
332 334 endDate : Fecha final. Rechaza todos los directorios donde
333 335 file start time > endDate (obejto datetime.date)
334 336
335 337 startTime : Tiempo inicial. Rechaza todos los archivos donde
336 338 file end time < startTime (obejto datetime.time)
337 339
338 340 endTime : Tiempo final. Rechaza todos los archivos donde
339 341 file start time > endTime (obejto datetime.time)
340 342
341 343 expLabel : Nombre del subexperimento (subfolder)
342 344
343 345 ext : extension de los files
344 346
345 347 Return:
346 348 directory : eL directorio donde esta el file encontrado
347 349 filename : el ultimo file de una determinada carpeta
348 350 year : el anho
349 351 doy : el numero de dia del anho
350 352 set : el set del archivo
351 353
352 354
353 355 """
354 356 dirList = []
355 357 pathList = []
356 358 directory = None
357 359
358 360 #Filtra solo los directorios
359 361 for thisPath in os.listdir(path):
360 362 if os.path.isdir(os.path.join(path, thisPath)):
361 363 dirList.append(thisPath)
362 364
363 365 if not(dirList):
364 366 return None, None, None, None, None
365 367
366 368 dirList = sorted( dirList, key=str.lower )
367 369
368 370 if startDate:
369 371 startDateTime = datetime.datetime.combine(startDate, startTime)
370 372 thisDateTime = startDateTime
371 373 if endDate == None: endDateTime = startDateTime
372 374 else: endDateTime = datetime.datetime.combine(endDate, endTime)
373 375
374 376 while(thisDateTime <= endDateTime):
375 377 year = thisDateTime.timetuple().tm_year
376 378 doy = thisDateTime.timetuple().tm_yday
377 379
378 380 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
379 381 if len(match) == 0:
380 382 thisDateTime += datetime.timedelta(1)
381 383 continue
382 384
383 385 pathList.append(os.path.join(path,match[0], expLabel))
384 386 thisDateTime += datetime.timedelta(1)
385 387
386 388 if not(pathList):
387 389 print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
388 390 return None, None, None, None, None
389 391
390 392 directory = pathList[0]
391 393
392 394 else:
393 395 directory = dirList[-1]
394 396 directory = os.path.join(path,directory)
395 397
396 398 filename = getlastFileFromPath(directory, ext)
397 399
398 400 if not(filename):
399 401 return None, None, None, None, None
400 402
401 403 if not(self.__verifyFile(os.path.join(directory, filename))):
402 404 return None, None, None, None, None
403 405
404 406 year = int( filename[1:5] )
405 407 doy = int( filename[5:8] )
406 408 set = int( filename[8:11] )
407 409
408 410 return directory, filename, year, doy, set
409 411
410 412 def setup(self,dataOutObj=None,
411 413 path=None,
412 414 startDate=None,
413 415 endDate=None,
414 416 startTime=datetime.time(0,0,0),
415 417 endTime=datetime.time(23,59,59),
416 418 set=0,
417 419 expLabel = "",
418 420 ext = None,
419 421 online = False,
420 422 delay = 60):
421 423
422 424 if path == None:
423 425 raise ValueError, "The path is not valid"
424 426
425 427 if ext == None:
426 428 ext = self.ext
427 429
428 430 if dataOutObj == None:
429 431 dataOutObj = self.createObjByDefault()
430 432
431 433 self.dataOutObj = dataOutObj
432 434
433 435 if online:
434 436 print "Searching files in online mode..."
435 437 doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext)
436 438
437 439 if not(doypath):
438 440 for nTries in range( self.nTries ):
439 441 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
440 442 time.sleep( self.delay )
441 443 doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp)
442 444 if doypath:
443 445 break
444 446
445 447 if not(doypath):
446 448 print "There 'isn't valied files in %s" % path
447 449 return None
448 450
449 451 self.year = year
450 452 self.doy = doy
451 453 self.set = set - 1
452 454 self.path = path
453 455
454 456 else:
455 457 print "Searching files in offline mode ..."
456 458 pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext)
457 459
458 460 if not(pathList):
459 461 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
460 462 datetime.datetime.combine(startDate,startTime).ctime(),
461 463 datetime.datetime.combine(endDate,endTime).ctime())
462 464
463 465 sys.exit(-1)
464 466
465 467
466 468 self.fileIndex = -1
467 469 self.pathList = pathList
468 470 self.filenameList = filenameList
469 471
470 472 self.online = online
471 473 self.delay = delay
472 474 ext = ext.lower()
473 475 self.ext = ext
474 476
475 477 if not(self.setNextFile()):
476 478 if (startDate!=None) and (endDate!=None):
477 479 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
478 480 elif startDate != None:
479 481 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
480 482 else:
481 483 print "No files"
482 484
483 485 sys.exit(-1)
484 486
485 487 # self.updateDataHeader()
486 488
487 489 return self.dataOutObj
488 490
489 491 def __setNextFileOffline(self):
490 492
491 493 idFile = self.fileIndex
492 494
493 495 while (True):
494 496 idFile += 1
495 497 if not(idFile < len(self.filenameList)):
496 498 self.flagNoMoreFiles = 1
497 499 print "No more Files"
498 500 return 0
499 501
500 502 filename = self.filenameList[idFile]
501 503
502 504 if not(self.__verifyFile(filename)):
503 505 continue
504 506
505 507 fileSize = os.path.getsize(filename)
506 508 fp = open(filename,'rb')
507 509 break
508 510
509 511 self.flagIsNewFile = 1
510 512 self.fileIndex = idFile
511 513 self.filename = filename
512 514 self.fileSize = fileSize
513 515 self.fp = fp
514 516
515 517 print "Setting the file: %s"%self.filename
516 518
517 519 return 1
518 520
519 521 def __setNextFileOnline(self):
520 522 """
521 523 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
522 524 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
523 525 siguientes.
524 526
525 527 Affected:
526 528 self.flagIsNewFile
527 529 self.filename
528 530 self.fileSize
529 531 self.fp
530 532 self.set
531 533 self.flagNoMoreFiles
532 534
533 535 Return:
534 536 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
535 537 1 : si el file fue abierto con exito y esta listo a ser leido
536 538
537 539 Excepciones:
538 540 Si un determinado file no puede ser abierto
539 541 """
540 542 nFiles = 0
541 543 fileOk_flag = False
542 544 firstTime_flag = True
543 545
544 546 self.set += 1
545 547
546 548 #busca el 1er file disponible
547 549 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
548 550 if file:
549 551 if self.__verifyFile(file, False):
550 552 fileOk_flag = True
551 553
552 554 #si no encuentra un file entonces espera y vuelve a buscar
553 555 if not(fileOk_flag):
554 556 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
555 557
556 558 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
557 559 tries = self.nTries
558 560 else:
559 561 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
560 562
561 563 for nTries in range( tries ):
562 564 if firstTime_flag:
563 565 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
564 566 time.sleep( self.delay )
565 567 else:
566 568 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
567 569
568 570 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
569 571 if file:
570 572 if self.__verifyFile(file):
571 573 fileOk_flag = True
572 574 break
573 575
574 576 if fileOk_flag:
575 577 break
576 578
577 579 firstTime_flag = False
578 580
579 581 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
580 582 self.set += 1
581 583
582 584 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
583 585 self.set = 0
584 586 self.doy += 1
585 587
586 588 if fileOk_flag:
587 589 self.fileSize = os.path.getsize( file )
588 590 self.filename = file
589 591 self.flagIsNewFile = 1
590 592 if self.fp != None: self.fp.close()
591 self.fp = open(file)
593 self.fp = open(file, 'rb')
592 594 self.flagNoMoreFiles = 0
593 595 print 'Setting the file: %s' % file
594 596 else:
595 597 self.fileSize = 0
596 598 self.filename = None
597 599 self.flagIsNewFile = 0
598 600 self.fp = None
599 601 self.flagNoMoreFiles = 1
600 602 print 'No more Files'
601 603
602 604 return fileOk_flag
603 605
604 606
605 607 def setNextFile(self):
606 608 if self.fp != None:
607 609 self.fp.close()
608 610
609 611 if self.online:
610 612 newFile = self.__setNextFileOnline()
611 613 else:
612 614 newFile = self.__setNextFileOffline()
613 615
614 616 if not(newFile):
615 617 return 0
616
618
617 619 self.__readFirstHeader()
618 620 self.nReadBlocks = 0
619 621 return 1
620
622
621 623 def __setNewBlock(self):
622 624 if self.fp == None:
623 625 return 0
624 626
625 627 if self.flagIsNewFile:
626 628 return 1
627 629
628 630 self.lastUTTime = self.basicHeaderObj.utc
629 631 currentSize = self.fileSize - self.fp.tell()
630 632 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
631 633
632 634 if (currentSize >= neededSize):
633 635 self.__rdBasicHeader()
634 636 return 1
635 637
636 638 if not(self.setNextFile()):
637 639 return 0
638 640
639 641 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
640 642
641 643 self.flagTimeBlock = 0
642 644
643 645 if deltaTime > self.maxTimeStep:
644 646 self.flagTimeBlock = 1
645 647
646 648 return 1
647 649
648 650
649 651 def readNextBlock(self):
650 652 if not(self.__setNewBlock()):
651 653 return 0
652 654
653 655 if not(self.readBlock()):
654 656 return 0
655 657
656 658 return 1
657 659
658 660 def __rdProcessingHeader(self, fp=None):
659 661 if fp == None:
660 662 fp = self.fp
661 663
662 664 self.processingHeaderObj.read(fp)
663 665
664 666 def __rdRadarControllerHeader(self, fp=None):
665 667 if fp == None:
666 668 fp = self.fp
667 669
668 670 self.radarControllerHeaderObj.read(fp)
669 671
670 672 def __rdSystemHeader(self, fp=None):
671 673 if fp == None:
672 674 fp = self.fp
673 675
674 676 self.systemHeaderObj.read(fp)
675 677
676 678 def __rdBasicHeader(self, fp=None):
677 679 if fp == None:
678 680 fp = self.fp
679 681
680 682 self.basicHeaderObj.read(fp)
681 683
682 684
683 685 def __readFirstHeader(self):
684 686 self.__rdBasicHeader()
685 687 self.__rdSystemHeader()
686 688 self.__rdRadarControllerHeader()
687 689 self.__rdProcessingHeader()
688 690
689 691 self.firstHeaderSize = self.basicHeaderObj.size
690 692
691 693 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
692 694 if datatype == 0:
693 695 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
694 696 elif datatype == 1:
695 697 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
696 698 elif datatype == 2:
697 699 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
698 700 elif datatype == 3:
699 701 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
700 702 elif datatype == 4:
701 703 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
702 704 elif datatype == 5:
703 705 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
704 706 else:
705 707 raise ValueError, 'Data type was not defined'
706 708
707 709 self.dtype = datatype_str
708 710 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
709 711 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
710 712 # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels)
711 713 # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
712 714 self.getBlockDimension()
713 715
714 716
715 717 def __verifyFile(self, filename, msgFlag=True):
716 718 msg = None
717 719 try:
718 720 fp = open(filename, 'rb')
719 721 currentPosition = fp.tell()
720 722 except:
721 723 if msgFlag:
722 724 print "The file %s can't be opened" % (filename)
723 725 return False
724 726
725 727 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
726 728
727 729 if neededSize == 0:
728 730 basicHeaderObj = BasicHeader()
729 731 systemHeaderObj = SystemHeader()
730 732 radarControllerHeaderObj = RadarControllerHeader()
731 733 processingHeaderObj = ProcessingHeader()
732 734
733 735 try:
734 736 if not( basicHeaderObj.read(fp) ): raise ValueError
735 737 if not( systemHeaderObj.read(fp) ): raise ValueError
736 738 if not( radarControllerHeaderObj.read(fp) ): raise ValueError
737 739 if not( processingHeaderObj.read(fp) ): raise ValueError
738 740 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
739 741
740 742 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
741 743
742 744 except:
743 745 if msgFlag:
744 746 print "\tThe file %s is empty or it hasn't enough data" % filename
745 747
746 748 fp.close()
747 749 return False
748 750 else:
749 751 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
750 752
751 753 fp.close()
752 754 fileSize = os.path.getsize(filename)
753 755 currentSize = fileSize - currentPosition
754 756 if currentSize < neededSize:
755 757 if msgFlag and (msg != None):
756 758 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
757 759 return False
758 760
759 761 return True
760 762
761 763 def getData():
762 764 pass
763 765
764 766 def hasNotDataInBuffer():
765 767 pass
766 768
767 769 def readBlock():
768 770 pass
769 771
770 772 class JRODataWriter(JRODataIO):
771 773
772 774 """
773 775 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
774 776 de los datos siempre se realiza por bloques.
775 777 """
776 778
777 779 blockIndex = 0
778 780
779 781 path = None
780 782
781 783 setFile = None
782 784
783 785 profilesPerBlock = None
784 786
785 787 blocksPerFile = None
786 788
787 789 nWriteBlocks = 0
788 790
789 791 def __init__(self, dataOutObj=None):
790 792 raise ValueError, "Not implemented"
791 793
792 794
793 795 def hasAllDataInBuffer(self):
794 796 raise ValueError, "Not implemented"
795 797
796 798
797 799 def setBlockDimension(self):
798 800 raise ValueError, "Not implemented"
799 801
800 802
801 803 def writeBlock(self):
802 804 raise ValueError, "No implemented"
803 805
804 806
805 807 def putData(self):
806 808 raise ValueError, "No implemented"
807 809
808 810
809 811 def __writeFirstHeader(self):
810 812 """
811 813 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
812 814
813 815 Affected:
814 816 __dataType
815 817
816 818 Return:
817 819 None
818 820 """
819 821
820 822 # CALCULAR PARAMETROS
821 823
822 824 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
823 825 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
824 826
825 827 self.__writeBasicHeader()
826 828 self.__wrSystemHeader()
827 829 self.__wrRadarControllerHeader()
828 830 self.__wrProcessingHeader()
829 831 self.dtype = self.dataOutObj.dtype
830 832
831 833
832 834 def __writeBasicHeader(self, fp=None):
833 835 """
834 836 Escribe solo el Basic header en el file creado
835 837
836 838 Return:
837 839 None
838 840 """
839 841 if fp == None:
840 842 fp = self.fp
841 843
842 844 self.basicHeaderObj.write(fp)
843 845
844 846
845 847 def __wrSystemHeader(self, fp=None):
846 848 """
847 849 Escribe solo el System header en el file creado
848 850
849 851 Return:
850 852 None
851 853 """
852 854 if fp == None:
853 855 fp = self.fp
854 856
855 857 self.systemHeaderObj.write(fp)
856 858
857 859
858 860 def __wrRadarControllerHeader(self, fp=None):
859 861 """
860 862 Escribe solo el RadarController header en el file creado
861 863
862 864 Return:
863 865 None
864 866 """
865 867 if fp == None:
866 868 fp = self.fp
867 869
868 870 self.radarControllerHeaderObj.write(fp)
869 871
870 872
871 873 def __wrProcessingHeader(self, fp=None):
872 874 """
873 875 Escribe solo el Processing header en el file creado
874 876
875 877 Return:
876 878 None
877 879 """
878 880 if fp == None:
879 881 fp = self.fp
880 882
881 883 self.processingHeaderObj.write(fp)
882 884
883 885
884 886 def setNextFile(self):
885 887 """
886 888 Determina el siguiente file que sera escrito
887 889
888 890 Affected:
889 891 self.filename
890 892 self.subfolder
891 893 self.fp
892 894 self.setFile
893 895 self.flagIsNewFile
894 896
895 897 Return:
896 898 0 : Si el archivo no puede ser escrito
897 899 1 : Si el archivo esta listo para ser escrito
898 900 """
899 901 ext = self.ext
900 902 path = self.path
901 903
902 904 if self.fp != None:
903 905 self.fp.close()
904 906
905 907 timeTuple = time.localtime( self.dataOutObj.dataUtcTime)
906 908 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
907 909
908 910 doypath = os.path.join( path, subfolder )
909 911 if not( os.path.exists(doypath) ):
910 912 os.mkdir(doypath)
911 913 self.setFile = -1 #inicializo mi contador de seteo
912 914 else:
913 915 filesList = os.listdir( doypath )
914 916 if len( filesList ) > 0:
915 917 filesList = sorted( filesList, key=str.lower )
916 918 filen = filesList[-1]
917 919 # el filename debera tener el siguiente formato
918 920 # 0 1234 567 89A BCDE (hex)
919 921 # x YYYY DDD SSS .ext
920 922 if isNumber( filen[8:11] ):
921 923 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
922 924 else:
923 925 self.setFile = -1
924 926 else:
925 927 self.setFile = -1 #inicializo mi contador de seteo
926 928
927 929 setFile = self.setFile
928 930 setFile += 1
929 931
930 932 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
931 933 timeTuple.tm_year,
932 934 timeTuple.tm_yday,
933 935 setFile,
934 936 ext )
935 937
936 938 filename = os.path.join( path, subfolder, file )
937 939
938 940 fp = open( filename,'wb' )
939 941
940 942 self.blockIndex = 0
941 943
942 944 #guardando atributos
943 945 self.filename = filename
944 946 self.subfolder = subfolder
945 947 self.fp = fp
946 948 self.setFile = setFile
947 949 self.flagIsNewFile = 1
948 950
949 951 self.getDataHeader()
950 952
951 953 print 'Writing the file: %s'%self.filename
952 954
953 955 self.__writeFirstHeader()
954 956
955 957 return 1
956 958
957 959
958 960 def __setNewBlock(self):
959 961 """
960 962 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
961 963
962 964 Return:
963 965 0 : si no pudo escribir nada
964 966 1 : Si escribio el Basic el First Header
965 967 """
966 968 if self.fp == None:
967 969 self.setNextFile()
968 970
969 971 if self.flagIsNewFile:
970 972 return 1
971 973
972 974 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
973 975 self.__writeBasicHeader()
974 976 return 1
975 977
976 978 if not( self.setNextFile() ):
977 979 return 0
978 980
979 981 return 1
980 982
981 983
982 984 def writeNextBlock(self):
983 985 """
984 986 Selecciona el bloque siguiente de datos y los escribe en un file
985 987
986 988 Return:
987 989 0 : Si no hizo pudo escribir el bloque de datos
988 990 1 : Si no pudo escribir el bloque de datos
989 991 """
990 992 if not( self.__setNewBlock() ):
991 993 return 0
992 994
993 995 self.writeBlock()
994 996
995 997 return 1
996 998
997 999
998 1000 def getDataHeader(self):
999 1001 """Obtiene una copia del First Header Affected: self.basicHeaderObj self.
1000 1002 systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self.
1001 1003 dtype Return: None
1002 1004 """
1003 1005
1004 1006 raise ValueError, "No implemented"
1005 1007
1006 1008 def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1007 1009 """
1008 1010 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1009 1011
1010 1012 Inputs:
1011 1013 path : el path destino en el cual se escribiran los files a crear
1012 1014 format : formato en el cual sera salvado un file
1013 1015 set : el setebo del file
1014 1016
1015 1017 Return:
1016 1018 0 : Si no realizo un buen seteo
1017 1019 1 : Si realizo un buen seteo
1018 1020 """
1019 1021
1020 1022 if ext == None:
1021 1023 ext = self.ext
1022 1024
1023 1025 ext = ext.lower()
1024 1026
1025 1027 self.ext = ext
1026 1028
1027 1029 self.path = path
1028 1030
1029 1031 self.setFile = set - 1
1030 1032
1031 1033 self.blocksPerFile = blocksPerFile
1032 1034
1033 1035 self.profilesPerBlock = profilesPerBlock
1034 1036
1035 1037 if not(self.setNextFile()):
1036 1038 print "There isn't a next file"
1037 1039 return 0
1038 1040
1039 1041 self.setBlockDimension()
1040 1042
1041 1043 return 1
1042 1044
1043 1045
1044 1046
1045 1047
1046 1048
1047 1049
@@ -1,905 +1,949
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
10 10 import pyfits
11 11 import glob
12 12 import fnmatch
13 13 import time, datetime
14 14
15 15 path = os.path.split(os.getcwd())[0]
16 16 sys.path.append(path)
17 17
18 18 from JROHeaderIO import *
19 19 from JRODataIO import JRODataReader
20 20 from JRODataIO import JRODataWriter
21 21
22 22 from Data.JROData import Spectra
23 23
24 24 from Data.JROData import SpectraHeis
25 25
26 26 class SpectraReader(JRODataReader):
27 27 """
28 28 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
29 29 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
30 30 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
31 31
32 32 paresCanalesIguales * alturas * perfiles (Self Spectra)
33 33 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
34 34 canales * alturas (DC Channels)
35 35
36 36 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
37 37 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
38 38 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
39 39 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
40 40
41 41 Example:
42 42 dpath = "/home/myuser/data"
43 43
44 44 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
45 45
46 46 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
47 47
48 48 readerObj = SpectraReader()
49 49
50 50 readerObj.setup(dpath, startTime, endTime)
51 51
52 52 while(True):
53 53
54 54 readerObj.getData()
55 55
56 56 print readerObj.data_spc
57 57
58 58 print readerObj.data_cspc
59 59
60 60 print readerObj.data_dc
61 61
62 62 if readerObj.flagNoMoreFiles:
63 63 break
64 64
65 65 """
66 66
67 67 pts2read_SelfSpectra = 0
68 68
69 69 pts2read_CrossSpectra = 0
70 70
71 71 pts2read_DCchannels = 0
72 72
73 73 ext = ".pdata"
74 74
75 75 optchar = "P"
76 76
77 77 dataOutObj = None
78 78
79 79 nRdChannels = None
80 80
81 81 nRdPairs = None
82 82
83 83 rdPairList = []
84 84
85 85
86 86 def __init__(self, dataOutObj=None):
87 87 """
88 88 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
89 89
90 90 Inputs:
91 91 dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para
92 92 almacenar un perfil de datos cada vez que se haga un requerimiento
93 93 (getData). El perfil sera obtenido a partir del buffer de datos,
94 94 si el buffer esta vacio se hara un nuevo proceso de lectura de un
95 95 bloque de datos.
96 96 Si este parametro no es pasado se creara uno internamente.
97 97
98 98 Affected:
99 99 self.dataOutObj
100 100
101 101 Return : None
102 102 """
103 103
104 104 self.pts2read_SelfSpectra = 0
105 105
106 106 self.pts2read_CrossSpectra = 0
107 107
108 108 self.pts2read_DCchannels = 0
109 109
110 110 self.datablock = None
111 111
112 112 self.utc = None
113 113
114 114 self.ext = ".pdata"
115 115
116 116 self.optchar = "P"
117 117
118 118 self.basicHeaderObj = BasicHeader()
119 119
120 120 self.systemHeaderObj = SystemHeader()
121 121
122 122 self.radarControllerHeaderObj = RadarControllerHeader()
123 123
124 124 self.processingHeaderObj = ProcessingHeader()
125 125
126 126 self.online = 0
127 127
128 128 self.fp = None
129 129
130 130 self.idFile = None
131 131
132 132 self.dtype = None
133 133
134 134 self.fileSizeByHeader = None
135 135
136 136 self.filenameList = []
137 137
138 138 self.filename = None
139 139
140 140 self.fileSize = None
141 141
142 142 self.firstHeaderSize = 0
143 143
144 144 self.basicHeaderSize = 24
145 145
146 146 self.pathList = []
147 147
148 148 self.lastUTTime = 0
149 149
150 150 self.maxTimeStep = 30
151 151
152 152 self.flagNoMoreFiles = 0
153 153
154 154 self.set = 0
155 155
156 156 self.path = None
157 157
158 158 self.delay = 3 #seconds
159 159
160 160 self.nTries = 3 #quantity tries
161 161
162 162 self.nFiles = 3 #number of files for searching
163 163
164 164 self.nReadBlocks = 0
165 165
166 166 self.flagIsNewFile = 1
167 167
168 168 self.ippSeconds = 0
169 169
170 170 self.flagTimeBlock = 0
171 171
172 172 self.flagIsNewBlock = 0
173 173
174 174 self.nTotalBlocks = 0
175 175
176 176 self.blocksize = 0
177 177
178 178
179 179 def createObjByDefault(self):
180 180
181 181 dataObj = Spectra()
182 182
183 183 return dataObj
184 184
185 185 def __hasNotDataInBuffer(self):
186 186 return 1
187 187
188 188
189 189 def getBlockDimension(self):
190 190 """
191 191 Obtiene la cantidad de puntos a leer por cada bloque de datos
192 192
193 193 Affected:
194 194 self.nRdChannels
195 195 self.nRdPairs
196 196 self.pts2read_SelfSpectra
197 197 self.pts2read_CrossSpectra
198 198 self.pts2read_DCchannels
199 199 self.blocksize
200 200 self.dataOutObj.nChannels
201 201 self.dataOutObj.nPairs
202 202
203 203 Return:
204 204 None
205 205 """
206 206 self.nRdChannels = 0
207 207 self.nRdPairs = 0
208 208 self.rdPairList = []
209 209
210 210 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
211 211 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
212 212 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
213 213 else:
214 214 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
215 215 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
216 216
217 217 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
218 218
219 219 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
220 220 self.blocksize = self.pts2read_SelfSpectra
221 221
222 222 if self.processingHeaderObj.flag_cspc:
223 223 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
224 224 self.blocksize += self.pts2read_CrossSpectra
225 225
226 226 if self.processingHeaderObj.flag_dc:
227 227 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
228 228 self.blocksize += self.pts2read_DCchannels
229 229
230 230 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
231 231
232 232
233 233 def readBlock(self):
234 234 """
235 235 Lee el bloque de datos desde la posicion actual del puntero del archivo
236 236 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
237 237 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
238 238 es seteado a 0
239 239
240 240 Return: None
241 241
242 242 Variables afectadas:
243 243
244 244 self.flagIsNewFile
245 245 self.flagIsNewBlock
246 246 self.nTotalBlocks
247 247 self.data_spc
248 248 self.data_cspc
249 249 self.data_dc
250 250
251 251 Exceptions:
252 252 Si un bloque leido no es un bloque valido
253 253 """
254 254 blockOk_flag = False
255 255 fpointer = self.fp.tell()
256 256
257 257 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
258 258 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 259
260 260 if self.processingHeaderObj.flag_cspc:
261 261 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
262 262 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
263 263
264 264 if self.processingHeaderObj.flag_dc:
265 265 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
266 266 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
267 267
268 268
269 269 if not(self.processingHeaderObj.shif_fft):
270 270 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
271 271
272 272 if self.processingHeaderObj.flag_cspc:
273 273 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
274 274
275 275
276 276 spc = numpy.transpose( spc, (0,2,1) )
277 277 self.data_spc = spc
278 278
279 279 if self.processingHeaderObj.flag_cspc:
280 280 cspc = numpy.transpose( cspc, (0,2,1) )
281 281 self.data_cspc = cspc['real'] + cspc['imag']*1j
282 282 else:
283 283 self.data_cspc = None
284 284
285 285 if self.processingHeaderObj.flag_dc:
286 286 self.data_dc = dc['real'] + dc['imag']*1j
287 287 else:
288 288 self.data_dc = None
289 289
290 290 self.flagIsNewFile = 0
291 291 self.flagIsNewBlock = 1
292 292
293 293 self.nTotalBlocks += 1
294 294 self.nReadBlocks += 1
295 295
296 296 return 1
297 297
298 298
299 299 def getData(self):
300 300 """
301 301 Copia el buffer de lectura a la clase "Spectra",
302 302 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
303 303 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
304 304
305 305 Return:
306 306 0 : Si no hay mas archivos disponibles
307 307 1 : Si hizo una buena copia del buffer
308 308
309 309 Affected:
310 310 self.dataOutObj
311 311
312 312 self.flagTimeBlock
313 313 self.flagIsNewBlock
314 314 """
315 315
316 316 if self.flagNoMoreFiles: return 0
317 317
318 318 self.flagTimeBlock = 0
319 319 self.flagIsNewBlock = 0
320 320
321 321 if self.__hasNotDataInBuffer():
322 322
323 323 if not( self.readNextBlock() ):
324 324 return 0
325 325
326 326 # self.updateDataHeader()
327 327
328 328 if self.flagNoMoreFiles == 1:
329 329 print 'Process finished'
330 330 return 0
331 331
332 332 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
333 333
334 334 if self.data_dc == None:
335 335 self.dataOutObj.flagNoData = True
336 336 return 0
337 337
338 338
339 339 self.dataOutObj.data_spc = self.data_spc
340 340
341 341 self.dataOutObj.data_cspc = self.data_cspc
342 342
343 343 self.dataOutObj.data_dc = self.data_dc
344 344
345 345 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
346 346
347 347 self.dataOutObj.flagNoData = False
348 348
349 349 self.dataOutObj.dtype = self.dtype
350 350
351 351 self.dataOutObj.nChannels = self.nRdChannels
352 352
353 353 self.dataOutObj.nPairs = self.nRdPairs
354 354
355 355 self.dataOutObj.pairsList = self.rdPairList
356 356
357 357 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
358 358
359 359 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
360 360
361 361 self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock
362 362
363 363 self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt
364 364
365 365
366 366 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
367 367
368 368 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
369 369
370 370 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
371 371
372 372 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
373 373
374 374 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
375 375
376 376 self.dataOutObj.ippSeconds = self.ippSeconds
377 377
378 378 self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOutObj.nFFTPoints
379 379
380 380 self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft
381 381
382 382 # self.profileIndex += 1
383 383
384 384 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
385 385
386 386 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
387 387
388 388 return self.dataOutObj.data_spc
389 389
390 390
391 391 class SpectraWriter(JRODataWriter):
392 392
393 393 """
394 394 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
395 395 de los datos siempre se realiza por bloques.
396 396 """
397 397
398 398 ext = ".pdata"
399 399
400 400 optchar = "P"
401 401
402 402 shape_spc_Buffer = None
403 403
404 404 shape_cspc_Buffer = None
405 405
406 406 shape_dc_Buffer = None
407 407
408 408 data_spc = None
409 409
410 410 data_cspc = None
411 411
412 412 data_dc = None
413 413
414 414 wrPairList = []
415 415
416 416 nWrPairs = 0
417 417
418 418 nWrChannels = 0
419 419
420 420 # dataOutObj = None
421 421
422 422 def __init__(self, dataOutObj=None):
423 423 """
424 424 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
425 425
426 426 Affected:
427 427 self.dataOutObj
428 428 self.basicHeaderObj
429 429 self.systemHeaderObj
430 430 self.radarControllerHeaderObj
431 431 self.processingHeaderObj
432 432
433 433 Return: None
434 434 """
435 435 if dataOutObj == None:
436 436 dataOutObj = Spectra()
437 437
438 438 if not( isinstance(dataOutObj, Spectra) ):
439 439 raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object"
440 440
441 441 self.dataOutObj = dataOutObj
442 442
443 443 self.nTotalBlocks = 0
444 444
445 445 self.nWrChannels = self.dataOutObj.nChannels
446 446
447 447 # if len(pairList) > 0:
448 448 # self.wrPairList = pairList
449 449 #
450 450 # self.nWrPairs = len(pairList)
451 451
452 452 self.wrPairList = self.dataOutObj.pairsList
453 453
454 454 self.nWrPairs = self.dataOutObj.nPairs
455 455
456 456 # self.data_spc = None
457 457 # self.data_cspc = None
458 458 # self.data_dc = None
459 459
460 460 # self.fp = None
461 461
462 462 # self.flagIsNewFile = 1
463 463 #
464 464 # self.nTotalBlocks = 0
465 465 #
466 466 # self.flagIsNewBlock = 0
467 467 #
468 468 # self.flagNoMoreFiles = 0
469 469 #
470 470 # self.setFile = None
471 471 #
472 472 # self.dtype = None
473 473 #
474 474 # self.path = None
475 475 #
476 476 # self.noMoreFiles = 0
477 477 #
478 478 # self.filename = None
479 479 #
480 480 # self.basicHeaderObj = BasicHeader()
481 481 #
482 482 # self.systemHeaderObj = SystemHeader()
483 483 #
484 484 # self.radarControllerHeaderObj = RadarControllerHeader()
485 485 #
486 486 # self.processingHeaderObj = ProcessingHeader()
487 487
488 488
489 489 def hasAllDataInBuffer(self):
490 490 return 1
491 491
492 492
493 493 def setBlockDimension(self):
494 494 """
495 495 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
496 496
497 497 Affected:
498 498 self.shape_spc_Buffer
499 499 self.shape_cspc_Buffer
500 500 self.shape_dc_Buffer
501 501
502 502 Return: None
503 503 """
504 504 self.shape_spc_Buffer = (self.dataOutObj.nChannels,
505 505 self.processingHeaderObj.nHeights,
506 506 self.processingHeaderObj.profilesPerBlock)
507 507
508 508 self.shape_cspc_Buffer = (self.dataOutObj.nPairs,
509 509 self.processingHeaderObj.nHeights,
510 510 self.processingHeaderObj.profilesPerBlock)
511 511
512 512 self.shape_dc_Buffer = (self.dataOutObj.nChannels,
513 513 self.processingHeaderObj.nHeights)
514 514
515 515
516 516 def writeBlock(self):
517 517 """
518 518 Escribe el buffer en el file designado
519 519
520 520 Affected:
521 521 self.data_spc
522 522 self.data_cspc
523 523 self.data_dc
524 524 self.flagIsNewFile
525 525 self.flagIsNewBlock
526 526 self.nTotalBlocks
527 527 self.nWriteBlocks
528 528
529 529 Return: None
530 530 """
531 531
532 532 spc = numpy.transpose( self.data_spc, (0,2,1) )
533 533 if not( self.processingHeaderObj.shif_fft ):
534 534 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
535 535 data = spc.reshape((-1))
536 536 data.tofile(self.fp)
537 537
538 538 if self.data_cspc != None:
539 539 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
540 540 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
541 541 if not( self.processingHeaderObj.shif_fft ):
542 542 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
543 543 data['real'] = cspc.real
544 544 data['imag'] = cspc.imag
545 545 data = data.reshape((-1))
546 546 data.tofile(self.fp)
547 547
548 548 if self.data_dc != None:
549 549 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
550 550 dc = self.data_dc
551 551 data['real'] = dc.real
552 552 data['imag'] = dc.imag
553 553 data = data.reshape((-1))
554 554 data.tofile(self.fp)
555 555
556 556 self.data_spc.fill(0)
557 557 self.data_dc.fill(0)
558 558 if self.data_cspc != None:
559 559 self.data_cspc.fill(0)
560 560
561 561 self.flagIsNewFile = 0
562 562 self.flagIsNewBlock = 1
563 563 self.nTotalBlocks += 1
564 564 self.nWriteBlocks += 1
565 565 self.blockIndex += 1
566 566
567 567
568 568 def putData(self):
569 569 """
570 570 Setea un bloque de datos y luego los escribe en un file
571 571
572 572 Affected:
573 573 self.data_spc
574 574 self.data_cspc
575 575 self.data_dc
576 576
577 577 Return:
578 578 0 : Si no hay data o no hay mas files que puedan escribirse
579 579 1 : Si se escribio la data de un bloque en un file
580 580 """
581 581 self.flagIsNewBlock = 0
582 582
583 583 if self.dataOutObj.flagNoData:
584 584 return 0
585 585
586 586 if self.dataOutObj.flagTimeBlock:
587 587 self.data_spc.fill(0)
588 588 self.data_cspc.fill(0)
589 589 self.data_dc.fill(0)
590 590 self.setNextFile()
591 591
592 592 if self.flagIsNewFile == 0:
593 593 self.getBasicHeader()
594 594
595 595 self.data_spc = self.dataOutObj.data_spc
596 596 self.data_cspc = self.dataOutObj.data_cspc
597 597 self.data_dc = self.dataOutObj.data_dc
598 598
599 599 # #self.processingHeaderObj.dataBlocksPerFile)
600 600 if self.hasAllDataInBuffer():
601 601 # self.getDataHeader()
602 602 self.writeNextBlock()
603 603
604 604 if self.flagNoMoreFiles:
605 605 #print 'Process finished'
606 return 0
607
606 return 0
608 607 return 1
609 608
610 609
611 610 def __getProcessFlags(self):
612 611
613 612 processFlags = 0
614 613
615 614 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
616 615 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
617 616 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
618 617 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
619 618 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
620 619 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
621 620
622 621 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
623 622
624 623
625 624
626 625 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
627 626 PROCFLAG.DATATYPE_SHORT,
628 627 PROCFLAG.DATATYPE_LONG,
629 628 PROCFLAG.DATATYPE_INT64,
630 629 PROCFLAG.DATATYPE_FLOAT,
631 630 PROCFLAG.DATATYPE_DOUBLE]
632 631
633 632
634 633 for index in range(len(dtypeList)):
635 634 if self.dataOutObj.dtype == dtypeList[index]:
636 635 dtypeValue = datatypeValueList[index]
637 636 break
638 637
639 638 processFlags += dtypeValue
640 639
641 640 if self.dataOutObj.flagDecodeData:
642 641 processFlags += PROCFLAG.DECODE_DATA
643 642
644 643 if self.dataOutObj.flagDeflipData:
645 644 processFlags += PROCFLAG.DEFLIP_DATA
646 645
647 646 if self.dataOutObj.code != None:
648 647 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
649 648
650 649 if self.dataOutObj.nIncohInt > 1:
651 650 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
652 651
653 652 if self.dataOutObj.data_dc != None:
654 653 processFlags += PROCFLAG.SAVE_CHANNELS_DC
655 654
656 655 return processFlags
657 656
658 657
659 658 def __getBlockSize(self):
660 659 '''
661 660 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
662 661 '''
663 662
664 663 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
665 664 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
666 665 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
667 666 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
668 667 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
669 668 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
670 669
671 670 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
672 671 datatypeValueList = [1,2,4,8,4,8]
673 672 for index in range(len(dtypeList)):
674 673 if self.dataOutObj.dtype == dtypeList[index]:
675 674 datatypeValue = datatypeValueList[index]
676 675 break
677 676
678 677
679 678 pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints
680 679
681 680 pts2write_SelfSpectra = int(self.nWrChannels * pts2write)
682 681 blocksize = (pts2write_SelfSpectra*datatypeValue)
683 682
684 683 if self.dataOutObj.data_cspc != None:
685 684 pts2write_CrossSpectra = int(self.nWrPairs * pts2write)
686 685 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
687 686
688 687 if self.dataOutObj.data_dc != None:
689 688 pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights)
690 689 blocksize += (pts2write_DCchannels*datatypeValue*2)
691 690
692 691 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
693 692
694 693 return blocksize
695 694
696 695
697 696 def getBasicHeader(self):
698 697 self.basicHeaderObj.size = self.basicHeaderSize #bytes
699 698 self.basicHeaderObj.version = self.versionFile
700 699 self.basicHeaderObj.dataBlock = self.nTotalBlocks
701 700
702 701 utc = numpy.floor(self.dataOutObj.utctime)
703 702 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
704 703
705 704 self.basicHeaderObj.utc = utc
706 705 self.basicHeaderObj.miliSecond = milisecond
707 706 self.basicHeaderObj.timeZone = 0
708 707 self.basicHeaderObj.dstFlag = 0
709 708 self.basicHeaderObj.errorCount = 0
710 709
711 710 def getDataHeader(self):
712 711
713 712 """
714 713 Obtiene una copia del First Header
715 714
716 715 Affected:
717 716 self.systemHeaderObj
718 717 self.radarControllerHeaderObj
719 718 self.dtype
720 719
721 720 Return:
722 721 None
723 722 """
724 723
725 724 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
726 725 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
727 726 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
728 727
729 728 self.getBasicHeader()
730 729
731 730 processingHeaderSize = 40 # bytes
732 731 self.processingHeaderObj.dtype = 0 # Voltage
733 732 self.processingHeaderObj.blockSize = self.__getBlockSize()
734 733 self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints
735 734 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
736 735 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
737 736 self.processingHeaderObj.processFlags = self.__getProcessFlags()
738 737 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt# Se requiere para determinar el valor de timeInterval
739 738 self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt
740 739 self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels
741 740
742 741 if self.processingHeaderObj.totalSpectra > 0:
743 742 channelList = []
744 743 for channel in range(self.dataOutObj.nChannels):
745 744 channelList.append(channel)
746 745 channelList.append(channel)
747 746
748 747 pairsList = []
749 748 for pair in self.dataOutObj.pairsList:
750 749 pairsList.append(pair[0])
751 750 pairsList.append(pair[1])
752 751 spectraComb = channelList + pairsList
753 752 spectraComb = numpy.array(spectraComb,dtype="u1")
754 753 self.processingHeaderObj.spectraComb = spectraComb
755 754 sizeOfSpcComb = len(spectraComb)
756 755 processingHeaderSize += sizeOfSpcComb
757 756
758 757 if self.dataOutObj.code != None:
759 758 self.processingHeaderObj.code = self.dataOutObj.code
760 759 self.processingHeaderObj.nCode = self.dataOutObj.nCode
761 760 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
762 761 nCodeSize = 4 # bytes
763 762 nBaudSize = 4 # bytes
764 763 codeSize = 4 # bytes
765 764 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud)
766 765 processingHeaderSize += sizeOfCode
767 766
768 767 if self.processingHeaderObj.nWindows != 0:
769 768 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
770 769 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
771 770 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
772 771 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
773 772 sizeOfFirstHeight = 4
774 773 sizeOfdeltaHeight = 4
775 774 sizeOfnHeights = 4
776 775 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
777 776 processingHeaderSize += sizeOfWindows
778 777
779 778 self.processingHeaderObj.size = processingHeaderSize
780 779
781 780
782 781
783 782 class FITS:
784 783 name=None
785 784 format=None
786 785 array =None
787 786 data =None
788 787 thdulist=None
788 prihdr=None
789 hdu=None
789 790
790 791 def __init__(self):
791 792
792 793 pass
793 794
794 795 def setColF(self,name,format,array):
795 796 self.name=name
796 797 self.format=format
797 798 self.array=array
798 799 a1=numpy.array([self.array],dtype=numpy.float32)
799 800 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
800 801 return self.col1
801 802
802 803 # def setColP(self,name,format,data):
803 804 # self.name=name
804 805 # self.format=format
805 806 # self.data=data
806 807 # a2=numpy.array([self.data],dtype=numpy.float32)
807 808 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
808 809 # return self.col2
809 810
810 def writeHeader(self,):
811 pass
812
811
813 812 def writeData(self,name,format,data):
814 813 self.name=name
815 814 self.format=format
816 815 self.data=data
817 816 a2=numpy.array([self.data],dtype=numpy.float32)
818 817 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
819 818 return self.col2
820 819
821 def cFImage(self,n):
822 self.hdu= pyfits.PrimaryHDU(n)
823 return self.hdu
824
825 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
826 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
820 def cFImage(self,idblock,year,month,day,hour,minute,second):
821 self.hdu= pyfits.PrimaryHDU(idblock)
822 self.hdu.header.set("Year",year)
823 self.hdu.header.set("Month",month)
824 self.hdu.header.set("Day",day)
825 self.hdu.header.set("Hour",hour)
826 self.hdu.header.set("Minute",minute)
827 self.hdu.header.set("Second",second)
828 return self.hdu
829
830
831 def Ctable(self,colList):
832 self.cols=pyfits.ColDefs(colList)
827 833 self.tbhdu = pyfits.new_table(self.cols)
828 834 return self.tbhdu
829 835
836
830 837 def CFile(self,hdu,tbhdu):
831 838 self.thdulist=pyfits.HDUList([hdu,tbhdu])
832
839
833 840 def wFile(self,filename):
834 841 self.thdulist.writeto(filename)
835 842
836 class SpectraHeisWriter():
837 i=0
843 class SpectraHeisWriter(JRODataWriter):
844 set = None
845 setFile = None
846 idblock = None
847 doypath = None
848 subfolder = None
849
838 850 def __init__(self, dataOutObj):
839 851 self.wrObj = FITS()
840 852 self.dataOutObj = dataOutObj
853 self.nTotalBlocks=0
854 self.set = None
855 self.setFile = 0
856 self.idblock = 0
857 self.wrpath = None
858 self.doypath = None
859 self.subfolder = None
860
841 861
842 862 def isNumber(str):
843 863 """
844 864 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
845 865
846 866 Excepciones:
847 867 Si un determinado string no puede ser convertido a numero
848 868 Input:
849 869 str, string al cual se le analiza para determinar si convertible a un numero o no
850 870
851 871 Return:
852 872 True : si el string es uno numerico
853 873 False : no es un string numerico
854 874 """
855 875 try:
856 876 float( str )
857 877 return True
858 878 except:
859 879 return False
860 880
861 def setup(self, wrpath,):
881 def setup(self, wrpath):
862 882
863 883 if not(os.path.exists(wrpath)):
864 884 os.mkdir(wrpath)
865 885
866 886 self.wrpath = wrpath
867 887 self.setFile = 0
868 888
869 889 def putData(self):
870 # self.wrObj.writeHeader(nChannels=self.dataOutObj.nChannels, nFFTPoints=self.dataOutObj.nFFTPoints)
871 #name = self.dataOutObj.utctime
872 890 name= time.localtime( self.dataOutObj.utctime)
873 ext=".fits"
874 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
875 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
891 ext=".fits"
892
893 if self.doypath == None:
894 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
895 self.doypath = os.path.join( self.wrpath, self.subfolder )
896 os.mkdir(self.doypath)
897
898 if self.set == None:
899 self.set = self.dataOutObj.set
900 self.setFile = 0
901 if self.set != self.dataOutObj.set:
902 self.set = self.dataOutObj.set
903 self.setFile = 0
904
905 #make the filename
906 file = 'D%4.4d%3.3d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.set,self.setFile,ext)
876 907
877 doypath = os.path.join( self.wrpath, subfolder )
878 if not( os.path.exists(doypath) ):
879 os.mkdir(doypath)
908 filename = os.path.join(self.wrpath,self.subfolder, file)
909
910 idblock = numpy.array([self.idblock],dtype="int64")
911 header=self.wrObj.cFImage(idblock=idblock,
912 year=time.gmtime(self.dataOutObj.utctime).tm_year,
913 month=time.gmtime(self.dataOutObj.utctime).tm_mon,
914 day=time.gmtime(self.dataOutObj.utctime).tm_mday,
915 hour=time.gmtime(self.dataOutObj.utctime).tm_hour,
916 minute=time.gmtime(self.dataOutObj.utctime).tm_min,
917 second=time.gmtime(self.dataOutObj.utctime).tm_sec)
918
919 c=3E8
920 freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*1000))
921
922 colList = []
923
924 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq)
925
926 colList.append(colFreq)
927
928 nchannel=self.dataOutObj.nChannels
929
930 for i in range(nchannel):
931 col = self.wrObj.writeData(name="PCh"+str(i+1),
932 format=str(self.dataOutObj.nFFTPoints)+'E',
933 data=10*numpy.log10(self.dataOutObj.data_spc[i,:]))
934
935 colList.append(col)
936
937 data=self.wrObj.Ctable(colList=colList)
938
939 self.wrObj.CFile(header,data)
940
941 self.wrObj.wFile(filename)
942
943 #update the setFile
880 944 self.setFile += 1
881 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
882
883 filename = os.path.join(self.wrpath,subfolder, file)
884
885 # print self.dataOutObj.ippSeconds
886 freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)/(2*self.dataOutObj.ippSeconds)
887
888 col1=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq)
889 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[0,:]))
890 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[1,:]))
891 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[2,:]))
892 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[3,:]))
893 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[4,:]))
894 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[5,:]))
895 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[6,:]))
896 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[7,:]))
897 #n=numpy.arange((100))
898 n=self.dataOutObj.data_spc[6,:]
899 a=self.wrObj.cFImage(n)
900 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
901 self.wrObj.CFile(a,b)
902 self.wrObj.wFile(filename)
945 self.idblock += 1
946
903 947 return 1
904 948
905 949 No newline at end of file
@@ -1,592 +1,602
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 glob
10 10 import fnmatch
11 11 import time, datetime
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from JROHeaderIO import *
17 17 from JRODataIO import JRODataReader
18 18 from JRODataIO import JRODataWriter
19 19
20 20 from Data.JROData import Voltage
21 21
22 22 class VoltageReader(JRODataReader):
23 23 """
24 24 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
25 25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
26 26 perfiles*alturas*canales) son almacenados en la variable "buffer".
27 27
28 28 perfiles * alturas * canales
29 29
30 30 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
31 31 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
32 32 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
33 33 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
34 34
35 35 Example:
36 36
37 37 dpath = "/home/myuser/data"
38 38
39 39 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
40 40
41 41 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
42 42
43 43 readerObj = VoltageReader()
44 44
45 45 readerObj.setup(dpath, startTime, endTime)
46 46
47 47 while(True):
48 48
49 49 #to get one profile
50 50 profile = readerObj.getData()
51 51
52 52 #print the profile
53 53 print profile
54 54
55 55 #If you want to see all datablock
56 56 print readerObj.datablock
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 62
63 63 ext = ".r"
64 64
65 65 optchar = "D"
66 66 dataOutObj = None
67 67
68 68
69 69 def __init__(self, dataOutObj=None):
70 70 """
71 71 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
72 72
73 73 Input:
74 74 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
75 75 almacenar un perfil de datos cada vez que se haga un requerimiento
76 76 (getData). El perfil sera obtenido a partir del buffer de datos,
77 77 si el buffer esta vacio se hara un nuevo proceso de lectura de un
78 78 bloque de datos.
79 79 Si este parametro no es pasado se creara uno internamente.
80 80
81 81 Variables afectadas:
82 82 self.dataOutObj
83 83
84 84 Return:
85 85 None
86 86 """
87 87
88 88 self.datablock = None
89 89
90 90 self.utc = 0
91 91
92 92 self.ext = ".r"
93 93
94 94 self.optchar = "D"
95 95
96 96 self.basicHeaderObj = BasicHeader()
97 97
98 98 self.systemHeaderObj = SystemHeader()
99 99
100 100 self.radarControllerHeaderObj = RadarControllerHeader()
101 101
102 102 self.processingHeaderObj = ProcessingHeader()
103 103
104 104 self.online = 0
105 105
106 106 self.fp = None
107 107
108 108 self.idFile = None
109 109
110 110 self.dtype = None
111 111
112 112 self.fileSizeByHeader = None
113 113
114 114 self.filenameList = []
115 115
116 116 self.filename = None
117 117
118 118 self.fileSize = None
119 119
120 120 self.firstHeaderSize = 0
121 121
122 122 self.basicHeaderSize = 24
123 123
124 124 self.pathList = []
125 125
126 126 self.filenameList = []
127 127
128 128 self.lastUTTime = 0
129 129
130 130 self.maxTimeStep = 30
131 131
132 132 self.flagNoMoreFiles = 0
133 133
134 134 self.set = 0
135 135
136 136 self.path = None
137 137
138 138 self.profileIndex = 9999
139 139
140 140 self.delay = 3 #seconds
141 141
142 142 self.nTries = 3 #quantity tries
143 143
144 144 self.nFiles = 3 #number of files for searching
145 145
146 146 self.nReadBlocks = 0
147 147
148 148 self.flagIsNewFile = 1
149 149
150 150 self.ippSeconds = 0
151 151
152 152 self.flagTimeBlock = 0
153 153
154 154 self.flagIsNewBlock = 0
155 155
156 156 self.nTotalBlocks = 0
157 157
158 158 self.blocksize = 0
159 159
160 160 def createObjByDefault(self):
161 161
162 162 dataObj = Voltage()
163 163
164 164 return dataObj
165 165
166 166 def __hasNotDataInBuffer(self):
167 167 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
168 168 return 1
169 169 return 0
170 170
171 171
172 172 def getBlockDimension(self):
173 173 """
174 174 Obtiene la cantidad de puntos a leer por cada bloque de datos
175 175
176 176 Affected:
177 177 self.blocksize
178 178
179 179 Return:
180 180 None
181 181 """
182 182 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
183 183 self.blocksize = pts2read
184 184
185 185
186 186 def readBlock(self):
187 187 """
188 188 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
189 189 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
190 190 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
191 191 es seteado a 0
192 192
193 193 Inputs:
194 194 None
195 195
196 196 Return:
197 197 None
198 198
199 199 Affected:
200 200 self.profileIndex
201 201 self.datablock
202 202 self.flagIsNewFile
203 203 self.flagIsNewBlock
204 204 self.nTotalBlocks
205 205
206 206 Exceptions:
207 207 Si un bloque leido no es un bloque valido
208 208 """
209 209
210 210 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
211 211
212 212 try:
213 213 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
214 214 except:
215 215 print "The read block (%3d) has not enough data" %self.nReadBlocks
216 216 return 0
217 217
218 218 junk = numpy.transpose(junk, (2,0,1))
219 219 self.datablock = junk['real'] + junk['imag']*1j
220 220
221 221 self.profileIndex = 0
222 222
223 223 self.flagIsNewFile = 0
224 224 self.flagIsNewBlock = 1
225 225
226 226 self.nTotalBlocks += 1
227 227 self.nReadBlocks += 1
228 228
229 229 return 1
230 230
231
232 def __getset(self,filename):
233 name = os.path.basename(filename)
234 basename,ext = os.path.splitext(name)
235 set = int(basename[8:])
236 return set
231 237
232 238 def getData(self):
233 239 """
234 240 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
235 241 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
236 242 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
237 243
238 244 Ademas incrementa el contador del buffer en 1.
239 245
240 246 Return:
241 247 data : retorna un perfil de voltages (alturas * canales) copiados desde el
242 248 buffer. Si no hay mas archivos a leer retorna None.
243 249
244 250 Variables afectadas:
245 251 self.dataOutObj
246 252 self.profileIndex
247 253
248 254 Affected:
249 255 self.dataOutObj
250 256 self.profileIndex
251 257 self.flagTimeBlock
252 258 self.flagIsNewBlock
253 259 """
254 260 if self.flagNoMoreFiles: return 0
255 261
256 262 self.flagTimeBlock = 0
257 263 self.flagIsNewBlock = 0
258 264
259 265 if self.__hasNotDataInBuffer():
260 266
261 267 if not( self.readNextBlock() ):
262 268 return 0
263 269
264 270 # self.updateDataHeader()
265 271
266 272 if self.flagNoMoreFiles == 1:
267 273 print 'Process finished'
268 274 return 0
269 275
270 276 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
271 277
272 278 if self.datablock == None:
273 279 self.dataOutObj.flagNoData = True
274 280 return 0
275 281
282 self.dataOutObj.set = self.__getset(self.filename)
283
276 284 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
277 285
278 286 self.dataOutObj.dtype = self.dtype
279 287
280 288 self.dataOutObj.nChannels = self.systemHeaderObj.nChannels
281 289
282 290 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
283 291
284 292 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
285 293
286 294 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
287 295
288 296 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
289 297
290 298 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
291 299
292 300 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
293 301
294 302 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
295 303
296 304 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
297 305
298 306 self.dataOutObj.ippSeconds = self.ippSeconds
299 307
308 self.dataOutObj.deltaHeight = self.processingHeaderObj.deltaHeight
309
300 310 self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
301 311
302 312 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
303 313
304 314 self.dataOutObj.flagShiftFFT = False
305 315
306 316 if self.processingHeaderObj.code != None:
307 317 self.dataOutObj.nCode = self.processingHeaderObj.nCode
308 318
309 319 self.dataOutObj.nBaud = self.processingHeaderObj.nBaud
310 320
311 321 self.dataOutObj.code = self.processingHeaderObj.code
312 322
313 323 self.profileIndex += 1
314 324
315 325 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
316 326
317 327 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
318 328
319 329 self.dataOutObj.flagNoData = False
320 330
321 331 # print self.profileIndex, self.dataOutObj.utctime
322 332 # if self.profileIndex == 800:
323 333 # a=1
324 334
325 335 return self.dataOutObj.data
326 336
327 337
328 338 class VoltageWriter(JRODataWriter):
329 339 """
330 340 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
331 341 de los datos siempre se realiza por bloques.
332 342 """
333 343
334 344 ext = ".r"
335 345
336 346 optchar = "D"
337 347
338 348 shapeBuffer = None
339 349
340 350
341 351 def __init__(self, dataOutObj=None):
342 352 """
343 353 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
344 354
345 355 Affected:
346 356 self.dataOutObj
347 357
348 358 Return: None
349 359 """
350 360 if dataOutObj == None:
351 361 dataOutObj = Voltage()
352 362
353 363 if not( isinstance(dataOutObj, Voltage) ):
354 364 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
355 365
356 366 self.dataOutObj = dataOutObj
357 367
358 368 self.nTotalBlocks = 0
359 369
360 370 self.profileIndex = 0
361 371
362 372 def hasAllDataInBuffer(self):
363 373 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
364 374 return 1
365 375 return 0
366 376
367 377
368 378 def setBlockDimension(self):
369 379 """
370 380 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
371 381
372 382 Affected:
373 383 self.shape_spc_Buffer
374 384 self.shape_cspc_Buffer
375 385 self.shape_dc_Buffer
376 386
377 387 Return: None
378 388 """
379 389 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
380 390 self.processingHeaderObj.nHeights,
381 391 self.systemHeaderObj.nChannels)
382 392
383 393 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
384 394 self.processingHeaderObj.profilesPerBlock,
385 395 self.processingHeaderObj.nHeights),
386 396 dtype=numpy.dtype('complex'))
387 397
388 398
389 399 def writeBlock(self):
390 400 """
391 401 Escribe el buffer en el file designado
392 402
393 403 Affected:
394 404 self.profileIndex
395 405 self.flagIsNewFile
396 406 self.flagIsNewBlock
397 407 self.nTotalBlocks
398 408 self.blockIndex
399 409
400 410 Return: None
401 411 """
402 412 data = numpy.zeros( self.shapeBuffer, self.dtype )
403 413
404 414 junk = numpy.transpose(self.datablock, (1,2,0))
405 415
406 416 data['real'] = junk.real
407 417 data['imag'] = junk.imag
408 418
409 419 data = data.reshape( (-1) )
410 420
411 421 data.tofile( self.fp )
412 422
413 423 self.datablock.fill(0)
414 424
415 425 self.profileIndex = 0
416 426 self.flagIsNewFile = 0
417 427 self.flagIsNewBlock = 1
418 428
419 429 self.blockIndex += 1
420 430 self.nTotalBlocks += 1
421 431
422 432 def putData(self):
423 433 """
424 434 Setea un bloque de datos y luego los escribe en un file
425 435
426 436 Affected:
427 437 self.flagIsNewBlock
428 438 self.profileIndex
429 439
430 440 Return:
431 441 0 : Si no hay data o no hay mas files que puedan escribirse
432 442 1 : Si se escribio la data de un bloque en un file
433 443 """
434 444 self.flagIsNewBlock = 0
435 445
436 446 if self.dataOutObj.flagNoData:
437 447 return 0
438 448
439 449 if self.dataOutObj.flagTimeBlock:
440 450
441 451 self.datablock.fill(0)
442 452 self.profileIndex = 0
443 453 self.setNextFile()
444 454
445 455 if self.profileIndex == 0:
446 456 self.getBasicHeader()
447 457
448 458 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
449 459
450 460 self.profileIndex += 1
451 461
452 462 if self.hasAllDataInBuffer():
453 463 #if self.flagIsNewFile:
454 464 self.writeNextBlock()
455 465 # self.getDataHeader()
456 466
457 467 if self.flagNoMoreFiles:
458 468 #print 'Process finished'
459 469 return 0
460 470
461 471 return 1
462 472
463 473 def __getProcessFlags(self):
464 474
465 475 processFlags = 0
466 476
467 477 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
468 478 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
469 479 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
470 480 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
471 481 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
472 482 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
473 483
474 484 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
475 485
476 486
477 487
478 488 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
479 489 PROCFLAG.DATATYPE_SHORT,
480 490 PROCFLAG.DATATYPE_LONG,
481 491 PROCFLAG.DATATYPE_INT64,
482 492 PROCFLAG.DATATYPE_FLOAT,
483 493 PROCFLAG.DATATYPE_DOUBLE]
484 494
485 495
486 496 for index in range(len(dtypeList)):
487 497 if self.dataOutObj.dtype == dtypeList[index]:
488 498 dtypeValue = datatypeValueList[index]
489 499 break
490 500
491 501 processFlags += dtypeValue
492 502
493 503 if self.dataOutObj.flagDecodeData:
494 504 processFlags += PROCFLAG.DECODE_DATA
495 505
496 506 if self.dataOutObj.flagDeflipData:
497 507 processFlags += PROCFLAG.DEFLIP_DATA
498 508
499 509 if self.dataOutObj.code != None:
500 510 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
501 511
502 512 if self.dataOutObj.nCohInt > 1:
503 513 processFlags += PROCFLAG.COHERENT_INTEGRATION
504 514
505 515 return processFlags
506 516
507 517
508 518 def __getBlockSize(self):
509 519 '''
510 520 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
511 521 '''
512 522
513 523 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
514 524 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
515 525 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
516 526 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
517 527 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
518 528 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
519 529
520 530 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
521 531 datatypeValueList = [1,2,4,8,4,8]
522 532 for index in range(len(dtypeList)):
523 533 if self.dataOutObj.dtype == dtypeList[index]:
524 534 datatypeValue = datatypeValueList[index]
525 535 break
526 536
527 537 blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2)
528 538
529 539 return blocksize
530 540
531 541
532 542 def getBasicHeader(self):
533 543 self.basicHeaderObj.size = self.basicHeaderSize #bytes
534 544 self.basicHeaderObj.version = self.versionFile
535 545 self.basicHeaderObj.dataBlock = self.nTotalBlocks
536 546
537 547 utc = numpy.floor(self.dataOutObj.utctime)
538 548 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
539 549
540 550 self.basicHeaderObj.utc = utc
541 551 self.basicHeaderObj.miliSecond = milisecond
542 552 self.basicHeaderObj.timeZone = 0
543 553 self.basicHeaderObj.dstFlag = 0
544 554 self.basicHeaderObj.errorCount = 0
545 555
546 556 def getDataHeader(self):
547 557
548 558 """
549 559 Obtiene una copia del First Header
550 560
551 561 Affected:
552 562 self.systemHeaderObj
553 563 self.radarControllerHeaderObj
554 564 self.dtype
555 565
556 566 Return:
557 567 None
558 568 """
559 569
560 570 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
561 571 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
562 572 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
563 573
564 574 self.getBasicHeader()
565 575
566 576 processingHeaderSize = 40 # bytes
567 577 self.processingHeaderObj.dtype = 0 # Voltage
568 578 self.processingHeaderObj.blockSize = self.__getBlockSize()
569 579 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
570 580 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
571 581 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
572 582 self.processingHeaderObj.processFlags = self.__getProcessFlags()
573 583 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt
574 584 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
575 585 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
576 586
577 587 if self.dataOutObj.code != None:
578 588 self.processingHeaderObj.code = self.dataOutObj.code
579 589 self.processingHeaderObj.nCode = self.dataOutObj.nCode
580 590 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
581 591 codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud)
582 592 processingHeaderSize += codesize
583 593
584 594 if self.processingHeaderObj.nWindows != 0:
585 595 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
586 596 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
587 597 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
588 598 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
589 599 processingHeaderSize += 12
590 600
591 601 self.processingHeaderObj.size = processingHeaderSize
592 602 No newline at end of file
@@ -1,778 +1,859
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 Spectra, SpectraHeis
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter,SpectraHeisWriter
16 16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure
17 from Graphics.BaseGraph_mpl import LinearPlot
17 18 #from JRONoise import Noise
18 19
19 20 class SpectraProcessor:
20 21 '''
21 22 classdocs
22 23 '''
23 24
24 25 dataInObj = None
25 26
26 27 dataOutObj = None
27 28
28 29 noiseObj = None
29 30
30 31 integratorObjList = []
31 32
32 33 writerObjList = []
33 34
34 35 integratorObjIndex = None
35 36
36 37 writerObjIndex = None
37 38
38 39 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39 40
40 41 firstdatatime = None
41 42
42 43 def __init__(self):
43 44 '''
44 45 Constructor
45 46 '''
46 47
47 48 self.integratorObjIndex = None
48 49 self.writerObjIndex = None
49 50 self.plotObjIndex = None
50 51 self.integratorOst = []
51 52 self.plotObjList = []
52 53 self.noiseObj = []
53 54 self.writerObjList = []
54 55 self.buffer = None
55 56 self.firstdatatime = None
56 57 self.profIndex = 0
57 58
58 59 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None, wavelength=6):
59 60
60 61 if dataInObj == None:
61 62 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
62 63
63 64 if dataInObj.type == "Voltage":
64 65 if nFFTPoints == None:
65 66 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
66 67
67 68
68 69
69 70 if dataInObj.type == "Spectra":
70 71 if nFFTPoints != None:
71 72 raise ValueError, "The nFFTPoints cannot be selected to this object type"
72 73
73 74 nFFTPoints = dataInObj.nFFTPoints
74 75
75 76 if pairsList == None:
76 77 pairsList = dataInObj.pairsList
77 78
78 79 if pairsList == None:
79 80 nPairs = 0
80 81 else:
81 82 nPairs = len(pairsList)
82 83
83 84 self.dataInObj = dataInObj
84 85
85 86 if dataOutObj == None:
86 87 dataOutObj = Spectra()
87 88
88 89 self.dataOutObj = dataOutObj
89 90 self.dataOutObj.nFFTPoints = nFFTPoints
90 91 self.dataOutObj.pairsList = pairsList
91 92 self.dataOutObj.nPairs = nPairs
92 93 self.dataOutObj.wavelength = wavelength
93 94
94 95 return self.dataOutObj
95 96
96 97 def init(self):
97 98
98 99 """
99 100
100 101 Este metodo reinicia los contadores de los objetos integrator, writer y plotter
101 102 y actualiza los parametros del objeto de salida dataOutObj a partir del objeto de entrada.
102 103
103 104 """
104 105
105 106 self.dataOutObj.flagNoData = True
106 107
107 108 if self.dataInObj.flagNoData:
108 109 return 0
109 110
110 111 self.integratorObjIndex = 0
111 112 self.writerObjIndex = 0
112 113 self.plotObjIndex = 0
113 114
114 115
115 116 if self.dataInObj.type == "Spectra":
116 117
117 118 self.dataOutObj.copy(self.dataInObj)
118 119 self.dataOutObj.flagNoData = False
119 120 return
120 121
121 122 if self.dataInObj.type == "Voltage":
122 123
123 124 if self.buffer == None:
124 125 self.buffer = numpy.zeros((self.dataInObj.nChannels,
125 126 self.dataOutObj.nFFTPoints,
126 127 self.dataInObj.nHeights),
127 128 dtype='complex')
128 129
129 130 self.buffer[:,self.profIndex,:] = self.dataInObj.data
130 131 self.profIndex += 1
131 132
132 133 if self.firstdatatime == None:
133 134 self.firstdatatime = self.dataInObj.utctime
134 135
135 136 if self.profIndex == self.dataOutObj.nFFTPoints:
136 137
137 138 self.__updateObjFromInput()
138 139 self.__getFft()
139 140
140 141 self.dataOutObj.flagNoData = False
141 142
142 143 self.buffer = None
143 144 self.firstdatatime = None
144 145 self.profIndex = 0
145 146
146 147 return
147 148
148 149 #Other kind of data
149 150 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
150 151
151 152 def __getFft(self):
152 153 """
153 154 Convierte valores de Voltaje a Spectra
154 155
155 156 Affected:
156 157 self.dataOutObj.data_spc
157 158 self.dataOutObj.data_cspc
158 159 self.dataOutObj.data_dc
159 160 self.dataOutObj.heightList
160 161 self.dataOutObj.m_BasicHeader
161 162 self.dataOutObj.m_ProcessingHeader
162 163 self.dataOutObj.radarControllerHeaderObj
163 164 self.dataOutObj.systemHeaderObj
164 165 self.profIndex
165 166 self.buffer
166 167 self.dataOutObj.flagNoData
167 168 self.dataOutObj.dtype
168 169 self.dataOutObj.nPairs
169 170 self.dataOutObj.nChannels
170 171 self.dataOutObj.nProfiles
171 172 self.dataOutObj.systemHeaderObj.numChannels
172 173 self.dataOutObj.m_ProcessingHeader.totalSpectra
173 174 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
174 175 self.dataOutObj.m_ProcessingHeader.numHeights
175 176 self.dataOutObj.m_ProcessingHeader.spectraComb
176 177 self.dataOutObj.m_ProcessingHeader.shif_fft
177 178 """
178 179
179 180 fft_volt = numpy.fft.fft(self.buffer,axis=1)
180 181 dc = fft_volt[:,0,:]
181 182
182 183 #calculo de self-spectra
183 184 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
184 185 spc = fft_volt * numpy.conjugate(fft_volt)
185 186 spc = spc.real
186 187
187 188 blocksize = 0
188 189 blocksize += dc.size
189 190 blocksize += spc.size
190 191
191 192 cspc = None
192 193 pairIndex = 0
193 194 if self.dataOutObj.pairsList != None:
194 195 #calculo de cross-spectra
195 196 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
196 197 for pair in self.dataOutObj.pairsList:
197 198 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
198 199 pairIndex += 1
199 200 blocksize += cspc.size
200 201
201 202 self.dataOutObj.data_spc = spc
202 203 self.dataOutObj.data_cspc = cspc
203 204 self.dataOutObj.data_dc = dc
204 205 self.dataOutObj.blockSize = blocksize
205 206
206 207 # self.getNoise()
207 208
208 209 def __updateObjFromInput(self):
209 210
210 211 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
211 212 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
212 213 self.dataOutObj.channelList = self.dataInObj.channelList
213 214 self.dataOutObj.heightList = self.dataInObj.heightList
214 215 self.dataOutObj.dtype = self.dataInObj.dtype
215 216 self.dataOutObj.nHeights = self.dataInObj.nHeights
216 217 self.dataOutObj.nChannels = self.dataInObj.nChannels
217 218 self.dataOutObj.nBaud = self.dataInObj.nBaud
218 219 self.dataOutObj.nCode = self.dataInObj.nCode
219 220 self.dataOutObj.code = self.dataInObj.code
220 221 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
221 222 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
222 223 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
223 224 self.dataOutObj.utctime = self.firstdatatime
224 225 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
225 226 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
226 227 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
227 228 self.dataOutObj.nCohInt = self.dataInObj.nCohInt
228 229 self.dataOutObj.nIncohInt = 1
229 230 self.dataOutObj.ippSeconds = self.dataInObj.ippSeconds
230 231 self.dataOutObj.timeInterval = self.dataInObj.timeInterval*self.dataOutObj.nFFTPoints
231 232
232 233 def addWriter(self, wrpath, blocksPerFile):
233 234
234 235 objWriter = SpectraWriter(self.dataOutObj)
235 236 objWriter.setup(wrpath, blocksPerFile)
236 237 self.writerObjList.append(objWriter)
237 238
238 239 def addIntegrator(self,N,timeInterval):
239 240
240 241 objIncohInt = IncoherentIntegration(N,timeInterval)
241 242 self.integratorObjList.append(objIncohInt)
242 243
243 244 def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
244 245 crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
245 246 self.plotObjList.append(crossSpcObj)
246 247
247 248 def plotCrossSpc(self, idfigure=None,
248 249 xmin=None,
249 250 xmax=None,
250 251 ymin=None,
251 252 ymax=None,
252 253 minvalue=None,
253 254 maxvalue=None,
254 255 wintitle='',
255 256 driver='plplot',
256 257 colormap='br_green',
257 258 colorbar=True,
258 259 showprofile=False,
259 260 save=False,
260 261 gpath=None,
261 262 pairsList = None):
262 263
263 264 if self.dataOutObj.flagNoData:
264 265 return 0
265 266
266 267 if pairsList == None:
267 268 pairsList = self.dataOutObj.pairsList
268 269
269 270 nframes = len(pairsList)
270 271
271 272 x = numpy.arange(self.dataOutObj.nFFTPoints)
272 273
273 274 y = self.dataOutObj.heightList
274 275
275 276 data_spc = self.dataOutObj.data_spc
276 277 data_cspc = self.dataOutObj.data_cspc
277 278
278 279 data = []
279 280
280 281
281 282 if len(self.plotObjList) <= self.plotObjIndex:
282 283 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
283 284
284 285
285 286
286 287
287 288
288 289 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
289 290 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
290 291 self.plotObjList.append(rtiObj)
291 292
292 293 def plotRti(self, idfigure=None,
293 294 starttime=None,
294 295 endtime=None,
295 296 rangemin=None,
296 297 rangemax=None,
297 298 minvalue=None,
298 299 maxvalue=None,
299 300 wintitle='',
300 301 driver='plplot',
301 302 colormap='br_greeen',
302 303 colorbar=True,
303 304 showprofile=False,
304 305 xrangestep=None,
305 306 save=False,
306 307 gpath=None,
307 308 ratio=1,
308 309 channelList=None):
309 310
310 311 if self.dataOutObj.flagNoData:
311 312 return 0
312 313
313 314 if channelList == None:
314 315 channelList = self.dataOutObj.channelList
315 316
316 317 nframes = len(channelList)
317 318
318 319 if len(self.plotObjList) <= self.plotObjIndex:
319 320 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
320 321
321 322 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
322 323
323 324 data = numpy.average(data, axis=1)
324 325
325 326 currenttime = self.dataOutObj.utctime - time.timezone
326 327
327 328 range = self.dataOutObj.heightList
328 329
329 330
330 331 figuretitle = "RTI Plot for Spectra Data" #+ date
331 332
332 333 cleardata = False
333 334
334 335 deltax = self.dataOutObj.timeInterval
335 336
336 337 plotObj = self.plotObjList[self.plotObjIndex]
337 338
338 339 plotObj.plotPcolor(data=data,
339 340 x=currenttime,
340 341 y=range,
341 342 channelList=channelList,
342 343 xmin=starttime,
343 344 xmax=endtime,
344 345 ymin=rangemin,
345 346 ymax=rangemax,
346 347 minvalue=minvalue,
347 348 maxvalue=maxvalue,
348 349 figuretitle=figuretitle,
349 350 xrangestep=xrangestep,
350 351 deltax=deltax,
351 352 save=save,
352 353 gpath=gpath,
353 354 ratio=ratio,
354 355 cleardata=cleardata
355 356 )
356 357
357 358
358 359
359 360 self.plotObjIndex += 1
360 361
361 362
362 363
363 364
364 365
365 366
366 367
367 368 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
368 369
369 370 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
370 371 self.plotObjList.append(spcObj)
371 372
372 373 def plotSpc(self, idfigure=None,
373 374 xmin=None,
374 375 xmax=None,
375 376 ymin=None,
376 377 ymax=None,
377 378 minvalue=None,
378 379 maxvalue=None,
379 380 wintitle='',
380 381 driver='plplot',
381 382 colormap='br_green',
382 383 colorbar=True,
383 384 showprofile=False,
384 385 save=False,
385 386 gpath=None,
386 387 ratio=1,
387 388 channelList=None):
388 389
389 390 if self.dataOutObj.flagNoData:
390 391 return 0
391 392
392 393 if channelList == None:
393 394 channelList = self.dataOutObj.channelList
394 395
395 396 nframes = len(channelList)
396 397
397 398 if len(self.plotObjList) <= self.plotObjIndex:
398 399 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
399 400
400 401 x = numpy.arange(self.dataOutObj.nFFTPoints)
401 402
402 403 y = self.dataOutObj.heightList
403 404
404 405 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
405 406 # noisedB = 10.*numpy.log10(noise)
406 407 noisedB = numpy.arange(len(channelList)+1)
407 408 noisedB = noisedB *1.2
408 409 titleList = []
409 410 for i in range(len(noisedB)):
410 411 title = "%.2f"%noisedB[i]
411 412 titleList.append(title)
412 413
413 414 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
414 415 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
415 416 figuretitle = "Spc Radar Data: %s"%dateTime
416 417
417 418 cleardata = True
418 419
419 420 plotObj = self.plotObjList[self.plotObjIndex]
420 421
421 422 plotObj.plotPcolor(data=data,
422 423 x=x,
423 424 y=y,
424 425 channelList=channelList,
425 426 xmin=xmin,
426 427 xmax=xmax,
427 428 ymin=ymin,
428 429 ymax=ymax,
429 430 minvalue=minvalue,
430 431 maxvalue=maxvalue,
431 432 figuretitle=figuretitle,
432 433 xrangestep=None,
433 434 deltax=None,
434 435 save=save,
435 436 gpath=gpath,
436 437 cleardata=cleardata
437 438 )
438 439
439 440 self.plotObjIndex += 1
440 441
441 442
442 443 def writeData(self, wrpath, blocksPerFile):
443 444
444 445 if self.dataOutObj.flagNoData:
445 446 return 0
446 447
447 448 if len(self.writerObjList) <= self.writerObjIndex:
448 449 self.addWriter(wrpath, blocksPerFile)
449 450
450 451 self.writerObjList[self.writerObjIndex].putData()
451 452
452 453 self.writerObjIndex += 1
453 454
454 455 def integrator(self, N=None, timeInterval=None):
455 456
456 457 if self.dataOutObj.flagNoData:
457 458 return 0
458 459
459 460 if len(self.integratorObjList) <= self.integratorObjIndex:
460 461 self.addIntegrator(N,timeInterval)
461 462
462 463 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
463 464 myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime)
464 465
465 466 if myIncohIntObj.isReady:
466 467 self.dataOutObj.data_spc = myIncohIntObj.data
467 468 self.dataOutObj.timeInterval *= myCohIntObj.nIncohInt
468 469 self.dataOutObj.nIncohInt = myIncohIntObj.navg * self.dataInObj.nIncohInt
469 470 self.dataOutObj.utctime = myIncohIntObj.firstdatatime
470 471 self.dataOutObj.flagNoData = False
471 472
472 473 """Calcular el ruido"""
473 474 self.getNoise()
474 475 else:
475 476 self.dataOutObj.flagNoData = True
476 477
477 478 self.integratorObjIndex += 1
478 479
479 480
480 481 class SpectraHeisProcessor:
481 482
482 483 def __init__(self):
483 484
484 485 self.integratorObjIndex = None
485 486 self.writerObjIndex = None
486 487 self.plotObjIndex = None
487 488 self.integratorObjList = []
488 489 self.writerObjList = []
489 490 self.plotObjList = []
490 491 #self.noiseObj = Noise()
491 492
492 493 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
493 494
494 495 if nFFTPoints == None:
495 496 nFFTPoints = self.dataInObj.nHeights
496 497
497 498 self.dataInObj = dataInObj
498 499
499 500 if dataOutObj == None:
500 501 dataOutObj = SpectraHeis()
501 502
502 503 self.dataOutObj = dataOutObj
503 504
504 505 return self.dataOutObj
505 506
506 507 def init(self):
507 508
508 509 self.dataOutObj.flagNoData = True
509 510
510 511 if self.dataInObj.flagNoData:
511 512 return 0
512 513
513 514 self.integratorObjIndex = 0
514 515 self.writerObjIndex = 0
515 516 self.plotObjIndex = 0
516 517
517 518 if self.dataInObj.type == "Voltage":
518 519 self.__updateObjFromInput()
519 520 self.__getFft()
520 521 self.dataOutObj.flagNoData = False
521 522 return
522 523
523 524 #Other kind of data
524 525 if self.dataInObj.type == "SpectraHeis":
525 526 self.dataOutObj.copy(self.dataInObj)
526 527 self.dataOutObj.flagNoData = False
527 528 return
528 529
529 530 raise ValueError, "The type is not valid"
530 531
531 532 def __updateObjFromInput(self):
532 533
533 534 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
534 535 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
535 536 self.dataOutObj.channelList = self.dataInObj.channelList
536 537 self.dataOutObj.heightList = self.dataInObj.heightList
537 538 self.dataOutObj.dtype = self.dataInObj.dtype
538 539 self.dataOutObj.nHeights = self.dataInObj.nHeights
539 540 self.dataOutObj.nChannels = self.dataInObj.nChannels
540 541 self.dataOutObj.nBaud = self.dataInObj.nBaud
541 542 self.dataOutObj.nCode = self.dataInObj.nCode
542 543 self.dataOutObj.code = self.dataInObj.code
543 544 self.dataOutObj.nProfiles = 1
544 545 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
545 546 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
546 547 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
547 548 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
548 549 self.dataOutObj.utctime = self.dataInObj.utctime
549 550 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
550 551 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
551 552 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
552 553 self.dataOutObj.nIncohInt = 1
553 554 self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds
554
555 self.dataOutObj.set=self.dataInObj.set
556 self.dataOutObj.deltaHeight=self.dataInObj.deltaHeight
557
555 558 # def addWriter(self,wrpath,blocksPerfile):
556 559 def addWriter(self,wrpath):
557 560 objWriter=SpectraHeisWriter(self.dataOutObj)
558 561 objWriter.setup(wrpath)
559 562 #objWriter.setup(wrpath,blocksPerfile)
560 563 self.writerObjList.append(objWriter)
561 564
562 565 # def writedata(self,wrpath,blocksPerfile):
563 566 def writedata(self,wrpath):
564 567 if self.dataOutObj.flagNoData:
565 568 return 0
566 569
567 570 if len(self.writerObjList) <= self.writerObjIndex:
568 571 #self.addWriter(wrpath, blocksPerFile)
569 572 self.addWriter(wrpath)
570 573
571 574 self.writerObjList[self.writerObjIndex].putData()
572 575
573 576 self.writerObjIndex += 1
574 577
575 578 def __getFft(self):
576 579
577 580 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
578 581 #print fft_volt
579 582 #calculo de self-spectra
580 583 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
581 584
582 585 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
583 586 self.dataOutObj.data_spc = spc
584 587
585 588 def getSpectra(self):
586 589
587 590 return self.dataOutObj.data_spc
588 591
589 592 def getFrecuencies(self):
590 593
591 594 print self.nFFTPoints
592 595 return numpy.arange(int(self.nFFTPoints))
593 596
594 597 def addIntegrator(self,N,timeInterval):
595 598
596 599 objIncohInt = IncoherentIntegration(N,timeInterval)
597 600 self.integratorObjList.append(objIncohInt)
598 601
599 602 def integrator(self, N=None, timeInterval=None):
600 603
601 604 if self.dataOutObj.flagNoData:
602 605 return 0
603 606
604 607 if len(self.integratorObjList) <= self.integratorObjIndex:
605 608 self.addIntegrator(N,timeInterval)
606 609
607 610 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
608 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
611 myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime)
609 612
610 613 if myIncohIntObj.isReady:
611 614 self.dataOutObj.data_spc = myIncohIntObj.data
612 615 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
613 616 self.dataOutObj.flagNoData = False
614 617
615 618 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
616 619 # self.getNoise(type="sort", parm=16)
617 620
618 621 else:
619 622 self.dataOutObj.flagNoData = True
620 623
621 624 self.integratorObjIndex += 1
622 625
623 626
624 627 def addScope(self, idfigure, nframes, wintitle, driver):
625 628
626 629 if idfigure==None:
627 630 idfigure = self.plotObjIndex
628 631
629 632 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
630 633 self.plotObjList.append(scopeObj)
631 634
632 635 def plotScope(self,
633 636 idfigure=None,
634 637 minvalue=None,
635 638 maxvalue=None,
636 639 xmin=None,
637 640 xmax=None,
638 641 wintitle='',
639 642 driver='plplot',
640 643 save=False,
641 644 gpath=None,
642 645 titleList=None,
643 646 xlabelList=None,
644 647 ylabelList=None):
645 648
646 649 if self.dataOutObj.flagNoData:
647 650 return 0
648 651
649 652 nframes = len(self.dataOutObj.channelList)
650 653
651 654 if len(self.plotObjList) <= self.plotObjIndex:
652 655 self.addScope(idfigure, nframes, wintitle, driver)
653 656
654 657
655 658 data1D = self.dataOutObj.data_spc
656 659
657 660 x = numpy.arange(self.dataOutObj.nHeights)
658 661
659 662 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
660 663
661 664 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
662 665 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
663 666
664 667 figureTitle = "Scope Plot Radar Data: " + date
665 668
666 669 plotObj = self.plotObjList[self.plotObjIndex]
667 670
668 671 plotObj.plot1DArray(data1D,
669 672 x,
670 673 self.dataOutObj.channelList,
671 674 xmin,
672 675 xmax,
673 676 minvalue,
674 677 maxvalue,
675 678 figureTitle,
676 679 save,
677 680 gpath)
678 681
679 682 self.plotObjIndex += 1
683
684
685 def addPlotMatScope(self, indexPlot,nsubplot,winTitle):
686 linearObj = LinearPlot(indexPlot,nsubplot,winTitle)
687 self.plotObjList.append(linearObj)
688
689 def plotMatScope(self, idfigure,
690 channelList=None,
691 wintitle="",
692 save=None,
693 gpath=None):
694
695 if self.dataOutObj.flagNoData:
696 return 0
697
698 if channelList == None:
699 channelList = self.dataOutObj.channelList
700
701 nchannels = len(channelList)
702
703 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
704 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
705 winTitle = "Spectra Profile" #+ dateTime
706
707 if len(self.plotObjList) <= self.plotObjIndex:
708 self.addPlotMatScope(idfigure,nchannels,winTitle)
709 c = 3E8
710 x=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*self.dataOutObj.nHeights*1000))
711 x= x/(10000.0)
712
713 data = 10*numpy.log10(self.dataOutObj.data_spc)
714
715 subplotTitle = "Channel No."
716 xlabel = "Frecuencias(hz)*10K"
717 ylabel = "Potencia(dB)"
718
719 isPlotIni=False
720 isPlotConfig=False
721
722 ntimes=2
723 nsubplot= nchannels
724
725 plotObj = self.plotObjList[self.plotObjIndex]
726
727 # for i in range(ntimes):
728 #Creacion de Subplots
729 if not(plotObj.isPlotIni):
730 for index in range(nsubplot):
731 indexplot = index + 1
732 title = subplotTitle + '%d'%indexplot
733 xmin = numpy.min(x)
734 xmax = numpy.max(x)
735 ymin = numpy.min(data[index,:])
736 ymax = numpy.max(data[index,:])
737 plotObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel)
738 plotObj.isPlotIni =True
739
740 # Inicializa el grafico en cada itearcion
741 plotObj.setFigure(idfigure)
742 plotObj.setFigure("")
743
744 for index in range(nsubplot):
745 subplot = index
746 plotObj.iniPlot(subplot+1)
747 #Ploteo de datos
748
749 for channel in range(nsubplot):
750 y=data[channel,:]
751 plotObj.plot(channel+1,x,y,type='simple')
752
753 plotObj.refresh()
754
755 #time.sleep(0.05)
756
757 # plotObj.show()
758
759 self.plotObjIndex += 1
760 #print "Ploteo Finalizado"
680 761
681 762 def rti(self):
682 763 if self.dataOutObj.flagNoData:
683 764 return 0
684 765
685 766 data=numpy.average(self.dataOutObj.data_spc,axis=1)
686 767 data[0]
687 768 print data[0]
688 769 x = numpy.arange(100000)
689 770
690 771 print "test"
691 772 #print self.dataOutObj.data_spc.average(axis=1)
692 773
693 774 class IncoherentIntegration:
694 775
695 776 integ_counter = None
696 777 data = None
697 778 navg = None
698 779 buffer = None
699 780 nIncohInt = None
700 781 firstdatatime = None
701 782
702 783 def __init__(self, N = None, timeInterval = None):
703 784 """
704 785 N
705 786 timeInterval - interval time [min], integer value
706 787 """
707 788
708 789 self.data = None
709 790 self.navg = None
710 791 self.buffer = None
711 792 self.timeOut = None
712 793 self.exitCondition = False
713 794 self.isReady = False
714 795 self.nIncohInt = N
715 796 self.integ_counter = 0
716 797 self.firstdatatime = None
717 798
718 799 if timeInterval!=None:
719 800 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
720 801
721 802 if ((timeInterval==None) and (N==None)):
722 803 print 'N = None ; timeInterval = None'
723 804 sys.exit(0)
724 805 elif timeInterval == None:
725 806 self.timeFlag = False
726 807 else:
727 808 self.timeFlag = True
728 809
729 810
730 811 def exe(self,data,datatime):
731 812 """
732 813 data
733 814
734 815 datatime [seconds]
735 816 """
736 817 if self.firstdatatime == None or self.isReady:
737 818 self.firstdatatime = datatime
738 819
739 820 if self.timeFlag:
740 821 if self.timeOut == None:
741 822 self.timeOut = datatime + self.timeIntervalInSeconds
742 823
743 824 if datatime < self.timeOut:
744 825 if self.buffer == None:
745 826 self.buffer = data
746 827 else:
747 828 self.buffer = self.buffer + data
748 829 self.integ_counter += 1
749 830 else:
750 831 self.exitCondition = True
751 832
752 833 else:
753 834 if self.integ_counter < self.nIncohInt:
754 835 if self.buffer == None:
755 836 self.buffer = data
756 837 else:
757 838 self.buffer = self.buffer + data
758 839
759 840 self.integ_counter += 1
760 841
761 842 if self.integ_counter == self.nIncohInt:
762 843 self.exitCondition = True
763 844
764 845 if self.exitCondition:
765 846 self.data = self.buffer
766 847 self.navg = self.integ_counter
767 848 self.isReady = True
768 849 self.buffer = None
769 850 self.timeOut = None
770 851 self.integ_counter = 0
771 852 self.exitCondition = False
772 853
773 854 if self.timeFlag:
774 855 self.buffer = data
775 856 self.timeOut = datatime + self.timeIntervalInSeconds
776 857 else:
777 858 self.isReady = False
778 859 No newline at end of file
@@ -1,103 +1,112
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 i=None
24
25 25 def __init__(self):
26 26 self.setValues()
27 27 self.createObjects()
28 28 self.testSChain()
29 29 self.i=0
30
31
32 def VerifyArguments(self):
33 pass
34
35
36
37 def setValues(self):
38
30 39
31 def setValues( self ):
32 40
33 self.path="/home/roj-idl71/data"
41 self.path="D:\\te"
34 42
35 43 #self.path = ""
36 self.startDate = datetime.date(2012,4,1)
37 self.endDate = datetime.date(2012,6,30)
44 # self.startDate = datetime.date(2012,10,1)
45 # self.endDate = datetime.date(2012,12,30)
46 #
47 # self.startTime = datetime.time(0,0,0)
48 # self.endTime = datetime.time(23,0,0)
49 #
38 50
39 self.startTime = datetime.time(0,0,0)
40 self.endTime = datetime.time(23,0,0)
41
42
51
52
53 self.N=1000
54
55 self.wrpath = "D:\\te\\FITS"
56
57 self.online
58
59 self.startDate = None
60 self.endDate = None
61 self.startTime = None
62 self.endTime = None
63
64 # self.blocksPerFile = 1
43 65 def createObjects( self ):
44 66
45 67 self.readerObj = VoltageReader()
46 68 self.specProcObj = SpectraHeisProcessor()
47
48 69 self.voltObj1 = self.readerObj.setup(
49 70 path = self.path,
50 71 startDate = self.startDate,
51 72 endDate = self.endDate,
52 73 startTime = self.startTime,
53 74 endTime = self.endTime,
54 75 expLabel = '',
55 online = 0)
76 online = self.online)
56 77
57 78 if not(self.voltObj1):
58 79 sys.exit(0)
59 80
60 81 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights)
61
62
63 #
64
65 #
66
82 #
67 83 def testSChain( self ):
68 84
69 85 ini = time.time()
70 86 counter = 0
71 87 while(True):
72 88 self.readerObj.getData()
89
73 90 self.specProcObj.init()
74 91
75 self.specProcObj.integrator(N=32) ## return self.dataOutObj
92 self.specProcObj.integrator(self.N) ## return self.dataOutObj
76 93
77
78
79
80 self.specProcObj.plotScope(idfigure=1,
81 wintitle='test plot library',
82 driver='plplot',
83 minvalue = 30000.0,
84 maxvalue = 5000000.0,
85 save=True,
86 gpath="/home/roj-idl71/PlotImage")
87
94 self.specProcObj.writedata(self.wrpath)
88 95
89 if self.readerObj.flagNoMoreFiles:
96 self.specProcObj.plotMatScope(idfigure=1)
97
98 if self.readerObj.flagNoMoreFiles:
90 99 break
91 100
92 101
93 102
94 103 if self.readerObj.flagIsNewBlock:
95 104 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
96 105 datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),)
97
106
98 107
99 108
100 109 if __name__ == '__main__':
101 110 TestHeis()
102 111
103 112 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now