##// END OF EJS Templates
Bug fixed:...
Miguel Valdez -
r624:bde47180e86e
parent child
Show More
@@ -609,7 +609,9 class Spectra(JROData):
609 609 return range(self.nPairs)
610 610
611 611 def getNormFactor(self):
612
612 613 pwcode = 1
614
613 615 if self.flagDecodeData:
614 616 pwcode = numpy.sum(self.code[0]**2)
615 617 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
@@ -637,13 +639,19 class Spectra(JROData):
637 639
638 640 return timeInterval
639 641
640 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
641 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
642 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
643 flag_cspc = property(getFlagCspc)
644 flag_dc = property(getFlagDc)
645 noise = property(getNoise, "I'm the 'nHeights' property.")
646 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
642 def setValue(self, value):
643
644 print "This property should not be initialized"
645
646 return
647
648 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
649 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
650 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
651 flag_cspc = property(getFlagCspc, setValue)
652 flag_dc = property(getFlagDc, setValue)
653 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
654 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
647 655
648 656 class SpectraHeis(Spectra):
649 657
@@ -182,8 +182,11 class SystemHeader(Header):
182 182
183 183 def read(self, fp):
184 184
185 startFp = fp.tell()
186
185 187 try:
186 188 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
189
187 190 self.size = header['nSize'][0]
188 191 self.nSamples = header['nNumSamples'][0]
189 192 self.nProfiles = header['nNumProfiles'][0]
@@ -195,6 +198,11 class SystemHeader(Header):
195 198 print "SystemHeader: " + e
196 199 return 0
197 200
201 endFp = self.size + startFp
202
203 if fp.tell() != endFp:
204 raise IOError, "System Header is not consistent"
205
198 206 return 1
199 207
200 208 def write(self, fp):
@@ -273,72 +281,63 class RadarControllerHeader(Header):
273 281
274 282 def read(self, fp):
275 283
276 try:
277 startFp = fp.tell()
278 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
279
280 size = int(header['nSize'][0])
281 self.expType = int(header['nExpType'][0])
282 self.nTx = int(header['nNTx'][0])
283 self.ipp = float(header['fIpp'][0])
284 self.txA = float(header['fTxA'][0])
285 self.txB = float(header['fTxB'][0])
286 self.nWindows = int(header['nNumWindows'][0])
287 self.numTaus = int(header['nNumTaus'][0])
288 self.codeType = int(header['nCodeType'][0])
289 self.line6Function = int(header['nLine6Function'][0])
290 self.line5Function = int(header['nLine5Function'][0])
291 self.fClock = float(header['fClock'][0])
292 self.prePulseBefore = int(header['nPrePulseBefore'][0])
293 self.prePulserAfter = int(header['nPrePulseAfter'][0])
294 self.rangeIpp = header['sRangeIPP'][0]
295 self.rangeTxA = header['sRangeTxA'][0]
296 self.rangeTxB = header['sRangeTxB'][0]
297 # jump Dynamic Radar Controller Header
298 # jumpFp = size - 116
299 # self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
300 #pointer backward to dynamic header and read
301 # backFp = fp.tell() - jumpFp
302 # fp.seek(backFp)
303
304 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
305
306 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
307 self.firstHeight = samplingWindow['h0']
308 self.deltaHeight = samplingWindow['dh']
309 self.samplesWin = samplingWindow['nsa']
284
285 startFp = fp.tell()
286 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
287
288 size = int(header['nSize'][0])
289 self.expType = int(header['nExpType'][0])
290 self.nTx = int(header['nNTx'][0])
291 self.ipp = float(header['fIpp'][0])
292 self.txA = float(header['fTxA'][0])
293 self.txB = float(header['fTxB'][0])
294 self.nWindows = int(header['nNumWindows'][0])
295 self.numTaus = int(header['nNumTaus'][0])
296 self.codeType = int(header['nCodeType'][0])
297 self.line6Function = int(header['nLine6Function'][0])
298 self.line5Function = int(header['nLine5Function'][0])
299 self.fClock = float(header['fClock'][0])
300 self.prePulseBefore = int(header['nPrePulseBefore'][0])
301 self.prePulserAfter = int(header['nPrePulseAfter'][0])
302 self.rangeIpp = header['sRangeIPP'][0]
303 self.rangeTxA = header['sRangeTxA'][0]
304 self.rangeTxB = header['sRangeTxB'][0]
305
306 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
307
308 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
309 self.firstHeight = samplingWindow['h0']
310 self.deltaHeight = samplingWindow['dh']
311 self.samplesWin = samplingWindow['nsa']
312
313 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
314
315 self.code_size = 0
316 if self.codeType != 0:
317 self.nCode = int(numpy.fromfile(fp,'<u4',1))
318 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
310 319
311 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
320 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
321 for ic in range(self.nCode):
322 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
323 for ib in range(self.nBaud-1,-1,-1):
324 code[ic,ib] = temp[ib/32]%2
325 temp[ib/32] = temp[ib/32]/2
326
327 self.code = 2.0*code - 1.0
328 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
312 329
313 self.code_size = 0
314 if self.codeType != 0:
315 self.nCode = int(numpy.fromfile(fp,'<u4',1))
316 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
317 self.code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
318
319 for ic in range(self.nCode):
320 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
321 for ib in range(self.nBaud-1,-1,-1):
322 self.code[ic,ib] = temp[ib/32]%2
323 temp[ib/32] = temp[ib/32]/2
324 self.code = 2.0*self.code - 1.0
325 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
326
327 330 # if self.line5Function == RCfunction.FLIP:
328 331 # self.flip1 = numpy.fromfile(fp,'<u4',1)
329 332 #
330 333 # if self.line6Function == RCfunction.FLIP:
331 334 # self.flip2 = numpy.fromfile(fp,'<u4',1)
332
333 endFp = size + startFp
334 jumpFp = endFp - fp.tell()
335 if jumpFp > 0:
336 fp.seek(jumpFp)
337 335
338 except Exception, e:
339 print "RadarControllerHeader: " + e
340 return 0
336 endFp = size + startFp
341 337
338 if fp.tell() != endFp:
339 raise IOError, "Radar Controller Header is not consistent"
340
342 341 return 1
343 342
344 343 def write(self, fp):
@@ -436,7 +435,7 class RadarControllerHeader(Header):
436 435
437 436 class ProcessingHeader(Header):
438 437
439 size = None
438 # size = None
440 439 dtype = None
441 440 blockSize = None
442 441 profilesPerBlock = None
@@ -452,7 +451,7 class ProcessingHeader(Header):
452 451
453 452 def __init__(self):
454 453
455 self.size = 0
454 # self.size = 0
456 455 self.dtype = 0
457 456 self.blockSize = 0
458 457 self.profilesPerBlock = 0
@@ -468,17 +467,23 class ProcessingHeader(Header):
468 467 self.deltaHeight = 0
469 468 self.samplesWin = 0
470 469 self.spectraComb = 0
471 # self.nCode = None
472 # self.code = None
473 # self.nBaud = None
470 self.nCode = None
471 self.code = None
472 self.nBaud = None
473
474 474 self.shif_fft = False
475 475 self.flag_dc = False
476 476 self.flag_cspc = False
477 self.flag_decode = False
478 self.flag_deflip = False
477 479
478 480 def read(self, fp):
479 # try:
481
482 startFp = fp.tell()
483
480 484 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
481 self.size = int(header['nSize'][0])
485
486 size = int(header['nSize'][0])
482 487 self.dtype = int(header['nDataType'][0])
483 488 self.blockSize = int(header['nSizeOfDataBlock'][0])
484 489 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
@@ -495,21 +500,38 class ProcessingHeader(Header):
495 500 self.firstHeight = float(samplingWindow['h0'][0])
496 501 self.deltaHeight = float(samplingWindow['dh'][0])
497 502 self.samplesWin = samplingWindow['nsa'][0]
503
498 504 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
499 505
500 # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
501 # self.nCode = int(numpy.fromfile(fp,'<u4',1))
502 # self.nBaud = int(numpy.fromfile(fp,'<u4',1))
503 # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
506 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
507 self.nCode = int(numpy.fromfile(fp,'<u4',1))
508 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
509 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
504 510
511 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
512 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
513 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
514
505 515 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
506 516 self.shif_fft = True
507 517 else:
508 518 self.shif_fft = False
509
519
510 520 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
511 521 self.flag_dc = True
522 else:
523 self.flag_dc = False
524
525 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
526 self.flag_decode = True
527 else:
528 self.flag_decode = False
512 529
530 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
531 self.flag_deflip = True
532 else:
533 self.flag_deflip = False
534
513 535 nChannels = 0
514 536 nPairs = 0
515 537 pairList = []
@@ -524,14 +546,17 class ProcessingHeader(Header):
524 546 self.flag_cspc = False
525 547 if nPairs > 0:
526 548 self.flag_cspc = True
527
528 # except Exception, e:
529 # print "Error ProcessingHeader: "
530 # return 0
549
550 endFp = size + startFp
551
552 if fp.tell() != endFp:
553 raise IOError, "Processing Header is not consistent"
531 554
532 555 return 1
533 556
534 557 def write(self, fp):
558 #Clear DEFINE_PROCESS_CODE
559 # self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
535 560
536 561 headerTuple = (self.size,
537 562 self.dtype,
@@ -551,26 +576,43 class ProcessingHeader(Header):
551 576 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
552 577 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
553 578 samplingWindow.tofile(fp)
554
555 579
556 580 if self.totalSpectra != 0:
557 spectraComb = numpy.array([],numpy.dtype('u1'))
581 # spectraComb = numpy.array([],numpy.dtype('u1'))
558 582 spectraComb = self.spectraComb
559 583 spectraComb.tofile(fp)
560 584
561 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
562 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
563 # nCode.tofile(fp)
564 #
565 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
566 # nBaud.tofile(fp)
567 #
568 # code = self.code.reshape(self.nCode*self.nBaud)
569 # code = code.astype(numpy.dtype('<f4'))
570 # code.tofile(fp)
585 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
586 nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
587 nCode.tofile(fp)
588
589 nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
590 nBaud.tofile(fp)
591
592 code = self.code.reshape(self.nCode*self.nBaud)
593 code = code.astype(numpy.dtype('<f4'))
594 code.tofile(fp)
571 595
572 596 return 1
573 597
598 def get_size(self):
599
600 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
601
602 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
603 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
604 self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
605
606 return self.__size
607
608 def set_size(self, value):
609
610 self.__size = value
611
612 return
613
614 size = property(get_size, set_size)
615
574 616 class RCfunction:
575 617 NONE=0
576 618 FLIP=1
@@ -954,6 +954,8 class JRODataReader(JRODataIO):
954 954
955 955 except IOError:
956 956 traceback.print_exc()
957 sys.exit(0)
958
957 959 if msgFlag:
958 960 print "[Reading] The file %s is empty or it hasn't enough data" % filename
959 961
@@ -1292,6 +1294,9 class JRODataWriter(JRODataIO):
1292 1294 if self.dataOut.data_dc is not None:
1293 1295 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1294 1296
1297 if self.dataOut.flagShiftFFT:
1298 processFlags += PROCFLAG.SHIFT_FFT_DATA
1299
1295 1300 return processFlags
1296 1301
1297 1302 def setBasicHeader(self):
@@ -1347,8 +1352,6 class JRODataWriter(JRODataIO):
1347 1352 self.radarControllerHeaderObj.write(self.fp)
1348 1353 self.processingHeaderObj.write(self.fp)
1349 1354
1350
1351
1352 1355 def __setNewBlock(self):
1353 1356 """
1354 1357 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
@@ -23,6 +23,68 class Reader(ProcessingUnit):
23 23
24 24 #Is really necessary create the output object in the initializer
25 25 self.dataOut = Voltage()
26
27 def fillJROHeader(*args):
28
29 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=10e5,
30 txA=0,
31 txB=0,
32 nWindows=1,
33 nHeights=self.__nSamples,
34 firstHeight=self.__firstHeigth,
35 deltaHeight=self.__deltaHeigth,
36 codeType=self.__codeType,
37 nCode=self.__nCode, nBaud=self.__nBaud,
38 code = self.__code)
39
40 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
41 nProfiles=nProfiles,
42 nChannels=len(self.__channelList),
43 adcResolution=14)
44
45 self.dataOut.data = None
46
47 self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')])
48
49 self.dataOut.nProfiles = nProfiles
50
51 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
52
53 self.dataOut.channelList = self.__channelList
54
55 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
56
57 # self.dataOut.channelIndexList = None
58
59 self.dataOut.flagNoData = True
60
61 #Set to TRUE if the data is discontinuous
62 self.dataOut.flagDiscontinuousBlock = False
63
64 self.dataOut.utctime = None
65
66 self.dataOut.timeZone = self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime
67
68 self.dataOut.dstFlag = 0
69
70 self.dataOut.errorCount = 0
71
72 self.dataOut.nCohInt = 1
73
74 self.dataOut.flagDecodeData = False #asumo que la data esta decodificada
75
76 self.dataOut.flagDeflipData = False #asumo que la data esta sin flip
77
78 self.dataOut.flagShiftFFT = False
79
80 self.dataOut.ippSeconds = 1.0*self.__nSamples/self.__sample_rate
81
82 #Time interval between profiles
83 #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
84
85 self.dataOut.frequency = self.__frequency
86
87 self.dataOut.realtime = self.__online
26 88
27 89 def setup(self, path = None,
28 90 startDate = None,
@@ -46,6 +108,13 class Reader(ProcessingUnit):
46 108
47 109 self.isConfig = True
48 110
111 self.readUSRPHeader()
112 self.fillJROHeader()
113
114 def getData(self):
115
116 pass
117
49 118 def run(self, **kwargs):
50 119 '''
51 120 This method will be called many times so here you should put all your code
@@ -54,6 +123,8 class Reader(ProcessingUnit):
54 123 if not self.isConfig:
55 124 self.setup(**kwargs)
56 125
126 self.getData()
127
57 128 '''
58 129 Add code
59 130 '''
@@ -271,8 +271,6 class SpectraReader(JRODataReader, ProcessingUnit):
271 271 if self.processingHeaderObj.flag_cspc:
272 272 #desplaza a la derecha en el eje 2 determinadas posiciones
273 273 cspc = numpy.roll( cspc, shift, axis=2 )
274
275 # self.processingHeaderObj.shif_fft = True
276 274
277 275 #Dimensions : nChannels, nProfiles, nSamples
278 276 spc = numpy.transpose( spc, (0,2,1) )
@@ -329,21 +327,11 class SpectraReader(JRODataReader, ProcessingUnit):
329 327
330 328 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
331 329
332 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
330 self.dataOut.flagShiftFFT = True #Data is always shifted
333 331
334 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
332 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
335 333
336 self.dataOut.flagDeflipData = False #asumo q la data esta sin flip
337
338 if self.radarControllerHeaderObj.code is not None:
339
340 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
341 #
342 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
343 #
344 # self.dataOut.code = self.radarControllerHeaderObj.code
345
346 self.dataOut.flagDecodeData = True
334 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
347 335
348 336 def getData(self):
349 337 """
@@ -380,7 +368,7 class SpectraReader(JRODataReader, ProcessingUnit):
380 368
381 369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
382 370
383 if self.data_dc is None:
371 if self.data_spc is None:
384 372 self.dataOut.flagNoData = True
385 373 return 0
386 374
@@ -591,8 +579,10 class SpectraWriter(JRODataWriter, Operation):
591 579 self.setBasicHeader()
592 580
593 581 self.data_spc = self.dataOut.data_spc.copy()
582
594 583 if self.dataOut.data_cspc is not None:
595 584 self.data_cspc = self.dataOut.data_cspc.copy()
585
596 586 self.data_dc = self.dataOut.data_dc.copy()
597 587
598 588 # #self.processingHeaderObj.dataBlocksPerFile)
@@ -643,19 +633,12 class SpectraWriter(JRODataWriter, Operation):
643 633 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
644 634 self.systemHeaderObj.nChannels = self.dataOut.nChannels
645 635 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
646 old_code_size = self.dataOut.radarControllerHeaderObj.code_size
647 new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4
648 self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size
649 636
650 self.setBasicHeader()
651
652 processingHeaderSize = 40 # bytes
653 637 self.processingHeaderObj.dtype = 1 # Spectra
654 638 self.processingHeaderObj.blockSize = self.__getBlockSize()
655 639 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
656 640 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
657 641 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
658 self.processingHeaderObj.processFlags = self.getProcessFlags()
659 642 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
660 643 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
661 644 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
@@ -674,32 +657,20 class SpectraWriter(JRODataWriter, Operation):
674 657 pairsList.append(pair[1])
675 658
676 659 spectraComb = channelList + pairsList
677 spectraComb = numpy.array(spectraComb,dtype="u1")
660 spectraComb = numpy.array(spectraComb, dtype="u1")
678 661 self.processingHeaderObj.spectraComb = spectraComb
679 sizeOfSpcComb = len(spectraComb)
680 processingHeaderSize += sizeOfSpcComb
681
682 # The processing header should not have information about code
683 # if self.dataOut.code is not None:
684 # self.processingHeaderObj.code = self.dataOut.code
685 # self.processingHeaderObj.nCode = self.dataOut.nCode
686 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
687 # nCodeSize = 4 # bytes
688 # nBaudSize = 4 # bytes
689 # codeSize = 4 # bytes
690 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
691 # processingHeaderSize += sizeOfCode
662
663 if self.dataOut.code is not None:
664 self.processingHeaderObj.code = self.dataOut.code
665 self.processingHeaderObj.nCode = self.dataOut.nCode
666 self.processingHeaderObj.nBaud = self.dataOut.nBaud
692 667
693 668 if self.processingHeaderObj.nWindows != 0:
694 669 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
695 670 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
696 671 self.processingHeaderObj.nHeights = self.dataOut.nHeights
697 672 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
698 sizeOfFirstHeight = 4
699 sizeOfdeltaHeight = 4
700 sizeOfnHeights = 4
701 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
702 processingHeaderSize += sizeOfWindows
703 673
704 self.processingHeaderObj.size = processingHeaderSize
674 self.processingHeaderObj.processFlags = self.getProcessFlags()
705 675
676 self.setBasicHeader()
@@ -251,6 +251,8 class VoltageReader(JRODataReader, ProcessingUnit):
251 251 if self.nTxs > 1:
252 252 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
253 253
254 #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
255
254 256 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
255 257 #
256 258 # if self.radarControllerHeaderObj.code is not None:
@@ -276,13 +278,11 class VoltageReader(JRODataReader, ProcessingUnit):
276 278
277 279 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
278 280
279 self.dataOut.flagShiftFFT = False
280
281 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
281 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
282 282
283 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
283 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip
284 284
285 self.dataOut.flagShiftFFT = False
285 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
286 286
287 287 def getData(self):
288 288 """
@@ -569,31 +569,26 class VoltageWriter(JRODataWriter, Operation):
569 569 self.systemHeaderObj.nChannels = self.dataOut.nChannels
570 570 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
571 571
572 self.setBasicHeader()
573
574 processingHeaderSize = 40 # bytes
575 572 self.processingHeaderObj.dtype = 0 # Voltage
576 573 self.processingHeaderObj.blockSize = self.__getBlockSize()
577 574 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
578 575 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
579 576 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
580 self.processingHeaderObj.processFlags = self.getProcessFlags()
581 577 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
582 578 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
583 579 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
584 580
585 # if self.dataOut.code is not None:
586 # self.processingHeaderObj.code = self.dataOut.code
587 # self.processingHeaderObj.nCode = self.dataOut.nCode
588 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
589 # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
590 # processingHeaderSize += codesize
581 if self.dataOut.code is not None:
582 self.processingHeaderObj.code = self.dataOut.code
583 self.processingHeaderObj.nCode = self.dataOut.nCode
584 self.processingHeaderObj.nBaud = self.dataOut.nBaud
591 585
592 586 if self.processingHeaderObj.nWindows != 0:
593 587 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
594 588 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
595 589 self.processingHeaderObj.nHeights = self.dataOut.nHeights
596 590 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
597 processingHeaderSize += 12
598 591
599 self.processingHeaderObj.size = processingHeaderSize No newline at end of file
592 self.processingHeaderObj.processFlags = self.getProcessFlags()
593
594 self.setBasicHeader() No newline at end of file
@@ -606,6 +606,7 class SpectraProc(ProcessingUnit):
606 606 return 1
607 607
608 608 def setRadarFrequency(self, frequency=None):
609
609 610 if frequency != None:
610 611 self.dataOut.frequency = frequency
611 612
@@ -807,7 +808,10 class IncohInt(Operation):
807 808 def byProfiles(self, *args):
808 809
809 810 self.__dataReady = False
810
811 avgdata_spc = None
812 avgdata_cspc = None
813 avgdata_dc = None
814
811 815 self.putData(*args)
812 816
813 817 if self.__profIndex == self.n:
@@ -821,6 +825,9 class IncohInt(Operation):
821 825 def byTime(self, datatime, *args):
822 826
823 827 self.__dataReady = False
828 avgdata_spc = None
829 avgdata_cspc = None
830 avgdata_dc = None
824 831
825 832 self.putData(*args)
826 833
@@ -136,9 +136,12 class VoltageProc(ProcessingUnit):
136 136 if maxHei == None:
137 137 maxHei = self.dataOut.heightList[-1]
138 138
139 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
140 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
141
139 if (minHei < self.dataOut.heightList[0]):
140 minHei = self.dataOut.heightList[0]
141 # raise ValueError, "height range [%d,%d] is not valid. Data height range is [%d, %d]" % (minHei,
142 # maxHei,
143 # self.dataOut.heightList[0],
144 # self.dataOut.heightList[-1])
142 145
143 146 if (maxHei > self.dataOut.heightList[-1]):
144 147 maxHei = self.dataOut.heightList[-1]
@@ -627,7 +630,10 class Decoder(Operation):
627 630 return self.datadecTime
628 631
629 632 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
630
633
634 if dataOut.flagDecodeData:
635 print "This data is already decoded, recoding again ..."
636
631 637 if not self.isConfig:
632 638
633 639 if code is None:
@@ -638,7 +644,11 class Decoder(Operation):
638 644 self.setup(code, osamp, dataOut)
639 645
640 646 self.isConfig = True
641
647
648 if self.code is None:
649 print "Fail decoding: Code is not defined."
650 return
651
642 652 if dataOut.flagDataAsBlock:
643 653 """
644 654 Decoding when data have been read as block,
@@ -917,139 +927,139 class Reshaper(Operation):
917 927 dataOut.nProfiles = dataOut.data.shape[1]
918 928
919 929 dataOut.ippSeconds *= factor
920
921 import collections
922 from scipy.stats import mode
923
924 class Synchronize(Operation):
925
926 isConfig = False
927 __profIndex = 0
928
929 def __init__(self):
930
931 Operation.__init__(self)
932 # self.isConfig = False
933 self.__powBuffer = None
934 self.__startIndex = 0
935 self.__pulseFound = False
936
937 def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
938
939 #Read data
940
941 powerdB = dataOut.getPower(channel = channel)
942 noisedB = dataOut.getNoise(channel = channel)[0]
943
944 self.__powBuffer.extend(powerdB.flatten())
945
946 dataArray = numpy.array(self.__powBuffer)
947
948 filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
949
950 maxValue = numpy.nanmax(filteredPower)
951
952 if maxValue < noisedB + 10:
953 #No se encuentra ningun pulso de transmision
954 return None
955
956 maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
957
958 if len(maxValuesIndex) < 2:
959 #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
960 return None
961
962 phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
963
964 #Seleccionar solo valores con un espaciamiento de nSamples
965 pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
966
967 if len(pulseIndex) < 2:
968 #Solo se encontro un pulso de transmision con ancho mayor a 1
969 return None
970
971 spacing = pulseIndex[1:] - pulseIndex[:-1]
972
973 #remover senales que se distancien menos de 10 unidades o muestras
974 #(No deberian existir IPP menor a 10 unidades)
975
976 realIndex = numpy.where(spacing > 10 )[0]
977
978 if len(realIndex) < 2:
979 #Solo se encontro un pulso de transmision con ancho mayor a 1
980 return None
981
982 #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
983 realPulseIndex = pulseIndex[realIndex]
984
985 period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
986
987 print "IPP = %d samples" %period
988
989 self.__newNSamples = dataOut.nHeights #int(period)
990 self.__startIndex = int(realPulseIndex[0])
991
992 return 1
993
994
995 def setup(self, nSamples, nChannels, buffer_size = 4):
996
997 self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
998 maxlen = buffer_size*nSamples)
999
1000 bufferList = []
1001
1002 for i in range(nChannels):
1003 bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1004 maxlen = buffer_size*nSamples)
1005
1006 bufferList.append(bufferByChannel)
1007
1008 self.__nSamples = nSamples
1009 self.__nChannels = nChannels
1010 self.__bufferList = bufferList
1011
1012 def run(self, dataOut, channel = 0):
1013
1014 if not self.isConfig:
1015 nSamples = dataOut.nHeights
1016 nChannels = dataOut.nChannels
1017 self.setup(nSamples, nChannels)
1018 self.isConfig = True
1019
1020 #Append new data to internal buffer
1021 for thisChannel in range(self.__nChannels):
1022 bufferByChannel = self.__bufferList[thisChannel]
1023 bufferByChannel.extend(dataOut.data[thisChannel])
1024
1025 if self.__pulseFound:
1026 self.__startIndex -= self.__nSamples
1027
1028 #Finding Tx Pulse
1029 if not self.__pulseFound:
1030 indexFound = self.__findTxPulse(dataOut, channel)
1031
1032 if indexFound == None:
1033 dataOut.flagNoData = True
1034 return
1035
1036 self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1037 self.__pulseFound = True
1038 self.__startIndex = indexFound
1039
1040 #If pulse was found ...
1041 for thisChannel in range(self.__nChannels):
1042 bufferByChannel = self.__bufferList[thisChannel]
1043 #print self.__startIndex
1044 x = numpy.array(bufferByChannel)
1045 self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1046
1047 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1048 dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1049 # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1050
1051 dataOut.data = self.__arrayBuffer
1052
1053 self.__startIndex += self.__newNSamples
1054
1055 return No newline at end of file
930 #
931 # import collections
932 # from scipy.stats import mode
933 #
934 # class Synchronize(Operation):
935 #
936 # isConfig = False
937 # __profIndex = 0
938 #
939 # def __init__(self):
940 #
941 # Operation.__init__(self)
942 # # self.isConfig = False
943 # self.__powBuffer = None
944 # self.__startIndex = 0
945 # self.__pulseFound = False
946 #
947 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
948 #
949 # #Read data
950 #
951 # powerdB = dataOut.getPower(channel = channel)
952 # noisedB = dataOut.getNoise(channel = channel)[0]
953 #
954 # self.__powBuffer.extend(powerdB.flatten())
955 #
956 # dataArray = numpy.array(self.__powBuffer)
957 #
958 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
959 #
960 # maxValue = numpy.nanmax(filteredPower)
961 #
962 # if maxValue < noisedB + 10:
963 # #No se encuentra ningun pulso de transmision
964 # return None
965 #
966 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
967 #
968 # if len(maxValuesIndex) < 2:
969 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
970 # return None
971 #
972 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
973 #
974 # #Seleccionar solo valores con un espaciamiento de nSamples
975 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
976 #
977 # if len(pulseIndex) < 2:
978 # #Solo se encontro un pulso de transmision con ancho mayor a 1
979 # return None
980 #
981 # spacing = pulseIndex[1:] - pulseIndex[:-1]
982 #
983 # #remover senales que se distancien menos de 10 unidades o muestras
984 # #(No deberian existir IPP menor a 10 unidades)
985 #
986 # realIndex = numpy.where(spacing > 10 )[0]
987 #
988 # if len(realIndex) < 2:
989 # #Solo se encontro un pulso de transmision con ancho mayor a 1
990 # return None
991 #
992 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
993 # realPulseIndex = pulseIndex[realIndex]
994 #
995 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
996 #
997 # print "IPP = %d samples" %period
998 #
999 # self.__newNSamples = dataOut.nHeights #int(period)
1000 # self.__startIndex = int(realPulseIndex[0])
1001 #
1002 # return 1
1003 #
1004 #
1005 # def setup(self, nSamples, nChannels, buffer_size = 4):
1006 #
1007 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1008 # maxlen = buffer_size*nSamples)
1009 #
1010 # bufferList = []
1011 #
1012 # for i in range(nChannels):
1013 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1014 # maxlen = buffer_size*nSamples)
1015 #
1016 # bufferList.append(bufferByChannel)
1017 #
1018 # self.__nSamples = nSamples
1019 # self.__nChannels = nChannels
1020 # self.__bufferList = bufferList
1021 #
1022 # def run(self, dataOut, channel = 0):
1023 #
1024 # if not self.isConfig:
1025 # nSamples = dataOut.nHeights
1026 # nChannels = dataOut.nChannels
1027 # self.setup(nSamples, nChannels)
1028 # self.isConfig = True
1029 #
1030 # #Append new data to internal buffer
1031 # for thisChannel in range(self.__nChannels):
1032 # bufferByChannel = self.__bufferList[thisChannel]
1033 # bufferByChannel.extend(dataOut.data[thisChannel])
1034 #
1035 # if self.__pulseFound:
1036 # self.__startIndex -= self.__nSamples
1037 #
1038 # #Finding Tx Pulse
1039 # if not self.__pulseFound:
1040 # indexFound = self.__findTxPulse(dataOut, channel)
1041 #
1042 # if indexFound == None:
1043 # dataOut.flagNoData = True
1044 # return
1045 #
1046 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1047 # self.__pulseFound = True
1048 # self.__startIndex = indexFound
1049 #
1050 # #If pulse was found ...
1051 # for thisChannel in range(self.__nChannels):
1052 # bufferByChannel = self.__bufferList[thisChannel]
1053 # #print self.__startIndex
1054 # x = numpy.array(bufferByChannel)
1055 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1056 #
1057 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1058 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1059 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1060 #
1061 # dataOut.data = self.__arrayBuffer
1062 #
1063 # self.__startIndex += self.__newNSamples
1064 #
1065 # return No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now