diff --git a/schainpy/IO/CorrelationIO.py b/schainpy/IO/CorrelationIO.py index 0c018aa..06830f9 100644 --- a/schainpy/IO/CorrelationIO.py +++ b/schainpy/IO/CorrelationIO.py @@ -5,20 +5,35 @@ Created on 23/01/2012 @version $Id$ ''' -from JRODataIO import JRODataIO +import os, sys +import numpy +import glob +import fnmatch +import time, datetime -class CorrelationReader(JRODataIO): +path = os.path.split(os.getcwd())[0] +sys.path.append(path) + +from Model.JROHeader import * +from Model.Voltage import Voltage + +from IO.JRODataIO import JRODataReader +from IO.JRODataIO import JRODataWriter + + +class CorrelationReader(JRODataReader):#JRODataReader para lectura de correlaciones en archivos HDF5 def __init__(self): pass -class CorrelationWriter(JRODataIO): +class CorrelationWriter(JRODataWriter):#JRODataWriter para escritura de correlaciones en archivos HDF5 def __init__(self): + pass - def putData(self): + def puData(self): pass def writeBlock(self): diff --git a/schainpy/Model/Correlation.py b/schainpy/Model/Correlation.py index 42b1814..c97a2ad 100644 --- a/schainpy/Model/Correlation.py +++ b/schainpy/Model/Correlation.py @@ -33,7 +33,7 @@ class Correlation(JROData): self.m_NoiseObj = Noise() - self.type = "Spectra" + self.type = "Correlation" self.dataType = None @@ -54,5 +54,7 @@ class Correlation(JROData): self.nLags = 0 - self.lagsList = None + self.tauList = None + + self.pairList = None \ No newline at end of file diff --git a/schainpy/Processing/CorrelationProcessor.py b/schainpy/Processing/CorrelationProcessor.py index 469d0c5..0394b93 100644 --- a/schainpy/Processing/CorrelationProcessor.py +++ b/schainpy/Processing/CorrelationProcessor.py @@ -5,18 +5,142 @@ Created on Feb 7, 2012 @version $Id$ ''' +import os, sys +import numpy + +path = os.path.split(os.getcwd())[0] +sys.path.append(path) + +from Model.Correlation import Correlation +from IO.CorrelationIO import CorrelationWriter +#from Graphics.CorrelationPlot import Correlator + + +from Model.Voltage import Voltage +from Model.Spectra import Spectra + class CorrelationProcessor: ''' classdocs ''' - - - def __init__(self): + + integratorIndex = None + writerIndex = None + plotterIndex = None + + lagsList = None + + nLags = None + tauList = None + pairList = None + indexTau = None + + + def __init__(self,dataInObj, dataOutObj=None): ''' Constructor ''' - pass - m_Correlation= Correlation() + self.dataInObj = dataInObj + + if dataOutObj == None: + self.dataOutObj = Correlation() + else: + self.dataOutObj = dataOutObj + + self.indexTau = 0 + self.buffer = None + + def init(self,pairList=None,tauList=None): + + self.integratorIndex = 0 + self.writerIndex = 0 + self.plotterIndex = 0 + + self.pairList = pairList + self.tauList = tauList + + if ( isinstance(self.dataInObj, Voltage) ): + self.__getCorrelation() + + if ( isinstance(self.dataInObj, Spectra) ): + sys.exit(0) + + if ( isinstance(self.dataInObj, Correlation) ): + sel.__getCopy() + + def __getCorrelation(self): + if self.dataInObj.flagNoData: + return 0 + + if self.tauList == None: # se lee el tauList desde el archivo + flip = None + if self.dataInObj.m_RadarControllerHeader.flip1 != None: + flip = self.dataInObj.m_RadarControllerHeader.flip1 + + if self.dataInObj.m_RadarControllerHeader.flip2 != None: + flip = self.dataInObj.m_RadarControllerHeader.flip2 + + if flip == None: + flip = 2 + print 'flip is None --> flip = %d '%flip + + ntaus = self.dataInObj.m_RadarControllerHeader.numTaus + taus = self.dataInObj.m_RadarControllerHeader.Taus.reshape(ntaus/flip,flip) + + index = 0 + self.tauList = taus[:,index] + print 'tauList is None --> tauList = obj.m_RadarControllerHeader.Taus[:,%d]'%index + + self.nLags = len(self.tauList) + + if self.pairList == None: + self.pairList = [(0,0)] # por defecto calcula la AutoCorrelacion de una canal + + self.dataOutObj.tauList = self.tauList + self.dataOutObj.nLags = self.nLags + self.dataOutObj.pairList = self.pairList + + if self.buffer == None: + nhei = self.dataInObj.nHeights + npairList = len(self.pairList) + self.buffer = numpy.zeros((self.nLags,nhei,npairList),dtype='complex') + + bufferZ = numpy.zeros((npairList,self.dataInObj.nHeights),dtype='complex') + + indexHeight = self.tauList[self.indexTau] / self.dataInObj.m_ProcessingHeader.deltaHeight + + countPair = 0 + + # make (signalA*signalB'), where signalA: channel without delay, signalB: channel with delay, + for pair in self.pairList: + bufferZ[countPair,0:self.dataInObj.nHeights-indexHeight] = self.dataInObj.data[pair[1],indexHeight:self.dataInObj.nHeights] + signalA = self.dataInObj.data[pair[0],:] + signalB = bufferZ[countPair,:] + data = signalA * numpy.conjugate(signalB) + self.buffer[self.indexTau,:,countPair] = data + countPair += 1 + + # change index Tau and lagCounter + self.indexTau += 1 + if self.indexTau >= self.nLags: + self.indexTau = 0 + self.dataOutObj.data = self.buffer + self.buffer = None + self.dataOutObj.flagNoData = False + else: + self.dataOutObj.flagNoData = True + - m_Voltage= Voltage() + def addIntegrator(self): + pass + + def addWriter(self): + pass + + def addPlotter(self): + pass + +class Integrator(): + def __init__(self): + pass diff --git a/schainpy/Processing/VoltageProcessor.py b/schainpy/Processing/VoltageProcessor.py index bda65a8..c67f84d 100644 --- a/schainpy/Processing/VoltageProcessor.py +++ b/schainpy/Processing/VoltageProcessor.py @@ -28,6 +28,7 @@ class VoltageProcessor: profSelectorObjIndex = None writerObjIndex = None plotterObjIndex = None + flipIndex = None integratorObjList = [] decoderObjList = [] @@ -60,7 +61,7 @@ class VoltageProcessor: self.profSelectorObjIndex = None self.writerObjIndex = None self.plotterObjIndex = None - + self.flipIndex = 1 self.integratorObjList = [] self.decoderObjList = [] self.profileSelectorObjList = [] @@ -75,6 +76,10 @@ class VoltageProcessor: self.writerObjIndex = 0 self.plotterObjIndex = 0 self.dataOutObj.copy(self.dataInObj) + + if self.profSelectorObjIndex != None: + for profSelObj in self.profileSelectorObjList: + profSelObj.incIndex() def addWriter(self, wrpath): objWriter = VoltageWriter(self.dataOutObj) @@ -173,8 +178,30 @@ class VoltageProcessor: def filterByHei(self, window): - pass - + if window == None: + window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0] + + newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window + dim1 = self.dataOutObj.data.shape[0] + dim2 = self.dataOutObj.data.shape[1] + r = dim2 % window + + buffer = self.dataOutObj.data[:,0:dim2-r] + buffer = buffer.reshape(dim1,dim2/window,window) + buffer = numpy.sum(buffer,2) + self.dataOutObj.data = buffer + + self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta + self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1] + + self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights + + #self.dataOutObj.heightList es un numpy.array + self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta) + + def deFlip(self): + self.dataOutObj.data *= self.flipIndex + self.flipIndex *= -1. def selectChannels(self, channelList): """ @@ -310,8 +337,27 @@ class VoltageProcessor: self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights return 1 + def selectProfilesByValue(self,indexList, nProfiles): + if self.dataOutObj.flagNoData: + return 0 + + if self.profSelectorObjIndex >= len(self.profileSelectorObjList): + self.addProfileSelector(nProfiles) + + profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] + + if not(profileSelectorObj.isProfileInList(indexList)): + self.dataOutObj.flagNoData = True + self.profSelectorObjIndex += 1 + return 0 + + self.dataOutObj.flagNoData = False + self.profSelectorObjIndex += 1 + + return 1 + - def selectProfiles(self, minIndex, maxIndex, nProfiles): + def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles): """ Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango minIndex <= index <= maxIndex @@ -337,15 +383,15 @@ class VoltageProcessor: profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] - if profileSelectorObj.isProfileInRange(minIndex, maxIndex): - self.dataOutObj.flagNoData = False + if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)): + self.dataOutObj.flagNoData = True self.profSelectorObjIndex += 1 - return 1 + return 0 - self.dataOutObj.flagNoData = True + self.dataOutObj.flagNoData = False self.profSelectorObjIndex += 1 - return 0 + return 1 def selectNtxs(self, ntx): pass @@ -466,37 +512,36 @@ class CoherentIntegrator: class ProfileSelector: - indexProfile = None + profileIndex = None # Tamanho total de los perfiles nProfiles = None def __init__(self, nProfiles): - self.indexProfile = 0 + self.profileIndex = 0 self.nProfiles = nProfiles + def incIndex(self): + self.profileIndex += 1 + + if self.profileIndex >= self.nProfiles: + self.profileIndex = 0 + def isProfileInRange(self, minIndex, maxIndex): - if self.indexProfile < minIndex: - self.indexProfile += 1 + if self.profileIndex < minIndex: return False - if self.indexProfile > maxIndex: - self.indexProfile += 1 + if self.profileIndex > maxIndex: return False - self.indexProfile += 1 - return True def isProfileInList(self, profileList): - if self.indexProfile not in profileList: - self.indexProfile += 1 + if self.profileIndex not in profileList: return False - self.indexProfile += 1 - return True