@@ -2,6 +2,7 import numpy | |||
|
2 | 2 | |
|
3 | 3 | from jroproc_base import ProcessingUnit, Operation |
|
4 | 4 | from model.data.jrodata import Voltage |
|
5 | from Carbon.Fonts import times | |
|
5 | 6 | |
|
6 | 7 | class VoltageProc(ProcessingUnit): |
|
7 | 8 | |
@@ -97,8 +98,13 class VoltageProc(ProcessingUnit): | |||
|
97 | 98 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
98 | 99 | |
|
99 | 100 | # nChannels = len(channelIndexList) |
|
100 | ||
|
101 | data = self.dataOut.data[channelIndexList,:] | |
|
101 | if dataOut.flagDataAsBlock: | |
|
102 | """ | |
|
103 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
|
104 | """ | |
|
105 | data = self.dataOut.data[channelIndexList,:,:] | |
|
106 | else: | |
|
107 | data = self.dataOut.data[channelIndexList,:] | |
|
102 | 108 | |
|
103 | 109 | self.dataOut.data = data |
|
104 | 110 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
@@ -185,7 +191,13 class VoltageProc(ProcessingUnit): | |||
|
185 | 191 | # nHeights = maxIndex - minIndex + 1 |
|
186 | 192 | |
|
187 | 193 | #voltage |
|
188 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
|
194 | if dataOut.flagDataAsBlock: | |
|
195 | """ | |
|
196 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
|
197 | """ | |
|
198 | data = self.dataOut.data[:,minIndex:maxIndex+1,:] | |
|
199 | else: | |
|
200 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
|
189 | 201 | |
|
190 | 202 | # firstHeight = self.dataOut.heightList[minIndex] |
|
191 | 203 | |
@@ -196,37 +208,69 class VoltageProc(ProcessingUnit): | |||
|
196 | 208 | |
|
197 | 209 | |
|
198 | 210 | def filterByHeights(self, window, axis=1): |
|
211 | ||
|
199 | 212 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
200 | 213 | |
|
201 | 214 | if window == None: |
|
202 | 215 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
203 | 216 | |
|
204 | 217 | newdelta = deltaHeight * window |
|
205 |
r = self.dataOut. |
|
|
206 | if axis == 1: | |
|
207 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r] | |
|
208 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window) | |
|
209 | buffer = numpy.sum(buffer,axis+1) | |
|
210 | ||
|
211 | elif axis == 2: | |
|
212 | buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r] | |
|
213 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window) | |
|
214 | buffer = numpy.sum(buffer,axis+1) | |
|
218 | r = self.dataOut.nHeights % window | |
|
215 | 219 | |
|
216 | else: | |
|
217 | raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis) | |
|
220 | if dataOut.flagDataAsBlock: | |
|
221 | """ | |
|
222 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
|
223 | """ | |
|
224 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] | |
|
225 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights,self.dataOut.nHeights/window,window) | |
|
226 | buffer = numpy.sum(buffer,3) | |
|
218 | 227 | |
|
228 | else: | |
|
229 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] | |
|
230 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) | |
|
231 | buffer = numpy.sum(buffer,2) | |
|
232 | ||
|
219 | 233 | self.dataOut.data = buffer.copy() |
|
220 | 234 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
221 | 235 | self.dataOut.windowOfFilter = window |
|
222 | 236 | |
|
223 | 237 | return 1 |
|
224 | 238 | |
|
225 | def deFlip(self): | |
|
226 | self.dataOut.data *= self.flip | |
|
227 | self.flip *= -1. | |
|
239 | def deFlip(self, channelList = []): | |
|
240 | ||
|
241 | data = self.dataOut.data.copy() | |
|
242 | ||
|
243 | if self.dataOut.flagDataAsBlock: | |
|
244 | flip = self.flip | |
|
245 | profileList = range(self.dataOut.nProfiles) | |
|
246 | ||
|
247 | if channelList == []: | |
|
248 | for thisProfile in profileList: | |
|
249 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
|
250 | flip *= -1.0 | |
|
251 | else: | |
|
252 | for thisChannel in channelList: | |
|
253 | for thisProfile in profileList: | |
|
254 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
|
255 | flip *= -1.0 | |
|
256 | ||
|
257 | self.flip = flip | |
|
258 | ||
|
259 | else: | |
|
260 | if channelList == []: | |
|
261 | data[:,:] = data[:,:]*self.flip | |
|
262 | else: | |
|
263 | for thisChannel in channelList: | |
|
264 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
|
265 | ||
|
266 | self.flip *= -1. | |
|
267 | ||
|
268 | self.dataOut.data = data | |
|
269 | ||
|
270 | ||
|
228 | 271 | |
|
229 | 272 | def setRadarFrequency(self, frequency=None): |
|
273 | ||
|
230 | 274 | if frequency != None: |
|
231 | 275 | self.dataOut.frequency = frequency |
|
232 | 276 | |
@@ -413,6 +457,7 class CohInt(Operation): | |||
|
413 | 457 | return avgdata, avgdatatime |
|
414 | 458 | |
|
415 | 459 | def integrateByBlock(self, dataOut): |
|
460 | ||
|
416 | 461 | times = int(dataOut.data.shape[1]/self.n) |
|
417 | 462 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
418 | 463 | |
@@ -436,7 +481,10 class CohInt(Operation): | |||
|
436 | 481 | self.setup(**kwargs) |
|
437 | 482 | self.isConfig = True |
|
438 | 483 | |
|
439 | if self.byblock: | |
|
484 | if dataOut.flagDataAsBlock: | |
|
485 | """ | |
|
486 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
|
487 | """ | |
|
440 | 488 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
441 | 489 | else: |
|
442 | 490 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
@@ -448,7 +496,7 class CohInt(Operation): | |||
|
448 | 496 | dataOut.data = avgdata |
|
449 | 497 | dataOut.nCohInt *= self.n |
|
450 | 498 | dataOut.utctime = avgdatatime |
|
451 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
|
499 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
|
452 | 500 | dataOut.flagNoData = False |
|
453 | 501 | |
|
454 | 502 | class Decoder(Operation): |
@@ -468,10 +516,10 class Decoder(Operation): | |||
|
468 | 516 | |
|
469 | 517 | self.times = None |
|
470 | 518 | self.osamp = None |
|
471 | self.__setValues = False | |
|
472 |
|
|
|
519 | # self.__setValues = False | |
|
520 | self.isConfig = False | |
|
473 | 521 | |
|
474 |
def setup(self, code, s |
|
|
522 | def setup(self, code, osamp, dataOut): | |
|
475 | 523 | |
|
476 | 524 | self.__profIndex = 0 |
|
477 | 525 | |
@@ -480,17 +528,23 class Decoder(Operation): | |||
|
480 | 528 | self.nCode = len(code) |
|
481 | 529 | self.nBaud = len(code[0]) |
|
482 | 530 | |
|
483 |
if |
|
|
484 | self.times = times | |
|
485 | ||
|
486 | if ((osamp != None) and (osamp >1)): | |
|
531 | if (osamp != None) and (osamp >1): | |
|
487 | 532 | self.osamp = osamp |
|
488 | self.code = numpy.repeat(code, repeats=self.osamp,axis=1) | |
|
533 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
|
489 | 534 | self.nBaud = self.nBaud*self.osamp |
|
490 | 535 | |
|
491 | if len(shape) == 2: | |
|
492 | self.__nChannels, self.__nHeis = shape | |
|
536 | self.__nChannels = dataOut.nChannels | |
|
537 | self.__nProfiles = dataOut.nProfiles | |
|
538 | self.__nHeis = dataOut.nHeights | |
|
539 | ||
|
540 | if dataOut.flagDataAsBlock: | |
|
493 | 541 | |
|
542 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
|
543 | ||
|
544 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
|
545 | ||
|
546 | else: | |
|
547 | ||
|
494 | 548 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
495 | 549 | |
|
496 | 550 | __codeBuffer[:,0:self.nBaud] = self.code |
@@ -499,16 +553,8 class Decoder(Operation): | |||
|
499 | 553 | |
|
500 | 554 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
501 | 555 | |
|
502 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
|
503 | else: | |
|
504 | self.__nChannels, self.__nProfiles, self.__nHeis = shape | |
|
505 | ||
|
506 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
|
507 | ||
|
508 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
|
509 | ||
|
556 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
|
510 | 557 | |
|
511 | ||
|
512 | 558 | def convolutionInFreq(self, data): |
|
513 | 559 | |
|
514 | 560 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
@@ -543,9 +589,12 class Decoder(Operation): | |||
|
543 | 589 | return self.datadecTime |
|
544 | 590 | |
|
545 | 591 | def convolutionByBlockInTime(self, data): |
|
546 | junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize)) | |
|
592 | ||
|
593 | repetitions = self.__nProfiles / self.nCode | |
|
594 | ||
|
595 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
|
547 | 596 | junk = junk.flatten() |
|
548 |
code_block = numpy.reshape(junk, (self.nCode* |
|
|
597 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
|
549 | 598 | |
|
550 | 599 | for i in range(self.__nChannels): |
|
551 | 600 | for j in range(self.__nProfiles): |
@@ -554,53 +603,49 class Decoder(Operation): | |||
|
554 | 603 | return self.datadecTime |
|
555 | 604 | |
|
556 | 605 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): |
|
557 | ||
|
558 | if code == None: | |
|
559 | code = dataOut.code | |
|
560 | else: | |
|
561 | code = numpy.array(code).reshape(nCode,nBaud) | |
|
562 | ||
|
563 | 606 | |
|
564 | ||
|
565 | 607 | if not self.isConfig: |
|
566 | 608 | |
|
567 | self.setup(code, dataOut.data.shape, times, osamp) | |
|
609 | if code == None: | |
|
610 | code = dataOut.code | |
|
611 | else: | |
|
612 | code = numpy.array(code).reshape(nCode,nBaud) | |
|
568 | 613 | |
|
569 | dataOut.code = code | |
|
570 | dataOut.nCode = nCode | |
|
571 | dataOut.nBaud = nBaud | |
|
572 | dataOut.radarControllerHeaderObj.code = code | |
|
573 | dataOut.radarControllerHeaderObj.nCode = nCode | |
|
574 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
|
614 | self.setup(code, osamp, dataOut) | |
|
575 | 615 | |
|
576 | 616 | self.isConfig = True |
|
617 | ||
|
618 | if dataOut.flagDataAsBlock: | |
|
619 | """ | |
|
620 | Decoding when data have been read as block, | |
|
621 | """ | |
|
622 | datadec = self.convolutionByBlockInTime(dataOut.data) | |
|
577 | 623 | |
|
578 | if mode == 0: | |
|
579 | datadec = self.convolutionInTime(dataOut.data) | |
|
580 | ||
|
581 |
|
|
|
582 | datadec = self.convolutionInFreq(dataOut.data) | |
|
583 | ||
|
584 | if mode == 2: | |
|
585 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
|
624 | else: | |
|
625 | """ | |
|
626 | Decoding when data have been read profile by profile | |
|
627 | """ | |
|
628 | if mode == 0: | |
|
629 | datadec = self.convolutionInTime(dataOut.data) | |
|
630 | ||
|
631 | if mode == 1: | |
|
632 | datadec = self.convolutionInFreq(dataOut.data) | |
|
586 | 633 | |
|
587 |
if mode == |
|
|
588 |
datadec = self.convolution |
|
|
634 | if mode == 2: | |
|
635 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
|
589 | 636 | |
|
590 | if not(self.__setValues): | |
|
591 |
|
|
|
592 |
|
|
|
593 | dataOut.nBaud = self.nBaud | |
|
594 |
|
|
|
595 |
|
|
|
596 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud | |
|
597 | #self.__setValues = True | |
|
637 | dataOut.code = code | |
|
638 | dataOut.nCode = nCode | |
|
639 | dataOut.nBaud = nBaud | |
|
640 | dataOut.radarControllerHeaderObj.code = code | |
|
641 | dataOut.radarControllerHeaderObj.nCode = nCode | |
|
642 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
|
598 | 643 | |
|
599 | 644 | dataOut.data = datadec |
|
600 | 645 | |
|
601 | 646 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
602 | 647 | |
|
603 |
dataOut.flagDecodeData = True #asumo q la data |
|
|
648 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
|
604 | 649 | |
|
605 | 650 | if self.__profIndex == self.nCode-1: |
|
606 | 651 | self.__profIndex = 0 |
@@ -645,17 +690,22 class ProfileConcat(Operation): | |||
|
645 | 690 | if not self.isConfig: |
|
646 | 691 | self.setup(dataOut.data, m, 1) |
|
647 | 692 | self.isConfig = True |
|
693 | ||
|
694 | if dataOut.flagDataAsBlock: | |
|
695 | ||
|
696 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profiel, getBlock = False" | |
|
648 | 697 | |
|
649 | self.concat(dataOut.data) | |
|
650 | self.times += 1 | |
|
651 |
|
|
|
652 | dataOut.data = self.buffer | |
|
653 | self.reset() | |
|
654 | dataOut.flagNoData = False | |
|
655 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
|
656 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
|
657 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
|
658 |
|
|
|
698 | else: | |
|
699 | self.concat(dataOut.data) | |
|
700 | self.times += 1 | |
|
701 | if self.times > m: | |
|
702 | dataOut.data = self.buffer | |
|
703 | self.reset() | |
|
704 | dataOut.flagNoData = False | |
|
705 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
|
706 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
|
707 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
|
708 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
|
659 | 709 | |
|
660 | 710 | class ProfileSelector(Operation): |
|
661 | 711 | |
@@ -692,48 +742,66 class ProfileSelector(Operation): | |||
|
692 | 742 | return True |
|
693 | 743 | |
|
694 | 744 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): |
|
745 | ||
|
746 | """ | |
|
747 | ProfileSelector: | |
|
695 | 748 |
|
|
749 | """ | |
|
750 | ||
|
696 | 751 | dataOut.flagNoData = True |
|
697 | 752 | self.nProfiles = dataOut.nProfiles |
|
698 | 753 | |
|
699 | if byblock: | |
|
700 | ||
|
754 | if dataOut.flagDataAsBlock: | |
|
755 | """ | |
|
756 | data dimension = [nChannels, nProfiles, nHeis] | |
|
757 | """ | |
|
701 | 758 | if profileList != None: |
|
702 | 759 | dataOut.data = dataOut.data[:,profileList,:] |
|
703 | pass | |
|
760 | dataOut.nProfiles = len(profileList) | |
|
704 | 761 | else: |
|
705 | 762 | pmin = profileRangeList[0] |
|
706 | 763 | pmax = profileRangeList[1] |
|
707 | 764 | dataOut.data = dataOut.data[:,pmin:pmax+1,:] |
|
765 | dataOut.nProfiles = pmax - pmin + 1 | |
|
766 | ||
|
767 | ||
|
708 | 768 | dataOut.flagNoData = False |
|
709 | 769 | self.profileIndex = 0 |
|
710 |
|
|
|
711 | ||
|
712 | if profileList != None: | |
|
713 | if self.isProfileInList(profileList): | |
|
714 | dataOut.flagNoData = False | |
|
715 | ||
|
716 |
|
|
|
717 |
|
|
|
718 | ||
|
719 | ||
|
720 | elif profileRangeList != None: | |
|
721 | minIndex = profileRangeList[0] | |
|
722 | maxIndex = profileRangeList[1] | |
|
723 | if self.isProfileInRange(minIndex, maxIndex): | |
|
724 | dataOut.flagNoData = False | |
|
770 | ||
|
771 | return True | |
|
772 | ||
|
773 | else: | |
|
774 | """ | |
|
775 | data dimension = [nChannels, nHeis] | |
|
776 | ||
|
777 | """ | |
|
778 | if profileList != None: | |
|
725 | 779 | |
|
726 | self.incIndex() | |
|
727 | return 1 | |
|
728 | elif beam != None: #beam is only for AMISR data | |
|
729 | if self.isProfileInList(dataOut.beamRangeDict[beam]): | |
|
730 | dataOut.flagNoData = False | |
|
780 | if self.isProfileInList(profileList): | |
|
781 | dataOut.flagNoData = False | |
|
782 | ||
|
783 | self.incIndex() | |
|
784 | return 1 | |
|
785 | ||
|
786 | ||
|
787 | if profileRangeList != None: | |
|
731 | 788 | |
|
732 | self.incIndex() | |
|
733 | return 1 | |
|
734 | ||
|
735 | else: | |
|
736 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
|
789 | minIndex = profileRangeList[0] | |
|
790 | maxIndex = profileRangeList[1] | |
|
791 | if self.isProfileInRange(minIndex, maxIndex): | |
|
792 | dataOut.flagNoData = False | |
|
793 | ||
|
794 | self.incIndex() | |
|
795 | return 1 | |
|
796 | ||
|
797 | if beam != None: #beam is only for AMISR data | |
|
798 | if self.isProfileInList(dataOut.beamRangeDict[beam]): | |
|
799 | dataOut.flagNoData = False | |
|
800 | ||
|
801 | self.incIndex() | |
|
802 | return 1 | |
|
803 | ||
|
804 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
|
737 | 805 | |
|
738 | 806 | return 0 |
|
739 | 807 | |
@@ -748,6 +816,12 class Reshaper(Operation): | |||
|
748 | 816 | |
|
749 | 817 | def run(self, dataOut, shape): |
|
750 | 818 | |
|
819 | if not dataOut.flagDataAsBlock: | |
|
820 | raise ValueError, "Reshaper can only be used when voltage have been read as Block, getBlock = True" | |
|
821 | ||
|
822 | if len(shape) != 3: | |
|
823 | raise ValueError, "shape len should be equal to 3, (nChannels, nProfiles, nHeis)" | |
|
824 | ||
|
751 | 825 | shape_tuple = tuple(shape) |
|
752 | 826 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
753 | 827 | dataOut.flagNoData = False |
@@ -757,6 +831,11 class Reshaper(Operation): | |||
|
757 | 831 | old_nheights = dataOut.nHeights |
|
758 | 832 | new_nheights = dataOut.data.shape[2] |
|
759 | 833 | factor = 1.0*new_nheights / old_nheights |
|
834 | ||
|
760 | 835 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
836 | ||
|
761 | 837 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor |
|
762 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) No newline at end of file | |
|
838 | ||
|
839 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
|
840 | ||
|
841 | dataOut.nProfiles = dataOut.data.shape[1] No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now