diff --git a/schainpy/Processing/Noise.py b/schainpy/Processing/Noise.py new file mode 100644 index 0000000..c3d042f --- /dev/null +++ b/schainpy/Processing/Noise.py @@ -0,0 +1,108 @@ +import numpy + +from Model.JROHeader import * +from Model.Voltage import Voltage + +def hildebrand_sekhon(Data, navg=1 ): + """ + This method is for the objective determination of de noise level in Doppler spectra. This + implementation technique is based on the fact that the standard deviation of the spectral + densities is equal to the mean spectral density for white Gaussian noise + + Inputs: + Data : heights + navg : numbers of averages + + Return: + -1 : any error + anoise : noise's level + """ + divisor = 8 + ratio = 7 / divisor + data = Data.reshape(-1) + npts = data.size #numbers of points of the data + + if npts < 32: + print "error in noise - requires at least 32 points" + return -1.0 + + # data sorted in ascending order + nmin = int(npts/divisor + ratio); + s = 0.0 + s2 = 0.0 + data2 = data[:npts] + data2.sort() + + for i in range(nmin): + s += data2[i] + s2 += data2[i]**2; + + icount = nmin + iflag = 0 + + for i in range(nmin, npts): + s += data2[i]; + s2 += data2[i]**2 + icount=icount+1; + p = s / float(icount); + p2 = p**2; + q = s2 / float(icount) - p2; + leftc = p2; + rightc = q * float(navg); + + if leftc > rightc: + iflag = 1; #No weather signal + # Signal detect: R2 < 1 (R2 = leftc/rightc) + if(leftc < rightc): + if iflag: + break + + anoise = 0.0; + for j in range(i): + anoise += data2[j]; + + anoise = anoise / float(i); + + return anoise; + + +class Noise(): + """ + Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler + """ + m_DataObj = None + + + def __init__(self, m_Voltage=None): + """ + Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. + + Affected: + self.m_DataObj + + Return: + None + """ +# if m_Voltage == None: +# m_Voltage = Voltage() +# +# if not(isinstance(m_Voltage, Voltage)): +# raise ValueError, "in Noise class, m_Voltage must be an Voltage class object" + + self.m_DataObj = m_Voltage + + + def getNoiseLevelByHildebrandSekhon(self): + """ + Determino el nivel de ruido usando el metodo Hildebrand-Sekhon + + Return: + noise level + """ + data = self.m_DataObj.data # heights x perfiles + #heights = numpy.transpose( Data, (2,0,1) ) # channel x profile x height + #data = Data[0,0,:] + + noiselevel = hildebrand_sekhon(data) + + print noiselevel