@@ -0,0 +1,473 | |||||
|
1 | import numpy,math,random,time | |||
|
2 | #---------------1 Heredamos JRODatareader | |||
|
3 | from schainpy.model.io.jroIO_base import * | |||
|
4 | #---------------2 Heredamos las propiedades de ProcessingUnit | |||
|
5 | from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator | |||
|
6 | #---------------3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader | |||
|
7 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader | |||
|
8 | #---------------4 Importaremos el objeto Voltge | |||
|
9 | from schainpy.model.data.jrodata import Voltage | |||
|
10 | ||||
|
11 | class SimulatorReader(JRODataReader, ProcessingUnit): | |||
|
12 | incIntFactor = 1 | |||
|
13 | nFFTPoints = 0 | |||
|
14 | FixPP_IncInt = 1 | |||
|
15 | FixRCP_IPP = 1000 | |||
|
16 | FixPP_CohInt = 1 | |||
|
17 | Tau_0 = 250 | |||
|
18 | AcqH0_0 = 70 | |||
|
19 | H0 = AcqH0_0 | |||
|
20 | AcqDH_0 = 1.25 | |||
|
21 | DH0 = AcqDH_0 | |||
|
22 | Bauds = 32 | |||
|
23 | BaudWidth = None | |||
|
24 | FixRCP_TXA = 40 | |||
|
25 | FixRCP_TXB = 70 | |||
|
26 | fAngle = 2.0*math.pi*(1/16) | |||
|
27 | DC_level = 500 | |||
|
28 | stdev = 8 | |||
|
29 | Num_Codes = 2 | |||
|
30 | #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) | |||
|
31 | #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) | |||
|
32 | #Dyn_snCode = numpy.array([Num_Codes,Bauds]) | |||
|
33 | Dyn_snCode = None | |||
|
34 | Samples = 200 | |||
|
35 | channels = 5 | |||
|
36 | pulses = None | |||
|
37 | Reference = None | |||
|
38 | pulse_size = None | |||
|
39 | prof_gen = None | |||
|
40 | Fdoppler = 100 | |||
|
41 | Hdoppler = 36 | |||
|
42 | Adoppler = 300 | |||
|
43 | frequency = 9345 | |||
|
44 | nTotalReadFiles = 1000 | |||
|
45 | ||||
|
46 | def __init__(self): | |||
|
47 | """ | |||
|
48 | Inicializador de la clases SimulatorReader para | |||
|
49 | generar datos de voltage simulados. | |||
|
50 | Input: | |||
|
51 | dataOut: Objeto de la clase Voltage. | |||
|
52 | Este Objeto sera utilizado apra almacenar | |||
|
53 | un perfil de datos cada vez qe se haga | |||
|
54 | un requerimiento (getData) | |||
|
55 | """ | |||
|
56 | ProcessingUnit.__init__(self) | |||
|
57 | print(" [ START ] init - Metodo Simulator Reader") | |||
|
58 | ||||
|
59 | self.isConfig = False | |||
|
60 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |||
|
61 | self.systemHeaderObj = SystemHeader() | |||
|
62 | self.radarControllerHeaderObj = RadarControllerHeader() | |||
|
63 | self.processingHeaderObj = ProcessingHeader() | |||
|
64 | self.profileIndex = 2**32-1 | |||
|
65 | self.dataOut = Voltage() | |||
|
66 | #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) | |||
|
67 | code0 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1]) | |||
|
68 | #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) | |||
|
69 | code1 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1]) | |||
|
70 | #self.Dyn_snCode = numpy.array([code0,code1]) | |||
|
71 | self.Dyn_snCode = None | |||
|
72 | ||||
|
73 | def set_kwargs(self, **kwargs): | |||
|
74 | for key, value in kwargs.items(): | |||
|
75 | setattr(self, key, value) | |||
|
76 | ||||
|
77 | def __hasNotDataInBuffer(self): | |||
|
78 | ||||
|
79 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs: | |||
|
80 | if self.nReadBlocks>0: | |||
|
81 | tmp = self.dataOut.utctime | |||
|
82 | tmp_utc = int(self.dataOut.utctime) | |||
|
83 | tmp_milisecond = int((tmp-tmp_utc)*1000) | |||
|
84 | self.basicHeaderObj.utc = tmp_utc | |||
|
85 | self.basicHeaderObj.miliSecond= tmp_milisecond | |||
|
86 | return 1 | |||
|
87 | return 0 | |||
|
88 | ||||
|
89 | def setNextFile(self): | |||
|
90 | """Set the next file to be readed open it and parse de file header""" | |||
|
91 | ||||
|
92 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |||
|
93 | self.nReadFiles=self.nReadFiles+1 | |||
|
94 | if self.nReadFiles ==self.nTotalReadFiles: | |||
|
95 | self.flagNoMoreFiles=1 | |||
|
96 | raise schainpy.admin.SchainWarning('No more files to read') | |||
|
97 | ||||
|
98 | print('------------------- [Opening file] ------------------------------',self.nReadFiles) | |||
|
99 | self.nReadBlocks = 0 | |||
|
100 | ||||
|
101 | def __setNewBlock(self): | |||
|
102 | self.setNextFile() | |||
|
103 | if self.flagIsNewFile: | |||
|
104 | return 1 | |||
|
105 | ||||
|
106 | def readNextBlock(self): | |||
|
107 | while True: | |||
|
108 | self.__setNewBlock() | |||
|
109 | if not(self.readBlock()): | |||
|
110 | return 0 | |||
|
111 | self.getBasicHeader() | |||
|
112 | break | |||
|
113 | if self.verbose: | |||
|
114 | print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, | |||
|
115 | self.processingHeaderObj.dataBlocksPerFile, | |||
|
116 | self.dataOut.datatime.ctime()) ) | |||
|
117 | return 1 | |||
|
118 | ||||
|
119 | def getFirstHeader(self): | |||
|
120 | self.getBasicHeader() | |||
|
121 | self.dataOut.processingHeaderObj = self.processingHeaderObj.copy() | |||
|
122 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |||
|
123 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |||
|
124 | ||||
|
125 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |||
|
126 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |||
|
127 | self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels)) | |||
|
128 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |||
|
129 | # asumo q la data no esta decodificada | |||
|
130 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode | |||
|
131 | # asumo q la data no esta sin flip | |||
|
132 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip | |||
|
133 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |||
|
134 | self.dataOut.frequency = self.frequency | |||
|
135 | ||||
|
136 | def getBasicHeader(self): | |||
|
137 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ | |||
|
138 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |||
|
139 | ||||
|
140 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |||
|
141 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |||
|
142 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |||
|
143 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |||
|
144 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |||
|
145 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |||
|
146 | ||||
|
147 | def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0, | |||
|
148 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, | |||
|
149 | numTaus=0, line6Function=0, line5Function=0, fClock=None, | |||
|
150 | prePulseBefore=0, prePulseAfter=0, | |||
|
151 | codeType=0, nCode=0, nBaud=0, code=None, | |||
|
152 | flip1=0, flip2=0): | |||
|
153 | self.radarControllerHeaderObj.expType = expType | |||
|
154 | self.radarControllerHeaderObj.nTx = nTx | |||
|
155 | self.radarControllerHeaderObj.ipp = float(ipp) | |||
|
156 | self.radarControllerHeaderObj.txA = float(txA) | |||
|
157 | self.radarControllerHeaderObj.txB = float(txB) | |||
|
158 | self.radarControllerHeaderObj.rangeIPP = ipp | |||
|
159 | self.radarControllerHeaderObj.rangeTxA = txA | |||
|
160 | self.radarControllerHeaderObj.rangeTxB = txB | |||
|
161 | ||||
|
162 | self.radarControllerHeaderObj.nHeights = int(nHeights) | |||
|
163 | self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight]) | |||
|
164 | self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight]) | |||
|
165 | self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights]) | |||
|
166 | ||||
|
167 | ||||
|
168 | self.radarControllerHeaderObj.nWindows = nWindows | |||
|
169 | self.radarControllerHeaderObj.numTaus = numTaus | |||
|
170 | self.radarControllerHeaderObj.codeType = codeType | |||
|
171 | self.radarControllerHeaderObj.line6Function = line6Function | |||
|
172 | self.radarControllerHeaderObj.line5Function = line5Function | |||
|
173 | self.radarControllerHeaderObj.fclock = fClock | |||
|
174 | self.radarControllerHeaderObj.prePulseBefore= prePulseBefore | |||
|
175 | self.radarControllerHeaderObj.prePulseAfter = prePulseAfter | |||
|
176 | ||||
|
177 | self.radarControllerHeaderObj.nCode = nCode | |||
|
178 | self.radarControllerHeaderObj.nBaud = nBaud | |||
|
179 | self.radarControllerHeaderObj.code = code | |||
|
180 | self.radarControllerHeaderObj.flip1 = flip1 | |||
|
181 | self.radarControllerHeaderObj.flip2 = flip2 | |||
|
182 | ||||
|
183 | self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4 | |||
|
184 | ||||
|
185 | if fClock is None and deltaHeight is not None: | |||
|
186 | self.fClock = 0.15 / (deltaHeight * 1e-6) | |||
|
187 | ||||
|
188 | def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0, | |||
|
189 | dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, | |||
|
190 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, | |||
|
191 | deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, | |||
|
192 | code=0, nBaud=None, shif_fft=False, flag_dc=False, | |||
|
193 | flag_cspc=False, flag_decode=False, flag_deflip=False): | |||
|
194 | ||||
|
195 | self.processingHeaderObj.profilesPerBlock = profilesPerBlock | |||
|
196 | self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile | |||
|
197 | self.processingHeaderObj.nWindows = nWindows | |||
|
198 | self.processingHeaderObj.nCohInt = nCohInt | |||
|
199 | self.processingHeaderObj.nIncohInt = nIncohInt | |||
|
200 | self.processingHeaderObj.totalSpectra = totalSpectra | |||
|
201 | self.processingHeaderObj.nHeights = int(nHeights) | |||
|
202 | self.processingHeaderObj.firstHeight = firstHeight | |||
|
203 | self.processingHeaderObj.deltaHeight = deltaHeight | |||
|
204 | self.processingHeaderObj.samplesWin = nHeights | |||
|
205 | ||||
|
206 | def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0): | |||
|
207 | self.basicHeaderObj.utc = utc | |||
|
208 | self.basicHeaderObj.miliSecond = miliSecond | |||
|
209 | self.basicHeaderObj.timeZone = timeZone | |||
|
210 | ||||
|
211 | def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): | |||
|
212 | self.systemHeaderObj.nSamples = nSamples | |||
|
213 | self.systemHeaderObj.nProfiles = nProfiles | |||
|
214 | self.systemHeaderObj.nChannels = nChannels | |||
|
215 | self.systemHeaderObj.adcResolution = adcResolution | |||
|
216 | self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth | |||
|
217 | ||||
|
218 | def init_acquisition(self): | |||
|
219 | ||||
|
220 | if self.nFFTPoints != 0: | |||
|
221 | self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints | |||
|
222 | if (self.FixPP_IncInt > self.incIntFactor): | |||
|
223 | self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor | |||
|
224 | elif(self.FixPP_IncInt< self.incIntFactor): | |||
|
225 | print("False alert...") | |||
|
226 | ||||
|
227 | ProfilesperBlock = self.processingHeaderObj.profilesPerBlock | |||
|
228 | ||||
|
229 | self.timeperblock =int(((self.FixRCP_IPP | |||
|
230 | *ProfilesperBlock | |||
|
231 | *self.FixPP_CohInt | |||
|
232 | *self.incIntFactor) | |||
|
233 | /150.0) | |||
|
234 | *0.9 | |||
|
235 | +0.5) | |||
|
236 | # para cada canal | |||
|
237 | self.profiles = ProfilesperBlock*self.FixPP_CohInt | |||
|
238 | self.profiles = ProfilesperBlock | |||
|
239 | self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5) | |||
|
240 | self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 ) | |||
|
241 | ||||
|
242 | if (self.BaudWidth==0): | |||
|
243 | self.BaudWidth=1 | |||
|
244 | ||||
|
245 | def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode): | |||
|
246 | ||||
|
247 | Num_Codes = Num_Codes | |||
|
248 | Bauds = Bauds | |||
|
249 | BaudWidth = BaudWidth | |||
|
250 | Dyn_snCode = Dyn_snCode | |||
|
251 | ||||
|
252 | if Dyn_snCode: | |||
|
253 | print("EXISTE") | |||
|
254 | else: | |||
|
255 | print("No existe") | |||
|
256 | ||||
|
257 | if Dyn_snCode: # if Bauds: | |||
|
258 | pulses = list(range(0,Num_Codes)) | |||
|
259 | num_codes = Num_Codes | |||
|
260 | for i in range(num_codes): | |||
|
261 | pulse_size = Bauds*BaudWidth | |||
|
262 | pulses[i] = numpy.zeros(pulse_size) | |||
|
263 | for j in range(Bauds): | |||
|
264 | for k in range(BaudWidth): | |||
|
265 | pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600) | |||
|
266 | else: | |||
|
267 | print("sin code") | |||
|
268 | pulses = list(range(1)) | |||
|
269 | if self.AcqDH_0>0.149: | |||
|
270 | pulse_size = int(self.FixRCP_TXB/0.15+0.5) | |||
|
271 | else: | |||
|
272 | pulse_size = int((self.FixRCP_TXB/self.AcqDH_0)+0.5) #0.0375 | |||
|
273 | pulses[0] = numpy.ones(pulse_size) | |||
|
274 | pulses = 600*pulses[0] | |||
|
275 | ||||
|
276 | return pulses,pulse_size | |||
|
277 | ||||
|
278 | def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev, | |||
|
279 | Reference= Reference,pulses= pulses, | |||
|
280 | Num_Codes= Num_Codes,pulse_size=pulse_size, | |||
|
281 | prof_gen= prof_gen,H0 = H0,DH0=DH0, | |||
|
282 | Adoppler=Adoppler,Fdoppler= Fdoppler,Hdoppler=Hdoppler): | |||
|
283 | Samples = Samples | |||
|
284 | DC_level = DC_level | |||
|
285 | stdev = stdev | |||
|
286 | m_nR = Reference | |||
|
287 | pulses = pulses | |||
|
288 | num_codes = Num_Codes | |||
|
289 | ps = pulse_size | |||
|
290 | prof_gen = prof_gen | |||
|
291 | channels = self.channels | |||
|
292 | H0 = H0 | |||
|
293 | DH0 = DH0 | |||
|
294 | ippSec = self.radarControllerHeaderObj.ippSeconds | |||
|
295 | Fdoppler = self.Fdoppler | |||
|
296 | Hdoppler = self.Hdoppler | |||
|
297 | Adoppler = self.Adoppler | |||
|
298 | ||||
|
299 | self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64) | |||
|
300 | for i in range(channels): | |||
|
301 | for k in range(prof_gen): | |||
|
302 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |||
|
303 | Noise_r = numpy.random.normal(DC_level,stdev,Samples) | |||
|
304 | Noise_i = numpy.random.normal(DC_level,stdev,Samples) | |||
|
305 | Noise = numpy.zeros(Samples,dtype=complex) | |||
|
306 | Noise.real = Noise_r | |||
|
307 | Noise.imag = Noise_i | |||
|
308 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·PULSOSΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |||
|
309 | Pulso = numpy.zeros(pulse_size,dtype=complex) | |||
|
310 | Pulso.real = pulses[k%num_codes] | |||
|
311 | Pulso.imag = pulses[k%num_codes] | |||
|
312 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· PULSES+NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |||
|
313 | InBuffer = numpy.zeros(Samples,dtype=complex) | |||
|
314 | InBuffer[m_nR:m_nR+ps] = Pulso | |||
|
315 | InBuffer = InBuffer+Noise | |||
|
316 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· ANGLE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |||
|
317 | InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5) | |||
|
318 | InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5) | |||
|
319 | InBuffer=InBuffer | |||
|
320 | self.datablock[i][k]= InBuffer | |||
|
321 | #plot_cts(InBuffer,H0=H0,DH0=DH0) | |||
|
322 | #wave_fft(x=InBuffer,plot_show=True) | |||
|
323 | #time.sleep(1) | |||
|
324 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DOPPLER SIGNAL............................................... | |||
|
325 | time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen+(self.nReadFiles-1)*ippSec*prof_gen | |||
|
326 | fd = Fdoppler #+(600.0/120)*self.nReadBlocks | |||
|
327 | d_signal = Adoppler*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64) | |||
|
328 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLERΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·........................... | |||
|
329 | HD=int(Hdoppler/self.AcqDH_0) | |||
|
330 | for i in range(12): | |||
|
331 | self.datablock[:,:,HD+i]=self.datablock[:,:,HD+i]+ d_signal # RESULT | |||
|
332 | ''' | |||
|
333 | a= numpy.zeros(10) | |||
|
334 | for i in range(10): | |||
|
335 | a[i]=i+self.nReadBlocks+20 | |||
|
336 | for i in a: | |||
|
337 | self.datablock[0,:,int(i)]=self.datablock[0,:,int(i)]+ d_signal # RESULT | |||
|
338 | ''' | |||
|
339 | ||||
|
340 | def readBlock(self): | |||
|
341 | ||||
|
342 | self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level, | |||
|
343 | stdev=self.stdev,Reference= self.Reference, | |||
|
344 | pulses = self.pulses,Num_Codes=self.Num_Codes, | |||
|
345 | pulse_size=self.pulse_size,prof_gen=self.profiles, | |||
|
346 | H0=self.H0,DH0=self.DH0) | |||
|
347 | ||||
|
348 | self.profileIndex = 0 | |||
|
349 | self.flagIsNewFile = 0 | |||
|
350 | self.flagIsNewBlock = 1 | |||
|
351 | self.nTotalBlocks += 1 | |||
|
352 | self.nReadBlocks += 1 | |||
|
353 | ||||
|
354 | return 1 | |||
|
355 | ||||
|
356 | ||||
|
357 | def getData(self): | |||
|
358 | if self.flagNoMoreFiles: | |||
|
359 | self.dataOut.flagNodata = True | |||
|
360 | return 0 | |||
|
361 | self.flagDiscontinuousBlock = 0 | |||
|
362 | self.flagIsNewBlock = 0 | |||
|
363 | if self.__hasNotDataInBuffer(): # aqui es verdad | |||
|
364 | if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header | |||
|
365 | return 0 | |||
|
366 | self.getFirstHeader() # atributo | |||
|
367 | ||||
|
368 | if not self.getByBlock: | |||
|
369 | self.dataOut.flagDataAsBlock = False | |||
|
370 | self.dataOut.data = self.datablock[:, self.profileIndex, :] | |||
|
371 | self.dataOut.profileIndex = self.profileIndex | |||
|
372 | self.profileIndex += 1 | |||
|
373 | else: | |||
|
374 | pass | |||
|
375 | self.dataOut.flagNoData = False | |||
|
376 | self.getBasicHeader() | |||
|
377 | self.dataOut.realtime = self.online | |||
|
378 | return self.dataOut.data | |||
|
379 | ||||
|
380 | ||||
|
381 | def setup(self,frequency=49.92e6,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000, | |||
|
382 | FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32, | |||
|
383 | FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 50, | |||
|
384 | stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200, | |||
|
385 | channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500,nTotalReadFiles=10000, | |||
|
386 | **kwargs): | |||
|
387 | ||||
|
388 | self.set_kwargs(**kwargs) | |||
|
389 | self.nReadBlocks = 0 | |||
|
390 | self.nReadFiles = 1 | |||
|
391 | print('------------------- [Opening file: ] ------------------------------',self.nReadFiles) | |||
|
392 | ||||
|
393 | tmp = time.time() | |||
|
394 | tmp_utc = int(tmp) | |||
|
395 | tmp_milisecond = int((tmp-tmp_utc)*1000) | |||
|
396 | print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp)) | |||
|
397 | if Dyn_snCode is None: | |||
|
398 | Num_Codes=1 | |||
|
399 | Bauds =1 | |||
|
400 | ||||
|
401 | ||||
|
402 | ||||
|
403 | self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 ) | |||
|
404 | ||||
|
405 | self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB, | |||
|
406 | nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0, | |||
|
407 | numTaus=1, line6Function=0, line5Function=0, fClock=None, | |||
|
408 | prePulseBefore=0, prePulseAfter=0, | |||
|
409 | codeType=14, nCode=Num_Codes, nBaud=32, code=Dyn_snCode, | |||
|
410 | flip1=0, flip2=0) | |||
|
411 | ||||
|
412 | self.set_PH(dtype=0, blockSize=0, profilesPerBlock=300, | |||
|
413 | dataBlocksPerFile=120, nWindows=1, processFlags=0, nCohInt=1, | |||
|
414 | nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0, | |||
|
415 | deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0, | |||
|
416 | code=0, nBaud=None, shif_fft=False, flag_dc=False, | |||
|
417 | flag_cspc=False, flag_decode=False, flag_deflip=False) | |||
|
418 | ||||
|
419 | self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels) | |||
|
420 | ||||
|
421 | ||||
|
422 | self.frequency = frequency | |||
|
423 | self.incIntFactor = incIntFactor | |||
|
424 | self.nFFTPoints = nFFTPoints | |||
|
425 | self.FixPP_IncInt = FixPP_IncInt | |||
|
426 | self.FixRCP_IPP = FixRCP_IPP | |||
|
427 | self.FixPP_CohInt = FixPP_CohInt | |||
|
428 | self.Tau_0 = Tau_0 | |||
|
429 | self.AcqH0_0 = AcqH0_0 | |||
|
430 | self.H0 = AcqH0_0 | |||
|
431 | self.AcqDH_0 = AcqDH_0 | |||
|
432 | self.DH0 = AcqDH_0 | |||
|
433 | self.Bauds = Bauds | |||
|
434 | self.FixRCP_TXA = FixRCP_TXA | |||
|
435 | self.FixRCP_TXB = FixRCP_TXB | |||
|
436 | self.fAngle = fAngle | |||
|
437 | self.DC_level = DC_level | |||
|
438 | self.stdev = stdev | |||
|
439 | self.Num_Codes = Num_Codes | |||
|
440 | self.Dyn_snCode = Dyn_snCode | |||
|
441 | self.samples = samples | |||
|
442 | self.channels = channels | |||
|
443 | self.profiles = None | |||
|
444 | self.m_nReference = None | |||
|
445 | self.Baudwidth = None | |||
|
446 | self.Fdoppler = Fdoppler | |||
|
447 | self.Hdoppler = Hdoppler | |||
|
448 | self.Adoppler = Adoppler | |||
|
449 | self.nTotalReadFiles = int(nTotalReadFiles) | |||
|
450 | ||||
|
451 | print("IPP ", self.FixRCP_IPP) | |||
|
452 | print("Tau_0 ",self.Tau_0) | |||
|
453 | print("AcqH0_0",self.AcqH0_0) | |||
|
454 | print("samples,window ",self.samples) | |||
|
455 | print("AcqDH_0",AcqDH_0) | |||
|
456 | print("FixRCP_TXA",self.FixRCP_TXA) | |||
|
457 | print("FixRCP_TXB",self.FixRCP_TXB) | |||
|
458 | print("Dyn_snCode",Dyn_snCode) | |||
|
459 | print("Fdoppler", Fdoppler) | |||
|
460 | print("Hdoppler",Hdoppler) | |||
|
461 | print("Vdopplermax",Fdoppler*(3.0e8/self.frequency)/2.0) | |||
|
462 | print("nTotalReadFiles", nTotalReadFiles) | |||
|
463 | ||||
|
464 | self.init_acquisition() | |||
|
465 | self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode) | |||
|
466 | print(" [ END ] - SETUP metodo") | |||
|
467 | return | |||
|
468 | ||||
|
469 | def run(self,**kwargs): # metodo propio | |||
|
470 | if not(self.isConfig): | |||
|
471 | self.setup(**kwargs) | |||
|
472 | self.isConfig = True | |||
|
473 | self.getData() |
@@ -1,1386 +1,1393 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import copy |
|
7 | import copy | |
8 | import numpy |
|
8 | import numpy | |
9 | import datetime |
|
9 | import datetime | |
10 | import json |
|
10 | import json | |
11 |
|
11 | |||
12 | import schainpy.admin |
|
12 | import schainpy.admin | |
13 | from schainpy.utils import log |
|
13 | from schainpy.utils import log | |
14 | from .jroheaderIO import SystemHeader, RadarControllerHeader |
|
14 | from .jroheaderIO import SystemHeader, RadarControllerHeader | |
15 | from schainpy.model.data import _noise |
|
15 | from schainpy.model.data import _noise | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | def getNumpyDtype(dataTypeCode): |
|
18 | def getNumpyDtype(dataTypeCode): | |
19 |
|
19 | |||
20 | if dataTypeCode == 0: |
|
20 | if dataTypeCode == 0: | |
21 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
21 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
22 | elif dataTypeCode == 1: |
|
22 | elif dataTypeCode == 1: | |
23 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
23 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
24 | elif dataTypeCode == 2: |
|
24 | elif dataTypeCode == 2: | |
25 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
25 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
26 | elif dataTypeCode == 3: |
|
26 | elif dataTypeCode == 3: | |
27 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
27 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
28 | elif dataTypeCode == 4: |
|
28 | elif dataTypeCode == 4: | |
29 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
29 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
30 | elif dataTypeCode == 5: |
|
30 | elif dataTypeCode == 5: | |
31 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
31 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
32 | else: |
|
32 | else: | |
33 | raise ValueError('dataTypeCode was not defined') |
|
33 | raise ValueError('dataTypeCode was not defined') | |
34 |
|
34 | |||
35 | return numpyDtype |
|
35 | return numpyDtype | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | def getDataTypeCode(numpyDtype): |
|
38 | def getDataTypeCode(numpyDtype): | |
39 |
|
39 | |||
40 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): |
|
40 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): | |
41 | datatype = 0 |
|
41 | datatype = 0 | |
42 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): |
|
42 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): | |
43 | datatype = 1 |
|
43 | datatype = 1 | |
44 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): |
|
44 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): | |
45 | datatype = 2 |
|
45 | datatype = 2 | |
46 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): |
|
46 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): | |
47 | datatype = 3 |
|
47 | datatype = 3 | |
48 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): |
|
48 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): | |
49 | datatype = 4 |
|
49 | datatype = 4 | |
50 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): |
|
50 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): | |
51 | datatype = 5 |
|
51 | datatype = 5 | |
52 | else: |
|
52 | else: | |
53 | datatype = None |
|
53 | datatype = None | |
54 |
|
54 | |||
55 | return datatype |
|
55 | return datatype | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def hildebrand_sekhon(data, navg): |
|
58 | def hildebrand_sekhon(data, navg): | |
59 | """ |
|
59 | """ | |
60 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
60 | This method is for the objective determination of the noise level in Doppler spectra. This | |
61 | implementation technique is based on the fact that the standard deviation of the spectral |
|
61 | implementation technique is based on the fact that the standard deviation of the spectral | |
62 | densities is equal to the mean spectral density for white Gaussian noise |
|
62 | densities is equal to the mean spectral density for white Gaussian noise | |
63 |
|
63 | |||
64 | Inputs: |
|
64 | Inputs: | |
65 | Data : heights |
|
65 | Data : heights | |
66 | navg : numbers of averages |
|
66 | navg : numbers of averages | |
67 |
|
67 | |||
68 | Return: |
|
68 | Return: | |
69 | mean : noise's level |
|
69 | mean : noise's level | |
70 | """ |
|
70 | """ | |
71 |
|
71 | |||
72 | sortdata = numpy.sort(data, axis=None) |
|
72 | sortdata = numpy.sort(data, axis=None) | |
73 | ''' |
|
73 | ''' | |
74 | lenOfData = len(sortdata) |
|
74 | lenOfData = len(sortdata) | |
75 | nums_min = lenOfData*0.2 |
|
75 | nums_min = lenOfData*0.2 | |
76 |
|
76 | |||
77 | if nums_min <= 5: |
|
77 | if nums_min <= 5: | |
78 |
|
78 | |||
79 | nums_min = 5 |
|
79 | nums_min = 5 | |
80 |
|
80 | |||
81 | sump = 0. |
|
81 | sump = 0. | |
82 | sumq = 0. |
|
82 | sumq = 0. | |
83 |
|
83 | |||
84 | j = 0 |
|
84 | j = 0 | |
85 | cont = 1 |
|
85 | cont = 1 | |
86 |
|
86 | |||
87 | while((cont == 1)and(j < lenOfData)): |
|
87 | while((cont == 1)and(j < lenOfData)): | |
88 |
|
88 | |||
89 | sump += sortdata[j] |
|
89 | sump += sortdata[j] | |
90 | sumq += sortdata[j]**2 |
|
90 | sumq += sortdata[j]**2 | |
91 |
|
91 | |||
92 | if j > nums_min: |
|
92 | if j > nums_min: | |
93 | rtest = float(j)/(j-1) + 1.0/navg |
|
93 | rtest = float(j)/(j-1) + 1.0/navg | |
94 | if ((sumq*j) > (rtest*sump**2)): |
|
94 | if ((sumq*j) > (rtest*sump**2)): | |
95 | j = j - 1 |
|
95 | j = j - 1 | |
96 | sump = sump - sortdata[j] |
|
96 | sump = sump - sortdata[j] | |
97 | sumq = sumq - sortdata[j]**2 |
|
97 | sumq = sumq - sortdata[j]**2 | |
98 | cont = 0 |
|
98 | cont = 0 | |
99 |
|
99 | |||
100 | j += 1 |
|
100 | j += 1 | |
101 |
|
101 | |||
102 | lnoise = sump / j |
|
102 | lnoise = sump / j | |
103 | ''' |
|
103 | ''' | |
104 | return _noise.hildebrand_sekhon(sortdata, navg) |
|
104 | return _noise.hildebrand_sekhon(sortdata, navg) | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | class Beam: |
|
107 | class Beam: | |
108 |
|
108 | |||
109 | def __init__(self): |
|
109 | def __init__(self): | |
110 | self.codeList = [] |
|
110 | self.codeList = [] | |
111 | self.azimuthList = [] |
|
111 | self.azimuthList = [] | |
112 | self.zenithList = [] |
|
112 | self.zenithList = [] | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | class GenericData(object): |
|
115 | class GenericData(object): | |
116 |
|
116 | |||
117 | flagNoData = True |
|
117 | flagNoData = True | |
118 |
|
118 | |||
119 | def copy(self, inputObj=None): |
|
119 | def copy(self, inputObj=None): | |
120 |
|
120 | |||
121 | if inputObj == None: |
|
121 | if inputObj == None: | |
122 | return copy.deepcopy(self) |
|
122 | return copy.deepcopy(self) | |
123 |
|
123 | |||
124 | for key in list(inputObj.__dict__.keys()): |
|
124 | for key in list(inputObj.__dict__.keys()): | |
125 |
|
125 | |||
126 | attribute = inputObj.__dict__[key] |
|
126 | attribute = inputObj.__dict__[key] | |
127 |
|
127 | |||
128 | # If this attribute is a tuple or list |
|
128 | # If this attribute is a tuple or list | |
129 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
129 | if type(inputObj.__dict__[key]) in (tuple, list): | |
130 | self.__dict__[key] = attribute[:] |
|
130 | self.__dict__[key] = attribute[:] | |
131 | continue |
|
131 | continue | |
132 |
|
132 | |||
133 | # If this attribute is another object or instance |
|
133 | # If this attribute is another object or instance | |
134 | if hasattr(attribute, '__dict__'): |
|
134 | if hasattr(attribute, '__dict__'): | |
135 | self.__dict__[key] = attribute.copy() |
|
135 | self.__dict__[key] = attribute.copy() | |
136 | continue |
|
136 | continue | |
137 |
|
137 | |||
138 | self.__dict__[key] = inputObj.__dict__[key] |
|
138 | self.__dict__[key] = inputObj.__dict__[key] | |
139 |
|
139 | |||
140 | def deepcopy(self): |
|
140 | def deepcopy(self): | |
141 |
|
141 | |||
142 | return copy.deepcopy(self) |
|
142 | return copy.deepcopy(self) | |
143 |
|
143 | |||
144 | def isEmpty(self): |
|
144 | def isEmpty(self): | |
145 |
|
145 | |||
146 | return self.flagNoData |
|
146 | return self.flagNoData | |
147 |
|
147 | |||
148 | def isReady(self): |
|
148 | def isReady(self): | |
149 |
|
149 | |||
150 | return not self.flagNoData |
|
150 | return not self.flagNoData | |
151 |
|
151 | |||
152 |
|
152 | |||
153 | class JROData(GenericData): |
|
153 | class JROData(GenericData): | |
154 |
|
154 | |||
155 | # m_BasicHeader = BasicHeader() |
|
155 | # m_BasicHeader = BasicHeader() | |
156 | # m_ProcessingHeader = ProcessingHeader() |
|
156 | # m_ProcessingHeader = ProcessingHeader() | |
157 |
|
157 | |||
158 | systemHeaderObj = SystemHeader() |
|
158 | systemHeaderObj = SystemHeader() | |
159 | radarControllerHeaderObj = RadarControllerHeader() |
|
159 | radarControllerHeaderObj = RadarControllerHeader() | |
160 | # data = None |
|
160 | # data = None | |
161 | type = None |
|
161 | type = None | |
162 | datatype = None # dtype but in string |
|
162 | datatype = None # dtype but in string | |
163 | # dtype = None |
|
163 | # dtype = None | |
164 | # nChannels = None |
|
164 | # nChannels = None | |
165 | # nHeights = None |
|
165 | # nHeights = None | |
166 | nProfiles = None |
|
166 | nProfiles = None | |
167 | heightList = None |
|
167 | heightList = None | |
168 | channelList = None |
|
168 | channelList = None | |
169 | flagDiscontinuousBlock = False |
|
169 | flagDiscontinuousBlock = False | |
170 | useLocalTime = False |
|
170 | useLocalTime = False | |
171 | utctime = None |
|
171 | utctime = None | |
172 | timeZone = None |
|
172 | timeZone = None | |
173 | dstFlag = None |
|
173 | dstFlag = None | |
174 | errorCount = None |
|
174 | errorCount = None | |
175 | blocksize = None |
|
175 | blocksize = None | |
176 | # nCode = None |
|
176 | # nCode = None | |
177 | # nBaud = None |
|
177 | # nBaud = None | |
178 | # code = None |
|
178 | # code = None | |
179 | flagDecodeData = False # asumo q la data no esta decodificada |
|
179 | flagDecodeData = False # asumo q la data no esta decodificada | |
180 | flagDeflipData = False # asumo q la data no esta sin flip |
|
180 | flagDeflipData = False # asumo q la data no esta sin flip | |
181 | flagShiftFFT = False |
|
181 | flagShiftFFT = False | |
182 | # ippSeconds = None |
|
182 | # ippSeconds = None | |
183 | # timeInterval = None |
|
183 | # timeInterval = None | |
184 | nCohInt = None |
|
184 | nCohInt = None | |
185 | # noise = None |
|
185 | # noise = None | |
186 | windowOfFilter = 1 |
|
186 | windowOfFilter = 1 | |
187 | # Speed of ligth |
|
187 | # Speed of ligth | |
188 | C = 3e8 |
|
188 | C = 3e8 | |
189 | frequency = 49.92e6 |
|
189 | frequency = 49.92e6 | |
190 | realtime = False |
|
190 | realtime = False | |
191 | beacon_heiIndexList = None |
|
191 | beacon_heiIndexList = None | |
192 | last_block = None |
|
192 | last_block = None | |
193 | blocknow = None |
|
193 | blocknow = None | |
194 | azimuth = None |
|
194 | azimuth = None | |
195 | zenith = None |
|
195 | zenith = None | |
196 | beam = Beam() |
|
196 | beam = Beam() | |
197 | profileIndex = None |
|
197 | profileIndex = None | |
198 | error = None |
|
198 | error = None | |
199 | data = None |
|
199 | data = None | |
200 | nmodes = None |
|
200 | nmodes = None | |
201 |
|
201 | |||
202 | def __str__(self): |
|
202 | def __str__(self): | |
203 |
|
203 | |||
204 | return '{} - {}'.format(self.type, self.getDatatime()) |
|
204 | return '{} - {}'.format(self.type, self.getDatatime()) | |
205 |
|
205 | |||
206 | def getNoise(self): |
|
206 | def getNoise(self): | |
207 |
|
207 | |||
208 | raise NotImplementedError |
|
208 | raise NotImplementedError | |
209 |
|
209 | |||
210 | def getNChannels(self): |
|
210 | def getNChannels(self): | |
211 |
|
211 | |||
212 | return len(self.channelList) |
|
212 | return len(self.channelList) | |
213 |
|
213 | |||
214 | def getChannelIndexList(self): |
|
214 | def getChannelIndexList(self): | |
215 |
|
215 | |||
216 | return list(range(self.nChannels)) |
|
216 | return list(range(self.nChannels)) | |
217 |
|
217 | |||
218 | def getNHeights(self): |
|
218 | def getNHeights(self): | |
219 |
|
219 | |||
220 | return len(self.heightList) |
|
220 | return len(self.heightList) | |
221 |
|
221 | |||
222 | def getHeiRange(self, extrapoints=0): |
|
222 | def getHeiRange(self, extrapoints=0): | |
223 |
|
223 | |||
224 | heis = self.heightList |
|
224 | heis = self.heightList | |
225 | # deltah = self.heightList[1] - self.heightList[0] |
|
225 | # deltah = self.heightList[1] - self.heightList[0] | |
226 | # |
|
226 | # | |
227 | # heis.append(self.heightList[-1]) |
|
227 | # heis.append(self.heightList[-1]) | |
228 |
|
228 | |||
229 | return heis |
|
229 | return heis | |
230 |
|
230 | |||
231 | def getDeltaH(self): |
|
231 | def getDeltaH(self): | |
232 |
|
232 | |||
233 | delta = self.heightList[1] - self.heightList[0] |
|
233 | delta = self.heightList[1] - self.heightList[0] | |
234 |
|
234 | |||
235 | return delta |
|
235 | return delta | |
236 |
|
236 | |||
237 | def getltctime(self): |
|
237 | def getltctime(self): | |
238 |
|
238 | |||
239 | if self.useLocalTime: |
|
239 | if self.useLocalTime: | |
240 | return self.utctime - self.timeZone * 60 |
|
240 | return self.utctime - self.timeZone * 60 | |
241 |
|
241 | |||
242 | return self.utctime |
|
242 | return self.utctime | |
243 |
|
243 | |||
244 | def getDatatime(self): |
|
244 | def getDatatime(self): | |
245 |
|
245 | |||
246 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
246 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
247 | return datatimeValue |
|
247 | return datatimeValue | |
248 |
|
248 | |||
249 | def getTimeRange(self): |
|
249 | def getTimeRange(self): | |
250 |
|
250 | |||
251 | datatime = [] |
|
251 | datatime = [] | |
252 |
|
252 | |||
253 | datatime.append(self.ltctime) |
|
253 | datatime.append(self.ltctime) | |
254 | datatime.append(self.ltctime + self.timeInterval + 1) |
|
254 | datatime.append(self.ltctime + self.timeInterval + 1) | |
255 |
|
255 | |||
256 | datatime = numpy.array(datatime) |
|
256 | datatime = numpy.array(datatime) | |
257 |
|
257 | |||
258 | return datatime |
|
258 | return datatime | |
259 |
|
259 | |||
260 | def getFmaxTimeResponse(self): |
|
260 | def getFmaxTimeResponse(self): | |
261 |
|
261 | |||
262 | period = (10**-6) * self.getDeltaH() / (0.15) |
|
262 | period = (10**-6) * self.getDeltaH() / (0.15) | |
263 |
|
263 | |||
264 | PRF = 1. / (period * self.nCohInt) |
|
264 | PRF = 1. / (period * self.nCohInt) | |
265 |
|
265 | |||
266 | fmax = PRF |
|
266 | fmax = PRF | |
267 |
|
267 | |||
268 | return fmax |
|
268 | return fmax | |
269 |
|
269 | |||
270 | def getFmax(self): |
|
270 | def getFmax(self): | |
271 | PRF = 1. / (self.ippSeconds * self.nCohInt) |
|
271 | PRF = 1. / (self.ippSeconds * self.nCohInt) | |
272 |
|
272 | |||
273 | fmax = PRF |
|
273 | fmax = PRF | |
274 | return fmax |
|
274 | return fmax | |
275 |
|
275 | |||
276 | def getVmax(self): |
|
276 | def getVmax(self): | |
277 |
|
277 | |||
278 | _lambda = self.C / self.frequency |
|
278 | _lambda = self.C / self.frequency | |
279 |
|
279 | |||
280 | vmax = self.getFmax() * _lambda / 2 |
|
280 | vmax = self.getFmax() * _lambda / 2 | |
281 |
|
281 | |||
282 | return vmax |
|
282 | return vmax | |
283 |
|
283 | |||
284 | def get_ippSeconds(self): |
|
284 | def get_ippSeconds(self): | |
285 | ''' |
|
285 | ''' | |
286 | ''' |
|
286 | ''' | |
287 | return self.radarControllerHeaderObj.ippSeconds |
|
287 | return self.radarControllerHeaderObj.ippSeconds | |
288 |
|
288 | |||
289 | def set_ippSeconds(self, ippSeconds): |
|
289 | def set_ippSeconds(self, ippSeconds): | |
290 | ''' |
|
290 | ''' | |
291 | ''' |
|
291 | ''' | |
292 |
|
292 | |||
293 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
293 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
294 |
|
294 | |||
295 | return |
|
295 | return | |
296 |
|
296 | |||
297 | def get_dtype(self): |
|
297 | def get_dtype(self): | |
298 | ''' |
|
298 | ''' | |
299 | ''' |
|
299 | ''' | |
300 | return getNumpyDtype(self.datatype) |
|
300 | return getNumpyDtype(self.datatype) | |
301 |
|
301 | |||
302 | def set_dtype(self, numpyDtype): |
|
302 | def set_dtype(self, numpyDtype): | |
303 | ''' |
|
303 | ''' | |
304 | ''' |
|
304 | ''' | |
305 |
|
305 | |||
306 | self.datatype = getDataTypeCode(numpyDtype) |
|
306 | self.datatype = getDataTypeCode(numpyDtype) | |
307 |
|
307 | |||
308 | def get_code(self): |
|
308 | def get_code(self): | |
309 | ''' |
|
309 | ''' | |
310 | ''' |
|
310 | ''' | |
311 | return self.radarControllerHeaderObj.code |
|
311 | return self.radarControllerHeaderObj.code | |
312 |
|
312 | |||
313 | def set_code(self, code): |
|
313 | def set_code(self, code): | |
314 | ''' |
|
314 | ''' | |
315 | ''' |
|
315 | ''' | |
316 | self.radarControllerHeaderObj.code = code |
|
316 | self.radarControllerHeaderObj.code = code | |
317 |
|
317 | |||
318 | return |
|
318 | return | |
319 |
|
319 | |||
320 | def get_ncode(self): |
|
320 | def get_ncode(self): | |
321 | ''' |
|
321 | ''' | |
322 | ''' |
|
322 | ''' | |
323 | return self.radarControllerHeaderObj.nCode |
|
323 | return self.radarControllerHeaderObj.nCode | |
324 |
|
324 | |||
325 | def set_ncode(self, nCode): |
|
325 | def set_ncode(self, nCode): | |
326 | ''' |
|
326 | ''' | |
327 | ''' |
|
327 | ''' | |
328 | self.radarControllerHeaderObj.nCode = nCode |
|
328 | self.radarControllerHeaderObj.nCode = nCode | |
329 |
|
329 | |||
330 | return |
|
330 | return | |
331 |
|
331 | |||
332 | def get_nbaud(self): |
|
332 | def get_nbaud(self): | |
333 | ''' |
|
333 | ''' | |
334 | ''' |
|
334 | ''' | |
335 | return self.radarControllerHeaderObj.nBaud |
|
335 | return self.radarControllerHeaderObj.nBaud | |
336 |
|
336 | |||
337 | def set_nbaud(self, nBaud): |
|
337 | def set_nbaud(self, nBaud): | |
338 | ''' |
|
338 | ''' | |
339 | ''' |
|
339 | ''' | |
340 | self.radarControllerHeaderObj.nBaud = nBaud |
|
340 | self.radarControllerHeaderObj.nBaud = nBaud | |
341 |
|
341 | |||
342 | return |
|
342 | return | |
343 |
|
343 | |||
344 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
344 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
345 | channelIndexList = property( |
|
345 | channelIndexList = property( | |
346 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
346 | getChannelIndexList, "I'm the 'channelIndexList' property.") | |
347 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
347 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
348 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
348 | #noise = property(getNoise, "I'm the 'nHeights' property.") | |
349 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
349 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
350 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
350 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
351 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
351 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
352 | dtype = property(get_dtype, set_dtype) |
|
352 | dtype = property(get_dtype, set_dtype) | |
353 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
353 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
354 | code = property(get_code, set_code) |
|
354 | code = property(get_code, set_code) | |
355 | nCode = property(get_ncode, set_ncode) |
|
355 | nCode = property(get_ncode, set_ncode) | |
356 | nBaud = property(get_nbaud, set_nbaud) |
|
356 | nBaud = property(get_nbaud, set_nbaud) | |
357 |
|
357 | |||
358 |
|
358 | |||
359 | class Voltage(JROData): |
|
359 | class Voltage(JROData): | |
360 |
|
360 | |||
361 | # data es un numpy array de 2 dmensiones (canales, alturas) |
|
361 | # data es un numpy array de 2 dmensiones (canales, alturas) | |
362 | data = None |
|
362 | data = None | |
363 |
|
363 | data_intensity = None | ||
|
364 | data_velocity = None | |||
364 | def __init__(self): |
|
365 | def __init__(self): | |
365 | ''' |
|
366 | ''' | |
366 | Constructor |
|
367 | Constructor | |
367 | ''' |
|
368 | ''' | |
368 |
|
369 | |||
369 | self.useLocalTime = True |
|
370 | self.useLocalTime = True | |
370 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
371 | self.radarControllerHeaderObj = RadarControllerHeader() | |
371 | self.systemHeaderObj = SystemHeader() |
|
372 | self.systemHeaderObj = SystemHeader() | |
372 | self.type = "Voltage" |
|
373 | self.type = "Voltage" | |
373 | self.data = None |
|
374 | self.data = None | |
374 | # self.dtype = None |
|
375 | # self.dtype = None | |
375 | # self.nChannels = 0 |
|
376 | # self.nChannels = 0 | |
376 | # self.nHeights = 0 |
|
377 | # self.nHeights = 0 | |
377 | self.nProfiles = None |
|
378 | self.nProfiles = None | |
378 | self.heightList = None |
|
379 | self.heightList = None | |
379 | self.channelList = None |
|
380 | self.channelList = None | |
380 | # self.channelIndexList = None |
|
381 | # self.channelIndexList = None | |
381 | self.flagNoData = True |
|
382 | self.flagNoData = True | |
382 | self.flagDiscontinuousBlock = False |
|
383 | self.flagDiscontinuousBlock = False | |
383 | self.utctime = None |
|
384 | self.utctime = None | |
384 | self.timeZone = None |
|
385 | self.timeZone = None | |
385 | self.dstFlag = None |
|
386 | self.dstFlag = None | |
386 | self.errorCount = None |
|
387 | self.errorCount = None | |
387 | self.nCohInt = None |
|
388 | self.nCohInt = None | |
388 | self.blocksize = None |
|
389 | self.blocksize = None | |
389 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
390 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
390 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
391 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
391 | self.flagShiftFFT = False |
|
392 | self.flagShiftFFT = False | |
392 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil |
|
393 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil | |
393 | self.profileIndex = 0 |
|
394 | self.profileIndex = 0 | |
394 |
|
395 | |||
395 | def getNoisebyHildebrand(self, channel=None): |
|
396 | def getNoisebyHildebrand(self, channel=None): | |
396 | """ |
|
397 | """ | |
397 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
398 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
398 |
|
399 | |||
399 | Return: |
|
400 | Return: | |
400 | noiselevel |
|
401 | noiselevel | |
401 | """ |
|
402 | """ | |
402 |
|
403 | |||
403 | if channel != None: |
|
404 | if channel != None: | |
404 | data = self.data[channel] |
|
405 | data = self.data[channel] | |
405 | nChannels = 1 |
|
406 | nChannels = 1 | |
406 | else: |
|
407 | else: | |
407 | data = self.data |
|
408 | data = self.data | |
408 | nChannels = self.nChannels |
|
409 | nChannels = self.nChannels | |
409 |
|
410 | |||
410 | noise = numpy.zeros(nChannels) |
|
411 | noise = numpy.zeros(nChannels) | |
411 | power = data * numpy.conjugate(data) |
|
412 | power = data * numpy.conjugate(data) | |
412 |
|
413 | |||
413 | for thisChannel in range(nChannels): |
|
414 | for thisChannel in range(nChannels): | |
414 | if nChannels == 1: |
|
415 | if nChannels == 1: | |
415 | daux = power[:].real |
|
416 | daux = power[:].real | |
416 | else: |
|
417 | else: | |
417 | daux = power[thisChannel, :].real |
|
418 | daux = power[thisChannel, :].real | |
418 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
419 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
419 |
|
420 | |||
420 | return noise |
|
421 | return noise | |
421 |
|
422 | |||
422 | def getNoise(self, type=1, channel=None): |
|
423 | def getNoise(self, type=1, channel=None): | |
423 |
|
424 | |||
424 | if type == 1: |
|
425 | if type == 1: | |
425 | noise = self.getNoisebyHildebrand(channel) |
|
426 | noise = self.getNoisebyHildebrand(channel) | |
426 |
|
427 | |||
427 | return noise |
|
428 | return noise | |
428 |
|
429 | |||
429 | def getPower(self, channel=None): |
|
430 | def getPower(self, channel=None): | |
430 |
|
431 | |||
431 | if channel != None: |
|
432 | if channel != None: | |
432 | data = self.data[channel] |
|
433 | data = self.data[channel] | |
433 | else: |
|
434 | else: | |
434 | data = self.data |
|
435 | data = self.data | |
435 |
|
436 | |||
436 | power = data * numpy.conjugate(data) |
|
437 | power = data * numpy.conjugate(data) | |
437 | powerdB = 10 * numpy.log10(power.real) |
|
438 | powerdB = 10 * numpy.log10(power.real) | |
438 | powerdB = numpy.squeeze(powerdB) |
|
439 | powerdB = numpy.squeeze(powerdB) | |
439 |
|
440 | |||
440 | return powerdB |
|
441 | return powerdB | |
441 |
|
442 | |||
442 | def getTimeInterval(self): |
|
443 | def getTimeInterval(self): | |
443 |
|
444 | |||
444 | timeInterval = self.ippSeconds * self.nCohInt |
|
445 | timeInterval = self.ippSeconds * self.nCohInt | |
445 |
|
446 | |||
446 | return timeInterval |
|
447 | return timeInterval | |
447 |
|
448 | |||
448 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
449 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
449 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
450 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
450 |
|
451 | |||
451 |
|
452 | |||
452 | class Spectra(JROData): |
|
453 | class Spectra(JROData): | |
453 |
|
454 | |||
454 | # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
455 | # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
455 | data_spc = None |
|
456 | data_spc = None | |
456 | # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
457 | # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) | |
457 | data_cspc = None |
|
458 | data_cspc = None | |
458 | # data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
459 | # data dc es un numpy array de 2 dmensiones (canales, alturas) | |
459 | data_dc = None |
|
460 | data_dc = None | |
460 | # data power |
|
461 | # data power | |
461 | data_pwr = None |
|
462 | data_pwr = None | |
462 | nFFTPoints = None |
|
463 | nFFTPoints = None | |
463 | # nPairs = None |
|
464 | # nPairs = None | |
464 | pairsList = None |
|
465 | pairsList = None | |
465 | nIncohInt = None |
|
466 | nIncohInt = None | |
466 | wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia |
|
467 | wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia | |
467 | nCohInt = None # se requiere para determinar el valor de timeInterval |
|
468 | nCohInt = None # se requiere para determinar el valor de timeInterval | |
468 | ippFactor = None |
|
469 | ippFactor = None | |
469 | profileIndex = 0 |
|
470 | profileIndex = 0 | |
470 | plotting = "spectra" |
|
471 | plotting = "spectra" | |
471 |
|
472 | |||
472 | def __init__(self): |
|
473 | def __init__(self): | |
473 | ''' |
|
474 | ''' | |
474 | Constructor |
|
475 | Constructor | |
475 | ''' |
|
476 | ''' | |
476 |
|
477 | |||
477 | self.useLocalTime = True |
|
478 | self.useLocalTime = True | |
478 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
479 | self.radarControllerHeaderObj = RadarControllerHeader() | |
479 | self.systemHeaderObj = SystemHeader() |
|
480 | self.systemHeaderObj = SystemHeader() | |
480 | self.type = "Spectra" |
|
481 | self.type = "Spectra" | |
481 | # self.data = None |
|
482 | # self.data = None | |
482 | # self.dtype = None |
|
483 | # self.dtype = None | |
483 | # self.nChannels = 0 |
|
484 | # self.nChannels = 0 | |
484 | # self.nHeights = 0 |
|
485 | # self.nHeights = 0 | |
485 | self.nProfiles = None |
|
486 | self.nProfiles = None | |
486 | self.heightList = None |
|
487 | self.heightList = None | |
487 | self.channelList = None |
|
488 | self.channelList = None | |
488 | # self.channelIndexList = None |
|
489 | # self.channelIndexList = None | |
489 | self.pairsList = None |
|
490 | self.pairsList = None | |
490 | self.flagNoData = True |
|
491 | self.flagNoData = True | |
491 | self.flagDiscontinuousBlock = False |
|
492 | self.flagDiscontinuousBlock = False | |
492 | self.utctime = None |
|
493 | self.utctime = None | |
493 | self.nCohInt = None |
|
494 | self.nCohInt = None | |
494 | self.nIncohInt = None |
|
495 | self.nIncohInt = None | |
495 | self.blocksize = None |
|
496 | self.blocksize = None | |
496 | self.nFFTPoints = None |
|
497 | self.nFFTPoints = None | |
497 | self.wavelength = None |
|
498 | self.wavelength = None | |
498 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
499 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
499 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
500 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
500 | self.flagShiftFFT = False |
|
501 | self.flagShiftFFT = False | |
501 | self.ippFactor = 1 |
|
502 | self.ippFactor = 1 | |
502 | #self.noise = None |
|
503 | #self.noise = None | |
503 | self.beacon_heiIndexList = [] |
|
504 | self.beacon_heiIndexList = [] | |
504 | self.noise_estimation = None |
|
505 | self.noise_estimation = None | |
505 |
|
506 | |||
506 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
507 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
507 | """ |
|
508 | """ | |
508 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
509 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
509 |
|
510 | |||
510 | Return: |
|
511 | Return: | |
511 | noiselevel |
|
512 | noiselevel | |
512 | """ |
|
513 | """ | |
513 |
|
514 | |||
514 | noise = numpy.zeros(self.nChannels) |
|
515 | noise = numpy.zeros(self.nChannels) | |
515 |
|
516 | |||
516 | for channel in range(self.nChannels): |
|
517 | for channel in range(self.nChannels): | |
517 | daux = self.data_spc[channel, |
|
518 | daux = self.data_spc[channel, | |
518 | xmin_index:xmax_index, ymin_index:ymax_index] |
|
519 | xmin_index:xmax_index, ymin_index:ymax_index] | |
519 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
520 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
520 |
|
521 | |||
521 | return noise |
|
522 | return noise | |
522 |
|
523 | |||
523 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
524 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
524 |
|
525 | |||
525 | if self.noise_estimation is not None: |
|
526 | if self.noise_estimation is not None: | |
526 | # this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
527 | # this was estimated by getNoise Operation defined in jroproc_spectra.py | |
527 | return self.noise_estimation |
|
528 | return self.noise_estimation | |
528 | else: |
|
529 | else: | |
529 | noise = self.getNoisebyHildebrand( |
|
530 | noise = self.getNoisebyHildebrand( | |
530 | xmin_index, xmax_index, ymin_index, ymax_index) |
|
531 | xmin_index, xmax_index, ymin_index, ymax_index) | |
531 | return noise |
|
532 | return noise | |
532 |
|
533 | |||
533 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
534 | def getFreqRangeTimeResponse(self, extrapoints=0): | |
534 |
|
535 | |||
535 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) |
|
536 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) | |
536 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2 |
|
537 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2 | |
537 |
|
538 | |||
538 | return freqrange |
|
539 | return freqrange | |
539 |
|
540 | |||
540 | def getAcfRange(self, extrapoints=0): |
|
541 | def getAcfRange(self, extrapoints=0): | |
541 |
|
542 | |||
542 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) |
|
543 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) | |
543 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 |
|
544 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
544 |
|
545 | |||
545 | return freqrange |
|
546 | return freqrange | |
546 |
|
547 | |||
547 | def getFreqRange(self, extrapoints=0): |
|
548 | def getFreqRange(self, extrapoints=0): | |
548 |
|
549 | |||
549 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) |
|
550 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) | |
550 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 |
|
551 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
551 |
|
552 | |||
552 | return freqrange |
|
553 | return freqrange | |
553 |
|
554 | |||
554 | def getVelRange(self, extrapoints=0): |
|
555 | def getVelRange(self, extrapoints=0): | |
555 |
|
556 | |||
556 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) |
|
557 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) | |
557 | velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) |
|
558 | velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) | |
558 |
|
559 | |||
559 | if self.nmodes: |
|
560 | if self.nmodes: | |
560 | return velrange/self.nmodes |
|
561 | return velrange/self.nmodes | |
561 | else: |
|
562 | else: | |
562 | return velrange |
|
563 | return velrange | |
563 |
|
564 | |||
564 | def getNPairs(self): |
|
565 | def getNPairs(self): | |
565 |
|
566 | |||
566 | return len(self.pairsList) |
|
567 | return len(self.pairsList) | |
567 |
|
568 | |||
568 | def getPairsIndexList(self): |
|
569 | def getPairsIndexList(self): | |
569 |
|
570 | |||
570 | return list(range(self.nPairs)) |
|
571 | return list(range(self.nPairs)) | |
571 |
|
572 | |||
572 | def getNormFactor(self): |
|
573 | def getNormFactor(self): | |
573 |
|
574 | |||
574 | pwcode = 1 |
|
575 | pwcode = 1 | |
575 |
|
576 | |||
576 | if self.flagDecodeData: |
|
577 | if self.flagDecodeData: | |
577 | pwcode = numpy.sum(self.code[0]**2) |
|
578 | pwcode = numpy.sum(self.code[0]**2) | |
578 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
579 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
579 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter |
|
580 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter | |
580 |
|
581 | |||
581 | return normFactor |
|
582 | return normFactor | |
582 |
|
583 | |||
583 | def getFlagCspc(self): |
|
584 | def getFlagCspc(self): | |
584 |
|
585 | |||
585 | if self.data_cspc is None: |
|
586 | if self.data_cspc is None: | |
586 | return True |
|
587 | return True | |
587 |
|
588 | |||
588 | return False |
|
589 | return False | |
589 |
|
590 | |||
590 | def getFlagDc(self): |
|
591 | def getFlagDc(self): | |
591 |
|
592 | |||
592 | if self.data_dc is None: |
|
593 | if self.data_dc is None: | |
593 | return True |
|
594 | return True | |
594 |
|
595 | |||
595 | return False |
|
596 | return False | |
596 |
|
597 | |||
597 | def getTimeInterval(self): |
|
598 | def getTimeInterval(self): | |
598 |
|
599 | |||
599 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor |
|
600 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor | |
600 | if self.nmodes: |
|
601 | if self.nmodes: | |
601 | return self.nmodes*timeInterval |
|
602 | return self.nmodes*timeInterval | |
602 | else: |
|
603 | else: | |
603 | return timeInterval |
|
604 | return timeInterval | |
604 |
|
605 | |||
605 | def getPower(self): |
|
606 | def getPower(self): | |
606 |
|
607 | |||
607 | factor = self.normFactor |
|
608 | factor = self.normFactor | |
608 | z = self.data_spc / factor |
|
609 | z = self.data_spc / factor | |
609 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
610 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
610 | avg = numpy.average(z, axis=1) |
|
611 | avg = numpy.average(z, axis=1) | |
611 |
|
612 | |||
612 | return 10 * numpy.log10(avg) |
|
613 | return 10 * numpy.log10(avg) | |
613 |
|
614 | |||
614 | def getCoherence(self, pairsList=None, phase=False): |
|
615 | def getCoherence(self, pairsList=None, phase=False): | |
615 |
|
616 | |||
616 | z = [] |
|
617 | z = [] | |
617 | if pairsList is None: |
|
618 | if pairsList is None: | |
618 | pairsIndexList = self.pairsIndexList |
|
619 | pairsIndexList = self.pairsIndexList | |
619 | else: |
|
620 | else: | |
620 | pairsIndexList = [] |
|
621 | pairsIndexList = [] | |
621 | for pair in pairsList: |
|
622 | for pair in pairsList: | |
622 | if pair not in self.pairsList: |
|
623 | if pair not in self.pairsList: | |
623 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( |
|
624 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( | |
624 | pair)) |
|
625 | pair)) | |
625 | pairsIndexList.append(self.pairsList.index(pair)) |
|
626 | pairsIndexList.append(self.pairsList.index(pair)) | |
626 | for i in range(len(pairsIndexList)): |
|
627 | for i in range(len(pairsIndexList)): | |
627 | pair = self.pairsList[pairsIndexList[i]] |
|
628 | pair = self.pairsList[pairsIndexList[i]] | |
628 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
629 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) | |
629 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
630 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) | |
630 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
631 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) | |
631 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
632 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
632 | if phase: |
|
633 | if phase: | |
633 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
634 | data = numpy.arctan2(avgcoherenceComplex.imag, | |
634 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
635 | avgcoherenceComplex.real) * 180 / numpy.pi | |
635 | else: |
|
636 | else: | |
636 | data = numpy.abs(avgcoherenceComplex) |
|
637 | data = numpy.abs(avgcoherenceComplex) | |
637 |
|
638 | |||
638 | z.append(data) |
|
639 | z.append(data) | |
639 |
|
640 | |||
640 | return numpy.array(z) |
|
641 | return numpy.array(z) | |
641 |
|
642 | |||
642 | def setValue(self, value): |
|
643 | def setValue(self, value): | |
643 |
|
644 | |||
644 | print("This property should not be initialized") |
|
645 | print("This property should not be initialized") | |
645 |
|
646 | |||
646 | return |
|
647 | return | |
647 |
|
648 | |||
648 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
649 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") | |
649 | pairsIndexList = property( |
|
650 | pairsIndexList = property( | |
650 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
651 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
651 | normFactor = property(getNormFactor, setValue, |
|
652 | normFactor = property(getNormFactor, setValue, | |
652 | "I'm the 'getNormFactor' property.") |
|
653 | "I'm the 'getNormFactor' property.") | |
653 | flag_cspc = property(getFlagCspc, setValue) |
|
654 | flag_cspc = property(getFlagCspc, setValue) | |
654 | flag_dc = property(getFlagDc, setValue) |
|
655 | flag_dc = property(getFlagDc, setValue) | |
655 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
656 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") | |
656 | timeInterval = property(getTimeInterval, setValue, |
|
657 | timeInterval = property(getTimeInterval, setValue, | |
657 | "I'm the 'timeInterval' property") |
|
658 | "I'm the 'timeInterval' property") | |
658 |
|
659 | |||
659 |
|
660 | |||
660 | class SpectraHeis(Spectra): |
|
661 | class SpectraHeis(Spectra): | |
661 |
|
662 | |||
662 | data_spc = None |
|
663 | data_spc = None | |
663 | data_cspc = None |
|
664 | data_cspc = None | |
664 | data_dc = None |
|
665 | data_dc = None | |
665 | nFFTPoints = None |
|
666 | nFFTPoints = None | |
666 | # nPairs = None |
|
667 | # nPairs = None | |
667 | pairsList = None |
|
668 | pairsList = None | |
668 | nCohInt = None |
|
669 | nCohInt = None | |
669 | nIncohInt = None |
|
670 | nIncohInt = None | |
670 |
|
671 | |||
671 | def __init__(self): |
|
672 | def __init__(self): | |
672 |
|
673 | |||
673 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
674 | self.radarControllerHeaderObj = RadarControllerHeader() | |
674 |
|
675 | |||
675 | self.systemHeaderObj = SystemHeader() |
|
676 | self.systemHeaderObj = SystemHeader() | |
676 |
|
677 | |||
677 | self.type = "SpectraHeis" |
|
678 | self.type = "SpectraHeis" | |
678 |
|
679 | |||
679 | # self.dtype = None |
|
680 | # self.dtype = None | |
680 |
|
681 | |||
681 | # self.nChannels = 0 |
|
682 | # self.nChannels = 0 | |
682 |
|
683 | |||
683 | # self.nHeights = 0 |
|
684 | # self.nHeights = 0 | |
684 |
|
685 | |||
685 | self.nProfiles = None |
|
686 | self.nProfiles = None | |
686 |
|
687 | |||
687 | self.heightList = None |
|
688 | self.heightList = None | |
688 |
|
689 | |||
689 | self.channelList = None |
|
690 | self.channelList = None | |
690 |
|
691 | |||
691 | # self.channelIndexList = None |
|
692 | # self.channelIndexList = None | |
692 |
|
693 | |||
693 | self.flagNoData = True |
|
694 | self.flagNoData = True | |
694 |
|
695 | |||
695 | self.flagDiscontinuousBlock = False |
|
696 | self.flagDiscontinuousBlock = False | |
696 |
|
697 | |||
697 | # self.nPairs = 0 |
|
698 | # self.nPairs = 0 | |
698 |
|
699 | |||
699 | self.utctime = None |
|
700 | self.utctime = None | |
700 |
|
701 | |||
701 | self.blocksize = None |
|
702 | self.blocksize = None | |
702 |
|
703 | |||
703 | self.profileIndex = 0 |
|
704 | self.profileIndex = 0 | |
704 |
|
705 | |||
705 | self.nCohInt = 1 |
|
706 | self.nCohInt = 1 | |
706 |
|
707 | |||
707 | self.nIncohInt = 1 |
|
708 | self.nIncohInt = 1 | |
708 |
|
709 | |||
709 | def getNormFactor(self): |
|
710 | def getNormFactor(self): | |
710 | pwcode = 1 |
|
711 | pwcode = 1 | |
711 | if self.flagDecodeData: |
|
712 | if self.flagDecodeData: | |
712 | pwcode = numpy.sum(self.code[0]**2) |
|
713 | pwcode = numpy.sum(self.code[0]**2) | |
713 |
|
714 | |||
714 | normFactor = self.nIncohInt * self.nCohInt * pwcode |
|
715 | normFactor = self.nIncohInt * self.nCohInt * pwcode | |
715 |
|
716 | |||
716 | return normFactor |
|
717 | return normFactor | |
717 |
|
718 | |||
718 | def getTimeInterval(self): |
|
719 | def getTimeInterval(self): | |
719 |
|
720 | |||
720 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
721 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
721 |
|
722 | |||
722 | return timeInterval |
|
723 | return timeInterval | |
723 |
|
724 | |||
724 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
725 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
725 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
726 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
726 |
|
727 | |||
727 |
|
728 | |||
728 | class Fits(JROData): |
|
729 | class Fits(JROData): | |
729 |
|
730 | |||
730 | heightList = None |
|
731 | heightList = None | |
731 | channelList = None |
|
732 | channelList = None | |
732 | flagNoData = True |
|
733 | flagNoData = True | |
733 | flagDiscontinuousBlock = False |
|
734 | flagDiscontinuousBlock = False | |
734 | useLocalTime = False |
|
735 | useLocalTime = False | |
735 | utctime = None |
|
736 | utctime = None | |
736 | timeZone = None |
|
737 | timeZone = None | |
737 | # ippSeconds = None |
|
738 | # ippSeconds = None | |
738 | # timeInterval = None |
|
739 | # timeInterval = None | |
739 | nCohInt = None |
|
740 | nCohInt = None | |
740 | nIncohInt = None |
|
741 | nIncohInt = None | |
741 | noise = None |
|
742 | noise = None | |
742 | windowOfFilter = 1 |
|
743 | windowOfFilter = 1 | |
743 | # Speed of ligth |
|
744 | # Speed of ligth | |
744 | C = 3e8 |
|
745 | C = 3e8 | |
745 | frequency = 49.92e6 |
|
746 | frequency = 49.92e6 | |
746 | realtime = False |
|
747 | realtime = False | |
747 |
|
748 | |||
748 | def __init__(self): |
|
749 | def __init__(self): | |
749 |
|
750 | |||
750 | self.type = "Fits" |
|
751 | self.type = "Fits" | |
751 |
|
752 | |||
752 | self.nProfiles = None |
|
753 | self.nProfiles = None | |
753 |
|
754 | |||
754 | self.heightList = None |
|
755 | self.heightList = None | |
755 |
|
756 | |||
756 | self.channelList = None |
|
757 | self.channelList = None | |
757 |
|
758 | |||
758 | # self.channelIndexList = None |
|
759 | # self.channelIndexList = None | |
759 |
|
760 | |||
760 | self.flagNoData = True |
|
761 | self.flagNoData = True | |
761 |
|
762 | |||
762 | self.utctime = None |
|
763 | self.utctime = None | |
763 |
|
764 | |||
764 | self.nCohInt = 1 |
|
765 | self.nCohInt = 1 | |
765 |
|
766 | |||
766 | self.nIncohInt = 1 |
|
767 | self.nIncohInt = 1 | |
767 |
|
768 | |||
768 | self.useLocalTime = True |
|
769 | self.useLocalTime = True | |
769 |
|
770 | |||
770 | self.profileIndex = 0 |
|
771 | self.profileIndex = 0 | |
771 |
|
772 | |||
772 | # self.utctime = None |
|
773 | # self.utctime = None | |
773 | # self.timeZone = None |
|
774 | # self.timeZone = None | |
774 | # self.ltctime = None |
|
775 | # self.ltctime = None | |
775 | # self.timeInterval = None |
|
776 | # self.timeInterval = None | |
776 | # self.header = None |
|
777 | # self.header = None | |
777 | # self.data_header = None |
|
778 | # self.data_header = None | |
778 | # self.data = None |
|
779 | # self.data = None | |
779 | # self.datatime = None |
|
780 | # self.datatime = None | |
780 | # self.flagNoData = False |
|
781 | # self.flagNoData = False | |
781 | # self.expName = '' |
|
782 | # self.expName = '' | |
782 | # self.nChannels = None |
|
783 | # self.nChannels = None | |
783 | # self.nSamples = None |
|
784 | # self.nSamples = None | |
784 | # self.dataBlocksPerFile = None |
|
785 | # self.dataBlocksPerFile = None | |
785 | # self.comments = '' |
|
786 | # self.comments = '' | |
786 | # |
|
787 | # | |
787 |
|
788 | |||
788 | def getltctime(self): |
|
789 | def getltctime(self): | |
789 |
|
790 | |||
790 | if self.useLocalTime: |
|
791 | if self.useLocalTime: | |
791 | return self.utctime - self.timeZone * 60 |
|
792 | return self.utctime - self.timeZone * 60 | |
792 |
|
793 | |||
793 | return self.utctime |
|
794 | return self.utctime | |
794 |
|
795 | |||
795 | def getDatatime(self): |
|
796 | def getDatatime(self): | |
796 |
|
797 | |||
797 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
798 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
798 | return datatime |
|
799 | return datatime | |
799 |
|
800 | |||
800 | def getTimeRange(self): |
|
801 | def getTimeRange(self): | |
801 |
|
802 | |||
802 | datatime = [] |
|
803 | datatime = [] | |
803 |
|
804 | |||
804 | datatime.append(self.ltctime) |
|
805 | datatime.append(self.ltctime) | |
805 | datatime.append(self.ltctime + self.timeInterval) |
|
806 | datatime.append(self.ltctime + self.timeInterval) | |
806 |
|
807 | |||
807 | datatime = numpy.array(datatime) |
|
808 | datatime = numpy.array(datatime) | |
808 |
|
809 | |||
809 | return datatime |
|
810 | return datatime | |
810 |
|
811 | |||
811 | def getHeiRange(self): |
|
812 | def getHeiRange(self): | |
812 |
|
813 | |||
813 | heis = self.heightList |
|
814 | heis = self.heightList | |
814 |
|
815 | |||
815 | return heis |
|
816 | return heis | |
816 |
|
817 | |||
817 | def getNHeights(self): |
|
818 | def getNHeights(self): | |
818 |
|
819 | |||
819 | return len(self.heightList) |
|
820 | return len(self.heightList) | |
820 |
|
821 | |||
821 | def getNChannels(self): |
|
822 | def getNChannels(self): | |
822 |
|
823 | |||
823 | return len(self.channelList) |
|
824 | return len(self.channelList) | |
824 |
|
825 | |||
825 | def getChannelIndexList(self): |
|
826 | def getChannelIndexList(self): | |
826 |
|
827 | |||
827 | return list(range(self.nChannels)) |
|
828 | return list(range(self.nChannels)) | |
828 |
|
829 | |||
829 | def getNoise(self, type=1): |
|
830 | def getNoise(self, type=1): | |
830 |
|
831 | |||
831 | #noise = numpy.zeros(self.nChannels) |
|
832 | #noise = numpy.zeros(self.nChannels) | |
832 |
|
833 | |||
833 | if type == 1: |
|
834 | if type == 1: | |
834 | noise = self.getNoisebyHildebrand() |
|
835 | noise = self.getNoisebyHildebrand() | |
835 |
|
836 | |||
836 | if type == 2: |
|
837 | if type == 2: | |
837 | noise = self.getNoisebySort() |
|
838 | noise = self.getNoisebySort() | |
838 |
|
839 | |||
839 | if type == 3: |
|
840 | if type == 3: | |
840 | noise = self.getNoisebyWindow() |
|
841 | noise = self.getNoisebyWindow() | |
841 |
|
842 | |||
842 | return noise |
|
843 | return noise | |
843 |
|
844 | |||
844 | def getTimeInterval(self): |
|
845 | def getTimeInterval(self): | |
845 |
|
846 | |||
846 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
847 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
847 |
|
848 | |||
848 | return timeInterval |
|
849 | return timeInterval | |
849 |
|
850 | |||
850 | def get_ippSeconds(self): |
|
851 | def get_ippSeconds(self): | |
851 | ''' |
|
852 | ''' | |
852 | ''' |
|
853 | ''' | |
853 | return self.ipp_sec |
|
854 | return self.ipp_sec | |
854 |
|
855 | |||
855 |
|
856 | |||
856 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
857 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
857 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
858 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
858 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
859 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
859 | channelIndexList = property( |
|
860 | channelIndexList = property( | |
860 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
861 | getChannelIndexList, "I'm the 'channelIndexList' property.") | |
861 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
862 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
862 |
|
863 | |||
863 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
864 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
864 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
865 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
865 | ippSeconds = property(get_ippSeconds, '') |
|
866 | ippSeconds = property(get_ippSeconds, '') | |
866 |
|
867 | |||
867 | class Correlation(JROData): |
|
868 | class Correlation(JROData): | |
868 |
|
869 | |||
869 | noise = None |
|
870 | noise = None | |
870 | SNR = None |
|
871 | SNR = None | |
871 | #-------------------------------------------------- |
|
872 | #-------------------------------------------------- | |
872 | mode = None |
|
873 | mode = None | |
873 | split = False |
|
874 | split = False | |
874 | data_cf = None |
|
875 | data_cf = None | |
875 | lags = None |
|
876 | lags = None | |
876 | lagRange = None |
|
877 | lagRange = None | |
877 | pairsList = None |
|
878 | pairsList = None | |
878 | normFactor = None |
|
879 | normFactor = None | |
879 | #-------------------------------------------------- |
|
880 | #-------------------------------------------------- | |
880 | # calculateVelocity = None |
|
881 | # calculateVelocity = None | |
881 | nLags = None |
|
882 | nLags = None | |
882 | nPairs = None |
|
883 | nPairs = None | |
883 | nAvg = None |
|
884 | nAvg = None | |
884 |
|
885 | |||
885 | def __init__(self): |
|
886 | def __init__(self): | |
886 | ''' |
|
887 | ''' | |
887 | Constructor |
|
888 | Constructor | |
888 | ''' |
|
889 | ''' | |
889 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
890 | self.radarControllerHeaderObj = RadarControllerHeader() | |
890 |
|
891 | |||
891 | self.systemHeaderObj = SystemHeader() |
|
892 | self.systemHeaderObj = SystemHeader() | |
892 |
|
893 | |||
893 | self.type = "Correlation" |
|
894 | self.type = "Correlation" | |
894 |
|
895 | |||
895 | self.data = None |
|
896 | self.data = None | |
896 |
|
897 | |||
897 | self.dtype = None |
|
898 | self.dtype = None | |
898 |
|
899 | |||
899 | self.nProfiles = None |
|
900 | self.nProfiles = None | |
900 |
|
901 | |||
901 | self.heightList = None |
|
902 | self.heightList = None | |
902 |
|
903 | |||
903 | self.channelList = None |
|
904 | self.channelList = None | |
904 |
|
905 | |||
905 | self.flagNoData = True |
|
906 | self.flagNoData = True | |
906 |
|
907 | |||
907 | self.flagDiscontinuousBlock = False |
|
908 | self.flagDiscontinuousBlock = False | |
908 |
|
909 | |||
909 | self.utctime = None |
|
910 | self.utctime = None | |
910 |
|
911 | |||
911 | self.timeZone = None |
|
912 | self.timeZone = None | |
912 |
|
913 | |||
913 | self.dstFlag = None |
|
914 | self.dstFlag = None | |
914 |
|
915 | |||
915 | self.errorCount = None |
|
916 | self.errorCount = None | |
916 |
|
917 | |||
917 | self.blocksize = None |
|
918 | self.blocksize = None | |
918 |
|
919 | |||
919 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
920 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
920 |
|
921 | |||
921 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
922 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
922 |
|
923 | |||
923 | self.pairsList = None |
|
924 | self.pairsList = None | |
924 |
|
925 | |||
925 | self.nPoints = None |
|
926 | self.nPoints = None | |
926 |
|
927 | |||
927 | def getPairsList(self): |
|
928 | def getPairsList(self): | |
928 |
|
929 | |||
929 | return self.pairsList |
|
930 | return self.pairsList | |
930 |
|
931 | |||
931 | def getNoise(self, mode=2): |
|
932 | def getNoise(self, mode=2): | |
932 |
|
933 | |||
933 | indR = numpy.where(self.lagR == 0)[0][0] |
|
934 | indR = numpy.where(self.lagR == 0)[0][0] | |
934 | indT = numpy.where(self.lagT == 0)[0][0] |
|
935 | indT = numpy.where(self.lagT == 0)[0][0] | |
935 |
|
936 | |||
936 | jspectra0 = self.data_corr[:, :, indR, :] |
|
937 | jspectra0 = self.data_corr[:, :, indR, :] | |
937 | jspectra = copy.copy(jspectra0) |
|
938 | jspectra = copy.copy(jspectra0) | |
938 |
|
939 | |||
939 | num_chan = jspectra.shape[0] |
|
940 | num_chan = jspectra.shape[0] | |
940 | num_hei = jspectra.shape[2] |
|
941 | num_hei = jspectra.shape[2] | |
941 |
|
942 | |||
942 | freq_dc = jspectra.shape[1] / 2 |
|
943 | freq_dc = jspectra.shape[1] / 2 | |
943 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
944 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
944 |
|
945 | |||
945 | if ind_vel[0] < 0: |
|
946 | if ind_vel[0] < 0: | |
946 | ind_vel[list(range(0, 1))] = ind_vel[list( |
|
947 | ind_vel[list(range(0, 1))] = ind_vel[list( | |
947 | range(0, 1))] + self.num_prof |
|
948 | range(0, 1))] + self.num_prof | |
948 |
|
949 | |||
949 | if mode == 1: |
|
950 | if mode == 1: | |
950 | jspectra[:, freq_dc, :] = ( |
|
951 | jspectra[:, freq_dc, :] = ( | |
951 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
952 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |
952 |
|
953 | |||
953 | if mode == 2: |
|
954 | if mode == 2: | |
954 |
|
955 | |||
955 | vel = numpy.array([-2, -1, 1, 2]) |
|
956 | vel = numpy.array([-2, -1, 1, 2]) | |
956 | xx = numpy.zeros([4, 4]) |
|
957 | xx = numpy.zeros([4, 4]) | |
957 |
|
958 | |||
958 | for fil in range(4): |
|
959 | for fil in range(4): | |
959 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
960 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) | |
960 |
|
961 | |||
961 | xx_inv = numpy.linalg.inv(xx) |
|
962 | xx_inv = numpy.linalg.inv(xx) | |
962 | xx_aux = xx_inv[0, :] |
|
963 | xx_aux = xx_inv[0, :] | |
963 |
|
964 | |||
964 | for ich in range(num_chan): |
|
965 | for ich in range(num_chan): | |
965 | yy = jspectra[ich, ind_vel, :] |
|
966 | yy = jspectra[ich, ind_vel, :] | |
966 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
967 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
967 |
|
968 | |||
968 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
969 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
969 | cjunkid = sum(junkid) |
|
970 | cjunkid = sum(junkid) | |
970 |
|
971 | |||
971 | if cjunkid.any(): |
|
972 | if cjunkid.any(): | |
972 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
973 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
973 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
974 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
974 |
|
975 | |||
975 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] |
|
976 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] | |
976 |
|
977 | |||
977 | return noise |
|
978 | return noise | |
978 |
|
979 | |||
979 | def getTimeInterval(self): |
|
980 | def getTimeInterval(self): | |
980 |
|
981 | |||
981 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
982 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles | |
982 |
|
983 | |||
983 | return timeInterval |
|
984 | return timeInterval | |
984 |
|
985 | |||
985 | def splitFunctions(self): |
|
986 | def splitFunctions(self): | |
986 |
|
987 | |||
987 | pairsList = self.pairsList |
|
988 | pairsList = self.pairsList | |
988 | ccf_pairs = [] |
|
989 | ccf_pairs = [] | |
989 | acf_pairs = [] |
|
990 | acf_pairs = [] | |
990 | ccf_ind = [] |
|
991 | ccf_ind = [] | |
991 | acf_ind = [] |
|
992 | acf_ind = [] | |
992 | for l in range(len(pairsList)): |
|
993 | for l in range(len(pairsList)): | |
993 | chan0 = pairsList[l][0] |
|
994 | chan0 = pairsList[l][0] | |
994 | chan1 = pairsList[l][1] |
|
995 | chan1 = pairsList[l][1] | |
995 |
|
996 | |||
996 | # Obteniendo pares de Autocorrelacion |
|
997 | # Obteniendo pares de Autocorrelacion | |
997 | if chan0 == chan1: |
|
998 | if chan0 == chan1: | |
998 | acf_pairs.append(chan0) |
|
999 | acf_pairs.append(chan0) | |
999 | acf_ind.append(l) |
|
1000 | acf_ind.append(l) | |
1000 | else: |
|
1001 | else: | |
1001 | ccf_pairs.append(pairsList[l]) |
|
1002 | ccf_pairs.append(pairsList[l]) | |
1002 | ccf_ind.append(l) |
|
1003 | ccf_ind.append(l) | |
1003 |
|
1004 | |||
1004 | data_acf = self.data_cf[acf_ind] |
|
1005 | data_acf = self.data_cf[acf_ind] | |
1005 | data_ccf = self.data_cf[ccf_ind] |
|
1006 | data_ccf = self.data_cf[ccf_ind] | |
1006 |
|
1007 | |||
1007 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1008 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf | |
1008 |
|
1009 | |||
1009 | def getNormFactor(self): |
|
1010 | def getNormFactor(self): | |
1010 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1011 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() | |
1011 | acf_pairs = numpy.array(acf_pairs) |
|
1012 | acf_pairs = numpy.array(acf_pairs) | |
1012 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) |
|
1013 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) | |
1013 |
|
1014 | |||
1014 | for p in range(self.nPairs): |
|
1015 | for p in range(self.nPairs): | |
1015 | pair = self.pairsList[p] |
|
1016 | pair = self.pairsList[p] | |
1016 |
|
1017 | |||
1017 | ch0 = pair[0] |
|
1018 | ch0 = pair[0] | |
1018 | ch1 = pair[1] |
|
1019 | ch1 = pair[1] | |
1019 |
|
1020 | |||
1020 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) |
|
1021 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) | |
1021 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) |
|
1022 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) | |
1022 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) |
|
1023 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) | |
1023 |
|
1024 | |||
1024 | return normFactor |
|
1025 | return normFactor | |
1025 |
|
1026 | |||
1026 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1027 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
1027 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1028 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") | |
1028 |
|
1029 | |||
1029 |
|
1030 | |||
1030 | class Parameters(Spectra): |
|
1031 | class Parameters(Spectra): | |
1031 |
|
1032 | |||
1032 | experimentInfo = None # Information about the experiment |
|
1033 | experimentInfo = None # Information about the experiment | |
1033 | # Information from previous data |
|
1034 | # Information from previous data | |
1034 | inputUnit = None # Type of data to be processed |
|
1035 | inputUnit = None # Type of data to be processed | |
1035 | operation = None # Type of operation to parametrize |
|
1036 | operation = None # Type of operation to parametrize | |
1036 | # normFactor = None #Normalization Factor |
|
1037 | # normFactor = None #Normalization Factor | |
1037 | groupList = None # List of Pairs, Groups, etc |
|
1038 | groupList = None # List of Pairs, Groups, etc | |
1038 | # Parameters |
|
1039 | # Parameters | |
1039 | data_param = None # Parameters obtained |
|
1040 | data_param = None # Parameters obtained | |
1040 | data_pre = None # Data Pre Parametrization |
|
1041 | data_pre = None # Data Pre Parametrization | |
1041 | data_SNR = None # Signal to Noise Ratio |
|
1042 | data_SNR = None # Signal to Noise Ratio | |
1042 | # heightRange = None #Heights |
|
1043 | # heightRange = None #Heights | |
1043 | abscissaList = None # Abscissa, can be velocities, lags or time |
|
1044 | abscissaList = None # Abscissa, can be velocities, lags or time | |
1044 | # noise = None #Noise Potency |
|
1045 | # noise = None #Noise Potency | |
1045 | utctimeInit = None # Initial UTC time |
|
1046 | utctimeInit = None # Initial UTC time | |
1046 | paramInterval = None # Time interval to calculate Parameters in seconds |
|
1047 | paramInterval = None # Time interval to calculate Parameters in seconds | |
1047 | useLocalTime = True |
|
1048 | useLocalTime = True | |
1048 | # Fitting |
|
1049 | # Fitting | |
1049 | data_error = None # Error of the estimation |
|
1050 | data_error = None # Error of the estimation | |
1050 | constants = None |
|
1051 | constants = None | |
1051 | library = None |
|
1052 | library = None | |
1052 | # Output signal |
|
1053 | # Output signal | |
1053 | outputInterval = None # Time interval to calculate output signal in seconds |
|
1054 | outputInterval = None # Time interval to calculate output signal in seconds | |
1054 | data_output = None # Out signal |
|
1055 | data_output = None # Out signal | |
1055 | nAvg = None |
|
1056 | nAvg = None | |
1056 | noise_estimation = None |
|
1057 | noise_estimation = None | |
1057 | GauSPC = None # Fit gaussian SPC |
|
1058 | GauSPC = None # Fit gaussian SPC | |
1058 |
|
1059 | |||
1059 | def __init__(self): |
|
1060 | def __init__(self): | |
1060 | ''' |
|
1061 | ''' | |
1061 | Constructor |
|
1062 | Constructor | |
1062 | ''' |
|
1063 | ''' | |
1063 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1064 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1064 |
|
1065 | |||
1065 | self.systemHeaderObj = SystemHeader() |
|
1066 | self.systemHeaderObj = SystemHeader() | |
1066 |
|
1067 | |||
1067 | self.type = "Parameters" |
|
1068 | self.type = "Parameters" | |
1068 |
|
1069 | |||
1069 | def getTimeRange1(self, interval): |
|
1070 | def getTimeRange1(self, interval): | |
1070 |
|
1071 | |||
1071 | datatime = [] |
|
1072 | datatime = [] | |
1072 |
|
1073 | |||
1073 | if self.useLocalTime: |
|
1074 | if self.useLocalTime: | |
1074 | time1 = self.utctimeInit - self.timeZone * 60 |
|
1075 | time1 = self.utctimeInit - self.timeZone * 60 | |
1075 | else: |
|
1076 | else: | |
1076 | time1 = self.utctimeInit |
|
1077 | time1 = self.utctimeInit | |
1077 |
|
1078 | |||
1078 | datatime.append(time1) |
|
1079 | datatime.append(time1) | |
1079 | datatime.append(time1 + interval) |
|
1080 | datatime.append(time1 + interval) | |
1080 | datatime = numpy.array(datatime) |
|
1081 | datatime = numpy.array(datatime) | |
1081 |
|
1082 | |||
1082 | return datatime |
|
1083 | return datatime | |
1083 |
|
1084 | |||
1084 | def getTimeInterval(self): |
|
1085 | def getTimeInterval(self): | |
1085 |
|
1086 | |||
1086 | if hasattr(self, 'timeInterval1'): |
|
1087 | if hasattr(self, 'timeInterval1'): | |
1087 | return self.timeInterval1 |
|
1088 | return self.timeInterval1 | |
1088 | else: |
|
1089 | else: | |
1089 | return self.paramInterval |
|
1090 | return self.paramInterval | |
1090 |
|
1091 | |||
1091 | def setValue(self, value): |
|
1092 | def setValue(self, value): | |
1092 |
|
1093 | |||
1093 | print("This property should not be initialized") |
|
1094 | print("This property should not be initialized") | |
1094 |
|
1095 | |||
1095 | return |
|
1096 | return | |
1096 |
|
1097 | |||
1097 | def getNoise(self): |
|
1098 | def getNoise(self): | |
1098 |
|
1099 | |||
1099 | return self.spc_noise |
|
1100 | return self.spc_noise | |
1100 |
|
1101 | |||
1101 | timeInterval = property(getTimeInterval) |
|
1102 | timeInterval = property(getTimeInterval) | |
1102 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
|
1103 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") | |
1103 |
|
1104 | |||
1104 |
|
1105 | |||
1105 | class PlotterData(object): |
|
1106 | class PlotterData(object): | |
1106 | ''' |
|
1107 | ''' | |
1107 | Object to hold data to be plotted |
|
1108 | Object to hold data to be plotted | |
1108 | ''' |
|
1109 | ''' | |
1109 |
|
1110 | |||
1110 | MAXNUMX = 100 |
|
1111 | MAXNUMX = 100 | |
1111 | MAXNUMY = 100 |
|
1112 | MAXNUMY = 100 | |
1112 |
|
1113 | |||
1113 | def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False): |
|
1114 | def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False): | |
1114 |
|
1115 | |||
1115 | self.key = code |
|
1116 | self.key = code | |
1116 | self.throttle = throttle_value |
|
1117 | self.throttle = throttle_value | |
1117 | self.exp_code = exp_code |
|
1118 | self.exp_code = exp_code | |
1118 | self.buffering = buffering |
|
1119 | self.buffering = buffering | |
1119 | self.ready = False |
|
1120 | self.ready = False | |
1120 | self.flagNoData = False |
|
1121 | self.flagNoData = False | |
1121 | self.localtime = False |
|
1122 | self.localtime = False | |
1122 | self.data = {} |
|
1123 | self.data = {} | |
1123 | self.meta = {} |
|
1124 | self.meta = {} | |
1124 | self.__times = [] |
|
1125 | self.__times = [] | |
1125 | self.__heights = [] |
|
1126 | self.__heights = [] | |
1126 |
|
1127 | |||
1127 | if 'snr' in code: |
|
1128 | if 'snr' in code: | |
1128 | self.plottypes = ['snr'] |
|
1129 | self.plottypes = ['snr'] | |
1129 | elif code == 'spc': |
|
1130 | elif code == 'spc': | |
1130 | self.plottypes = ['spc', 'noise', 'rti'] |
|
1131 | self.plottypes = ['spc', 'noise', 'rti'] | |
1131 | elif code == 'rti': |
|
1132 | elif code == 'rti': | |
1132 | self.plottypes = ['noise', 'rti'] |
|
1133 | self.plottypes = ['noise', 'rti'] | |
1133 | else: |
|
1134 | else: | |
1134 | self.plottypes = [code] |
|
1135 | self.plottypes = [code] | |
1135 |
|
1136 | |||
1136 | if 'snr' not in self.plottypes and snr: |
|
1137 | if 'snr' not in self.plottypes and snr: | |
1137 | self.plottypes.append('snr') |
|
1138 | self.plottypes.append('snr') | |
1138 |
|
1139 | |||
1139 | for plot in self.plottypes: |
|
1140 | for plot in self.plottypes: | |
1140 | self.data[plot] = {} |
|
1141 | self.data[plot] = {} | |
1141 |
|
1142 | |||
|
1143 | ||||
1142 | def __str__(self): |
|
1144 | def __str__(self): | |
1143 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] |
|
1145 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] | |
1144 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) |
|
1146 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) | |
1145 |
|
1147 | |||
1146 | def __len__(self): |
|
1148 | def __len__(self): | |
1147 | return len(self.__times) |
|
1149 | return len(self.__times) | |
1148 |
|
1150 | |||
1149 | def __getitem__(self, key): |
|
1151 | def __getitem__(self, key): | |
1150 |
|
1152 | |||
1151 | if key not in self.data: |
|
1153 | if key not in self.data: | |
1152 | raise KeyError(log.error('Missing key: {}'.format(key))) |
|
1154 | raise KeyError(log.error('Missing key: {}'.format(key))) | |
1153 | if 'spc' in key or not self.buffering: |
|
1155 | if 'spc' in key or not self.buffering: | |
1154 | ret = self.data[key] |
|
1156 | ret = self.data[key] | |
1155 | elif 'scope' in key: |
|
1157 | elif 'scope' in key: | |
1156 | ret = numpy.array(self.data[key][float(self.tm)]) |
|
1158 | ret = numpy.array(self.data[key][float(self.tm)]) | |
1157 | else: |
|
1159 | else: | |
1158 | ret = numpy.array([self.data[key][x] for x in self.times]) |
|
1160 | ret = numpy.array([self.data[key][x] for x in self.times]) | |
1159 | if ret.ndim > 1: |
|
1161 | if ret.ndim > 1: | |
1160 | ret = numpy.swapaxes(ret, 0, 1) |
|
1162 | ret = numpy.swapaxes(ret, 0, 1) | |
1161 | return ret |
|
1163 | return ret | |
1162 |
|
1164 | |||
1163 | def __contains__(self, key): |
|
1165 | def __contains__(self, key): | |
1164 | return key in self.data |
|
1166 | return key in self.data | |
1165 |
|
1167 | |||
1166 | def setup(self): |
|
1168 | def setup(self): | |
1167 | ''' |
|
1169 | ''' | |
1168 | Configure object |
|
1170 | Configure object | |
1169 | ''' |
|
1171 | ''' | |
1170 |
|
||||
1171 | self.type = '' |
|
1172 | self.type = '' | |
1172 | self.ready = False |
|
1173 | self.ready = False | |
1173 | self.data = {} |
|
1174 | self.data = {} | |
1174 | self.__times = [] |
|
1175 | self.__times = [] | |
1175 | self.__heights = [] |
|
1176 | self.__heights = [] | |
1176 | self.__all_heights = set() |
|
1177 | self.__all_heights = set() | |
1177 | for plot in self.plottypes: |
|
1178 | for plot in self.plottypes: | |
1178 | if 'snr' in plot: |
|
1179 | if 'snr' in plot: | |
1179 | plot = 'snr' |
|
1180 | plot = 'snr' | |
1180 | elif 'spc_moments' == plot: |
|
1181 | elif 'spc_moments' == plot: | |
1181 | plot = 'moments' |
|
1182 | plot = 'moments' | |
1182 | self.data[plot] = {} |
|
1183 | self.data[plot] = {} | |
1183 |
|
1184 | |||
1184 | if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data: |
|
1185 | if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data: | |
1185 | self.data['noise'] = {} |
|
1186 | self.data['noise'] = {} | |
1186 | self.data['rti'] = {} |
|
1187 | self.data['rti'] = {} | |
1187 | if 'noise' not in self.plottypes: |
|
1188 | if 'noise' not in self.plottypes: | |
1188 | self.plottypes.append('noise') |
|
1189 | self.plottypes.append('noise') | |
1189 | if 'rti' not in self.plottypes: |
|
1190 | if 'rti' not in self.plottypes: | |
1190 | self.plottypes.append('rti') |
|
1191 | self.plottypes.append('rti') | |
1191 |
|
1192 | |||
1192 | def shape(self, key): |
|
1193 | def shape(self, key): | |
1193 | ''' |
|
1194 | ''' | |
1194 | Get the shape of the one-element data for the given key |
|
1195 | Get the shape of the one-element data for the given key | |
1195 | ''' |
|
1196 | ''' | |
1196 |
|
1197 | |||
1197 | if len(self.data[key]): |
|
1198 | if len(self.data[key]): | |
1198 | if 'spc' in key or not self.buffering: |
|
1199 | if 'spc' in key or not self.buffering: | |
1199 | return self.data[key].shape |
|
1200 | return self.data[key].shape | |
1200 | return self.data[key][self.__times[0]].shape |
|
1201 | return self.data[key][self.__times[0]].shape | |
1201 | return (0,) |
|
1202 | return (0,) | |
1202 |
|
1203 | |||
1203 | def update(self, dataOut, tm): |
|
1204 | def update(self, dataOut, tm): | |
1204 | ''' |
|
1205 | ''' | |
1205 | Update data object with new dataOut |
|
1206 | Update data object with new dataOut | |
1206 | ''' |
|
1207 | ''' | |
1207 |
|
||||
1208 | if tm in self.__times: |
|
1208 | if tm in self.__times: | |
1209 | return |
|
1209 | return | |
1210 | self.profileIndex = dataOut.profileIndex |
|
1210 | self.profileIndex = dataOut.profileIndex | |
1211 | self.tm = tm |
|
1211 | self.tm = tm | |
1212 | self.type = dataOut.type |
|
1212 | self.type = dataOut.type | |
1213 | self.parameters = getattr(dataOut, 'parameters', []) |
|
1213 | self.parameters = getattr(dataOut, 'parameters', []) | |
1214 |
|
1214 | |||
1215 | if hasattr(dataOut, 'meta'): |
|
1215 | if hasattr(dataOut, 'meta'): | |
1216 | self.meta.update(dataOut.meta) |
|
1216 | self.meta.update(dataOut.meta) | |
1217 |
|
1217 | |||
1218 | if hasattr(dataOut, 'pairsList'): |
|
1218 | if hasattr(dataOut, 'pairsList'): | |
1219 | self.pairs = dataOut.pairsList |
|
1219 | self.pairs = dataOut.pairsList | |
1220 |
|
1220 | |||
1221 | self.interval = dataOut.getTimeInterval() |
|
1221 | self.interval = dataOut.getTimeInterval() | |
1222 | self.localtime = dataOut.useLocalTime |
|
1222 | self.localtime = dataOut.useLocalTime | |
1223 | if True in ['spc' in ptype for ptype in self.plottypes]: |
|
1223 | if True in ['spc' in ptype for ptype in self.plottypes]: | |
1224 | self.xrange = (dataOut.getFreqRange(1)/1000., |
|
1224 | self.xrange = (dataOut.getFreqRange(1)/1000., | |
1225 | dataOut.getAcfRange(1), dataOut.getVelRange(1)) |
|
1225 | dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |
1226 | self.factor = dataOut.normFactor |
|
1226 | self.factor = dataOut.normFactor | |
1227 | self.__heights.append(dataOut.heightList) |
|
1227 | self.__heights.append(dataOut.heightList) | |
1228 | self.__all_heights.update(dataOut.heightList) |
|
1228 | self.__all_heights.update(dataOut.heightList) | |
1229 | self.__times.append(tm) |
|
1229 | self.__times.append(tm) | |
1230 |
|
||||
1231 | for plot in self.plottypes: |
|
1230 | for plot in self.plottypes: | |
1232 | if plot in ('spc', 'spc_moments', 'spc_cut'): |
|
1231 | if plot in ('spc', 'spc_moments', 'spc_cut'): | |
1233 | z = dataOut.data_spc/dataOut.normFactor |
|
1232 | z = dataOut.data_spc/dataOut.normFactor | |
1234 | buffer = 10*numpy.log10(z) |
|
1233 | buffer = 10*numpy.log10(z) | |
1235 | if plot == 'cspc': |
|
1234 | if plot == 'cspc': | |
1236 | z = dataOut.data_spc/dataOut.normFactor |
|
1235 | z = dataOut.data_spc/dataOut.normFactor | |
1237 | buffer = (dataOut.data_spc, dataOut.data_cspc) |
|
1236 | buffer = (dataOut.data_spc, dataOut.data_cspc) | |
1238 | if plot == 'noise': |
|
1237 | if plot == 'noise': | |
1239 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) |
|
1238 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |
1240 | if plot in ('rti', 'spcprofile'): |
|
1239 | if plot in ('rti', 'spcprofile'): | |
1241 | buffer = dataOut.getPower() |
|
1240 | buffer = dataOut.getPower() | |
1242 | if plot == 'snr_db': |
|
1241 | if plot == 'snr_db': | |
1243 | buffer = dataOut.data_SNR |
|
1242 | buffer = dataOut.data_SNR | |
1244 | if plot == 'snr': |
|
1243 | if plot == 'snr': | |
1245 | buffer = 10*numpy.log10(dataOut.data_SNR) |
|
1244 | buffer = 10*numpy.log10(dataOut.data_SNR) | |
1246 | if plot == 'dop': |
|
1245 | if plot == 'dop': | |
1247 | buffer = dataOut.data_DOP |
|
1246 | buffer = dataOut.data_DOP | |
1248 | if plot == 'pow': |
|
1247 | if plot == 'pow': | |
1249 | buffer = 10*numpy.log10(dataOut.data_POW) |
|
1248 | buffer = 10*numpy.log10(dataOut.data_POW) | |
1250 | if plot == 'width': |
|
1249 | if plot == 'width': | |
1251 | buffer = dataOut.data_WIDTH |
|
1250 | buffer = dataOut.data_WIDTH | |
1252 | if plot == 'coh': |
|
1251 | if plot == 'coh': | |
1253 | buffer = dataOut.getCoherence() |
|
1252 | buffer = dataOut.getCoherence() | |
1254 | if plot == 'phase': |
|
1253 | if plot == 'phase': | |
1255 | buffer = dataOut.getCoherence(phase=True) |
|
1254 | buffer = dataOut.getCoherence(phase=True) | |
1256 | if plot == 'output': |
|
1255 | if plot == 'output': | |
1257 | buffer = dataOut.data_output |
|
1256 | buffer = dataOut.data_output | |
1258 | if plot == 'param': |
|
1257 | if plot == 'param': | |
1259 | buffer = dataOut.data_param |
|
1258 | buffer = dataOut.data_param | |
1260 | if plot == 'scope': |
|
1259 | if plot == 'scope': | |
1261 | buffer = dataOut.data |
|
1260 | buffer = dataOut.data | |
1262 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
1261 | self.flagDataAsBlock = dataOut.flagDataAsBlock | |
1263 |
self.nProfiles = dataOut.nProfiles |
|
1262 | self.nProfiles = dataOut.nProfiles | |
1264 |
|
1263 | if plot == 'pp_power': | ||
|
1264 | buffer = dataOut.data_intensity | |||
|
1265 | self.flagDataAsBlock = dataOut.flagDataAsBlock | |||
|
1266 | self.nProfiles = dataOut.nProfiles | |||
|
1267 | if plot == 'pp_velocity': | |||
|
1268 | buffer = dataOut.data_velocity | |||
|
1269 | self.flagDataAsBlock = dataOut.flagDataAsBlock | |||
|
1270 | self.nProfiles = dataOut.nProfiles | |||
|
1271 | ||||
1265 | if plot == 'spc': |
|
1272 | if plot == 'spc': | |
1266 | self.data['spc'] = buffer |
|
1273 | self.data['spc'] = buffer | |
1267 | elif plot == 'cspc': |
|
1274 | elif plot == 'cspc': | |
1268 | self.data['spc'] = buffer[0] |
|
1275 | self.data['spc'] = buffer[0] | |
1269 | self.data['cspc'] = buffer[1] |
|
1276 | self.data['cspc'] = buffer[1] | |
1270 | elif plot == 'spc_moments': |
|
1277 | elif plot == 'spc_moments': | |
1271 | self.data['spc'] = buffer |
|
1278 | self.data['spc'] = buffer | |
1272 | self.data['moments'][tm] = dataOut.moments |
|
1279 | self.data['moments'][tm] = dataOut.moments | |
1273 | else: |
|
1280 | else: | |
1274 | if self.buffering: |
|
1281 | if self.buffering: | |
1275 | self.data[plot][tm] = buffer |
|
1282 | self.data[plot][tm] = buffer | |
1276 | else: |
|
1283 | else: | |
1277 | self.data[plot] = buffer |
|
1284 | self.data[plot] = buffer | |
1278 |
|
1285 | |||
1279 | if dataOut.channelList is None: |
|
1286 | if dataOut.channelList is None: | |
1280 | self.channels = range(buffer.shape[0]) |
|
1287 | self.channels = range(buffer.shape[0]) | |
1281 | else: |
|
1288 | else: | |
1282 | self.channels = dataOut.channelList |
|
1289 | self.channels = dataOut.channelList | |
1283 |
|
1290 | |||
1284 | if buffer is None: |
|
1291 | if buffer is None: | |
1285 | self.flagNoData = True |
|
1292 | self.flagNoData = True | |
1286 |
raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key)) |
|
1293 | raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key)) | |
1287 |
|
1294 | |||
1288 | def normalize_heights(self): |
|
1295 | def normalize_heights(self): | |
1289 | ''' |
|
1296 | ''' | |
1290 | Ensure same-dimension of the data for different heighList |
|
1297 | Ensure same-dimension of the data for different heighList | |
1291 | ''' |
|
1298 | ''' | |
1292 |
|
1299 | |||
1293 | H = numpy.array(list(self.__all_heights)) |
|
1300 | H = numpy.array(list(self.__all_heights)) | |
1294 | H.sort() |
|
1301 | H.sort() | |
1295 | for key in self.data: |
|
1302 | for key in self.data: | |
1296 | shape = self.shape(key)[:-1] + H.shape |
|
1303 | shape = self.shape(key)[:-1] + H.shape | |
1297 | for tm, obj in list(self.data[key].items()): |
|
1304 | for tm, obj in list(self.data[key].items()): | |
1298 | h = self.__heights[self.__times.index(tm)] |
|
1305 | h = self.__heights[self.__times.index(tm)] | |
1299 | if H.size == h.size: |
|
1306 | if H.size == h.size: | |
1300 | continue |
|
1307 | continue | |
1301 | index = numpy.where(numpy.in1d(H, h))[0] |
|
1308 | index = numpy.where(numpy.in1d(H, h))[0] | |
1302 | dummy = numpy.zeros(shape) + numpy.nan |
|
1309 | dummy = numpy.zeros(shape) + numpy.nan | |
1303 | if len(shape) == 2: |
|
1310 | if len(shape) == 2: | |
1304 | dummy[:, index] = obj |
|
1311 | dummy[:, index] = obj | |
1305 | else: |
|
1312 | else: | |
1306 | dummy[index] = obj |
|
1313 | dummy[index] = obj | |
1307 | self.data[key][tm] = dummy |
|
1314 | self.data[key][tm] = dummy | |
1308 |
|
1315 | |||
1309 | self.__heights = [H for tm in self.__times] |
|
1316 | self.__heights = [H for tm in self.__times] | |
1310 |
|
1317 | |||
1311 | def jsonify(self, plot_name, plot_type, decimate=False): |
|
1318 | def jsonify(self, plot_name, plot_type, decimate=False): | |
1312 | ''' |
|
1319 | ''' | |
1313 | Convert data to json |
|
1320 | Convert data to json | |
1314 | ''' |
|
1321 | ''' | |
1315 |
|
1322 | |||
1316 | tm = self.times[-1] |
|
1323 | tm = self.times[-1] | |
1317 | dy = int(self.heights.size/self.MAXNUMY) + 1 |
|
1324 | dy = int(self.heights.size/self.MAXNUMY) + 1 | |
1318 | if self.key in ('spc', 'cspc') or not self.buffering: |
|
1325 | if self.key in ('spc', 'cspc') or not self.buffering: | |
1319 | dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1 |
|
1326 | dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1 | |
1320 | data = self.roundFloats( |
|
1327 | data = self.roundFloats( | |
1321 | self.data[self.key][::, ::dx, ::dy].tolist()) |
|
1328 | self.data[self.key][::, ::dx, ::dy].tolist()) | |
1322 | else: |
|
1329 | else: | |
1323 | data = self.roundFloats(self.data[self.key][tm].tolist()) |
|
1330 | data = self.roundFloats(self.data[self.key][tm].tolist()) | |
1324 | if self.key is 'noise': |
|
1331 | if self.key is 'noise': | |
1325 | data = [[x] for x in data] |
|
1332 | data = [[x] for x in data] | |
1326 |
|
1333 | |||
1327 | meta = {} |
|
1334 | meta = {} | |
1328 | ret = { |
|
1335 | ret = { | |
1329 | 'plot': plot_name, |
|
1336 | 'plot': plot_name, | |
1330 | 'code': self.exp_code, |
|
1337 | 'code': self.exp_code, | |
1331 | 'time': float(tm), |
|
1338 | 'time': float(tm), | |
1332 | 'data': data, |
|
1339 | 'data': data, | |
1333 | } |
|
1340 | } | |
1334 | meta['type'] = plot_type |
|
1341 | meta['type'] = plot_type | |
1335 | meta['interval'] = float(self.interval) |
|
1342 | meta['interval'] = float(self.interval) | |
1336 | meta['localtime'] = self.localtime |
|
1343 | meta['localtime'] = self.localtime | |
1337 | meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) |
|
1344 | meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) | |
1338 | if 'spc' in self.data or 'cspc' in self.data: |
|
1345 | if 'spc' in self.data or 'cspc' in self.data: | |
1339 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) |
|
1346 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) | |
1340 | else: |
|
1347 | else: | |
1341 | meta['xrange'] = [] |
|
1348 | meta['xrange'] = [] | |
1342 |
|
1349 | |||
1343 |
meta.update(self.meta) |
|
1350 | meta.update(self.meta) | |
1344 | ret['metadata'] = meta |
|
1351 | ret['metadata'] = meta | |
1345 | return json.dumps(ret) |
|
1352 | return json.dumps(ret) | |
1346 |
|
1353 | |||
1347 | @property |
|
1354 | @property | |
1348 | def times(self): |
|
1355 | def times(self): | |
1349 | ''' |
|
1356 | ''' | |
1350 | Return the list of times of the current data |
|
1357 | Return the list of times of the current data | |
1351 | ''' |
|
1358 | ''' | |
1352 |
|
1359 | |||
1353 | ret = numpy.array(self.__times) |
|
1360 | ret = numpy.array(self.__times) | |
1354 | ret.sort() |
|
1361 | ret.sort() | |
1355 | return ret |
|
1362 | return ret | |
1356 |
|
1363 | |||
1357 | @property |
|
1364 | @property | |
1358 | def min_time(self): |
|
1365 | def min_time(self): | |
1359 | ''' |
|
1366 | ''' | |
1360 | Return the minimun time value |
|
1367 | Return the minimun time value | |
1361 | ''' |
|
1368 | ''' | |
1362 |
|
1369 | |||
1363 | return self.times[0] |
|
1370 | return self.times[0] | |
1364 |
|
1371 | |||
1365 | @property |
|
1372 | @property | |
1366 | def max_time(self): |
|
1373 | def max_time(self): | |
1367 | ''' |
|
1374 | ''' | |
1368 | Return the maximun time value |
|
1375 | Return the maximun time value | |
1369 | ''' |
|
1376 | ''' | |
1370 |
|
1377 | |||
1371 | return self.times[-1] |
|
1378 | return self.times[-1] | |
1372 |
|
1379 | |||
1373 | @property |
|
1380 | @property | |
1374 | def heights(self): |
|
1381 | def heights(self): | |
1375 | ''' |
|
1382 | ''' | |
1376 | Return the list of heights of the current data |
|
1383 | Return the list of heights of the current data | |
1377 | ''' |
|
1384 | ''' | |
1378 |
|
1385 | |||
1379 | return numpy.array(self.__heights[-1]) |
|
1386 | return numpy.array(self.__heights[-1]) | |
1380 |
|
1387 | |||
1381 | @staticmethod |
|
1388 | @staticmethod | |
1382 | def roundFloats(obj): |
|
1389 | def roundFloats(obj): | |
1383 | if isinstance(obj, list): |
|
1390 | if isinstance(obj, list): | |
1384 | return list(map(PlotterData.roundFloats, obj)) |
|
1391 | return list(map(PlotterData.roundFloats, obj)) | |
1385 | elif isinstance(obj, float): |
|
1392 | elif isinstance(obj, float): | |
1386 | return round(obj, 2) |
|
1393 | return round(obj, 2) |
@@ -1,134 +1,233 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 9, 2014 |
|
2 | Created on Jul 9, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import datetime |
|
7 | import datetime | |
8 | import numpy |
|
8 | import numpy | |
9 |
|
9 | |||
10 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
10 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class ScopePlot(Plot): |
|
13 | class ScopePlot(Plot): | |
14 |
|
14 | |||
15 | ''' |
|
15 | ''' | |
16 | Plot for Scope |
|
16 | Plot for Scope | |
17 |
''' |
|
17 | ''' | |
18 |
|
18 | |||
19 | CODE = 'scope' |
|
19 | CODE = 'scope' | |
20 | plot_name = 'Scope' |
|
20 | plot_name = 'Scope' | |
21 | plot_type = 'scatter' |
|
21 | plot_type = 'scatter' | |
22 |
|
22 | |||
23 | def setup(self): |
|
23 | def setup(self): | |
24 |
|
24 | |||
25 | self.xaxis = 'Range (Km)' |
|
25 | self.xaxis = 'Range (Km)' | |
26 | self.ncols = 1 |
|
26 | self.ncols = 1 | |
27 | self.nrows = 1 |
|
27 | self.nrows = 1 | |
28 | self.nplots = 1 |
|
28 | self.nplots = 1 | |
29 | self.ylabel = 'Intensity [dB]' |
|
29 | self.ylabel = 'Intensity [dB]' | |
30 | self.titles = ['Scope'] |
|
30 | self.titles = ['Scope'] | |
31 | self.colorbar = False |
|
31 | self.colorbar = False | |
32 | self.width = 6 |
|
32 | self.width = 6 | |
33 | self.height = 4 |
|
33 | self.height = 4 | |
34 |
|
34 | |||
35 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
35 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): | |
36 |
|
36 | |||
37 | yreal = y[channelIndexList,:].real |
|
37 | yreal = y[channelIndexList,:].real | |
38 | yimag = y[channelIndexList,:].imag |
|
38 | yimag = y[channelIndexList,:].imag | |
39 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
39 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
40 | self.xlabel = "Range (Km)" |
|
40 | self.xlabel = "Range (Km)" | |
41 | self.ylabel = "Intensity - IQ" |
|
41 | self.ylabel = "Intensity - IQ" | |
42 |
|
42 | |||
43 | self.y = yreal |
|
43 | self.y = yreal | |
44 | self.x = x |
|
44 | self.x = x | |
45 | self.xmin = min(x) |
|
45 | self.xmin = min(x) | |
46 | self.xmax = max(x) |
|
46 | self.xmax = max(x) | |
47 |
|
||||
48 |
|
47 | |||
49 | self.titles[0] = title |
|
48 | ||
|
49 | self.titles[0] = title | |||
50 |
|
50 | |||
51 | for i,ax in enumerate(self.axes): |
|
51 | for i,ax in enumerate(self.axes): | |
52 | title = "Channel %d" %(i) |
|
52 | title = "Channel %d" %(i) | |
53 | if ax.firsttime: |
|
53 | if ax.firsttime: | |
54 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] |
|
54 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] | |
55 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] |
|
55 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] | |
56 | else: |
|
56 | else: | |
57 | ax.plt_r.set_data(x, yreal[i,:]) |
|
57 | ax.plt_r.set_data(x, yreal[i,:]) | |
58 | ax.plt_i.set_data(x, yimag[i,:]) |
|
58 | ax.plt_i.set_data(x, yimag[i,:]) | |
59 |
|
59 | |||
60 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
60 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): | |
61 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
61 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | |
62 | yreal = y.real |
|
62 | yreal = y.real | |
|
63 | yreal = 10*numpy.log10(yreal) | |||
63 | self.y = yreal |
|
64 | self.y = yreal | |
64 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
65 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
65 | self.xlabel = "Range (Km)" |
|
66 | self.xlabel = "Range (Km)" | |
66 | self.ylabel = "Intensity" |
|
67 | self.ylabel = "Intensity" | |
67 | self.xmin = min(x) |
|
68 | self.xmin = min(x) | |
68 | self.xmax = max(x) |
|
69 | self.xmax = max(x) | |
69 |
|
70 | |||
70 |
|
71 | |||
71 | self.titles[0] = title |
|
72 | self.titles[0] = title | |
72 |
|
73 | |||
73 | for i,ax in enumerate(self.axes): |
|
74 | for i,ax in enumerate(self.axes): | |
74 | title = "Channel %d" %(i) |
|
75 | title = "Channel %d" %(i) | |
75 |
|
76 | |||
76 | ychannel = yreal[i,:] |
|
77 | ychannel = yreal[i,:] | |
77 |
|
78 | |||
78 |
if ax.firsttime: |
|
79 | if ax.firsttime: | |
79 | ax.plt_r = ax.plot(x, ychannel)[0] |
|
80 | ax.plt_r = ax.plot(x, ychannel)[0] | |
80 | else: |
|
81 | else: | |
81 | #pass |
|
82 | #pass | |
82 | ax.plt_r.set_data(x, ychannel) |
|
83 | ax.plt_r.set_data(x, ychannel) | |
83 |
|
84 | |||
|
85 | def plot_weatherpower(self, x, y, channelIndexList, thisDatetime, wintitle): | |||
|
86 | ||||
|
87 | ||||
|
88 | y = y[channelIndexList,:] | |||
|
89 | yreal = y.real | |||
|
90 | yreal = 10*numpy.log10(yreal) | |||
|
91 | self.y = yreal | |||
|
92 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
93 | self.xlabel = "Range (Km)" | |||
|
94 | self.ylabel = "Intensity" | |||
|
95 | self.xmin = min(x) | |||
|
96 | self.xmax = max(x) | |||
|
97 | ||||
|
98 | self.titles[0] =title | |||
|
99 | for i,ax in enumerate(self.axes): | |||
|
100 | title = "Channel %d" %(i) | |||
|
101 | ||||
|
102 | ychannel = yreal[i,:] | |||
|
103 | ||||
|
104 | if ax.firsttime: | |||
|
105 | ax.plt_r = ax.plot(x, ychannel)[0] | |||
|
106 | else: | |||
|
107 | #pass | |||
|
108 | ax.plt_r.set_data(x, ychannel) | |||
|
109 | ||||
|
110 | def plot_weathervelocity(self, x, y, channelIndexList, thisDatetime, wintitle): | |||
|
111 | ||||
|
112 | x = x[channelIndexList,:] | |||
|
113 | yreal = y | |||
|
114 | self.y = yreal | |||
|
115 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
116 | self.xlabel = "Velocity (m/s)" | |||
|
117 | self.ylabel = "Range (Km)" | |||
|
118 | self.xmin = numpy.min(x) | |||
|
119 | self.xmax = numpy.max(x) | |||
|
120 | self.titles[0] =title | |||
|
121 | for i,ax in enumerate(self.axes): | |||
|
122 | title = "Channel %d" %(i) | |||
|
123 | xchannel = x[i,:] | |||
|
124 | if ax.firsttime: | |||
|
125 | ax.plt_r = ax.plot(xchannel, yreal)[0] | |||
|
126 | else: | |||
|
127 | #pass | |||
|
128 | ax.plt_r.set_data(xchannel, yreal) | |||
84 |
|
129 | |||
85 | def plot(self): |
|
130 | def plot(self): | |
86 |
|
||||
87 | if self.channels: |
|
131 | if self.channels: | |
88 | channels = self.channels |
|
132 | channels = self.channels | |
89 | else: |
|
133 | else: | |
90 | channels = self.data.channels |
|
134 | channels = self.data.channels | |
91 |
|
135 | |||
92 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) |
|
136 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) | |
93 |
|
137 | if self.CODE == "pp_power": | ||
94 |
scope = self.data[' |
|
138 | scope = self.data['pp_power'] | |
95 |
|
139 | elif self.CODE == "pp_velocity": | ||
|
140 | scope = self.data["pp_velocity"] | |||
|
141 | else: | |||
|
142 | scope =self.data["scope"] | |||
|
143 | ||||
96 | if self.data.flagDataAsBlock: |
|
144 | if self.data.flagDataAsBlock: | |
97 |
|
145 | |||
98 | for i in range(self.data.nProfiles): |
|
146 | for i in range(self.data.nProfiles): | |
99 |
|
147 | |||
100 | wintitle1 = " [Profile = %d] " %i |
|
148 | wintitle1 = " [Profile = %d] " %i | |
101 |
|
149 | if self.CODE =="scope": | ||
102 | if self.type == "power": |
|
150 | if self.type == "power": | |
103 |
self.plot_power(self.data.heights, |
|
151 | self.plot_power(self.data.heights, | |
104 |
scope[:,i,:], |
|
152 | scope[:,i,:], | |
105 | channels, |
|
153 | channels, | |
106 |
thisDatetime, |
|
154 | thisDatetime, | |
107 | wintitle1 |
|
155 | wintitle1 | |
|
156 | ) | |||
|
157 | ||||
|
158 | if self.type == "iq": | |||
|
159 | self.plot_iq(self.data.heights, | |||
|
160 | scope[:,i,:], | |||
|
161 | channels, | |||
|
162 | thisDatetime, | |||
|
163 | wintitle1 | |||
108 | ) |
|
164 | ) | |
|
165 | if self.CODE=="pp_power": | |||
|
166 | self.plot_weatherpower(self.data.heights, | |||
|
167 | scope[:,i,:], | |||
|
168 | channels, | |||
|
169 | thisDatetime, | |||
|
170 | wintitle | |||
|
171 | ) | |||
|
172 | if self.CODE=="pp_velocity": | |||
|
173 | self.plot_weathervelocity(scope[:,i,:], | |||
|
174 | self.data.heights, | |||
|
175 | channels, | |||
|
176 | thisDatetime, | |||
|
177 | wintitle | |||
|
178 | ) | |||
|
179 | else: | |||
|
180 | wintitle = " [Profile = %d] " %self.data.profileIndex | |||
|
181 | if self.CODE== "scope": | |||
|
182 | if self.type == "power": | |||
|
183 | self.plot_power(self.data.heights, | |||
|
184 | scope, | |||
|
185 | channels, | |||
|
186 | thisDatetime, | |||
|
187 | wintitle | |||
|
188 | ) | |||
109 |
|
189 | |||
110 | if self.type == "iq": |
|
190 | if self.type == "iq": | |
111 |
self.plot_iq(self.data.heights, |
|
191 | self.plot_iq(self.data.heights, | |
112 |
|
|
192 | scope, | |
113 |
|
|
193 | channels, | |
114 |
|
|
194 | thisDatetime, | |
115 |
|
|
195 | wintitle | |
116 | ) |
|
196 | ) | |
117 | else: |
|
197 | if self.CODE=="pp_power": | |
118 | wintitle = " [Profile = %d] " %self.data.profileIndex |
|
198 | self.plot_weatherpower(self.data.heights, | |
119 |
|
199 | scope, | ||
120 | if self.type == "power": |
|
200 | channels, | |
121 | self.plot_power(self.data.heights, |
|
201 | thisDatetime, | |
122 |
|
|
202 | wintitle | |
123 |
|
|
203 | ) | |
124 | thisDatetime, |
|
204 | if self.CODE=="pp_velocity": | |
125 | wintitle |
|
205 | self.plot_weathervelocity(scope, | |
126 |
|
|
206 | self.data.heights, | |
127 |
|
207 | channels, | ||
128 | if self.type == "iq": |
|
208 | thisDatetime, | |
129 | self.plot_iq(self.data.heights, |
|
209 | wintitle | |
130 |
|
|
210 | ) | |
131 | channels, |
|
211 | ||
132 | thisDatetime, |
|
212 | ||
133 | wintitle |
|
213 | ||
134 | ) |
|
214 | class PulsepairPowerPlot(ScopePlot): | |
|
215 | ''' | |||
|
216 | Plot for | |||
|
217 | ''' | |||
|
218 | ||||
|
219 | CODE = 'pp_power' | |||
|
220 | plot_name = 'PulsepairPower' | |||
|
221 | plot_type = 'scatter' | |||
|
222 | buffering = False | |||
|
223 | ||||
|
224 | ||||
|
225 | ||||
|
226 | class PulsepairVelocityPlot(ScopePlot): | |||
|
227 | ''' | |||
|
228 | Plot for | |||
|
229 | ''' | |||
|
230 | CODE = 'pp_velocity' | |||
|
231 | plot_name = 'PulsepairVelocity' | |||
|
232 | plot_type = 'scatter' | |||
|
233 | buffering = False |
@@ -1,1409 +1,1557 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy |
|
2 | import numpy,math | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
5 | from schainpy.model.data.jrodata import Voltage |
|
5 | from schainpy.model.data.jrodata import Voltage | |
6 | from schainpy.utils import log |
|
6 | from schainpy.utils import log | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 |
|
9 | |||
10 |
|
10 | |||
11 |
class VoltageProc(ProcessingUnit): |
|
11 | class VoltageProc(ProcessingUnit): | |
12 |
|
12 | |||
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 |
|
14 | |||
15 | ProcessingUnit.__init__(self) |
|
15 | ProcessingUnit.__init__(self) | |
16 |
|
16 | |||
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 | self.setupReq = False |
|
19 | self.setupReq = False | |
20 |
|
20 | |||
21 | def run(self): |
|
21 | def run(self): | |
22 |
|
22 | |||
23 | if self.dataIn.type == 'AMISR': |
|
23 | if self.dataIn.type == 'AMISR': | |
24 | self.__updateObjFromAmisrInput() |
|
24 | self.__updateObjFromAmisrInput() | |
25 |
|
25 | |||
26 | if self.dataIn.type == 'Voltage': |
|
26 | if self.dataIn.type == 'Voltage': | |
27 | self.dataOut.copy(self.dataIn) |
|
27 | self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | def __updateObjFromAmisrInput(self): |
|
29 | def __updateObjFromAmisrInput(self): | |
30 |
|
30 | |||
31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
31 | self.dataOut.timeZone = self.dataIn.timeZone | |
32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
32 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
33 | self.dataOut.errorCount = self.dataIn.errorCount | |
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
35 |
|
35 | |||
36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
36 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
37 | self.dataOut.data = self.dataIn.data |
|
37 | self.dataOut.data = self.dataIn.data | |
38 | self.dataOut.utctime = self.dataIn.utctime |
|
38 | self.dataOut.utctime = self.dataIn.utctime | |
39 | self.dataOut.channelList = self.dataIn.channelList |
|
39 | self.dataOut.channelList = self.dataIn.channelList | |
40 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
40 | #self.dataOut.timeInterval = self.dataIn.timeInterval | |
41 | self.dataOut.heightList = self.dataIn.heightList |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
42 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
43 |
|
43 | |||
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
46 | self.dataOut.frequency = self.dataIn.frequency |
|
46 | self.dataOut.frequency = self.dataIn.frequency | |
47 |
|
47 | |||
48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
48 | self.dataOut.azimuth = self.dataIn.azimuth | |
49 | self.dataOut.zenith = self.dataIn.zenith |
|
49 | self.dataOut.zenith = self.dataIn.zenith | |
50 |
|
50 | |||
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | class selectChannels(Operation): |
|
56 | class selectChannels(Operation): | |
57 |
|
57 | |||
58 | def run(self, dataOut, channelList): |
|
58 | def run(self, dataOut, channelList): | |
59 |
|
59 | |||
60 | channelIndexList = [] |
|
60 | channelIndexList = [] | |
61 | self.dataOut = dataOut |
|
61 | self.dataOut = dataOut | |
62 |
|
||||
63 | for channel in channelList: |
|
62 | for channel in channelList: | |
64 | if channel not in self.dataOut.channelList: |
|
63 | if channel not in self.dataOut.channelList: | |
65 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) | |
66 |
|
65 | |||
67 | index = self.dataOut.channelList.index(channel) |
|
66 | index = self.dataOut.channelList.index(channel) | |
68 | channelIndexList.append(index) |
|
67 | channelIndexList.append(index) | |
69 |
|
||||
70 | self.selectChannelsByIndex(channelIndexList) |
|
68 | self.selectChannelsByIndex(channelIndexList) | |
71 | return self.dataOut |
|
69 | return self.dataOut | |
72 |
|
70 | |||
73 | def selectChannelsByIndex(self, channelIndexList): |
|
71 | def selectChannelsByIndex(self, channelIndexList): | |
74 | """ |
|
72 | """ | |
75 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
73 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
76 |
|
74 | |||
77 | Input: |
|
75 | Input: | |
78 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
79 |
|
77 | |||
80 | Affected: |
|
78 | Affected: | |
81 | self.dataOut.data |
|
79 | self.dataOut.data | |
82 | self.dataOut.channelIndexList |
|
80 | self.dataOut.channelIndexList | |
83 | self.dataOut.nChannels |
|
81 | self.dataOut.nChannels | |
84 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
82 | self.dataOut.m_ProcessingHeader.totalSpectra | |
85 | self.dataOut.systemHeaderObj.numChannels |
|
83 | self.dataOut.systemHeaderObj.numChannels | |
86 | self.dataOut.m_ProcessingHeader.blockSize |
|
84 | self.dataOut.m_ProcessingHeader.blockSize | |
87 |
|
85 | |||
88 | Return: |
|
86 | Return: | |
89 | None |
|
87 | None | |
90 | """ |
|
88 | """ | |
91 |
|
89 | |||
92 | for channelIndex in channelIndexList: |
|
90 | for channelIndex in channelIndexList: | |
93 | if channelIndex not in self.dataOut.channelIndexList: |
|
91 | if channelIndex not in self.dataOut.channelIndexList: | |
94 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) | |
95 |
|
93 | |||
96 | if self.dataOut.type == 'Voltage': |
|
94 | if self.dataOut.type == 'Voltage': | |
97 | if self.dataOut.flagDataAsBlock: |
|
95 | if self.dataOut.flagDataAsBlock: | |
98 | """ |
|
96 | """ | |
99 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
100 | """ |
|
98 | """ | |
101 | data = self.dataOut.data[channelIndexList,:,:] |
|
99 | data = self.dataOut.data[channelIndexList,:,:] | |
102 | else: |
|
100 | else: | |
103 | data = self.dataOut.data[channelIndexList,:] |
|
101 | data = self.dataOut.data[channelIndexList,:] | |
104 |
|
102 | |||
105 | self.dataOut.data = data |
|
103 | self.dataOut.data = data | |
106 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
107 | self.dataOut.channelList = range(len(channelIndexList)) |
|
105 | self.dataOut.channelList = range(len(channelIndexList)) | |
|
106 | ||||
108 | elif self.dataOut.type == 'Spectra': |
|
107 | elif self.dataOut.type == 'Spectra': | |
109 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
108 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
110 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
109 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
111 |
|
110 | |||
112 | self.dataOut.data_spc = data_spc |
|
111 | self.dataOut.data_spc = data_spc | |
113 | self.dataOut.data_dc = data_dc |
|
112 | self.dataOut.data_dc = data_dc | |
114 |
|
113 | |||
115 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
116 | self.dataOut.channelList = range(len(channelIndexList)) |
|
115 | self.dataOut.channelList = range(len(channelIndexList)) | |
117 | self.__selectPairsByChannel(channelIndexList) |
|
116 | self.__selectPairsByChannel(channelIndexList) | |
118 |
|
117 | |||
119 | return 1 |
|
118 | return 1 | |
120 |
|
119 | |||
121 | def __selectPairsByChannel(self, channelList=None): |
|
120 | def __selectPairsByChannel(self, channelList=None): | |
122 |
|
121 | |||
123 | if channelList == None: |
|
122 | if channelList == None: | |
124 | return |
|
123 | return | |
125 |
|
124 | |||
126 | pairsIndexListSelected = [] |
|
125 | pairsIndexListSelected = [] | |
127 | for pairIndex in self.dataOut.pairsIndexList: |
|
126 | for pairIndex in self.dataOut.pairsIndexList: | |
128 | # First pair |
|
127 | # First pair | |
129 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
130 | continue |
|
129 | continue | |
131 | # Second pair |
|
130 | # Second pair | |
132 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
133 | continue |
|
132 | continue | |
134 |
|
133 | |||
135 | pairsIndexListSelected.append(pairIndex) |
|
134 | pairsIndexListSelected.append(pairIndex) | |
136 |
|
135 | |||
137 | if not pairsIndexListSelected: |
|
136 | if not pairsIndexListSelected: | |
138 | self.dataOut.data_cspc = None |
|
137 | self.dataOut.data_cspc = None | |
139 | self.dataOut.pairsList = [] |
|
138 | self.dataOut.pairsList = [] | |
140 | return |
|
139 | return | |
141 |
|
140 | |||
142 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
143 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
144 | for i in pairsIndexListSelected] |
|
143 | for i in pairsIndexListSelected] | |
145 |
|
144 | |||
146 | return |
|
145 | return | |
147 |
|
146 | |||
148 | class selectHeights(Operation): |
|
147 | class selectHeights(Operation): | |
149 |
|
148 | |||
150 | def run(self, dataOut, minHei=None, maxHei=None): |
|
149 | def run(self, dataOut, minHei=None, maxHei=None): | |
151 | """ |
|
150 | """ | |
152 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
153 | minHei <= height <= maxHei |
|
152 | minHei <= height <= maxHei | |
154 |
|
153 | |||
155 | Input: |
|
154 | Input: | |
156 | minHei : valor minimo de altura a considerar |
|
155 | minHei : valor minimo de altura a considerar | |
157 | maxHei : valor maximo de altura a considerar |
|
156 | maxHei : valor maximo de altura a considerar | |
158 |
|
157 | |||
159 | Affected: |
|
158 | Affected: | |
160 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
161 |
|
160 | |||
162 | Return: |
|
161 | Return: | |
163 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
164 | """ |
|
163 | """ | |
165 |
|
164 | |||
166 | self.dataOut = dataOut |
|
165 | self.dataOut = dataOut | |
167 |
|
166 | |||
168 | if minHei == None: |
|
167 | if minHei == None: | |
169 | minHei = self.dataOut.heightList[0] |
|
168 | minHei = self.dataOut.heightList[0] | |
170 |
|
169 | |||
171 | if maxHei == None: |
|
170 | if maxHei == None: | |
172 | maxHei = self.dataOut.heightList[-1] |
|
171 | maxHei = self.dataOut.heightList[-1] | |
173 |
|
172 | |||
174 | if (minHei < self.dataOut.heightList[0]): |
|
173 | if (minHei < self.dataOut.heightList[0]): | |
175 | minHei = self.dataOut.heightList[0] |
|
174 | minHei = self.dataOut.heightList[0] | |
176 |
|
175 | |||
177 | if (maxHei > self.dataOut.heightList[-1]): |
|
176 | if (maxHei > self.dataOut.heightList[-1]): | |
178 | maxHei = self.dataOut.heightList[-1] |
|
177 | maxHei = self.dataOut.heightList[-1] | |
179 |
|
178 | |||
180 | minIndex = 0 |
|
179 | minIndex = 0 | |
181 | maxIndex = 0 |
|
180 | maxIndex = 0 | |
182 | heights = self.dataOut.heightList |
|
181 | heights = self.dataOut.heightList | |
183 |
|
182 | |||
184 | inda = numpy.where(heights >= minHei) |
|
183 | inda = numpy.where(heights >= minHei) | |
185 | indb = numpy.where(heights <= maxHei) |
|
184 | indb = numpy.where(heights <= maxHei) | |
186 |
|
185 | |||
187 | try: |
|
186 | try: | |
188 | minIndex = inda[0][0] |
|
187 | minIndex = inda[0][0] | |
189 | except: |
|
188 | except: | |
190 | minIndex = 0 |
|
189 | minIndex = 0 | |
191 |
|
190 | |||
192 | try: |
|
191 | try: | |
193 | maxIndex = indb[0][-1] |
|
192 | maxIndex = indb[0][-1] | |
194 | except: |
|
193 | except: | |
195 | maxIndex = len(heights) |
|
194 | maxIndex = len(heights) | |
196 |
|
195 | |||
197 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
196 | self.selectHeightsByIndex(minIndex, maxIndex) | |
198 |
|
197 | |||
199 | return self.dataOut |
|
198 | return self.dataOut | |
200 |
|
199 | |||
201 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
200 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
202 | """ |
|
201 | """ | |
203 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
202 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
204 | minIndex <= index <= maxIndex |
|
203 | minIndex <= index <= maxIndex | |
205 |
|
204 | |||
206 | Input: |
|
205 | Input: | |
207 | minIndex : valor de indice minimo de altura a considerar |
|
206 | minIndex : valor de indice minimo de altura a considerar | |
208 | maxIndex : valor de indice maximo de altura a considerar |
|
207 | maxIndex : valor de indice maximo de altura a considerar | |
209 |
|
208 | |||
210 | Affected: |
|
209 | Affected: | |
211 | self.dataOut.data |
|
210 | self.dataOut.data | |
212 | self.dataOut.heightList |
|
211 | self.dataOut.heightList | |
213 |
|
212 | |||
214 | Return: |
|
213 | Return: | |
215 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
214 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
216 | """ |
|
215 | """ | |
217 |
|
216 | |||
218 | if self.dataOut.type == 'Voltage': |
|
217 | if self.dataOut.type == 'Voltage': | |
219 | if (minIndex < 0) or (minIndex > maxIndex): |
|
218 | if (minIndex < 0) or (minIndex > maxIndex): | |
220 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
219 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
221 |
|
220 | |||
222 | if (maxIndex >= self.dataOut.nHeights): |
|
221 | if (maxIndex >= self.dataOut.nHeights): | |
223 | maxIndex = self.dataOut.nHeights |
|
222 | maxIndex = self.dataOut.nHeights | |
224 |
|
223 | |||
225 | #voltage |
|
224 | #voltage | |
226 | if self.dataOut.flagDataAsBlock: |
|
225 | if self.dataOut.flagDataAsBlock: | |
227 | """ |
|
226 | """ | |
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
227 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
229 | """ |
|
228 | """ | |
230 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
229 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
231 | else: |
|
230 | else: | |
232 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
231 | data = self.dataOut.data[:, minIndex:maxIndex] | |
233 |
|
232 | |||
234 | # firstHeight = self.dataOut.heightList[minIndex] |
|
233 | # firstHeight = self.dataOut.heightList[minIndex] | |
235 |
|
234 | |||
236 | self.dataOut.data = data |
|
235 | self.dataOut.data = data | |
237 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
236 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
238 |
|
237 | |||
239 | if self.dataOut.nHeights <= 1: |
|
238 | if self.dataOut.nHeights <= 1: | |
240 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
239 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) | |
241 | elif self.dataOut.type == 'Spectra': |
|
240 | elif self.dataOut.type == 'Spectra': | |
242 | if (minIndex < 0) or (minIndex > maxIndex): |
|
241 | if (minIndex < 0) or (minIndex > maxIndex): | |
243 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
242 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
244 | minIndex, maxIndex)) |
|
243 | minIndex, maxIndex)) | |
245 |
|
244 | |||
246 | if (maxIndex >= self.dataOut.nHeights): |
|
245 | if (maxIndex >= self.dataOut.nHeights): | |
247 | maxIndex = self.dataOut.nHeights - 1 |
|
246 | maxIndex = self.dataOut.nHeights - 1 | |
248 |
|
247 | |||
249 | # Spectra |
|
248 | # Spectra | |
250 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
249 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
251 |
|
250 | |||
252 | data_cspc = None |
|
251 | data_cspc = None | |
253 | if self.dataOut.data_cspc is not None: |
|
252 | if self.dataOut.data_cspc is not None: | |
254 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
253 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
255 |
|
254 | |||
256 | data_dc = None |
|
255 | data_dc = None | |
257 | if self.dataOut.data_dc is not None: |
|
256 | if self.dataOut.data_dc is not None: | |
258 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
257 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
259 |
|
258 | |||
260 | self.dataOut.data_spc = data_spc |
|
259 | self.dataOut.data_spc = data_spc | |
261 | self.dataOut.data_cspc = data_cspc |
|
260 | self.dataOut.data_cspc = data_cspc | |
262 | self.dataOut.data_dc = data_dc |
|
261 | self.dataOut.data_dc = data_dc | |
263 |
|
262 | |||
264 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
263 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
265 |
|
264 | |||
266 | return 1 |
|
265 | return 1 | |
267 |
|
266 | |||
268 |
|
267 | |||
269 | class filterByHeights(Operation): |
|
268 | class filterByHeights(Operation): | |
270 |
|
269 | |||
271 | def run(self, dataOut, window): |
|
270 | def run(self, dataOut, window): | |
272 |
|
271 | |||
273 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
272 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
274 |
|
273 | |||
275 | if window == None: |
|
274 | if window == None: | |
276 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
275 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
277 |
|
276 | |||
278 | newdelta = deltaHeight * window |
|
277 | newdelta = deltaHeight * window | |
279 | r = dataOut.nHeights % window |
|
278 | r = dataOut.nHeights % window | |
280 | newheights = (dataOut.nHeights-r)/window |
|
279 | newheights = (dataOut.nHeights-r)/window | |
281 |
|
280 | |||
282 | if newheights <= 1: |
|
281 | if newheights <= 1: | |
283 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
282 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) | |
284 |
|
283 | |||
285 | if dataOut.flagDataAsBlock: |
|
284 | if dataOut.flagDataAsBlock: | |
286 | """ |
|
285 | """ | |
287 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
286 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
288 | """ |
|
287 | """ | |
289 |
buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
288 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] | |
290 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
289 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) | |
291 | buffer = numpy.sum(buffer,3) |
|
290 | buffer = numpy.sum(buffer,3) | |
292 |
|
291 | |||
293 | else: |
|
292 | else: | |
294 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
293 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] | |
295 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
294 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) | |
296 | buffer = numpy.sum(buffer,2) |
|
295 | buffer = numpy.sum(buffer,2) | |
297 |
|
296 | |||
298 | dataOut.data = buffer |
|
297 | dataOut.data = buffer | |
299 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
298 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
300 | dataOut.windowOfFilter = window |
|
299 | dataOut.windowOfFilter = window | |
301 |
|
300 | |||
302 | return dataOut |
|
301 | return dataOut | |
303 |
|
302 | |||
304 |
|
303 | |||
305 | class setH0(Operation): |
|
304 | class setH0(Operation): | |
306 |
|
305 | |||
307 | def run(self, dataOut, h0, deltaHeight = None): |
|
306 | def run(self, dataOut, h0, deltaHeight = None): | |
308 |
|
307 | |||
309 | if not deltaHeight: |
|
308 | if not deltaHeight: | |
310 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
309 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
311 |
|
310 | |||
312 | nHeights = dataOut.nHeights |
|
311 | nHeights = dataOut.nHeights | |
313 |
|
312 | |||
314 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
313 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
315 |
|
314 | |||
316 | dataOut.heightList = newHeiRange |
|
315 | dataOut.heightList = newHeiRange | |
317 |
|
316 | |||
318 | return dataOut |
|
317 | return dataOut | |
319 |
|
318 | |||
320 |
|
319 | |||
321 | class deFlip(Operation): |
|
320 | class deFlip(Operation): | |
322 |
|
321 | |||
323 | def run(self, dataOut, channelList = []): |
|
322 | def run(self, dataOut, channelList = []): | |
324 |
|
323 | |||
325 | data = dataOut.data.copy() |
|
324 | data = dataOut.data.copy() | |
326 |
|
325 | |||
327 | if dataOut.flagDataAsBlock: |
|
326 | if dataOut.flagDataAsBlock: | |
328 | flip = self.flip |
|
327 | flip = self.flip | |
329 | profileList = list(range(dataOut.nProfiles)) |
|
328 | profileList = list(range(dataOut.nProfiles)) | |
330 |
|
329 | |||
331 | if not channelList: |
|
330 | if not channelList: | |
332 | for thisProfile in profileList: |
|
331 | for thisProfile in profileList: | |
333 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
332 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
334 | flip *= -1.0 |
|
333 | flip *= -1.0 | |
335 | else: |
|
334 | else: | |
336 | for thisChannel in channelList: |
|
335 | for thisChannel in channelList: | |
337 | if thisChannel not in dataOut.channelList: |
|
336 | if thisChannel not in dataOut.channelList: | |
338 | continue |
|
337 | continue | |
339 |
|
338 | |||
340 | for thisProfile in profileList: |
|
339 | for thisProfile in profileList: | |
341 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
340 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
342 | flip *= -1.0 |
|
341 | flip *= -1.0 | |
343 |
|
342 | |||
344 | self.flip = flip |
|
343 | self.flip = flip | |
345 |
|
344 | |||
346 | else: |
|
345 | else: | |
347 | if not channelList: |
|
346 | if not channelList: | |
348 | data[:,:] = data[:,:]*self.flip |
|
347 | data[:,:] = data[:,:]*self.flip | |
349 | else: |
|
348 | else: | |
350 | for thisChannel in channelList: |
|
349 | for thisChannel in channelList: | |
351 | if thisChannel not in dataOut.channelList: |
|
350 | if thisChannel not in dataOut.channelList: | |
352 | continue |
|
351 | continue | |
353 |
|
352 | |||
354 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
353 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
355 |
|
354 | |||
356 | self.flip *= -1. |
|
355 | self.flip *= -1. | |
357 |
|
356 | |||
358 | dataOut.data = data |
|
357 | dataOut.data = data | |
359 |
|
358 | |||
360 | return dataOut |
|
359 | return dataOut | |
361 |
|
360 | |||
362 |
|
361 | |||
363 | class setAttribute(Operation): |
|
362 | class setAttribute(Operation): | |
364 | ''' |
|
363 | ''' | |
365 | Set an arbitrary attribute(s) to dataOut |
|
364 | Set an arbitrary attribute(s) to dataOut | |
366 | ''' |
|
365 | ''' | |
367 |
|
366 | |||
368 | def __init__(self): |
|
367 | def __init__(self): | |
369 |
|
368 | |||
370 | Operation.__init__(self) |
|
369 | Operation.__init__(self) | |
371 | self._ready = False |
|
370 | self._ready = False | |
372 |
|
371 | |||
373 | def run(self, dataOut, **kwargs): |
|
372 | def run(self, dataOut, **kwargs): | |
374 |
|
373 | |||
375 | for key, value in kwargs.items(): |
|
374 | for key, value in kwargs.items(): | |
376 | setattr(dataOut, key, value) |
|
375 | setattr(dataOut, key, value) | |
377 |
|
376 | |||
378 | return dataOut |
|
377 | return dataOut | |
379 |
|
378 | |||
380 |
|
379 | |||
381 | class interpolateHeights(Operation): |
|
380 | class interpolateHeights(Operation): | |
382 |
|
381 | |||
383 | def run(self, dataOut, topLim, botLim): |
|
382 | def run(self, dataOut, topLim, botLim): | |
384 | #69 al 72 para julia |
|
383 | #69 al 72 para julia | |
385 | #82-84 para meteoros |
|
384 | #82-84 para meteoros | |
386 | if len(numpy.shape(dataOut.data))==2: |
|
385 | if len(numpy.shape(dataOut.data))==2: | |
387 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
386 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 | |
388 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
387 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
389 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
388 | #dataOut.data[:,botLim:limSup+1] = sampInterp | |
390 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
389 | dataOut.data[:,botLim:topLim+1] = sampInterp | |
391 | else: |
|
390 | else: | |
392 | nHeights = dataOut.data.shape[2] |
|
391 | nHeights = dataOut.data.shape[2] | |
393 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
392 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
394 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
393 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] | |
395 | f = interpolate.interp1d(x, y, axis = 2) |
|
394 | f = interpolate.interp1d(x, y, axis = 2) | |
396 | xnew = numpy.arange(botLim,topLim+1) |
|
395 | xnew = numpy.arange(botLim,topLim+1) | |
397 | ynew = f(xnew) |
|
396 | ynew = f(xnew) | |
398 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
397 | dataOut.data[:,:,botLim:topLim+1] = ynew | |
399 |
|
398 | |||
400 | return dataOut |
|
399 | return dataOut | |
401 |
|
400 | |||
402 |
|
401 | |||
403 | class CohInt(Operation): |
|
402 | class CohInt(Operation): | |
404 |
|
403 | |||
405 | isConfig = False |
|
404 | isConfig = False | |
406 | __profIndex = 0 |
|
405 | __profIndex = 0 | |
407 | __byTime = False |
|
406 | __byTime = False | |
408 | __initime = None |
|
407 | __initime = None | |
409 | __lastdatatime = None |
|
408 | __lastdatatime = None | |
410 | __integrationtime = None |
|
409 | __integrationtime = None | |
411 | __buffer = None |
|
410 | __buffer = None | |
412 | __bufferStride = [] |
|
411 | __bufferStride = [] | |
413 | __dataReady = False |
|
412 | __dataReady = False | |
414 | __profIndexStride = 0 |
|
413 | __profIndexStride = 0 | |
415 | __dataToPutStride = False |
|
414 | __dataToPutStride = False | |
416 | n = None |
|
415 | n = None | |
417 |
|
416 | |||
418 | def __init__(self, **kwargs): |
|
417 | def __init__(self, **kwargs): | |
419 |
|
418 | |||
420 | Operation.__init__(self, **kwargs) |
|
419 | Operation.__init__(self, **kwargs) | |
421 |
|
420 | |||
422 | # self.isConfig = False |
|
421 | # self.isConfig = False | |
423 |
|
422 | |||
424 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
423 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
425 | """ |
|
424 | """ | |
426 | Set the parameters of the integration class. |
|
425 | Set the parameters of the integration class. | |
427 |
|
426 | |||
428 | Inputs: |
|
427 | Inputs: | |
429 |
|
428 | |||
430 | n : Number of coherent integrations |
|
429 | n : Number of coherent integrations | |
431 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
430 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
432 | overlapping : |
|
431 | overlapping : | |
433 | """ |
|
432 | """ | |
434 |
|
433 | |||
435 | self.__initime = None |
|
434 | self.__initime = None | |
436 | self.__lastdatatime = 0 |
|
435 | self.__lastdatatime = 0 | |
437 | self.__buffer = None |
|
436 | self.__buffer = None | |
438 | self.__dataReady = False |
|
437 | self.__dataReady = False | |
439 | self.byblock = byblock |
|
438 | self.byblock = byblock | |
440 | self.stride = stride |
|
439 | self.stride = stride | |
441 |
|
440 | |||
442 | if n == None and timeInterval == None: |
|
441 | if n == None and timeInterval == None: | |
443 | raise ValueError("n or timeInterval should be specified ...") |
|
442 | raise ValueError("n or timeInterval should be specified ...") | |
444 |
|
443 | |||
445 | if n != None: |
|
444 | if n != None: | |
446 | self.n = n |
|
445 | self.n = n | |
447 | self.__byTime = False |
|
446 | self.__byTime = False | |
448 | else: |
|
447 | else: | |
449 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
448 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
450 | self.n = 9999 |
|
449 | self.n = 9999 | |
451 | self.__byTime = True |
|
450 | self.__byTime = True | |
452 |
|
451 | |||
453 | if overlapping: |
|
452 | if overlapping: | |
454 | self.__withOverlapping = True |
|
453 | self.__withOverlapping = True | |
455 | self.__buffer = None |
|
454 | self.__buffer = None | |
456 | else: |
|
455 | else: | |
457 | self.__withOverlapping = False |
|
456 | self.__withOverlapping = False | |
458 | self.__buffer = 0 |
|
457 | self.__buffer = 0 | |
459 |
|
458 | |||
460 | self.__profIndex = 0 |
|
459 | self.__profIndex = 0 | |
461 |
|
460 | |||
462 | def putData(self, data): |
|
461 | def putData(self, data): | |
463 |
|
462 | |||
464 | """ |
|
463 | """ | |
465 | Add a profile to the __buffer and increase in one the __profileIndex |
|
464 | Add a profile to the __buffer and increase in one the __profileIndex | |
466 |
|
465 | |||
467 | """ |
|
466 | """ | |
468 |
|
467 | |||
469 | if not self.__withOverlapping: |
|
468 | if not self.__withOverlapping: | |
470 | self.__buffer += data.copy() |
|
469 | self.__buffer += data.copy() | |
471 | self.__profIndex += 1 |
|
470 | self.__profIndex += 1 | |
472 | return |
|
471 | return | |
473 |
|
472 | |||
474 | #Overlapping data |
|
473 | #Overlapping data | |
475 | nChannels, nHeis = data.shape |
|
474 | nChannels, nHeis = data.shape | |
476 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
475 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
477 |
|
476 | |||
478 | #If the buffer is empty then it takes the data value |
|
477 | #If the buffer is empty then it takes the data value | |
479 | if self.__buffer is None: |
|
478 | if self.__buffer is None: | |
480 | self.__buffer = data |
|
479 | self.__buffer = data | |
481 | self.__profIndex += 1 |
|
480 | self.__profIndex += 1 | |
482 | return |
|
481 | return | |
483 |
|
482 | |||
484 | #If the buffer length is lower than n then stakcing the data value |
|
483 | #If the buffer length is lower than n then stakcing the data value | |
485 | if self.__profIndex < self.n: |
|
484 | if self.__profIndex < self.n: | |
486 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
485 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
487 | self.__profIndex += 1 |
|
486 | self.__profIndex += 1 | |
488 | return |
|
487 | return | |
489 |
|
488 | |||
490 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
489 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
491 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
490 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
492 | self.__buffer[self.n-1] = data |
|
491 | self.__buffer[self.n-1] = data | |
493 | self.__profIndex = self.n |
|
492 | self.__profIndex = self.n | |
494 | return |
|
493 | return | |
495 |
|
494 | |||
496 |
|
495 | |||
497 | def pushData(self): |
|
496 | def pushData(self): | |
498 | """ |
|
497 | """ | |
499 | Return the sum of the last profiles and the profiles used in the sum. |
|
498 | Return the sum of the last profiles and the profiles used in the sum. | |
500 |
|
499 | |||
501 | Affected: |
|
500 | Affected: | |
502 |
|
501 | |||
503 | self.__profileIndex |
|
502 | self.__profileIndex | |
504 |
|
503 | |||
505 | """ |
|
504 | """ | |
506 |
|
505 | |||
507 | if not self.__withOverlapping: |
|
506 | if not self.__withOverlapping: | |
508 | data = self.__buffer |
|
507 | data = self.__buffer | |
509 | n = self.__profIndex |
|
508 | n = self.__profIndex | |
510 |
|
509 | |||
511 | self.__buffer = 0 |
|
510 | self.__buffer = 0 | |
512 | self.__profIndex = 0 |
|
511 | self.__profIndex = 0 | |
513 |
|
512 | |||
514 | return data, n |
|
513 | return data, n | |
515 |
|
514 | |||
516 | #Integration with Overlapping |
|
515 | #Integration with Overlapping | |
517 | data = numpy.sum(self.__buffer, axis=0) |
|
516 | data = numpy.sum(self.__buffer, axis=0) | |
518 | # print data |
|
517 | # print data | |
519 | # raise |
|
518 | # raise | |
520 | n = self.__profIndex |
|
519 | n = self.__profIndex | |
521 |
|
520 | |||
522 | return data, n |
|
521 | return data, n | |
523 |
|
522 | |||
524 | def byProfiles(self, data): |
|
523 | def byProfiles(self, data): | |
525 |
|
524 | |||
526 | self.__dataReady = False |
|
525 | self.__dataReady = False | |
527 | avgdata = None |
|
526 | avgdata = None | |
528 | # n = None |
|
527 | # n = None | |
529 | # print data |
|
528 | # print data | |
530 | # raise |
|
529 | # raise | |
531 | self.putData(data) |
|
530 | self.putData(data) | |
532 |
|
531 | |||
533 | if self.__profIndex == self.n: |
|
532 | if self.__profIndex == self.n: | |
534 | avgdata, n = self.pushData() |
|
533 | avgdata, n = self.pushData() | |
535 | self.__dataReady = True |
|
534 | self.__dataReady = True | |
536 |
|
535 | |||
537 | return avgdata |
|
536 | return avgdata | |
538 |
|
537 | |||
539 | def byTime(self, data, datatime): |
|
538 | def byTime(self, data, datatime): | |
540 |
|
539 | |||
541 | self.__dataReady = False |
|
540 | self.__dataReady = False | |
542 | avgdata = None |
|
541 | avgdata = None | |
543 | n = None |
|
542 | n = None | |
544 |
|
543 | |||
545 | self.putData(data) |
|
544 | self.putData(data) | |
546 |
|
545 | |||
547 | if (datatime - self.__initime) >= self.__integrationtime: |
|
546 | if (datatime - self.__initime) >= self.__integrationtime: | |
548 | avgdata, n = self.pushData() |
|
547 | avgdata, n = self.pushData() | |
549 | self.n = n |
|
548 | self.n = n | |
550 | self.__dataReady = True |
|
549 | self.__dataReady = True | |
551 |
|
550 | |||
552 | return avgdata |
|
551 | return avgdata | |
553 |
|
552 | |||
554 | def integrateByStride(self, data, datatime): |
|
553 | def integrateByStride(self, data, datatime): | |
555 | # print data |
|
554 | # print data | |
556 | if self.__profIndex == 0: |
|
555 | if self.__profIndex == 0: | |
557 | self.__buffer = [[data.copy(), datatime]] |
|
556 | self.__buffer = [[data.copy(), datatime]] | |
558 | else: |
|
557 | else: | |
559 | self.__buffer.append([data.copy(),datatime]) |
|
558 | self.__buffer.append([data.copy(),datatime]) | |
560 | self.__profIndex += 1 |
|
559 | self.__profIndex += 1 | |
561 | self.__dataReady = False |
|
560 | self.__dataReady = False | |
562 |
|
561 | |||
563 | if self.__profIndex == self.n * self.stride : |
|
562 | if self.__profIndex == self.n * self.stride : | |
564 | self.__dataToPutStride = True |
|
563 | self.__dataToPutStride = True | |
565 | self.__profIndexStride = 0 |
|
564 | self.__profIndexStride = 0 | |
566 | self.__profIndex = 0 |
|
565 | self.__profIndex = 0 | |
567 | self.__bufferStride = [] |
|
566 | self.__bufferStride = [] | |
568 | for i in range(self.stride): |
|
567 | for i in range(self.stride): | |
569 | current = self.__buffer[i::self.stride] |
|
568 | current = self.__buffer[i::self.stride] | |
570 | data = numpy.sum([t[0] for t in current], axis=0) |
|
569 | data = numpy.sum([t[0] for t in current], axis=0) | |
571 | avgdatatime = numpy.average([t[1] for t in current]) |
|
570 | avgdatatime = numpy.average([t[1] for t in current]) | |
572 | # print data |
|
571 | # print data | |
573 | self.__bufferStride.append((data, avgdatatime)) |
|
572 | self.__bufferStride.append((data, avgdatatime)) | |
574 |
|
573 | |||
575 | if self.__dataToPutStride: |
|
574 | if self.__dataToPutStride: | |
576 | self.__dataReady = True |
|
575 | self.__dataReady = True | |
577 | self.__profIndexStride += 1 |
|
576 | self.__profIndexStride += 1 | |
578 | if self.__profIndexStride == self.stride: |
|
577 | if self.__profIndexStride == self.stride: | |
579 | self.__dataToPutStride = False |
|
578 | self.__dataToPutStride = False | |
580 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
579 | # print self.__bufferStride[self.__profIndexStride - 1] | |
581 | # raise |
|
580 | # raise | |
582 | return self.__bufferStride[self.__profIndexStride - 1] |
|
581 | return self.__bufferStride[self.__profIndexStride - 1] | |
583 |
|
582 | |||
584 |
|
583 | |||
585 | return None, None |
|
584 | return None, None | |
586 |
|
585 | |||
587 | def integrate(self, data, datatime=None): |
|
586 | def integrate(self, data, datatime=None): | |
588 |
|
587 | |||
589 | if self.__initime == None: |
|
588 | if self.__initime == None: | |
590 | self.__initime = datatime |
|
589 | self.__initime = datatime | |
591 |
|
590 | |||
592 | if self.__byTime: |
|
591 | if self.__byTime: | |
593 | avgdata = self.byTime(data, datatime) |
|
592 | avgdata = self.byTime(data, datatime) | |
594 | else: |
|
593 | else: | |
595 | avgdata = self.byProfiles(data) |
|
594 | avgdata = self.byProfiles(data) | |
596 |
|
595 | |||
597 |
|
596 | |||
598 | self.__lastdatatime = datatime |
|
597 | self.__lastdatatime = datatime | |
599 |
|
598 | |||
600 | if avgdata is None: |
|
599 | if avgdata is None: | |
601 | return None, None |
|
600 | return None, None | |
602 |
|
601 | |||
603 | avgdatatime = self.__initime |
|
602 | avgdatatime = self.__initime | |
604 |
|
603 | |||
605 | deltatime = datatime - self.__lastdatatime |
|
604 | deltatime = datatime - self.__lastdatatime | |
606 |
|
605 | |||
607 | if not self.__withOverlapping: |
|
606 | if not self.__withOverlapping: | |
608 | self.__initime = datatime |
|
607 | self.__initime = datatime | |
609 | else: |
|
608 | else: | |
610 | self.__initime += deltatime |
|
609 | self.__initime += deltatime | |
611 |
|
610 | |||
612 | return avgdata, avgdatatime |
|
611 | return avgdata, avgdatatime | |
613 |
|
612 | |||
614 | def integrateByBlock(self, dataOut): |
|
613 | def integrateByBlock(self, dataOut): | |
615 |
|
614 | |||
616 | times = int(dataOut.data.shape[1]/self.n) |
|
615 | times = int(dataOut.data.shape[1]/self.n) | |
617 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
616 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
618 |
|
617 | |||
619 | id_min = 0 |
|
618 | id_min = 0 | |
620 | id_max = self.n |
|
619 | id_max = self.n | |
621 |
|
620 | |||
622 | for i in range(times): |
|
621 | for i in range(times): | |
623 | junk = dataOut.data[:,id_min:id_max,:] |
|
622 | junk = dataOut.data[:,id_min:id_max,:] | |
624 | avgdata[:,i,:] = junk.sum(axis=1) |
|
623 | avgdata[:,i,:] = junk.sum(axis=1) | |
625 | id_min += self.n |
|
624 | id_min += self.n | |
626 | id_max += self.n |
|
625 | id_max += self.n | |
627 |
|
626 | |||
628 | timeInterval = dataOut.ippSeconds*self.n |
|
627 | timeInterval = dataOut.ippSeconds*self.n | |
629 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
628 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
630 | self.__dataReady = True |
|
629 | self.__dataReady = True | |
631 | return avgdata, avgdatatime |
|
630 | return avgdata, avgdatatime | |
632 |
|
631 | |||
633 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
632 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
634 |
|
633 | |||
635 | if not self.isConfig: |
|
634 | if not self.isConfig: | |
636 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
635 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
637 | self.isConfig = True |
|
636 | self.isConfig = True | |
638 |
|
637 | |||
639 | if dataOut.flagDataAsBlock: |
|
638 | if dataOut.flagDataAsBlock: | |
640 | """ |
|
639 | """ | |
641 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
640 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
642 | """ |
|
641 | """ | |
643 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
642 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
644 | dataOut.nProfiles /= self.n |
|
643 | dataOut.nProfiles /= self.n | |
645 | else: |
|
644 | else: | |
646 |
if stride is None: |
|
645 | if stride is None: | |
647 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
646 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
648 | else: |
|
647 | else: | |
649 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
648 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
650 |
|
649 | |||
651 |
|
650 | |||
652 | # dataOut.timeInterval *= n |
|
651 | # dataOut.timeInterval *= n | |
653 | dataOut.flagNoData = True |
|
652 | dataOut.flagNoData = True | |
654 |
|
653 | |||
655 | if self.__dataReady: |
|
654 | if self.__dataReady: | |
656 | dataOut.data = avgdata |
|
655 | dataOut.data = avgdata | |
657 | dataOut.nCohInt *= self.n |
|
656 | dataOut.nCohInt *= self.n | |
658 | dataOut.utctime = avgdatatime |
|
657 | dataOut.utctime = avgdatatime | |
659 | # print avgdata, avgdatatime |
|
658 | # print avgdata, avgdatatime | |
660 | # raise |
|
659 | # raise | |
661 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
660 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
662 | dataOut.flagNoData = False |
|
661 | dataOut.flagNoData = False | |
663 | return dataOut |
|
662 | return dataOut | |
664 |
|
663 | |||
665 | class Decoder(Operation): |
|
664 | class Decoder(Operation): | |
666 |
|
665 | |||
667 | isConfig = False |
|
666 | isConfig = False | |
668 | __profIndex = 0 |
|
667 | __profIndex = 0 | |
669 |
|
668 | |||
670 | code = None |
|
669 | code = None | |
671 |
|
670 | |||
672 | nCode = None |
|
671 | nCode = None | |
673 | nBaud = None |
|
672 | nBaud = None | |
674 |
|
673 | |||
675 | def __init__(self, **kwargs): |
|
674 | def __init__(self, **kwargs): | |
676 |
|
675 | |||
677 | Operation.__init__(self, **kwargs) |
|
676 | Operation.__init__(self, **kwargs) | |
678 |
|
677 | |||
679 | self.times = None |
|
678 | self.times = None | |
680 | self.osamp = None |
|
679 | self.osamp = None | |
681 | # self.__setValues = False |
|
680 | # self.__setValues = False | |
682 | self.isConfig = False |
|
681 | self.isConfig = False | |
683 | self.setupReq = False |
|
682 | self.setupReq = False | |
684 | def setup(self, code, osamp, dataOut): |
|
683 | def setup(self, code, osamp, dataOut): | |
685 |
|
684 | |||
686 | self.__profIndex = 0 |
|
685 | self.__profIndex = 0 | |
687 |
|
686 | |||
688 | self.code = code |
|
687 | self.code = code | |
689 |
|
688 | |||
690 | self.nCode = len(code) |
|
689 | self.nCode = len(code) | |
691 | self.nBaud = len(code[0]) |
|
690 | self.nBaud = len(code[0]) | |
692 |
|
691 | |||
693 | if (osamp != None) and (osamp >1): |
|
692 | if (osamp != None) and (osamp >1): | |
694 | self.osamp = osamp |
|
693 | self.osamp = osamp | |
695 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
694 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
696 | self.nBaud = self.nBaud*self.osamp |
|
695 | self.nBaud = self.nBaud*self.osamp | |
697 |
|
696 | |||
698 | self.__nChannels = dataOut.nChannels |
|
697 | self.__nChannels = dataOut.nChannels | |
699 | self.__nProfiles = dataOut.nProfiles |
|
698 | self.__nProfiles = dataOut.nProfiles | |
700 | self.__nHeis = dataOut.nHeights |
|
699 | self.__nHeis = dataOut.nHeights | |
701 |
|
700 | |||
702 | if self.__nHeis < self.nBaud: |
|
701 | if self.__nHeis < self.nBaud: | |
703 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
702 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
704 |
|
703 | |||
705 | #Frequency |
|
704 | #Frequency | |
706 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
705 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
707 |
|
706 | |||
708 | __codeBuffer[:,0:self.nBaud] = self.code |
|
707 | __codeBuffer[:,0:self.nBaud] = self.code | |
709 |
|
708 | |||
710 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
709 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
711 |
|
710 | |||
712 | if dataOut.flagDataAsBlock: |
|
711 | if dataOut.flagDataAsBlock: | |
713 |
|
712 | |||
714 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
713 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
715 |
|
714 | |||
716 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
715 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
717 |
|
716 | |||
718 | else: |
|
717 | else: | |
719 |
|
718 | |||
720 | #Time |
|
719 | #Time | |
721 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
720 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
722 |
|
721 | |||
723 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
722 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
724 |
|
723 | |||
725 | def __convolutionInFreq(self, data): |
|
724 | def __convolutionInFreq(self, data): | |
726 |
|
725 | |||
727 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
726 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
728 |
|
727 | |||
729 | fft_data = numpy.fft.fft(data, axis=1) |
|
728 | fft_data = numpy.fft.fft(data, axis=1) | |
730 |
|
729 | |||
731 | conv = fft_data*fft_code |
|
730 | conv = fft_data*fft_code | |
732 |
|
731 | |||
733 | data = numpy.fft.ifft(conv,axis=1) |
|
732 | data = numpy.fft.ifft(conv,axis=1) | |
734 |
|
733 | |||
735 | return data |
|
734 | return data | |
736 |
|
735 | |||
737 | def __convolutionInFreqOpt(self, data): |
|
736 | def __convolutionInFreqOpt(self, data): | |
738 |
|
737 | |||
739 | raise NotImplementedError |
|
738 | raise NotImplementedError | |
740 |
|
739 | |||
741 | def __convolutionInTime(self, data): |
|
740 | def __convolutionInTime(self, data): | |
742 |
|
741 | |||
743 | code = self.code[self.__profIndex] |
|
742 | code = self.code[self.__profIndex] | |
744 | for i in range(self.__nChannels): |
|
743 | for i in range(self.__nChannels): | |
745 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
744 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
746 |
|
745 | |||
747 | return self.datadecTime |
|
746 | return self.datadecTime | |
748 |
|
747 | |||
749 | def __convolutionByBlockInTime(self, data): |
|
748 | def __convolutionByBlockInTime(self, data): | |
750 |
|
749 | |||
751 | repetitions = int(self.__nProfiles / self.nCode) |
|
750 | repetitions = int(self.__nProfiles / self.nCode) | |
752 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
751 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
753 | junk = junk.flatten() |
|
752 | junk = junk.flatten() | |
754 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
753 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
755 | profilesList = range(self.__nProfiles) |
|
754 | profilesList = range(self.__nProfiles) | |
756 |
|
755 | |||
757 |
for i in range(self.__nChannels): |
|
756 | for i in range(self.__nChannels): | |
758 |
for j in profilesList: |
|
757 | for j in profilesList: | |
759 |
self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
758 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
760 |
return self.datadecTime |
|
759 | return self.datadecTime | |
761 |
|
760 | |||
762 | def __convolutionByBlockInFreq(self, data): |
|
761 | def __convolutionByBlockInFreq(self, data): | |
763 |
|
762 | |||
764 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
763 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
765 |
|
764 | |||
766 |
|
765 | |||
767 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
766 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
768 |
|
767 | |||
769 | fft_data = numpy.fft.fft(data, axis=2) |
|
768 | fft_data = numpy.fft.fft(data, axis=2) | |
770 |
|
769 | |||
771 | conv = fft_data*fft_code |
|
770 | conv = fft_data*fft_code | |
772 |
|
771 | |||
773 | data = numpy.fft.ifft(conv,axis=2) |
|
772 | data = numpy.fft.ifft(conv,axis=2) | |
774 |
|
773 | |||
775 | return data |
|
774 | return data | |
776 |
|
775 | |||
777 |
|
776 | |||
778 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
777 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
779 |
|
778 | |||
780 | if dataOut.flagDecodeData: |
|
779 | if dataOut.flagDecodeData: | |
781 | print("This data is already decoded, recoding again ...") |
|
780 | print("This data is already decoded, recoding again ...") | |
782 |
|
781 | |||
783 | if not self.isConfig: |
|
782 | if not self.isConfig: | |
784 |
|
783 | |||
785 | if code is None: |
|
784 | if code is None: | |
786 | if dataOut.code is None: |
|
785 | if dataOut.code is None: | |
787 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
786 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
788 |
|
787 | |||
789 | code = dataOut.code |
|
788 | code = dataOut.code | |
790 | else: |
|
789 | else: | |
791 | code = numpy.array(code).reshape(nCode,nBaud) |
|
790 | code = numpy.array(code).reshape(nCode,nBaud) | |
792 | self.setup(code, osamp, dataOut) |
|
791 | self.setup(code, osamp, dataOut) | |
793 |
|
792 | |||
794 | self.isConfig = True |
|
793 | self.isConfig = True | |
795 |
|
794 | |||
796 | if mode == 3: |
|
795 | if mode == 3: | |
797 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
796 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
798 |
|
797 | |||
799 | if times != None: |
|
798 | if times != None: | |
800 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
799 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
801 |
|
800 | |||
802 | if self.code is None: |
|
801 | if self.code is None: | |
803 | print("Fail decoding: Code is not defined.") |
|
802 | print("Fail decoding: Code is not defined.") | |
804 | return |
|
803 | return | |
805 |
|
804 | |||
806 | self.__nProfiles = dataOut.nProfiles |
|
805 | self.__nProfiles = dataOut.nProfiles | |
807 | datadec = None |
|
806 | datadec = None | |
808 |
|
807 | |||
809 | if mode == 3: |
|
808 | if mode == 3: | |
810 | mode = 0 |
|
809 | mode = 0 | |
811 |
|
810 | |||
812 | if dataOut.flagDataAsBlock: |
|
811 | if dataOut.flagDataAsBlock: | |
813 | """ |
|
812 | """ | |
814 | Decoding when data have been read as block, |
|
813 | Decoding when data have been read as block, | |
815 | """ |
|
814 | """ | |
816 |
|
815 | |||
817 | if mode == 0: |
|
816 | if mode == 0: | |
818 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
817 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
819 | if mode == 1: |
|
818 | if mode == 1: | |
820 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
819 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
821 | else: |
|
820 | else: | |
822 | """ |
|
821 | """ | |
823 | Decoding when data have been read profile by profile |
|
822 | Decoding when data have been read profile by profile | |
824 | """ |
|
823 | """ | |
825 | if mode == 0: |
|
824 | if mode == 0: | |
826 | datadec = self.__convolutionInTime(dataOut.data) |
|
825 | datadec = self.__convolutionInTime(dataOut.data) | |
827 |
|
826 | |||
828 | if mode == 1: |
|
827 | if mode == 1: | |
829 | datadec = self.__convolutionInFreq(dataOut.data) |
|
828 | datadec = self.__convolutionInFreq(dataOut.data) | |
830 |
|
829 | |||
831 | if mode == 2: |
|
830 | if mode == 2: | |
832 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
831 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
833 |
|
832 | |||
834 | if datadec is None: |
|
833 | if datadec is None: | |
835 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
834 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
836 |
|
835 | |||
837 | dataOut.code = self.code |
|
836 | dataOut.code = self.code | |
838 | dataOut.nCode = self.nCode |
|
837 | dataOut.nCode = self.nCode | |
839 | dataOut.nBaud = self.nBaud |
|
838 | dataOut.nBaud = self.nBaud | |
840 |
|
839 | |||
841 | dataOut.data = datadec |
|
840 | dataOut.data = datadec | |
842 |
|
841 | |||
843 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
842 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
844 |
|
843 | |||
845 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
844 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
846 |
|
845 | |||
847 | if self.__profIndex == self.nCode-1: |
|
846 | if self.__profIndex == self.nCode-1: | |
848 | self.__profIndex = 0 |
|
847 | self.__profIndex = 0 | |
849 | return dataOut |
|
848 | return dataOut | |
850 |
|
849 | |||
851 | self.__profIndex += 1 |
|
850 | self.__profIndex += 1 | |
852 |
|
851 | |||
853 | return dataOut |
|
852 | return dataOut | |
854 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
853 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
855 |
|
854 | |||
856 |
|
855 | |||
857 | class ProfileConcat(Operation): |
|
856 | class ProfileConcat(Operation): | |
858 |
|
857 | |||
859 | isConfig = False |
|
858 | isConfig = False | |
860 | buffer = None |
|
859 | buffer = None | |
861 |
|
860 | |||
862 | def __init__(self, **kwargs): |
|
861 | def __init__(self, **kwargs): | |
863 |
|
862 | |||
864 | Operation.__init__(self, **kwargs) |
|
863 | Operation.__init__(self, **kwargs) | |
865 | self.profileIndex = 0 |
|
864 | self.profileIndex = 0 | |
866 |
|
865 | |||
867 | def reset(self): |
|
866 | def reset(self): | |
868 | self.buffer = numpy.zeros_like(self.buffer) |
|
867 | self.buffer = numpy.zeros_like(self.buffer) | |
869 | self.start_index = 0 |
|
868 | self.start_index = 0 | |
870 | self.times = 1 |
|
869 | self.times = 1 | |
871 |
|
870 | |||
872 | def setup(self, data, m, n=1): |
|
871 | def setup(self, data, m, n=1): | |
873 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
872 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
874 | self.nHeights = data.shape[1]#.nHeights |
|
873 | self.nHeights = data.shape[1]#.nHeights | |
875 | self.start_index = 0 |
|
874 | self.start_index = 0 | |
876 | self.times = 1 |
|
875 | self.times = 1 | |
877 |
|
876 | |||
878 | def concat(self, data): |
|
877 | def concat(self, data): | |
879 |
|
878 | |||
880 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
879 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
881 | self.start_index = self.start_index + self.nHeights |
|
880 | self.start_index = self.start_index + self.nHeights | |
882 |
|
881 | |||
883 | def run(self, dataOut, m): |
|
882 | def run(self, dataOut, m): | |
884 | dataOut.flagNoData = True |
|
883 | dataOut.flagNoData = True | |
885 |
|
884 | |||
886 | if not self.isConfig: |
|
885 | if not self.isConfig: | |
887 | self.setup(dataOut.data, m, 1) |
|
886 | self.setup(dataOut.data, m, 1) | |
888 | self.isConfig = True |
|
887 | self.isConfig = True | |
889 |
|
888 | |||
890 | if dataOut.flagDataAsBlock: |
|
889 | if dataOut.flagDataAsBlock: | |
891 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
890 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
892 |
|
891 | |||
893 | else: |
|
892 | else: | |
894 | self.concat(dataOut.data) |
|
893 | self.concat(dataOut.data) | |
895 | self.times += 1 |
|
894 | self.times += 1 | |
896 | if self.times > m: |
|
895 | if self.times > m: | |
897 | dataOut.data = self.buffer |
|
896 | dataOut.data = self.buffer | |
898 | self.reset() |
|
897 | self.reset() | |
899 | dataOut.flagNoData = False |
|
898 | dataOut.flagNoData = False | |
900 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
899 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
901 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
900 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
902 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
901 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
903 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
902 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
904 | dataOut.ippSeconds *= m |
|
903 | dataOut.ippSeconds *= m | |
905 | return dataOut |
|
904 | return dataOut | |
906 |
|
905 | |||
907 | class ProfileSelector(Operation): |
|
906 | class ProfileSelector(Operation): | |
908 |
|
907 | |||
909 | profileIndex = None |
|
908 | profileIndex = None | |
910 | # Tamanho total de los perfiles |
|
909 | # Tamanho total de los perfiles | |
911 | nProfiles = None |
|
910 | nProfiles = None | |
912 |
|
911 | |||
913 | def __init__(self, **kwargs): |
|
912 | def __init__(self, **kwargs): | |
914 |
|
913 | |||
915 | Operation.__init__(self, **kwargs) |
|
914 | Operation.__init__(self, **kwargs) | |
916 | self.profileIndex = 0 |
|
915 | self.profileIndex = 0 | |
917 |
|
916 | |||
918 | def incProfileIndex(self): |
|
917 | def incProfileIndex(self): | |
919 |
|
918 | |||
920 | self.profileIndex += 1 |
|
919 | self.profileIndex += 1 | |
921 |
|
920 | |||
922 | if self.profileIndex >= self.nProfiles: |
|
921 | if self.profileIndex >= self.nProfiles: | |
923 | self.profileIndex = 0 |
|
922 | self.profileIndex = 0 | |
924 |
|
923 | |||
925 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
924 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
926 |
|
925 | |||
927 | if profileIndex < minIndex: |
|
926 | if profileIndex < minIndex: | |
928 | return False |
|
927 | return False | |
929 |
|
928 | |||
930 | if profileIndex > maxIndex: |
|
929 | if profileIndex > maxIndex: | |
931 | return False |
|
930 | return False | |
932 |
|
931 | |||
933 | return True |
|
932 | return True | |
934 |
|
933 | |||
935 | def isThisProfileInList(self, profileIndex, profileList): |
|
934 | def isThisProfileInList(self, profileIndex, profileList): | |
936 |
|
935 | |||
937 | if profileIndex not in profileList: |
|
936 | if profileIndex not in profileList: | |
938 | return False |
|
937 | return False | |
939 |
|
938 | |||
940 | return True |
|
939 | return True | |
941 |
|
940 | |||
942 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
941 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
943 |
|
942 | |||
944 | """ |
|
943 | """ | |
945 | ProfileSelector: |
|
944 | ProfileSelector: | |
946 |
|
945 | |||
947 | Inputs: |
|
946 | Inputs: | |
948 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
947 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
949 |
|
948 | |||
950 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
949 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
951 |
|
950 | |||
952 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
951 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
953 |
|
952 | |||
954 | """ |
|
953 | """ | |
955 |
|
954 | |||
956 | if rangeList is not None: |
|
955 | if rangeList is not None: | |
957 | if type(rangeList[0]) not in (tuple, list): |
|
956 | if type(rangeList[0]) not in (tuple, list): | |
958 | rangeList = [rangeList] |
|
957 | rangeList = [rangeList] | |
959 |
|
958 | |||
960 | dataOut.flagNoData = True |
|
959 | dataOut.flagNoData = True | |
961 |
|
960 | |||
962 | if dataOut.flagDataAsBlock: |
|
961 | if dataOut.flagDataAsBlock: | |
963 | """ |
|
962 | """ | |
964 | data dimension = [nChannels, nProfiles, nHeis] |
|
963 | data dimension = [nChannels, nProfiles, nHeis] | |
965 | """ |
|
964 | """ | |
966 | if profileList != None: |
|
965 | if profileList != None: | |
967 | dataOut.data = dataOut.data[:,profileList,:] |
|
966 | dataOut.data = dataOut.data[:,profileList,:] | |
968 |
|
967 | |||
969 | if profileRangeList != None: |
|
968 | if profileRangeList != None: | |
970 | minIndex = profileRangeList[0] |
|
969 | minIndex = profileRangeList[0] | |
971 | maxIndex = profileRangeList[1] |
|
970 | maxIndex = profileRangeList[1] | |
972 | profileList = list(range(minIndex, maxIndex+1)) |
|
971 | profileList = list(range(minIndex, maxIndex+1)) | |
973 |
|
972 | |||
974 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
973 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
975 |
|
974 | |||
976 | if rangeList != None: |
|
975 | if rangeList != None: | |
977 |
|
976 | |||
978 | profileList = [] |
|
977 | profileList = [] | |
979 |
|
978 | |||
980 | for thisRange in rangeList: |
|
979 | for thisRange in rangeList: | |
981 | minIndex = thisRange[0] |
|
980 | minIndex = thisRange[0] | |
982 | maxIndex = thisRange[1] |
|
981 | maxIndex = thisRange[1] | |
983 |
|
982 | |||
984 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
983 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
985 |
|
984 | |||
986 | dataOut.data = dataOut.data[:,profileList,:] |
|
985 | dataOut.data = dataOut.data[:,profileList,:] | |
987 |
|
986 | |||
988 | dataOut.nProfiles = len(profileList) |
|
987 | dataOut.nProfiles = len(profileList) | |
989 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
988 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
990 | dataOut.flagNoData = False |
|
989 | dataOut.flagNoData = False | |
991 |
|
990 | |||
992 | return dataOut |
|
991 | return dataOut | |
993 |
|
992 | |||
994 | """ |
|
993 | """ | |
995 | data dimension = [nChannels, nHeis] |
|
994 | data dimension = [nChannels, nHeis] | |
996 | """ |
|
995 | """ | |
997 |
|
996 | |||
998 | if profileList != None: |
|
997 | if profileList != None: | |
999 |
|
998 | |||
1000 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
999 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
1001 |
|
1000 | |||
1002 | self.nProfiles = len(profileList) |
|
1001 | self.nProfiles = len(profileList) | |
1003 | dataOut.nProfiles = self.nProfiles |
|
1002 | dataOut.nProfiles = self.nProfiles | |
1004 | dataOut.profileIndex = self.profileIndex |
|
1003 | dataOut.profileIndex = self.profileIndex | |
1005 | dataOut.flagNoData = False |
|
1004 | dataOut.flagNoData = False | |
1006 |
|
1005 | |||
1007 | self.incProfileIndex() |
|
1006 | self.incProfileIndex() | |
1008 | return dataOut |
|
1007 | return dataOut | |
1009 |
|
1008 | |||
1010 | if profileRangeList != None: |
|
1009 | if profileRangeList != None: | |
1011 |
|
1010 | |||
1012 | minIndex = profileRangeList[0] |
|
1011 | minIndex = profileRangeList[0] | |
1013 | maxIndex = profileRangeList[1] |
|
1012 | maxIndex = profileRangeList[1] | |
1014 |
|
1013 | |||
1015 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1014 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1016 |
|
1015 | |||
1017 | self.nProfiles = maxIndex - minIndex + 1 |
|
1016 | self.nProfiles = maxIndex - minIndex + 1 | |
1018 | dataOut.nProfiles = self.nProfiles |
|
1017 | dataOut.nProfiles = self.nProfiles | |
1019 | dataOut.profileIndex = self.profileIndex |
|
1018 | dataOut.profileIndex = self.profileIndex | |
1020 | dataOut.flagNoData = False |
|
1019 | dataOut.flagNoData = False | |
1021 |
|
1020 | |||
1022 | self.incProfileIndex() |
|
1021 | self.incProfileIndex() | |
1023 | return dataOut |
|
1022 | return dataOut | |
1024 |
|
1023 | |||
1025 | if rangeList != None: |
|
1024 | if rangeList != None: | |
1026 |
|
1025 | |||
1027 | nProfiles = 0 |
|
1026 | nProfiles = 0 | |
1028 |
|
1027 | |||
1029 | for thisRange in rangeList: |
|
1028 | for thisRange in rangeList: | |
1030 | minIndex = thisRange[0] |
|
1029 | minIndex = thisRange[0] | |
1031 | maxIndex = thisRange[1] |
|
1030 | maxIndex = thisRange[1] | |
1032 |
|
1031 | |||
1033 | nProfiles += maxIndex - minIndex + 1 |
|
1032 | nProfiles += maxIndex - minIndex + 1 | |
1034 |
|
1033 | |||
1035 | for thisRange in rangeList: |
|
1034 | for thisRange in rangeList: | |
1036 |
|
1035 | |||
1037 | minIndex = thisRange[0] |
|
1036 | minIndex = thisRange[0] | |
1038 | maxIndex = thisRange[1] |
|
1037 | maxIndex = thisRange[1] | |
1039 |
|
1038 | |||
1040 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1039 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1041 |
|
1040 | |||
1042 | self.nProfiles = nProfiles |
|
1041 | self.nProfiles = nProfiles | |
1043 | dataOut.nProfiles = self.nProfiles |
|
1042 | dataOut.nProfiles = self.nProfiles | |
1044 | dataOut.profileIndex = self.profileIndex |
|
1043 | dataOut.profileIndex = self.profileIndex | |
1045 | dataOut.flagNoData = False |
|
1044 | dataOut.flagNoData = False | |
1046 |
|
1045 | |||
1047 | self.incProfileIndex() |
|
1046 | self.incProfileIndex() | |
1048 |
|
1047 | |||
1049 | break |
|
1048 | break | |
1050 |
|
1049 | |||
1051 | return dataOut |
|
1050 | return dataOut | |
1052 |
|
1051 | |||
1053 |
|
1052 | |||
1054 | if beam != None: #beam is only for AMISR data |
|
1053 | if beam != None: #beam is only for AMISR data | |
1055 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1054 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
1056 | dataOut.flagNoData = False |
|
1055 | dataOut.flagNoData = False | |
1057 | dataOut.profileIndex = self.profileIndex |
|
1056 | dataOut.profileIndex = self.profileIndex | |
1058 |
|
1057 | |||
1059 | self.incProfileIndex() |
|
1058 | self.incProfileIndex() | |
1060 |
|
1059 | |||
1061 | return dataOut |
|
1060 | return dataOut | |
1062 |
|
1061 | |||
1063 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1062 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
1064 |
|
1063 | |||
1065 |
|
1064 | |||
1066 | class Reshaper(Operation): |
|
1065 | class Reshaper(Operation): | |
1067 |
|
1066 | |||
1068 | def __init__(self, **kwargs): |
|
1067 | def __init__(self, **kwargs): | |
1069 |
|
1068 | |||
1070 | Operation.__init__(self, **kwargs) |
|
1069 | Operation.__init__(self, **kwargs) | |
1071 |
|
1070 | |||
1072 | self.__buffer = None |
|
1071 | self.__buffer = None | |
1073 | self.__nitems = 0 |
|
1072 | self.__nitems = 0 | |
1074 |
|
1073 | |||
1075 | def __appendProfile(self, dataOut, nTxs): |
|
1074 | def __appendProfile(self, dataOut, nTxs): | |
1076 |
|
1075 | |||
1077 | if self.__buffer is None: |
|
1076 | if self.__buffer is None: | |
1078 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1077 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
1079 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1078 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
1080 |
|
1079 | |||
1081 | ini = dataOut.nHeights * self.__nitems |
|
1080 | ini = dataOut.nHeights * self.__nitems | |
1082 | end = ini + dataOut.nHeights |
|
1081 | end = ini + dataOut.nHeights | |
1083 |
|
1082 | |||
1084 | self.__buffer[:, ini:end] = dataOut.data |
|
1083 | self.__buffer[:, ini:end] = dataOut.data | |
1085 |
|
1084 | |||
1086 | self.__nitems += 1 |
|
1085 | self.__nitems += 1 | |
1087 |
|
1086 | |||
1088 | return int(self.__nitems*nTxs) |
|
1087 | return int(self.__nitems*nTxs) | |
1089 |
|
1088 | |||
1090 | def __getBuffer(self): |
|
1089 | def __getBuffer(self): | |
1091 |
|
1090 | |||
1092 | if self.__nitems == int(1./self.__nTxs): |
|
1091 | if self.__nitems == int(1./self.__nTxs): | |
1093 |
|
1092 | |||
1094 | self.__nitems = 0 |
|
1093 | self.__nitems = 0 | |
1095 |
|
1094 | |||
1096 | return self.__buffer.copy() |
|
1095 | return self.__buffer.copy() | |
1097 |
|
1096 | |||
1098 | return None |
|
1097 | return None | |
1099 |
|
1098 | |||
1100 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1099 | def __checkInputs(self, dataOut, shape, nTxs): | |
1101 |
|
1100 | |||
1102 | if shape is None and nTxs is None: |
|
1101 | if shape is None and nTxs is None: | |
1103 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1102 | raise ValueError("Reshaper: shape of factor should be defined") | |
1104 |
|
1103 | |||
1105 | if nTxs: |
|
1104 | if nTxs: | |
1106 | if nTxs < 0: |
|
1105 | if nTxs < 0: | |
1107 | raise ValueError("nTxs should be greater than 0") |
|
1106 | raise ValueError("nTxs should be greater than 0") | |
1108 |
|
1107 | |||
1109 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1108 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1110 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1109 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
1111 |
|
1110 | |||
1112 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1111 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1113 |
|
1112 | |||
1114 | return shape, nTxs |
|
1113 | return shape, nTxs | |
1115 |
|
1114 | |||
1116 | if len(shape) != 2 and len(shape) != 3: |
|
1115 | if len(shape) != 2 and len(shape) != 3: | |
1117 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) |
|
1116 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) | |
1118 |
|
1117 | |||
1119 | if len(shape) == 2: |
|
1118 | if len(shape) == 2: | |
1120 | shape_tuple = [dataOut.nChannels] |
|
1119 | shape_tuple = [dataOut.nChannels] | |
1121 | shape_tuple.extend(shape) |
|
1120 | shape_tuple.extend(shape) | |
1122 | else: |
|
1121 | else: | |
1123 | shape_tuple = list(shape) |
|
1122 | shape_tuple = list(shape) | |
1124 |
|
1123 | |||
1125 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1124 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1126 |
|
1125 | |||
1127 | return shape_tuple, nTxs |
|
1126 | return shape_tuple, nTxs | |
1128 |
|
1127 | |||
1129 | def run(self, dataOut, shape=None, nTxs=None): |
|
1128 | def run(self, dataOut, shape=None, nTxs=None): | |
1130 |
|
1129 | |||
1131 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1130 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1132 |
|
1131 | |||
1133 | dataOut.flagNoData = True |
|
1132 | dataOut.flagNoData = True | |
1134 | profileIndex = None |
|
1133 | profileIndex = None | |
1135 |
|
1134 | |||
1136 | if dataOut.flagDataAsBlock: |
|
1135 | if dataOut.flagDataAsBlock: | |
1137 |
|
1136 | |||
1138 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1137 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1139 | dataOut.flagNoData = False |
|
1138 | dataOut.flagNoData = False | |
1140 |
|
1139 | |||
1141 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1140 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1142 |
|
1141 | |||
1143 | else: |
|
1142 | else: | |
1144 |
|
1143 | |||
1145 | if self.__nTxs < 1: |
|
1144 | if self.__nTxs < 1: | |
1146 |
|
1145 | |||
1147 | self.__appendProfile(dataOut, self.__nTxs) |
|
1146 | self.__appendProfile(dataOut, self.__nTxs) | |
1148 | new_data = self.__getBuffer() |
|
1147 | new_data = self.__getBuffer() | |
1149 |
|
1148 | |||
1150 | if new_data is not None: |
|
1149 | if new_data is not None: | |
1151 | dataOut.data = new_data |
|
1150 | dataOut.data = new_data | |
1152 | dataOut.flagNoData = False |
|
1151 | dataOut.flagNoData = False | |
1153 |
|
1152 | |||
1154 | profileIndex = dataOut.profileIndex*nTxs |
|
1153 | profileIndex = dataOut.profileIndex*nTxs | |
1155 |
|
1154 | |||
1156 | else: |
|
1155 | else: | |
1157 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1156 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
1158 |
|
1157 | |||
1159 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1158 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1160 |
|
1159 | |||
1161 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1160 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1162 |
|
1161 | |||
1163 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1162 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1164 |
|
1163 | |||
1165 | dataOut.profileIndex = profileIndex |
|
1164 | dataOut.profileIndex = profileIndex | |
1166 |
|
1165 | |||
1167 | dataOut.ippSeconds /= self.__nTxs |
|
1166 | dataOut.ippSeconds /= self.__nTxs | |
1168 |
|
1167 | |||
1169 | return dataOut |
|
1168 | return dataOut | |
1170 |
|
1169 | |||
1171 | class SplitProfiles(Operation): |
|
1170 | class SplitProfiles(Operation): | |
1172 |
|
1171 | |||
1173 | def __init__(self, **kwargs): |
|
1172 | def __init__(self, **kwargs): | |
1174 |
|
1173 | |||
1175 | Operation.__init__(self, **kwargs) |
|
1174 | Operation.__init__(self, **kwargs) | |
1176 |
|
1175 | |||
1177 | def run(self, dataOut, n): |
|
1176 | def run(self, dataOut, n): | |
1178 |
|
1177 | |||
1179 | dataOut.flagNoData = True |
|
1178 | dataOut.flagNoData = True | |
1180 | profileIndex = None |
|
1179 | profileIndex = None | |
1181 |
|
1180 | |||
1182 | if dataOut.flagDataAsBlock: |
|
1181 | if dataOut.flagDataAsBlock: | |
1183 |
|
1182 | |||
1184 | #nchannels, nprofiles, nsamples |
|
1183 | #nchannels, nprofiles, nsamples | |
1185 | shape = dataOut.data.shape |
|
1184 | shape = dataOut.data.shape | |
1186 |
|
1185 | |||
1187 | if shape[2] % n != 0: |
|
1186 | if shape[2] % n != 0: | |
1188 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1187 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
1189 |
|
1188 | |||
1190 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1189 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
1191 |
|
1190 | |||
1192 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1191 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1193 | dataOut.flagNoData = False |
|
1192 | dataOut.flagNoData = False | |
1194 |
|
1193 | |||
1195 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1194 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1196 |
|
1195 | |||
1197 | else: |
|
1196 | else: | |
1198 |
|
1197 | |||
1199 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1198 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
1200 |
|
1199 | |||
1201 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1200 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1202 |
|
1201 | |||
1203 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1202 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1204 |
|
1203 | |||
1205 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1204 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1206 |
|
1205 | |||
1207 | dataOut.profileIndex = profileIndex |
|
1206 | dataOut.profileIndex = profileIndex | |
1208 |
|
1207 | |||
1209 | dataOut.ippSeconds /= n |
|
1208 | dataOut.ippSeconds /= n | |
1210 |
|
1209 | |||
1211 | return dataOut |
|
1210 | return dataOut | |
1212 |
|
1211 | |||
1213 | class CombineProfiles(Operation): |
|
1212 | class CombineProfiles(Operation): | |
1214 | def __init__(self, **kwargs): |
|
1213 | def __init__(self, **kwargs): | |
1215 |
|
1214 | |||
1216 | Operation.__init__(self, **kwargs) |
|
1215 | Operation.__init__(self, **kwargs) | |
1217 |
|
1216 | |||
1218 | self.__remData = None |
|
1217 | self.__remData = None | |
1219 | self.__profileIndex = 0 |
|
1218 | self.__profileIndex = 0 | |
1220 |
|
1219 | |||
1221 | def run(self, dataOut, n): |
|
1220 | def run(self, dataOut, n): | |
1222 |
|
1221 | |||
1223 | dataOut.flagNoData = True |
|
1222 | dataOut.flagNoData = True | |
1224 | profileIndex = None |
|
1223 | profileIndex = None | |
1225 |
|
1224 | |||
1226 | if dataOut.flagDataAsBlock: |
|
1225 | if dataOut.flagDataAsBlock: | |
1227 |
|
1226 | |||
1228 | #nchannels, nprofiles, nsamples |
|
1227 | #nchannels, nprofiles, nsamples | |
1229 | shape = dataOut.data.shape |
|
1228 | shape = dataOut.data.shape | |
1230 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1229 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1231 |
|
1230 | |||
1232 | if shape[1] % n != 0: |
|
1231 | if shape[1] % n != 0: | |
1233 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1232 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
1234 |
|
1233 | |||
1235 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1234 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1236 | dataOut.flagNoData = False |
|
1235 | dataOut.flagNoData = False | |
1237 |
|
1236 | |||
1238 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1237 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1239 |
|
1238 | |||
1240 | else: |
|
1239 | else: | |
1241 |
|
1240 | |||
1242 | #nchannels, nsamples |
|
1241 | #nchannels, nsamples | |
1243 | if self.__remData is None: |
|
1242 | if self.__remData is None: | |
1244 | newData = dataOut.data |
|
1243 | newData = dataOut.data | |
1245 | else: |
|
1244 | else: | |
1246 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1245 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1247 |
|
1246 | |||
1248 | self.__profileIndex += 1 |
|
1247 | self.__profileIndex += 1 | |
1249 |
|
1248 | |||
1250 | if self.__profileIndex < n: |
|
1249 | if self.__profileIndex < n: | |
1251 | self.__remData = newData |
|
1250 | self.__remData = newData | |
1252 | #continue |
|
1251 | #continue | |
1253 | return |
|
1252 | return | |
1254 |
|
1253 | |||
1255 | self.__profileIndex = 0 |
|
1254 | self.__profileIndex = 0 | |
1256 | self.__remData = None |
|
1255 | self.__remData = None | |
1257 |
|
1256 | |||
1258 | dataOut.data = newData |
|
1257 | dataOut.data = newData | |
1259 | dataOut.flagNoData = False |
|
1258 | dataOut.flagNoData = False | |
1260 |
|
1259 | |||
1261 | profileIndex = dataOut.profileIndex/n |
|
1260 | profileIndex = dataOut.profileIndex/n | |
1262 |
|
1261 | |||
1263 |
|
1262 | |||
1264 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1263 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1265 |
|
1264 | |||
1266 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1265 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1267 |
|
1266 | |||
1268 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1267 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1269 |
|
1268 | |||
1270 | dataOut.profileIndex = profileIndex |
|
1269 | dataOut.profileIndex = profileIndex | |
1271 |
|
1270 | |||
1272 | dataOut.ippSeconds *= n |
|
1271 | dataOut.ippSeconds *= n | |
1273 |
|
1272 | |||
1274 | return dataOut |
|
1273 | return dataOut | |
|
1274 | ||||
|
1275 | class PulsePairVoltage(Operation): | |||
|
1276 | ''' | |||
|
1277 | Function PulsePair(Signal Power, Velocity) | |||
|
1278 | The real component of Lag[0] provides Intensity Information | |||
|
1279 | The imag component of Lag[1] Phase provides Velocity Information | |||
|
1280 | ||||
|
1281 | Configuration Parameters: | |||
|
1282 | nPRF = Number of Several PRF | |||
|
1283 | theta = Degree Azimuth angel Boundaries | |||
|
1284 | ||||
|
1285 | Input: | |||
|
1286 | self.dataOut | |||
|
1287 | lag[N] | |||
|
1288 | Affected: | |||
|
1289 | self.dataOut.spc | |||
|
1290 | ''' | |||
|
1291 | isConfig = False | |||
|
1292 | __profIndex = 0 | |||
|
1293 | __initime = None | |||
|
1294 | __lastdatatime = None | |||
|
1295 | __buffer = None | |||
|
1296 | __buffer2 = [] | |||
|
1297 | __buffer3 = None | |||
|
1298 | __dataReady = False | |||
|
1299 | n = None | |||
|
1300 | __nch = 0 | |||
|
1301 | __nHeis = 0 | |||
|
1302 | removeDC = False | |||
|
1303 | ipp = None | |||
|
1304 | lambda_ = 0 | |||
|
1305 | ||||
|
1306 | def __init__(self,**kwargs): | |||
|
1307 | Operation.__init__(self,**kwargs) | |||
|
1308 | ||||
|
1309 | def setup(self, dataOut, n = None, removeDC=False): | |||
|
1310 | ''' | |||
|
1311 | n= Numero de PRF's de entrada | |||
|
1312 | ''' | |||
|
1313 | self.__initime = None | |||
|
1314 | self.__lastdatatime = 0 | |||
|
1315 | self.__dataReady = False | |||
|
1316 | self.__buffer = 0 | |||
|
1317 | self.__buffer2 = [] | |||
|
1318 | self.__buffer3 = 0 | |||
|
1319 | self.__profIndex = 0 | |||
|
1320 | ||||
|
1321 | self.__nch = dataOut.nChannels | |||
|
1322 | self.__nHeis = dataOut.nHeights | |||
|
1323 | self.removeDC = removeDC | |||
|
1324 | self.lambda_ = 3.0e8/(9345.0e6) | |||
|
1325 | self.ippSec = dataOut.ippSeconds | |||
|
1326 | self.nCohInt = dataOut.nCohInt | |||
|
1327 | print("IPPseconds",dataOut.ippSeconds) | |||
|
1328 | ||||
|
1329 | print("ELVALOR DE n es:", n) | |||
|
1330 | if n == None: | |||
|
1331 | raise ValueError("n should be specified.") | |||
|
1332 | ||||
|
1333 | if n != None: | |||
|
1334 | if n<2: | |||
|
1335 | raise ValueError("n should be greater than 2") | |||
|
1336 | ||||
|
1337 | self.n = n | |||
|
1338 | self.__nProf = n | |||
|
1339 | ||||
|
1340 | self.__buffer = numpy.zeros((dataOut.nChannels, | |||
|
1341 | n, | |||
|
1342 | dataOut.nHeights), | |||
|
1343 | dtype='complex') | |||
|
1344 | ||||
|
1345 | def putData(self,data): | |||
|
1346 | ''' | |||
|
1347 | Add a profile to he __buffer and increase in one the __profiel Index | |||
|
1348 | ''' | |||
|
1349 | self.__buffer[:,self.__profIndex,:]= data | |||
|
1350 | self.__profIndex += 1 | |||
|
1351 | return | |||
|
1352 | ||||
|
1353 | def pushData(self): | |||
|
1354 | ''' | |||
|
1355 | Return the PULSEPAIR and the profiles used in the operation | |||
|
1356 | Affected : self.__profileIndex | |||
|
1357 | ''' | |||
|
1358 | ||||
|
1359 | if self.removeDC==True: | |||
|
1360 | mean = numpy.mean(self.__buffer,1) | |||
|
1361 | tmp = mean.reshape(self.__nch,1,self.__nHeis) | |||
|
1362 | dc= numpy.tile(tmp,[1,self.__nProf,1]) | |||
|
1363 | self.__buffer = self.__buffer - dc | |||
|
1364 | ||||
|
1365 | data_intensity = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1)/(self.n*self.nCohInt)#*self.nCohInt) | |||
|
1366 | pair1 = self.__buffer[:,1:,:]*numpy.conjugate(self.__buffer[:,:-1,:]) | |||
|
1367 | angle = numpy.angle(numpy.sum(pair1,1))*180/(math.pi) | |||
|
1368 | #print(angle.shape)#print("__ANGLE__") #print("angle",angle[:,:10]) | |||
|
1369 | data_velocity = (self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(numpy.sum(pair1,1))#self.ippSec*self.nCohInt | |||
|
1370 | n = self.__profIndex | |||
|
1371 | ||||
|
1372 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') | |||
|
1373 | self.__profIndex = 0 | |||
|
1374 | return data_intensity,data_velocity,n | |||
|
1375 | ||||
|
1376 | def pulsePairbyProfiles(self,data): | |||
|
1377 | ||||
|
1378 | self.__dataReady = False | |||
|
1379 | data_intensity = None | |||
|
1380 | data_velocity = None | |||
|
1381 | self.putData(data) | |||
|
1382 | if self.__profIndex == self.n: | |||
|
1383 | data_intensity, data_velocity, n = self.pushData() | |||
|
1384 | self.__dataReady = True | |||
|
1385 | ||||
|
1386 | return data_intensity, data_velocity | |||
|
1387 | ||||
|
1388 | def pulsePairOp(self, data, datatime= None): | |||
|
1389 | ||||
|
1390 | if self.__initime == None: | |||
|
1391 | self.__initime = datatime | |||
|
1392 | ||||
|
1393 | data_intensity, data_velocity = self.pulsePairbyProfiles(data) | |||
|
1394 | self.__lastdatatime = datatime | |||
|
1395 | ||||
|
1396 | if data_intensity is None: | |||
|
1397 | return None, None, None | |||
|
1398 | ||||
|
1399 | avgdatatime = self.__initime | |||
|
1400 | deltatime = datatime - self.__lastdatatime | |||
|
1401 | self.__initime = datatime | |||
|
1402 | ||||
|
1403 | return data_intensity, data_velocity, avgdatatime | |||
|
1404 | ||||
|
1405 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): | |||
|
1406 | ||||
|
1407 | if not self.isConfig: | |||
|
1408 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) | |||
|
1409 | self.isConfig = True | |||
|
1410 | data_intensity, data_velocity, avgdatatime = self.pulsePairOp(dataOut.data, dataOut.utctime) | |||
|
1411 | dataOut.flagNoData = True | |||
|
1412 | ||||
|
1413 | if self.__dataReady: | |||
|
1414 | dataOut.nCohInt *= self.n | |||
|
1415 | dataOut.data_intensity = data_intensity #valor para intensidad | |||
|
1416 | dataOut.data_velocity = data_velocity #valor para velocidad | |||
|
1417 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. | |||
|
1418 | dataOut.utctime = avgdatatime | |||
|
1419 | dataOut.flagNoData = False | |||
|
1420 | return dataOut | |||
|
1421 | ||||
|
1422 | ||||
1275 | # import collections |
|
1423 | # import collections | |
1276 | # from scipy.stats import mode |
|
1424 | # from scipy.stats import mode | |
1277 | # |
|
1425 | # | |
1278 | # class Synchronize(Operation): |
|
1426 | # class Synchronize(Operation): | |
1279 | # |
|
1427 | # | |
1280 | # isConfig = False |
|
1428 | # isConfig = False | |
1281 | # __profIndex = 0 |
|
1429 | # __profIndex = 0 | |
1282 | # |
|
1430 | # | |
1283 | # def __init__(self, **kwargs): |
|
1431 | # def __init__(self, **kwargs): | |
1284 | # |
|
1432 | # | |
1285 | # Operation.__init__(self, **kwargs) |
|
1433 | # Operation.__init__(self, **kwargs) | |
1286 | # # self.isConfig = False |
|
1434 | # # self.isConfig = False | |
1287 | # self.__powBuffer = None |
|
1435 | # self.__powBuffer = None | |
1288 | # self.__startIndex = 0 |
|
1436 | # self.__startIndex = 0 | |
1289 | # self.__pulseFound = False |
|
1437 | # self.__pulseFound = False | |
1290 | # |
|
1438 | # | |
1291 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1439 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1292 | # |
|
1440 | # | |
1293 | # #Read data |
|
1441 | # #Read data | |
1294 | # |
|
1442 | # | |
1295 | # powerdB = dataOut.getPower(channel = channel) |
|
1443 | # powerdB = dataOut.getPower(channel = channel) | |
1296 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1444 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1297 | # |
|
1445 | # | |
1298 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1446 | # self.__powBuffer.extend(powerdB.flatten()) | |
1299 | # |
|
1447 | # | |
1300 | # dataArray = numpy.array(self.__powBuffer) |
|
1448 | # dataArray = numpy.array(self.__powBuffer) | |
1301 | # |
|
1449 | # | |
1302 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1450 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1303 | # |
|
1451 | # | |
1304 | # maxValue = numpy.nanmax(filteredPower) |
|
1452 | # maxValue = numpy.nanmax(filteredPower) | |
1305 | # |
|
1453 | # | |
1306 | # if maxValue < noisedB + 10: |
|
1454 | # if maxValue < noisedB + 10: | |
1307 | # #No se encuentra ningun pulso de transmision |
|
1455 | # #No se encuentra ningun pulso de transmision | |
1308 | # return None |
|
1456 | # return None | |
1309 | # |
|
1457 | # | |
1310 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1458 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1311 | # |
|
1459 | # | |
1312 | # if len(maxValuesIndex) < 2: |
|
1460 | # if len(maxValuesIndex) < 2: | |
1313 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1461 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1314 | # return None |
|
1462 | # return None | |
1315 | # |
|
1463 | # | |
1316 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1464 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1317 | # |
|
1465 | # | |
1318 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1466 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1319 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1467 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1320 | # |
|
1468 | # | |
1321 | # if len(pulseIndex) < 2: |
|
1469 | # if len(pulseIndex) < 2: | |
1322 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1470 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1323 | # return None |
|
1471 | # return None | |
1324 | # |
|
1472 | # | |
1325 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1473 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1326 | # |
|
1474 | # | |
1327 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1475 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1328 | # #(No deberian existir IPP menor a 10 unidades) |
|
1476 | # #(No deberian existir IPP menor a 10 unidades) | |
1329 | # |
|
1477 | # | |
1330 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1478 | # realIndex = numpy.where(spacing > 10 )[0] | |
1331 | # |
|
1479 | # | |
1332 | # if len(realIndex) < 2: |
|
1480 | # if len(realIndex) < 2: | |
1333 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1481 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1334 | # return None |
|
1482 | # return None | |
1335 | # |
|
1483 | # | |
1336 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1484 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1337 | # realPulseIndex = pulseIndex[realIndex] |
|
1485 | # realPulseIndex = pulseIndex[realIndex] | |
1338 | # |
|
1486 | # | |
1339 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1487 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1340 | # |
|
1488 | # | |
1341 | # print "IPP = %d samples" %period |
|
1489 | # print "IPP = %d samples" %period | |
1342 | # |
|
1490 | # | |
1343 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1491 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1344 | # self.__startIndex = int(realPulseIndex[0]) |
|
1492 | # self.__startIndex = int(realPulseIndex[0]) | |
1345 | # |
|
1493 | # | |
1346 | # return 1 |
|
1494 | # return 1 | |
1347 | # |
|
1495 | # | |
1348 | # |
|
1496 | # | |
1349 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1497 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1350 | # |
|
1498 | # | |
1351 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1499 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1352 | # maxlen = buffer_size*nSamples) |
|
1500 | # maxlen = buffer_size*nSamples) | |
1353 | # |
|
1501 | # | |
1354 | # bufferList = [] |
|
1502 | # bufferList = [] | |
1355 | # |
|
1503 | # | |
1356 | # for i in range(nChannels): |
|
1504 | # for i in range(nChannels): | |
1357 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1505 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1358 | # maxlen = buffer_size*nSamples) |
|
1506 | # maxlen = buffer_size*nSamples) | |
1359 | # |
|
1507 | # | |
1360 | # bufferList.append(bufferByChannel) |
|
1508 | # bufferList.append(bufferByChannel) | |
1361 | # |
|
1509 | # | |
1362 | # self.__nSamples = nSamples |
|
1510 | # self.__nSamples = nSamples | |
1363 | # self.__nChannels = nChannels |
|
1511 | # self.__nChannels = nChannels | |
1364 | # self.__bufferList = bufferList |
|
1512 | # self.__bufferList = bufferList | |
1365 | # |
|
1513 | # | |
1366 | # def run(self, dataOut, channel = 0): |
|
1514 | # def run(self, dataOut, channel = 0): | |
1367 | # |
|
1515 | # | |
1368 | # if not self.isConfig: |
|
1516 | # if not self.isConfig: | |
1369 | # nSamples = dataOut.nHeights |
|
1517 | # nSamples = dataOut.nHeights | |
1370 | # nChannels = dataOut.nChannels |
|
1518 | # nChannels = dataOut.nChannels | |
1371 | # self.setup(nSamples, nChannels) |
|
1519 | # self.setup(nSamples, nChannels) | |
1372 | # self.isConfig = True |
|
1520 | # self.isConfig = True | |
1373 | # |
|
1521 | # | |
1374 | # #Append new data to internal buffer |
|
1522 | # #Append new data to internal buffer | |
1375 | # for thisChannel in range(self.__nChannels): |
|
1523 | # for thisChannel in range(self.__nChannels): | |
1376 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1524 | # bufferByChannel = self.__bufferList[thisChannel] | |
1377 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1525 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1378 | # |
|
1526 | # | |
1379 | # if self.__pulseFound: |
|
1527 | # if self.__pulseFound: | |
1380 | # self.__startIndex -= self.__nSamples |
|
1528 | # self.__startIndex -= self.__nSamples | |
1381 | # |
|
1529 | # | |
1382 | # #Finding Tx Pulse |
|
1530 | # #Finding Tx Pulse | |
1383 | # if not self.__pulseFound: |
|
1531 | # if not self.__pulseFound: | |
1384 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1532 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1385 | # |
|
1533 | # | |
1386 | # if indexFound == None: |
|
1534 | # if indexFound == None: | |
1387 | # dataOut.flagNoData = True |
|
1535 | # dataOut.flagNoData = True | |
1388 | # return |
|
1536 | # return | |
1389 | # |
|
1537 | # | |
1390 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1538 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1391 | # self.__pulseFound = True |
|
1539 | # self.__pulseFound = True | |
1392 | # self.__startIndex = indexFound |
|
1540 | # self.__startIndex = indexFound | |
1393 | # |
|
1541 | # | |
1394 | # #If pulse was found ... |
|
1542 | # #If pulse was found ... | |
1395 | # for thisChannel in range(self.__nChannels): |
|
1543 | # for thisChannel in range(self.__nChannels): | |
1396 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1544 | # bufferByChannel = self.__bufferList[thisChannel] | |
1397 | # #print self.__startIndex |
|
1545 | # #print self.__startIndex | |
1398 | # x = numpy.array(bufferByChannel) |
|
1546 | # x = numpy.array(bufferByChannel) | |
1399 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1547 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1400 | # |
|
1548 | # | |
1401 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1549 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1402 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1550 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1403 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1551 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1404 | # |
|
1552 | # | |
1405 | # dataOut.data = self.__arrayBuffer |
|
1553 | # dataOut.data = self.__arrayBuffer | |
1406 | # |
|
1554 | # | |
1407 | # self.__startIndex += self.__newNSamples |
|
1555 | # self.__startIndex += self.__newNSamples | |
1408 | # |
|
1556 | # | |
1409 | # return |
|
1557 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now