diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 5064a37..5f3f4e2 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -368,6 +368,8 @@ class Voltage(JROData): dataPP_DOP = None dataPP_WIDTH = None dataPP_SNR = None + flagProfilesByRange = False + nProfilesByRange = None def __init__(self): ''' @@ -458,6 +460,8 @@ class Voltage(JROData): class Spectra(JROData): data_outlier = None + flagProfilesByRange = False + nProfilesByRange = None def __init__(self): ''' @@ -588,13 +592,13 @@ class Spectra(JROData): def normFactor(self): pwcode = 1 - if self.flagDecodeData: pwcode = numpy.sum(self.code[0]**2) #print(self.flagDecodeData, pwcode) #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter - + if self.flagProfilesByRange: + normFactor *= (self.nProfilesByRange/self.nProfilesByRange.max()) return normFactor @@ -939,7 +943,8 @@ class Parameters(Spectra): noise_estimation = None GauSPC = None # Fit gaussian SPC txPower = None - + flagProfilesByRange = False + nProfilesByRange = None def __init__(self): ''' diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index 0712922..70e5a5f 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -943,18 +943,21 @@ class NoiselessSpectraPlot(Plot): data = {} meta = {} - norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter#*dataOut.nFFTPoints - n0 = 10*numpy.log10(dataOut.getNoise()/norm) + norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter + n0 = (dataOut.getNoise()/norm) noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights) + noise = 10*numpy.log10(noise) - z = [] + z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights)) for ch in range(dataOut.nChannels): - if hasattr(dataOut.normFactor,'shape'): - z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch])) + if hasattr(dataOut.normFactor,'ndim'): + if dataOut.normFactor.ndim > 1: + z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch])) + else: + z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor)) else: - z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor)) + z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor)) - z = numpy.asarray(z) z = numpy.where(numpy.isfinite(z), z, numpy.NAN) spc = 10*numpy.log10(z) @@ -1061,8 +1064,6 @@ class NoiselessRTIPlot(RTIPlot): #print(dataOut.max_nIncohInt, dataOut.nIncohInt) #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt) norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter - - n0 = 10*numpy.log10(dataOut.getNoise()/norm) data['noise'] = n0 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights) diff --git a/schainpy/model/proc/jroproc_parameters.py b/schainpy/model/proc/jroproc_parameters.py index 95d6f06..3707fda 100755 --- a/schainpy/model/proc/jroproc_parameters.py +++ b/schainpy/model/proc/jroproc_parameters.py @@ -145,7 +145,8 @@ class ParametersProc(ProcessingUnit): self.dataOut.nIncohInt = self.dataIn.nIncohInt self.dataOut.nFFTPoints = self.dataIn.nFFTPoints self.dataOut.ippFactor = self.dataIn.ippFactor - + self.dataOut.flagProfilesByRange = self.dataIn.flagProfilesByRange + self.dataOut.nProfilesByRange = self.dataIn.nProfilesByRange self.dataOut.deltaHeight = self.dataIn.deltaHeight self.dataOut.abscissaList = self.dataIn.getVelRange(1) diff --git a/schainpy/model/proc/jroproc_spectra.py b/schainpy/model/proc/jroproc_spectra.py index 4a4db5d..c2f563d 100644 --- a/schainpy/model/proc/jroproc_spectra.py +++ b/schainpy/model/proc/jroproc_spectra.py @@ -76,6 +76,8 @@ class SpectraProc(ProcessingUnit): self.dataOut.elevationList = self.dataIn.elevationList self.dataOut.code = self.dataIn.code self.dataOut.nCode = self.dataIn.nCode + self.dataOut.flagProfilesByRange = self.dataIn.flagProfilesByRange + self.dataOut.nProfilesByRange = self.dataIn.nProfilesByRange def __getFft(self): @@ -1305,6 +1307,9 @@ class IntegrationFaradaySpectra(Operation): factor = 0.0 dataoutliers = None # (CHANNELS, HEIGHTS) + _flagProfilesByRange = False + _nProfilesByRange = 0 + def __init__(self): Operation.__init__(self) @@ -1631,7 +1636,10 @@ class IntegrationFaradaySpectra(Operation): if n == 1: return self.dataOut self.dataOut.processingHeaderObj.timeIncohInt = timeInterval - #print("nchannels", self.dataOut.nChannels) + + if dataOut.flagProfilesByRange == True: + self._flagProfilesByRange = True + if self.dataOut.nChannels == 1: self.dataOut.data_cspc = None #si es un solo canal no vale la pena acumular DATOS #print("IN spc:", self.dataOut.data_spc.shape, self.dataOut.data_cspc) @@ -1656,6 +1664,11 @@ class IntegrationFaradaySpectra(Operation): self.dataOut.dataLag_cspc, self.dataOut.dataLag_dc) self.dataOut.flagNoData = True + + if self._flagProfilesByRange: + dataOut.flagProfilesByRange = True + self._nProfilesByRange += dataOut.nProfilesByRange + if self.__dataReady: if not self.ByLags: @@ -1668,6 +1681,7 @@ class IntegrationFaradaySpectra(Operation): self.dataOut.data_cspc = numpy.squeeze(avgdata_cspc) self.dataOut.data_dc = avgdata_dc self.dataOut.data_outlier = self.dataOutliers + else: self.dataOut.dataLag_spc = avgdata_spc @@ -1684,6 +1698,10 @@ class IntegrationFaradaySpectra(Operation): self.dataOut.utctime = avgdatatime self.dataOut.flagNoData = False + + dataOut.nProfilesByRange = self._nProfilesByRange + self._nProfilesByRange = 0 + self._flagProfilesByRange = False # #update Processing Header: # self.dataOut.processingHeaderObj.nIncohInt = @@ -1996,7 +2014,9 @@ class IncohInt(Operation): incohInt = 0 nOutliers = 0 n = None - + + _flagProfilesByRange = False + _nProfilesByRange = 0 def __init__(self): Operation.__init__(self) @@ -2139,6 +2159,9 @@ class IncohInt(Operation): if dataOut.flagNoData == True: return dataOut + if dataOut.flagProfilesByRange == True: + self._flagProfilesByRange = True + dataOut.flagNoData = True dataOut.processingHeaderObj.timeIncohInt = timeInterval if not self.isConfig: @@ -2152,10 +2175,15 @@ class IncohInt(Operation): dataOut.data_dc) self.incohInt += dataOut.nIncohInt + if isinstance(dataOut.data_outlier,numpy.ndarray) or isinstance(dataOut.data_outlier,int) or isinstance(dataOut.data_outlier, float): self.nOutliers += dataOut.data_outlier + if self._flagProfilesByRange: + dataOut.flagProfilesByRange = True + self._nProfilesByRange += dataOut.nProfilesByRange + if self.__dataReady: #print("prof: ",dataOut.max_nIncohInt,self.__profIndex) dataOut.data_spc = avgdata_spc @@ -2168,6 +2196,9 @@ class IncohInt(Operation): self.incohInt = 0 self.nOutliers = 0 self.__profIndex = 0 + dataOut.nProfilesByRange = self._nProfilesByRange + self._nProfilesByRange = 0 + self._flagProfilesByRange = False #print("IncohInt Done") return dataOut diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 7646af3..b8e5565 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -45,8 +45,7 @@ class VoltageProc(ProcessingUnit): self.dataOut.processingHeaderObj.codeList = self.dataOut.nChannels self.dataOut.processingHeaderObj.heightList = self.dataOut.heightList self.dataOut.processingHeaderObj.heightResolution = self.dataOut.heightList[1] - self.dataOut.heightList[0] - - + def __updateObjFromAmisrInput(self): @@ -2018,7 +2017,17 @@ class SSheightProfiles2(Operation): dataOut.processingHeaderObj.ipp = ippSeconds dataOut.processingHeaderObj.heightResolution = dataOut.deltaHeight #dataOut.processingHeaderObj.profilesPerBlock = nProfiles - + + # # dataOut.data = CH, PROFILES, HEIGHTS + #print(dataOut.data .shape) + if dataOut.flagProfilesByRange: + # #assuming the same remotion for all channels + aux = [ self.nsamples - numpy.count_nonzero(dataOut.data[0, :, h]==0) for h in range(len(dataOut.heightList))] + dataOut.nProfilesByRange = numpy.asarray(aux) + #print(dataOut.nProfilesByRange) + else: + dataOut.nProfilesByRange = numpy.ones(len(dataOut.heightList))*dataOut.nProfiles + print(dataOut.nProfilesByRange) return dataOut @@ -2766,9 +2775,9 @@ class removeProfileByFaradayHS(Operation): if self.__profIndex == self.n: #print("apnd : ",data) - #dataBlock = self.cleanOutliersByBlock() + dataBlock = self.cleanOutliersByBlock() #dataBlock = self.cleanSpikesFFT2D() - dataBlock = self.filterSatsProfiles2() + #dataBlock = self.filterSatsProfiles2() self.__dataReady = True return dataBlock @@ -3566,3 +3575,83 @@ class RemoveProfileSats2(Operation): #print(self.__count_exec) return dataOut + + + + +class remHeightsIppInterf(Operation): + + def __init__(self): + + self.config = False + + self.heights_indx = None + self.heightsList = [] + + self.ipp1 = None + self.ipp2 = None + self.tx1 = None + self.tx2 = None + self.dh1 = None + + + def setup(self, dataOut, ipp1=None, ipp2=None, tx1=None, tx2=None, dh1=None, + idate=None, startH=None, endH=None): + + + self.ipp1 = ipp1 + self.ipp2 = ipp2 + self.tx1 = tx1 + self.tx2 = tx2 + self.dh1 = dh1 + + _maxIpp1R = dataOut.heightList.max() + + _n_repeats = int(_maxIpp1R / ipp2) + _init_hIntf = (tx1 + ipp2/2)+ dh1 + _n_hIntf = int(tx2 / dh1) + + self.heightsList = [_init_hIntf+n*ipp2 for n in range(_n_repeats) ] + heiList = dataOut.heightList + self.heights_indx = [getHei_index(h,h,heiList)[0] for h in self.heightsList] + + self.heights_indx = [ numpy.asarray([k for k in range(_n_hIntf+2)])+(getHei_index(h,h,heiList)[0] -1) for h in self.heightsList] + + self.heights_indx = numpy.asarray(self.heights_indx ) + self.config = True + self.startTime = datetime.datetime.combine(idate,startH) + self.endTime = datetime.datetime.combine(idate,endH) + #print(self.startTime, self.endTime) + #print("nrepeats: ", _n_repeats, " _nH: ",_n_hIntf ) + #print("H interf:",self.heightsList, dataOut.heightList[self.heights_indx] ) + + def run(self, dataOut, ipp1=None, ipp2=None, tx1=None, tx2=None, dh1=None, idate=None, + startH=None, endH=None): + #print(locals().values()) + if None in locals().values(): + log.warning('Missing kwargs, invalid values """None""" ', self.name) + return dataOut + + + if not self.config: + self.setup(dataOut, ipp1=ipp1, ipp2=ipp2, tx1=tx1, tx2=tx2, dh1=dh1, + idate=idate, startH=startH, endH=endH) + + flagProfilesByRange = False + currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) + + if currentTime < self.startTime or currentTime > self.endTime: + return dataOut + + + for ch in range(dataOut.data.shape[0]): + + for hk in self.heights_indx.flatten(): + if dataOut.data.ndim < 3: + dataOut.data[ch,hk] = 0 + 0j + else: + dataOut.data[ch,:,hk] = 0 + 0j + + dataOut.flagProfilesByRange = True + + return dataOut \ No newline at end of file