@@ -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,7 +98,12 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 | 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: | |
|
101 | 107 | data = self.dataOut.data[channelIndexList,:] |
|
102 | 108 | |
|
103 | 109 | self.dataOut.data = data |
@@ -185,6 +191,12 class VoltageProc(ProcessingUnit): | |||
|
185 | 191 | # nHeights = maxIndex - minIndex + 1 |
|
186 | 192 | |
|
187 | 193 | #voltage |
|
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: | |
|
188 | 200 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
189 | 201 | |
|
190 | 202 | # firstHeight = self.dataOut.heightList[minIndex] |
@@ -196,25 +208,27 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) | |
|
218 | r = self.dataOut.nHeights % window | |
|
210 | 219 | |
|
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) | |
|
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) | |
|
215 | 227 | |
|
216 | 228 | else: |
|
217 | raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis) | |
|
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) | |
|
218 | 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) |
@@ -222,11 +236,41 class VoltageProc(ProcessingUnit): | |||
|
222 | 236 | |
|
223 | 237 | return 1 |
|
224 | 238 | |
|
225 | def deFlip(self): | |
|
226 | self.dataOut.data *= self.flip | |
|
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 | ||
|
227 | 266 | self.flip *= -1. |
|
228 | 267 | |
|
268 | self.dataOut.data = data | |
|
269 | ||
|
270 | ||
|
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,16 +528,22 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 | 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: | |
|
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: | |
|
493 | 547 |
|
|
494 | 548 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
495 | 549 | |
@@ -500,14 +554,6 class Decoder(Operation): | |||
|
500 | 554 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
501 | 555 | |
|
502 | 556 | 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 | ||
|
510 | ||
|
511 | 557 | |
|
512 | 558 | def convolutionInFreq(self, data): |
|
513 | 559 | |
@@ -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): |
@@ -555,26 +604,27 class Decoder(Operation): | |||
|
555 | 604 | |
|
556 | 605 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): |
|
557 | 606 | |
|
607 | if not self.isConfig: | |
|
608 | ||
|
558 | 609 | if code == None: |
|
559 | 610 | code = dataOut.code |
|
560 | 611 | else: |
|
561 | 612 | code = numpy.array(code).reshape(nCode,nBaud) |
|
562 | 613 | |
|
563 | ||
|
564 | ||
|
565 | if not self.isConfig: | |
|
566 | ||
|
567 | self.setup(code, dataOut.data.shape, times, osamp) | |
|
568 | ||
|
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 |
|
577 | 617 | |
|
618 | if dataOut.flagDataAsBlock: | |
|
619 | """ | |
|
620 | Decoding when data have been read as block, | |
|
621 | """ | |
|
622 | datadec = self.convolutionByBlockInTime(dataOut.data) | |
|
623 | ||
|
624 | else: | |
|
625 | """ | |
|
626 | Decoding when data have been read profile by profile | |
|
627 | """ | |
|
578 | 628 | if mode == 0: |
|
579 | 629 | datadec = self.convolutionInTime(dataOut.data) |
|
580 | 630 | |
@@ -584,23 +634,18 class Decoder(Operation): | |||
|
584 | 634 | if mode == 2: |
|
585 | 635 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
586 | 636 |
|
|
587 | if mode == 3: | |
|
588 | datadec = self.convolutionByBlockInTime(dataOut.data) | |
|
589 | ||
|
590 | if not(self.__setValues): | |
|
591 | dataOut.code = self.code | |
|
592 | dataOut.nCode = self.nCode | |
|
593 | dataOut.nBaud = self.nBaud | |
|
594 | dataOut.radarControllerHeaderObj.code = self.code | |
|
595 | dataOut.radarControllerHeaderObj.nCode = self.nCode | |
|
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 |
@@ -646,6 +691,11 class ProfileConcat(Operation): | |||
|
646 | 691 | self.setup(dataOut.data, m, 1) |
|
647 | 692 | self.isConfig = True |
|
648 | 693 | |
|
694 | if dataOut.flagDataAsBlock: | |
|
695 | ||
|
696 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profiel, getBlock = False" | |
|
697 | ||
|
698 | else: | |
|
649 | 699 | self.concat(dataOut.data) |
|
650 | 700 | self.times += 1 |
|
651 | 701 | if self.times > m: |
@@ -693,23 +743,40 class ProfileSelector(Operation): | |||
|
693 | 743 | |
|
694 | 744 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): |
|
695 | 745 | |
|
746 | """ | |
|
747 | ProfileSelector: | |
|
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 | return 1 | |
|
711 | 770 | |
|
771 | return True | |
|
772 | ||
|
773 | else: | |
|
774 | """ | |
|
775 | data dimension = [nChannels, nHeis] | |
|
776 | ||
|
777 | """ | |
|
712 | 778 | if profileList != None: |
|
779 | ||
|
713 | 780 | if self.isProfileInList(profileList): |
|
714 | 781 | dataOut.flagNoData = False |
|
715 | 782 | |
@@ -717,7 +784,8 class ProfileSelector(Operation): | |||
|
717 | 784 | return 1 |
|
718 | 785 | |
|
719 | 786 | |
|
720 |
|
|
|
787 | if profileRangeList != None: | |
|
788 | ||
|
721 | 789 | minIndex = profileRangeList[0] |
|
722 | 790 | maxIndex = profileRangeList[1] |
|
723 | 791 | if self.isProfileInRange(minIndex, maxIndex): |
@@ -725,14 +793,14 class ProfileSelector(Operation): | |||
|
725 | 793 | |
|
726 | 794 | self.incIndex() |
|
727 | 795 | return 1 |
|
728 | elif beam != None: #beam is only for AMISR data | |
|
796 | ||
|
797 | if beam != None: #beam is only for AMISR data | |
|
729 | 798 | if self.isProfileInList(dataOut.beamRangeDict[beam]): |
|
730 | 799 | dataOut.flagNoData = False |
|
731 | 800 | |
|
732 | 801 | self.incIndex() |
|
733 | 802 | return 1 |
|
734 | 803 | |
|
735 | else: | |
|
736 | 804 |
|
|
737 | 805 | |
|
738 | 806 | return 0 |
@@ -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 |
|
838 | ||
|
762 | 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