import numpy from jroproc_base import ProcessingUnit, Operation from model.data.jrodata import Correlation class CorrelationProc(ProcessingUnit): def __init__(self): ProcessingUnit.__init__(self) self.objectDict = {} self.buffer = None self.firstdatatime = None self.profIndex = 0 self.dataOut = Correlation() def __updateObjFromInput(self): self.dataOut.timeZone = self.dataIn.timeZone self.dataOut.dstFlag = self.dataIn.dstFlag self.dataOut.errorCount = self.dataIn.errorCount self.dataOut.useLocalTime = self.dataIn.useLocalTime self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() self.dataOut.channelList = self.dataIn.channelList self.dataOut.heightList = self.dataIn.heightList self.dataOut.dtype = numpy.dtype([('real','= 0 and AC2 >= 0): data1 = numpy.abs(self.dataOut.data_corr[AC1,:,indR,:]) data2 = numpy.abs(self.dataOut.data_corr[AC2,:,indR,:]) maxim1 = data1.max(axis = 0) maxim2 = data1.max(axis = 0) maxim = numpy.sqrt(maxim1*maxim2) else: #In case there is no autocorrelation for the pair data = numpy.abs(self.dataOut.data_corr[l,:,indR,:]) maxim = numpy.max(data, axis = 0) normFactor[l,:] = maxim self.dataOut.normFactor = normFactor return 1 def run(self, lagT=None, lagR=None, pairsList=None, nPoints=None, nAvg=None, bufferSize=None, fullT = False, fullR = False, removeDC = False): self.dataOut.flagNoData = True if self.dataIn.type == "Correlation": self.dataOut.copy(self.dataIn) return if self.dataIn.type == "Voltage": if pairsList == None: pairsList = [numpy.array([0,0])] if nPoints == None: nPoints = 128 #------------------------------------------------------------ #Condicionales para calcular Correlaciones en Tiempo y Rango if fullT: lagT = numpy.arange(nPoints*2 - 1) - nPoints + 1 elif lagT == None: lagT = numpy.array([0]) else: lagT = numpy.array(lagT) if fullR: lagR = numpy.arange(self.dataOut.nHeights) elif lagR == None: lagR = numpy.array([0]) #------------------------------------------------------------- if nAvg == None: nAvg = 1 if bufferSize == None: bufferSize = 0 deltaH = self.dataIn.heightList[1] - self.dataIn.heightList[0] self.dataOut.lagR = numpy.round(numpy.array(lagR)/deltaH) self.dataOut.pairsList = pairsList self.dataOut.nPoints = nPoints # channels = numpy.sort(list(set(list(itertools.chain.from_iterable(pairsList))))) if self.buffer == None: self.buffer = numpy.zeros((self.dataIn.nChannels,self.dataIn.nProfiles,self.dataIn.nHeights),dtype='complex') self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()[:,:] self.profIndex += 1 if self.firstdatatime == None: self.firstdatatime = self.dataIn.utctime if self.profIndex == nPoints: tmp = self.buffer[:,0:nPoints,:] self.buffer = None self.buffer = tmp #--------------- Remover DC ------------ if removeDC: self.buffer = self.removeDC(self.buffer) #--------------------------------------------- self.dataOut.data_volts = self.buffer self.__updateObjFromInput() self.dataOut.data_corr = numpy.zeros((len(pairsList), len(lagT),len(lagR), self.dataIn.nHeights), dtype='complex') for l in range(len(pairsList)): firstChannel = pairsList[l][0] secondChannel = pairsList[l][1] tmp = None tmp = numpy.zeros((len(lagT),len(lagR),self.dataIn.nHeights),dtype='complex') for t in range(len(lagT)): for r in range(len(lagR)): idxT = lagT[t] idxR = lagR[r] if idxT >= 0: vStacked = numpy.vstack((self.buffer[secondChannel,idxT:,:], numpy.zeros((idxT,self.dataIn.nHeights),dtype='complex'))) else: vStacked = numpy.vstack((numpy.zeros((-idxT,self.dataIn.nHeights),dtype='complex'), self.buffer[secondChannel,:(nPoints + idxT),:])) if idxR >= 0: hStacked = numpy.hstack((vStacked[:,idxR:],numpy.zeros((nPoints,idxR),dtype='complex'))) else: hStacked = numpy.hstack((numpy.zeros((nPoints,-idxR),dtype='complex'),vStacked[:,(self.dataOut.nHeights + idxR)])) tmp[t,r,:] = numpy.sum((numpy.conjugate(self.buffer[firstChannel,:,:])*hStacked),axis=0) hStacked = None vStacked = None self.dataOut.data_corr[l,:,:,:] = tmp[:,:,:] #Se Calcula los factores de Normalizacion self.dataOut.pairsAutoCorr = self.dataOut.getPairsAutoCorr() self.dataOut.lagT = lagT*self.dataIn.ippSeconds*self.dataIn.nCohInt self.dataOut.lagR = lagR self.calculateNormFactor() self.dataOut.flagNoData = False self.buffer = None self.firstdatatime = None self.profIndex = 0 return