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