diff --git a/schainpy/model/data/jroheaderIO.py b/schainpy/model/data/jroheaderIO.py index c85ae5d..8303525 100644 --- a/schainpy/model/data/jroheaderIO.py +++ b/schainpy/model/data/jroheaderIO.py @@ -13,75 +13,77 @@ SPEED_OF_LIGHT = 299792458 SPEED_OF_LIGHT = 3e8 BASIC_STRUCTURE = numpy.dtype([ - ('nSize',' endFp: - sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name) + sys.stderr.write( + "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name) return 0 - + if fp.tell() < endFp: - sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name) + sys.stderr.write( + "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name) return 0 - + self.length = header.nbytes return 1 - + def write(self, fp): - - headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) - header = numpy.array(headerTuple,SYSTEM_STRUCTURE) + + headerTuple = (self.size, self.nSamples, self.nProfiles, + self.nChannels, self.adcResolution, self.pciDioBusWidth) + header = numpy.array(headerTuple, SYSTEM_STRUCTURE) header.tofile(fp) - + return 1 + class RadarControllerHeader(Header): - + expType = None nTx = None ipp = None @@ -287,7 +295,7 @@ class RadarControllerHeader(Header): rangeTxB = None structure = RADAR_STRUCTURE __size = None - + def __init__(self, expType=2, nTx=1, ipp=None, txA=0, txB=0, nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, @@ -295,8 +303,8 @@ class RadarControllerHeader(Header): prePulseBefore=0, prePulseAfter=0, codeType=0, nCode=0, nBaud=0, code=None, flip1=0, flip2=0): - -# self.size = 116 + + # self.size = 116 self.expType = expType self.nTx = nTx self.ipp = ipp @@ -305,7 +313,7 @@ class RadarControllerHeader(Header): self.rangeIpp = ipp self.rangeTxA = txA self.rangeTxB = txB - + self.nWindows = nWindows self.numTaus = numTaus self.codeType = codeType @@ -314,23 +322,23 @@ class RadarControllerHeader(Header): self.fClock = fClock self.prePulseBefore = prePulseBefore self.prePulseAfter = prePulseAfter - + self.nHeights = nHeights self.firstHeight = firstHeight self.deltaHeight = deltaHeight self.samplesWin = nHeights - + self.nCode = nCode self.nBaud = nBaud self.code = code self.flip1 = flip1 self.flip2 = flip2 - - self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 + + self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 # self.dynamic = numpy.array([],numpy.dtype('byte')) - + if self.fClock is None and self.deltaHeight is not None: - self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u) + self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u) def read(self, fp): self.length = 0 @@ -342,14 +350,14 @@ class RadarControllerHeader(Header): try: if hasattr(fp, 'read'): - header = numpy.fromfile(fp, RADAR_STRUCTURE,1) + header = numpy.fromfile(fp, RADAR_STRUCTURE, 1) else: - header = numpy.fromstring(fp, RADAR_STRUCTURE,1) + header = numpy.fromstring(fp, RADAR_STRUCTURE, 1) self.length += header.nbytes except Exception, e: print "RadarControllerHeader: " + str(e) return 0 - + size = int(header['nSize'][0]) self.expType = int(header['nExpType'][0]) self.nTx = int(header['nNTx'][0]) @@ -367,12 +375,14 @@ class RadarControllerHeader(Header): self.rangeIpp = header['sRangeIPP'][0] self.rangeTxA = header['sRangeTxA'][0] self.rangeTxB = header['sRangeTxB'][0] - + try: if hasattr(fp, 'read'): - samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows) + samplingWindow = numpy.fromfile( + fp, SAMPLING_STRUCTURE, self.nWindows) else: - samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) + samplingWindow = numpy.fromstring( + fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) self.length += samplingWindow.nbytes except Exception, e: print "RadarControllerHeader: " + str(e) @@ -381,24 +391,21 @@ class RadarControllerHeader(Header): self.firstHeight = samplingWindow['h0'] self.deltaHeight = samplingWindow['dh'] self.samplesWin = samplingWindow['nsa'] - - try: if hasattr(fp, 'read'): self.Taus = numpy.fromfile(fp, ' endFp: - sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name) + sys.stderr.write( + "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name) # return 0 - + if fp.tell() < endFp: - sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name) - - + sys.stderr.write( + "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name) + return 1 - + def write(self, fp): - + headerTuple = (self.size, self.expType, self.nTx, @@ -475,83 +487,87 @@ class RadarControllerHeader(Header): self.rangeIpp, self.rangeTxA, self.rangeTxB) - - header = numpy.array(headerTuple,RADAR_STRUCTURE) + + header = numpy.array(headerTuple, RADAR_STRUCTURE) header.tofile(fp) - - sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) - samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) + + sampleWindowTuple = ( + self.firstHeight, self.deltaHeight, self.samplesWin) + samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) samplingWindow.tofile(fp) - + if self.numTaus > 0: self.Taus.tofile(fp) - - if self.codeType !=0: + + if self.codeType != 0: nCode = numpy.array(self.nCode, ' 0: self.flag_cspc = True - - - + if startFp is not None: endFp = size + startFp if fp.tell() > endFp: - sys.stderr.write("Warning: Processing header size is lower than it has to be") + sys.stderr.write( + "Warning: Processing header size is lower than it has to be") return 0 - + if fp.tell() < endFp: - sys.stderr.write("Warning: Processing header size is greater than it is considered") - + sys.stderr.write( + "Warning: Processing header size is greater than it is considered") + return 1 - + def write(self, fp): - #Clear DEFINE_PROCESS_CODE + # Clear DEFINE_PROCESS_CODE self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) - + headerTuple = (self.size, self.dtype, self.blockSize, @@ -723,154 +743,163 @@ class ProcessingHeader(Header): self.nCohInt, self.nIncohInt, self.totalSpectra) - - header = numpy.array(headerTuple,PROCESSING_STRUCTURE) + + header = numpy.array(headerTuple, PROCESSING_STRUCTURE) header.tofile(fp) - + if self.nWindows != 0: - sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) - samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) + sampleWindowTuple = ( + self.firstHeight, self.deltaHeight, self.samplesWin) + samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) samplingWindow.tofile(fp) - + if self.totalSpectra != 0: -# spectraComb = numpy.array([],numpy.dtype('u1')) + # spectraComb = numpy.array([],numpy.dtype('u1')) spectraComb = self.spectraComb spectraComb.tofile(fp) - + # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba # nCode.tofile(fp) -# +# # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) # nBaud.tofile(fp) -# +# # code = self.code.reshape(self.nCode*self.nBaud) # code = code.astype(numpy.dtype(' maxHei): - raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) + raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % ( + minHei, maxHei) if (minHei < self.dataOut.heightList[0]): minHei = self.dataOut.heightList[0] @@ -320,20 +339,23 @@ class SpectraProc(ProcessingUnit): return 1 - def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): - newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) + def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): + newheis = numpy.where( + self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) if hei_ref != None: - newheis = numpy.where(self.dataOut.heightList>hei_ref) + newheis = numpy.where(self.dataOut.heightList > hei_ref) minIndex = min(newheis[0]) maxIndex = max(newheis[0]) - data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] - heightList = self.dataOut.heightList[minIndex:maxIndex+1] + data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] + heightList = self.dataOut.heightList[minIndex:maxIndex + 1] # determina indices - nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) - avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) + nheis = int(self.dataOut.radarControllerHeaderObj.txB / + (self.dataOut.heightList[1] - self.dataOut.heightList[0])) + avg_dB = 10 * \ + numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) beacon_dB = numpy.sort(avg_dB)[-nheis:] beacon_heiIndexList = [] for val in avg_dB.tolist(): @@ -343,12 +365,12 @@ class SpectraProc(ProcessingUnit): #data_spc = data_spc[:,:,beacon_heiIndexList] data_cspc = None if self.dataOut.data_cspc is not None: - data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] + data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] #data_cspc = data_cspc[:,:,beacon_heiIndexList] data_dc = None if self.dataOut.data_dc is not None: - data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] + data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] #data_dc = data_dc[:,beacon_heiIndexList] self.dataOut.data_spc = data_spc @@ -359,7 +381,6 @@ class SpectraProc(ProcessingUnit): return 1 - def selectHeightsByIndex(self, minIndex, maxIndex): """ Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango @@ -380,104 +401,107 @@ class SpectraProc(ProcessingUnit): """ if (minIndex < 0) or (minIndex > maxIndex): - raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) + raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % ( + minIndex, maxIndex) if (maxIndex >= self.dataOut.nHeights): - maxIndex = self.dataOut.nHeights-1 + maxIndex = self.dataOut.nHeights - 1 - #Spectra - data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] + # Spectra + data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] data_cspc = None if self.dataOut.data_cspc is not None: - data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] + data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] data_dc = None if self.dataOut.data_dc is not None: - data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] + data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] self.dataOut.data_spc = data_spc self.dataOut.data_cspc = data_cspc self.dataOut.data_dc = data_dc - self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] + self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] return 1 - def removeDC(self, mode = 2): + def removeDC(self, mode=2): jspectra = self.dataOut.data_spc jcspectra = self.dataOut.data_cspc - num_chan = jspectra.shape[0] num_hei = jspectra.shape[2] if jcspectra is not None: jcspectraExist = True num_pairs = jcspectra.shape[0] - else: jcspectraExist = False + else: + jcspectraExist = False - freq_dc = jspectra.shape[1]/2 - ind_vel = numpy.array([-2,-1,1,2]) + freq_dc + freq_dc = jspectra.shape[1] / 2 + ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc - if ind_vel[0]<0: - ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof + if ind_vel[0] < 0: + ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof if mode == 1: - jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION + jspectra[:, freq_dc, :] = ( + jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION if jcspectraExist: - jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 + jcspectra[:, freq_dc, :] = ( + jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 if mode == 2: - vel = numpy.array([-2,-1,1,2]) - xx = numpy.zeros([4,4]) + vel = numpy.array([-2, -1, 1, 2]) + xx = numpy.zeros([4, 4]) for fil in range(4): - xx[fil,:] = vel[fil]**numpy.asarray(range(4)) + xx[fil, :] = vel[fil]**numpy.asarray(range(4)) xx_inv = numpy.linalg.inv(xx) - xx_aux = xx_inv[0,:] + xx_aux = xx_inv[0, :] for ich in range(num_chan): - yy = jspectra[ich,ind_vel,:] - jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) + yy = jspectra[ich, ind_vel, :] + jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) - junkid = jspectra[ich,freq_dc,:]<=0 + junkid = jspectra[ich, freq_dc, :] <= 0 cjunkid = sum(junkid) if cjunkid.any(): - jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 + jspectra[ich, freq_dc, junkid.nonzero()] = ( + jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 if jcspectraExist: for ip in range(num_pairs): - yy = jcspectra[ip,ind_vel,:] - jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) - + yy = jcspectra[ip, ind_vel, :] + jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) self.dataOut.data_spc = jspectra self.dataOut.data_cspc = jcspectra return 1 - def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): + def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None): jspectra = self.dataOut.data_spc jcspectra = self.dataOut.data_cspc jnoise = self.dataOut.getNoise() num_incoh = self.dataOut.nIncohInt - num_channel = jspectra.shape[0] - num_prof = jspectra.shape[1] - num_hei = jspectra.shape[2] + num_channel = jspectra.shape[0] + num_prof = jspectra.shape[1] + num_hei = jspectra.shape[2] - #hei_interf + # hei_interf if hei_interf is None: - count_hei = num_hei/2 #Como es entero no importa + count_hei = num_hei / 2 # Como es entero no importa hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei hei_interf = numpy.asarray(hei_interf)[0] - #nhei_interf + # nhei_interf if (nhei_interf == None): nhei_interf = 5 if (nhei_interf < 1): @@ -492,136 +516,153 @@ class SpectraProc(ProcessingUnit): # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 mask_prof = numpy.asarray(range(num_prof)) num_mask_prof = mask_prof.size - comp_mask_prof = [0, num_prof/2] - + comp_mask_prof = [0, num_prof / 2] - #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal + # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): jnoise = numpy.nan noise_exist = jnoise[0] < numpy.Inf - #Subrutina de Remocion de la Interferencia + # Subrutina de Remocion de la Interferencia for ich in range(num_channel): - #Se ordena los espectros segun su potencia (menor a mayor) - power = jspectra[ich,mask_prof,:] - power = power[:,hei_interf] - power = power.sum(axis = 0) + # Se ordena los espectros segun su potencia (menor a mayor) + power = jspectra[ich, mask_prof, :] + power = power[:, hei_interf] + power = power.sum(axis=0) psort = power.ravel().argsort() - #Se estima la interferencia promedio en los Espectros de Potencia empleando - junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] + # Se estima la interferencia promedio en los Espectros de Potencia empleando + junkspc_interf = jspectra[ich, :, hei_interf[psort[range( + offhei_interf, nhei_interf + offhei_interf)]]] if noise_exist: - # tmp_noise = jnoise[ich] / num_prof + # tmp_noise = jnoise[ich] / num_prof tmp_noise = jnoise[ich] junkspc_interf = junkspc_interf - tmp_noise #junkspc_interf[:,comp_mask_prof] = 0 - jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf + jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf jspc_interf = jspc_interf.transpose() - #Calculando el espectro de interferencia promedio - noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) + # Calculando el espectro de interferencia promedio + noiseid = numpy.where( + jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) noiseid = noiseid[0] cnoiseid = noiseid.size - interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) + interfid = numpy.where( + jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) interfid = interfid[0] cinterfid = interfid.size - if (cnoiseid > 0): jspc_interf[noiseid] = 0 + if (cnoiseid > 0): + jspc_interf[noiseid] = 0 - #Expandiendo los perfiles a limpiar + # Expandiendo los perfiles a limpiar if (cinterfid > 0): - new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof + new_interfid = ( + numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof new_interfid = numpy.asarray(new_interfid) new_interfid = {x for x in new_interfid} new_interfid = numpy.array(list(new_interfid)) new_cinterfid = new_interfid.size - else: new_cinterfid = 0 + else: + new_cinterfid = 0 for ip in range(new_cinterfid): - ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() - jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] - + ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() + jspc_interf[new_interfid[ip] + ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]] - jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices + jspectra[ich, :, ind_hei] = jspectra[ich, :, + ind_hei] - jspc_interf # Corregir indices - #Removiendo la interferencia del punto de mayor interferencia + # Removiendo la interferencia del punto de mayor interferencia ListAux = jspc_interf[mask_prof].tolist() maxid = ListAux.index(max(ListAux)) - if cinterfid > 0: - for ip in range(cinterfid*(interf == 2) - 1): - ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() + for ip in range(cinterfid * (interf == 2) - 1): + ind = (jspectra[ich, interfid[ip], :] < tmp_noise * + (1 + 1 / numpy.sqrt(num_incoh))).nonzero() cind = len(ind) if (cind > 0): - jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) + jspectra[ich, interfid[ip], ind] = tmp_noise * \ + (1 + (numpy.random.uniform(cind) - 0.5) / + numpy.sqrt(num_incoh)) - ind = numpy.array([-2,-1,1,2]) - xx = numpy.zeros([4,4]) + ind = numpy.array([-2, -1, 1, 2]) + xx = numpy.zeros([4, 4]) for id1 in range(4): - xx[:,id1] = ind[id1]**numpy.asarray(range(4)) + xx[:, id1] = ind[id1]**numpy.asarray(range(4)) xx_inv = numpy.linalg.inv(xx) - xx = xx_inv[:,0] - ind = (ind + maxid + num_mask_prof)%num_mask_prof - yy = jspectra[ich,mask_prof[ind],:] - jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) - - - indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() - jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) - - #Remocion de Interferencia en el Cross Spectra - if jcspectra is None: return jspectra, jcspectra - num_pairs = jcspectra.size/(num_prof*num_hei) + xx = xx_inv[:, 0] + ind = (ind + maxid + num_mask_prof) % num_mask_prof + yy = jspectra[ich, mask_prof[ind], :] + jspectra[ich, mask_prof[maxid], :] = numpy.dot( + yy.transpose(), xx) + + indAux = (jspectra[ich, :, :] < tmp_noise * + (1 - 1 / numpy.sqrt(num_incoh))).nonzero() + jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ + (1 - 1 / numpy.sqrt(num_incoh)) + + # Remocion de Interferencia en el Cross Spectra + if jcspectra is None: + return jspectra, jcspectra + num_pairs = jcspectra.size / (num_prof * num_hei) jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) for ip in range(num_pairs): #------------------------------------------- - cspower = numpy.abs(jcspectra[ip,mask_prof,:]) - cspower = cspower[:,hei_interf] - cspower = cspower.sum(axis = 0) + cspower = numpy.abs(jcspectra[ip, mask_prof, :]) + cspower = cspower[:, hei_interf] + cspower = cspower.sum(axis=0) cspsort = cspower.ravel().argsort() - junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] + junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[range( + offhei_interf, nhei_interf + offhei_interf)]]] junkcspc_interf = junkcspc_interf.transpose() - jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf + jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() - median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) - median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) - junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) + median_real = numpy.median(numpy.real( + junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) + median_imag = numpy.median(numpy.imag( + junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) + junkcspc_interf[comp_mask_prof, :] = numpy.complex( + median_real, median_imag) for iprof in range(num_prof): - ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() - jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] + ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() + jcspc_interf[iprof] = junkcspc_interf[iprof, + ind[nhei_interf / 2]] - #Removiendo la Interferencia - jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf + # Removiendo la Interferencia + jcspectra[ip, :, ind_hei] = jcspectra[ip, + :, ind_hei] - jcspc_interf ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() maxid = ListAux.index(max(ListAux)) - ind = numpy.array([-2,-1,1,2]) - xx = numpy.zeros([4,4]) + ind = numpy.array([-2, -1, 1, 2]) + xx = numpy.zeros([4, 4]) for id1 in range(4): - xx[:,id1] = ind[id1]**numpy.asarray(range(4)) + xx[:, id1] = ind[id1]**numpy.asarray(range(4)) xx_inv = numpy.linalg.inv(xx) - xx = xx_inv[:,0] + xx = xx_inv[:, 0] - ind = (ind + maxid + num_mask_prof)%num_mask_prof - yy = jcspectra[ip,mask_prof[ind],:] - jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) + ind = (ind + maxid + num_mask_prof) % num_mask_prof + yy = jcspectra[ip, mask_prof[ind], :] + jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) - #Guardar Resultados + # Guardar Resultados self.dataOut.data_spc = jspectra self.dataOut.data_cspc = jcspectra @@ -635,7 +676,7 @@ class SpectraProc(ProcessingUnit): return 1 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): - #validacion de rango + # validacion de rango if minHei == None: minHei = self.dataOut.heightList[0] @@ -643,13 +684,13 @@ class SpectraProc(ProcessingUnit): 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]) + 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]) + 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] # validacion de velocidades @@ -662,13 +703,13 @@ class SpectraProc(ProcessingUnit): 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]) + 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]) + print 'maxVel: %.2f is out of the velocity range' % (maxVel) + print 'maxVel is setting to %.2f' % (velrange[-1]) maxVel = velrange[-1] # seleccion de indices para rango @@ -690,10 +731,11 @@ class SpectraProc(ProcessingUnit): maxIndex = len(heights) if (minIndex < 0) or (minIndex > maxIndex): - raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) + raise ValueError, "some value in (%d,%d) is not valid" % ( + minIndex, maxIndex) if (maxIndex >= self.dataOut.nHeights): - maxIndex = self.dataOut.nHeights-1 + maxIndex = self.dataOut.nHeights - 1 # seleccion de indices para velocidades indminvel = numpy.where(velrange >= minVel) @@ -708,24 +750,25 @@ class SpectraProc(ProcessingUnit): except: maxIndexVel = len(velrange) - #seleccion del espectro - data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] - #estimacion de ruido + # seleccion del espectro + data_spc = self.dataOut.data_spc[:, + minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] + # estimacion de ruido noise = numpy.zeros(self.dataOut.nChannels) for channel in range(self.dataOut.nChannels): - daux = data_spc[channel,:,:] + daux = data_spc[channel, :, :] noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) self.dataOut.noise_estimation = noise.copy() return 1 -class IncohInt(Operation): +class IncohInt(Operation): __profIndex = 0 - __withOverapping = False + __withOverapping = False __byTime = False __initime = None @@ -742,8 +785,6 @@ class IncohInt(Operation): n = None - - def __init__(self, **kwargs): Operation.__init__(self, **kwargs) @@ -778,12 +819,12 @@ class IncohInt(Operation): if n is not None: self.n = int(n) else: - self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line + # if (type(timeInterval)!=integer) -> change this line + self.__integrationtime = int(timeInterval) self.n = None self.__byTime = True def putData(self, data_spc, data_cspc, data_dc): - """ Add a profile to the __buffer_spc and increase in one the __profileIndex @@ -866,7 +907,8 @@ class IncohInt(Operation): self.__initime = datatime if self.__byTime: - avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) + avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( + datatime, *args) else: avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) @@ -876,7 +918,7 @@ class IncohInt(Operation): return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc def run(self, dataOut, n=None, timeInterval=None, overlapping=False): - if n==1: + if n == 1: return dataOut.flagNoData = True