@@ -619,6 +619,9 class Decoder(Operation): | |||
|
619 | 619 | |
|
620 | 620 | def __convolutionByBlockInFreq(self, data): |
|
621 | 621 | |
|
622 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" | |
|
623 | ||
|
624 | ||
|
622 | 625 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
623 | 626 | |
|
624 | 627 | fft_data = numpy.fft.fft(data, axis=2) |
@@ -651,19 +654,21 class Decoder(Operation): | |||
|
651 | 654 | if mode == 3: |
|
652 | 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 | 660 | if self.code is None: |
|
656 | 661 | print "Fail decoding: Code is not defined." |
|
657 | 662 | return |
|
658 | 663 | |
|
659 | 664 | datadec = None |
|
665 | if mode == 3: | |
|
666 | mode = 0 | |
|
660 | 667 | |
|
661 | 668 | if dataOut.flagDataAsBlock: |
|
662 | 669 | """ |
|
663 | 670 | Decoding when data have been read as block, |
|
664 | 671 | """ |
|
665 | if mode == 3: | |
|
666 | mode = 0 | |
|
667 | 672 | |
|
668 | 673 | if mode == 0: |
|
669 | 674 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
@@ -812,20 +817,28 class ProfileSelector(Operation): | |||
|
812 | 817 | """ |
|
813 | 818 | if profileList != None: |
|
814 | 819 | dataOut.data = dataOut.data[:,profileList,:] |
|
815 | dataOut.nProfiles = len(profileList) | |
|
816 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
|
817 | 820 | |
|
818 | 821 | if profileRangeList != None: |
|
819 | 822 | minIndex = profileRangeList[0] |
|
820 | 823 | maxIndex = profileRangeList[1] |
|
824 | profileList = range(minIndex, maxIndex+1) | |
|
821 | 825 | |
|
822 | 826 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
823 | dataOut.nProfiles = maxIndex - minIndex + 1 | |
|
824 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
|
825 | 827 | |
|
826 | 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 | 842 | dataOut.flagNoData = False |
|
830 | 843 | |
|
831 | 844 | return True |
@@ -834,18 +847,14 class ProfileSelector(Operation): | |||
|
834 | 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 | 850 | if profileList != None: |
|
843 | 851 | |
|
844 | dataOut.nProfiles = len(profileList) | |
|
845 | ||
|
846 | 852 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
847 | dataOut.flagNoData = False | |
|
853 | ||
|
854 | self.nProfiles = len(profileList) | |
|
855 | dataOut.nProfiles = self.nProfiles | |
|
848 | 856 | dataOut.profileIndex = self.profileIndex |
|
857 | dataOut.flagNoData = False | |
|
849 | 858 | |
|
850 | 859 | self.incIndex() |
|
851 | 860 | return True |
@@ -855,11 +864,12 class ProfileSelector(Operation): | |||
|
855 | 864 | minIndex = profileRangeList[0] |
|
856 | 865 | maxIndex = profileRangeList[1] |
|
857 | 866 | |
|
858 | dataOut.nProfiles = maxIndex - minIndex + 1 | |
|
859 | ||
|
860 | 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 | 871 | dataOut.profileIndex = self.profileIndex |
|
872 | dataOut.flagNoData = False | |
|
863 | 873 | |
|
864 | 874 | self.incIndex() |
|
865 | 875 | return True |
@@ -874,8 +884,6 class ProfileSelector(Operation): | |||
|
874 | 884 | |
|
875 | 885 | nProfiles += maxIndex - minIndex + 1 |
|
876 | 886 | |
|
877 | dataOut.nProfiles = nProfiles | |
|
878 | ||
|
879 | 887 | for thisRange in rangeList: |
|
880 | 888 | |
|
881 | 889 | minIndex = thisRange[0] |
@@ -883,13 +891,15 class ProfileSelector(Operation): | |||
|
883 | 891 | |
|
884 | 892 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
885 | 893 | |
|
886 |
|
|
|
887 | ||
|
888 | dataOut.flagNoData = False | |
|
894 | self.nProfiles = nProfiles | |
|
895 | dataOut.nProfiles = self.nProfiles | |
|
889 | 896 | dataOut.profileIndex = self.profileIndex |
|
897 | dataOut.flagNoData = False | |
|
890 | 898 |
|
|
891 | 899 | self.incIndex() |
|
900 | ||
|
892 | 901 | break |
|
902 | ||
|
893 | 903 | return True |
|
894 | 904 | |
|
895 | 905 | |
@@ -913,35 +923,102 class Reshaper(Operation): | |||
|
913 | 923 | def __init__(self): |
|
914 | 924 | |
|
915 | 925 | Operation.__init__(self) |
|
916 | self.updateNewHeights = True | |
|
917 | 926 | |
|
918 | def run(self, dataOut, shape): | |
|
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) | |
|
944 | ||
|
945 | def __getBuffer(self): | |
|
946 | ||
|
947 | if self.__nitems == int(1./self.__nTxs): | |
|
919 | 948 | |
|
920 | if not dataOut.flagDataAsBlock: | |
|
921 | raise ValueError, "Reshaper can only be used when voltage have been read as Block, getBlock = True" | |
|
949 | self.__nitems = 0 | |
|
922 | 950 | |
|
923 | if len(shape) != 3: | |
|
924 | raise ValueError, "shape len should be equal to 3, (nChannels, nProfiles, nHeis)" | |
|
951 | return self.__buffer.copy() | |
|
952 | ||
|
953 | return None | |
|
954 | ||
|
955 | def __checkInputs(self, dataOut, shape, nTxs): | |
|
956 | ||
|
957 | if shape is None and nTxs is None: | |
|
958 | raise ValueError, "Reshaper: shape of factor should be defined" | |
|
959 | ||
|
960 | if nTxs: | |
|
961 | if nTxs < 0: | |
|
962 | raise ValueError, "nTxs should be greater than 0" | |
|
963 | ||
|
964 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
|
965 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) | |
|
966 | ||
|
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) | |
|
980 | ||
|
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: | |
|
925 | 991 | |
|
926 | shape_tuple = tuple(shape) | |
|
927 | 992 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
928 | 993 | dataOut.flagNoData = False |
|
929 | 994 | |
|
930 | if self.updateNewHeights: | |
|
995 | profileIndex = int(dataOut.nProfiles*nTxs) - 1 | |
|
931 | 996 | |
|
932 | old_nheights = dataOut.nHeights | |
|
933 | new_nheights = dataOut.data.shape[2] | |
|
934 | factor = 1.0*new_nheights / old_nheights | |
|
997 | else: | |
|
998 | ||
|
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)" | |
|
935 | 1012 |
|
|
936 | 1013 |
|
|
937 | 1014 |
|
|
938 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor | |
|
1015 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
|
939 | 1016 |
|
|
940 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
|
1017 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
|
941 | 1018 |
|
|
942 | dataOut.nProfiles = dataOut.data.shape[1] | |
|
1019 | dataOut.profileIndex = profileIndex | |
|
943 | 1020 |
|
|
944 |
|
|
|
1021 | dataOut.ippSeconds /= self.__nTxs | |
|
945 | 1022 | # |
|
946 | 1023 | # import collections |
|
947 | 1024 | # from scipy.stats import mode |
General Comments 0
You need to be logged in to leave comments.
Login now