diff --git a/schainpy/model/jrodata.py b/schainpy/model/jrodata.py index d845d8b..6632e8b 100644 --- a/schainpy/model/jrodata.py +++ b/schainpy/model/jrodata.py @@ -147,9 +147,9 @@ class JROData: code = None - flagDecodeData = True #asumo q la data esta decodificada + flagDecodeData = False #asumo q la data no esta decodificada - flagDeflipData = True #asumo q la data esta sin flip + flagDeflipData = False #asumo q la data no esta sin flip flagShiftFFT = False @@ -290,6 +290,13 @@ class Voltage(JROData): self.nCohInt = None self.blocksize = None + + self.flagDecodeData = False #asumo q la data no esta decodificada + + self.flagDeflipData = False #asumo q la data no esta sin flip + + self.flagShiftFFT = False + def getNoisebyHildebrand(self): """ @@ -379,6 +386,12 @@ class Spectra(JROData): self.nFFTPoints = None self.wavelength = None + + self.flagDecodeData = False #asumo q la data no esta decodificada + + self.flagDeflipData = False #asumo q la data no esta sin flip + + self.flagShiftFFT = False def getNoisebyHildebrand(self): """ diff --git a/schainpy/model/jrodataIO.py b/schainpy/model/jrodataIO.py index 78d1461..c4d93aa 100644 --- a/schainpy/model/jrodataIO.py +++ b/schainpy/model/jrodataIO.py @@ -1399,6 +1399,7 @@ class VoltageReader(JRODataReader): self.dataOut.flagShiftFFT = False if self.processingHeaderObj.code != None: + self.dataOut.nCode = self.processingHeaderObj.nCode self.dataOut.nBaud = self.processingHeaderObj.nBaud @@ -1408,6 +1409,13 @@ class VoltageReader(JRODataReader): self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() + + self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada + + self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip + + self.dataOut.flagShiftFFT = False + # self.updateDataHeader() @@ -2059,13 +2067,18 @@ class SpectraReader(JRODataReader): self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints - self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft - # self.profileIndex += 1 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() + + self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft + + self.dataOut.flagDecodeData = True #asumo q la data no esta decodificada + + self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip + return self.dataOut.data_spc diff --git a/schainpy/model/jroheaderIO.py b/schainpy/model/jroheaderIO.py index 0928ab0..41f10a8 100644 --- a/schainpy/model/jroheaderIO.py +++ b/schainpy/model/jroheaderIO.py @@ -369,7 +369,7 @@ class ProcessingHeader(Header): self.profilesPerBlock = int(header['nProfilesperBlock'][0]) self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) self.nWindows = int(header['nNumWindows'][0]) - self.processFlags = int(header['nProcessFlags']) + self.processFlags = header['nProcessFlags'] self.nCohInt = int(header['nCoherentIntegrations'][0]) self.nIncohInt = int(header['nIncoherentIntegrations'][0]) self.totalSpectra = int(header['nTotalSpectra'][0]) diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index 2dff751..58c9e2d 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -88,6 +88,7 @@ class CrossSpectraPlot(Figure): x = dataOut.getFreqRange(1) y = dataOut.getHeiRange() z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) avg = numpy.average(numpy.abs(z), axis=1) noise = dataOut.getNoise() @@ -265,10 +266,11 @@ class RTIPlot(Figure): x = dataOut.getTimeRange() y = dataOut.getHeiRange() z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) avg = numpy.average(z, axis=1) noise = dataOut.getNoise() - + if not self.__isConfig: nplots = len(channelIndexList) @@ -284,6 +286,7 @@ class RTIPlot(Figure): if zmin == None: zmin = numpy.nanmin(avg)*0.9 if zmax == None: zmax = numpy.nanmax(avg)*0.9 + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") self.__isConfig = True thisDatetime = dataOut.datatime @@ -313,9 +316,9 @@ class RTIPlot(Figure): self.draw() if save: - date = thisDatetime.strftime("%Y%m%d") + if figfile == None: - figfile = self.getFilename(name = date) + figfile = self.getFilename(name = self.name) self.saveFigure(figpath, figfile) @@ -412,7 +415,9 @@ class SpectraPlot(Figure): x = dataOut.getVelRange(1) y = dataOut.getHeiRange() + z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) avg = numpy.average(z, axis=1) noise = dataOut.getNoise() @@ -485,6 +490,8 @@ class Scope(Figure): def setup(self, idfigure, nplots, wintitle): + self.nplots = nplots + self.createFigure(idfigure, wintitle) nrow,ncol = self.getSubplots() @@ -494,7 +501,7 @@ class Scope(Figure): for i in range(nplots): self.addAxes(nrow, ncol, i, 0, colspan, rowspan) - self.nplots = nplots + def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): @@ -522,13 +529,11 @@ class Scope(Figure): channelIndexList.append(dataOut.channelList.index(channel)) x = dataOut.heightList - y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) + y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) y = y.real - noise = dataOut.getNoise() - if not self.__isConfig: - nplots = len(channelList) + nplots = len(channelIndexList) self.setup(idfigure=idfigure, nplots=nplots, @@ -550,7 +555,7 @@ class Scope(Figure): self.setWinTitle(title) for i in range(len(self.axesList)): - title = "Channel %d: %4.2fdB" %(i, noise[i]) + title = "Channel %d" %(i) axes = self.axesList[i] ychannel = y[i,:] axes.pline(x, ychannel, diff --git a/schainpy/model/jroprocessing.py b/schainpy/model/jroprocessing.py index 1e12f1f..26edf5e 100644 --- a/schainpy/model/jroprocessing.py +++ b/schainpy/model/jroprocessing.py @@ -62,7 +62,7 @@ class ProcessingUnit: def operation(self, **kwargs): """ - Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los + Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los atributos del objeto dataOut Input: @@ -347,24 +347,11 @@ class VoltageProc(ProcessingUnit): return 1 - - def filterByHeights(self, window): - deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] - - if window == None: - window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight - - newdelta = deltaHeight * window - r = self.dataOut.data.shape[1] % window - buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] - buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) - buffer = numpy.sum(buffer,2) - self.dataOut.data = buffer - self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta) - class CohInt(Operation): + __isConfig = False + __profIndex = 0 __withOverapping = False @@ -539,10 +526,10 @@ class CohInt(Operation): return avgdata, avgdatatime - def run(self, dataOut, n=None, timeInterval=None, overlapping=False): + def run(self, dataOut, **kwargs): if not self.__isConfig: - self.setup(n, timeInterval, overlapping) + self.setup(**kwargs) self.__isConfig = True avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) @@ -556,7 +543,102 @@ class CohInt(Operation): dataOut.utctime = avgdatatime dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt dataOut.flagNoData = False + +class Decoder(Operation): + + __isConfig = False + __profIndex = 0 + + code = None + + nCode = None + nBaud = None + + def __init__(self): + + self.__isConfig = False + + def setup(self, code): + + self.__profIndex = 0 + + self.code = code + + self.nCode = len(code) + self.nBaud = len(code[0]) + + def convolutionInFreq(self, data): + + ndata = data.shape[1] + newcode = numpy.zeros(ndata) + newcode[0:self.nBaud] = self.code[self.__profIndex] + + fft_data = numpy.fft.fft(data, axis=1) + fft_code = numpy.conj(numpy.fft.fft(newcode)) + fft_code = fft_code.reshape(1,len(fft_code)) + +# conv = fft_data.copy() +# conv.fill(0) + + conv = fft_data*fft_code + + data = numpy.fft.ifft(conv,axis=1) + + datadec = data[:,:-self.nBaud+1] + ndatadec = ndata - self.nBaud + 1 + + if self.__profIndex == self.nCode: + self.__profIndex = 0 + + self.__profIndex += 1 + + return ndatadec, datadec + + + def convolutionInTime(self, data): + + nchannel = data.shape[1] + newcode = self.code[self.__profIndex] + + datadec = data.copy() + + for i in range(nchannel): + datadec[i,:] = numpy.correlate(data[i,:], newcode) + + ndatadec = ndata - self.nBaud + 1 + + if self.__profIndex == self.nCode: + self.__profIndex = 0 + + self.__profIndex += 1 + + return ndatadec, datadec + + def run(self, dataOut, code=None, mode = 0): + + if not self.__isConfig: + if code == None: + code = dataOut.code + + self.setup(code) + self.__isConfig = True + + if mode == 0: + ndatadec, datadec = self.convolutionInFreq(data) + + if mode == 1: + ndatadec, datadec = self.convolutionInTime(data) + + dataOut.data = datadec + + dataOut.heightList = dataOut.heightList[0:ndatadec+1] + + dataOut.flagDecodeData = True #asumo q la data no esta decodificada + +# dataOut.flagDeflipData = True #asumo q la data no esta sin flip + + class SpectraProc(ProcessingUnit): @@ -606,7 +688,7 @@ class SpectraProc(ProcessingUnit): self.buffer self.dataOut.flagNoData """ - fft_volt = numpy.fft.fft(self.buffer,axis=1)/numpy.sqrt(self.dataOut.nFFTPoints) + fft_volt = numpy.fft.fft(self.buffer,axis=1) dc = fft_volt[:,0,:] #calculo de self-spectra @@ -635,6 +717,8 @@ class SpectraProc(ProcessingUnit): def init(self, nFFTPoints=None, pairsList=None): + self.dataOut.flagNoData = True + if self.dataIn.type == "Spectra": self.dataOut.copy(self.dataIn) return @@ -660,7 +744,7 @@ class SpectraProc(ProcessingUnit): dtype='complex') - self.buffer[:,self.profIndex,:] = self.dataIn.data + self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() self.profIndex += 1 if self.firstdatatime == None: @@ -987,159 +1071,4 @@ class IncohInt(Operation): dataOut.utctime = avgdatatime dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints dataOut.flagNoData = False - - -class ProfileSelector(Operation): - - profileIndex = None - # Tamanho total de los perfiles - nProfiles = None - - def __init__(self): - - self.profileIndex = 0 - - def incIndex(self): - self.profileIndex += 1 - - if self.profileIndex >= self.nProfiles: - self.profileIndex = 0 - - def isProfileInRange(self, minIndex, maxIndex): - - if self.profileIndex < minIndex: - return False - - if self.profileIndex > maxIndex: - return False - - return True - - def isProfileInList(self, profileList): - - if self.profileIndex not in profileList: - return False - - return True - - def run(self, dataOut, profileList=None, profileRangeList=None): - - self.nProfiles = dataOut.nProfiles - - if profileList != None: - if not(self.isProfileInList(profileList)): - dataOut.flagNoData = True - else: - dataOut.flagNoData = False - self.incIndex() - return 1 - - - elif profileRangeList != None: - minIndex = profileRangeList[0] - maxIndex = profileRangeList[1] - if not(self.isProfileInRange(minIndex, maxIndex)): - dataOut.flagNoData = True - else: - dataOut.flagNoData = False - self.incIndex() - return 1 - else: - raise ValueError, "ProfileSelector needs profileList or profileRangeList" - - return 0 - -class Decoder: - - data = None - profCounter = None - code = None - ncode = None - nbaud = None - codeIndex = None - flag = False - - def __init__(self): - - self.data = None - self.ndata = None - self.profCounter = 1 - self.codeIndex = 0 - self.flag = False - self.code = None - self.ncode = None - self.nbaud = None - self.__isConfig = False - - def convolutionInFreq(self, data, ndata): - - newcode = numpy.zeros(ndata) - newcode[0:self.nbaud] = self.code[self.codeIndex] - - self.codeIndex += 1 - - fft_data = numpy.fft.fft(data, axis=1) - fft_code = numpy.conj(numpy.fft.fft(newcode)) - fft_code = fft_code.reshape(1,len(fft_code)) - - conv = fft_data.copy() - conv.fill(0) - - conv = fft_data*fft_code - - data = numpy.fft.ifft(conv,axis=1) - self.data = data[:,:-self.nbaud+1] - self.flag = True - - if self.profCounter == self.ncode: - self.profCounter = 0 - self.codeIndex = 0 - - self.profCounter += 1 - - def convolutionInTime(self, data, ndata): - - nchannel = data.shape[1] - newcode = self.code[self.codeIndex] - self.codeIndex += 1 - conv = data.copy() - for i in range(nchannel): - conv[i,:] = numpy.correlate(data[i,:], newcode) - - self.data = conv - self.flag = True - - if self.profCounter == self.ncode: - self.profCounter = 0 - self.codeIndex = 0 - - self.profCounter += 1 - - def run(self, dataOut, code=None, mode = 0): - - if not(self.__isConfig): - if code == None: - code = dataOut.radarControllerHeaderObj.code -# code = dataOut.code - - ncode, nbaud = code.shape - self.code = code - self.ncode = ncode - self.nbaud = nbaud - self.__isConfig = True - - ndata = dataOut.data.shape[1] - - if mode == 0: - self.convolutionInFreq(dataOut.data, ndata) - - if mode == 1: - self.convolutionInTime(dataOut.data, ndata) - - self.ndata = ndata - self.nbaud + 1 - - dataOut.data = self.data - - dataOut.heightList = dataOut.heightList[:self.ndata] - - dataOut.flagNoData = False \ No newline at end of file + \ No newline at end of file