diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 5e647ce..9514156 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -201,6 +201,8 @@ class JROData(GenericData): beam = Beam() + profileIndex = None + def __init__(self): raise ValueError, "This class has not been implemented" @@ -363,6 +365,8 @@ class Voltage(JROData): self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil + self.profileIndex = 0 + def getNoisebyHildebrand(self): """ Determino el nivel de ruido usando el metodo Hildebrand-Sekhon @@ -420,6 +424,8 @@ class Spectra(JROData): ippFactor = None + profileIndex = 0 + def __init__(self): ''' Constructor @@ -609,6 +615,8 @@ class SpectraHeis(Spectra): self.utctime = None self.blocksize = None + + self.profileIndex = 0 def getNormFactor(self): pwcode = 1 @@ -686,6 +694,8 @@ class Fits: self.useLocalTime = True + self.profileIndex = 0 + # self.utctime = None # self.timeZone = None # self.ltctime = None diff --git a/schainpy/model/io/jroIO_base.py b/schainpy/model/io/jroIO_base.py index bc59a8d..a96e177 100644 --- a/schainpy/model/io/jroIO_base.py +++ b/schainpy/model/io/jroIO_base.py @@ -378,6 +378,10 @@ class JRODataReader(JRODataIO): profileIndex = None + nTxs = 1 + + txIndex = None + def __init__(self): """ @@ -937,7 +941,8 @@ class JRODataReader(JRODataIO): online = False, delay = 60, walk = True, - getblock = False): + getblock = False, + nTxs = 1): if path == None: raise ValueError, "The path is not valid" @@ -995,6 +1000,7 @@ class JRODataReader(JRODataIO): ext = ext.lower() self.ext = ext self.getByBlock = getblock + self.nTxs = int(nTxs) if not(self.setNextFile()): if (startDate!=None) and (endDate!=None): diff --git a/schainpy/model/io/jroIO_voltage.py b/schainpy/model/io/jroIO_voltage.py index 1656745..7d91bfb 100644 --- a/schainpy/model/io/jroIO_voltage.py +++ b/schainpy/model/io/jroIO_voltage.py @@ -153,6 +153,10 @@ class VoltageReader(JRODataReader, ProcessingUnit): self.blocksize = 0 self.dataOut = self.createObjByDefault() + + self.nTxs = 1 + + self.txIndex = 0 def createObjByDefault(self): @@ -161,8 +165,10 @@ class VoltageReader(JRODataReader, ProcessingUnit): return dataObj def __hasNotDataInBuffer(self): + if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: return 1 + return 0 @@ -235,7 +241,8 @@ class VoltageReader(JRODataReader, ProcessingUnit): self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() -# self.dataOut.ippSeconds = self.ippSeconds + if self.nTxs > 1: + self.dataOut.radarControllerHeaderObj.ippSeconds /= self.nTxs # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt @@ -249,9 +256,12 @@ class VoltageReader(JRODataReader, ProcessingUnit): self.dataOut.dtype = self.dtype - self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock + self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs + + if self.processingHeaderObj.nHeights % self.nTxs != 0: + raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights) - xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight + xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) @@ -323,21 +333,52 @@ class VoltageReader(JRODataReader, ProcessingUnit): self.dataOut.flagNoData = True return 0 - if self.getByBlock: + if not self.getByBlock: + + """ + Return profile by profile + + If nTxs > 1 then one profile is divided by nTxs and number of total + blocks is increased by nTxs (nProfiles *= nTxs) + """ + if self.nTxs == 1: + self.dataOut.flagDataAsBlock = False + self.dataOut.data = self.datablock[:,self.profileIndex,:] + self.dataOut.profileIndex = self.profileIndex + + self.profileIndex += 1 + + else: + self.dataOut.flagDataAsBlock = False + + iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs) + endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs) + +# print iniHei_ForThisTx, endHei_ForThisTx + + self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx] + self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex + + self.txIndex += 1 + + if self.txIndex == self.nTxs: + self.txIndex = 0 + self.profileIndex += 1 + + else: + """ + Return all block + """ self.dataOut.flagDataAsBlock = True self.dataOut.data = self.datablock - self.profileIndex = self.processingHeaderObj.profilesPerBlock - else: - self.dataOut.flagDataAsBlock = False - self.dataOut.data = self.datablock[:,self.profileIndex,:] - self.profileIndex += 1 + self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock - 1 + + self.profileIndex = self.processingHeaderObj.profilesPerBlock - 1 self.dataOut.flagNoData = False self.getBasicHeader() - - self.dataOut.realtime = self.online return self.dataOut.data diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 43e4769..c3381f6 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -185,7 +185,7 @@ class VoltageProc(ProcessingUnit): raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) if (maxIndex >= self.dataOut.nHeights): - maxIndex = self.dataOut.nHeights-1 + maxIndex = self.dataOut.nHeights # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) # nHeights = maxIndex - minIndex + 1 @@ -195,14 +195,14 @@ class VoltageProc(ProcessingUnit): """ Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] """ - data = self.dataOut.data[:,minIndex:maxIndex+1,:] + data = self.dataOut.data[:,minIndex:maxIndex,:] else: - data = self.dataOut.data[:,minIndex:maxIndex+1] + data = self.dataOut.data[:,minIndex:maxIndex] # firstHeight = self.dataOut.heightList[minIndex] self.dataOut.data = data - self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] + self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] return 1 @@ -539,7 +539,7 @@ class Decoder(Operation): if dataOut.flagDataAsBlock: - self.ndatadec = self.__nHeis - self.nBaud + 1 + self.ndatadec = self.__nHeis #- self.nBaud + 1 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) @@ -551,7 +551,7 @@ class Decoder(Operation): self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) - self.ndatadec = self.__nHeis - self.nBaud + 1 + self.ndatadec = self.__nHeis #- self.nBaud + 1 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) @@ -565,7 +565,7 @@ class Decoder(Operation): data = numpy.fft.ifft(conv,axis=1) - datadec = data[:,:-self.nBaud+1] + datadec = data#[:,:] return datadec @@ -575,7 +575,7 @@ class Decoder(Operation): data = cfunctions.decoder(fft_code, data) - datadec = data[:,:-self.nBaud+1] + datadec = data#[:,:] return datadec @@ -584,7 +584,7 @@ class Decoder(Operation): code = self.code[self.__profIndex] for i in range(self.__nChannels): - self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') + self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='same') return self.datadecTime @@ -598,7 +598,7 @@ class Decoder(Operation): for i in range(self.__nChannels): for j in range(self.__nProfiles): - self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid') + self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='same') return self.datadecTime @@ -674,14 +674,14 @@ class ProfileConcat(Operation): def setup(self, data, m, n=1): self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) - self.profiles = data.shape[1] + self.nHeights = data.nHeights self.start_index = 0 self.times = 1 def concat(self, data): self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() - self.start_index = self.start_index + self.profiles + self.start_index = self.start_index + self.nHeights def run(self, dataOut, m): @@ -693,7 +693,7 @@ class ProfileConcat(Operation): if dataOut.flagDataAsBlock: - raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profiel, getBlock = False" + raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" else: self.concat(dataOut.data) @@ -704,8 +704,9 @@ class ProfileConcat(Operation): dataOut.flagNoData = False # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] - xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 + xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) + dataOut.ippSeconds *= m class ProfileSelector(Operation): @@ -719,33 +720,41 @@ class ProfileSelector(Operation): self.profileIndex = 0 def incIndex(self): + self.profileIndex += 1 if self.profileIndex >= self.nProfiles: self.profileIndex = 0 - def isProfileInRange(self, minIndex, maxIndex): + def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): - if self.profileIndex < minIndex: + if profileIndex < minIndex: return False - if self.profileIndex > maxIndex: + if profileIndex > maxIndex: return False return True - def isProfileInList(self, profileList): + def isThisProfileInList(self, profileIndex, profileList): - if self.profileIndex not in profileList: + if profileIndex not in profileList: return False return True - def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): + def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None): """ ProfileSelector: + Inputs: + profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) + + profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) + + rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) + """ dataOut.flagNoData = True @@ -758,15 +767,16 @@ class ProfileSelector(Operation): if profileList != None: dataOut.data = dataOut.data[:,profileList,:] dataOut.nProfiles = len(profileList) + dataOut.profileIndex = dataOut.nProfiles - 1 else: - pmin = profileRangeList[0] - pmax = profileRangeList[1] - dataOut.data = dataOut.data[:,pmin:pmax+1,:] - dataOut.nProfiles = pmax - pmin + 1 - + minIndex = profileRangeList[0] + maxIndex = profileRangeList[1] + + dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] + dataOut.nProfiles = maxIndex - minIndex + 1 + dataOut.profileIndex = dataOut.nProfiles - 1 dataOut.flagNoData = False - self.profileIndex = 0 return True @@ -777,28 +787,65 @@ class ProfileSelector(Operation): """ if profileList != None: - if self.isProfileInList(profileList): + dataOut.nProfiles = len(profileList) + + if self.isThisProfileInList(dataOut.profileIndex, profileList): dataOut.flagNoData = False + dataOut.profileIndex = self.profileIndex - self.incIndex() - return 1 + self.incIndex() + return True if profileRangeList != None: minIndex = profileRangeList[0] maxIndex = profileRangeList[1] - if self.isProfileInRange(minIndex, maxIndex): + + dataOut.nProfiles = maxIndex - minIndex + 1 + + if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): dataOut.flagNoData = False + dataOut.profileIndex = self.profileIndex - self.incIndex() - return 1 + self.incIndex() + return True + if rangeList != None: + + nProfiles = 0 + + for thisRange in rangeList: + minIndex = thisRange[0] + maxIndex = thisRange[1] + + nProfiles += maxIndex - minIndex + 1 + + dataOut.nProfiles = nProfiles + + for thisRange in rangeList: + + minIndex = thisRange[0] + maxIndex = thisRange[1] + + if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): + +# print "profileIndex = ", dataOut.profileIndex + + dataOut.flagNoData = False + dataOut.profileIndex = self.profileIndex + + self.incIndex() + break + return True + + if beam != None: #beam is only for AMISR data - if self.isProfileInList(dataOut.beamRangeDict[beam]): + if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): dataOut.flagNoData = False + dataOut.profileIndex = self.profileIndex - self.incIndex() + self.incIndex() return 1 raise ValueError, "ProfileSelector needs profileList or profileRangeList" @@ -838,4 +885,6 @@ class Reshaper(Operation): dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) - dataOut.nProfiles = dataOut.data.shape[1] \ No newline at end of file + dataOut.nProfiles = dataOut.data.shape[1] + + dataOut.ippSeconds *= factor \ No newline at end of file