##// END OF EJS Templates
Se añadio la clase SpectraHeis
Alexander Valdez -
r145:0d184bf86479
parent child
Show More
@@ -1,371 +1,516
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 from Data.JROData import Spectra
14 from Data.JROData import SpectraHeis
15 15 from IO.SpectraIO import SpectraWriter
16 from Graphics.schainPlotTypes import SpcFigure
16 #from Graphics.schainPlotTypes import SpcFigure
17 17 #from JRONoise import Noise
18 18
19 19 class SpectraProcessor:
20 20 '''
21 21 classdocs
22 22 '''
23 23
24 24 dataInObj = None
25 25
26 26 dataOutObj = None
27 27
28 28 noiseObj = None
29 29
30 30 integratorObjList = []
31 31
32 32 writerObjList = []
33 33
34 34 integratorObjIndex = None
35 35
36 36 writerObjIndex = None
37 37
38 38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39 39
40 40
41 41 def __init__(self):
42 42 '''
43 43 Constructor
44 44 '''
45 45
46 46 self.integratorObjIndex = None
47 47 self.writerObjIndex = None
48 48 self.plotObjIndex = None
49 self.integratorObjList = []
50 self.writerObjList = []
49 self.integratorOst = []
51 50 self.plotObjList = []
52 self.noiseObj = None
51 self.noiseObj = bjList = []
52 self.writerObjLiNone
53 53 self.buffer = None
54 54 self.profIndex = 0
55 55
56 56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
57 57
58 58 if dataInObj == None:
59 59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60 60
61 61 if dataInObj.type == "Voltage":
62 62 if nFFTPoints == None:
63 63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64 64 else:
65 65 nFFTPoints = dataInObj.nFFTPoints
66 66
67 67 self.dataInObj = dataInObj
68 68
69 69 if dataOutObj == None:
70 70 dataOutObj = Spectra()
71 71
72 72 self.dataOutObj = dataOutObj
73 73
74 74 return self.dataOutObj
75 75
76 76 def init(self):
77 77
78 78 self.integratorObjIndex = 0
79 79 self.writerObjIndex = 0
80 80 self.plotObjIndex = 0
81 81 if self.dataInObj.type == "Voltage":
82 82
83 83 if self.buffer == None:
84 84 self.buffer = numpy.zeros((self.nChannels,
85 85 self.nFFTPoints,
86 86 self.dataInObj.nHeights),
87 87 dtype='complex')
88 88
89 89 self.buffer[:,self.profIndex,:] = self.dataInObj.data
90 90 self.profIndex += 1
91 91
92 92 if self.profIndex == self.nFFTPoints:
93 93 self.__getFft()
94 94 self.dataOutObj.flagNoData = False
95 95
96 96 self.buffer = None
97 97 self.profIndex = 0
98 98 return
99 99
100 100 self.dataOutObj.flagNoData = True
101 101
102 102 return
103 103
104 104 #Other kind of data
105 105 if self.dataInObj.type == "Spectra":
106 106 self.dataOutObj.copy(self.dataInObj)
107 107 self.dataOutObj.flagNoData = False
108 108 return
109 109
110 110 raise ValueError, "The datatype is not valid"
111 111
112 112 def __getFft(self):
113 113 """
114 114 Convierte valores de Voltaje a Spectra
115 115
116 116 Affected:
117 117 self.dataOutObj.data_spc
118 118 self.dataOutObj.data_cspc
119 119 self.dataOutObj.data_dc
120 120 self.dataOutObj.heightList
121 121 self.dataOutObj.m_BasicHeader
122 122 self.dataOutObj.m_ProcessingHeader
123 123 self.dataOutObj.m_RadarControllerHeader
124 124 self.dataOutObj.m_SystemHeader
125 125 self.profIndex
126 126 self.buffer
127 127 self.dataOutObj.flagNoData
128 128 self.dataOutObj.dataType
129 129 self.dataOutObj.nPairs
130 130 self.dataOutObj.nChannels
131 131 self.dataOutObj.nProfiles
132 132 self.dataOutObj.m_SystemHeader.numChannels
133 133 self.dataOutObj.m_ProcessingHeader.totalSpectra
134 134 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
135 135 self.dataOutObj.m_ProcessingHeader.numHeights
136 136 self.dataOutObj.m_ProcessingHeader.spectraComb
137 137 self.dataOutObj.m_ProcessingHeader.shif_fft
138 138 """
139 139
140 140 if self.dataInObj.flagNoData:
141 141 return 0
142 142
143 143 fft_volt = numpy.fft.fft(self.buffer,axis=1)
144 144 dc = fft_volt[:,0,:]
145 145
146 146 #calculo de self-spectra
147 147 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
148 148 spc = fft_volt * numpy.conjugate(fft_volt)
149 149 spc = spc.real
150 150
151 151 blocksize = 0
152 152 blocksize += dc.size
153 153 blocksize += spc.size
154 154
155 155 cspc = None
156 156 pairIndex = 0
157 157 if self.pairList != None:
158 158 #calculo de cross-spectra
159 159 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
160 160 for pair in self.pairList:
161 161 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
162 162 pairIndex += 1
163 163 blocksize += cspc.size
164 164
165 165 self.dataOutObj.data_spc = spc
166 166 self.dataOutObj.data_cspc = cspc
167 167 self.dataOutObj.data_dc = dc
168 168 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
169 169 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
170 170
171 171 # self.getNoise()
172 172
173 173 def addWriter(self, wrpath, blocksPerFile):
174 174 objWriter = SpectraWriter(self.dataOutObj)
175 175 objWriter.setup(wrpath, blocksPerFile)
176 176 self.writerObjList.append(objWriter)
177 177
178 178 def addIntegrator(self,N,timeInterval):
179 179
180 180 objIncohInt = IncoherentIntegration(N,timeInterval)
181 181 self.integratorObjList.append(objIncohInt)
182 182
183 183 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
184 184 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
185 185 self.plotObjList.append(spcObj)
186 186
187 187 def plotSpc(self, idfigure=None,
188 188 xmin=None,
189 189 xmax=None,
190 190 ymin=None,
191 191 ymax=None,
192 192 minvalue=None,
193 193 maxvalue=None,
194 194 wintitle='',
195 195 driver='plplot',
196 196 colormap='br_greeen',
197 197 colorbar=True,
198 198 showprofile=False,
199 199 save=False,
200 200 gpath=None):
201 201
202 202 if self.dataOutObj.flagNoData:
203 203 return 0
204 204
205 205 nframes = len(self.dataOutObj.channelList)
206 206
207 207 if len(self.plotObjList) <= self.plotObjIndex:
208 208 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
209 209
210 210 x = numpy.arange(self.dataOutObj.nFFTPoints)
211 211
212 212 y = self.dataOutObj.heightList
213 213
214 214 channelList = self.dataOutObj.channelList
215 215
216 216 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
217 217 # noisedB = 10.*numpy.log10(noise)
218 218 noisedB = numpy.arange(len(channelList)+1)
219 219 noisedB = noisedB *1.2
220 220 titleList = []
221 221 for i in range(len(noisedB)):
222 222 title = "%.2f"%noisedB[i]
223 223 titleList.append(title)
224 224
225 225 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
226 226 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
227 227 figuretitle = "Spc Radar Data: %s"%dateTime
228 228
229 229 cleardata = True
230 230
231 231 plotObj = self.plotObjList[self.plotObjIndex]
232 232
233 233 plotObj.plotPcolor(data,
234 234 x,
235 235 y,
236 236 channelList,
237 237 xmin,
238 238 xmax,
239 239 ymin,
240 240 ymax,
241 241 minvalue,
242 242 maxvalue,
243 243 figuretitle,
244 244 None,
245 245 save,
246 246 gpath,
247 247 cleardata,
248 248 titleList)
249 249
250 250 self.plotObjIndex += 1
251 251
252 252
253 253 def writeData(self, wrpath, blocksPerFile):
254 254 if self.dataOutObj.flagNoData:
255 255 return 0
256 256
257 257 if len(self.writerObjList) <= self.writerObjIndex:
258 258 self.addWriter(wrpath, blocksPerFile)
259 259
260 260 self.writerObjList[self.writerObjIndex].putData()
261 261
262 262 self.writerObjIndex += 1
263 263
264 264 def integrator(self, N=None, timeInterval=None):
265 265
266 266 if self.dataOutObj.flagNoData:
267 267 return 0
268 268
269 269 if len(self.integratorObjList) <= self.integratorObjIndex:
270 270 self.addIntegrator(N,timeInterval)
271 271
272 272 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
273 273 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
274 274
275 275 if myIncohIntObj.isReady:
276 276 self.dataOutObj.data_spc = myIncohIntObj.data
277 277 self.dataOutObj.nAvg = myIncohIntObj.navg
278 278 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
279 279 self.dataOutObj.flagNoData = False
280 280
281 281 """Calcular el ruido"""
282 282 self.getNoise()
283 283 else:
284 284 self.dataOutObj.flagNoData = True
285 285
286 286 self.integratorObjIndex += 1
287 287
288
289 class SpectraHeisProcessor:
290 def __init__(self):
291 self.integratorObjIndex = None
292 self.writerObjIndex = None
293 self.plotterObjIndex = None
294 self.integratorObjList = []
295 self.writerObjList = []
296 self.plotterObjList = []
297 #self.noiseObj = Noise()
298
299 def setup(self,dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
300 if dataInObj == None:
301 raise ValueError, ""
302
303 if nFFTPoints == None:
304 raise ValueError, ""
305
306 self.dataInObj = dataInObj
307
308 if dataOutObj == None:
309 dataOutObj = SpectraHeis()
310
311 self.dataOutObj = dataOutObj
312 # self.noiseObj = Noise()
313
314 ##########################################
315 self.nFFTPoints = nFFTPoints
316 self.nChannels = self.dataInObj.nChannels
317 self.nHeights = self.dataInObj.nHeights
318 self.pairList = pairList
319 if pairList != None:
320 self.nPairs = len(pairList)
321 else:
322 self.nPairs = 0
323
324 self.dataOutObj.heightList = self.dataInObj.heightList
325 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
326 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
327 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
328
329 self.dataOutObj.dataType = self.dataInObj.dataType
330 self.dataOutObj.nPairs = self.nPairs
331 self.dataOutObj.nChannels = self.nChannels
332 self.dataOutObj.nProfiles = self.nFFTPoints
333 self.dataOutObj.nHeights = self.nHeights
334 self.dataOutObj.nFFTPoints = self.nFFTPoints
335 #self.dataOutObj.data = None
336
337 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
338 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
339
340 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
341 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
342 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
343 self.dataOutObj.m_ProcessingHeader.shif_fft = True
344
345 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
346 k = 0
347 for i in range( 0,self.nChannels*2,2 ):
348 spectraComb[i] = k
349 spectraComb[i+1] = k
350 k += 1
351
352 k *= 2
353
354 if self.pairList != None:
355
356 for pair in self.pairList:
357 spectraComb[k] = pair[0]
358 spectraComb[k+1] = pair[1]
359 k += 2
360
361 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
362
363 return self.dataOutObj
364
365 def init(self):
366 self.integratorObjIndex = 0
367 self.writerObjIndex = 0
368 self.plotterObjIndex = 0
288 369
370 if self.dataInObj.type == "Voltage":
371 self.__getFft()
372 self.dataOutObj.flagNoData = False
373 return
374
375 #Other kind of data
376 if self.dataInObj.type == "SpectraHeis":
377 self.dataOutObj.copy(self.dataInObj)
378 self.dataOutObj.flagNoData = False
379 return
380
381 raise ValueError, "The datatype is not valid"
382
383 def __getFft(self):
384 if self.dataInObj.flagNoData:
385 return 0
386
387 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
388 #print fft_volt
389 #calculo de self-spectra
390 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
391
392 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
393 self.dataOutObj.data_spc = spc
394 #print spc
395
396 def getSpectra(self):
397
398 return self.dataOutObj.data_spc
399
400 def getFrecuencies(self):
401
402 print self.nFFTPoints
403 return numpy.arange(int(self.nFFTPoints))
404
405 def addIntegrator(self,N,timeInterval):
406 objIncohInt = IncoherentIntegration(N,timeInterval)
407 self.integratorObjList.append(objIncohInt)
408
409 def integrator(self, N=None, timeInterval=None):
410 if self.dataOutObj.flagNoData:
411 return 0
412
413 if len(self.integratorObjList) <= self.integratorObjIndex:
414 self.addIntegrator(N,timeInterval)
415
416 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
417 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
418
419 if myIncohIntObj.isReady:
420 self.dataOutObj.data_spc = myIncohIntObj.data
421 self.dataOutObj.nAvg = myIncohIntObj.navg
422 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
423 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
424 self.dataOutObj.flagNoData = False
425
426 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
427 # self.getNoise(type="sort", parm=16)
428
429 else:
430 self.dataOutObj.flagNoData = True
431
432 self.integratorObjIndex += 1
433
289 434
290 435
291 436 class IncoherentIntegration:
292 437
293 438 integ_counter = None
294 439 data = None
295 440 navg = None
296 441 buffer = None
297 442 nIncohInt = None
298 443
299 444 def __init__(self, N = None, timeInterval = None):
300 445 """
301 446 N
302 447 timeInterval - interval time [min], integer value
303 448 """
304 449
305 450 self.data = None
306 451 self.navg = None
307 452 self.buffer = None
308 453 self.timeOut = None
309 454 self.exitCondition = False
310 455 self.isReady = False
311 456 self.nIncohInt = N
312 457 self.integ_counter = 0
313 458 if timeInterval!=None:
314 459 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
315 460
316 461 if ((timeInterval==None) and (N==None)):
317 462 print 'N = None ; timeInterval = None'
318 463 sys.exit(0)
319 464 elif timeInterval == None:
320 465 self.timeFlag = False
321 466 else:
322 467 self.timeFlag = True
323 468
324 469
325 470 def exe(self,data,timeOfData):
326 471 """
327 472 data
328 473
329 474 timeOfData [seconds]
330 475 """
331 476
332 477 if self.timeFlag:
333 478 if self.timeOut == None:
334 479 self.timeOut = timeOfData + self.timeIntervalInSeconds
335 480
336 481 if timeOfData < self.timeOut:
337 482 if self.buffer == None:
338 483 self.buffer = data
339 484 else:
340 485 self.buffer = self.buffer + data
341 486 self.integ_counter += 1
342 487 else:
343 488 self.exitCondition = True
344 489
345 490 else:
346 491 if self.integ_counter < self.nIncohInt:
347 492 if self.buffer == None:
348 493 self.buffer = data
349 494 else:
350 495 self.buffer = self.buffer + data
351 496
352 497 self.integ_counter += 1
353 498
354 499 if self.integ_counter == self.nIncohInt:
355 500 self.exitCondition = True
356 501
357 502 if self.exitCondition:
358 503 self.data = self.buffer
359 504 self.navg = self.integ_counter
360 505 self.isReady = True
361 506 self.buffer = None
362 507 self.timeOut = None
363 508 self.integ_counter = 0
364 509 self.exitCondition = False
365 510
366 511 if self.timeFlag:
367 512 self.buffer = data
368 513 self.timeOut = timeOfData + self.timeIntervalInSeconds
369 514 else:
370 515 self.isReady = False
371 516 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now