##// END OF EJS Templates
jroproc_voltage.py: ProfileSelector, Decoder, Reshape was tested with nTxs != 1 and getblock = True
Miguel Valdez -
r749:2d4c40d861d3
parent child
Show More
@@ -619,6 +619,9 class Decoder(Operation):
619
619
620 def __convolutionByBlockInFreq(self, data):
620 def __convolutionByBlockInFreq(self, data):
621
621
622 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
623
624
622 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
623
626
624 fft_data = numpy.fft.fft(data, axis=2)
627 fft_data = numpy.fft.fft(data, axis=2)
@@ -650,20 +653,22 class Decoder(Operation):
650
653
651 if mode == 3:
654 if mode == 3:
652 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
655 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
653
656
657 if times != None:
658 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
654
659
655 if self.code is None:
660 if self.code is None:
656 print "Fail decoding: Code is not defined."
661 print "Fail decoding: Code is not defined."
657 return
662 return
658
663
659 datadec = None
664 datadec = None
660
665 if mode == 3:
666 mode = 0
667
661 if dataOut.flagDataAsBlock:
668 if dataOut.flagDataAsBlock:
662 """
669 """
663 Decoding when data have been read as block,
670 Decoding when data have been read as block,
664 """
671 """
665 if mode == 3:
666 mode = 0
667
672
668 if mode == 0:
673 if mode == 0:
669 datadec = self.__convolutionByBlockInTime(dataOut.data)
674 datadec = self.__convolutionByBlockInTime(dataOut.data)
@@ -805,27 +810,35 class ProfileSelector(Operation):
805 """
810 """
806
811
807 dataOut.flagNoData = True
812 dataOut.flagNoData = True
808
813
809 if dataOut.flagDataAsBlock:
814 if dataOut.flagDataAsBlock:
810 """
815 """
811 data dimension = [nChannels, nProfiles, nHeis]
816 data dimension = [nChannels, nProfiles, nHeis]
812 """
817 """
813 if profileList != None:
818 if profileList != None:
814 dataOut.data = dataOut.data[:,profileList,:]
819 dataOut.data = dataOut.data[:,profileList,:]
815 dataOut.nProfiles = len(profileList)
816 dataOut.profileIndex = dataOut.nProfiles - 1
817
820
818 if profileRangeList != None:
821 if profileRangeList != None:
819 minIndex = profileRangeList[0]
822 minIndex = profileRangeList[0]
820 maxIndex = profileRangeList[1]
823 maxIndex = profileRangeList[1]
821
824 profileList = range(minIndex, maxIndex+1)
825
822 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
826 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
823 dataOut.nProfiles = maxIndex - minIndex + 1
824 dataOut.profileIndex = dataOut.nProfiles - 1
825
827
826 if rangeList != None:
828 if rangeList != None:
827 raise ValueError, "Profile Selector: Invalid argument rangeList. Not implemented for getByBlock yet"
828
829
830 profileList = []
831
832 for thisRange in rangeList:
833 minIndex = thisRange[0]
834 maxIndex = thisRange[1]
835
836 profileList.extend(range(minIndex, maxIndex+1))
837
838 dataOut.data = dataOut.data[:,profileList,:]
839
840 dataOut.nProfiles = len(profileList)
841 dataOut.profileIndex = dataOut.nProfiles - 1
829 dataOut.flagNoData = False
842 dataOut.flagNoData = False
830
843
831 return True
844 return True
@@ -834,18 +847,14 class ProfileSelector(Operation):
834 data dimension = [nChannels, nHeis]
847 data dimension = [nChannels, nHeis]
835 """
848 """
836
849
837 if nProfiles:
838 self.nProfiles = nProfiles
839 else:
840 self.nProfiles = dataOut.nProfiles
841
842 if profileList != None:
850 if profileList != None:
843
851
844 dataOut.nProfiles = len(profileList)
845
846 if self.isThisProfileInList(dataOut.profileIndex, profileList):
852 if self.isThisProfileInList(dataOut.profileIndex, profileList):
847 dataOut.flagNoData = False
853
854 self.nProfiles = len(profileList)
855 dataOut.nProfiles = self.nProfiles
848 dataOut.profileIndex = self.profileIndex
856 dataOut.profileIndex = self.profileIndex
857 dataOut.flagNoData = False
849
858
850 self.incIndex()
859 self.incIndex()
851 return True
860 return True
@@ -855,11 +864,12 class ProfileSelector(Operation):
855 minIndex = profileRangeList[0]
864 minIndex = profileRangeList[0]
856 maxIndex = profileRangeList[1]
865 maxIndex = profileRangeList[1]
857
866
858 dataOut.nProfiles = maxIndex - minIndex + 1
859
860 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
867 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
861 dataOut.flagNoData = False
868
869 self.nProfiles = maxIndex - minIndex + 1
870 dataOut.nProfiles = self.nProfiles
862 dataOut.profileIndex = self.profileIndex
871 dataOut.profileIndex = self.profileIndex
872 dataOut.flagNoData = False
863
873
864 self.incIndex()
874 self.incIndex()
865 return True
875 return True
@@ -874,8 +884,6 class ProfileSelector(Operation):
874
884
875 nProfiles += maxIndex - minIndex + 1
885 nProfiles += maxIndex - minIndex + 1
876
886
877 dataOut.nProfiles = nProfiles
878
879 for thisRange in rangeList:
887 for thisRange in rangeList:
880
888
881 minIndex = thisRange[0]
889 minIndex = thisRange[0]
@@ -883,13 +891,15 class ProfileSelector(Operation):
883
891
884 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
892 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
885
893
886 # print "profileIndex = ", dataOut.profileIndex
894 self.nProfiles = nProfiles
887
895 dataOut.nProfiles = self.nProfiles
888 dataOut.flagNoData = False
889 dataOut.profileIndex = self.profileIndex
896 dataOut.profileIndex = self.profileIndex
890
897 dataOut.flagNoData = False
898
891 self.incIndex()
899 self.incIndex()
900
892 break
901 break
902
893 return True
903 return True
894
904
895
905
@@ -913,35 +923,102 class Reshaper(Operation):
913 def __init__(self):
923 def __init__(self):
914
924
915 Operation.__init__(self)
925 Operation.__init__(self)
916 self.updateNewHeights = True
926
927 self.__buffer = None
928 self.__nitems = 0
929
930 def __appendProfile(self, dataOut, nTxs):
931
932 if self.__buffer is None:
933 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
934 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
935
936 ini = dataOut.nHeights * self.__nitems
937 end = ini + dataOut.nHeights
938
939 self.__buffer[:, ini:end] = dataOut.data
940
941 self.__nitems += 1
942
943 return int(self.__nitems*nTxs)
917
944
918 def run(self, dataOut, shape):
945 def __getBuffer(self):
919
946
920 if not dataOut.flagDataAsBlock:
947 if self.__nitems == int(1./self.__nTxs):
921 raise ValueError, "Reshaper can only be used when voltage have been read as Block, getBlock = True"
948
949 self.__nitems = 0
950
951 return self.__buffer.copy()
922
952
923 if len(shape) != 3:
953 return None
924 raise ValueError, "shape len should be equal to 3, (nChannels, nProfiles, nHeis)"
954
955 def __checkInputs(self, dataOut, shape, nTxs):
925
956
926 shape_tuple = tuple(shape)
957 if shape is None and nTxs is None:
927 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
958 raise ValueError, "Reshaper: shape of factor should be defined"
928 dataOut.flagNoData = False
929
959
930 if self.updateNewHeights:
960 if nTxs:
961 if nTxs < 0:
962 raise ValueError, "nTxs should be greater than 0"
931
963
932 old_nheights = dataOut.nHeights
964 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
933 new_nheights = dataOut.data.shape[2]
965 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
934 factor = 1.0*new_nheights / old_nheights
935
966
936 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
967 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
968
969 if len(shape) != 2 and len(shape) != 3:
970 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
971
972 if len(shape) == 2:
973 shape_tuple = [dataOut.nChannels]
974 shape_tuple.extend(shape)
975 else:
976 shape_tuple = list(shape)
977
978 if not nTxs:
979 nTxs = int(shape_tuple[1]/dataOut.nProfiles)
937
980
938 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor
981 return shape_tuple, nTxs
982
983 def run(self, dataOut, shape=None, nTxs=None):
984
985 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
986
987 dataOut.flagNoData = True
988 profileIndex = None
989
990 if dataOut.flagDataAsBlock:
991
992 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
993 dataOut.flagNoData = False
939
994
940 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
995 profileIndex = int(dataOut.nProfiles*nTxs) - 1
941
996
942 dataOut.nProfiles = dataOut.data.shape[1]
997 else:
943
998
944 dataOut.ippSeconds *= factor
999 if self.__nTxs < 1:
1000
1001 self.__appendProfile(dataOut, self.__nTxs)
1002 new_data = self.__getBuffer()
1003
1004 if new_data is not None:
1005 dataOut.data = new_data
1006 dataOut.flagNoData = False
1007
1008 profileIndex = dataOut.profileIndex*nTxs
1009
1010 else:
1011 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1012
1013 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1014
1015 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1016
1017 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1018
1019 dataOut.profileIndex = profileIndex
1020
1021 dataOut.ippSeconds /= self.__nTxs
945 #
1022 #
946 # import collections
1023 # import collections
947 # from scipy.stats import mode
1024 # from scipy.stats import mode
General Comments 0
You need to be logged in to leave comments. Login now