diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index dbf7c0d..f3a0452 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -489,7 +489,7 @@ class Spectra(JROData): return noise def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): - + if self.noise_estimation is not None: # this was estimated by getNoise Operation defined in jroproc_spectra.py return self.noise_estimation diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index 1f2a84a..0da983d 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -379,7 +379,8 @@ class NoisePlot(Plot): data = {} meta = {} - data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1) + noise = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1) + data['noise'] = noise meta['yrange'] = numpy.array([]) return data, meta @@ -392,8 +393,8 @@ class NoisePlot(Plot): Y = self.data['noise'] if self.axes[0].firsttime: - self.ymin = numpy.nanmin(Y) - 5 - self.ymax = numpy.nanmax(Y) + 5 + if self.ymin is None: self.ymin = numpy.nanmin(Y) - 5 + if self.ymax is None: self.ymax = numpy.nanmax(Y) + 5 for ch in self.data.channels: y = Y[ch] self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) diff --git a/schainpy/model/proc/jroproc_spectra.py b/schainpy/model/proc/jroproc_spectra.py index ff2e730..57dc8a9 100644 --- a/schainpy/model/proc/jroproc_spectra.py +++ b/schainpy/model/proc/jroproc_spectra.py @@ -202,6 +202,7 @@ class SpectraProc(ProcessingUnit): self.dataOut.flagNoData = False self.firstdatatime = None self.profIndex = 0 + self.dataOut.noise_estimation = None else: raise ValueError("The type of input object '%s' is not valid".format( self.dataIn.type)) @@ -488,6 +489,131 @@ class removeDC(Operation): return self.dataOut +class getNoise(Operation): + def __init__(self): + + Operation.__init__(self) + + def run(self, dataOut, minHei=None, maxHei=None, minVel=None, maxVel=None, minFreq= None, maxFreq=None,): + self.dataOut = dataOut.copy() + print("1: ",dataOut.noise_estimation, dataOut.normFactor) + + if minHei == None: + minHei = self.dataOut.heightList[0] + + if maxHei == None: + maxHei = self.dataOut.heightList[-1] + + if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): + print('minHei: %.2f is out of the heights range' % (minHei)) + print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) + minHei = self.dataOut.heightList[0] + + if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): + print('maxHei: %.2f is out of the heights range' % (maxHei)) + print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) + maxHei = self.dataOut.heightList[-1] + + + #indices relativos a los puntos de fft, puede ser de acuerdo a velocidad o frecuencia + minIndexFFT = 0 + maxIndexFFT = 0 + # validacion de velocidades + indminPoint = None + indmaxPoint = None + + if minVel == None and maxVel == None: + + freqrange = self.dataOut.getFreqRange(1) + + if minFreq == None: + minFreq = freqrange[0] + + if maxFreq == None: + maxFreq = freqrange[-1] + + if (minFreq < freqrange[0]) or (minFreq > maxFreq): + print('minFreq: %.2f is out of the frequency range' % (minFreq)) + print('minFreq is setting to %.2f' % (freqrange[0])) + minFreq = freqrange[0] + + if (maxFreq > freqrange[-1]) or (maxFreq < minFreq): + print('maxFreq: %.2f is out of the frequency range' % (maxFreq)) + print('maxFreq is setting to %.2f' % (freqrange[-1])) + maxFreq = freqrange[-1] + + indminPoint = numpy.where(freqrange >= minFreq) + indmaxPoint = numpy.where(freqrange <= maxFreq) + + else: + velrange = self.dataOut.getVelRange(1) + + if minVel == None: + minVel = velrange[0] + + if maxVel == None: + maxVel = velrange[-1] + + if (minVel < velrange[0]) or (minVel > maxVel): + print('minVel: %.2f is out of the velocity range' % (minVel)) + print('minVel is setting to %.2f' % (velrange[0])) + minVel = velrange[0] + + if (maxVel > velrange[-1]) or (maxVel < minVel): + print('maxVel: %.2f is out of the velocity range' % (maxVel)) + print('maxVel is setting to %.2f' % (velrange[-1])) + maxVel = velrange[-1] + + indminPoint = numpy.where(velrange >= minVel) + indmaxPoint = numpy.where(velrange <= maxVel) + + + # seleccion de indices para rango + minIndex = 0 + maxIndex = 0 + heights = self.dataOut.heightList + + inda = numpy.where(heights >= minHei) + indb = numpy.where(heights <= maxHei) + + try: + minIndex = inda[0][0] + except: + minIndex = 0 + + try: + maxIndex = indb[0][-1] + except: + maxIndex = len(heights) + + if (minIndex < 0) or (minIndex > maxIndex): + raise ValueError("some value in (%d,%d) is not valid" % ( + minIndex, maxIndex)) + + if (maxIndex >= self.dataOut.nHeights): + maxIndex = self.dataOut.nHeights - 1 + #############################################################3 + # seleccion de indices para velocidades + + try: + minIndexFFT = indminPoint[0][0] + except: + minIndexFFT = 0 + + try: + maxIndexFFT = indmaxPoint[0][-1] + except: + maxIndexFFT = len( self.dataOut.getFreqRange(1)) + + #print(minIndex, maxIndex,minIndexVel, maxIndexVel) + noise = self.dataOut.getNoise(xmin_index=minIndexFFT, xmax_index=maxIndexFFT, ymin_index=minIndex, ymax_index=maxIndex) + + self.dataOut.noise_estimation = noise.copy() + #print("2: ",10*numpy.log10(self.dataOut.noise_estimation/64)) + return self.dataOut + + + # import matplotlib.pyplot as plt def fit_func( x, a0, a1, a2): #, a3, a4, a5):