@@ -1,777 +1,781 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author$ |
|
4 | 4 | $Id$ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | 9 | import glob |
|
10 | 10 | import fnmatch |
|
11 | 11 | import time, datetime |
|
12 | 12 | |
|
13 | 13 | path = os.path.split(os.getcwd())[0] |
|
14 | 14 | sys.path.append(path) |
|
15 | 15 | |
|
16 | 16 | from JROHeaderIO import * |
|
17 | 17 | from JRODataIO import JRODataReader |
|
18 | 18 | from JRODataIO import JRODataWriter |
|
19 | 19 | |
|
20 | 20 | from Data.JROData import Spectra |
|
21 | 21 | |
|
22 | 22 | class SpectraReader(JRODataReader): |
|
23 | 23 | """ |
|
24 | 24 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
25 | 25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
26 | 26 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
27 | 27 | |
|
28 | 28 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
29 | 29 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
30 | 30 | canales * alturas (DC Channels) |
|
31 | 31 | |
|
32 | 32 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
33 | 33 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
34 | 34 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
35 | 35 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
36 | 36 | |
|
37 | 37 | Example: |
|
38 | 38 | dpath = "/home/myuser/data" |
|
39 | 39 | |
|
40 | 40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
41 | 41 | |
|
42 | 42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
43 | 43 | |
|
44 | 44 | readerObj = SpectraReader() |
|
45 | 45 | |
|
46 | 46 | readerObj.setup(dpath, startTime, endTime) |
|
47 | 47 | |
|
48 | 48 | while(True): |
|
49 | 49 | |
|
50 | 50 | readerObj.getData() |
|
51 | 51 | |
|
52 | 52 | print readerObj.data_spc |
|
53 | 53 | |
|
54 | 54 | print readerObj.data_cspc |
|
55 | 55 | |
|
56 | 56 | print readerObj.data_dc |
|
57 | 57 | |
|
58 | 58 | if readerObj.flagNoMoreFiles: |
|
59 | 59 | break |
|
60 | 60 | |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | pts2read_SelfSpectra = 0 |
|
64 | 64 | |
|
65 | 65 | pts2read_CrossSpectra = 0 |
|
66 | 66 | |
|
67 | 67 | pts2read_DCchannels = 0 |
|
68 | 68 | |
|
69 | 69 | ext = ".pdata" |
|
70 | 70 | |
|
71 | 71 | optchar = "P" |
|
72 | 72 | |
|
73 | 73 | dataOutObj = None |
|
74 | 74 | |
|
75 | 75 | nRdChannels = None |
|
76 | 76 | |
|
77 | 77 | nRdPairs = None |
|
78 | 78 | |
|
79 | 79 | rdPairList = [] |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | def __init__(self, dataOutObj=None): |
|
83 | 83 | """ |
|
84 | 84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
85 | 85 | |
|
86 | 86 | Inputs: |
|
87 | 87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
88 | 88 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
89 | 89 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
90 | 90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
91 | 91 | bloque de datos. |
|
92 | 92 | Si este parametro no es pasado se creara uno internamente. |
|
93 | 93 | |
|
94 | 94 | Affected: |
|
95 | 95 | self.dataOutObj |
|
96 | 96 | |
|
97 | 97 | Return : None |
|
98 | 98 | """ |
|
99 | 99 | |
|
100 | 100 | self.pts2read_SelfSpectra = 0 |
|
101 | 101 | |
|
102 | 102 | self.pts2read_CrossSpectra = 0 |
|
103 | 103 | |
|
104 | 104 | self.pts2read_DCchannels = 0 |
|
105 | 105 | |
|
106 | 106 | self.datablock = None |
|
107 | 107 | |
|
108 | 108 | self.utc = None |
|
109 | 109 | |
|
110 | 110 | self.ext = ".pdata" |
|
111 | 111 | |
|
112 | 112 | self.optchar = "P" |
|
113 | 113 | |
|
114 | 114 | self.basicHeaderObj = BasicHeader() |
|
115 | 115 | |
|
116 | 116 | self.systemHeaderObj = SystemHeader() |
|
117 | 117 | |
|
118 | 118 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
119 | 119 | |
|
120 | 120 | self.processingHeaderObj = ProcessingHeader() |
|
121 | 121 | |
|
122 | 122 | self.online = 0 |
|
123 | 123 | |
|
124 | 124 | self.fp = None |
|
125 | 125 | |
|
126 | 126 | self.idFile = None |
|
127 | 127 | |
|
128 | 128 | self.dtype = None |
|
129 | 129 | |
|
130 | 130 | self.fileSizeByHeader = None |
|
131 | 131 | |
|
132 | 132 | self.filenameList = [] |
|
133 | 133 | |
|
134 | 134 | self.filename = None |
|
135 | 135 | |
|
136 | 136 | self.fileSize = None |
|
137 | 137 | |
|
138 | 138 | self.firstHeaderSize = 0 |
|
139 | 139 | |
|
140 | 140 | self.basicHeaderSize = 24 |
|
141 | 141 | |
|
142 | 142 | self.pathList = [] |
|
143 | 143 | |
|
144 | 144 | self.lastUTTime = 0 |
|
145 | 145 | |
|
146 | 146 | self.maxTimeStep = 30 |
|
147 | 147 | |
|
148 | 148 | self.flagNoMoreFiles = 0 |
|
149 | 149 | |
|
150 | 150 | self.set = 0 |
|
151 | 151 | |
|
152 | 152 | self.path = None |
|
153 | 153 | |
|
154 | 154 | self.delay = 3 #seconds |
|
155 | 155 | |
|
156 | 156 | self.nTries = 3 #quantity tries |
|
157 | 157 | |
|
158 | 158 | self.nFiles = 3 #number of files for searching |
|
159 | 159 | |
|
160 | 160 | self.nReadBlocks = 0 |
|
161 | 161 | |
|
162 | 162 | self.flagIsNewFile = 1 |
|
163 | 163 | |
|
164 | 164 | self.ippSeconds = 0 |
|
165 | 165 | |
|
166 | 166 | self.flagTimeBlock = 0 |
|
167 | 167 | |
|
168 | 168 | self.flagIsNewBlock = 0 |
|
169 | 169 | |
|
170 | 170 | self.nTotalBlocks = 0 |
|
171 | 171 | |
|
172 | 172 | self.blocksize = 0 |
|
173 | 173 | |
|
174 | 174 | |
|
175 | 175 | def createObjByDefault(self): |
|
176 | 176 | |
|
177 | 177 | dataObj = Spectra() |
|
178 | 178 | |
|
179 | 179 | return dataObj |
|
180 | 180 | |
|
181 | 181 | def __hasNotDataInBuffer(self): |
|
182 | 182 | return 1 |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | def getBlockDimension(self): |
|
186 | 186 | """ |
|
187 | 187 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
188 | 188 | |
|
189 | 189 | Affected: |
|
190 | 190 | self.nRdChannels |
|
191 | 191 | self.nRdPairs |
|
192 | 192 | self.pts2read_SelfSpectra |
|
193 | 193 | self.pts2read_CrossSpectra |
|
194 | 194 | self.pts2read_DCchannels |
|
195 | 195 | self.blocksize |
|
196 | 196 | self.dataOutObj.nChannels |
|
197 | 197 | self.dataOutObj.nPairs |
|
198 | 198 | |
|
199 | 199 | Return: |
|
200 | 200 | None |
|
201 | 201 | """ |
|
202 | 202 | self.nRdChannels = 0 |
|
203 | 203 | self.nRdPairs = 0 |
|
204 | 204 | self.rdPairList = [] |
|
205 | 205 | |
|
206 | 206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
207 | 207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
208 | 208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
209 | 209 | else: |
|
210 | 210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
211 | 211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
212 | 212 | |
|
213 | 213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
214 | 214 | |
|
215 | 215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
216 | 216 | self.blocksize = self.pts2read_SelfSpectra |
|
217 | 217 | |
|
218 | 218 | if self.processingHeaderObj.flag_cspc: |
|
219 | 219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
220 | 220 | self.blocksize += self.pts2read_CrossSpectra |
|
221 | 221 | |
|
222 | 222 | if self.processingHeaderObj.flag_dc: |
|
223 | 223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
224 | 224 | self.blocksize += self.pts2read_DCchannels |
|
225 | 225 | |
|
226 | 226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | def readBlock(self): |
|
230 | 230 | """ |
|
231 | 231 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
232 | 232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
233 | 233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
234 | 234 | es seteado a 0 |
|
235 | 235 | |
|
236 | 236 | Return: None |
|
237 | 237 | |
|
238 | 238 | Variables afectadas: |
|
239 | 239 | |
|
240 | 240 | self.flagIsNewFile |
|
241 | 241 | self.flagIsNewBlock |
|
242 | 242 | self.nTotalBlocks |
|
243 | 243 | self.data_spc |
|
244 | 244 | self.data_cspc |
|
245 | 245 | self.data_dc |
|
246 | 246 | |
|
247 | 247 | Exceptions: |
|
248 | 248 | Si un bloque leido no es un bloque valido |
|
249 | 249 | """ |
|
250 | 250 | blockOk_flag = False |
|
251 | 251 | fpointer = self.fp.tell() |
|
252 | 252 | |
|
253 | 253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
254 | 254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
255 | 255 | |
|
256 | 256 | if self.processingHeaderObj.flag_cspc: |
|
257 | 257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
258 | 258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
259 | 259 | |
|
260 | 260 | if self.processingHeaderObj.flag_dc: |
|
261 | 261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
262 | 262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
263 | 263 | |
|
264 | 264 | |
|
265 | 265 | if not(self.processingHeaderObj.shif_fft): |
|
266 | 266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
267 | 267 | |
|
268 | 268 | if self.processingHeaderObj.flag_cspc: |
|
269 | 269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
270 | 270 | |
|
271 | 271 | |
|
272 | 272 | spc = numpy.transpose( spc, (0,2,1) ) |
|
273 | 273 | self.data_spc = spc |
|
274 | 274 | |
|
275 | 275 | if self.processingHeaderObj.flag_cspc: |
|
276 | 276 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
277 | 277 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
278 | 278 | else: |
|
279 | 279 | self.data_cspc = None |
|
280 | 280 | |
|
281 | 281 | if self.processingHeaderObj.flag_dc: |
|
282 | 282 | self.data_dc = dc['real'] + dc['imag']*1j |
|
283 | 283 | else: |
|
284 | 284 | self.data_dc = None |
|
285 | 285 | |
|
286 | 286 | self.flagIsNewFile = 0 |
|
287 | 287 | self.flagIsNewBlock = 1 |
|
288 | 288 | |
|
289 | 289 | self.nTotalBlocks += 1 |
|
290 | 290 | self.nReadBlocks += 1 |
|
291 | 291 | |
|
292 | 292 | return 1 |
|
293 | 293 | |
|
294 | 294 | |
|
295 | 295 | def getData(self): |
|
296 | 296 | """ |
|
297 | 297 | Copia el buffer de lectura a la clase "Spectra", |
|
298 | 298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
299 | 299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
300 | 300 | |
|
301 | 301 | Return: |
|
302 | 302 | 0 : Si no hay mas archivos disponibles |
|
303 | 303 | 1 : Si hizo una buena copia del buffer |
|
304 | 304 | |
|
305 | 305 | Affected: |
|
306 | 306 | self.dataOutObj |
|
307 | 307 | |
|
308 | 308 | self.flagTimeBlock |
|
309 | 309 | self.flagIsNewBlock |
|
310 | 310 | """ |
|
311 | 311 | |
|
312 | 312 | if self.flagNoMoreFiles: return 0 |
|
313 | 313 | |
|
314 | 314 | self.flagTimeBlock = 0 |
|
315 | 315 | self.flagIsNewBlock = 0 |
|
316 | 316 | |
|
317 | 317 | if self.__hasNotDataInBuffer(): |
|
318 | 318 | |
|
319 | 319 | if not( self.readNextBlock() ): |
|
320 | 320 | return 0 |
|
321 | 321 | |
|
322 | 322 | # self.updateDataHeader() |
|
323 | 323 | |
|
324 | 324 | if self.flagNoMoreFiles == 1: |
|
325 | 325 | print 'Process finished' |
|
326 | 326 | return 0 |
|
327 | 327 | |
|
328 | 328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
329 | 329 | |
|
330 | 330 | if self.data_dc == None: |
|
331 | 331 | self.dataOutObj.flagNoData = True |
|
332 | 332 | return 0 |
|
333 | 333 | |
|
334 | 334 | |
|
335 | 335 | self.dataOutObj.data_spc = self.data_spc |
|
336 | 336 | |
|
337 | 337 | self.dataOutObj.data_cspc = self.data_cspc |
|
338 | 338 | |
|
339 | 339 | self.dataOutObj.data_dc = self.data_dc |
|
340 | 340 | |
|
341 | 341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
342 | 342 | |
|
343 | 343 | self.dataOutObj.flagNoData = False |
|
344 | 344 | |
|
345 | 345 | self.dataOutObj.dtype = self.dtype |
|
346 | 346 | |
|
347 | 347 | self.dataOutObj.nChannels = self.nRdChannels |
|
348 | 348 | |
|
349 | 349 | self.dataOutObj.nPairs = self.nRdPairs |
|
350 | 350 | |
|
351 | 351 | self.dataOutObj.pairsList = self.rdPairList |
|
352 | 352 | |
|
353 | 353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
354 | 354 | |
|
355 | 355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
356 | 356 | |
|
357 | 357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
358 | 358 | |
|
359 | 359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt |
|
360 | 360 | |
|
361 | 361 | |
|
362 | 362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
363 | 363 | |
|
364 | 364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
365 | 365 | |
|
366 | 366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
367 | 367 | |
|
368 | 368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
369 | 369 | |
|
370 | 370 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
371 | 371 | |
|
372 | self.dataOutObj.ippSeconds = self.ippSeconds | |
|
373 | ||
|
374 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOutObj.nFFTPoints | |
|
375 | ||
|
372 | 376 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
373 | 377 | |
|
374 | 378 | # self.profileIndex += 1 |
|
375 | 379 | |
|
376 | 380 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
377 | 381 | |
|
378 | 382 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
379 | 383 | |
|
380 | 384 | return self.dataOutObj.data_spc |
|
381 | 385 | |
|
382 | 386 | |
|
383 | 387 | class SpectraWriter(JRODataWriter): |
|
384 | 388 | |
|
385 | 389 | """ |
|
386 | 390 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
387 | 391 | de los datos siempre se realiza por bloques. |
|
388 | 392 | """ |
|
389 | 393 | |
|
390 | 394 | ext = ".pdata" |
|
391 | 395 | |
|
392 | 396 | optchar = "P" |
|
393 | 397 | |
|
394 | 398 | shape_spc_Buffer = None |
|
395 | 399 | |
|
396 | 400 | shape_cspc_Buffer = None |
|
397 | 401 | |
|
398 | 402 | shape_dc_Buffer = None |
|
399 | 403 | |
|
400 | 404 | data_spc = None |
|
401 | 405 | |
|
402 | 406 | data_cspc = None |
|
403 | 407 | |
|
404 | 408 | data_dc = None |
|
405 | 409 | |
|
406 | 410 | wrPairList = [] |
|
407 | 411 | |
|
408 | 412 | nWrPairs = 0 |
|
409 | 413 | |
|
410 | 414 | nWrChannels = 0 |
|
411 | 415 | |
|
412 | 416 | # dataOutObj = None |
|
413 | 417 | |
|
414 | 418 | def __init__(self, dataOutObj=None): |
|
415 | 419 | """ |
|
416 | 420 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
417 | 421 | |
|
418 | 422 | Affected: |
|
419 | 423 | self.dataOutObj |
|
420 | 424 | self.basicHeaderObj |
|
421 | 425 | self.systemHeaderObj |
|
422 | 426 | self.radarControllerHeaderObj |
|
423 | 427 | self.processingHeaderObj |
|
424 | 428 | |
|
425 | 429 | Return: None |
|
426 | 430 | """ |
|
427 | 431 | if dataOutObj == None: |
|
428 | 432 | dataOutObj = Spectra() |
|
429 | 433 | |
|
430 | 434 | if not( isinstance(dataOutObj, Spectra) ): |
|
431 | 435 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" |
|
432 | 436 | |
|
433 | 437 | self.dataOutObj = dataOutObj |
|
434 | 438 | |
|
435 | 439 | self.nTotalBlocks = 0 |
|
436 | 440 | |
|
437 | 441 | self.nWrChannels = self.dataOutObj.nChannels |
|
438 | 442 | |
|
439 | 443 | # if len(pairList) > 0: |
|
440 | 444 | # self.wrPairList = pairList |
|
441 | 445 | # |
|
442 | 446 | # self.nWrPairs = len(pairList) |
|
443 | 447 | |
|
444 | 448 | self.wrPairList = self.dataOutObj.pairsList |
|
445 | 449 | |
|
446 | 450 | self.nWrPairs = self.dataOutObj.nPairs |
|
447 | 451 | |
|
448 | 452 | |
|
449 | 453 | |
|
450 | 454 | |
|
451 | 455 | |
|
452 | 456 | # self.data_spc = None |
|
453 | 457 | # self.data_cspc = None |
|
454 | 458 | # self.data_dc = None |
|
455 | 459 | |
|
456 | 460 | # self.fp = None |
|
457 | 461 | |
|
458 | 462 | # self.flagIsNewFile = 1 |
|
459 | 463 | # |
|
460 | 464 | # self.nTotalBlocks = 0 |
|
461 | 465 | # |
|
462 | 466 | # self.flagIsNewBlock = 0 |
|
463 | 467 | # |
|
464 | 468 | # self.flagNoMoreFiles = 0 |
|
465 | 469 | # |
|
466 | 470 | # self.setFile = None |
|
467 | 471 | # |
|
468 | 472 | # self.dtype = None |
|
469 | 473 | # |
|
470 | 474 | # self.path = None |
|
471 | 475 | # |
|
472 | 476 | # self.noMoreFiles = 0 |
|
473 | 477 | # |
|
474 | 478 | # self.filename = None |
|
475 | 479 | # |
|
476 | 480 | # self.basicHeaderObj = BasicHeader() |
|
477 | 481 | # |
|
478 | 482 | # self.systemHeaderObj = SystemHeader() |
|
479 | 483 | # |
|
480 | 484 | # self.radarControllerHeaderObj = RadarControllerHeader() |
|
481 | 485 | # |
|
482 | 486 | # self.processingHeaderObj = ProcessingHeader() |
|
483 | 487 | |
|
484 | 488 | |
|
485 | 489 | def hasAllDataInBuffer(self): |
|
486 | 490 | return 1 |
|
487 | 491 | |
|
488 | 492 | |
|
489 | 493 | def setBlockDimension(self): |
|
490 | 494 | """ |
|
491 | 495 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
492 | 496 | |
|
493 | 497 | Affected: |
|
494 | 498 | self.shape_spc_Buffer |
|
495 | 499 | self.shape_cspc_Buffer |
|
496 | 500 | self.shape_dc_Buffer |
|
497 | 501 | |
|
498 | 502 | Return: None |
|
499 | 503 | """ |
|
500 | 504 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, |
|
501 | 505 | self.processingHeaderObj.nHeights, |
|
502 | 506 | self.processingHeaderObj.profilesPerBlock) |
|
503 | 507 | |
|
504 | 508 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, |
|
505 | 509 | self.processingHeaderObj.nHeights, |
|
506 | 510 | self.processingHeaderObj.profilesPerBlock) |
|
507 | 511 | |
|
508 | 512 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, |
|
509 | 513 | self.processingHeaderObj.nHeights) |
|
510 | 514 | |
|
511 | 515 | |
|
512 | 516 | def writeBlock(self): |
|
513 | 517 | """ |
|
514 | 518 | Escribe el buffer en el file designado |
|
515 | 519 | |
|
516 | 520 | Affected: |
|
517 | 521 | self.data_spc |
|
518 | 522 | self.data_cspc |
|
519 | 523 | self.data_dc |
|
520 | 524 | self.flagIsNewFile |
|
521 | 525 | self.flagIsNewBlock |
|
522 | 526 | self.nTotalBlocks |
|
523 | 527 | self.nWriteBlocks |
|
524 | 528 | |
|
525 | 529 | Return: None |
|
526 | 530 | """ |
|
527 | 531 | |
|
528 | 532 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
529 | 533 | if not( self.processingHeaderObj.shif_fft ): |
|
530 | 534 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
531 | 535 | data = spc.reshape((-1)) |
|
532 | 536 | data.tofile(self.fp) |
|
533 | 537 | |
|
534 | 538 | if self.data_cspc != None: |
|
535 | 539 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
536 | 540 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
537 | 541 | if not( self.processingHeaderObj.shif_fft ): |
|
538 | 542 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
539 | 543 | data['real'] = cspc.real |
|
540 | 544 | data['imag'] = cspc.imag |
|
541 | 545 | data = data.reshape((-1)) |
|
542 | 546 | data.tofile(self.fp) |
|
543 | 547 | |
|
544 | 548 | if self.data_dc != None: |
|
545 | 549 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
546 | 550 | dc = self.data_dc |
|
547 | 551 | data['real'] = dc.real |
|
548 | 552 | data['imag'] = dc.imag |
|
549 | 553 | data = data.reshape((-1)) |
|
550 | 554 | data.tofile(self.fp) |
|
551 | 555 | |
|
552 | 556 | self.data_spc.fill(0) |
|
553 | 557 | self.data_dc.fill(0) |
|
554 | 558 | if self.data_cspc != None: |
|
555 | 559 | self.data_cspc.fill(0) |
|
556 | 560 | |
|
557 | 561 | self.flagIsNewFile = 0 |
|
558 | 562 | self.flagIsNewBlock = 1 |
|
559 | 563 | self.nTotalBlocks += 1 |
|
560 | 564 | self.nWriteBlocks += 1 |
|
561 | 565 | self.blockIndex += 1 |
|
562 | 566 | |
|
563 | 567 | |
|
564 | 568 | def putData(self): |
|
565 | 569 | """ |
|
566 | 570 | Setea un bloque de datos y luego los escribe en un file |
|
567 | 571 | |
|
568 | 572 | Affected: |
|
569 | 573 | self.data_spc |
|
570 | 574 | self.data_cspc |
|
571 | 575 | self.data_dc |
|
572 | 576 | |
|
573 | 577 | Return: |
|
574 | 578 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
575 | 579 | 1 : Si se escribio la data de un bloque en un file |
|
576 | 580 | """ |
|
577 | 581 | self.flagIsNewBlock = 0 |
|
578 | 582 | |
|
579 | 583 | if self.dataOutObj.flagNoData: |
|
580 | 584 | return 0 |
|
581 | 585 | |
|
582 | 586 | if self.dataOutObj.flagTimeBlock: |
|
583 | 587 | self.data_spc.fill(0) |
|
584 | 588 | self.data_cspc.fill(0) |
|
585 | 589 | self.data_dc.fill(0) |
|
586 | 590 | self.setNextFile() |
|
587 | 591 | |
|
588 | 592 | if self.flagIsNewFile == 0: |
|
589 | 593 | self.getBasicHeader() |
|
590 | 594 | |
|
591 | 595 | self.data_spc = self.dataOutObj.data_spc |
|
592 | 596 | self.data_cspc = self.dataOutObj.data_cspc |
|
593 | 597 | self.data_dc = self.dataOutObj.data_dc |
|
594 | 598 | |
|
595 | 599 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
596 | 600 | if self.hasAllDataInBuffer(): |
|
597 | 601 | # self.getDataHeader() |
|
598 | 602 | self.writeNextBlock() |
|
599 | 603 | |
|
600 | 604 | if self.flagNoMoreFiles: |
|
601 | 605 | #print 'Process finished' |
|
602 | 606 | return 0 |
|
603 | 607 | |
|
604 | 608 | return 1 |
|
605 | 609 | |
|
606 | 610 | |
|
607 | 611 | def __getProcessFlags(self): |
|
608 | 612 | |
|
609 | 613 | processFlags = 0 |
|
610 | 614 | |
|
611 | 615 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
612 | 616 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
613 | 617 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
614 | 618 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
615 | 619 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
616 | 620 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
617 | 621 | |
|
618 | 622 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
619 | 623 | |
|
620 | 624 | |
|
621 | 625 | |
|
622 | 626 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
623 | 627 | PROCFLAG.DATATYPE_SHORT, |
|
624 | 628 | PROCFLAG.DATATYPE_LONG, |
|
625 | 629 | PROCFLAG.DATATYPE_INT64, |
|
626 | 630 | PROCFLAG.DATATYPE_FLOAT, |
|
627 | 631 | PROCFLAG.DATATYPE_DOUBLE] |
|
628 | 632 | |
|
629 | 633 | |
|
630 | 634 | for index in range(len(dtypeList)): |
|
631 | 635 | if self.dataOutObj.dtype == dtypeList[index]: |
|
632 | 636 | dtypeValue = datatypeValueList[index] |
|
633 | 637 | break |
|
634 | 638 | |
|
635 | 639 | processFlags += dtypeValue |
|
636 | 640 | |
|
637 | 641 | if self.dataOutObj.flagDecodeData: |
|
638 | 642 | processFlags += PROCFLAG.DECODE_DATA |
|
639 | 643 | |
|
640 | 644 | if self.dataOutObj.flagDeflipData: |
|
641 | 645 | processFlags += PROCFLAG.DEFLIP_DATA |
|
642 | 646 | |
|
643 | 647 | if self.dataOutObj.code != None: |
|
644 | 648 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
645 | 649 | |
|
646 | 650 | if self.dataOutObj.nIncohInt > 1: |
|
647 | 651 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
648 | 652 | |
|
649 | 653 | if self.dataOutObj.data_dc != None: |
|
650 | 654 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
651 | 655 | |
|
652 | 656 | return processFlags |
|
653 | 657 | |
|
654 | 658 | |
|
655 | 659 | def __getBlockSize(self): |
|
656 | 660 | ''' |
|
657 | 661 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
658 | 662 | ''' |
|
659 | 663 | |
|
660 | 664 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
661 | 665 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
662 | 666 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
663 | 667 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
664 | 668 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
665 | 669 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
666 | 670 | |
|
667 | 671 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
668 | 672 | datatypeValueList = [1,2,4,8,4,8] |
|
669 | 673 | for index in range(len(dtypeList)): |
|
670 | 674 | if self.dataOutObj.dtype == dtypeList[index]: |
|
671 | 675 | datatypeValue = datatypeValueList[index] |
|
672 | 676 | break |
|
673 | 677 | |
|
674 | 678 | |
|
675 | 679 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints |
|
676 | 680 | |
|
677 | 681 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) |
|
678 | 682 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
679 | 683 | |
|
680 | 684 | if self.dataOutObj.data_cspc != None: |
|
681 | 685 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) |
|
682 | 686 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
683 | 687 | |
|
684 | 688 | if self.dataOutObj.data_dc != None: |
|
685 | 689 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) |
|
686 | 690 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
687 | 691 | |
|
688 | 692 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
689 | 693 | |
|
690 | 694 | return blocksize |
|
691 | 695 | |
|
692 | 696 | |
|
693 | 697 | def getBasicHeader(self): |
|
694 | 698 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
695 | 699 | self.basicHeaderObj.version = self.versionFile |
|
696 | 700 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
697 | 701 | |
|
698 | 702 | utc = numpy.floor(self.dataOutObj.utctime) |
|
699 | 703 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 |
|
700 | 704 | |
|
701 | 705 | self.basicHeaderObj.utc = utc |
|
702 | 706 | self.basicHeaderObj.miliSecond = milisecond |
|
703 | 707 | self.basicHeaderObj.timeZone = 0 |
|
704 | 708 | self.basicHeaderObj.dstFlag = 0 |
|
705 | 709 | self.basicHeaderObj.errorCount = 0 |
|
706 | 710 | |
|
707 | 711 | def getDataHeader(self): |
|
708 | 712 | |
|
709 | 713 | """ |
|
710 | 714 | Obtiene una copia del First Header |
|
711 | 715 | |
|
712 | 716 | Affected: |
|
713 | 717 | self.systemHeaderObj |
|
714 | 718 | self.radarControllerHeaderObj |
|
715 | 719 | self.dtype |
|
716 | 720 | |
|
717 | 721 | Return: |
|
718 | 722 | None |
|
719 | 723 | """ |
|
720 | 724 | |
|
721 | 725 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
722 | 726 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
723 | 727 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
724 | 728 | |
|
725 | 729 | self.getBasicHeader() |
|
726 | 730 | |
|
727 | 731 | processingHeaderSize = 40 # bytes |
|
728 | 732 | self.processingHeaderObj.dtype = 0 # Voltage |
|
729 | 733 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
730 | 734 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints |
|
731 | 735 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
732 | 736 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
733 | 737 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
734 | 738 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra |
|
735 | 739 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt |
|
736 | 740 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels |
|
737 | 741 | |
|
738 | 742 | if self.processingHeaderObj.totalSpectra > 0: |
|
739 | 743 | channelList = [] |
|
740 | 744 | for channel in range(self.dataOutObj.nChannels): |
|
741 | 745 | channelList.append(channel) |
|
742 | 746 | channelList.append(channel) |
|
743 | 747 | |
|
744 | 748 | pairsList = [] |
|
745 | 749 | for pair in self.dataOutObj.pairsList: |
|
746 | 750 | pairsList.append(pair[0]) |
|
747 | 751 | pairsList.append(pair[1]) |
|
748 | 752 | spectraComb = channelList + pairsList |
|
749 | 753 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
750 | 754 | self.processingHeaderObj.spectraComb = spectraComb |
|
751 | 755 | sizeOfSpcComb = len(spectraComb) |
|
752 | 756 | processingHeaderSize += sizeOfSpcComb |
|
753 | 757 | |
|
754 | 758 | if self.dataOutObj.code != None: |
|
755 | 759 | self.processingHeaderObj.code = self.dataOutObj.code |
|
756 | 760 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
757 | 761 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
758 | 762 | nCodeSize = 4 # bytes |
|
759 | 763 | nBaudSize = 4 # bytes |
|
760 | 764 | codeSize = 4 # bytes |
|
761 | 765 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
762 | 766 | processingHeaderSize += sizeOfCode |
|
763 | 767 | |
|
764 | 768 | if self.processingHeaderObj.nWindows != 0: |
|
765 | 769 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
766 | 770 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
767 | 771 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
768 | 772 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
769 | 773 | sizeOfFirstHeight = 4 |
|
770 | 774 | sizeOfdeltaHeight = 4 |
|
771 | 775 | sizeOfnHeights = 4 |
|
772 | 776 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
773 | 777 | processingHeaderSize += sizeOfWindows |
|
774 | 778 | |
|
775 | 779 | self.processingHeaderObj.size = processingHeaderSize |
|
776 | 780 | |
|
777 | 781 | No newline at end of file |
@@ -1,592 +1,592 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author$ |
|
4 | 4 | $Id$ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | 9 | import glob |
|
10 | 10 | import fnmatch |
|
11 | 11 | import time, datetime |
|
12 | 12 | |
|
13 | 13 | path = os.path.split(os.getcwd())[0] |
|
14 | 14 | sys.path.append(path) |
|
15 | 15 | |
|
16 | 16 | from JROHeaderIO import * |
|
17 | 17 | from JRODataIO import JRODataReader |
|
18 | 18 | from JRODataIO import JRODataWriter |
|
19 | 19 | |
|
20 | 20 | from Data.JROData import Voltage |
|
21 | 21 | |
|
22 | 22 | class VoltageReader(JRODataReader): |
|
23 | 23 | """ |
|
24 | 24 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
25 | 25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
26 | 26 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
27 | 27 | |
|
28 | 28 | perfiles * alturas * canales |
|
29 | 29 | |
|
30 | 30 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
31 | 31 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
32 | 32 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
33 | 33 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
34 | 34 | |
|
35 | 35 | Example: |
|
36 | 36 | |
|
37 | 37 | dpath = "/home/myuser/data" |
|
38 | 38 | |
|
39 | 39 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
40 | 40 | |
|
41 | 41 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
42 | 42 | |
|
43 | 43 | readerObj = VoltageReader() |
|
44 | 44 | |
|
45 | 45 | readerObj.setup(dpath, startTime, endTime) |
|
46 | 46 | |
|
47 | 47 | while(True): |
|
48 | 48 | |
|
49 | 49 | #to get one profile |
|
50 | 50 | profile = readerObj.getData() |
|
51 | 51 | |
|
52 | 52 | #print the profile |
|
53 | 53 | print profile |
|
54 | 54 | |
|
55 | 55 | #If you want to see all datablock |
|
56 | 56 | print readerObj.datablock |
|
57 | 57 | |
|
58 | 58 | if readerObj.flagNoMoreFiles: |
|
59 | 59 | break |
|
60 | 60 | |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | ext = ".r" |
|
64 | 64 | |
|
65 | 65 | optchar = "D" |
|
66 | 66 | dataOutObj = None |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | def __init__(self, dataOutObj=None): |
|
70 | 70 | """ |
|
71 | 71 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
72 | 72 | |
|
73 | 73 | Input: |
|
74 | 74 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
75 | 75 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
76 | 76 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
77 | 77 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
78 | 78 | bloque de datos. |
|
79 | 79 | Si este parametro no es pasado se creara uno internamente. |
|
80 | 80 | |
|
81 | 81 | Variables afectadas: |
|
82 | 82 | self.dataOutObj |
|
83 | 83 | |
|
84 | 84 | Return: |
|
85 | 85 | None |
|
86 | 86 | """ |
|
87 | 87 | |
|
88 | 88 | self.datablock = None |
|
89 | 89 | |
|
90 | 90 | self.utc = 0 |
|
91 | 91 | |
|
92 | 92 | self.ext = ".r" |
|
93 | 93 | |
|
94 | 94 | self.optchar = "D" |
|
95 | 95 | |
|
96 | 96 | self.basicHeaderObj = BasicHeader() |
|
97 | 97 | |
|
98 | 98 | self.systemHeaderObj = SystemHeader() |
|
99 | 99 | |
|
100 | 100 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
101 | 101 | |
|
102 | 102 | self.processingHeaderObj = ProcessingHeader() |
|
103 | 103 | |
|
104 | 104 | self.online = 0 |
|
105 | 105 | |
|
106 | 106 | self.fp = None |
|
107 | 107 | |
|
108 | 108 | self.idFile = None |
|
109 | 109 | |
|
110 | 110 | self.dtype = None |
|
111 | 111 | |
|
112 | 112 | self.fileSizeByHeader = None |
|
113 | 113 | |
|
114 | 114 | self.filenameList = [] |
|
115 | 115 | |
|
116 | 116 | self.filename = None |
|
117 | 117 | |
|
118 | 118 | self.fileSize = None |
|
119 | 119 | |
|
120 | 120 | self.firstHeaderSize = 0 |
|
121 | 121 | |
|
122 | 122 | self.basicHeaderSize = 24 |
|
123 | 123 | |
|
124 | 124 | self.pathList = [] |
|
125 | 125 | |
|
126 | 126 | self.filenameList = [] |
|
127 | 127 | |
|
128 | 128 | self.lastUTTime = 0 |
|
129 | 129 | |
|
130 | 130 | self.maxTimeStep = 30 |
|
131 | 131 | |
|
132 | 132 | self.flagNoMoreFiles = 0 |
|
133 | 133 | |
|
134 | 134 | self.set = 0 |
|
135 | 135 | |
|
136 | 136 | self.path = None |
|
137 | 137 | |
|
138 | 138 | self.profileIndex = 9999 |
|
139 | 139 | |
|
140 | 140 | self.delay = 3 #seconds |
|
141 | 141 | |
|
142 | 142 | self.nTries = 3 #quantity tries |
|
143 | 143 | |
|
144 | 144 | self.nFiles = 3 #number of files for searching |
|
145 | 145 | |
|
146 | 146 | self.nReadBlocks = 0 |
|
147 | 147 | |
|
148 | 148 | self.flagIsNewFile = 1 |
|
149 | 149 | |
|
150 | 150 | self.ippSeconds = 0 |
|
151 | 151 | |
|
152 | 152 | self.flagTimeBlock = 0 |
|
153 | 153 | |
|
154 | 154 | self.flagIsNewBlock = 0 |
|
155 | 155 | |
|
156 | 156 | self.nTotalBlocks = 0 |
|
157 | 157 | |
|
158 | 158 | self.blocksize = 0 |
|
159 | 159 | |
|
160 | 160 | def createObjByDefault(self): |
|
161 | 161 | |
|
162 | 162 | dataObj = Voltage() |
|
163 | 163 | |
|
164 | 164 | return dataObj |
|
165 | 165 | |
|
166 | 166 | def __hasNotDataInBuffer(self): |
|
167 | 167 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
168 | 168 | return 1 |
|
169 | 169 | return 0 |
|
170 | 170 | |
|
171 | 171 | |
|
172 | 172 | def getBlockDimension(self): |
|
173 | 173 | """ |
|
174 | 174 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
175 | 175 | |
|
176 | 176 | Affected: |
|
177 | 177 | self.blocksize |
|
178 | 178 | |
|
179 | 179 | Return: |
|
180 | 180 | None |
|
181 | 181 | """ |
|
182 | 182 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
183 | 183 | self.blocksize = pts2read |
|
184 | 184 | |
|
185 | 185 | |
|
186 | 186 | def readBlock(self): |
|
187 | 187 | """ |
|
188 | 188 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
189 | 189 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
190 | 190 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
191 | 191 | es seteado a 0 |
|
192 | 192 | |
|
193 | 193 | Inputs: |
|
194 | 194 | None |
|
195 | 195 | |
|
196 | 196 | Return: |
|
197 | 197 | None |
|
198 | 198 | |
|
199 | 199 | Affected: |
|
200 | 200 | self.profileIndex |
|
201 | 201 | self.datablock |
|
202 | 202 | self.flagIsNewFile |
|
203 | 203 | self.flagIsNewBlock |
|
204 | 204 | self.nTotalBlocks |
|
205 | 205 | |
|
206 | 206 | Exceptions: |
|
207 | 207 | Si un bloque leido no es un bloque valido |
|
208 | 208 | """ |
|
209 | 209 | |
|
210 | 210 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
211 | 211 | |
|
212 | 212 | try: |
|
213 | 213 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
214 | 214 | except: |
|
215 | 215 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
216 | 216 | return 0 |
|
217 | 217 | |
|
218 | 218 | junk = numpy.transpose(junk, (2,0,1)) |
|
219 | 219 | self.datablock = junk['real'] + junk['imag']*1j |
|
220 | 220 | |
|
221 | 221 | self.profileIndex = 0 |
|
222 | 222 | |
|
223 | 223 | self.flagIsNewFile = 0 |
|
224 | 224 | self.flagIsNewBlock = 1 |
|
225 | 225 | |
|
226 | 226 | self.nTotalBlocks += 1 |
|
227 | 227 | self.nReadBlocks += 1 |
|
228 | 228 | |
|
229 | 229 | return 1 |
|
230 | 230 | |
|
231 | 231 | |
|
232 | 232 | def getData(self): |
|
233 | 233 | """ |
|
234 | 234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
235 | 235 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
236 | 236 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
237 | 237 | |
|
238 | 238 | Ademas incrementa el contador del buffer en 1. |
|
239 | 239 | |
|
240 | 240 | Return: |
|
241 | 241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
242 | 242 | buffer. Si no hay mas archivos a leer retorna None. |
|
243 | 243 | |
|
244 | 244 | Variables afectadas: |
|
245 | 245 | self.dataOutObj |
|
246 | 246 | self.profileIndex |
|
247 | 247 | |
|
248 | 248 | Affected: |
|
249 | 249 | self.dataOutObj |
|
250 | 250 | self.profileIndex |
|
251 | 251 | self.flagTimeBlock |
|
252 | 252 | self.flagIsNewBlock |
|
253 | 253 | """ |
|
254 | 254 | if self.flagNoMoreFiles: return 0 |
|
255 | 255 | |
|
256 | 256 | self.flagTimeBlock = 0 |
|
257 | 257 | self.flagIsNewBlock = 0 |
|
258 | 258 | |
|
259 | 259 | if self.__hasNotDataInBuffer(): |
|
260 | 260 | |
|
261 | 261 | if not( self.readNextBlock() ): |
|
262 | 262 | return 0 |
|
263 | 263 | |
|
264 | 264 | # self.updateDataHeader() |
|
265 | 265 | |
|
266 | 266 | if self.flagNoMoreFiles == 1: |
|
267 | 267 | print 'Process finished' |
|
268 | 268 | return 0 |
|
269 | 269 | |
|
270 | 270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
271 | 271 | |
|
272 | 272 | if self.datablock == None: |
|
273 | 273 | self.dataOutObj.flagNoData = True |
|
274 | 274 | return 0 |
|
275 | 275 | |
|
276 | 276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] |
|
277 | 277 | |
|
278 | 278 | self.dataOutObj.dtype = self.dtype |
|
279 | 279 | |
|
280 | 280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels |
|
281 | 281 | |
|
282 | 282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
283 | 283 | |
|
284 | 284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
285 | 285 | |
|
286 | 286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
287 | 287 | |
|
288 | 288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
289 | 289 | |
|
290 | 290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
291 | 291 | |
|
292 | 292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
293 | 293 | |
|
294 | 294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
295 | 295 | |
|
296 | 296 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
297 | 297 | |
|
298 | 298 | self.dataOutObj.ippSeconds = self.ippSeconds |
|
299 | 299 | |
|
300 | self.dataOutObj.timeInterval = self.ippSeconds | |
|
300 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
|
301 | 301 | |
|
302 | 302 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt |
|
303 | 303 | |
|
304 | 304 | self.dataOutObj.flagShiftFFT = False |
|
305 | 305 | |
|
306 | 306 | if self.processingHeaderObj.code != None: |
|
307 | 307 | self.dataOutObj.nCode = self.processingHeaderObj.nCode |
|
308 | 308 | |
|
309 | 309 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud |
|
310 | 310 | |
|
311 | 311 | self.dataOutObj.code = self.processingHeaderObj.code |
|
312 | 312 | |
|
313 | 313 | self.profileIndex += 1 |
|
314 | 314 | |
|
315 | 315 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
316 | 316 | |
|
317 | 317 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
318 | 318 | |
|
319 | 319 | self.dataOutObj.flagNoData = False |
|
320 | 320 | |
|
321 | 321 | # print self.profileIndex, self.dataOutObj.utctime |
|
322 | 322 | # if self.profileIndex == 800: |
|
323 | 323 | # a=1 |
|
324 | 324 | |
|
325 | 325 | return self.dataOutObj.data |
|
326 | 326 | |
|
327 | 327 | |
|
328 | 328 | class VoltageWriter(JRODataWriter): |
|
329 | 329 | """ |
|
330 | 330 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
331 | 331 | de los datos siempre se realiza por bloques. |
|
332 | 332 | """ |
|
333 | 333 | |
|
334 | 334 | ext = ".r" |
|
335 | 335 | |
|
336 | 336 | optchar = "D" |
|
337 | 337 | |
|
338 | 338 | shapeBuffer = None |
|
339 | 339 | |
|
340 | 340 | |
|
341 | 341 | def __init__(self, dataOutObj=None): |
|
342 | 342 | """ |
|
343 | 343 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
344 | 344 | |
|
345 | 345 | Affected: |
|
346 | 346 | self.dataOutObj |
|
347 | 347 | |
|
348 | 348 | Return: None |
|
349 | 349 | """ |
|
350 | 350 | if dataOutObj == None: |
|
351 | 351 | dataOutObj = Voltage() |
|
352 | 352 | |
|
353 | 353 | if not( isinstance(dataOutObj, Voltage) ): |
|
354 | 354 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" |
|
355 | 355 | |
|
356 | 356 | self.dataOutObj = dataOutObj |
|
357 | 357 | |
|
358 | 358 | self.nTotalBlocks = 0 |
|
359 | 359 | |
|
360 | 360 | self.profileIndex = 0 |
|
361 | 361 | |
|
362 | 362 | def hasAllDataInBuffer(self): |
|
363 | 363 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
364 | 364 | return 1 |
|
365 | 365 | return 0 |
|
366 | 366 | |
|
367 | 367 | |
|
368 | 368 | def setBlockDimension(self): |
|
369 | 369 | """ |
|
370 | 370 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
371 | 371 | |
|
372 | 372 | Affected: |
|
373 | 373 | self.shape_spc_Buffer |
|
374 | 374 | self.shape_cspc_Buffer |
|
375 | 375 | self.shape_dc_Buffer |
|
376 | 376 | |
|
377 | 377 | Return: None |
|
378 | 378 | """ |
|
379 | 379 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
380 | 380 | self.processingHeaderObj.nHeights, |
|
381 | 381 | self.systemHeaderObj.nChannels) |
|
382 | 382 | |
|
383 | 383 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
384 | 384 | self.processingHeaderObj.profilesPerBlock, |
|
385 | 385 | self.processingHeaderObj.nHeights), |
|
386 | 386 | dtype=numpy.dtype('complex')) |
|
387 | 387 | |
|
388 | 388 | |
|
389 | 389 | def writeBlock(self): |
|
390 | 390 | """ |
|
391 | 391 | Escribe el buffer en el file designado |
|
392 | 392 | |
|
393 | 393 | Affected: |
|
394 | 394 | self.profileIndex |
|
395 | 395 | self.flagIsNewFile |
|
396 | 396 | self.flagIsNewBlock |
|
397 | 397 | self.nTotalBlocks |
|
398 | 398 | self.blockIndex |
|
399 | 399 | |
|
400 | 400 | Return: None |
|
401 | 401 | """ |
|
402 | 402 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
403 | 403 | |
|
404 | 404 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
405 | 405 | |
|
406 | 406 | data['real'] = junk.real |
|
407 | 407 | data['imag'] = junk.imag |
|
408 | 408 | |
|
409 | 409 | data = data.reshape( (-1) ) |
|
410 | 410 | |
|
411 | 411 | data.tofile( self.fp ) |
|
412 | 412 | |
|
413 | 413 | self.datablock.fill(0) |
|
414 | 414 | |
|
415 | 415 | self.profileIndex = 0 |
|
416 | 416 | self.flagIsNewFile = 0 |
|
417 | 417 | self.flagIsNewBlock = 1 |
|
418 | 418 | |
|
419 | 419 | self.blockIndex += 1 |
|
420 | 420 | self.nTotalBlocks += 1 |
|
421 | 421 | |
|
422 | 422 | def putData(self): |
|
423 | 423 | """ |
|
424 | 424 | Setea un bloque de datos y luego los escribe en un file |
|
425 | 425 | |
|
426 | 426 | Affected: |
|
427 | 427 | self.flagIsNewBlock |
|
428 | 428 | self.profileIndex |
|
429 | 429 | |
|
430 | 430 | Return: |
|
431 | 431 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
432 | 432 | 1 : Si se escribio la data de un bloque en un file |
|
433 | 433 | """ |
|
434 | 434 | self.flagIsNewBlock = 0 |
|
435 | 435 | |
|
436 | 436 | if self.dataOutObj.flagNoData: |
|
437 | 437 | return 0 |
|
438 | 438 | |
|
439 | 439 | if self.dataOutObj.flagTimeBlock: |
|
440 | 440 | |
|
441 | 441 | self.datablock.fill(0) |
|
442 | 442 | self.profileIndex = 0 |
|
443 | 443 | self.setNextFile() |
|
444 | 444 | |
|
445 | 445 | if self.profileIndex == 0: |
|
446 | 446 | self.getBasicHeader() |
|
447 | 447 | |
|
448 | 448 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data |
|
449 | 449 | |
|
450 | 450 | self.profileIndex += 1 |
|
451 | 451 | |
|
452 | 452 | if self.hasAllDataInBuffer(): |
|
453 | 453 | #if self.flagIsNewFile: |
|
454 | 454 | self.writeNextBlock() |
|
455 | 455 | # self.getDataHeader() |
|
456 | 456 | |
|
457 | 457 | if self.flagNoMoreFiles: |
|
458 | 458 | #print 'Process finished' |
|
459 | 459 | return 0 |
|
460 | 460 | |
|
461 | 461 | return 1 |
|
462 | 462 | |
|
463 | 463 | def __getProcessFlags(self): |
|
464 | 464 | |
|
465 | 465 | processFlags = 0 |
|
466 | 466 | |
|
467 | 467 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
468 | 468 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
469 | 469 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
470 | 470 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
471 | 471 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
472 | 472 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
473 | 473 | |
|
474 | 474 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
475 | 475 | |
|
476 | 476 | |
|
477 | 477 | |
|
478 | 478 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
479 | 479 | PROCFLAG.DATATYPE_SHORT, |
|
480 | 480 | PROCFLAG.DATATYPE_LONG, |
|
481 | 481 | PROCFLAG.DATATYPE_INT64, |
|
482 | 482 | PROCFLAG.DATATYPE_FLOAT, |
|
483 | 483 | PROCFLAG.DATATYPE_DOUBLE] |
|
484 | 484 | |
|
485 | 485 | |
|
486 | 486 | for index in range(len(dtypeList)): |
|
487 | 487 | if self.dataOutObj.dtype == dtypeList[index]: |
|
488 | 488 | dtypeValue = datatypeValueList[index] |
|
489 | 489 | break |
|
490 | 490 | |
|
491 | 491 | processFlags += dtypeValue |
|
492 | 492 | |
|
493 | 493 | if self.dataOutObj.flagDecodeData: |
|
494 | 494 | processFlags += PROCFLAG.DECODE_DATA |
|
495 | 495 | |
|
496 | 496 | if self.dataOutObj.flagDeflipData: |
|
497 | 497 | processFlags += PROCFLAG.DEFLIP_DATA |
|
498 | 498 | |
|
499 | 499 | if self.dataOutObj.code != None: |
|
500 | 500 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
501 | 501 | |
|
502 | 502 | if self.dataOutObj.nCohInt > 1: |
|
503 | 503 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
504 | 504 | |
|
505 | 505 | return processFlags |
|
506 | 506 | |
|
507 | 507 | |
|
508 | 508 | def __getBlockSize(self): |
|
509 | 509 | ''' |
|
510 | 510 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
511 | 511 | ''' |
|
512 | 512 | |
|
513 | 513 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
514 | 514 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
515 | 515 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
516 | 516 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
517 | 517 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
518 | 518 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
519 | 519 | |
|
520 | 520 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
521 | 521 | datatypeValueList = [1,2,4,8,4,8] |
|
522 | 522 | for index in range(len(dtypeList)): |
|
523 | 523 | if self.dataOutObj.dtype == dtypeList[index]: |
|
524 | 524 | datatypeValue = datatypeValueList[index] |
|
525 | 525 | break |
|
526 | 526 | |
|
527 | 527 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) |
|
528 | 528 | |
|
529 | 529 | return blocksize |
|
530 | 530 | |
|
531 | 531 | |
|
532 | 532 | def getBasicHeader(self): |
|
533 | 533 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
534 | 534 | self.basicHeaderObj.version = self.versionFile |
|
535 | 535 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
536 | 536 | |
|
537 | 537 | utc = numpy.floor(self.dataOutObj.utctime) |
|
538 | 538 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 |
|
539 | 539 | |
|
540 | 540 | self.basicHeaderObj.utc = utc |
|
541 | 541 | self.basicHeaderObj.miliSecond = milisecond |
|
542 | 542 | self.basicHeaderObj.timeZone = 0 |
|
543 | 543 | self.basicHeaderObj.dstFlag = 0 |
|
544 | 544 | self.basicHeaderObj.errorCount = 0 |
|
545 | 545 | |
|
546 | 546 | def getDataHeader(self): |
|
547 | 547 | |
|
548 | 548 | """ |
|
549 | 549 | Obtiene una copia del First Header |
|
550 | 550 | |
|
551 | 551 | Affected: |
|
552 | 552 | self.systemHeaderObj |
|
553 | 553 | self.radarControllerHeaderObj |
|
554 | 554 | self.dtype |
|
555 | 555 | |
|
556 | 556 | Return: |
|
557 | 557 | None |
|
558 | 558 | """ |
|
559 | 559 | |
|
560 | 560 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
561 | 561 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
562 | 562 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
563 | 563 | |
|
564 | 564 | self.getBasicHeader() |
|
565 | 565 | |
|
566 | 566 | processingHeaderSize = 40 # bytes |
|
567 | 567 | self.processingHeaderObj.dtype = 0 # Voltage |
|
568 | 568 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
569 | 569 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
570 | 570 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
571 | 571 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
572 | 572 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
573 | 573 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt |
|
574 | 574 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
575 | 575 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
576 | 576 | |
|
577 | 577 | if self.dataOutObj.code != None: |
|
578 | 578 | self.processingHeaderObj.code = self.dataOutObj.code |
|
579 | 579 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
580 | 580 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
581 | 581 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
582 | 582 | processingHeaderSize += codesize |
|
583 | 583 | |
|
584 | 584 | if self.processingHeaderObj.nWindows != 0: |
|
585 | 585 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
586 | 586 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
587 | 587 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
588 | 588 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
589 | 589 | processingHeaderSize += 12 |
|
590 | 590 | |
|
591 | 591 | self.processingHeaderObj.size = processingHeaderSize |
|
592 | 592 | No newline at end of file |
@@ -1,639 +1,698 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author$ |
|
4 | 4 | $Id$ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | 9 | import time |
|
10 | 10 | import datetime |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Data.JROData import Spectra, SpectraHeis |
|
15 | 15 | from IO.SpectraIO import SpectraWriter |
|
16 | 16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure |
|
17 | 17 | #from JRONoise import Noise |
|
18 | 18 | |
|
19 | 19 | class SpectraProcessor: |
|
20 | 20 | ''' |
|
21 | 21 | classdocs |
|
22 | 22 | ''' |
|
23 | 23 | |
|
24 | 24 | dataInObj = None |
|
25 | 25 | |
|
26 | 26 | dataOutObj = None |
|
27 | 27 | |
|
28 | 28 | noiseObj = None |
|
29 | 29 | |
|
30 | 30 | integratorObjList = [] |
|
31 | 31 | |
|
32 | 32 | writerObjList = [] |
|
33 | 33 | |
|
34 | 34 | integratorObjIndex = None |
|
35 | 35 | |
|
36 | 36 | writerObjIndex = None |
|
37 | 37 | |
|
38 | 38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | def __init__(self): |
|
42 | 42 | ''' |
|
43 | 43 | Constructor |
|
44 | 44 | ''' |
|
45 | 45 | |
|
46 | 46 | self.integratorObjIndex = None |
|
47 | 47 | self.writerObjIndex = None |
|
48 | 48 | self.plotObjIndex = None |
|
49 | 49 | self.integratorOst = [] |
|
50 | 50 | self.plotObjList = [] |
|
51 | 51 | self.noiseObj = [] |
|
52 | 52 | self.writerObjList = [] |
|
53 | 53 | self.buffer = None |
|
54 | 54 | self.profIndex = 0 |
|
55 | 55 | |
|
56 | 56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None): |
|
57 | 57 | |
|
58 | 58 | if dataInObj == None: |
|
59 | 59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
60 | 60 | |
|
61 | 61 | if dataInObj.type == "Voltage": |
|
62 | 62 | if nFFTPoints == None: |
|
63 | 63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | if dataInObj.type == "Spectra": |
|
68 | 68 | if nFFTPoints != None: |
|
69 | 69 | raise ValueError, "The nFFTPoints cannot be selected to this object type" |
|
70 | 70 | |
|
71 | 71 | nFFTPoints = dataInObj.nFFTPoints |
|
72 | 72 | |
|
73 | 73 | if pairsList == None: |
|
74 | 74 | pairsList = dataInObj.pairsList |
|
75 | 75 | |
|
76 | 76 | if pairsList == None: |
|
77 | 77 | nPairs = 0 |
|
78 | 78 | else: |
|
79 | 79 | nPairs = len(pairsList) |
|
80 | 80 | |
|
81 | 81 | self.dataInObj = dataInObj |
|
82 | 82 | |
|
83 | 83 | if dataOutObj == None: |
|
84 | 84 | dataOutObj = Spectra() |
|
85 | 85 | |
|
86 | 86 | self.dataOutObj = dataOutObj |
|
87 | 87 | self.dataOutObj.nFFTPoints = nFFTPoints |
|
88 | 88 | self.dataOutObj.pairsList = pairsList |
|
89 | 89 | self.dataOutObj.nPairs = nPairs |
|
90 | 90 | |
|
91 | 91 | return self.dataOutObj |
|
92 | 92 | |
|
93 | 93 | def init(self): |
|
94 | 94 | |
|
95 | 95 | self.dataOutObj.flagNoData = True |
|
96 | 96 | |
|
97 | 97 | if self.dataInObj.flagNoData: |
|
98 | 98 | return 0 |
|
99 | 99 | |
|
100 | 100 | self.integratorObjIndex = 0 |
|
101 | 101 | self.writerObjIndex = 0 |
|
102 | 102 | self.plotObjIndex = 0 |
|
103 | 103 | |
|
104 | 104 | |
|
105 | 105 | if self.dataInObj.type == "Spectra": |
|
106 | 106 | |
|
107 | 107 | self.dataOutObj.copy(self.dataInObj) |
|
108 | 108 | self.dataOutObj.flagNoData = False |
|
109 | 109 | return |
|
110 | 110 | |
|
111 | 111 | if self.dataInObj.type == "Voltage": |
|
112 | 112 | |
|
113 | 113 | if self.buffer == None: |
|
114 | 114 | self.buffer = numpy.zeros((self.dataInObj.nChannels, |
|
115 | 115 | self.dataOutObj.nFFTPoints, |
|
116 | 116 | self.dataInObj.nHeights), |
|
117 | 117 | dtype='complex') |
|
118 | 118 | |
|
119 | 119 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
120 | 120 | self.profIndex += 1 |
|
121 | 121 | |
|
122 | 122 | if self.profIndex == self.dataOutObj.nFFTPoints: |
|
123 | 123 | |
|
124 | 124 | self.__updateObjFromInput() |
|
125 | 125 | self.__getFft() |
|
126 | 126 | |
|
127 | 127 | self.dataOutObj.flagNoData = False |
|
128 | 128 | |
|
129 | 129 | self.buffer = None |
|
130 | 130 | self.profIndex = 0 |
|
131 | 131 | |
|
132 | 132 | return |
|
133 | 133 | |
|
134 | 134 | #Other kind of data |
|
135 | 135 | raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type) |
|
136 | 136 | |
|
137 | 137 | def __getFft(self): |
|
138 | 138 | """ |
|
139 | 139 | Convierte valores de Voltaje a Spectra |
|
140 | 140 | |
|
141 | 141 | Affected: |
|
142 | 142 | self.dataOutObj.data_spc |
|
143 | 143 | self.dataOutObj.data_cspc |
|
144 | 144 | self.dataOutObj.data_dc |
|
145 | 145 | self.dataOutObj.heightList |
|
146 | 146 | self.dataOutObj.m_BasicHeader |
|
147 | 147 | self.dataOutObj.m_ProcessingHeader |
|
148 | 148 | self.dataOutObj.radarControllerHeaderObj |
|
149 | 149 | self.dataOutObj.systemHeaderObj |
|
150 | 150 | self.profIndex |
|
151 | 151 | self.buffer |
|
152 | 152 | self.dataOutObj.flagNoData |
|
153 | 153 | self.dataOutObj.dtype |
|
154 | 154 | self.dataOutObj.nPairs |
|
155 | 155 | self.dataOutObj.nChannels |
|
156 | 156 | self.dataOutObj.nProfiles |
|
157 | 157 | self.dataOutObj.systemHeaderObj.numChannels |
|
158 | 158 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
159 | 159 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
160 | 160 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
161 | 161 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
162 | 162 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
163 | 163 | """ |
|
164 | 164 | |
|
165 | 165 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
166 | 166 | dc = fft_volt[:,0,:] |
|
167 | 167 | |
|
168 | 168 | #calculo de self-spectra |
|
169 | 169 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
170 | 170 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
171 | 171 | spc = spc.real |
|
172 | 172 | |
|
173 | 173 | blocksize = 0 |
|
174 | 174 | blocksize += dc.size |
|
175 | 175 | blocksize += spc.size |
|
176 | 176 | |
|
177 | 177 | cspc = None |
|
178 | 178 | pairIndex = 0 |
|
179 | 179 | if self.dataOutObj.pairsList != None: |
|
180 | 180 | #calculo de cross-spectra |
|
181 | 181 | cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex') |
|
182 | 182 | for pair in self.dataOutObj.pairsList: |
|
183 | 183 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
184 | 184 | pairIndex += 1 |
|
185 | 185 | blocksize += cspc.size |
|
186 | 186 | |
|
187 | 187 | self.dataOutObj.data_spc = spc |
|
188 | 188 | self.dataOutObj.data_cspc = cspc |
|
189 | 189 | self.dataOutObj.data_dc = dc |
|
190 | 190 | self.dataOutObj.blockSize = blocksize |
|
191 | 191 | |
|
192 | 192 | # self.getNoise() |
|
193 | 193 | |
|
194 | 194 | def __updateObjFromInput(self): |
|
195 | 195 | |
|
196 | 196 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
197 | 197 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
198 | 198 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
199 | 199 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
200 | 200 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
201 | 201 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
202 | 202 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
203 | 203 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
204 | 204 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
205 | 205 | self.dataOutObj.code = self.dataInObj.code |
|
206 | 206 | self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints |
|
207 | 207 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
208 | 208 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
209 | 209 | self.dataOutObj.utctime = self.dataInObj.utctime |
|
210 | 210 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
211 | 211 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
212 | 212 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
213 | 213 | self.dataOutObj.nIncohInt = 1 |
|
214 | self.dataOutObj.ippSeconds = self.dataInObj.ippSeconds | |
|
215 | self.dataOutObj.timeInterval = self.dataInObj.timeInterval | |
|
214 | 216 | |
|
215 | 217 | def addWriter(self, wrpath, blocksPerFile): |
|
216 | 218 | |
|
217 | 219 | objWriter = SpectraWriter(self.dataOutObj) |
|
218 | 220 | objWriter.setup(wrpath, blocksPerFile) |
|
219 | 221 | self.writerObjList.append(objWriter) |
|
220 | 222 | |
|
221 | 223 | def addIntegrator(self,N,timeInterval): |
|
222 | 224 | |
|
223 | 225 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
224 | 226 | self.integratorObjList.append(objIncohInt) |
|
225 | 227 | |
|
226 | 228 | def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
227 | 229 | crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
228 | 230 | self.plotObjList.append(crossSpcObj) |
|
229 | 231 | |
|
230 | 232 | def plotCrossSpc(self, idfigure=None, |
|
231 | 233 | xmin=None, |
|
232 | 234 | xmax=None, |
|
233 | 235 | ymin=None, |
|
234 | 236 | ymax=None, |
|
235 | 237 | minvalue=None, |
|
236 | 238 | maxvalue=None, |
|
237 | 239 | wintitle='', |
|
238 | 240 | driver='plplot', |
|
239 | 241 | colormap='br_green', |
|
240 | 242 | colorbar=True, |
|
241 | 243 | showprofile=False, |
|
242 | 244 | save=False, |
|
243 | 245 | gpath=None, |
|
244 | 246 | pairsList = None): |
|
245 | 247 | |
|
246 | 248 | if self.dataOutObj.flagNoData: |
|
247 | 249 | return 0 |
|
248 | 250 | |
|
249 | 251 | if pairsList == None: |
|
250 | 252 | pairsList = self.dataOutObj.pairsList |
|
251 | 253 | |
|
252 | 254 | nframes = len(pairsList) |
|
253 | 255 | |
|
254 | 256 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
255 | 257 | |
|
256 | 258 | y = self.dataOutObj.heightList |
|
257 | 259 | |
|
258 | 260 | |
|
259 | 261 | |
|
260 | 262 | |
|
261 | 263 | if len(self.plotObjList) <= self.plotObjIndex: |
|
262 | 264 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
263 | 265 | |
|
266 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
|
267 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
|
268 | self.plotObjList.append(rtiObj) | |
|
269 | ||
|
270 | def plotRti(self, idfigure=None, | |
|
271 | starttime=None, | |
|
272 | endtime=None, | |
|
273 | rangemin=None, | |
|
274 | rangemax=None, | |
|
275 | minvalue=None, | |
|
276 | maxvalue=None, | |
|
277 | wintitle='', | |
|
278 | driver='plplot', | |
|
279 | colormap='br_greeen', | |
|
280 | colorbar=True, | |
|
281 | showprofile=False, | |
|
282 | xrangestep=None, | |
|
283 | save=False, | |
|
284 | gpath=None, | |
|
285 | ratio=1, | |
|
286 | channelList=None): | |
|
287 | ||
|
288 | if self.dataOutObj.flagNoData: | |
|
289 | return 0 | |
|
290 | ||
|
291 | if channelList == None: | |
|
292 | channelList = self.dataOutObj.channelList | |
|
293 | ||
|
294 | nframes = len(channelList) | |
|
295 | ||
|
296 | if len(self.plotObjList) <= self.plotObjIndex: | |
|
297 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
|
298 | ||
|
299 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |
|
300 | ||
|
301 | currenttime = self.dataOutObj.utctime - time.timezone | |
|
302 | ||
|
303 | range = self.dataOutObj.heightList | |
|
304 | ||
|
305 | ||
|
306 | figuretitle = "RTI Plot for Spectra Data" #+ date | |
|
307 | ||
|
308 | cleardata = False | |
|
309 | ||
|
310 | deltax = self.dataOutObj.timeInterval | |
|
311 | ||
|
312 | plotObj = self.plotObjList[self.plotObjIndex] | |
|
313 | ||
|
314 | ||
|
315 | ||
|
316 | ||
|
317 | ||
|
318 | self.plotObjIndex += 1 | |
|
319 | ||
|
320 | ||
|
321 | ||
|
322 | ||
|
264 | 323 | |
|
265 | 324 | |
|
266 | 325 | |
|
267 | 326 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
268 | 327 | |
|
269 | 328 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
270 | 329 | self.plotObjList.append(spcObj) |
|
271 | 330 | |
|
272 | 331 | def plotSpc(self, idfigure=None, |
|
273 | 332 | xmin=None, |
|
274 | 333 | xmax=None, |
|
275 | 334 | ymin=None, |
|
276 | 335 | ymax=None, |
|
277 | 336 | minvalue=None, |
|
278 | 337 | maxvalue=None, |
|
279 | 338 | wintitle='', |
|
280 | 339 | driver='plplot', |
|
281 | 340 | colormap='br_green', |
|
282 | 341 | colorbar=True, |
|
283 | 342 | showprofile=False, |
|
284 | 343 | save=False, |
|
285 | 344 | gpath=None, |
|
286 | 345 | ratio=1, |
|
287 | 346 | channelList=None): |
|
288 | 347 | |
|
289 | 348 | if self.dataOutObj.flagNoData: |
|
290 | 349 | return 0 |
|
291 | 350 | |
|
292 | 351 | if channelList == None: |
|
293 | 352 | channelList = self.dataOutObj.channelList |
|
294 | 353 | |
|
295 | 354 | nframes = len(channelList) |
|
296 | 355 | |
|
297 | 356 | if len(self.plotObjList) <= self.plotObjIndex: |
|
298 | 357 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
299 | 358 | |
|
300 | 359 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
301 | 360 | |
|
302 | 361 | y = self.dataOutObj.heightList |
|
303 | 362 | |
|
304 | 363 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
305 | 364 | # noisedB = 10.*numpy.log10(noise) |
|
306 | 365 | noisedB = numpy.arange(len(channelList)+1) |
|
307 | 366 | noisedB = noisedB *1.2 |
|
308 | 367 | titleList = [] |
|
309 | 368 | for i in range(len(noisedB)): |
|
310 | 369 | title = "%.2f"%noisedB[i] |
|
311 | 370 | titleList.append(title) |
|
312 | 371 | |
|
313 | 372 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
314 | 373 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
315 | 374 | figuretitle = "Spc Radar Data: %s"%dateTime |
|
316 | 375 | |
|
317 | 376 | cleardata = True |
|
318 | 377 | |
|
319 | 378 | plotObj = self.plotObjList[self.plotObjIndex] |
|
320 | 379 | |
|
321 | 380 | plotObj.plotPcolor(data=data, |
|
322 | 381 | x=x, |
|
323 | 382 | y=y, |
|
324 | 383 | channelList=channelList, |
|
325 | 384 | xmin=xmin, |
|
326 | 385 | xmax=xmax, |
|
327 | 386 | ymin=ymin, |
|
328 | 387 | ymax=ymax, |
|
329 | 388 | minvalue=minvalue, |
|
330 | 389 | maxvalue=maxvalue, |
|
331 | 390 | figuretitle=figuretitle, |
|
332 | 391 | xrangestep=None, |
|
333 | 392 | deltax=None, |
|
334 | 393 | save=save, |
|
335 | 394 | gpath=gpath, |
|
336 | 395 | cleardata=cleardata |
|
337 | 396 | ) |
|
338 | 397 | |
|
339 | 398 | self.plotObjIndex += 1 |
|
340 | 399 | |
|
341 | 400 | |
|
342 | 401 | def writeData(self, wrpath, blocksPerFile): |
|
343 | 402 | |
|
344 | 403 | if self.dataOutObj.flagNoData: |
|
345 | 404 | return 0 |
|
346 | 405 | |
|
347 | 406 | if len(self.writerObjList) <= self.writerObjIndex: |
|
348 | 407 | self.addWriter(wrpath, blocksPerFile) |
|
349 | 408 | |
|
350 | 409 | self.writerObjList[self.writerObjIndex].putData() |
|
351 | 410 | |
|
352 | 411 | self.writerObjIndex += 1 |
|
353 | 412 | |
|
354 | 413 | def integrator(self, N=None, timeInterval=None): |
|
355 | 414 | |
|
356 | 415 | if self.dataOutObj.flagNoData: |
|
357 | 416 | return 0 |
|
358 | 417 | |
|
359 | 418 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
360 | 419 | self.addIntegrator(N,timeInterval) |
|
361 | 420 | |
|
362 | 421 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
363 | 422 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
364 | 423 | |
|
365 | 424 | if myIncohIntObj.isReady: |
|
366 | 425 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
367 | 426 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
368 | 427 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
369 | 428 | self.dataOutObj.flagNoData = False |
|
370 | 429 | |
|
371 | 430 | """Calcular el ruido""" |
|
372 | 431 | self.getNoise() |
|
373 | 432 | else: |
|
374 | 433 | self.dataOutObj.flagNoData = True |
|
375 | 434 | |
|
376 | 435 | self.integratorObjIndex += 1 |
|
377 | 436 | |
|
378 | 437 | |
|
379 | 438 | class SpectraHeisProcessor: |
|
380 | 439 | |
|
381 | 440 | def __init__(self): |
|
382 | 441 | |
|
383 | 442 | self.integratorObjIndex = None |
|
384 | 443 | self.writerObjIndex = None |
|
385 | 444 | self.plotObjIndex = None |
|
386 | 445 | self.integratorObjList = [] |
|
387 | 446 | self.writerObjList = [] |
|
388 | 447 | self.plotObjList = [] |
|
389 | 448 | #self.noiseObj = Noise() |
|
390 | 449 | |
|
391 | 450 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
392 | 451 | |
|
393 | 452 | if nFFTPoints == None: |
|
394 | 453 | nFFTPoints = self.dataInObj.nHeights |
|
395 | 454 | |
|
396 | 455 | self.dataInObj = dataInObj |
|
397 | 456 | |
|
398 | 457 | if dataOutObj == None: |
|
399 | 458 | dataOutObj = SpectraHeis() |
|
400 | 459 | |
|
401 | 460 | self.dataOutObj = dataOutObj |
|
402 | 461 | |
|
403 | 462 | return self.dataOutObj |
|
404 | 463 | |
|
405 | 464 | def init(self): |
|
406 | 465 | |
|
407 | 466 | self.dataOutObj.flagNoData = True |
|
408 | 467 | |
|
409 | 468 | if self.dataInObj.flagNoData: |
|
410 | 469 | return 0 |
|
411 | 470 | |
|
412 | 471 | self.integratorObjIndex = 0 |
|
413 | 472 | self.writerObjIndex = 0 |
|
414 | 473 | self.plotObjIndex = 0 |
|
415 | 474 | |
|
416 | 475 | if self.dataInObj.type == "Voltage": |
|
417 | 476 | self.__updateObjFromInput() |
|
418 | 477 | self.__getFft() |
|
419 | 478 | self.dataOutObj.flagNoData = False |
|
420 | 479 | return |
|
421 | 480 | |
|
422 | 481 | #Other kind of data |
|
423 | 482 | if self.dataInObj.type == "SpectraHeis": |
|
424 | 483 | self.dataOutObj.copy(self.dataInObj) |
|
425 | 484 | self.dataOutObj.flagNoData = False |
|
426 | 485 | return |
|
427 | 486 | |
|
428 | 487 | raise ValueError, "The type is not valid" |
|
429 | 488 | |
|
430 | 489 | def __updateObjFromInput(self): |
|
431 | 490 | |
|
432 | 491 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
433 | 492 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
434 | 493 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
435 | 494 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
436 | 495 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
437 | 496 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
438 | 497 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
439 | 498 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
440 | 499 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
441 | 500 | self.dataOutObj.code = self.dataInObj.code |
|
442 | 501 | self.dataOutObj.nProfiles = 1 |
|
443 | 502 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights |
|
444 | 503 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
445 | 504 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData |
|
446 | 505 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
447 | 506 | self.dataOutObj.utctime = self.dataInObj.utctime |
|
448 | 507 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
449 | 508 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
450 | 509 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
451 | 510 | self.dataOutObj.nIncohInt = 1 |
|
452 | 511 | |
|
453 | 512 | def __getFft(self): |
|
454 | 513 | |
|
455 | 514 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) |
|
456 | 515 | #print fft_volt |
|
457 | 516 | #calculo de self-spectra |
|
458 | 517 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
459 | 518 | |
|
460 | 519 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
461 | 520 | self.dataOutObj.data_spc = spc |
|
462 | 521 | |
|
463 | 522 | def getSpectra(self): |
|
464 | 523 | |
|
465 | 524 | return self.dataOutObj.data_spc |
|
466 | 525 | |
|
467 | 526 | def getFrecuencies(self): |
|
468 | 527 | |
|
469 | 528 | print self.nFFTPoints |
|
470 | 529 | return numpy.arange(int(self.nFFTPoints)) |
|
471 | 530 | |
|
472 | 531 | def addIntegrator(self,N,timeInterval): |
|
473 | 532 | |
|
474 | 533 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
475 | 534 | self.integratorObjList.append(objIncohInt) |
|
476 | 535 | |
|
477 | 536 | def integrator(self, N=None, timeInterval=None): |
|
478 | 537 | |
|
479 | 538 | if self.dataOutObj.flagNoData: |
|
480 | 539 | return 0 |
|
481 | 540 | |
|
482 | 541 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
483 | 542 | self.addIntegrator(N,timeInterval) |
|
484 | 543 | |
|
485 | 544 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
486 | 545 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime) |
|
487 | 546 | |
|
488 | 547 | if myIncohIntObj.isReady: |
|
489 | 548 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
490 | 549 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg |
|
491 | 550 | self.dataOutObj.flagNoData = False |
|
492 | 551 | |
|
493 | 552 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) |
|
494 | 553 | # self.getNoise(type="sort", parm=16) |
|
495 | 554 | |
|
496 | 555 | else: |
|
497 | 556 | self.dataOutObj.flagNoData = True |
|
498 | 557 | |
|
499 | 558 | self.integratorObjIndex += 1 |
|
500 | 559 | |
|
501 | 560 | |
|
502 | 561 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
503 | 562 | |
|
504 | 563 | if idfigure==None: |
|
505 | 564 | idfigure = self.plotObjIndex |
|
506 | 565 | |
|
507 | 566 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
508 | 567 | self.plotObjList.append(scopeObj) |
|
509 | 568 | |
|
510 | 569 | def plotScope(self, |
|
511 | 570 | idfigure=None, |
|
512 | 571 | minvalue=None, |
|
513 | 572 | maxvalue=None, |
|
514 | 573 | xmin=None, |
|
515 | 574 | xmax=None, |
|
516 | 575 | wintitle='', |
|
517 | 576 | driver='plplot', |
|
518 | 577 | save=False, |
|
519 | 578 | gpath=None, |
|
520 | 579 | titleList=None, |
|
521 | 580 | xlabelList=None, |
|
522 | 581 | ylabelList=None): |
|
523 | 582 | |
|
524 | 583 | if self.dataOutObj.flagNoData: |
|
525 | 584 | return 0 |
|
526 | 585 | |
|
527 | 586 | nframes = len(self.dataOutObj.channelList) |
|
528 | 587 | |
|
529 | 588 | if len(self.plotObjList) <= self.plotObjIndex: |
|
530 | 589 | self.addScope(idfigure, nframes, wintitle, driver) |
|
531 | 590 | |
|
532 | 591 | |
|
533 | 592 | data1D = self.dataOutObj.data_spc |
|
534 | 593 | |
|
535 | 594 | x = numpy.arange(self.dataOutObj.nHeights) |
|
536 | 595 | |
|
537 | 596 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
538 | 597 | |
|
539 | 598 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
540 | 599 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
541 | 600 | |
|
542 | 601 | figureTitle = "Scope Plot Radar Data: " + date |
|
543 | 602 | |
|
544 | 603 | plotObj = self.plotObjList[self.plotObjIndex] |
|
545 | 604 | |
|
546 | 605 | plotObj.plot1DArray(data1D, |
|
547 | 606 | x, |
|
548 | 607 | self.dataOutObj.channelList, |
|
549 | 608 | xmin, |
|
550 | 609 | xmax, |
|
551 | 610 | minvalue, |
|
552 | 611 | maxvalue, |
|
553 | 612 | figureTitle, |
|
554 | 613 | save, |
|
555 | 614 | gpath) |
|
556 | 615 | |
|
557 | 616 | self.plotObjIndex += 1 |
|
558 | 617 | |
|
559 | 618 | class IncoherentIntegration: |
|
560 | 619 | |
|
561 | 620 | integ_counter = None |
|
562 | 621 | data = None |
|
563 | 622 | navg = None |
|
564 | 623 | buffer = None |
|
565 | 624 | nIncohInt = None |
|
566 | 625 | |
|
567 | 626 | def __init__(self, N = None, timeInterval = None): |
|
568 | 627 | """ |
|
569 | 628 | N |
|
570 | 629 | timeInterval - interval time [min], integer value |
|
571 | 630 | """ |
|
572 | 631 | |
|
573 | 632 | self.data = None |
|
574 | 633 | self.navg = None |
|
575 | 634 | self.buffer = None |
|
576 | 635 | self.timeOut = None |
|
577 | 636 | self.exitCondition = False |
|
578 | 637 | self.isReady = False |
|
579 | 638 | self.nIncohInt = N |
|
580 | 639 | self.integ_counter = 0 |
|
581 | 640 | if timeInterval!=None: |
|
582 | 641 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
583 | 642 | |
|
584 | 643 | if ((timeInterval==None) and (N==None)): |
|
585 | 644 | print 'N = None ; timeInterval = None' |
|
586 | 645 | sys.exit(0) |
|
587 | 646 | elif timeInterval == None: |
|
588 | 647 | self.timeFlag = False |
|
589 | 648 | else: |
|
590 | 649 | self.timeFlag = True |
|
591 | 650 | |
|
592 | 651 | |
|
593 | 652 | def exe(self,data,timeOfData): |
|
594 | 653 | """ |
|
595 | 654 | data |
|
596 | 655 | |
|
597 | 656 | timeOfData [seconds] |
|
598 | 657 | """ |
|
599 | 658 | |
|
600 | 659 | if self.timeFlag: |
|
601 | 660 | if self.timeOut == None: |
|
602 | 661 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
603 | 662 | |
|
604 | 663 | if timeOfData < self.timeOut: |
|
605 | 664 | if self.buffer == None: |
|
606 | 665 | self.buffer = data |
|
607 | 666 | else: |
|
608 | 667 | self.buffer = self.buffer + data |
|
609 | 668 | self.integ_counter += 1 |
|
610 | 669 | else: |
|
611 | 670 | self.exitCondition = True |
|
612 | 671 | |
|
613 | 672 | else: |
|
614 | 673 | if self.integ_counter < self.nIncohInt: |
|
615 | 674 | if self.buffer == None: |
|
616 | 675 | self.buffer = data |
|
617 | 676 | else: |
|
618 | 677 | self.buffer = self.buffer + data |
|
619 | 678 | |
|
620 | 679 | self.integ_counter += 1 |
|
621 | 680 | |
|
622 | 681 | if self.integ_counter == self.nIncohInt: |
|
623 | 682 | self.exitCondition = True |
|
624 | 683 | |
|
625 | 684 | if self.exitCondition: |
|
626 | 685 | self.data = self.buffer |
|
627 | 686 | self.navg = self.integ_counter |
|
628 | 687 | self.isReady = True |
|
629 | 688 | self.buffer = None |
|
630 | 689 | self.timeOut = None |
|
631 | 690 | self.integ_counter = 0 |
|
632 | 691 | self.exitCondition = False |
|
633 | 692 | |
|
634 | 693 | if self.timeFlag: |
|
635 | 694 | self.buffer = data |
|
636 | 695 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
637 | 696 | else: |
|
638 | 697 | self.isReady = False |
|
639 | 698 | No newline at end of file |
@@ -1,419 +1,419 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author$ |
|
4 | 4 | $Id$ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os |
|
8 | 8 | import sys |
|
9 | 9 | import numpy |
|
10 | 10 | import datetime |
|
11 | 11 | import time |
|
12 | 12 | |
|
13 | 13 | path = os.path.split(os.getcwd())[0] |
|
14 | 14 | sys.path.append(path) |
|
15 | 15 | |
|
16 | 16 | from Data.JROData import Voltage |
|
17 | 17 | from IO.VoltageIO import VoltageWriter |
|
18 | 18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure |
|
19 | 19 | |
|
20 | 20 | class VoltageProcessor: |
|
21 | 21 | |
|
22 | 22 | dataInObj = None |
|
23 | 23 | dataOutObj = None |
|
24 | 24 | integratorObjIndex = None |
|
25 | 25 | writerObjIndex = None |
|
26 | 26 | integratorObjList = None |
|
27 | 27 | writerObjList = None |
|
28 | 28 | |
|
29 | 29 | def __init__(self): |
|
30 | 30 | self.integratorObjIndex = None |
|
31 | 31 | self.writerObjIndex = None |
|
32 | 32 | self.plotObjIndex = None |
|
33 | 33 | self.integratorObjList = [] |
|
34 | 34 | self.writerObjList = [] |
|
35 | 35 | self.plotObjList = [] |
|
36 | 36 | |
|
37 | 37 | def setup(self,dataInObj=None,dataOutObj=None): |
|
38 | 38 | self.dataInObj = dataInObj |
|
39 | 39 | |
|
40 | 40 | if self.dataOutObj == None: |
|
41 | 41 | dataOutObj = Voltage() |
|
42 | 42 | |
|
43 | 43 | self.dataOutObj = dataOutObj |
|
44 | 44 | |
|
45 | 45 | return self.dataOutObj |
|
46 | 46 | |
|
47 | 47 | def init(self): |
|
48 | 48 | self.integratorObjIndex = 0 |
|
49 | 49 | self.writerObjIndex = 0 |
|
50 | 50 | self.plotObjIndex = 0 |
|
51 | 51 | |
|
52 | 52 | if not(self.dataInObj.flagNoData): |
|
53 | 53 | self.dataOutObj.copy(self.dataInObj) |
|
54 | 54 | # No necesita copiar en cada init() los atributos de dataInObj |
|
55 | 55 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
56 | 56 | |
|
57 | 57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
58 | 58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
59 | 59 | self.plotObjList.append(rtiObj) |
|
60 | 60 | |
|
61 | 61 | def plotRti(self, idfigure=None, |
|
62 | 62 | starttime=None, |
|
63 | 63 | endtime=None, |
|
64 | 64 | rangemin=None, |
|
65 | 65 | rangemax=None, |
|
66 | 66 | minvalue=None, |
|
67 | 67 | maxvalue=None, |
|
68 | 68 | wintitle='', |
|
69 | 69 | driver='plplot', |
|
70 | 70 | colormap='br_greeen', |
|
71 | 71 | colorbar=True, |
|
72 | 72 | showprofile=False, |
|
73 | 73 | xrangestep=None, |
|
74 | 74 | save=False, |
|
75 | 75 | gpath=None, |
|
76 | 76 | ratio=1, |
|
77 | 77 | channelList=None): |
|
78 | 78 | |
|
79 | 79 | if self.dataOutObj.flagNoData: |
|
80 | 80 | return 0 |
|
81 | 81 | |
|
82 | 82 | if channelList == None: |
|
83 | 83 | channelList = self.dataOutObj.channelList |
|
84 | 84 | |
|
85 | 85 | nframes = len(channelList) |
|
86 | 86 | |
|
87 | 87 | if len(self.plotObjList) <= self.plotObjIndex: |
|
88 | 88 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
89 | 89 | |
|
90 | 90 | data = self.dataOutObj.data[channelList,:] * numpy.conjugate(self.dataOutObj.data[channelList,:]) |
|
91 | 91 | data = 10*numpy.log10(data.real) |
|
92 | 92 | |
|
93 | 93 | currenttime = self.dataOutObj.utctime - time.timezone |
|
94 | 94 | |
|
95 | 95 | range = self.dataOutObj.heightList |
|
96 | 96 | |
|
97 | 97 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
98 | 98 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
99 | 99 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
100 | print thisdatetime | |
|
100 | ||
|
101 | 101 | figuretitle = "RTI Plot Radar Data" #+ date |
|
102 | 102 | |
|
103 | 103 | plotObj = self.plotObjList[self.plotObjIndex] |
|
104 | 104 | |
|
105 | 105 | cleardata = False |
|
106 | 106 | |
|
107 | 107 | deltax = self.dataOutObj.timeInterval |
|
108 | 108 | |
|
109 | 109 | plotObj.plotPcolor(data=data, |
|
110 | 110 | x=currenttime, |
|
111 | 111 | y=range, |
|
112 | 112 | channelList=channelList, |
|
113 | 113 | xmin=starttime, |
|
114 | 114 | xmax=endtime, |
|
115 | 115 | ymin=rangemin, |
|
116 | 116 | ymax=rangemax, |
|
117 | 117 | minvalue=minvalue, |
|
118 | 118 | maxvalue=maxvalue, |
|
119 | 119 | figuretitle=figuretitle, |
|
120 | 120 | xrangestep=xrangestep, |
|
121 | 121 | deltax=deltax, |
|
122 | 122 | save=save, |
|
123 | 123 | gpath=gpath, |
|
124 | 124 | ratio=ratio, |
|
125 | 125 | cleardata=cleardata |
|
126 | 126 | ) |
|
127 | 127 | |
|
128 | 128 | |
|
129 | 129 | self.plotObjIndex += 1 |
|
130 | 130 | |
|
131 | 131 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
132 | 132 | if idfigure==None: |
|
133 | 133 | idfigure = self.plotObjIndex |
|
134 | 134 | |
|
135 | 135 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
136 | 136 | self.plotObjList.append(scopeObj) |
|
137 | 137 | |
|
138 | 138 | def plotScope(self, |
|
139 | 139 | idfigure=None, |
|
140 | 140 | minvalue=None, |
|
141 | 141 | maxvalue=None, |
|
142 | 142 | xmin=None, |
|
143 | 143 | xmax=None, |
|
144 | 144 | wintitle='', |
|
145 | 145 | driver='plplot', |
|
146 | 146 | save=False, |
|
147 | 147 | gpath=None, |
|
148 | 148 | ratio=1, |
|
149 | 149 | type="power"): |
|
150 | 150 | |
|
151 | 151 | if self.dataOutObj.flagNoData: |
|
152 | 152 | return 0 |
|
153 | 153 | |
|
154 | 154 | nframes = len(self.dataOutObj.channelList) |
|
155 | 155 | |
|
156 | 156 | if len(self.plotObjList) <= self.plotObjIndex: |
|
157 | 157 | self.addScope(idfigure, nframes, wintitle, driver) |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | if type=="power": |
|
161 | 161 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
162 | 162 | data1D = data1D.real |
|
163 | 163 | |
|
164 | 164 | if type =="iq": |
|
165 | 165 | data1D = self.dataOutObj.data |
|
166 | 166 | |
|
167 | 167 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
168 | 168 | |
|
169 | 169 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
170 | 170 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
171 | 171 | |
|
172 | 172 | figuretitle = "Scope Plot Radar Data: " + date |
|
173 | 173 | |
|
174 | 174 | plotObj = self.plotObjList[self.plotObjIndex] |
|
175 | 175 | |
|
176 | 176 | plotObj.plot1DArray(data1D=data1D, |
|
177 | 177 | x=self.dataOutObj.heightList, |
|
178 | 178 | channelList=self.dataOutObj.channelList, |
|
179 | 179 | xmin=xmin, |
|
180 | 180 | xmax=xmax, |
|
181 | 181 | minvalue=minvalue, |
|
182 | 182 | maxvalue=maxvalue, |
|
183 | 183 | figuretitle=figuretitle, |
|
184 | 184 | save=save, |
|
185 | 185 | gpath=gpath, |
|
186 | 186 | ratio=ratio) |
|
187 | 187 | |
|
188 | 188 | |
|
189 | 189 | self.plotObjIndex += 1 |
|
190 | 190 | |
|
191 | 191 | |
|
192 | 192 | def addIntegrator(self, *args): |
|
193 | 193 | objCohInt = CoherentIntegrator(*args) |
|
194 | 194 | self.integratorObjList.append(objCohInt) |
|
195 | 195 | |
|
196 | 196 | def addWriter(self, *args): |
|
197 | 197 | writerObj = VoltageWriter(self.dataOutObj) |
|
198 | 198 | writerObj.setup(*args) |
|
199 | 199 | self.writerObjList.append(writerObj) |
|
200 | 200 | |
|
201 | 201 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
202 | 202 | |
|
203 | 203 | if self.dataOutObj.flagNoData: |
|
204 | 204 | return 0 |
|
205 | 205 | |
|
206 | 206 | if len(self.writerObjList) <= self.writerObjIndex: |
|
207 | 207 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
208 | 208 | |
|
209 | 209 | self.writerObjList[self.writerObjIndex].putData() |
|
210 | 210 | |
|
211 | 211 | self.writerObjIndex += 1 |
|
212 | 212 | |
|
213 | 213 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
214 | 214 | |
|
215 | 215 | if self.dataOutObj.flagNoData: |
|
216 | 216 | return 0 |
|
217 | 217 | |
|
218 | 218 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
219 | 219 | self.addIntegrator(nCohInt, timeInterval, overlapping) |
|
220 | 220 | |
|
221 | 221 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
222 | 222 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) |
|
223 | 223 | |
|
224 | self.dataOutObj.timeInterval *= nCohInt | |
|
224 | # self.dataOutObj.timeInterval *= nCohInt | |
|
225 | 225 | self.dataOutObj.flagNoData = True |
|
226 | 226 | |
|
227 | 227 | if myCohIntObj.isReady: |
|
228 | 228 | self.dataOutObj.timeInterval = myCohIntObj.nCohInt * self.dataOutObj.timeInterval |
|
229 | 229 | self.dataOutObj.flagNoData = False |
|
230 | 230 | |
|
231 | 231 | def selectChannels(self, channelList): |
|
232 | 232 | |
|
233 | 233 | self.selectChannelsByIndex(channelList) |
|
234 | 234 | |
|
235 | 235 | def selectChannelsByIndex(self, channelIndexList): |
|
236 | 236 | """ |
|
237 | 237 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
238 | 238 | |
|
239 | 239 | Input: |
|
240 | 240 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
241 | 241 | |
|
242 | 242 | Affected: |
|
243 | 243 | self.dataOutObj.data |
|
244 | 244 | self.dataOutObj.channelIndexList |
|
245 | 245 | self.dataOutObj.nChannels |
|
246 | 246 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
247 | 247 | self.dataOutObj.systemHeaderObj.numChannels |
|
248 | 248 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
249 | 249 | |
|
250 | 250 | Return: |
|
251 | 251 | None |
|
252 | 252 | """ |
|
253 | 253 | if self.dataOutObj.flagNoData: |
|
254 | 254 | return 0 |
|
255 | 255 | |
|
256 | 256 | for channel in channelIndexList: |
|
257 | 257 | if channel not in self.dataOutObj.channelIndexList: |
|
258 | 258 | raise ValueError, "The value %d in channelIndexList is not valid" %channel |
|
259 | 259 | |
|
260 | 260 | nChannels = len(channelIndexList) |
|
261 | 261 | |
|
262 | 262 | data = self.dataOutObj.data[channelIndexList,:] |
|
263 | 263 | |
|
264 | 264 | self.dataOutObj.data = data |
|
265 | 265 | self.dataOutObj.channelIndexList = channelIndexList |
|
266 | 266 | self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList] |
|
267 | 267 | self.dataOutObj.nChannels = nChannels |
|
268 | 268 | |
|
269 | 269 | return 1 |
|
270 | 270 | |
|
271 | 271 | class CoherentIntegrator: |
|
272 | 272 | |
|
273 | 273 | |
|
274 | 274 | __profIndex = 0 |
|
275 | 275 | __withOverapping = False |
|
276 | 276 | |
|
277 | 277 | __isByTime = False |
|
278 | 278 | __initime = None |
|
279 | 279 | __integrationtime = None |
|
280 | 280 | |
|
281 | 281 | __buffer = None |
|
282 | 282 | |
|
283 | 283 | isReady = False |
|
284 | 284 | nCohInt = None |
|
285 | 285 | |
|
286 | 286 | |
|
287 | 287 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
288 | 288 | |
|
289 | 289 | """ |
|
290 | 290 | Set the parameters of the integration class. |
|
291 | 291 | |
|
292 | 292 | Inputs: |
|
293 | 293 | |
|
294 | 294 | nCohInt : Number of coherent integrations |
|
295 | 295 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work |
|
296 | 296 | overlapping : |
|
297 | 297 | |
|
298 | 298 | """ |
|
299 | 299 | |
|
300 | 300 | self.__buffer = None |
|
301 | 301 | self.isReady = False |
|
302 | 302 | |
|
303 | 303 | if nCohInt == None and timeInterval == None: |
|
304 | 304 | raise ValueError, "nCohInt or timeInterval should be specified ..." |
|
305 | 305 | |
|
306 | 306 | if nCohInt != None: |
|
307 | 307 | self.nCohInt = nCohInt |
|
308 | 308 | self.__isByTime = False |
|
309 | 309 | else: |
|
310 | 310 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
311 | 311 | self.__isByTime = True |
|
312 | 312 | |
|
313 | 313 | if overlapping: |
|
314 | 314 | self.__withOverapping = True |
|
315 | 315 | self.__buffer = None |
|
316 | 316 | else: |
|
317 | 317 | self.__withOverapping = False |
|
318 | 318 | self.__buffer = 0 |
|
319 | 319 | |
|
320 | 320 | self.__profIndex = 0 |
|
321 | 321 | |
|
322 | 322 | def putData(self, data): |
|
323 | 323 | |
|
324 | 324 | """ |
|
325 | 325 | Add a profile to the __buffer and increase in one the __profileIndex |
|
326 | 326 | |
|
327 | 327 | """ |
|
328 | 328 | if not self.__withOverapping: |
|
329 | 329 | self.__buffer += data |
|
330 | 330 | self.__profIndex += 1 |
|
331 | 331 | return |
|
332 | 332 | |
|
333 | 333 | #Overlapping data |
|
334 | 334 | nChannels, nHeis = data.shape |
|
335 | 335 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
336 | 336 | |
|
337 | 337 | if self.__buffer == None: |
|
338 | 338 | self.__buffer = data |
|
339 | 339 | self.__profIndex += 1 |
|
340 | 340 | return |
|
341 | 341 | |
|
342 | 342 | if self.__profIndex < self.nCohInt: |
|
343 | 343 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
344 | 344 | self.__profIndex += 1 |
|
345 | 345 | return |
|
346 | 346 | |
|
347 | 347 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
348 | 348 | self.__buffer[self.nCohInt-1] = data |
|
349 | 349 | #self.__profIndex = self.nCohInt |
|
350 | 350 | return |
|
351 | 351 | |
|
352 | 352 | |
|
353 | 353 | def pushData(self): |
|
354 | 354 | """ |
|
355 | 355 | Return the sum of the last profiles and the profiles used in the sum. |
|
356 | 356 | |
|
357 | 357 | Affected: |
|
358 | 358 | |
|
359 | 359 | self.__profileIndex |
|
360 | 360 | |
|
361 | 361 | """ |
|
362 | 362 | |
|
363 | 363 | if not self.__withOverapping: |
|
364 | 364 | data = self.__buffer |
|
365 | 365 | nCohInt = self.__profIndex |
|
366 | 366 | |
|
367 | 367 | self.__buffer = 0 |
|
368 | 368 | self.__profIndex = 0 |
|
369 | 369 | |
|
370 | 370 | return data, nCohInt |
|
371 | 371 | |
|
372 | 372 | #Overlapping data |
|
373 | 373 | data = numpy.sum(self.__buffer, axis=0) |
|
374 | 374 | nCohInt = self.__profIndex |
|
375 | 375 | |
|
376 | 376 | return data, nCohInt |
|
377 | 377 | |
|
378 | 378 | def byProfiles(self, data): |
|
379 | 379 | |
|
380 | 380 | self.isReady = False |
|
381 | 381 | avg_data = None |
|
382 | 382 | |
|
383 | 383 | self.putData(data) |
|
384 | 384 | |
|
385 | 385 | if self.__profIndex == self.nCohInt: |
|
386 | 386 | avg_data, nCohInt = self.pushData() |
|
387 | 387 | self.isReady = True |
|
388 | 388 | |
|
389 | 389 | return avg_data |
|
390 | 390 | |
|
391 | 391 | def byTime(self, data, datatime): |
|
392 | 392 | |
|
393 | 393 | self.isReady = False |
|
394 | 394 | avg_data = None |
|
395 | 395 | |
|
396 | 396 | if self.__initime == None: |
|
397 | 397 | self.__initime = datatime |
|
398 | 398 | |
|
399 | 399 | self.putData(data) |
|
400 | 400 | |
|
401 | 401 | if (datatime - self.__initime) >= self.__integrationtime: |
|
402 | 402 | avg_data, nCohInt = self.pushData() |
|
403 | 403 | self.nCohInt = nCohInt |
|
404 | 404 | self.isReady = True |
|
405 | 405 | |
|
406 | 406 | return avg_data |
|
407 | 407 | |
|
408 | 408 | def exe(self, data, datatime=None): |
|
409 | 409 | |
|
410 | 410 | if not self.__isByTime: |
|
411 | 411 | avg_data = self.byProfiles(data) |
|
412 | 412 | else: |
|
413 | 413 | avg_data = self.byTime(data, datatime) |
|
414 | 414 | |
|
415 | 415 | self.data = avg_data |
|
416 | 416 | |
|
417 | 417 | return avg_data |
|
418 | 418 | |
|
419 | 419 |
General Comments 0
You need to be logged in to leave comments.
Login now