diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 1040be4..ef2ff07 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -267,7 +267,7 @@ class JROData(GenericData): return fmax def getVmax(self): - + #print("frequency",self.frequency) _lambda = self.C / self.frequency vmax = self.getFmax() * _lambda / 2 diff --git a/schainpy/model/graphics/jroplot_voltage.py b/schainpy/model/graphics/jroplot_voltage.py index 2b2e922..f7684db 100644 --- a/schainpy/model/graphics/jroplot_voltage.py +++ b/schainpy/model/graphics/jroplot_voltage.py @@ -100,6 +100,7 @@ class Scope_(Figure): if ymin == None: ymin = numpy.nanmin(yreal) if ymax == None: ymax = numpy.nanmax(yreal) + self.isConfig = True self.setWinTitle(title) @@ -113,9 +114,10 @@ class Scope_(Figure): xlabel=xlabel, ylabel=ylabel, title=title) def plot_weatherpower(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): - y = y[channelIndexList,:] - yreal = y + #x = x[channelIndexList,:] + y = y[channelIndexList,:].real + y = 10*numpy.log10(y) title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) xlabel = "Range (Km)" ylabel = "Intensity" @@ -130,8 +132,9 @@ class Scope_(Figure): if xmin == None: xmin = numpy.nanmin(x) if xmax == None: xmax = numpy.nanmax(x) - if ymin == None: ymin = numpy.nanmin(yreal) - if ymax == None: ymax = numpy.nanmax(yreal) + if ymin == None: ymin = numpy.nanmin(y) + if ymax == None: ymax = numpy.nanmax(y) + #print (xmin,xmax) self.isConfig = True @@ -140,11 +143,48 @@ class Scope_(Figure): for i in range(len(self.axesList)): title = "Channel %d" %(i) axes = self.axesList[i] - ychannel = yreal[i,:] + #print(numpy.nanmax(x)) + ychannel = y[i,:] + #ychannel = yreal[i,:] axes.pline(x, ychannel, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title) + def plot_weathervelocity(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): + #print(channelIndexList) + x = x[channelIndexList,:] + + title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + xlabel = "Velocity (m/s)" + ylabel = "Range (Km)" + + if not self.isConfig: + nplots = len(channelIndexList) + + self.setup(id=id, + nplots=nplots, + wintitle='', + show=show) + + if xmin == None: xmin = numpy.nanmin(x) + if xmax == None: xmax = numpy.nanmax(x) + if ymin == None: ymin = numpy.nanmin(y) + if ymax == None: ymax = numpy.nanmax(y) + print (xmin,xmax) + + self.isConfig = True + + self.setWinTitle(title) + + for i in range(len(self.axesList)): + title = "Channel %d" %(i) + axes = self.axesList[i] + #print(numpy.nanmax(x)) + xchannel = x[i,:] + #ychannel = yreal[i,:] + axes.pline(xchannel, y, + xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, + xlabel=xlabel, ylabel=ylabel, title=title) def run(self, dataOut, id, wintitle="", channelList=None, @@ -206,7 +246,7 @@ class Scope_(Figure): id, channelIndexList, thisDatetime, - wintitle1, + wintitle, show, xmin, xmax, @@ -214,8 +254,8 @@ class Scope_(Figure): ymax) if type == "weathervelocity": - self.plot_weatherpower(dataOut.heightList, - dataOut.data_velocity[:,i,:], + self.plot_weathervelocity(dataOut.data_velocity[:,i,:], + dataOut.heightList, id, channelIndexList, thisDatetime, @@ -280,6 +320,31 @@ class Scope_(Figure): ymin, ymax) + if type== "weatherpower": + self.plot_weatherpower(dataOut.heightList, + dataOut.data, + id, + channelIndexList, + thisDatetime, + wintitle, + show, + xmin, + xmax, + ymin, + ymax) + if type== "weathervelocity": + self.plot_weathervelocity(dataOut.data_velocity, + dataOut.heightList, + id, + channelIndexList, + thisDatetime, + wintitle, + show, + xmin, + xmax, + ymin, + ymax) + self.draw() str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex) @@ -293,3 +358,224 @@ class Scope_(Figure): thisDatetime=thisDatetime) return dataOut + + + +@MPDecorator +class TimePlot_(Figure): + + __isConfig = None + __nsubplots = None + + WIDTHPROF = None + HEIGHTPROF = None + PREFIX = 'time' + + def __init__(self): + + Figure.__init__(self) + self.timerange = None + self.isConfig = False + self.__nsubplots = 1 + + self.WIDTH = 800 + self.HEIGHT = 250 + self.WIDTHPROF = 120 + self.HEIGHTPROF = 0 + self.counter_imagwr = 0 + + self.PLOT_CODE = RTIVOLT_CODE + + self.FTP_WEI = None + self.EXP_CODE = None + self.SUB_EXP_CODE = None + self.PLOT_POS = None + self.tmin = None + self.tmax = None + + self.xmin = None + self.xmax = None + + self.figfile = None + + def getSubplots(self): + + ncol = 1 + nrow = self.nplots + + return nrow, ncol + + def setup(self, id, nplots, wintitle, showprofile=True, show=True): + + self.__showprofile = showprofile + self.nplots = nplots + + ncolspan = 1 + colspan = 1 + if showprofile: + ncolspan = 7 + colspan = 6 + self.__nsubplots = 2 + + self.createFigure(id = id, + wintitle = wintitle, + widthplot = self.WIDTH + self.WIDTHPROF, + heightplot = self.HEIGHT + self.HEIGHTPROF, + show=show) + + nrow, ncol = self.getSubplots() + + counter = 0 + for y in range(nrow): + for x in range(ncol): + + if counter >= self.nplots: + break + + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) + + if showprofile: + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) + + counter += 1 + + def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', + xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,type="intensity", + timerange=None, colormap='jet', + save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, + server=None, folder=None, username=None, password=None, + ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): + + """ + + Input: + dataOut : + id : + wintitle : + channelList : + showProfile : + xmin : None, + xmax : None, + ymin : None, + ymax : None, + zmin : None, + zmax : None + """ + print("estoy aqui :D") + if dataOut.flagNoData: + return dataOut + + #colormap = kwargs.get('colormap', 'jet') + if HEIGHT is not None: + self.HEIGHT = HEIGHT + + if not isTimeInHourRange(dataOut.datatime, xmin, xmax): + return + + if channelList == None: + channelIndexList = dataOut.channelIndexList + else: + channelIndexList = [] + for channel in channelList: + if channel not in dataOut.channelList: + raise ValueError("Channel %d is not in dataOut.channelList") + channelIndexList.append(dataOut.channelList.index(channel)) + + if normFactor is None: + factor = dataOut.normFactor + else: + factor = normFactor + + #factor = dataOut.normFactor + x = dataOut.getTimeRange() + y = dataOut.getHeiRange() + if type=="intensity": + z = dataOut.data_intensity/factor + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) + avgdB = numpy.average(z, axis=1) + avgdB = 10.*numpy.log10(avg) + else: + z= dataOut.data_velocity + avgdB = numpy.average(z, axis=1) + + # avgdB = dataOut.getPower() + + + thisDatetime = dataOut.datatime + #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) + title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) + xlabel = "" + ylabel = "Range (Km)" + + update_figfile = False + + if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong + self.counter_imagwr = wr_period + self.isConfig = False + update_figfile = True + + if not self.isConfig: + + nplots = len(channelIndexList) + + self.setup(id=id, + nplots=nplots, + wintitle=wintitle, + showprofile=showprofile, + show=show) + + if timerange != None: + self.timerange = timerange + + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) + + noise = dataOut.noise/factor + noisedB = 10*numpy.log10(noise) + + if ymin == None: ymin = numpy.nanmin(y) + if ymax == None: ymax = numpy.nanmax(y) + if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 + if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 + + self.FTP_WEI = ftp_wei + self.EXP_CODE = exp_code + self.SUB_EXP_CODE = sub_exp_code + self.PLOT_POS = plot_pos + + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.isConfig = True + self.figfile = figfile + update_figfile = True + + self.setWinTitle(title) + + for i in range(self.nplots): + index = channelIndexList[i] + title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) + if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): + title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) + axes = self.axesList[i*self.__nsubplots] + zdB = avgdB[index].reshape((1,-1)) + axes.pcolorbuffer(x, y, zdB, + xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, + xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, + ticksize=9, cblabel='', cbsize="1%", colormap=colormap) + + if self.__showprofile: + axes = self.axesList[i*self.__nsubplots +1] + axes.pline(avgdB[index], y, + xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, + xlabel='dB', ylabel='', title='', + ytick_visible=False, + grid='x') + + self.draw() + + self.save(figpath=figpath, + figfile=figfile, + save=save, + ftp=ftp, + wr_period=wr_period, + thisDatetime=thisDatetime, + update_figfile=update_figfile) + return dataOut diff --git a/schainpy/model/graphics/plotting_codes.py b/schainpy/model/graphics/plotting_codes.py index 52bd98d..370dcfd 100644 --- a/schainpy/model/graphics/plotting_codes.py +++ b/schainpy/model/graphics/plotting_codes.py @@ -28,3 +28,4 @@ SPECFIT_CODE = 27 EWDRIFT_CODE = 28 WPO_CODE = 29 #Weather Intensity - Power +RTIVOLT_CODE = 30 diff --git a/schainpy/model/io/jroIO_simulator.py b/schainpy/model/io/jroIO_simulator.py index d4c7b56..3ae4b2a 100644 --- a/schainpy/model/io/jroIO_simulator.py +++ b/schainpy/model/io/jroIO_simulator.py @@ -43,6 +43,8 @@ class SimulatorReader(JRODataReader, ProcessingUnit): prof_gen = None Fdoppler = 100 Hdoppler = 36 + Adoppler = 300 + frequency = 9345 def __init__(self): """ Inicializador de la clases SimulatorReader para @@ -89,7 +91,8 @@ class SimulatorReader(JRODataReader, ProcessingUnit): """Set the next file to be readed open it and parse de file header""" if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): - print('------------------- [Opening file] ------------------------------') + self.nReadFiles=self.nReadFiles+1 + print('------------------- [Opening file] ------------------------------',self.nReadFiles) self.nReadBlocks = 0 def __setNewBlock(self): @@ -126,6 +129,8 @@ class SimulatorReader(JRODataReader, ProcessingUnit): # asumo q la data no esta sin flip self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft + # + self.dataOut.frequency = self.frequency def getBasicHeader(self): @@ -265,14 +270,18 @@ class SimulatorReader(JRODataReader, ProcessingUnit): self.systemHeaderObj.adcResolution = adcResolution self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth - def setup(self,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000, + def setup(self,frequency=49.92e6,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000, FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32, - FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 500, - stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200,channels=1,Fdoppler=20,Hdoppler=36, + FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 50, + stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200, + channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500, **kwargs): self.set_kwargs(**kwargs) self.nReadBlocks = 0 + self.nReadFiles = 1 + print('------------------- [Opening file: ] ------------------------------',self.nReadFiles) + tmp = time.time() tmp_utc = int(tmp) tmp_milisecond = int((tmp-tmp_utc)*1000) @@ -301,6 +310,8 @@ class SimulatorReader(JRODataReader, ProcessingUnit): self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels) + + self.frequency = frequency self.incIntFactor = incIntFactor self.nFFTPoints = nFFTPoints self.FixPP_IncInt = FixPP_IncInt @@ -326,6 +337,7 @@ class SimulatorReader(JRODataReader, ProcessingUnit): self.Baudwidth = None self.Fdoppler = Fdoppler self.Hdoppler = Hdoppler + self.Adoppler = Adoppler print("IPP ", self.FixRCP_IPP) print("Tau_0 ",self.Tau_0) @@ -337,6 +349,7 @@ class SimulatorReader(JRODataReader, ProcessingUnit): print("Dyn_snCode",Dyn_snCode) print("Fdoppler", Fdoppler) print("Hdoppler",Hdoppler) + print("Vdopplermax",Fdoppler*(3.0e8/self.frequency)/2.0) self.init_acquisition() self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode) @@ -423,7 +436,8 @@ class SimulatorReader(JRODataReader, ProcessingUnit): def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev, Reference= Reference,pulses= pulses, Num_Codes= Num_Codes,pulse_size=pulse_size, - prof_gen= prof_gen,H0 = H0,DH0=DH0,Fdoppler= Fdoppler,Hdoppler=Hdoppler): + prof_gen= prof_gen,H0 = H0,DH0=DH0, + Adoppler=Adoppler,Fdoppler= Fdoppler,Hdoppler=Hdoppler): Samples = Samples DC_level = DC_level stdev = stdev @@ -438,6 +452,7 @@ class SimulatorReader(JRODataReader, ProcessingUnit): ippSec = self.radarControllerHeaderObj.ippSeconds Fdoppler = self.Fdoppler Hdoppler = self.Hdoppler + Adoppler = self.Adoppler self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64) for i in range(channels): @@ -455,7 +470,7 @@ class SimulatorReader(JRODataReader, ProcessingUnit): #····················· PULSES+NOISE·········· InBuffer = numpy.zeros(Samples,dtype=complex) InBuffer[m_nR:m_nR+ps] = Pulso - InBuffer = Noise+ InBuffer + InBuffer = InBuffer+Noise #····················· ANGLE ······························· InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5) InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5) @@ -465,12 +480,13 @@ class SimulatorReader(JRODataReader, ProcessingUnit): #wave_fft(x=InBuffer,plot_show=True) #time.sleep(1) #················DOPPLER SIGNAL............................................... - time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen + time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen+(self.nReadFiles-1)*ippSec*prof_gen fd = Fdoppler #+(600.0/120)*self.nReadBlocks - d_signal = 650*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64) + d_signal = Adoppler*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64) #·················· DATABLOCK + DOPPLER············........................... HD=int(Hdoppler/self.AcqDH_0) - self.datablock[0,:,HD]=self.datablock[0,:,HD]+ d_signal # RESULT + for i in range(12): + self.datablock[:,:,HD+i]=self.datablock[:,:,HD+i]+ d_signal # RESULT ''' a= numpy.zeros(10) for i in range(10): diff --git a/schainpy/model/proc/jroproc_spectra.py b/schainpy/model/proc/jroproc_spectra.py index 60b8215..92b4379 100644 --- a/schainpy/model/proc/jroproc_spectra.py +++ b/schainpy/model/proc/jroproc_spectra.py @@ -98,7 +98,7 @@ class SpectraProc(ProcessingUnit): #print("spc :",spc.shape) data_wr = None if self.dataOut.flagWR: - data_wr = fft_volt + data_wr = self.buffer blocksize = fft_volt.size cspc = None diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 0d769b6..7f02345 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -1,5 +1,6 @@ import sys -import numpy +import time +import numpy,math from scipy import interpolate from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator from schainpy.model.data.jrodata import Voltage @@ -384,16 +385,16 @@ class CohInt(Operation): """ if not self.__withOverlapping: - print("inside over") + #print("inside over") self.__buffer += data.copy() self.__profIndex += 1 return #Overlapping data nChannels, nHeis = data.shape - print("show me the light",data.shape) + #print("show me the light",data.shape) data = numpy.reshape(data, (1, nChannels, nHeis)) - print(data.shape) + #print(data.shape) #If the buffer is empty then it takes the data value if self.__buffer is None: self.__buffer = data @@ -424,7 +425,7 @@ class CohInt(Operation): """ if not self.__withOverlapping: - #print("ahora que fue") + print("ahora que fue") data = self.__buffer n = self.__profIndex @@ -1233,8 +1234,8 @@ class CreateBlockVoltage(Operation): #print("new numberSamples",numberSamples) self.bufferShape = shape[0], numberProfile, numberSamples # nchannels,nprofiles,nsamples - self.buffer = numpy.zeros((self.bufferShape)) - self.bufferVel = numpy.zeros((self.bufferShape)) + self.buffer = numpy.zeros([shape[0], numberProfile, numberSamples]) + self.bufferVel = numpy.zeros([shape[0], numberProfile, numberSamples]) def run(self, dataOut, m=None): #print("RUN") @@ -1248,6 +1249,7 @@ class CreateBlockVoltage(Operation): if self.__Index < m: #print("PROFINDEX BLOCK CBV",self.__Index) self.buffer[:,self.__Index,:] = dataOut.data + #corregir porque debe tener un perfil menos ojo self.bufferVel[:,self.__Index,:] = dataOut.data_velocity self.__Index += 1 dataOut.flagNoData = True @@ -1302,11 +1304,14 @@ class PulsePairVoltage(Operation): n = None __nch = 0 __nHeis = 0 + removeDC = False + ipp = None + lambda_ = 0 def __init__(self,**kwargs): Operation.__init__(self,**kwargs) - def setup(self, dataOut, n = None ): + def setup(self, dataOut, n = None, removeDC=False): ''' n= Numero de PRF's de entrada ''' @@ -1320,6 +1325,10 @@ class PulsePairVoltage(Operation): self.__nch = dataOut.nChannels self.__nHeis = dataOut.nHeights + self.removeDC = removeDC + self.lambda_ = 3.0e8/(9345.0e6) + self.ippSec = dataOut.ippSeconds + print("IPPseconds",dataOut.ippSeconds) print("ELVALOR DE n es:", n) if n == None: @@ -1331,115 +1340,55 @@ class PulsePairVoltage(Operation): self.n = n self.__nProf = n - ''' - if overlapping: - self.__withOverlapping = True - self.__buffer = None - else: - #print ("estoy sin __withO") - self.__withOverlapping = False - self.__buffer = 0 - self.__buffer2 = [] - self.__buffer3 = 0 - ''' + self.__buffer = numpy.zeros((dataOut.nChannels, + n, + dataOut.nHeights), + dtype='complex') + + def putData(self,data): ''' Add a profile to he __buffer and increase in one the __profiel Index ''' - #print("self.__profIndex :",self.__profIndex) - self.__buffer += data*numpy.conjugate(data) - self.__buffer2.append(numpy.conjugate(data)) - if self.__profIndex > 0: - self.__buffer3 += self.__buffer2[self.__profIndex-1]*data + self.__buffer[:,self.__profIndex,:]= data self.__profIndex += 1 return - ''' - if not self.__withOverlapping: - #print("Putdata inside over") - self.__buffer += data* numpy.conjugate(data) - self.__buffer2.append(numpy.conjugate(data)) - - if self.__profIndex >0: - self.__buffer3 += self.__buffer2[self.__profIndex-1]*data - self.__profIndex += 1 - return - - if self.__buffer is None: - #print("aqui bro") - self.__buffer = data* numpy.conjugate(data) - self.__buffer2.append(numpy.conjugate(data)) - self.__profIndex += 1 - - return - - if self.__profIndex < self.n: - self.__buffer = numpy.vstack(self.__buffer,data* numpy.conjugate(data)) - self.__buffer2.append(numpy.conjugate(data)) - - if self.__profIndex == 1: - self.__buffer3 = self.__buffer2[self.__profIndex -1] * data - else: - self.__buffer3 = numpy.vstack(self.__buffer3, self.__buffer2[self.profIndex-1]*data) - - self.__profIndex += 1 - return - ''' def pushData(self): ''' Return the PULSEPAIR and the profiles used in the operation Affected : self.__profileIndex ''' - #print("************************************************") - #print("push data int vel n") - data_intensity = self.__buffer/self.n - data_velocity = self.__buffer3/(self.n-1) + + if self.removeDC==True: + mean = numpy.mean(self.__buffer,1) + tmp = mean.reshape(self.__nch,1,self.__nHeis) + dc= numpy.tile(tmp,[1,self.__nProf,1]) + self.__buffer = self.__buffer - dc + + data_intensity = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1)/self.n + pair1 = self.__buffer[:,1:,:]*numpy.conjugate(self.__buffer[:,:-1,:]) + angle=numpy.angle(numpy.sum(pair1,1))*180/(math.pi) + #print(angle.shape)#print("__ANGLE__") #print("angle",angle[:,:10]) + data_velocity = (self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(numpy.sum(pair1,1)) n = self.__profIndex - self.__buffer = 0 - self.__buffer2 = [] - self.__buffer3 = 0 + self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') self.__profIndex = 0 - - return data_intensity, data_velocity,n - ''' - if not self.__withOverlapping: - #print("ahora que fue") - data_intensity = self.__buffer/self.n - data_velocity = self.__buffer3/(self.n-1) - n = self.__profIndex - - self.__buffer = 0 - self.__buffer2 = [] - self.__buffer3 = 0 - self.__profIndex = 0 - return data_intensity, data_velocity,n - - data_intensity = numpy.sum(self.__buffer,axis = 0) - data_velocity = numpy.sum(self.__buffer3,axis = 0) - n = self.__profIndex - #self.__buffer = 0 - #self.__buffer2 = [] - #self.__buffer3 = 0 - #self.__profIndex = 0 - return data_intensity, data_velocity,n - ''' + return data_intensity,data_velocity,n def pulsePairbyProfiles(self,data): self.__dataReady = False data_intensity = None data_velocity = None - #print("beforeputada") self.putData(data) - #print("ProfileIndex:",self.__profIndex) if self.__profIndex == self.n: data_intensity, data_velocity, n = self.pushData() self.__dataReady = True - #print("-----------------------------------------------") - #print("data_intensity",data_intensity.shape,"data_velocity",data_velocity.shape) + return data_intensity, data_velocity def pulsePairOp(self, data, datatime= None): @@ -1456,18 +1405,13 @@ class PulsePairVoltage(Operation): avgdatatime = self.__initime deltatime = datatime - self.__lastdatatime self.__initime = datatime - ''' - if not self.__withOverlapping: - self.__initime = datatime - else: - self.__initime += deltatime - ''' + return data_intensity, data_velocity, avgdatatime - def run(self, dataOut,n = None, overlapping= False,**kwargs): + def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): if not self.isConfig: - self.setup(dataOut = dataOut, n = n , **kwargs) + self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) self.isConfig = True #print("*******************") #print("print Shape input data:",dataOut.data.shape) @@ -1485,139 +1429,3 @@ class PulsePairVoltage(Operation): dataOut.utctime = avgdatatime dataOut.flagNoData = False return dataOut - -# import collections -# from scipy.stats import mode -# -# class Synchronize(Operation): -# -# isConfig = False -# __profIndex = 0 -# -# def __init__(self, **kwargs): -# -# Operation.__init__(self, **kwargs) -# # self.isConfig = False -# self.__powBuffer = None -# self.__startIndex = 0 -# self.__pulseFound = False -# -# def __findTxPulse(self, dataOut, channel=0, pulse_with = None): -# -# #Read data -# -# powerdB = dataOut.getPower(channel = channel) -# noisedB = dataOut.getNoise(channel = channel)[0] -# -# self.__powBuffer.extend(powerdB.flatten()) -# -# dataArray = numpy.array(self.__powBuffer) -# -# filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") -# -# maxValue = numpy.nanmax(filteredPower) -# -# if maxValue < noisedB + 10: -# #No se encuentra ningun pulso de transmision -# return None -# -# maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] -# -# if len(maxValuesIndex) < 2: -# #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX -# return None -# -# phasedMaxValuesIndex = maxValuesIndex - self.__nSamples -# -# #Seleccionar solo valores con un espaciamiento de nSamples -# pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) -# -# if len(pulseIndex) < 2: -# #Solo se encontro un pulso de transmision con ancho mayor a 1 -# return None -# -# spacing = pulseIndex[1:] - pulseIndex[:-1] -# -# #remover senales que se distancien menos de 10 unidades o muestras -# #(No deberian existir IPP menor a 10 unidades) -# -# realIndex = numpy.where(spacing > 10 )[0] -# -# if len(realIndex) < 2: -# #Solo se encontro un pulso de transmision con ancho mayor a 1 -# return None -# -# #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) -# realPulseIndex = pulseIndex[realIndex] -# -# period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] -# -# print "IPP = %d samples" %period -# -# self.__newNSamples = dataOut.nHeights #int(period) -# self.__startIndex = int(realPulseIndex[0]) -# -# return 1 -# -# -# def setup(self, nSamples, nChannels, buffer_size = 4): -# -# self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), -# maxlen = buffer_size*nSamples) -# -# bufferList = [] -# -# for i in range(nChannels): -# bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, -# maxlen = buffer_size*nSamples) -# -# bufferList.append(bufferByChannel) -# -# self.__nSamples = nSamples -# self.__nChannels = nChannels -# self.__bufferList = bufferList -# -# def run(self, dataOut, channel = 0): -# -# if not self.isConfig: -# nSamples = dataOut.nHeights -# nChannels = dataOut.nChannels -# self.setup(nSamples, nChannels) -# self.isConfig = True -# -# #Append new data to internal buffer -# for thisChannel in range(self.__nChannels): -# bufferByChannel = self.__bufferList[thisChannel] -# bufferByChannel.extend(dataOut.data[thisChannel]) -# -# if self.__pulseFound: -# self.__startIndex -= self.__nSamples -# -# #Finding Tx Pulse -# if not self.__pulseFound: -# indexFound = self.__findTxPulse(dataOut, channel) -# -# if indexFound == None: -# dataOut.flagNoData = True -# return -# -# self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) -# self.__pulseFound = True -# self.__startIndex = indexFound -# -# #If pulse was found ... -# for thisChannel in range(self.__nChannels): -# bufferByChannel = self.__bufferList[thisChannel] -# #print self.__startIndex -# x = numpy.array(bufferByChannel) -# self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] -# -# deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] -# dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight -# # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 -# -# dataOut.data = self.__arrayBuffer -# -# self.__startIndex += self.__newNSamples -# -# return