##// END OF EJS Templates
jrodataIO.py: Adicion del parametro LOCALTIME para la lectura de datos....
Miguel Valdez -
r234:039d4869c5dd
parent child
Show More
@@ -1,2560 +1,2562
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import time, datetime
12 import time, datetime
13
13
14 from jrodata import *
14 from jrodata import *
15 from jroheaderIO import *
15 from jroheaderIO import *
16 from jroprocessing import *
16 from jroprocessing import *
17
17
18 LOCALTIME = -18000
19
18 def isNumber(str):
20 def isNumber(str):
19 """
21 """
20 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
22 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
21
23
22 Excepciones:
24 Excepciones:
23 Si un determinado string no puede ser convertido a numero
25 Si un determinado string no puede ser convertido a numero
24 Input:
26 Input:
25 str, string al cual se le analiza para determinar si convertible a un numero o no
27 str, string al cual se le analiza para determinar si convertible a un numero o no
26
28
27 Return:
29 Return:
28 True : si el string es uno numerico
30 True : si el string es uno numerico
29 False : no es un string numerico
31 False : no es un string numerico
30 """
32 """
31 try:
33 try:
32 float( str )
34 float( str )
33 return True
35 return True
34 except:
36 except:
35 return False
37 return False
36
38
37 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
39 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
38 """
40 """
39 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
41 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
40
42
41 Inputs:
43 Inputs:
42 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
44 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
43
45
44 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
46 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
45 segundos contados desde 01/01/1970.
47 segundos contados desde 01/01/1970.
46 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
48 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
47 segundos contados desde 01/01/1970.
49 segundos contados desde 01/01/1970.
48
50
49 Return:
51 Return:
50 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
52 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
51 fecha especificado, de lo contrario retorna False.
53 fecha especificado, de lo contrario retorna False.
52
54
53 Excepciones:
55 Excepciones:
54 Si el archivo no existe o no puede ser abierto
56 Si el archivo no existe o no puede ser abierto
55 Si la cabecera no puede ser leida.
57 Si la cabecera no puede ser leida.
56
58
57 """
59 """
58 basicHeaderObj = BasicHeader()
60 basicHeaderObj = BasicHeader(LOCALTIME)
59
61
60 try:
62 try:
61 fp = open(filename,'rb')
63 fp = open(filename,'rb')
62 except:
64 except:
63 raise IOError, "The file %s can't be opened" %(filename)
65 raise IOError, "The file %s can't be opened" %(filename)
64
66
65 sts = basicHeaderObj.read(fp)
67 sts = basicHeaderObj.read(fp)
66 fp.close()
68 fp.close()
67
69
68 if not(sts):
70 if not(sts):
69 print "Skipping the file %s because it has not a valid header" %(filename)
71 print "Skipping the file %s because it has not a valid header" %(filename)
70 return 0
72 return 0
71
73
72 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
74 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
73 return 0
75 return 0
74
76
75 return 1
77 return 1
76
78
77 def isFileinThisTime(filename, startTime, endTime):
79 def isFileinThisTime(filename, startTime, endTime):
78 """
80 """
79 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
81 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
80
82
81 Inputs:
83 Inputs:
82 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
84 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
83
85
84 startTime : tiempo inicial del rango seleccionado en formato datetime.time
86 startTime : tiempo inicial del rango seleccionado en formato datetime.time
85
87
86 endTime : tiempo final del rango seleccionado en formato datetime.time
88 endTime : tiempo final del rango seleccionado en formato datetime.time
87
89
88 Return:
90 Return:
89 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
91 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
90 fecha especificado, de lo contrario retorna False.
92 fecha especificado, de lo contrario retorna False.
91
93
92 Excepciones:
94 Excepciones:
93 Si el archivo no existe o no puede ser abierto
95 Si el archivo no existe o no puede ser abierto
94 Si la cabecera no puede ser leida.
96 Si la cabecera no puede ser leida.
95
97
96 """
98 """
97
99
98
100
99 try:
101 try:
100 fp = open(filename,'rb')
102 fp = open(filename,'rb')
101 except:
103 except:
102 raise IOError, "The file %s can't be opened" %(filename)
104 raise IOError, "The file %s can't be opened" %(filename)
103
105
104 basicHeaderObj = BasicHeader()
106 basicHeaderObj = BasicHeader(LOCALTIME)
105 sts = basicHeaderObj.read(fp)
107 sts = basicHeaderObj.read(fp)
106 fp.close()
108 fp.close()
107
109
108 thisTime = basicHeaderObj.datatime.time()
110 thisTime = basicHeaderObj.datatime.time()
109
111
110 if not(sts):
112 if not(sts):
111 print "Skipping the file %s because it has not a valid header" %(filename)
113 print "Skipping the file %s because it has not a valid header" %(filename)
112 return 0
114 return 0
113
115
114 if not ((startTime <= thisTime) and (endTime > thisTime)):
116 if not ((startTime <= thisTime) and (endTime > thisTime)):
115 return 0
117 return 0
116
118
117 return 1
119 return 1
118
120
119 def getlastFileFromPath(path, ext):
121 def getlastFileFromPath(path, ext):
120 """
122 """
121 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
123 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
122 al final de la depuracion devuelve el ultimo file de la lista que quedo.
124 al final de la depuracion devuelve el ultimo file de la lista que quedo.
123
125
124 Input:
126 Input:
125 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
127 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
126 ext : extension de los files contenidos en una carpeta
128 ext : extension de los files contenidos en una carpeta
127
129
128 Return:
130 Return:
129 El ultimo file de una determinada carpeta, no se considera el path.
131 El ultimo file de una determinada carpeta, no se considera el path.
130 """
132 """
131 validFilelist = []
133 validFilelist = []
132 fileList = os.listdir(path)
134 fileList = os.listdir(path)
133
135
134 # 0 1234 567 89A BCDE
136 # 0 1234 567 89A BCDE
135 # H YYYY DDD SSS .ext
137 # H YYYY DDD SSS .ext
136
138
137 for file in fileList:
139 for file in fileList:
138 try:
140 try:
139 year = int(file[1:5])
141 year = int(file[1:5])
140 doy = int(file[5:8])
142 doy = int(file[5:8])
141
143
142
144
143 except:
145 except:
144 continue
146 continue
145
147
146 if (os.path.splitext(file)[-1].lower() != ext.lower()):
148 if (os.path.splitext(file)[-1].lower() != ext.lower()):
147 continue
149 continue
148
150
149 validFilelist.append(file)
151 validFilelist.append(file)
150
152
151 if validFilelist:
153 if validFilelist:
152 validFilelist = sorted( validFilelist, key=str.lower )
154 validFilelist = sorted( validFilelist, key=str.lower )
153 return validFilelist[-1]
155 return validFilelist[-1]
154
156
155 return None
157 return None
156
158
157 def checkForRealPath(path, year, doy, set, ext):
159 def checkForRealPath(path, year, doy, set, ext):
158 """
160 """
159 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
161 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
160 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
162 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
161 el path exacto de un determinado file.
163 el path exacto de un determinado file.
162
164
163 Example :
165 Example :
164 nombre correcto del file es .../.../D2009307/P2009307367.ext
166 nombre correcto del file es .../.../D2009307/P2009307367.ext
165
167
166 Entonces la funcion prueba con las siguientes combinaciones
168 Entonces la funcion prueba con las siguientes combinaciones
167 .../.../y2009307367.ext
169 .../.../y2009307367.ext
168 .../.../Y2009307367.ext
170 .../.../Y2009307367.ext
169 .../.../x2009307/y2009307367.ext
171 .../.../x2009307/y2009307367.ext
170 .../.../x2009307/Y2009307367.ext
172 .../.../x2009307/Y2009307367.ext
171 .../.../X2009307/y2009307367.ext
173 .../.../X2009307/y2009307367.ext
172 .../.../X2009307/Y2009307367.ext
174 .../.../X2009307/Y2009307367.ext
173 siendo para este caso, la ultima combinacion de letras, identica al file buscado
175 siendo para este caso, la ultima combinacion de letras, identica al file buscado
174
176
175 Return:
177 Return:
176 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
178 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
177 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
179 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
178 para el filename
180 para el filename
179 """
181 """
180 fullfilename = None
182 fullfilename = None
181 find_flag = False
183 find_flag = False
182 filename = None
184 filename = None
183
185
184 prefixDirList = [None,'d','D']
186 prefixDirList = [None,'d','D']
185 if ext.lower() == ".r": #voltage
187 if ext.lower() == ".r": #voltage
186 prefixFileList = ['d','D']
188 prefixFileList = ['d','D']
187 elif ext.lower() == ".pdata": #spectra
189 elif ext.lower() == ".pdata": #spectra
188 prefixFileList = ['p','P']
190 prefixFileList = ['p','P']
189 else:
191 else:
190 return None, filename
192 return None, filename
191
193
192 #barrido por las combinaciones posibles
194 #barrido por las combinaciones posibles
193 for prefixDir in prefixDirList:
195 for prefixDir in prefixDirList:
194 thispath = path
196 thispath = path
195 if prefixDir != None:
197 if prefixDir != None:
196 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
198 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
197 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
199 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
198
200
199 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
201 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
200 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
202 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
201 fullfilename = os.path.join( thispath, filename ) #formo el path completo
203 fullfilename = os.path.join( thispath, filename ) #formo el path completo
202
204
203 if os.path.exists( fullfilename ): #verifico que exista
205 if os.path.exists( fullfilename ): #verifico que exista
204 find_flag = True
206 find_flag = True
205 break
207 break
206 if find_flag:
208 if find_flag:
207 break
209 break
208
210
209 if not(find_flag):
211 if not(find_flag):
210 return None, filename
212 return None, filename
211
213
212 return fullfilename, filename
214 return fullfilename, filename
213
215
214 class JRODataIO:
216 class JRODataIO:
215
217
216 c = 3E8
218 c = 3E8
217
219
218 isConfig = False
220 isConfig = False
219
221
220 basicHeaderObj = BasicHeader()
222 basicHeaderObj = BasicHeader(LOCALTIME)
221
223
222 systemHeaderObj = SystemHeader()
224 systemHeaderObj = SystemHeader()
223
225
224 radarControllerHeaderObj = RadarControllerHeader()
226 radarControllerHeaderObj = RadarControllerHeader()
225
227
226 processingHeaderObj = ProcessingHeader()
228 processingHeaderObj = ProcessingHeader()
227
229
228 online = 0
230 online = 0
229
231
230 dtype = None
232 dtype = None
231
233
232 pathList = []
234 pathList = []
233
235
234 filenameList = []
236 filenameList = []
235
237
236 filename = None
238 filename = None
237
239
238 ext = None
240 ext = None
239
241
240 flagIsNewFile = 1
242 flagIsNewFile = 1
241
243
242 flagTimeBlock = 0
244 flagTimeBlock = 0
243
245
244 flagIsNewBlock = 0
246 flagIsNewBlock = 0
245
247
246 fp = None
248 fp = None
247
249
248 firstHeaderSize = 0
250 firstHeaderSize = 0
249
251
250 basicHeaderSize = 24
252 basicHeaderSize = 24
251
253
252 versionFile = 1103
254 versionFile = 1103
253
255
254 fileSize = None
256 fileSize = None
255
257
256 ippSeconds = None
258 ippSeconds = None
257
259
258 fileSizeByHeader = None
260 fileSizeByHeader = None
259
261
260 fileIndex = None
262 fileIndex = None
261
263
262 profileIndex = None
264 profileIndex = None
263
265
264 blockIndex = None
266 blockIndex = None
265
267
266 nTotalBlocks = None
268 nTotalBlocks = None
267
269
268 maxTimeStep = 30
270 maxTimeStep = 30
269
271
270 lastUTTime = None
272 lastUTTime = None
271
273
272 datablock = None
274 datablock = None
273
275
274 dataOut = None
276 dataOut = None
275
277
276 blocksize = None
278 blocksize = None
277
279
278 def __init__(self):
280 def __init__(self):
279
281
280 raise ValueError, "Not implemented"
282 raise ValueError, "Not implemented"
281
283
282 def run(self):
284 def run(self):
283
285
284 raise ValueError, "Not implemented"
286 raise ValueError, "Not implemented"
285
287
286 def getOutput(self):
288 def getOutput(self):
287
289
288 return self.dataOut
290 return self.dataOut
289
291
290 class JRODataReader(JRODataIO, ProcessingUnit):
292 class JRODataReader(JRODataIO, ProcessingUnit):
291
293
292 nReadBlocks = 0
294 nReadBlocks = 0
293
295
294 delay = 10 #number of seconds waiting a new file
296 delay = 10 #number of seconds waiting a new file
295
297
296 nTries = 3 #quantity tries
298 nTries = 3 #quantity tries
297
299
298 nFiles = 3 #number of files for searching
300 nFiles = 3 #number of files for searching
299
301
300 flagNoMoreFiles = 0
302 flagNoMoreFiles = 0
301
303
302 def __init__(self):
304 def __init__(self):
303
305
304 """
306 """
305
307
306 """
308 """
307
309
308 raise ValueError, "This method has not been implemented"
310 raise ValueError, "This method has not been implemented"
309
311
310
312
311 def createObjByDefault(self):
313 def createObjByDefault(self):
312 """
314 """
313
315
314 """
316 """
315 raise ValueError, "This method has not been implemented"
317 raise ValueError, "This method has not been implemented"
316
318
317 def getBlockDimension(self):
319 def getBlockDimension(self):
318
320
319 raise ValueError, "No implemented"
321 raise ValueError, "No implemented"
320
322
321 def __searchFilesOffLine(self,
323 def __searchFilesOffLine(self,
322 path,
324 path,
323 startDate,
325 startDate,
324 endDate,
326 endDate,
325 startTime=datetime.time(0,0,0),
327 startTime=datetime.time(0,0,0),
326 endTime=datetime.time(23,59,59),
328 endTime=datetime.time(23,59,59),
327 set=None,
329 set=None,
328 expLabel='',
330 expLabel='',
329 ext='.r',
331 ext='.r',
330 walk=True):
332 walk=True):
331
333
332 pathList = []
334 pathList = []
333
335
334 if not walk:
336 if not walk:
335 pathList.append(path)
337 pathList.append(path)
336
338
337 else:
339 else:
338 dirList = []
340 dirList = []
339 for thisPath in os.listdir(path):
341 for thisPath in os.listdir(path):
340 if os.path.isdir(os.path.join(path,thisPath)):
342 if os.path.isdir(os.path.join(path,thisPath)):
341 dirList.append(thisPath)
343 dirList.append(thisPath)
342
344
343 if not(dirList):
345 if not(dirList):
344 return None, None
346 return None, None
345
347
346 thisDate = startDate
348 thisDate = startDate
347
349
348 while(thisDate <= endDate):
350 while(thisDate <= endDate):
349 year = thisDate.timetuple().tm_year
351 year = thisDate.timetuple().tm_year
350 doy = thisDate.timetuple().tm_yday
352 doy = thisDate.timetuple().tm_yday
351
353
352 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
354 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
353 if len(match) == 0:
355 if len(match) == 0:
354 thisDate += datetime.timedelta(1)
356 thisDate += datetime.timedelta(1)
355 continue
357 continue
356
358
357 pathList.append(os.path.join(path,match[0],expLabel))
359 pathList.append(os.path.join(path,match[0],expLabel))
358 thisDate += datetime.timedelta(1)
360 thisDate += datetime.timedelta(1)
359
361
360 if pathList == []:
362 if pathList == []:
361 print "Any folder found into date range %s-%s" %(startDate, endDate)
363 print "Any folder found into date range %s-%s" %(startDate, endDate)
362 return None, None
364 return None, None
363
365
364 print "%d folder(s) found [%s, ...]" %(len(pathList), pathList[0])
366 print "%d folder(s) found [%s, ...]" %(len(pathList), pathList[0])
365
367
366 filenameList = []
368 filenameList = []
367 for thisPath in pathList:
369 for thisPath in pathList:
368
370
369 fileList = glob.glob1(thisPath, "*%s" %ext)
371 fileList = glob.glob1(thisPath, "*%s" %ext)
370 fileList.sort()
372 fileList.sort()
371
373
372 for file in fileList:
374 for file in fileList:
373
375
374 filename = os.path.join(thisPath,file)
376 filename = os.path.join(thisPath,file)
375
377
376 if isFileinThisTime(filename, startTime, endTime):
378 if isFileinThisTime(filename, startTime, endTime):
377 filenameList.append(filename)
379 filenameList.append(filename)
378
380
379 if not(filenameList):
381 if not(filenameList):
380 print "Any file found into time range %s-%s" %(startTime, endTime)
382 print "Any file found into time range %s-%s" %(startTime, endTime)
381 return None, None
383 return None, None
382
384
383 self.filenameList = filenameList
385 self.filenameList = filenameList
384
386
385 return pathList, filenameList
387 return pathList, filenameList
386
388
387 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
389 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
388
390
389 """
391 """
390 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
392 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
391 devuelve el archivo encontrado ademas de otros datos.
393 devuelve el archivo encontrado ademas de otros datos.
392
394
393 Input:
395 Input:
394 path : carpeta donde estan contenidos los files que contiene data
396 path : carpeta donde estan contenidos los files que contiene data
395
397
396 expLabel : Nombre del subexperimento (subfolder)
398 expLabel : Nombre del subexperimento (subfolder)
397
399
398 ext : extension de los files
400 ext : extension de los files
399
401
400 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
402 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
401
403
402 Return:
404 Return:
403 directory : eL directorio donde esta el file encontrado
405 directory : eL directorio donde esta el file encontrado
404 filename : el ultimo file de una determinada carpeta
406 filename : el ultimo file de una determinada carpeta
405 year : el anho
407 year : el anho
406 doy : el numero de dia del anho
408 doy : el numero de dia del anho
407 set : el set del archivo
409 set : el set del archivo
408
410
409
411
410 """
412 """
411 dirList = []
413 dirList = []
412
414
413 if walk:
415 if walk:
414
416
415 #Filtra solo los directorios
417 #Filtra solo los directorios
416 for thisPath in os.listdir(path):
418 for thisPath in os.listdir(path):
417 if os.path.isdir(os.path.join(path, thisPath)):
419 if os.path.isdir(os.path.join(path, thisPath)):
418 dirList.append(thisPath)
420 dirList.append(thisPath)
419
421
420 if not(dirList):
422 if not(dirList):
421 return None, None, None, None, None
423 return None, None, None, None, None
422
424
423 dirList = sorted( dirList, key=str.lower )
425 dirList = sorted( dirList, key=str.lower )
424
426
425 doypath = dirList[-1]
427 doypath = dirList[-1]
426 fullpath = os.path.join(path, doypath, expLabel)
428 fullpath = os.path.join(path, doypath, expLabel)
427
429
428 else:
430 else:
429 fullpath = path
431 fullpath = path
430
432
431 filename = getlastFileFromPath(fullpath, ext)
433 filename = getlastFileFromPath(fullpath, ext)
432
434
433 if not(filename):
435 if not(filename):
434 return None, None, None, None, None
436 return None, None, None, None, None
435
437
436 if not(self.__verifyFile(os.path.join(fullpath, filename))):
438 if not(self.__verifyFile(os.path.join(fullpath, filename))):
437 return None, None, None, None, None
439 return None, None, None, None, None
438
440
439 year = int( filename[1:5] )
441 year = int( filename[1:5] )
440 doy = int( filename[5:8] )
442 doy = int( filename[5:8] )
441 set = int( filename[8:11] )
443 set = int( filename[8:11] )
442
444
443 return fullpath, filename, year, doy, set
445 return fullpath, filename, year, doy, set
444
446
445
447
446
448
447 def __setNextFileOffline(self):
449 def __setNextFileOffline(self):
448
450
449 idFile = self.fileIndex
451 idFile = self.fileIndex
450
452
451 while (True):
453 while (True):
452 idFile += 1
454 idFile += 1
453 if not(idFile < len(self.filenameList)):
455 if not(idFile < len(self.filenameList)):
454 self.flagNoMoreFiles = 1
456 self.flagNoMoreFiles = 1
455 print "No more Files"
457 print "No more Files"
456 return 0
458 return 0
457
459
458 filename = self.filenameList[idFile]
460 filename = self.filenameList[idFile]
459
461
460 if not(self.__verifyFile(filename)):
462 if not(self.__verifyFile(filename)):
461 continue
463 continue
462
464
463 fileSize = os.path.getsize(filename)
465 fileSize = os.path.getsize(filename)
464 fp = open(filename,'rb')
466 fp = open(filename,'rb')
465 break
467 break
466
468
467 self.flagIsNewFile = 1
469 self.flagIsNewFile = 1
468 self.fileIndex = idFile
470 self.fileIndex = idFile
469 self.filename = filename
471 self.filename = filename
470 self.fileSize = fileSize
472 self.fileSize = fileSize
471 self.fp = fp
473 self.fp = fp
472
474
473 print "Setting the file: %s"%self.filename
475 print "Setting the file: %s"%self.filename
474
476
475 return 1
477 return 1
476
478
477 def __setNextFileOnline(self):
479 def __setNextFileOnline(self):
478 """
480 """
479 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
481 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
480 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
482 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
481 siguientes.
483 siguientes.
482
484
483 Affected:
485 Affected:
484 self.flagIsNewFile
486 self.flagIsNewFile
485 self.filename
487 self.filename
486 self.fileSize
488 self.fileSize
487 self.fp
489 self.fp
488 self.set
490 self.set
489 self.flagNoMoreFiles
491 self.flagNoMoreFiles
490
492
491 Return:
493 Return:
492 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
494 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
493 1 : si el file fue abierto con exito y esta listo a ser leido
495 1 : si el file fue abierto con exito y esta listo a ser leido
494
496
495 Excepciones:
497 Excepciones:
496 Si un determinado file no puede ser abierto
498 Si un determinado file no puede ser abierto
497 """
499 """
498 nFiles = 0
500 nFiles = 0
499 fileOk_flag = False
501 fileOk_flag = False
500 firstTime_flag = True
502 firstTime_flag = True
501
503
502 self.set += 1
504 self.set += 1
503
505
504 #busca el 1er file disponible
506 #busca el 1er file disponible
505 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
507 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
506 if fullfilename:
508 if fullfilename:
507 if self.__verifyFile(fullfilename, False):
509 if self.__verifyFile(fullfilename, False):
508 fileOk_flag = True
510 fileOk_flag = True
509
511
510 #si no encuentra un file entonces espera y vuelve a buscar
512 #si no encuentra un file entonces espera y vuelve a buscar
511 if not(fileOk_flag):
513 if not(fileOk_flag):
512 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
514 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
513
515
514 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
516 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
515 tries = self.nTries
517 tries = self.nTries
516 else:
518 else:
517 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
519 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
518
520
519 for nTries in range( tries ):
521 for nTries in range( tries ):
520 if firstTime_flag:
522 if firstTime_flag:
521 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
523 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
522 time.sleep( self.delay )
524 time.sleep( self.delay )
523 else:
525 else:
524 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
526 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
525
527
526 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
528 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
527 if fullfilename:
529 if fullfilename:
528 if self.__verifyFile(fullfilename):
530 if self.__verifyFile(fullfilename):
529 fileOk_flag = True
531 fileOk_flag = True
530 break
532 break
531
533
532 if fileOk_flag:
534 if fileOk_flag:
533 break
535 break
534
536
535 firstTime_flag = False
537 firstTime_flag = False
536
538
537 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
539 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
538 self.set += 1
540 self.set += 1
539
541
540 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
542 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
541 self.set = 0
543 self.set = 0
542 self.doy += 1
544 self.doy += 1
543
545
544 if fileOk_flag:
546 if fileOk_flag:
545 self.fileSize = os.path.getsize( fullfilename )
547 self.fileSize = os.path.getsize( fullfilename )
546 self.filename = fullfilename
548 self.filename = fullfilename
547 self.flagIsNewFile = 1
549 self.flagIsNewFile = 1
548 if self.fp != None: self.fp.close()
550 if self.fp != None: self.fp.close()
549 self.fp = open(fullfilename, 'rb')
551 self.fp = open(fullfilename, 'rb')
550 self.flagNoMoreFiles = 0
552 self.flagNoMoreFiles = 0
551 print 'Setting the file: %s' % fullfilename
553 print 'Setting the file: %s' % fullfilename
552 else:
554 else:
553 self.fileSize = 0
555 self.fileSize = 0
554 self.filename = None
556 self.filename = None
555 self.flagIsNewFile = 0
557 self.flagIsNewFile = 0
556 self.fp = None
558 self.fp = None
557 self.flagNoMoreFiles = 1
559 self.flagNoMoreFiles = 1
558 print 'No more Files'
560 print 'No more Files'
559
561
560 return fileOk_flag
562 return fileOk_flag
561
563
562
564
563 def setNextFile(self):
565 def setNextFile(self):
564 if self.fp != None:
566 if self.fp != None:
565 self.fp.close()
567 self.fp.close()
566
568
567 if self.online:
569 if self.online:
568 newFile = self.__setNextFileOnline()
570 newFile = self.__setNextFileOnline()
569 else:
571 else:
570 newFile = self.__setNextFileOffline()
572 newFile = self.__setNextFileOffline()
571
573
572 if not(newFile):
574 if not(newFile):
573 return 0
575 return 0
574
576
575 self.__readFirstHeader()
577 self.__readFirstHeader()
576 self.nReadBlocks = 0
578 self.nReadBlocks = 0
577 return 1
579 return 1
578
580
579 def __waitNewBlock(self):
581 def __waitNewBlock(self):
580 """
582 """
581 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
583 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
582
584
583 Si el modo de lectura es OffLine siempre retorn 0
585 Si el modo de lectura es OffLine siempre retorn 0
584 """
586 """
585 if not self.online:
587 if not self.online:
586 return 0
588 return 0
587
589
588 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
590 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
589 return 0
591 return 0
590
592
591 currentPointer = self.fp.tell()
593 currentPointer = self.fp.tell()
592
594
593 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
595 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
594
596
595 for nTries in range( self.nTries ):
597 for nTries in range( self.nTries ):
596
598
597 self.fp.close()
599 self.fp.close()
598 self.fp = open( self.filename, 'rb' )
600 self.fp = open( self.filename, 'rb' )
599 self.fp.seek( currentPointer )
601 self.fp.seek( currentPointer )
600
602
601 self.fileSize = os.path.getsize( self.filename )
603 self.fileSize = os.path.getsize( self.filename )
602 currentSize = self.fileSize - currentPointer
604 currentSize = self.fileSize - currentPointer
603
605
604 if ( currentSize >= neededSize ):
606 if ( currentSize >= neededSize ):
605 self.__rdBasicHeader()
607 self.__rdBasicHeader()
606 return 1
608 return 1
607
609
608 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
610 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
609 time.sleep( self.delay )
611 time.sleep( self.delay )
610
612
611
613
612 return 0
614 return 0
613
615
614 def __setNewBlock(self):
616 def __setNewBlock(self):
615
617
616 if self.fp == None:
618 if self.fp == None:
617 return 0
619 return 0
618
620
619 if self.flagIsNewFile:
621 if self.flagIsNewFile:
620 return 1
622 return 1
621
623
622 self.lastUTTime = self.basicHeaderObj.utc
624 self.lastUTTime = self.basicHeaderObj.utc
623 currentSize = self.fileSize - self.fp.tell()
625 currentSize = self.fileSize - self.fp.tell()
624 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
626 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
625
627
626 if (currentSize >= neededSize):
628 if (currentSize >= neededSize):
627 self.__rdBasicHeader()
629 self.__rdBasicHeader()
628 return 1
630 return 1
629
631
630 if self.__waitNewBlock():
632 if self.__waitNewBlock():
631 return 1
633 return 1
632
634
633 if not(self.setNextFile()):
635 if not(self.setNextFile()):
634 return 0
636 return 0
635
637
636 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
638 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
637
639
638 self.flagTimeBlock = 0
640 self.flagTimeBlock = 0
639
641
640 if deltaTime > self.maxTimeStep:
642 if deltaTime > self.maxTimeStep:
641 self.flagTimeBlock = 1
643 self.flagTimeBlock = 1
642
644
643 return 1
645 return 1
644
646
645
647
646 def readNextBlock(self):
648 def readNextBlock(self):
647 if not(self.__setNewBlock()):
649 if not(self.__setNewBlock()):
648 return 0
650 return 0
649
651
650 if not(self.readBlock()):
652 if not(self.readBlock()):
651 return 0
653 return 0
652
654
653 return 1
655 return 1
654
656
655 def __rdProcessingHeader(self, fp=None):
657 def __rdProcessingHeader(self, fp=None):
656 if fp == None:
658 if fp == None:
657 fp = self.fp
659 fp = self.fp
658
660
659 self.processingHeaderObj.read(fp)
661 self.processingHeaderObj.read(fp)
660
662
661 def __rdRadarControllerHeader(self, fp=None):
663 def __rdRadarControllerHeader(self, fp=None):
662 if fp == None:
664 if fp == None:
663 fp = self.fp
665 fp = self.fp
664
666
665 self.radarControllerHeaderObj.read(fp)
667 self.radarControllerHeaderObj.read(fp)
666
668
667 def __rdSystemHeader(self, fp=None):
669 def __rdSystemHeader(self, fp=None):
668 if fp == None:
670 if fp == None:
669 fp = self.fp
671 fp = self.fp
670
672
671 self.systemHeaderObj.read(fp)
673 self.systemHeaderObj.read(fp)
672
674
673 def __rdBasicHeader(self, fp=None):
675 def __rdBasicHeader(self, fp=None):
674 if fp == None:
676 if fp == None:
675 fp = self.fp
677 fp = self.fp
676
678
677 self.basicHeaderObj.read(fp)
679 self.basicHeaderObj.read(fp)
678
680
679
681
680 def __readFirstHeader(self):
682 def __readFirstHeader(self):
681 self.__rdBasicHeader()
683 self.__rdBasicHeader()
682 self.__rdSystemHeader()
684 self.__rdSystemHeader()
683 self.__rdRadarControllerHeader()
685 self.__rdRadarControllerHeader()
684 self.__rdProcessingHeader()
686 self.__rdProcessingHeader()
685
687
686 self.firstHeaderSize = self.basicHeaderObj.size
688 self.firstHeaderSize = self.basicHeaderObj.size
687
689
688 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
690 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
689 if datatype == 0:
691 if datatype == 0:
690 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
692 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
691 elif datatype == 1:
693 elif datatype == 1:
692 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
694 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
693 elif datatype == 2:
695 elif datatype == 2:
694 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
696 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
695 elif datatype == 3:
697 elif datatype == 3:
696 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
698 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
697 elif datatype == 4:
699 elif datatype == 4:
698 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
700 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
699 elif datatype == 5:
701 elif datatype == 5:
700 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
702 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
701 else:
703 else:
702 raise ValueError, 'Data type was not defined'
704 raise ValueError, 'Data type was not defined'
703
705
704 self.dtype = datatype_str
706 self.dtype = datatype_str
705 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
707 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
706 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
708 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
707 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
709 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
708 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
710 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
709 self.getBlockDimension()
711 self.getBlockDimension()
710
712
711
713
712 def __verifyFile(self, filename, msgFlag=True):
714 def __verifyFile(self, filename, msgFlag=True):
713 msg = None
715 msg = None
714 try:
716 try:
715 fp = open(filename, 'rb')
717 fp = open(filename, 'rb')
716 currentPosition = fp.tell()
718 currentPosition = fp.tell()
717 except:
719 except:
718 if msgFlag:
720 if msgFlag:
719 print "The file %s can't be opened" % (filename)
721 print "The file %s can't be opened" % (filename)
720 return False
722 return False
721
723
722 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
724 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
723
725
724 if neededSize == 0:
726 if neededSize == 0:
725 basicHeaderObj = BasicHeader()
727 basicHeaderObj = BasicHeader(LOCALTIME)
726 systemHeaderObj = SystemHeader()
728 systemHeaderObj = SystemHeader()
727 radarControllerHeaderObj = RadarControllerHeader()
729 radarControllerHeaderObj = RadarControllerHeader()
728 processingHeaderObj = ProcessingHeader()
730 processingHeaderObj = ProcessingHeader()
729
731
730 try:
732 try:
731 if not( basicHeaderObj.read(fp) ): raise IOError
733 if not( basicHeaderObj.read(fp) ): raise IOError
732 if not( systemHeaderObj.read(fp) ): raise IOError
734 if not( systemHeaderObj.read(fp) ): raise IOError
733 if not( radarControllerHeaderObj.read(fp) ): raise IOError
735 if not( radarControllerHeaderObj.read(fp) ): raise IOError
734 if not( processingHeaderObj.read(fp) ): raise IOError
736 if not( processingHeaderObj.read(fp) ): raise IOError
735 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
737 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
736
738
737 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
739 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
738
740
739 except:
741 except:
740 if msgFlag:
742 if msgFlag:
741 print "\tThe file %s is empty or it hasn't enough data" % filename
743 print "\tThe file %s is empty or it hasn't enough data" % filename
742
744
743 fp.close()
745 fp.close()
744 return False
746 return False
745 else:
747 else:
746 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
748 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
747
749
748 fp.close()
750 fp.close()
749 fileSize = os.path.getsize(filename)
751 fileSize = os.path.getsize(filename)
750 currentSize = fileSize - currentPosition
752 currentSize = fileSize - currentPosition
751 if currentSize < neededSize:
753 if currentSize < neededSize:
752 if msgFlag and (msg != None):
754 if msgFlag and (msg != None):
753 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
755 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
754 return False
756 return False
755
757
756 return True
758 return True
757
759
758 def setup(self,
760 def setup(self,
759 path=None,
761 path=None,
760 startDate=None,
762 startDate=None,
761 endDate=None,
763 endDate=None,
762 startTime=datetime.time(0,0,0),
764 startTime=datetime.time(0,0,0),
763 endTime=datetime.time(23,59,59),
765 endTime=datetime.time(23,59,59),
764 set=0,
766 set=0,
765 expLabel = "",
767 expLabel = "",
766 ext = None,
768 ext = None,
767 online = False,
769 online = False,
768 delay = 60,
770 delay = 60,
769 walk = True):
771 walk = True):
770
772
771 if path == None:
773 if path == None:
772 raise ValueError, "The path is not valid"
774 raise ValueError, "The path is not valid"
773
775
774 if ext == None:
776 if ext == None:
775 ext = self.ext
777 ext = self.ext
776
778
777 if online:
779 if online:
778 print "Searching files in online mode..."
780 print "Searching files in online mode..."
779
781
780 for nTries in range( self.nTries ):
782 for nTries in range( self.nTries ):
781 fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
783 fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
782
784
783 if fullpath:
785 if fullpath:
784 break
786 break
785
787
786 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
788 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
787 time.sleep( self.delay )
789 time.sleep( self.delay )
788
790
789 if not(fullpath):
791 if not(fullpath):
790 print "There 'isn't valied files in %s" % path
792 print "There 'isn't valied files in %s" % path
791 return None
793 return None
792
794
793 self.year = year
795 self.year = year
794 self.doy = doy
796 self.doy = doy
795 self.set = set - 1
797 self.set = set - 1
796 self.path = path
798 self.path = path
797
799
798 else:
800 else:
799 print "Searching files in offline mode ..."
801 print "Searching files in offline mode ..."
800 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
802 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
801 startTime=startTime, endTime=endTime,
803 startTime=startTime, endTime=endTime,
802 set=set, expLabel=expLabel, ext=ext,
804 set=set, expLabel=expLabel, ext=ext,
803 walk=walk)
805 walk=walk)
804
806
805 if not(pathList):
807 if not(pathList):
806 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
808 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
807 datetime.datetime.combine(startDate,startTime).ctime(),
809 datetime.datetime.combine(startDate,startTime).ctime(),
808 datetime.datetime.combine(endDate,endTime).ctime())
810 datetime.datetime.combine(endDate,endTime).ctime())
809
811
810 sys.exit(-1)
812 sys.exit(-1)
811
813
812
814
813 self.fileIndex = -1
815 self.fileIndex = -1
814 self.pathList = pathList
816 self.pathList = pathList
815 self.filenameList = filenameList
817 self.filenameList = filenameList
816
818
817 self.online = online
819 self.online = online
818 self.delay = delay
820 self.delay = delay
819 ext = ext.lower()
821 ext = ext.lower()
820 self.ext = ext
822 self.ext = ext
821
823
822 if not(self.setNextFile()):
824 if not(self.setNextFile()):
823 if (startDate!=None) and (endDate!=None):
825 if (startDate!=None) and (endDate!=None):
824 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
826 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
825 elif startDate != None:
827 elif startDate != None:
826 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
828 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
827 else:
829 else:
828 print "No files"
830 print "No files"
829
831
830 sys.exit(-1)
832 sys.exit(-1)
831
833
832 # self.updateDataHeader()
834 # self.updateDataHeader()
833
835
834 return self.dataOut
836 return self.dataOut
835
837
836 def getData():
838 def getData():
837
839
838 raise ValueError, "This method has not been implemented"
840 raise ValueError, "This method has not been implemented"
839
841
840 def hasNotDataInBuffer():
842 def hasNotDataInBuffer():
841
843
842 raise ValueError, "This method has not been implemented"
844 raise ValueError, "This method has not been implemented"
843
845
844 def readBlock():
846 def readBlock():
845
847
846 raise ValueError, "This method has not been implemented"
848 raise ValueError, "This method has not been implemented"
847
849
848 def isEndProcess(self):
850 def isEndProcess(self):
849
851
850 return self.flagNoMoreFiles
852 return self.flagNoMoreFiles
851
853
852 def printReadBlocks(self):
854 def printReadBlocks(self):
853
855
854 print "Number of read blocks per file %04d" %self.nReadBlocks
856 print "Number of read blocks per file %04d" %self.nReadBlocks
855
857
856 def printTotalBlocks(self):
858 def printTotalBlocks(self):
857
859
858 print "Number of read blocks %04d" %self.nTotalBlocks
860 print "Number of read blocks %04d" %self.nTotalBlocks
859
861
860 def printInfo(self):
862 def printInfo(self):
861
863
862 print self.basicHeaderObj.printInfo()
864 print self.basicHeaderObj.printInfo()
863 print self.systemHeaderObj.printInfo()
865 print self.systemHeaderObj.printInfo()
864 print self.radarControllerHeaderObj.printInfo()
866 print self.radarControllerHeaderObj.printInfo()
865 print self.processingHeaderObj.printInfo()
867 print self.processingHeaderObj.printInfo()
866
868
867
869
868 def run(self, **kwargs):
870 def run(self, **kwargs):
869
871
870 if not(self.isConfig):
872 if not(self.isConfig):
871
873
872 # self.dataOut = dataOut
874 # self.dataOut = dataOut
873 self.setup(**kwargs)
875 self.setup(**kwargs)
874 self.isConfig = True
876 self.isConfig = True
875
877
876 self.getData()
878 self.getData()
877
879
878 class JRODataWriter(JRODataIO, Operation):
880 class JRODataWriter(JRODataIO, Operation):
879
881
880 """
882 """
881 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
883 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
882 de los datos siempre se realiza por bloques.
884 de los datos siempre se realiza por bloques.
883 """
885 """
884
886
885 blockIndex = 0
887 blockIndex = 0
886
888
887 path = None
889 path = None
888
890
889 setFile = None
891 setFile = None
890
892
891 profilesPerBlock = None
893 profilesPerBlock = None
892
894
893 blocksPerFile = None
895 blocksPerFile = None
894
896
895 nWriteBlocks = 0
897 nWriteBlocks = 0
896
898
897 def __init__(self, dataOut=None):
899 def __init__(self, dataOut=None):
898 raise ValueError, "Not implemented"
900 raise ValueError, "Not implemented"
899
901
900
902
901 def hasAllDataInBuffer(self):
903 def hasAllDataInBuffer(self):
902 raise ValueError, "Not implemented"
904 raise ValueError, "Not implemented"
903
905
904
906
905 def setBlockDimension(self):
907 def setBlockDimension(self):
906 raise ValueError, "Not implemented"
908 raise ValueError, "Not implemented"
907
909
908
910
909 def writeBlock(self):
911 def writeBlock(self):
910 raise ValueError, "No implemented"
912 raise ValueError, "No implemented"
911
913
912
914
913 def putData(self):
915 def putData(self):
914 raise ValueError, "No implemented"
916 raise ValueError, "No implemented"
915
917
916 def getDataHeader(self):
918 def getDataHeader(self):
917 """
919 """
918 Obtiene una copia del First Header
920 Obtiene una copia del First Header
919
921
920 Affected:
922 Affected:
921
923
922 self.basicHeaderObj
924 self.basicHeaderObj
923 self.systemHeaderObj
925 self.systemHeaderObj
924 self.radarControllerHeaderObj
926 self.radarControllerHeaderObj
925 self.processingHeaderObj self.
927 self.processingHeaderObj self.
926
928
927 Return:
929 Return:
928 None
930 None
929 """
931 """
930
932
931 raise ValueError, "No implemented"
933 raise ValueError, "No implemented"
932
934
933 def getBasicHeader(self):
935 def getBasicHeader(self):
934
936
935 self.basicHeaderObj.size = self.basicHeaderSize #bytes
937 self.basicHeaderObj.size = self.basicHeaderSize #bytes
936 self.basicHeaderObj.version = self.versionFile
938 self.basicHeaderObj.version = self.versionFile
937 self.basicHeaderObj.dataBlock = self.nTotalBlocks
939 self.basicHeaderObj.dataBlock = self.nTotalBlocks
938
940
939 utc = numpy.floor(self.dataOut.utctime)
941 utc = numpy.floor(self.dataOut.utctime)
940 milisecond = (self.dataOut.utctime - utc)* 1000.0
942 milisecond = (self.dataOut.utctime - utc)* 1000.0
941
943
942 self.basicHeaderObj.utc = utc
944 self.basicHeaderObj.utc = utc
943 self.basicHeaderObj.miliSecond = milisecond
945 self.basicHeaderObj.miliSecond = milisecond
944 self.basicHeaderObj.timeZone = 0
946 self.basicHeaderObj.timeZone = 0
945 self.basicHeaderObj.dstFlag = 0
947 self.basicHeaderObj.dstFlag = 0
946 self.basicHeaderObj.errorCount = 0
948 self.basicHeaderObj.errorCount = 0
947
949
948 def __writeFirstHeader(self):
950 def __writeFirstHeader(self):
949 """
951 """
950 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
952 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
951
953
952 Affected:
954 Affected:
953 __dataType
955 __dataType
954
956
955 Return:
957 Return:
956 None
958 None
957 """
959 """
958
960
959 # CALCULAR PARAMETROS
961 # CALCULAR PARAMETROS
960
962
961 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
963 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
962 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
964 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
963
965
964 self.basicHeaderObj.write(self.fp)
966 self.basicHeaderObj.write(self.fp)
965 self.systemHeaderObj.write(self.fp)
967 self.systemHeaderObj.write(self.fp)
966 self.radarControllerHeaderObj.write(self.fp)
968 self.radarControllerHeaderObj.write(self.fp)
967 self.processingHeaderObj.write(self.fp)
969 self.processingHeaderObj.write(self.fp)
968
970
969 self.dtype = self.dataOut.dtype
971 self.dtype = self.dataOut.dtype
970
972
971 def __setNewBlock(self):
973 def __setNewBlock(self):
972 """
974 """
973 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
975 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
974
976
975 Return:
977 Return:
976 0 : si no pudo escribir nada
978 0 : si no pudo escribir nada
977 1 : Si escribio el Basic el First Header
979 1 : Si escribio el Basic el First Header
978 """
980 """
979 if self.fp == None:
981 if self.fp == None:
980 self.setNextFile()
982 self.setNextFile()
981
983
982 if self.flagIsNewFile:
984 if self.flagIsNewFile:
983 return 1
985 return 1
984
986
985 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
987 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
986 self.basicHeaderObj.write(self.fp)
988 self.basicHeaderObj.write(self.fp)
987 return 1
989 return 1
988
990
989 if not( self.setNextFile() ):
991 if not( self.setNextFile() ):
990 return 0
992 return 0
991
993
992 return 1
994 return 1
993
995
994
996
995 def writeNextBlock(self):
997 def writeNextBlock(self):
996 """
998 """
997 Selecciona el bloque siguiente de datos y los escribe en un file
999 Selecciona el bloque siguiente de datos y los escribe en un file
998
1000
999 Return:
1001 Return:
1000 0 : Si no hizo pudo escribir el bloque de datos
1002 0 : Si no hizo pudo escribir el bloque de datos
1001 1 : Si no pudo escribir el bloque de datos
1003 1 : Si no pudo escribir el bloque de datos
1002 """
1004 """
1003 if not( self.__setNewBlock() ):
1005 if not( self.__setNewBlock() ):
1004 return 0
1006 return 0
1005
1007
1006 self.writeBlock()
1008 self.writeBlock()
1007
1009
1008 return 1
1010 return 1
1009
1011
1010 def setNextFile(self):
1012 def setNextFile(self):
1011 """
1013 """
1012 Determina el siguiente file que sera escrito
1014 Determina el siguiente file que sera escrito
1013
1015
1014 Affected:
1016 Affected:
1015 self.filename
1017 self.filename
1016 self.subfolder
1018 self.subfolder
1017 self.fp
1019 self.fp
1018 self.setFile
1020 self.setFile
1019 self.flagIsNewFile
1021 self.flagIsNewFile
1020
1022
1021 Return:
1023 Return:
1022 0 : Si el archivo no puede ser escrito
1024 0 : Si el archivo no puede ser escrito
1023 1 : Si el archivo esta listo para ser escrito
1025 1 : Si el archivo esta listo para ser escrito
1024 """
1026 """
1025 ext = self.ext
1027 ext = self.ext
1026 path = self.path
1028 path = self.path
1027
1029
1028 if self.fp != None:
1030 if self.fp != None:
1029 self.fp.close()
1031 self.fp.close()
1030
1032
1031 timeTuple = time.localtime( self.dataOut.dataUtcTime)
1033 timeTuple = time.localtime( self.dataOut.dataUtcTime)
1032 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1034 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1033
1035
1034 fullpath = os.path.join( path, subfolder )
1036 fullpath = os.path.join( path, subfolder )
1035 if not( os.path.exists(fullpath) ):
1037 if not( os.path.exists(fullpath) ):
1036 os.mkdir(fullpath)
1038 os.mkdir(fullpath)
1037 self.setFile = -1 #inicializo mi contador de seteo
1039 self.setFile = -1 #inicializo mi contador de seteo
1038 else:
1040 else:
1039 filesList = os.listdir( fullpath )
1041 filesList = os.listdir( fullpath )
1040 if len( filesList ) > 0:
1042 if len( filesList ) > 0:
1041 filesList = sorted( filesList, key=str.lower )
1043 filesList = sorted( filesList, key=str.lower )
1042 filen = filesList[-1]
1044 filen = filesList[-1]
1043 # el filename debera tener el siguiente formato
1045 # el filename debera tener el siguiente formato
1044 # 0 1234 567 89A BCDE (hex)
1046 # 0 1234 567 89A BCDE (hex)
1045 # x YYYY DDD SSS .ext
1047 # x YYYY DDD SSS .ext
1046 if isNumber( filen[8:11] ):
1048 if isNumber( filen[8:11] ):
1047 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1049 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1048 else:
1050 else:
1049 self.setFile = -1
1051 self.setFile = -1
1050 else:
1052 else:
1051 self.setFile = -1 #inicializo mi contador de seteo
1053 self.setFile = -1 #inicializo mi contador de seteo
1052
1054
1053 setFile = self.setFile
1055 setFile = self.setFile
1054 setFile += 1
1056 setFile += 1
1055
1057
1056 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1058 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1057 timeTuple.tm_year,
1059 timeTuple.tm_year,
1058 timeTuple.tm_yday,
1060 timeTuple.tm_yday,
1059 setFile,
1061 setFile,
1060 ext )
1062 ext )
1061
1063
1062 filename = os.path.join( path, subfolder, file )
1064 filename = os.path.join( path, subfolder, file )
1063
1065
1064 fp = open( filename,'wb' )
1066 fp = open( filename,'wb' )
1065
1067
1066 self.blockIndex = 0
1068 self.blockIndex = 0
1067
1069
1068 #guardando atributos
1070 #guardando atributos
1069 self.filename = filename
1071 self.filename = filename
1070 self.subfolder = subfolder
1072 self.subfolder = subfolder
1071 self.fp = fp
1073 self.fp = fp
1072 self.setFile = setFile
1074 self.setFile = setFile
1073 self.flagIsNewFile = 1
1075 self.flagIsNewFile = 1
1074
1076
1075 self.getDataHeader()
1077 self.getDataHeader()
1076
1078
1077 print 'Writing the file: %s'%self.filename
1079 print 'Writing the file: %s'%self.filename
1078
1080
1079 self.__writeFirstHeader()
1081 self.__writeFirstHeader()
1080
1082
1081 return 1
1083 return 1
1082
1084
1083 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1085 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1084 """
1086 """
1085 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1087 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1086
1088
1087 Inputs:
1089 Inputs:
1088 path : el path destino en el cual se escribiran los files a crear
1090 path : el path destino en el cual se escribiran los files a crear
1089 format : formato en el cual sera salvado un file
1091 format : formato en el cual sera salvado un file
1090 set : el setebo del file
1092 set : el setebo del file
1091
1093
1092 Return:
1094 Return:
1093 0 : Si no realizo un buen seteo
1095 0 : Si no realizo un buen seteo
1094 1 : Si realizo un buen seteo
1096 1 : Si realizo un buen seteo
1095 """
1097 """
1096
1098
1097 if ext == None:
1099 if ext == None:
1098 ext = self.ext
1100 ext = self.ext
1099
1101
1100 ext = ext.lower()
1102 ext = ext.lower()
1101
1103
1102 self.ext = ext
1104 self.ext = ext
1103
1105
1104 self.path = path
1106 self.path = path
1105
1107
1106 self.setFile = set - 1
1108 self.setFile = set - 1
1107
1109
1108 self.blocksPerFile = blocksPerFile
1110 self.blocksPerFile = blocksPerFile
1109
1111
1110 self.profilesPerBlock = profilesPerBlock
1112 self.profilesPerBlock = profilesPerBlock
1111
1113
1112 self.dataOut = dataOut
1114 self.dataOut = dataOut
1113
1115
1114 if not(self.setNextFile()):
1116 if not(self.setNextFile()):
1115 print "There isn't a next file"
1117 print "There isn't a next file"
1116 return 0
1118 return 0
1117
1119
1118 self.setBlockDimension()
1120 self.setBlockDimension()
1119
1121
1120 return 1
1122 return 1
1121
1123
1122 def run(self, dataOut, **kwargs):
1124 def run(self, dataOut, **kwargs):
1123
1125
1124 if not(self.isConfig):
1126 if not(self.isConfig):
1125
1127
1126 self.setup(dataOut, **kwargs)
1128 self.setup(dataOut, **kwargs)
1127 self.isConfig = True
1129 self.isConfig = True
1128
1130
1129 self.putData()
1131 self.putData()
1130
1132
1131 class VoltageReader(JRODataReader):
1133 class VoltageReader(JRODataReader):
1132 """
1134 """
1133 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1135 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1134 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1136 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1135 perfiles*alturas*canales) son almacenados en la variable "buffer".
1137 perfiles*alturas*canales) son almacenados en la variable "buffer".
1136
1138
1137 perfiles * alturas * canales
1139 perfiles * alturas * canales
1138
1140
1139 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1141 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1140 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1142 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1141 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1143 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1142 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1144 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1143
1145
1144 Example:
1146 Example:
1145
1147
1146 dpath = "/home/myuser/data"
1148 dpath = "/home/myuser/data"
1147
1149
1148 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1150 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1149
1151
1150 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1152 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1151
1153
1152 readerObj = VoltageReader()
1154 readerObj = VoltageReader()
1153
1155
1154 readerObj.setup(dpath, startTime, endTime)
1156 readerObj.setup(dpath, startTime, endTime)
1155
1157
1156 while(True):
1158 while(True):
1157
1159
1158 #to get one profile
1160 #to get one profile
1159 profile = readerObj.getData()
1161 profile = readerObj.getData()
1160
1162
1161 #print the profile
1163 #print the profile
1162 print profile
1164 print profile
1163
1165
1164 #If you want to see all datablock
1166 #If you want to see all datablock
1165 print readerObj.datablock
1167 print readerObj.datablock
1166
1168
1167 if readerObj.flagNoMoreFiles:
1169 if readerObj.flagNoMoreFiles:
1168 break
1170 break
1169
1171
1170 """
1172 """
1171
1173
1172 ext = ".r"
1174 ext = ".r"
1173
1175
1174 optchar = "D"
1176 optchar = "D"
1175 dataOut = None
1177 dataOut = None
1176
1178
1177
1179
1178 def __init__(self):
1180 def __init__(self):
1179 """
1181 """
1180 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1182 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1181
1183
1182 Input:
1184 Input:
1183 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1185 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1184 almacenar un perfil de datos cada vez que se haga un requerimiento
1186 almacenar un perfil de datos cada vez que se haga un requerimiento
1185 (getData). El perfil sera obtenido a partir del buffer de datos,
1187 (getData). El perfil sera obtenido a partir del buffer de datos,
1186 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1188 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1187 bloque de datos.
1189 bloque de datos.
1188 Si este parametro no es pasado se creara uno internamente.
1190 Si este parametro no es pasado se creara uno internamente.
1189
1191
1190 Variables afectadas:
1192 Variables afectadas:
1191 self.dataOut
1193 self.dataOut
1192
1194
1193 Return:
1195 Return:
1194 None
1196 None
1195 """
1197 """
1196
1198
1197 self.isConfig = False
1199 self.isConfig = False
1198
1200
1199 self.datablock = None
1201 self.datablock = None
1200
1202
1201 self.utc = 0
1203 self.utc = 0
1202
1204
1203 self.ext = ".r"
1205 self.ext = ".r"
1204
1206
1205 self.optchar = "D"
1207 self.optchar = "D"
1206
1208
1207 self.basicHeaderObj = BasicHeader()
1209 self.basicHeaderObj = BasicHeader(LOCALTIME)
1208
1210
1209 self.systemHeaderObj = SystemHeader()
1211 self.systemHeaderObj = SystemHeader()
1210
1212
1211 self.radarControllerHeaderObj = RadarControllerHeader()
1213 self.radarControllerHeaderObj = RadarControllerHeader()
1212
1214
1213 self.processingHeaderObj = ProcessingHeader()
1215 self.processingHeaderObj = ProcessingHeader()
1214
1216
1215 self.online = 0
1217 self.online = 0
1216
1218
1217 self.fp = None
1219 self.fp = None
1218
1220
1219 self.idFile = None
1221 self.idFile = None
1220
1222
1221 self.dtype = None
1223 self.dtype = None
1222
1224
1223 self.fileSizeByHeader = None
1225 self.fileSizeByHeader = None
1224
1226
1225 self.filenameList = []
1227 self.filenameList = []
1226
1228
1227 self.filename = None
1229 self.filename = None
1228
1230
1229 self.fileSize = None
1231 self.fileSize = None
1230
1232
1231 self.firstHeaderSize = 0
1233 self.firstHeaderSize = 0
1232
1234
1233 self.basicHeaderSize = 24
1235 self.basicHeaderSize = 24
1234
1236
1235 self.pathList = []
1237 self.pathList = []
1236
1238
1237 self.filenameList = []
1239 self.filenameList = []
1238
1240
1239 self.lastUTTime = 0
1241 self.lastUTTime = 0
1240
1242
1241 self.maxTimeStep = 30
1243 self.maxTimeStep = 30
1242
1244
1243 self.flagNoMoreFiles = 0
1245 self.flagNoMoreFiles = 0
1244
1246
1245 self.set = 0
1247 self.set = 0
1246
1248
1247 self.path = None
1249 self.path = None
1248
1250
1249 self.profileIndex = 9999
1251 self.profileIndex = 9999
1250
1252
1251 self.delay = 3 #seconds
1253 self.delay = 3 #seconds
1252
1254
1253 self.nTries = 3 #quantity tries
1255 self.nTries = 3 #quantity tries
1254
1256
1255 self.nFiles = 3 #number of files for searching
1257 self.nFiles = 3 #number of files for searching
1256
1258
1257 self.nReadBlocks = 0
1259 self.nReadBlocks = 0
1258
1260
1259 self.flagIsNewFile = 1
1261 self.flagIsNewFile = 1
1260
1262
1261 self.ippSeconds = 0
1263 self.ippSeconds = 0
1262
1264
1263 self.flagTimeBlock = 0
1265 self.flagTimeBlock = 0
1264
1266
1265 self.flagIsNewBlock = 0
1267 self.flagIsNewBlock = 0
1266
1268
1267 self.nTotalBlocks = 0
1269 self.nTotalBlocks = 0
1268
1270
1269 self.blocksize = 0
1271 self.blocksize = 0
1270
1272
1271 self.dataOut = self.createObjByDefault()
1273 self.dataOut = self.createObjByDefault()
1272
1274
1273 def createObjByDefault(self):
1275 def createObjByDefault(self):
1274
1276
1275 dataObj = Voltage()
1277 dataObj = Voltage()
1276
1278
1277 return dataObj
1279 return dataObj
1278
1280
1279 def __hasNotDataInBuffer(self):
1281 def __hasNotDataInBuffer(self):
1280 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1282 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1281 return 1
1283 return 1
1282 return 0
1284 return 0
1283
1285
1284
1286
1285 def getBlockDimension(self):
1287 def getBlockDimension(self):
1286 """
1288 """
1287 Obtiene la cantidad de puntos a leer por cada bloque de datos
1289 Obtiene la cantidad de puntos a leer por cada bloque de datos
1288
1290
1289 Affected:
1291 Affected:
1290 self.blocksize
1292 self.blocksize
1291
1293
1292 Return:
1294 Return:
1293 None
1295 None
1294 """
1296 """
1295 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1297 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1296 self.blocksize = pts2read
1298 self.blocksize = pts2read
1297
1299
1298
1300
1299 def readBlock(self):
1301 def readBlock(self):
1300 """
1302 """
1301 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1303 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1302 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1304 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1303 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1305 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1304 es seteado a 0
1306 es seteado a 0
1305
1307
1306 Inputs:
1308 Inputs:
1307 None
1309 None
1308
1310
1309 Return:
1311 Return:
1310 None
1312 None
1311
1313
1312 Affected:
1314 Affected:
1313 self.profileIndex
1315 self.profileIndex
1314 self.datablock
1316 self.datablock
1315 self.flagIsNewFile
1317 self.flagIsNewFile
1316 self.flagIsNewBlock
1318 self.flagIsNewBlock
1317 self.nTotalBlocks
1319 self.nTotalBlocks
1318
1320
1319 Exceptions:
1321 Exceptions:
1320 Si un bloque leido no es un bloque valido
1322 Si un bloque leido no es un bloque valido
1321 """
1323 """
1322
1324
1323 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1325 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1324
1326
1325 try:
1327 try:
1326 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1328 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1327 except:
1329 except:
1328 print "The read block (%3d) has not enough data" %self.nReadBlocks
1330 print "The read block (%3d) has not enough data" %self.nReadBlocks
1329 return 0
1331 return 0
1330
1332
1331 junk = numpy.transpose(junk, (2,0,1))
1333 junk = numpy.transpose(junk, (2,0,1))
1332 self.datablock = junk['real'] + junk['imag']*1j
1334 self.datablock = junk['real'] + junk['imag']*1j
1333
1335
1334 self.profileIndex = 0
1336 self.profileIndex = 0
1335
1337
1336 self.flagIsNewFile = 0
1338 self.flagIsNewFile = 0
1337 self.flagIsNewBlock = 1
1339 self.flagIsNewBlock = 1
1338
1340
1339 self.nTotalBlocks += 1
1341 self.nTotalBlocks += 1
1340 self.nReadBlocks += 1
1342 self.nReadBlocks += 1
1341
1343
1342 return 1
1344 return 1
1343
1345
1344
1346
1345 def getData(self):
1347 def getData(self):
1346 """
1348 """
1347 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1349 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1348 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1350 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1349 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1351 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1350
1352
1351 Ademas incrementa el contador del buffer en 1.
1353 Ademas incrementa el contador del buffer en 1.
1352
1354
1353 Return:
1355 Return:
1354 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1356 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1355 buffer. Si no hay mas archivos a leer retorna None.
1357 buffer. Si no hay mas archivos a leer retorna None.
1356
1358
1357 Variables afectadas:
1359 Variables afectadas:
1358 self.dataOut
1360 self.dataOut
1359 self.profileIndex
1361 self.profileIndex
1360
1362
1361 Affected:
1363 Affected:
1362 self.dataOut
1364 self.dataOut
1363 self.profileIndex
1365 self.profileIndex
1364 self.flagTimeBlock
1366 self.flagTimeBlock
1365 self.flagIsNewBlock
1367 self.flagIsNewBlock
1366 """
1368 """
1367
1369
1368 if self.flagNoMoreFiles:
1370 if self.flagNoMoreFiles:
1369 self.dataOut.flagNoData = True
1371 self.dataOut.flagNoData = True
1370 print 'Process finished'
1372 print 'Process finished'
1371 return 0
1373 return 0
1372
1374
1373 self.flagTimeBlock = 0
1375 self.flagTimeBlock = 0
1374 self.flagIsNewBlock = 0
1376 self.flagIsNewBlock = 0
1375
1377
1376 if self.__hasNotDataInBuffer():
1378 if self.__hasNotDataInBuffer():
1377
1379
1378 if not( self.readNextBlock() ):
1380 if not( self.readNextBlock() ):
1379 return 0
1381 return 0
1380
1382
1381 self.dataOut.dtype = self.dtype
1383 self.dataOut.dtype = self.dtype
1382
1384
1383 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1385 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1384
1386
1385 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1387 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1386
1388
1387 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1389 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1388
1390
1389 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1391 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1390
1392
1391 self.dataOut.flagTimeBlock = self.flagTimeBlock
1393 self.dataOut.flagTimeBlock = self.flagTimeBlock
1392
1394
1393 self.dataOut.ippSeconds = self.ippSeconds
1395 self.dataOut.ippSeconds = self.ippSeconds
1394
1396
1395 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1397 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1396
1398
1397 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1399 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1398
1400
1399 self.dataOut.flagShiftFFT = False
1401 self.dataOut.flagShiftFFT = False
1400
1402
1401 if self.processingHeaderObj.code != None:
1403 if self.processingHeaderObj.code != None:
1402
1404
1403 self.dataOut.nCode = self.processingHeaderObj.nCode
1405 self.dataOut.nCode = self.processingHeaderObj.nCode
1404
1406
1405 self.dataOut.nBaud = self.processingHeaderObj.nBaud
1407 self.dataOut.nBaud = self.processingHeaderObj.nBaud
1406
1408
1407 self.dataOut.code = self.processingHeaderObj.code
1409 self.dataOut.code = self.processingHeaderObj.code
1408
1410
1409 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1411 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1410
1412
1411 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1413 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1412
1414
1413 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1415 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1414
1416
1415 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1417 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1416
1418
1417 self.dataOut.flagShiftFFT = False
1419 self.dataOut.flagShiftFFT = False
1418
1420
1419
1421
1420 # self.updateDataHeader()
1422 # self.updateDataHeader()
1421
1423
1422 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1424 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1423
1425
1424 if self.datablock == None:
1426 if self.datablock == None:
1425 self.dataOut.flagNoData = True
1427 self.dataOut.flagNoData = True
1426 return 0
1428 return 0
1427
1429
1428 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1430 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1429
1431
1430 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
1432 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
1431
1433
1432 self.profileIndex += 1
1434 self.profileIndex += 1
1433
1435
1434 self.dataOut.flagNoData = False
1436 self.dataOut.flagNoData = False
1435
1437
1436 # print self.profileIndex, self.dataOut.utctime
1438 # print self.profileIndex, self.dataOut.utctime
1437 # if self.profileIndex == 800:
1439 # if self.profileIndex == 800:
1438 # a=1
1440 # a=1
1439
1441
1440
1442
1441 return self.dataOut.data
1443 return self.dataOut.data
1442
1444
1443
1445
1444 class VoltageWriter(JRODataWriter):
1446 class VoltageWriter(JRODataWriter):
1445 """
1447 """
1446 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1448 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1447 de los datos siempre se realiza por bloques.
1449 de los datos siempre se realiza por bloques.
1448 """
1450 """
1449
1451
1450 ext = ".r"
1452 ext = ".r"
1451
1453
1452 optchar = "D"
1454 optchar = "D"
1453
1455
1454 shapeBuffer = None
1456 shapeBuffer = None
1455
1457
1456
1458
1457 def __init__(self):
1459 def __init__(self):
1458 """
1460 """
1459 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1461 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1460
1462
1461 Affected:
1463 Affected:
1462 self.dataOut
1464 self.dataOut
1463
1465
1464 Return: None
1466 Return: None
1465 """
1467 """
1466
1468
1467 self.nTotalBlocks = 0
1469 self.nTotalBlocks = 0
1468
1470
1469 self.profileIndex = 0
1471 self.profileIndex = 0
1470
1472
1471 self.isConfig = False
1473 self.isConfig = False
1472
1474
1473 self.fp = None
1475 self.fp = None
1474
1476
1475 self.flagIsNewFile = 1
1477 self.flagIsNewFile = 1
1476
1478
1477 self.nTotalBlocks = 0
1479 self.nTotalBlocks = 0
1478
1480
1479 self.flagIsNewBlock = 0
1481 self.flagIsNewBlock = 0
1480
1482
1481 self.setFile = None
1483 self.setFile = None
1482
1484
1483 self.dtype = None
1485 self.dtype = None
1484
1486
1485 self.path = None
1487 self.path = None
1486
1488
1487 self.filename = None
1489 self.filename = None
1488
1490
1489 self.basicHeaderObj = BasicHeader()
1491 self.basicHeaderObj = BasicHeader(LOCALTIME)
1490
1492
1491 self.systemHeaderObj = SystemHeader()
1493 self.systemHeaderObj = SystemHeader()
1492
1494
1493 self.radarControllerHeaderObj = RadarControllerHeader()
1495 self.radarControllerHeaderObj = RadarControllerHeader()
1494
1496
1495 self.processingHeaderObj = ProcessingHeader()
1497 self.processingHeaderObj = ProcessingHeader()
1496
1498
1497 def hasAllDataInBuffer(self):
1499 def hasAllDataInBuffer(self):
1498 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1500 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1499 return 1
1501 return 1
1500 return 0
1502 return 0
1501
1503
1502
1504
1503 def setBlockDimension(self):
1505 def setBlockDimension(self):
1504 """
1506 """
1505 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1507 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1506
1508
1507 Affected:
1509 Affected:
1508 self.shape_spc_Buffer
1510 self.shape_spc_Buffer
1509 self.shape_cspc_Buffer
1511 self.shape_cspc_Buffer
1510 self.shape_dc_Buffer
1512 self.shape_dc_Buffer
1511
1513
1512 Return: None
1514 Return: None
1513 """
1515 """
1514 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1516 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1515 self.processingHeaderObj.nHeights,
1517 self.processingHeaderObj.nHeights,
1516 self.systemHeaderObj.nChannels)
1518 self.systemHeaderObj.nChannels)
1517
1519
1518 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1520 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1519 self.processingHeaderObj.profilesPerBlock,
1521 self.processingHeaderObj.profilesPerBlock,
1520 self.processingHeaderObj.nHeights),
1522 self.processingHeaderObj.nHeights),
1521 dtype=numpy.dtype('complex'))
1523 dtype=numpy.dtype('complex'))
1522
1524
1523
1525
1524 def writeBlock(self):
1526 def writeBlock(self):
1525 """
1527 """
1526 Escribe el buffer en el file designado
1528 Escribe el buffer en el file designado
1527
1529
1528 Affected:
1530 Affected:
1529 self.profileIndex
1531 self.profileIndex
1530 self.flagIsNewFile
1532 self.flagIsNewFile
1531 self.flagIsNewBlock
1533 self.flagIsNewBlock
1532 self.nTotalBlocks
1534 self.nTotalBlocks
1533 self.blockIndex
1535 self.blockIndex
1534
1536
1535 Return: None
1537 Return: None
1536 """
1538 """
1537 data = numpy.zeros( self.shapeBuffer, self.dtype )
1539 data = numpy.zeros( self.shapeBuffer, self.dtype )
1538
1540
1539 junk = numpy.transpose(self.datablock, (1,2,0))
1541 junk = numpy.transpose(self.datablock, (1,2,0))
1540
1542
1541 data['real'] = junk.real
1543 data['real'] = junk.real
1542 data['imag'] = junk.imag
1544 data['imag'] = junk.imag
1543
1545
1544 data = data.reshape( (-1) )
1546 data = data.reshape( (-1) )
1545
1547
1546 data.tofile( self.fp )
1548 data.tofile( self.fp )
1547
1549
1548 self.datablock.fill(0)
1550 self.datablock.fill(0)
1549
1551
1550 self.profileIndex = 0
1552 self.profileIndex = 0
1551 self.flagIsNewFile = 0
1553 self.flagIsNewFile = 0
1552 self.flagIsNewBlock = 1
1554 self.flagIsNewBlock = 1
1553
1555
1554 self.blockIndex += 1
1556 self.blockIndex += 1
1555 self.nTotalBlocks += 1
1557 self.nTotalBlocks += 1
1556
1558
1557 def putData(self):
1559 def putData(self):
1558 """
1560 """
1559 Setea un bloque de datos y luego los escribe en un file
1561 Setea un bloque de datos y luego los escribe en un file
1560
1562
1561 Affected:
1563 Affected:
1562 self.flagIsNewBlock
1564 self.flagIsNewBlock
1563 self.profileIndex
1565 self.profileIndex
1564
1566
1565 Return:
1567 Return:
1566 0 : Si no hay data o no hay mas files que puedan escribirse
1568 0 : Si no hay data o no hay mas files que puedan escribirse
1567 1 : Si se escribio la data de un bloque en un file
1569 1 : Si se escribio la data de un bloque en un file
1568 """
1570 """
1569 if self.dataOut.flagNoData:
1571 if self.dataOut.flagNoData:
1570 return 0
1572 return 0
1571
1573
1572 self.flagIsNewBlock = 0
1574 self.flagIsNewBlock = 0
1573
1575
1574 if self.dataOut.flagTimeBlock:
1576 if self.dataOut.flagTimeBlock:
1575
1577
1576 self.datablock.fill(0)
1578 self.datablock.fill(0)
1577 self.profileIndex = 0
1579 self.profileIndex = 0
1578 self.setNextFile()
1580 self.setNextFile()
1579
1581
1580 if self.profileIndex == 0:
1582 if self.profileIndex == 0:
1581 self.getBasicHeader()
1583 self.getBasicHeader()
1582
1584
1583 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1585 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1584
1586
1585 self.profileIndex += 1
1587 self.profileIndex += 1
1586
1588
1587 if self.hasAllDataInBuffer():
1589 if self.hasAllDataInBuffer():
1588 #if self.flagIsNewFile:
1590 #if self.flagIsNewFile:
1589 self.writeNextBlock()
1591 self.writeNextBlock()
1590 # self.getDataHeader()
1592 # self.getDataHeader()
1591
1593
1592 return 1
1594 return 1
1593
1595
1594 def __getProcessFlags(self):
1596 def __getProcessFlags(self):
1595
1597
1596 processFlags = 0
1598 processFlags = 0
1597
1599
1598 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1600 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1599 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1601 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1600 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1602 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1601 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1603 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1602 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1604 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1603 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1605 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1604
1606
1605 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1607 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1606
1608
1607
1609
1608
1610
1609 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1611 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1610 PROCFLAG.DATATYPE_SHORT,
1612 PROCFLAG.DATATYPE_SHORT,
1611 PROCFLAG.DATATYPE_LONG,
1613 PROCFLAG.DATATYPE_LONG,
1612 PROCFLAG.DATATYPE_INT64,
1614 PROCFLAG.DATATYPE_INT64,
1613 PROCFLAG.DATATYPE_FLOAT,
1615 PROCFLAG.DATATYPE_FLOAT,
1614 PROCFLAG.DATATYPE_DOUBLE]
1616 PROCFLAG.DATATYPE_DOUBLE]
1615
1617
1616
1618
1617 for index in range(len(dtypeList)):
1619 for index in range(len(dtypeList)):
1618 if self.dataOut.dtype == dtypeList[index]:
1620 if self.dataOut.dtype == dtypeList[index]:
1619 dtypeValue = datatypeValueList[index]
1621 dtypeValue = datatypeValueList[index]
1620 break
1622 break
1621
1623
1622 processFlags += dtypeValue
1624 processFlags += dtypeValue
1623
1625
1624 if self.dataOut.flagDecodeData:
1626 if self.dataOut.flagDecodeData:
1625 processFlags += PROCFLAG.DECODE_DATA
1627 processFlags += PROCFLAG.DECODE_DATA
1626
1628
1627 if self.dataOut.flagDeflipData:
1629 if self.dataOut.flagDeflipData:
1628 processFlags += PROCFLAG.DEFLIP_DATA
1630 processFlags += PROCFLAG.DEFLIP_DATA
1629
1631
1630 if self.dataOut.code != None:
1632 if self.dataOut.code != None:
1631 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1633 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1632
1634
1633 if self.dataOut.nCohInt > 1:
1635 if self.dataOut.nCohInt > 1:
1634 processFlags += PROCFLAG.COHERENT_INTEGRATION
1636 processFlags += PROCFLAG.COHERENT_INTEGRATION
1635
1637
1636 return processFlags
1638 return processFlags
1637
1639
1638
1640
1639 def __getBlockSize(self):
1641 def __getBlockSize(self):
1640 '''
1642 '''
1641 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1643 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1642 '''
1644 '''
1643
1645
1644 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1646 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1645 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1647 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1646 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1648 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1647 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1649 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1648 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1650 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1649 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1651 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1650
1652
1651 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1653 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1652 datatypeValueList = [1,2,4,8,4,8]
1654 datatypeValueList = [1,2,4,8,4,8]
1653 for index in range(len(dtypeList)):
1655 for index in range(len(dtypeList)):
1654 if self.dataOut.dtype == dtypeList[index]:
1656 if self.dataOut.dtype == dtypeList[index]:
1655 datatypeValue = datatypeValueList[index]
1657 datatypeValue = datatypeValueList[index]
1656 break
1658 break
1657
1659
1658 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1660 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1659
1661
1660 return blocksize
1662 return blocksize
1661
1663
1662 def getDataHeader(self):
1664 def getDataHeader(self):
1663
1665
1664 """
1666 """
1665 Obtiene una copia del First Header
1667 Obtiene una copia del First Header
1666
1668
1667 Affected:
1669 Affected:
1668 self.systemHeaderObj
1670 self.systemHeaderObj
1669 self.radarControllerHeaderObj
1671 self.radarControllerHeaderObj
1670 self.dtype
1672 self.dtype
1671
1673
1672 Return:
1674 Return:
1673 None
1675 None
1674 """
1676 """
1675
1677
1676 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1678 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1677 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1679 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1678 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1680 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1679
1681
1680 self.getBasicHeader()
1682 self.getBasicHeader()
1681
1683
1682 processingHeaderSize = 40 # bytes
1684 processingHeaderSize = 40 # bytes
1683 self.processingHeaderObj.dtype = 0 # Voltage
1685 self.processingHeaderObj.dtype = 0 # Voltage
1684 self.processingHeaderObj.blockSize = self.__getBlockSize()
1686 self.processingHeaderObj.blockSize = self.__getBlockSize()
1685 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1687 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1686 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1688 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1687 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1689 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1688 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1690 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1689 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1691 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1690 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1692 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1691 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1693 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1692
1694
1693 if self.dataOut.code != None:
1695 if self.dataOut.code != None:
1694 self.processingHeaderObj.code = self.dataOut.code
1696 self.processingHeaderObj.code = self.dataOut.code
1695 self.processingHeaderObj.nCode = self.dataOut.nCode
1697 self.processingHeaderObj.nCode = self.dataOut.nCode
1696 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1698 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1697 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1699 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1698 processingHeaderSize += codesize
1700 processingHeaderSize += codesize
1699
1701
1700 if self.processingHeaderObj.nWindows != 0:
1702 if self.processingHeaderObj.nWindows != 0:
1701 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1703 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1702 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1704 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1703 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1705 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1704 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1706 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1705 processingHeaderSize += 12
1707 processingHeaderSize += 12
1706
1708
1707 self.processingHeaderObj.size = processingHeaderSize
1709 self.processingHeaderObj.size = processingHeaderSize
1708
1710
1709 class SpectraReader(JRODataReader):
1711 class SpectraReader(JRODataReader):
1710 """
1712 """
1711 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1713 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1712 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1714 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1713 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1715 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1714
1716
1715 paresCanalesIguales * alturas * perfiles (Self Spectra)
1717 paresCanalesIguales * alturas * perfiles (Self Spectra)
1716 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1718 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1717 canales * alturas (DC Channels)
1719 canales * alturas (DC Channels)
1718
1720
1719 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1721 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1720 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1722 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1721 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1723 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1722 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1724 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1723
1725
1724 Example:
1726 Example:
1725 dpath = "/home/myuser/data"
1727 dpath = "/home/myuser/data"
1726
1728
1727 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1729 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1728
1730
1729 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1731 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1730
1732
1731 readerObj = SpectraReader()
1733 readerObj = SpectraReader()
1732
1734
1733 readerObj.setup(dpath, startTime, endTime)
1735 readerObj.setup(dpath, startTime, endTime)
1734
1736
1735 while(True):
1737 while(True):
1736
1738
1737 readerObj.getData()
1739 readerObj.getData()
1738
1740
1739 print readerObj.data_spc
1741 print readerObj.data_spc
1740
1742
1741 print readerObj.data_cspc
1743 print readerObj.data_cspc
1742
1744
1743 print readerObj.data_dc
1745 print readerObj.data_dc
1744
1746
1745 if readerObj.flagNoMoreFiles:
1747 if readerObj.flagNoMoreFiles:
1746 break
1748 break
1747
1749
1748 """
1750 """
1749
1751
1750 pts2read_SelfSpectra = 0
1752 pts2read_SelfSpectra = 0
1751
1753
1752 pts2read_CrossSpectra = 0
1754 pts2read_CrossSpectra = 0
1753
1755
1754 pts2read_DCchannels = 0
1756 pts2read_DCchannels = 0
1755
1757
1756 ext = ".pdata"
1758 ext = ".pdata"
1757
1759
1758 optchar = "P"
1760 optchar = "P"
1759
1761
1760 dataOut = None
1762 dataOut = None
1761
1763
1762 nRdChannels = None
1764 nRdChannels = None
1763
1765
1764 nRdPairs = None
1766 nRdPairs = None
1765
1767
1766 rdPairList = []
1768 rdPairList = []
1767
1769
1768
1770
1769 def __init__(self):
1771 def __init__(self):
1770 """
1772 """
1771 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1773 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1772
1774
1773 Inputs:
1775 Inputs:
1774 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1776 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1775 almacenar un perfil de datos cada vez que se haga un requerimiento
1777 almacenar un perfil de datos cada vez que se haga un requerimiento
1776 (getData). El perfil sera obtenido a partir del buffer de datos,
1778 (getData). El perfil sera obtenido a partir del buffer de datos,
1777 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1779 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1778 bloque de datos.
1780 bloque de datos.
1779 Si este parametro no es pasado se creara uno internamente.
1781 Si este parametro no es pasado se creara uno internamente.
1780
1782
1781 Affected:
1783 Affected:
1782 self.dataOut
1784 self.dataOut
1783
1785
1784 Return : None
1786 Return : None
1785 """
1787 """
1786
1788
1787 self.isConfig = False
1789 self.isConfig = False
1788
1790
1789 self.pts2read_SelfSpectra = 0
1791 self.pts2read_SelfSpectra = 0
1790
1792
1791 self.pts2read_CrossSpectra = 0
1793 self.pts2read_CrossSpectra = 0
1792
1794
1793 self.pts2read_DCchannels = 0
1795 self.pts2read_DCchannels = 0
1794
1796
1795 self.datablock = None
1797 self.datablock = None
1796
1798
1797 self.utc = None
1799 self.utc = None
1798
1800
1799 self.ext = ".pdata"
1801 self.ext = ".pdata"
1800
1802
1801 self.optchar = "P"
1803 self.optchar = "P"
1802
1804
1803 self.basicHeaderObj = BasicHeader()
1805 self.basicHeaderObj = BasicHeader(LOCALTIME)
1804
1806
1805 self.systemHeaderObj = SystemHeader()
1807 self.systemHeaderObj = SystemHeader()
1806
1808
1807 self.radarControllerHeaderObj = RadarControllerHeader()
1809 self.radarControllerHeaderObj = RadarControllerHeader()
1808
1810
1809 self.processingHeaderObj = ProcessingHeader()
1811 self.processingHeaderObj = ProcessingHeader()
1810
1812
1811 self.online = 0
1813 self.online = 0
1812
1814
1813 self.fp = None
1815 self.fp = None
1814
1816
1815 self.idFile = None
1817 self.idFile = None
1816
1818
1817 self.dtype = None
1819 self.dtype = None
1818
1820
1819 self.fileSizeByHeader = None
1821 self.fileSizeByHeader = None
1820
1822
1821 self.filenameList = []
1823 self.filenameList = []
1822
1824
1823 self.filename = None
1825 self.filename = None
1824
1826
1825 self.fileSize = None
1827 self.fileSize = None
1826
1828
1827 self.firstHeaderSize = 0
1829 self.firstHeaderSize = 0
1828
1830
1829 self.basicHeaderSize = 24
1831 self.basicHeaderSize = 24
1830
1832
1831 self.pathList = []
1833 self.pathList = []
1832
1834
1833 self.lastUTTime = 0
1835 self.lastUTTime = 0
1834
1836
1835 self.maxTimeStep = 30
1837 self.maxTimeStep = 30
1836
1838
1837 self.flagNoMoreFiles = 0
1839 self.flagNoMoreFiles = 0
1838
1840
1839 self.set = 0
1841 self.set = 0
1840
1842
1841 self.path = None
1843 self.path = None
1842
1844
1843 self.delay = 3 #seconds
1845 self.delay = 3 #seconds
1844
1846
1845 self.nTries = 3 #quantity tries
1847 self.nTries = 3 #quantity tries
1846
1848
1847 self.nFiles = 3 #number of files for searching
1849 self.nFiles = 3 #number of files for searching
1848
1850
1849 self.nReadBlocks = 0
1851 self.nReadBlocks = 0
1850
1852
1851 self.flagIsNewFile = 1
1853 self.flagIsNewFile = 1
1852
1854
1853 self.ippSeconds = 0
1855 self.ippSeconds = 0
1854
1856
1855 self.flagTimeBlock = 0
1857 self.flagTimeBlock = 0
1856
1858
1857 self.flagIsNewBlock = 0
1859 self.flagIsNewBlock = 0
1858
1860
1859 self.nTotalBlocks = 0
1861 self.nTotalBlocks = 0
1860
1862
1861 self.blocksize = 0
1863 self.blocksize = 0
1862
1864
1863 self.dataOut = self.createObjByDefault()
1865 self.dataOut = self.createObjByDefault()
1864
1866
1865
1867
1866 def createObjByDefault(self):
1868 def createObjByDefault(self):
1867
1869
1868 dataObj = Spectra()
1870 dataObj = Spectra()
1869
1871
1870 return dataObj
1872 return dataObj
1871
1873
1872 def __hasNotDataInBuffer(self):
1874 def __hasNotDataInBuffer(self):
1873 return 1
1875 return 1
1874
1876
1875
1877
1876 def getBlockDimension(self):
1878 def getBlockDimension(self):
1877 """
1879 """
1878 Obtiene la cantidad de puntos a leer por cada bloque de datos
1880 Obtiene la cantidad de puntos a leer por cada bloque de datos
1879
1881
1880 Affected:
1882 Affected:
1881 self.nRdChannels
1883 self.nRdChannels
1882 self.nRdPairs
1884 self.nRdPairs
1883 self.pts2read_SelfSpectra
1885 self.pts2read_SelfSpectra
1884 self.pts2read_CrossSpectra
1886 self.pts2read_CrossSpectra
1885 self.pts2read_DCchannels
1887 self.pts2read_DCchannels
1886 self.blocksize
1888 self.blocksize
1887 self.dataOut.nChannels
1889 self.dataOut.nChannels
1888 self.dataOut.nPairs
1890 self.dataOut.nPairs
1889
1891
1890 Return:
1892 Return:
1891 None
1893 None
1892 """
1894 """
1893 self.nRdChannels = 0
1895 self.nRdChannels = 0
1894 self.nRdPairs = 0
1896 self.nRdPairs = 0
1895 self.rdPairList = []
1897 self.rdPairList = []
1896
1898
1897 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
1899 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
1898 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
1900 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
1899 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
1901 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
1900 else:
1902 else:
1901 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
1903 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
1902 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
1904 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
1903
1905
1904 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
1906 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
1905
1907
1906 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
1908 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
1907 self.blocksize = self.pts2read_SelfSpectra
1909 self.blocksize = self.pts2read_SelfSpectra
1908
1910
1909 if self.processingHeaderObj.flag_cspc:
1911 if self.processingHeaderObj.flag_cspc:
1910 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
1912 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
1911 self.blocksize += self.pts2read_CrossSpectra
1913 self.blocksize += self.pts2read_CrossSpectra
1912
1914
1913 if self.processingHeaderObj.flag_dc:
1915 if self.processingHeaderObj.flag_dc:
1914 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
1916 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
1915 self.blocksize += self.pts2read_DCchannels
1917 self.blocksize += self.pts2read_DCchannels
1916
1918
1917 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
1919 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
1918
1920
1919
1921
1920 def readBlock(self):
1922 def readBlock(self):
1921 """
1923 """
1922 Lee el bloque de datos desde la posicion actual del puntero del archivo
1924 Lee el bloque de datos desde la posicion actual del puntero del archivo
1923 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1925 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1924 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1926 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1925 es seteado a 0
1927 es seteado a 0
1926
1928
1927 Return: None
1929 Return: None
1928
1930
1929 Variables afectadas:
1931 Variables afectadas:
1930
1932
1931 self.flagIsNewFile
1933 self.flagIsNewFile
1932 self.flagIsNewBlock
1934 self.flagIsNewBlock
1933 self.nTotalBlocks
1935 self.nTotalBlocks
1934 self.data_spc
1936 self.data_spc
1935 self.data_cspc
1937 self.data_cspc
1936 self.data_dc
1938 self.data_dc
1937
1939
1938 Exceptions:
1940 Exceptions:
1939 Si un bloque leido no es un bloque valido
1941 Si un bloque leido no es un bloque valido
1940 """
1942 """
1941 blockOk_flag = False
1943 blockOk_flag = False
1942 fpointer = self.fp.tell()
1944 fpointer = self.fp.tell()
1943
1945
1944 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
1946 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
1945 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1947 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1946
1948
1947 if self.processingHeaderObj.flag_cspc:
1949 if self.processingHeaderObj.flag_cspc:
1948 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
1950 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
1949 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1951 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1950
1952
1951 if self.processingHeaderObj.flag_dc:
1953 if self.processingHeaderObj.flag_dc:
1952 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
1954 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
1953 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
1955 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
1954
1956
1955
1957
1956 if not(self.processingHeaderObj.shif_fft):
1958 if not(self.processingHeaderObj.shif_fft):
1957 #desplaza a la derecha en el eje 2 determinadas posiciones
1959 #desplaza a la derecha en el eje 2 determinadas posiciones
1958 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1960 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1959 spc = numpy.roll( spc, shift , axis=2 )
1961 spc = numpy.roll( spc, shift , axis=2 )
1960
1962
1961 if self.processingHeaderObj.flag_cspc:
1963 if self.processingHeaderObj.flag_cspc:
1962 #desplaza a la derecha en el eje 2 determinadas posiciones
1964 #desplaza a la derecha en el eje 2 determinadas posiciones
1963 cspc = numpy.roll( cspc, shift, axis=2 )
1965 cspc = numpy.roll( cspc, shift, axis=2 )
1964
1966
1965
1967
1966 spc = numpy.transpose( spc, (0,2,1) )
1968 spc = numpy.transpose( spc, (0,2,1) )
1967 self.data_spc = spc
1969 self.data_spc = spc
1968
1970
1969 if self.processingHeaderObj.flag_cspc:
1971 if self.processingHeaderObj.flag_cspc:
1970 cspc = numpy.transpose( cspc, (0,2,1) )
1972 cspc = numpy.transpose( cspc, (0,2,1) )
1971 self.data_cspc = cspc['real'] + cspc['imag']*1j
1973 self.data_cspc = cspc['real'] + cspc['imag']*1j
1972 else:
1974 else:
1973 self.data_cspc = None
1975 self.data_cspc = None
1974
1976
1975 if self.processingHeaderObj.flag_dc:
1977 if self.processingHeaderObj.flag_dc:
1976 self.data_dc = dc['real'] + dc['imag']*1j
1978 self.data_dc = dc['real'] + dc['imag']*1j
1977 else:
1979 else:
1978 self.data_dc = None
1980 self.data_dc = None
1979
1981
1980 self.flagIsNewFile = 0
1982 self.flagIsNewFile = 0
1981 self.flagIsNewBlock = 1
1983 self.flagIsNewBlock = 1
1982
1984
1983 self.nTotalBlocks += 1
1985 self.nTotalBlocks += 1
1984 self.nReadBlocks += 1
1986 self.nReadBlocks += 1
1985
1987
1986 return 1
1988 return 1
1987
1989
1988
1990
1989 def getData(self):
1991 def getData(self):
1990 """
1992 """
1991 Copia el buffer de lectura a la clase "Spectra",
1993 Copia el buffer de lectura a la clase "Spectra",
1992 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1994 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1993 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1995 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1994
1996
1995 Return:
1997 Return:
1996 0 : Si no hay mas archivos disponibles
1998 0 : Si no hay mas archivos disponibles
1997 1 : Si hizo una buena copia del buffer
1999 1 : Si hizo una buena copia del buffer
1998
2000
1999 Affected:
2001 Affected:
2000 self.dataOut
2002 self.dataOut
2001
2003
2002 self.flagTimeBlock
2004 self.flagTimeBlock
2003 self.flagIsNewBlock
2005 self.flagIsNewBlock
2004 """
2006 """
2005
2007
2006 if self.flagNoMoreFiles:
2008 if self.flagNoMoreFiles:
2007 self.dataOut.flagNoData = True
2009 self.dataOut.flagNoData = True
2008 print 'Process finished'
2010 print 'Process finished'
2009 return 0
2011 return 0
2010
2012
2011 self.flagTimeBlock = 0
2013 self.flagTimeBlock = 0
2012 self.flagIsNewBlock = 0
2014 self.flagIsNewBlock = 0
2013
2015
2014 if self.__hasNotDataInBuffer():
2016 if self.__hasNotDataInBuffer():
2015
2017
2016 if not( self.readNextBlock() ):
2018 if not( self.readNextBlock() ):
2017 self.dataOut.flagNoData = True
2019 self.dataOut.flagNoData = True
2018 return 0
2020 return 0
2019
2021
2020 # self.updateDataHeader()
2022 # self.updateDataHeader()
2021
2023
2022 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2024 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2023
2025
2024 if self.data_dc == None:
2026 if self.data_dc == None:
2025 self.dataOut.flagNoData = True
2027 self.dataOut.flagNoData = True
2026 return 0
2028 return 0
2027
2029
2028 self.dataOut.data_spc = self.data_spc
2030 self.dataOut.data_spc = self.data_spc
2029
2031
2030 self.dataOut.data_cspc = self.data_cspc
2032 self.dataOut.data_cspc = self.data_cspc
2031
2033
2032 self.dataOut.data_dc = self.data_dc
2034 self.dataOut.data_dc = self.data_dc
2033
2035
2034 self.dataOut.flagTimeBlock = self.flagTimeBlock
2036 self.dataOut.flagTimeBlock = self.flagTimeBlock
2035
2037
2036 self.dataOut.flagNoData = False
2038 self.dataOut.flagNoData = False
2037
2039
2038 self.dataOut.dtype = self.dtype
2040 self.dataOut.dtype = self.dtype
2039
2041
2040 # self.dataOut.nChannels = self.nRdChannels
2042 # self.dataOut.nChannels = self.nRdChannels
2041
2043
2042 self.dataOut.nPairs = self.nRdPairs
2044 self.dataOut.nPairs = self.nRdPairs
2043
2045
2044 self.dataOut.pairsList = self.rdPairList
2046 self.dataOut.pairsList = self.rdPairList
2045
2047
2046 # self.dataOut.nHeights = self.processingHeaderObj.nHeights
2048 # self.dataOut.nHeights = self.processingHeaderObj.nHeights
2047
2049
2048 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2050 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2049
2051
2050 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2052 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2051
2053
2052 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2054 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2053
2055
2054 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2056 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2055
2057
2056 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2058 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2057
2059
2058 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2060 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2059
2061
2060 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2062 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2061
2063
2062 # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels)
2064 # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels)
2063
2065
2064 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
2066 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
2065
2067
2066 self.dataOut.ippSeconds = self.ippSeconds
2068 self.dataOut.ippSeconds = self.ippSeconds
2067
2069
2068 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2070 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2069
2071
2070 # self.profileIndex += 1
2072 # self.profileIndex += 1
2071
2073
2072 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2074 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2073
2075
2074 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2076 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2075
2077
2076 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2078 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2077
2079
2078 self.dataOut.flagDecodeData = True #asumo q la data no esta decodificada
2080 self.dataOut.flagDecodeData = True #asumo q la data no esta decodificada
2079
2081
2080 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2082 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2081
2083
2082
2084
2083 return self.dataOut.data_spc
2085 return self.dataOut.data_spc
2084
2086
2085
2087
2086 class SpectraWriter(JRODataWriter):
2088 class SpectraWriter(JRODataWriter):
2087
2089
2088 """
2090 """
2089 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2091 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2090 de los datos siempre se realiza por bloques.
2092 de los datos siempre se realiza por bloques.
2091 """
2093 """
2092
2094
2093 ext = ".pdata"
2095 ext = ".pdata"
2094
2096
2095 optchar = "P"
2097 optchar = "P"
2096
2098
2097 shape_spc_Buffer = None
2099 shape_spc_Buffer = None
2098
2100
2099 shape_cspc_Buffer = None
2101 shape_cspc_Buffer = None
2100
2102
2101 shape_dc_Buffer = None
2103 shape_dc_Buffer = None
2102
2104
2103 data_spc = None
2105 data_spc = None
2104
2106
2105 data_cspc = None
2107 data_cspc = None
2106
2108
2107 data_dc = None
2109 data_dc = None
2108
2110
2109 # dataOut = None
2111 # dataOut = None
2110
2112
2111 def __init__(self):
2113 def __init__(self):
2112 """
2114 """
2113 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2115 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2114
2116
2115 Affected:
2117 Affected:
2116 self.dataOut
2118 self.dataOut
2117 self.basicHeaderObj
2119 self.basicHeaderObj
2118 self.systemHeaderObj
2120 self.systemHeaderObj
2119 self.radarControllerHeaderObj
2121 self.radarControllerHeaderObj
2120 self.processingHeaderObj
2122 self.processingHeaderObj
2121
2123
2122 Return: None
2124 Return: None
2123 """
2125 """
2124
2126
2125 self.isConfig = False
2127 self.isConfig = False
2126
2128
2127 self.nTotalBlocks = 0
2129 self.nTotalBlocks = 0
2128
2130
2129 self.data_spc = None
2131 self.data_spc = None
2130
2132
2131 self.data_cspc = None
2133 self.data_cspc = None
2132
2134
2133 self.data_dc = None
2135 self.data_dc = None
2134
2136
2135 self.fp = None
2137 self.fp = None
2136
2138
2137 self.flagIsNewFile = 1
2139 self.flagIsNewFile = 1
2138
2140
2139 self.nTotalBlocks = 0
2141 self.nTotalBlocks = 0
2140
2142
2141 self.flagIsNewBlock = 0
2143 self.flagIsNewBlock = 0
2142
2144
2143 self.setFile = None
2145 self.setFile = None
2144
2146
2145 self.dtype = None
2147 self.dtype = None
2146
2148
2147 self.path = None
2149 self.path = None
2148
2150
2149 self.noMoreFiles = 0
2151 self.noMoreFiles = 0
2150
2152
2151 self.filename = None
2153 self.filename = None
2152
2154
2153 self.basicHeaderObj = BasicHeader()
2155 self.basicHeaderObj = BasicHeader(LOCALTIME)
2154
2156
2155 self.systemHeaderObj = SystemHeader()
2157 self.systemHeaderObj = SystemHeader()
2156
2158
2157 self.radarControllerHeaderObj = RadarControllerHeader()
2159 self.radarControllerHeaderObj = RadarControllerHeader()
2158
2160
2159 self.processingHeaderObj = ProcessingHeader()
2161 self.processingHeaderObj = ProcessingHeader()
2160
2162
2161
2163
2162 def hasAllDataInBuffer(self):
2164 def hasAllDataInBuffer(self):
2163 return 1
2165 return 1
2164
2166
2165
2167
2166 def setBlockDimension(self):
2168 def setBlockDimension(self):
2167 """
2169 """
2168 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2170 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2169
2171
2170 Affected:
2172 Affected:
2171 self.shape_spc_Buffer
2173 self.shape_spc_Buffer
2172 self.shape_cspc_Buffer
2174 self.shape_cspc_Buffer
2173 self.shape_dc_Buffer
2175 self.shape_dc_Buffer
2174
2176
2175 Return: None
2177 Return: None
2176 """
2178 """
2177 self.shape_spc_Buffer = (self.dataOut.nChannels,
2179 self.shape_spc_Buffer = (self.dataOut.nChannels,
2178 self.processingHeaderObj.nHeights,
2180 self.processingHeaderObj.nHeights,
2179 self.processingHeaderObj.profilesPerBlock)
2181 self.processingHeaderObj.profilesPerBlock)
2180
2182
2181 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2183 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2182 self.processingHeaderObj.nHeights,
2184 self.processingHeaderObj.nHeights,
2183 self.processingHeaderObj.profilesPerBlock)
2185 self.processingHeaderObj.profilesPerBlock)
2184
2186
2185 self.shape_dc_Buffer = (self.dataOut.nChannels,
2187 self.shape_dc_Buffer = (self.dataOut.nChannels,
2186 self.processingHeaderObj.nHeights)
2188 self.processingHeaderObj.nHeights)
2187
2189
2188
2190
2189 def writeBlock(self):
2191 def writeBlock(self):
2190 """
2192 """
2191 Escribe el buffer en el file designado
2193 Escribe el buffer en el file designado
2192
2194
2193 Affected:
2195 Affected:
2194 self.data_spc
2196 self.data_spc
2195 self.data_cspc
2197 self.data_cspc
2196 self.data_dc
2198 self.data_dc
2197 self.flagIsNewFile
2199 self.flagIsNewFile
2198 self.flagIsNewBlock
2200 self.flagIsNewBlock
2199 self.nTotalBlocks
2201 self.nTotalBlocks
2200 self.nWriteBlocks
2202 self.nWriteBlocks
2201
2203
2202 Return: None
2204 Return: None
2203 """
2205 """
2204
2206
2205 spc = numpy.transpose( self.data_spc, (0,2,1) )
2207 spc = numpy.transpose( self.data_spc, (0,2,1) )
2206 if not( self.processingHeaderObj.shif_fft ):
2208 if not( self.processingHeaderObj.shif_fft ):
2207 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2209 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2208 data = spc.reshape((-1))
2210 data = spc.reshape((-1))
2209 data.tofile(self.fp)
2211 data.tofile(self.fp)
2210
2212
2211 if self.data_cspc != None:
2213 if self.data_cspc != None:
2212 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2214 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2213 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2215 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2214 if not( self.processingHeaderObj.shif_fft ):
2216 if not( self.processingHeaderObj.shif_fft ):
2215 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2217 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2216 data['real'] = cspc.real
2218 data['real'] = cspc.real
2217 data['imag'] = cspc.imag
2219 data['imag'] = cspc.imag
2218 data = data.reshape((-1))
2220 data = data.reshape((-1))
2219 data.tofile(self.fp)
2221 data.tofile(self.fp)
2220
2222
2221 if self.data_dc != None:
2223 if self.data_dc != None:
2222 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2224 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2223 dc = self.data_dc
2225 dc = self.data_dc
2224 data['real'] = dc.real
2226 data['real'] = dc.real
2225 data['imag'] = dc.imag
2227 data['imag'] = dc.imag
2226 data = data.reshape((-1))
2228 data = data.reshape((-1))
2227 data.tofile(self.fp)
2229 data.tofile(self.fp)
2228
2230
2229 self.data_spc.fill(0)
2231 self.data_spc.fill(0)
2230 self.data_dc.fill(0)
2232 self.data_dc.fill(0)
2231 if self.data_cspc != None:
2233 if self.data_cspc != None:
2232 self.data_cspc.fill(0)
2234 self.data_cspc.fill(0)
2233
2235
2234 self.flagIsNewFile = 0
2236 self.flagIsNewFile = 0
2235 self.flagIsNewBlock = 1
2237 self.flagIsNewBlock = 1
2236 self.nTotalBlocks += 1
2238 self.nTotalBlocks += 1
2237 self.nWriteBlocks += 1
2239 self.nWriteBlocks += 1
2238 self.blockIndex += 1
2240 self.blockIndex += 1
2239
2241
2240
2242
2241 def putData(self):
2243 def putData(self):
2242 """
2244 """
2243 Setea un bloque de datos y luego los escribe en un file
2245 Setea un bloque de datos y luego los escribe en un file
2244
2246
2245 Affected:
2247 Affected:
2246 self.data_spc
2248 self.data_spc
2247 self.data_cspc
2249 self.data_cspc
2248 self.data_dc
2250 self.data_dc
2249
2251
2250 Return:
2252 Return:
2251 0 : Si no hay data o no hay mas files que puedan escribirse
2253 0 : Si no hay data o no hay mas files que puedan escribirse
2252 1 : Si se escribio la data de un bloque en un file
2254 1 : Si se escribio la data de un bloque en un file
2253 """
2255 """
2254
2256
2255 if self.dataOut.flagNoData:
2257 if self.dataOut.flagNoData:
2256 return 0
2258 return 0
2257
2259
2258 self.flagIsNewBlock = 0
2260 self.flagIsNewBlock = 0
2259
2261
2260 if self.dataOut.flagTimeBlock:
2262 if self.dataOut.flagTimeBlock:
2261 self.data_spc.fill(0)
2263 self.data_spc.fill(0)
2262 self.data_cspc.fill(0)
2264 self.data_cspc.fill(0)
2263 self.data_dc.fill(0)
2265 self.data_dc.fill(0)
2264 self.setNextFile()
2266 self.setNextFile()
2265
2267
2266 if self.flagIsNewFile == 0:
2268 if self.flagIsNewFile == 0:
2267 self.getBasicHeader()
2269 self.getBasicHeader()
2268
2270
2269 self.data_spc = self.dataOut.data_spc
2271 self.data_spc = self.dataOut.data_spc
2270 self.data_cspc = self.dataOut.data_cspc
2272 self.data_cspc = self.dataOut.data_cspc
2271 self.data_dc = self.dataOut.data_dc
2273 self.data_dc = self.dataOut.data_dc
2272
2274
2273 # #self.processingHeaderObj.dataBlocksPerFile)
2275 # #self.processingHeaderObj.dataBlocksPerFile)
2274 if self.hasAllDataInBuffer():
2276 if self.hasAllDataInBuffer():
2275 # self.getDataHeader()
2277 # self.getDataHeader()
2276 self.writeNextBlock()
2278 self.writeNextBlock()
2277
2279
2278 return 1
2280 return 1
2279
2281
2280
2282
2281 def __getProcessFlags(self):
2283 def __getProcessFlags(self):
2282
2284
2283 processFlags = 0
2285 processFlags = 0
2284
2286
2285 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2287 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2286 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2288 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2287 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2289 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2288 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2290 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2289 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2291 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2290 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2292 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2291
2293
2292 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2294 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2293
2295
2294
2296
2295
2297
2296 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2298 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2297 PROCFLAG.DATATYPE_SHORT,
2299 PROCFLAG.DATATYPE_SHORT,
2298 PROCFLAG.DATATYPE_LONG,
2300 PROCFLAG.DATATYPE_LONG,
2299 PROCFLAG.DATATYPE_INT64,
2301 PROCFLAG.DATATYPE_INT64,
2300 PROCFLAG.DATATYPE_FLOAT,
2302 PROCFLAG.DATATYPE_FLOAT,
2301 PROCFLAG.DATATYPE_DOUBLE]
2303 PROCFLAG.DATATYPE_DOUBLE]
2302
2304
2303
2305
2304 for index in range(len(dtypeList)):
2306 for index in range(len(dtypeList)):
2305 if self.dataOut.dtype == dtypeList[index]:
2307 if self.dataOut.dtype == dtypeList[index]:
2306 dtypeValue = datatypeValueList[index]
2308 dtypeValue = datatypeValueList[index]
2307 break
2309 break
2308
2310
2309 processFlags += dtypeValue
2311 processFlags += dtypeValue
2310
2312
2311 if self.dataOut.flagDecodeData:
2313 if self.dataOut.flagDecodeData:
2312 processFlags += PROCFLAG.DECODE_DATA
2314 processFlags += PROCFLAG.DECODE_DATA
2313
2315
2314 if self.dataOut.flagDeflipData:
2316 if self.dataOut.flagDeflipData:
2315 processFlags += PROCFLAG.DEFLIP_DATA
2317 processFlags += PROCFLAG.DEFLIP_DATA
2316
2318
2317 if self.dataOut.code != None:
2319 if self.dataOut.code != None:
2318 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2320 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2319
2321
2320 if self.dataOut.nIncohInt > 1:
2322 if self.dataOut.nIncohInt > 1:
2321 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2323 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2322
2324
2323 if self.dataOut.data_dc != None:
2325 if self.dataOut.data_dc != None:
2324 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2326 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2325
2327
2326 return processFlags
2328 return processFlags
2327
2329
2328
2330
2329 def __getBlockSize(self):
2331 def __getBlockSize(self):
2330 '''
2332 '''
2331 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2333 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2332 '''
2334 '''
2333
2335
2334 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2336 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2335 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2337 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2336 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2338 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2337 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2339 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2338 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2340 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2339 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2341 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2340
2342
2341 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2343 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2342 datatypeValueList = [1,2,4,8,4,8]
2344 datatypeValueList = [1,2,4,8,4,8]
2343 for index in range(len(dtypeList)):
2345 for index in range(len(dtypeList)):
2344 if self.dataOut.dtype == dtypeList[index]:
2346 if self.dataOut.dtype == dtypeList[index]:
2345 datatypeValue = datatypeValueList[index]
2347 datatypeValue = datatypeValueList[index]
2346 break
2348 break
2347
2349
2348
2350
2349 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2351 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2350
2352
2351 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2353 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2352 blocksize = (pts2write_SelfSpectra*datatypeValue)
2354 blocksize = (pts2write_SelfSpectra*datatypeValue)
2353
2355
2354 if self.dataOut.data_cspc != None:
2356 if self.dataOut.data_cspc != None:
2355 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2357 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2356 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2358 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2357
2359
2358 if self.dataOut.data_dc != None:
2360 if self.dataOut.data_dc != None:
2359 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2361 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2360 blocksize += (pts2write_DCchannels*datatypeValue*2)
2362 blocksize += (pts2write_DCchannels*datatypeValue*2)
2361
2363
2362 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2364 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2363
2365
2364 return blocksize
2366 return blocksize
2365
2367
2366 def getDataHeader(self):
2368 def getDataHeader(self):
2367
2369
2368 """
2370 """
2369 Obtiene una copia del First Header
2371 Obtiene una copia del First Header
2370
2372
2371 Affected:
2373 Affected:
2372 self.systemHeaderObj
2374 self.systemHeaderObj
2373 self.radarControllerHeaderObj
2375 self.radarControllerHeaderObj
2374 self.dtype
2376 self.dtype
2375
2377
2376 Return:
2378 Return:
2377 None
2379 None
2378 """
2380 """
2379
2381
2380 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2382 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2381 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2383 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2382 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2384 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2383
2385
2384 self.getBasicHeader()
2386 self.getBasicHeader()
2385
2387
2386 processingHeaderSize = 40 # bytes
2388 processingHeaderSize = 40 # bytes
2387 self.processingHeaderObj.dtype = 0 # Voltage
2389 self.processingHeaderObj.dtype = 0 # Voltage
2388 self.processingHeaderObj.blockSize = self.__getBlockSize()
2390 self.processingHeaderObj.blockSize = self.__getBlockSize()
2389 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2391 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2390 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2392 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2391 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2393 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2392 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2394 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2393 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2395 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2394 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2396 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2395 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2397 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2396
2398
2397 if self.processingHeaderObj.totalSpectra > 0:
2399 if self.processingHeaderObj.totalSpectra > 0:
2398 channelList = []
2400 channelList = []
2399 for channel in range(self.dataOut.nChannels):
2401 for channel in range(self.dataOut.nChannels):
2400 channelList.append(channel)
2402 channelList.append(channel)
2401 channelList.append(channel)
2403 channelList.append(channel)
2402
2404
2403 pairsList = []
2405 pairsList = []
2404 for pair in self.dataOut.pairsList:
2406 for pair in self.dataOut.pairsList:
2405 pairsList.append(pair[0])
2407 pairsList.append(pair[0])
2406 pairsList.append(pair[1])
2408 pairsList.append(pair[1])
2407 spectraComb = channelList + pairsList
2409 spectraComb = channelList + pairsList
2408 spectraComb = numpy.array(spectraComb,dtype="u1")
2410 spectraComb = numpy.array(spectraComb,dtype="u1")
2409 self.processingHeaderObj.spectraComb = spectraComb
2411 self.processingHeaderObj.spectraComb = spectraComb
2410 sizeOfSpcComb = len(spectraComb)
2412 sizeOfSpcComb = len(spectraComb)
2411 processingHeaderSize += sizeOfSpcComb
2413 processingHeaderSize += sizeOfSpcComb
2412
2414
2413 if self.dataOut.code != None:
2415 if self.dataOut.code != None:
2414 self.processingHeaderObj.code = self.dataOut.code
2416 self.processingHeaderObj.code = self.dataOut.code
2415 self.processingHeaderObj.nCode = self.dataOut.nCode
2417 self.processingHeaderObj.nCode = self.dataOut.nCode
2416 self.processingHeaderObj.nBaud = self.dataOut.nBaud
2418 self.processingHeaderObj.nBaud = self.dataOut.nBaud
2417 nCodeSize = 4 # bytes
2419 nCodeSize = 4 # bytes
2418 nBaudSize = 4 # bytes
2420 nBaudSize = 4 # bytes
2419 codeSize = 4 # bytes
2421 codeSize = 4 # bytes
2420 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2422 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2421 processingHeaderSize += sizeOfCode
2423 processingHeaderSize += sizeOfCode
2422
2424
2423 if self.processingHeaderObj.nWindows != 0:
2425 if self.processingHeaderObj.nWindows != 0:
2424 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2426 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2425 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2427 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2426 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2428 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2427 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2429 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2428 sizeOfFirstHeight = 4
2430 sizeOfFirstHeight = 4
2429 sizeOfdeltaHeight = 4
2431 sizeOfdeltaHeight = 4
2430 sizeOfnHeights = 4
2432 sizeOfnHeights = 4
2431 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2433 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2432 processingHeaderSize += sizeOfWindows
2434 processingHeaderSize += sizeOfWindows
2433
2435
2434 self.processingHeaderObj.size = processingHeaderSize
2436 self.processingHeaderObj.size = processingHeaderSize
2435
2437
2436 class SpectraHeisWriter():
2438 class SpectraHeisWriter():
2437
2439
2438 i=0
2440 i=0
2439
2441
2440 def __init__(self, dataOut):
2442 def __init__(self, dataOut):
2441
2443
2442 self.wrObj = FITS()
2444 self.wrObj = FITS()
2443 self.dataOut = dataOut
2445 self.dataOut = dataOut
2444
2446
2445 def isNumber(str):
2447 def isNumber(str):
2446 """
2448 """
2447 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2449 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2448
2450
2449 Excepciones:
2451 Excepciones:
2450 Si un determinado string no puede ser convertido a numero
2452 Si un determinado string no puede ser convertido a numero
2451 Input:
2453 Input:
2452 str, string al cual se le analiza para determinar si convertible a un numero o no
2454 str, string al cual se le analiza para determinar si convertible a un numero o no
2453
2455
2454 Return:
2456 Return:
2455 True : si el string es uno numerico
2457 True : si el string es uno numerico
2456 False : no es un string numerico
2458 False : no es un string numerico
2457 """
2459 """
2458 try:
2460 try:
2459 float( str )
2461 float( str )
2460 return True
2462 return True
2461 except:
2463 except:
2462 return False
2464 return False
2463
2465
2464 def setup(self, wrpath,):
2466 def setup(self, wrpath,):
2465
2467
2466 if not(os.path.exists(wrpath)):
2468 if not(os.path.exists(wrpath)):
2467 os.mkdir(wrpath)
2469 os.mkdir(wrpath)
2468
2470
2469 self.wrpath = wrpath
2471 self.wrpath = wrpath
2470 self.setFile = 0
2472 self.setFile = 0
2471
2473
2472 def putData(self):
2474 def putData(self):
2473 # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
2475 # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
2474 #name = self.dataOut.utctime
2476 #name = self.dataOut.utctime
2475 name= time.localtime( self.dataOut.utctime)
2477 name= time.localtime( self.dataOut.utctime)
2476 ext=".fits"
2478 ext=".fits"
2477 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
2479 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
2478 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
2480 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
2479
2481
2480 fullpath = os.path.join( self.wrpath, subfolder )
2482 fullpath = os.path.join( self.wrpath, subfolder )
2481 if not( os.path.exists(fullpath) ):
2483 if not( os.path.exists(fullpath) ):
2482 os.mkdir(fullpath)
2484 os.mkdir(fullpath)
2483 self.setFile += 1
2485 self.setFile += 1
2484 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2486 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2485
2487
2486 filename = os.path.join(self.wrpath,subfolder, file)
2488 filename = os.path.join(self.wrpath,subfolder, file)
2487
2489
2488 # print self.dataOut.ippSeconds
2490 # print self.dataOut.ippSeconds
2489 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
2491 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
2490
2492
2491 col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2493 col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2492 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
2494 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
2493 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
2495 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
2494 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
2496 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
2495 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
2497 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
2496 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
2498 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
2497 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
2499 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
2498 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
2500 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
2499 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
2501 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
2500 #n=numpy.arange((100))
2502 #n=numpy.arange((100))
2501 n=self.dataOut.data_spc[6,:]
2503 n=self.dataOut.data_spc[6,:]
2502 a=self.wrObj.cFImage(n)
2504 a=self.wrObj.cFImage(n)
2503 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
2505 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
2504 self.wrObj.CFile(a,b)
2506 self.wrObj.CFile(a,b)
2505 self.wrObj.wFile(filename)
2507 self.wrObj.wFile(filename)
2506 return 1
2508 return 1
2507
2509
2508 class FITS:
2510 class FITS:
2509
2511
2510 name=None
2512 name=None
2511 format=None
2513 format=None
2512 array =None
2514 array =None
2513 data =None
2515 data =None
2514 thdulist=None
2516 thdulist=None
2515
2517
2516 def __init__(self):
2518 def __init__(self):
2517
2519
2518 pass
2520 pass
2519
2521
2520 def setColF(self,name,format,array):
2522 def setColF(self,name,format,array):
2521 self.name=name
2523 self.name=name
2522 self.format=format
2524 self.format=format
2523 self.array=array
2525 self.array=array
2524 a1=numpy.array([self.array],dtype=numpy.float32)
2526 a1=numpy.array([self.array],dtype=numpy.float32)
2525 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2527 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2526 return self.col1
2528 return self.col1
2527
2529
2528 # def setColP(self,name,format,data):
2530 # def setColP(self,name,format,data):
2529 # self.name=name
2531 # self.name=name
2530 # self.format=format
2532 # self.format=format
2531 # self.data=data
2533 # self.data=data
2532 # a2=numpy.array([self.data],dtype=numpy.float32)
2534 # a2=numpy.array([self.data],dtype=numpy.float32)
2533 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2535 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2534 # return self.col2
2536 # return self.col2
2535
2537
2536 def writeHeader(self,):
2538 def writeHeader(self,):
2537 pass
2539 pass
2538
2540
2539 def writeData(self,name,format,data):
2541 def writeData(self,name,format,data):
2540 self.name=name
2542 self.name=name
2541 self.format=format
2543 self.format=format
2542 self.data=data
2544 self.data=data
2543 a2=numpy.array([self.data],dtype=numpy.float32)
2545 a2=numpy.array([self.data],dtype=numpy.float32)
2544 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2546 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2545 return self.col2
2547 return self.col2
2546
2548
2547 def cFImage(self,n):
2549 def cFImage(self,n):
2548 self.hdu= pyfits.PrimaryHDU(n)
2550 self.hdu= pyfits.PrimaryHDU(n)
2549 return self.hdu
2551 return self.hdu
2550
2552
2551 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
2553 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
2552 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
2554 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
2553 self.tbhdu = pyfits.new_table(self.cols)
2555 self.tbhdu = pyfits.new_table(self.cols)
2554 return self.tbhdu
2556 return self.tbhdu
2555
2557
2556 def CFile(self,hdu,tbhdu):
2558 def CFile(self,hdu,tbhdu):
2557 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2559 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2558
2560
2559 def wFile(self,filename):
2561 def wFile(self,filename):
2560 self.thdulist.writeto(filename) No newline at end of file
2562 self.thdulist.writeto(filename)
@@ -1,519 +1,526
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10
10
11 class Header:
11 class Header:
12
12
13 def __init__(self):
13 def __init__(self):
14 raise
14 raise
15
15
16 def copy(self):
16 def copy(self):
17 return copy.deepcopy(self)
17 return copy.deepcopy(self)
18
18
19 def read():
19 def read():
20 pass
20 pass
21
21
22 def write():
22 def write():
23 pass
23 pass
24
24
25 def printInfo(self):
25 def printInfo(self):
26
26
27 for key in self.__dict__.keys():
27 for key in self.__dict__.keys():
28 print "%s = %s" %(key, self.__dict__[key])
28 print "%s = %s" %(key, self.__dict__[key])
29
29
30 class BasicHeader(Header):
30 class BasicHeader(Header):
31
31
32 size = None
32 size = None
33 version = None
33 version = None
34 dataBlock = None
34 dataBlock = None
35 utc = None
35 utc = None
36 miliSecond = None
36 miliSecond = None
37 timeZone = None
37 timeZone = None
38 dstFlag = None
38 dstFlag = None
39 errorCount = None
39 errorCount = None
40 struct = None
40 struct = None
41 datatime = None
41 datatime = None
42
43 __LOCALTIME = None
42
44
43 def __init__(self):
45 def __init__(self, localtime=0):
44
46
45 self.size = 0
47 self.size = 0
46 self.version = 0
48 self.version = 0
47 self.dataBlock = 0
49 self.dataBlock = 0
48 self.utc = 0
50 self.utc = 0
49 self.miliSecond = 0
51 self.miliSecond = 0
50 self.timeZone = 0
52 self.timeZone = 0
51 self.dstFlag = 0
53 self.dstFlag = 0
52 self.errorCount = 0
54 self.errorCount = 0
53 self.struct = numpy.dtype([
55 self.struct = numpy.dtype([
54 ('nSize','<u4'),
56 ('nSize','<u4'),
55 ('nVersion','<u2'),
57 ('nVersion','<u2'),
56 ('nDataBlockId','<u4'),
58 ('nDataBlockId','<u4'),
57 ('nUtime','<u4'),
59 ('nUtime','<u4'),
58 ('nMilsec','<u2'),
60 ('nMilsec','<u2'),
59 ('nTimezone','<i2'),
61 ('nTimezone','<i2'),
60 ('nDstflag','<i2'),
62 ('nDstflag','<i2'),
61 ('nErrorCount','<u4')
63 ('nErrorCount','<u4')
62 ])
64 ])
63
65
66 self.__LOCALTIME = localtime
64
67
65 def read(self, fp):
68 def read(self, fp):
66 try:
69 try:
67 header = numpy.fromfile(fp, self.struct,1)
70 header = numpy.fromfile(fp, self.struct,1)
68 self.size = int(header['nSize'][0])
71 self.size = int(header['nSize'][0])
69 self.version = int(header['nVersion'][0])
72 self.version = int(header['nVersion'][0])
70 self.dataBlock = int(header['nDataBlockId'][0])
73 self.dataBlock = int(header['nDataBlockId'][0])
71 self.utc = int(header['nUtime'][0])
74 self.utc = int(header['nUtime'][0])
72 self.miliSecond = int(header['nMilsec'][0])
75 self.miliSecond = int(header['nMilsec'][0])
73 self.timeZone = int(header['nTimezone'][0])
76 self.timeZone = int(header['nTimezone'][0])
74 self.dstFlag = int(header['nDstflag'][0])
77 self.dstFlag = int(header['nDstflag'][0])
75 self.errorCount = int(header['nErrorCount'][0])
78 self.errorCount = int(header['nErrorCount'][0])
76
79
80 self.utc += self.__LOCALTIME
81
77 self.datatime = datetime.datetime.utcfromtimestamp(self.utc)
82 self.datatime = datetime.datetime.utcfromtimestamp(self.utc)
83
78 except Exception, e:
84 except Exception, e:
79 print "BasicHeader: " + e
85 print "BasicHeader: "
86 print e
80 return 0
87 return 0
81
88
82 return 1
89 return 1
83
90
84 def write(self, fp):
91 def write(self, fp):
85 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
92 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
86 header = numpy.array(headerTuple,self.struct)
93 header = numpy.array(headerTuple,self.struct)
87 header.tofile(fp)
94 header.tofile(fp)
88
95
89 return 1
96 return 1
90
97
91 class SystemHeader(Header):
98 class SystemHeader(Header):
92
99
93 size = None
100 size = None
94 nSamples = None
101 nSamples = None
95 nProfiles = None
102 nProfiles = None
96 nChannels = None
103 nChannels = None
97 adcResolution = None
104 adcResolution = None
98 pciDioBusWidth = None
105 pciDioBusWidth = None
99 struct = None
106 struct = None
100
107
101 def __init__(self):
108 def __init__(self):
102 self.size = 0
109 self.size = 0
103 self.nSamples = 0
110 self.nSamples = 0
104 self.nProfiles = 0
111 self.nProfiles = 0
105 self.nChannels = 0
112 self.nChannels = 0
106 self.adcResolution = 0
113 self.adcResolution = 0
107 self.pciDioBusWidth = 0
114 self.pciDioBusWidth = 0
108 self.struct = numpy.dtype([
115 self.struct = numpy.dtype([
109 ('nSize','<u4'),
116 ('nSize','<u4'),
110 ('nNumSamples','<u4'),
117 ('nNumSamples','<u4'),
111 ('nNumProfiles','<u4'),
118 ('nNumProfiles','<u4'),
112 ('nNumChannels','<u4'),
119 ('nNumChannels','<u4'),
113 ('nADCResolution','<u4'),
120 ('nADCResolution','<u4'),
114 ('nPCDIOBusWidth','<u4'),
121 ('nPCDIOBusWidth','<u4'),
115 ])
122 ])
116
123
117
124
118 def read(self, fp):
125 def read(self, fp):
119 try:
126 try:
120 header = numpy.fromfile(fp,self.struct,1)
127 header = numpy.fromfile(fp,self.struct,1)
121 self.size = header['nSize'][0]
128 self.size = header['nSize'][0]
122 self.nSamples = header['nNumSamples'][0]
129 self.nSamples = header['nNumSamples'][0]
123 self.nProfiles = header['nNumProfiles'][0]
130 self.nProfiles = header['nNumProfiles'][0]
124 self.nChannels = header['nNumChannels'][0]
131 self.nChannels = header['nNumChannels'][0]
125 self.adcResolution = header['nADCResolution'][0]
132 self.adcResolution = header['nADCResolution'][0]
126 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
133 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
127
134
128 except Exception, e:
135 except Exception, e:
129 print "SystemHeader: " + e
136 print "SystemHeader: " + e
130 return 0
137 return 0
131
138
132 return 1
139 return 1
133
140
134 def write(self, fp):
141 def write(self, fp):
135 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
142 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
136 header = numpy.array(headerTuple,self.struct)
143 header = numpy.array(headerTuple,self.struct)
137 header.tofile(fp)
144 header.tofile(fp)
138
145
139 return 1
146 return 1
140
147
141 class RadarControllerHeader(Header):
148 class RadarControllerHeader(Header):
142
149
143 size = None
150 size = None
144 expType = None
151 expType = None
145 nTx = None
152 nTx = None
146 ipp = None
153 ipp = None
147 txA = None
154 txA = None
148 txB = None
155 txB = None
149 nWindows = None
156 nWindows = None
150 numTaus = None
157 numTaus = None
151 codeType = None
158 codeType = None
152 line6Function = None
159 line6Function = None
153 line5Function = None
160 line5Function = None
154 fClock = None
161 fClock = None
155 prePulseBefore = None
162 prePulseBefore = None
156 prePulserAfter = None
163 prePulserAfter = None
157 rangeIpp = None
164 rangeIpp = None
158 rangeTxA = None
165 rangeTxA = None
159 rangeTxB = None
166 rangeTxB = None
160 struct = None
167 struct = None
161
168
162 def __init__(self):
169 def __init__(self):
163 self.size = 0
170 self.size = 0
164 self.expType = 0
171 self.expType = 0
165 self.nTx = 0
172 self.nTx = 0
166 self.ipp = 0
173 self.ipp = 0
167 self.txA = 0
174 self.txA = 0
168 self.txB = 0
175 self.txB = 0
169 self.nWindows = 0
176 self.nWindows = 0
170 self.numTaus = 0
177 self.numTaus = 0
171 self.codeType = 0
178 self.codeType = 0
172 self.line6Function = 0
179 self.line6Function = 0
173 self.line5Function = 0
180 self.line5Function = 0
174 self.fClock = 0
181 self.fClock = 0
175 self.prePulseBefore = 0
182 self.prePulseBefore = 0
176 self.prePulserAfter = 0
183 self.prePulserAfter = 0
177 self.rangeIpp = 0
184 self.rangeIpp = 0
178 self.rangeTxA = 0
185 self.rangeTxA = 0
179 self.rangeTxB = 0
186 self.rangeTxB = 0
180 self.struct = numpy.dtype([
187 self.struct = numpy.dtype([
181 ('nSize','<u4'),
188 ('nSize','<u4'),
182 ('nExpType','<u4'),
189 ('nExpType','<u4'),
183 ('nNTx','<u4'),
190 ('nNTx','<u4'),
184 ('fIpp','<f4'),
191 ('fIpp','<f4'),
185 ('fTxA','<f4'),
192 ('fTxA','<f4'),
186 ('fTxB','<f4'),
193 ('fTxB','<f4'),
187 ('nNumWindows','<u4'),
194 ('nNumWindows','<u4'),
188 ('nNumTaus','<u4'),
195 ('nNumTaus','<u4'),
189 ('nCodeType','<u4'),
196 ('nCodeType','<u4'),
190 ('nLine6Function','<u4'),
197 ('nLine6Function','<u4'),
191 ('nLine5Function','<u4'),
198 ('nLine5Function','<u4'),
192 ('fClock','<f4'),
199 ('fClock','<f4'),
193 ('nPrePulseBefore','<u4'),
200 ('nPrePulseBefore','<u4'),
194 ('nPrePulseAfter','<u4'),
201 ('nPrePulseAfter','<u4'),
195 ('sRangeIPP','<a20'),
202 ('sRangeIPP','<a20'),
196 ('sRangeTxA','<a20'),
203 ('sRangeTxA','<a20'),
197 ('sRangeTxB','<a20'),
204 ('sRangeTxB','<a20'),
198 ])
205 ])
199
206
200 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
207 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
201
208
202 self.samplingWindow = None
209 self.samplingWindow = None
203 self.nHeights = None
210 self.nHeights = None
204 self.firstHeight = None
211 self.firstHeight = None
205 self.deltaHeight = None
212 self.deltaHeight = None
206 self.samplesWin = None
213 self.samplesWin = None
207
214
208 self.nCode = None
215 self.nCode = None
209 self.nBaud = None
216 self.nBaud = None
210 self.code = None
217 self.code = None
211 self.flip1 = None
218 self.flip1 = None
212 self.flip2 = None
219 self.flip2 = None
213
220
214 self.dynamic = numpy.array([],numpy.dtype('byte'))
221 self.dynamic = numpy.array([],numpy.dtype('byte'))
215
222
216
223
217 def read(self, fp):
224 def read(self, fp):
218 try:
225 try:
219 startFp = fp.tell()
226 startFp = fp.tell()
220 header = numpy.fromfile(fp,self.struct,1)
227 header = numpy.fromfile(fp,self.struct,1)
221 self.size = int(header['nSize'][0])
228 self.size = int(header['nSize'][0])
222 self.expType = int(header['nExpType'][0])
229 self.expType = int(header['nExpType'][0])
223 self.nTx = int(header['nNTx'][0])
230 self.nTx = int(header['nNTx'][0])
224 self.ipp = float(header['fIpp'][0])
231 self.ipp = float(header['fIpp'][0])
225 self.txA = float(header['fTxA'][0])
232 self.txA = float(header['fTxA'][0])
226 self.txB = float(header['fTxB'][0])
233 self.txB = float(header['fTxB'][0])
227 self.nWindows = int(header['nNumWindows'][0])
234 self.nWindows = int(header['nNumWindows'][0])
228 self.numTaus = int(header['nNumTaus'][0])
235 self.numTaus = int(header['nNumTaus'][0])
229 self.codeType = int(header['nCodeType'][0])
236 self.codeType = int(header['nCodeType'][0])
230 self.line6Function = int(header['nLine6Function'][0])
237 self.line6Function = int(header['nLine6Function'][0])
231 self.line5Function = int(header['nLine5Function'][0])
238 self.line5Function = int(header['nLine5Function'][0])
232 self.fClock = float(header['fClock'][0])
239 self.fClock = float(header['fClock'][0])
233 self.prePulseBefore = int(header['nPrePulseBefore'][0])
240 self.prePulseBefore = int(header['nPrePulseBefore'][0])
234 self.prePulserAfter = int(header['nPrePulseAfter'][0])
241 self.prePulserAfter = int(header['nPrePulseAfter'][0])
235 self.rangeIpp = header['sRangeIPP'][0]
242 self.rangeIpp = header['sRangeIPP'][0]
236 self.rangeTxA = header['sRangeTxA'][0]
243 self.rangeTxA = header['sRangeTxA'][0]
237 self.rangeTxB = header['sRangeTxB'][0]
244 self.rangeTxB = header['sRangeTxB'][0]
238 # jump Dynamic Radar Controller Header
245 # jump Dynamic Radar Controller Header
239 jumpFp = self.size - 116
246 jumpFp = self.size - 116
240 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
247 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
241 #pointer backward to dynamic header and read
248 #pointer backward to dynamic header and read
242 backFp = fp.tell() - jumpFp
249 backFp = fp.tell() - jumpFp
243 fp.seek(backFp)
250 fp.seek(backFp)
244
251
245 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
252 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
246 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
253 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
247 self.firstHeight = self.samplingWindow['h0']
254 self.firstHeight = self.samplingWindow['h0']
248 self.deltaHeight = self.samplingWindow['dh']
255 self.deltaHeight = self.samplingWindow['dh']
249 self.samplesWin = self.samplingWindow['nsa']
256 self.samplesWin = self.samplingWindow['nsa']
250
257
251 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
258 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
252
259
253 if self.codeType != 0:
260 if self.codeType != 0:
254 self.nCode = int(numpy.fromfile(fp,'<u4',1))
261 self.nCode = int(numpy.fromfile(fp,'<u4',1))
255 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
262 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
256 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
263 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
257 tempList = []
264 tempList = []
258 for ic in range(self.nCode):
265 for ic in range(self.nCode):
259 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
266 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
260 tempList.append(temp)
267 tempList.append(temp)
261 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
268 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
262 self.code = 2.0*self.code - 1.0
269 self.code = 2.0*self.code - 1.0
263
270
264 if self.line5Function == RCfunction.FLIP:
271 if self.line5Function == RCfunction.FLIP:
265 self.flip1 = numpy.fromfile(fp,'<u4',1)
272 self.flip1 = numpy.fromfile(fp,'<u4',1)
266
273
267 if self.line6Function == RCfunction.FLIP:
274 if self.line6Function == RCfunction.FLIP:
268 self.flip2 = numpy.fromfile(fp,'<u4',1)
275 self.flip2 = numpy.fromfile(fp,'<u4',1)
269
276
270 endFp = self.size + startFp
277 endFp = self.size + startFp
271 jumpFp = endFp - fp.tell()
278 jumpFp = endFp - fp.tell()
272 if jumpFp > 0:
279 if jumpFp > 0:
273 fp.seek(jumpFp)
280 fp.seek(jumpFp)
274
281
275 except Exception, e:
282 except Exception, e:
276 print "RadarControllerHeader: " + e
283 print "RadarControllerHeader: " + e
277 return 0
284 return 0
278
285
279 return 1
286 return 1
280
287
281 def write(self, fp):
288 def write(self, fp):
282 headerTuple = (self.size,
289 headerTuple = (self.size,
283 self.expType,
290 self.expType,
284 self.nTx,
291 self.nTx,
285 self.ipp,
292 self.ipp,
286 self.txA,
293 self.txA,
287 self.txB,
294 self.txB,
288 self.nWindows,
295 self.nWindows,
289 self.numTaus,
296 self.numTaus,
290 self.codeType,
297 self.codeType,
291 self.line6Function,
298 self.line6Function,
292 self.line5Function,
299 self.line5Function,
293 self.fClock,
300 self.fClock,
294 self.prePulseBefore,
301 self.prePulseBefore,
295 self.prePulserAfter,
302 self.prePulserAfter,
296 self.rangeIpp,
303 self.rangeIpp,
297 self.rangeTxA,
304 self.rangeTxA,
298 self.rangeTxB)
305 self.rangeTxB)
299
306
300 header = numpy.array(headerTuple,self.struct)
307 header = numpy.array(headerTuple,self.struct)
301 header.tofile(fp)
308 header.tofile(fp)
302
309
303 dynamic = self.dynamic
310 dynamic = self.dynamic
304 dynamic.tofile(fp)
311 dynamic.tofile(fp)
305
312
306 return 1
313 return 1
307
314
308
315
309
316
310 class ProcessingHeader(Header):
317 class ProcessingHeader(Header):
311
318
312 size = None
319 size = None
313 dtype = None
320 dtype = None
314 blockSize = None
321 blockSize = None
315 profilesPerBlock = None
322 profilesPerBlock = None
316 dataBlocksPerFile = None
323 dataBlocksPerFile = None
317 nWindows = None
324 nWindows = None
318 processFlags = None
325 processFlags = None
319 nCohInt = None
326 nCohInt = None
320 nIncohInt = None
327 nIncohInt = None
321 totalSpectra = None
328 totalSpectra = None
322 struct = None
329 struct = None
323 flag_dc = None
330 flag_dc = None
324 flag_cspc = None
331 flag_cspc = None
325
332
326 def __init__(self):
333 def __init__(self):
327 self.size = 0
334 self.size = 0
328 self.dtype = 0
335 self.dtype = 0
329 self.blockSize = 0
336 self.blockSize = 0
330 self.profilesPerBlock = 0
337 self.profilesPerBlock = 0
331 self.dataBlocksPerFile = 0
338 self.dataBlocksPerFile = 0
332 self.nWindows = 0
339 self.nWindows = 0
333 self.processFlags = 0
340 self.processFlags = 0
334 self.nCohInt = 0
341 self.nCohInt = 0
335 self.nIncohInt = 0
342 self.nIncohInt = 0
336 self.totalSpectra = 0
343 self.totalSpectra = 0
337 self.struct = numpy.dtype([
344 self.struct = numpy.dtype([
338 ('nSize','<u4'),
345 ('nSize','<u4'),
339 ('nDataType','<u4'),
346 ('nDataType','<u4'),
340 ('nSizeOfDataBlock','<u4'),
347 ('nSizeOfDataBlock','<u4'),
341 ('nProfilesperBlock','<u4'),
348 ('nProfilesperBlock','<u4'),
342 ('nDataBlocksperFile','<u4'),
349 ('nDataBlocksperFile','<u4'),
343 ('nNumWindows','<u4'),
350 ('nNumWindows','<u4'),
344 ('nProcessFlags','<u4'),
351 ('nProcessFlags','<u4'),
345 ('nCoherentIntegrations','<u4'),
352 ('nCoherentIntegrations','<u4'),
346 ('nIncoherentIntegrations','<u4'),
353 ('nIncoherentIntegrations','<u4'),
347 ('nTotalSpectra','<u4')
354 ('nTotalSpectra','<u4')
348 ])
355 ])
349 self.samplingWindow = 0
356 self.samplingWindow = 0
350 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
357 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
351 self.nHeights = 0
358 self.nHeights = 0
352 self.firstHeight = 0
359 self.firstHeight = 0
353 self.deltaHeight = 0
360 self.deltaHeight = 0
354 self.samplesWin = 0
361 self.samplesWin = 0
355 self.spectraComb = 0
362 self.spectraComb = 0
356 self.nCode = None
363 self.nCode = None
357 self.code = None
364 self.code = None
358 self.nBaud = None
365 self.nBaud = None
359 self.shif_fft = False
366 self.shif_fft = False
360 self.flag_dc = False
367 self.flag_dc = False
361 self.flag_cspc = False
368 self.flag_cspc = False
362
369
363 def read(self, fp):
370 def read(self, fp):
364 try:
371 try:
365 header = numpy.fromfile(fp,self.struct,1)
372 header = numpy.fromfile(fp,self.struct,1)
366 self.size = int(header['nSize'][0])
373 self.size = int(header['nSize'][0])
367 self.dtype = int(header['nDataType'][0])
374 self.dtype = int(header['nDataType'][0])
368 self.blockSize = int(header['nSizeOfDataBlock'][0])
375 self.blockSize = int(header['nSizeOfDataBlock'][0])
369 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
376 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
370 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
377 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
371 self.nWindows = int(header['nNumWindows'][0])
378 self.nWindows = int(header['nNumWindows'][0])
372 self.processFlags = header['nProcessFlags']
379 self.processFlags = header['nProcessFlags']
373 self.nCohInt = int(header['nCoherentIntegrations'][0])
380 self.nCohInt = int(header['nCoherentIntegrations'][0])
374 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
381 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
375 self.totalSpectra = int(header['nTotalSpectra'][0])
382 self.totalSpectra = int(header['nTotalSpectra'][0])
376 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
383 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
377 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
384 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
378 self.firstHeight = float(self.samplingWindow['h0'][0])
385 self.firstHeight = float(self.samplingWindow['h0'][0])
379 self.deltaHeight = float(self.samplingWindow['dh'][0])
386 self.deltaHeight = float(self.samplingWindow['dh'][0])
380 self.samplesWin = self.samplingWindow['nsa']
387 self.samplesWin = self.samplingWindow['nsa']
381 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
388 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
382
389
383 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
390 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
384 self.nCode = int(numpy.fromfile(fp,'<u4',1))
391 self.nCode = int(numpy.fromfile(fp,'<u4',1))
385 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
392 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
386 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
393 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
387
394
388 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
395 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
389 self.shif_fft = True
396 self.shif_fft = True
390 else:
397 else:
391 self.shif_fft = False
398 self.shif_fft = False
392
399
393 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
400 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
394 self.flag_dc = True
401 self.flag_dc = True
395
402
396 nChannels = 0
403 nChannels = 0
397 nPairs = 0
404 nPairs = 0
398 pairList = []
405 pairList = []
399
406
400 for i in range( 0, self.totalSpectra*2, 2 ):
407 for i in range( 0, self.totalSpectra*2, 2 ):
401 if self.spectraComb[i] == self.spectraComb[i+1]:
408 if self.spectraComb[i] == self.spectraComb[i+1]:
402 nChannels = nChannels + 1 #par de canales iguales
409 nChannels = nChannels + 1 #par de canales iguales
403 else:
410 else:
404 nPairs = nPairs + 1 #par de canales diferentes
411 nPairs = nPairs + 1 #par de canales diferentes
405 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
412 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
406
413
407 self.flag_cspc = False
414 self.flag_cspc = False
408 if nPairs > 0:
415 if nPairs > 0:
409 self.flag_cspc = True
416 self.flag_cspc = True
410
417
411 except Exception, e:
418 except Exception, e:
412 print "ProcessingHeader: " + e
419 print "ProcessingHeader: " + e
413 return 0
420 return 0
414
421
415 return 1
422 return 1
416
423
417 def write(self, fp):
424 def write(self, fp):
418 headerTuple = (self.size,
425 headerTuple = (self.size,
419 self.dtype,
426 self.dtype,
420 self.blockSize,
427 self.blockSize,
421 self.profilesPerBlock,
428 self.profilesPerBlock,
422 self.dataBlocksPerFile,
429 self.dataBlocksPerFile,
423 self.nWindows,
430 self.nWindows,
424 self.processFlags,
431 self.processFlags,
425 self.nCohInt,
432 self.nCohInt,
426 self.nIncohInt,
433 self.nIncohInt,
427 self.totalSpectra)
434 self.totalSpectra)
428
435
429 header = numpy.array(headerTuple,self.struct)
436 header = numpy.array(headerTuple,self.struct)
430 header.tofile(fp)
437 header.tofile(fp)
431
438
432 if self.nWindows != 0:
439 if self.nWindows != 0:
433 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
440 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
434 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
441 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
435 samplingWindow.tofile(fp)
442 samplingWindow.tofile(fp)
436
443
437
444
438 if self.totalSpectra != 0:
445 if self.totalSpectra != 0:
439 spectraComb = numpy.array([],numpy.dtype('u1'))
446 spectraComb = numpy.array([],numpy.dtype('u1'))
440 spectraComb = self.spectraComb
447 spectraComb = self.spectraComb
441 spectraComb.tofile(fp)
448 spectraComb.tofile(fp)
442
449
443
450
444 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
451 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
445 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
452 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
446 nCode.tofile(fp)
453 nCode.tofile(fp)
447
454
448 nBaud = self.nBaud
455 nBaud = self.nBaud
449 nBaud.tofile(fp)
456 nBaud.tofile(fp)
450
457
451 code = self.code.reshape(nCode*nBaud)
458 code = self.code.reshape(nCode*nBaud)
452 code.tofile(fp)
459 code.tofile(fp)
453
460
454 return 1
461 return 1
455
462
456 class RCfunction:
463 class RCfunction:
457 NONE=0
464 NONE=0
458 FLIP=1
465 FLIP=1
459 CODE=2
466 CODE=2
460 SAMPLING=3
467 SAMPLING=3
461 LIN6DIV256=4
468 LIN6DIV256=4
462 SYNCHRO=5
469 SYNCHRO=5
463
470
464 class nCodeType:
471 class nCodeType:
465 NONE=0
472 NONE=0
466 USERDEFINE=1
473 USERDEFINE=1
467 BARKER2=2
474 BARKER2=2
468 BARKER3=3
475 BARKER3=3
469 BARKER4=4
476 BARKER4=4
470 BARKER5=5
477 BARKER5=5
471 BARKER7=6
478 BARKER7=6
472 BARKER11=7
479 BARKER11=7
473 BARKER13=8
480 BARKER13=8
474 AC128=9
481 AC128=9
475 COMPLEMENTARYCODE2=10
482 COMPLEMENTARYCODE2=10
476 COMPLEMENTARYCODE4=11
483 COMPLEMENTARYCODE4=11
477 COMPLEMENTARYCODE8=12
484 COMPLEMENTARYCODE8=12
478 COMPLEMENTARYCODE16=13
485 COMPLEMENTARYCODE16=13
479 COMPLEMENTARYCODE32=14
486 COMPLEMENTARYCODE32=14
480 COMPLEMENTARYCODE64=15
487 COMPLEMENTARYCODE64=15
481 COMPLEMENTARYCODE128=16
488 COMPLEMENTARYCODE128=16
482 CODE_BINARY28=17
489 CODE_BINARY28=17
483
490
484 class PROCFLAG:
491 class PROCFLAG:
485 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
492 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
486 DECODE_DATA = numpy.uint32(0x00000002)
493 DECODE_DATA = numpy.uint32(0x00000002)
487 SPECTRA_CALC = numpy.uint32(0x00000004)
494 SPECTRA_CALC = numpy.uint32(0x00000004)
488 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
495 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
489 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
496 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
490 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
497 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
491
498
492 DATATYPE_CHAR = numpy.uint32(0x00000040)
499 DATATYPE_CHAR = numpy.uint32(0x00000040)
493 DATATYPE_SHORT = numpy.uint32(0x00000080)
500 DATATYPE_SHORT = numpy.uint32(0x00000080)
494 DATATYPE_LONG = numpy.uint32(0x00000100)
501 DATATYPE_LONG = numpy.uint32(0x00000100)
495 DATATYPE_INT64 = numpy.uint32(0x00000200)
502 DATATYPE_INT64 = numpy.uint32(0x00000200)
496 DATATYPE_FLOAT = numpy.uint32(0x00000400)
503 DATATYPE_FLOAT = numpy.uint32(0x00000400)
497 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
504 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
498
505
499 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
506 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
500 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
507 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
501 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
508 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
502
509
503 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
510 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
504 DEFLIP_DATA = numpy.uint32(0x00010000)
511 DEFLIP_DATA = numpy.uint32(0x00010000)
505 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
512 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
506
513
507 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
514 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
508 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
515 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
509 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
516 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
510 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
517 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
511 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
518 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
512
519
513 EXP_NAME_ESP = numpy.uint32(0x00200000)
520 EXP_NAME_ESP = numpy.uint32(0x00200000)
514 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
521 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
515
522
516 OPERATION_MASK = numpy.uint32(0x0000003F)
523 OPERATION_MASK = numpy.uint32(0x0000003F)
517 DATATYPE_MASK = numpy.uint32(0x00000FC0)
524 DATATYPE_MASK = numpy.uint32(0x00000FC0)
518 DATAARRANGE_MASK = numpy.uint32(0x00007000)
525 DATAARRANGE_MASK = numpy.uint32(0x00007000)
519 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
526 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,967 +1,976
1 import numpy
1 import numpy
2 import time, datetime
2 import time, datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class CrossSpectraPlot(Figure):
5 class CrossSpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTH = None
11 HEIGHT = None
10 WIDTHPROF = None
12 WIDTHPROF = None
11 HEIGHTPROF = None
13 HEIGHTPROF = None
12 PREFIX = 'cspc'
14 PREFIX = 'cspc'
13
15
14 def __init__(self):
16 def __init__(self):
15
17
16 self.__isConfig = False
18 self.__isConfig = False
17 self.__nsubplots = 4
19 self.__nsubplots = 4
18
20
19 self.WIDTH = 300
21 self.WIDTH = 250
20 self.HEIGHT = 400
22 self.HEIGHT = 250
21 self.WIDTHPROF = 0
23 self.WIDTHPROF = 0
22 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
23
25
24 def getSubplots(self):
26 def getSubplots(self):
25
27
26 ncol = 4
28 ncol = 4
27 nrow = self.nplots
29 nrow = self.nplots
28
30
29 return nrow, ncol
31 return nrow, ncol
30
32
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32
34
33 self.__showprofile = showprofile
35 self.__showprofile = showprofile
34 self.nplots = nplots
36 self.nplots = nplots
35
37
36 ncolspan = 1
38 ncolspan = 1
37 colspan = 1
39 colspan = 1
38
40
39 self.createFigure(idfigure = idfigure,
41 self.createFigure(idfigure = idfigure,
40 wintitle = wintitle,
42 wintitle = wintitle,
41 widthplot = self.WIDTH + self.WIDTHPROF,
43 widthplot = self.WIDTH + self.WIDTHPROF,
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
44 heightplot = self.HEIGHT + self.HEIGHTPROF)
43
45
44 nrow, ncol = self.getSubplots()
46 nrow, ncol = self.getSubplots()
45
47
46 counter = 0
48 counter = 0
47 for y in range(nrow):
49 for y in range(nrow):
48 for x in range(ncol):
50 for x in range(ncol):
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
50
52
51 counter += 1
53 counter += 1
52
54
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
55 save=False, figpath='./', figfile=None):
57 save=False, figpath='./', figfile=None):
56
58
57 """
59 """
58
60
59 Input:
61 Input:
60 dataOut :
62 dataOut :
61 idfigure :
63 idfigure :
62 wintitle :
64 wintitle :
63 channelList :
65 channelList :
64 showProfile :
66 showProfile :
65 xmin : None,
67 xmin : None,
66 xmax : None,
68 xmax : None,
67 ymin : None,
69 ymin : None,
68 ymax : None,
70 ymax : None,
69 zmin : None,
71 zmin : None,
70 zmax : None
72 zmax : None
71 """
73 """
72
74
73 if pairsList == None:
75 if pairsList == None:
74 pairsIndexList = dataOut.pairsIndexList
76 pairsIndexList = dataOut.pairsIndexList
75 else:
77 else:
76 pairsIndexList = []
78 pairsIndexList = []
77 for pair in pairsList:
79 for pair in pairsList:
78 if pair not in dataOut.pairsList:
80 if pair not in dataOut.pairsList:
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
81 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
80 pairsIndexList.append(dataOut.pairsList.index(pair))
82 pairsIndexList.append(dataOut.pairsList.index(pair))
81
83
82 if pairsIndexList == []:
84 if pairsIndexList == []:
83 return
85 return
84
86
85 if len(pairsIndexList) > 4:
87 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
88 pairsIndexList = pairsIndexList[0:4]
87
89
88 x = dataOut.getFreqRange(1)
90 x = dataOut.getFreqRange(1)
89 y = dataOut.getHeiRange()
91 y = dataOut.getHeiRange()
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
92 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
91 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
93 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
92 avg = numpy.average(numpy.abs(z), axis=1)
94 avg = numpy.average(numpy.abs(z), axis=1)
93
95
94 noise = dataOut.getNoise()
96 noise = dataOut.getNoise()
95
97
96 if not self.__isConfig:
98 if not self.__isConfig:
97
99
98 nplots = len(pairsIndexList)
100 nplots = len(pairsIndexList)
99
101
100 self.setup(idfigure=idfigure,
102 self.setup(idfigure=idfigure,
101 nplots=nplots,
103 nplots=nplots,
102 wintitle=wintitle,
104 wintitle=wintitle,
103 showprofile=showprofile)
105 showprofile=showprofile)
104
106
105 if xmin == None: xmin = numpy.nanmin(x)
107 if xmin == None: xmin = numpy.nanmin(x)
106 if xmax == None: xmax = numpy.nanmax(x)
108 if xmax == None: xmax = numpy.nanmax(x)
107 if ymin == None: ymin = numpy.nanmin(y)
109 if ymin == None: ymin = numpy.nanmin(y)
108 if ymax == None: ymax = numpy.nanmax(y)
110 if ymax == None: ymax = numpy.nanmax(y)
109 if zmin == None: zmin = numpy.nanmin(avg)*0.9
111 if zmin == None: zmin = numpy.nanmin(avg)*0.9
110 if zmax == None: zmax = numpy.nanmax(avg)*0.9
112 if zmax == None: zmax = numpy.nanmax(avg)*0.9
111
113
112 self.__isConfig = True
114 self.__isConfig = True
113
115
114 thisDatetime = dataOut.datatime
116 thisDatetime = dataOut.datatime
115 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
117 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
116 xlabel = "Velocity (m/s)"
118 xlabel = "Velocity (m/s)"
117 ylabel = "Range (Km)"
119 ylabel = "Range (Km)"
118
120
119 self.setWinTitle(title)
121 self.setWinTitle(title)
120
122
121 for i in range(self.nplots):
123 for i in range(self.nplots):
122 pair = dataOut.pairsList[pairsIndexList[i]]
124 pair = dataOut.pairsList[pairsIndexList[i]]
123
125
124 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
126 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
125 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
127 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
126 axes0 = self.axesList[i*self.__nsubplots]
128 axes0 = self.axesList[i*self.__nsubplots]
127 axes0.pcolor(x, y, z,
129 axes0.pcolor(x, y, z,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
130 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
129 xlabel=xlabel, ylabel=ylabel, title=title,
131 xlabel=xlabel, ylabel=ylabel, title=title,
130 ticksize=9, cblabel='')
132 ticksize=9, cblabel='')
131
133
132 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
134 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
133 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
135 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
134 axes0 = self.axesList[i*self.__nsubplots+1]
136 axes0 = self.axesList[i*self.__nsubplots+1]
135 axes0.pcolor(x, y, z,
137 axes0.pcolor(x, y, z,
136 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
138 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
137 xlabel=xlabel, ylabel=ylabel, title=title,
139 xlabel=xlabel, ylabel=ylabel, title=title,
138 ticksize=9, cblabel='')
140 ticksize=9, cblabel='')
139
141
140 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
142 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
141 coherence = numpy.abs(coherenceComplex)
143 coherence = numpy.abs(coherenceComplex)
142 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
144 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
143
145
144
146
145 title = "Coherence %d%d" %(pair[0], pair[1])
147 title = "Coherence %d%d" %(pair[0], pair[1])
146 axes0 = self.axesList[i*self.__nsubplots+2]
148 axes0 = self.axesList[i*self.__nsubplots+2]
147 axes0.pcolor(x, y, coherence,
149 axes0.pcolor(x, y, coherence,
148 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
150 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
149 xlabel=xlabel, ylabel=ylabel, title=title,
151 xlabel=xlabel, ylabel=ylabel, title=title,
150 ticksize=9, cblabel='')
152 ticksize=9, cblabel='')
151
153
152 title = "Phase %d%d" %(pair[0], pair[1])
154 title = "Phase %d%d" %(pair[0], pair[1])
153 axes0 = self.axesList[i*self.__nsubplots+3]
155 axes0 = self.axesList[i*self.__nsubplots+3]
154 axes0.pcolor(x, y, phase,
156 axes0.pcolor(x, y, phase,
155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
157 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
156 xlabel=xlabel, ylabel=ylabel, title=title,
158 xlabel=xlabel, ylabel=ylabel, title=title,
157 ticksize=9, cblabel='', colormap='RdBu')
159 ticksize=9, cblabel='', colormap='RdBu')
158
160
159
161
160
162
161 self.draw()
163 self.draw()
162
164
163 if save:
165 if save:
164 date = thisDatetime.strftime("%Y%m%d")
166 date = thisDatetime.strftime("%Y%m%d")
165 if figfile == None:
167 if figfile == None:
166 figfile = self.getFilename(name = date)
168 figfile = self.getFilename(name = date)
167
169
168 self.saveFigure(figpath, figfile)
170 self.saveFigure(figpath, figfile)
169
171
170
172
171 class RTIPlot(Figure):
173 class RTIPlot(Figure):
172
174
173 __isConfig = None
175 __isConfig = None
174 __nsubplots = None
176 __nsubplots = None
175
177
176 WIDTHPROF = None
178 WIDTHPROF = None
177 HEIGHTPROF = None
179 HEIGHTPROF = None
178 PREFIX = 'rti'
180 PREFIX = 'rti'
179
181
180 def __init__(self):
182 def __init__(self):
181
183
182 self.timerange = 24*60*60
184 self.timerange = 24*60*60
183 self.__isConfig = False
185 self.__isConfig = False
184 self.__nsubplots = 1
186 self.__nsubplots = 1
185
187
186 self.WIDTH = 800
188 self.WIDTH = 800
187 self.HEIGHT = 200
189 self.HEIGHT = 200
188 self.WIDTHPROF = 120
190 self.WIDTHPROF = 120
189 self.HEIGHTPROF = 0
191 self.HEIGHTPROF = 0
190
192
191 def getSubplots(self):
193 def getSubplots(self):
192
194
193 ncol = 1
195 ncol = 1
194 nrow = self.nplots
196 nrow = self.nplots
195
197
196 return nrow, ncol
198 return nrow, ncol
197
199
198 def setup(self, idfigure, nplots, wintitle, showprofile=True):
200 def setup(self, idfigure, nplots, wintitle, showprofile=True):
199
201
200 self.__showprofile = showprofile
202 self.__showprofile = showprofile
201 self.nplots = nplots
203 self.nplots = nplots
202
204
203 ncolspan = 1
205 ncolspan = 1
204 colspan = 1
206 colspan = 1
205 if showprofile:
207 if showprofile:
206 ncolspan = 7
208 ncolspan = 7
207 colspan = 6
209 colspan = 6
208 self.__nsubplots = 2
210 self.__nsubplots = 2
209
211
210 self.createFigure(idfigure = idfigure,
212 self.createFigure(idfigure = idfigure,
211 wintitle = wintitle,
213 wintitle = wintitle,
212 widthplot = self.WIDTH + self.WIDTHPROF,
214 widthplot = self.WIDTH + self.WIDTHPROF,
213 heightplot = self.HEIGHT + self.HEIGHTPROF)
215 heightplot = self.HEIGHT + self.HEIGHTPROF)
214
216
215 nrow, ncol = self.getSubplots()
217 nrow, ncol = self.getSubplots()
216
218
217 counter = 0
219 counter = 0
218 for y in range(nrow):
220 for y in range(nrow):
219 for x in range(ncol):
221 for x in range(ncol):
220
222
221 if counter >= self.nplots:
223 if counter >= self.nplots:
222 break
224 break
223
225
224 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
225
227
226 if showprofile:
228 if showprofile:
227 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
229 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
228
230
229 counter += 1
231 counter += 1
230
232
231 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
233 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
232 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
234 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
233 timerange=None,
235 timerange=None,
234 save=False, figpath='./', figfile=None):
236 save=False, figpath='./', figfile=None):
235
237
236 """
238 """
237
239
238 Input:
240 Input:
239 dataOut :
241 dataOut :
240 idfigure :
242 idfigure :
241 wintitle :
243 wintitle :
242 channelList :
244 channelList :
243 showProfile :
245 showProfile :
244 xmin : None,
246 xmin : None,
245 xmax : None,
247 xmax : None,
246 ymin : None,
248 ymin : None,
247 ymax : None,
249 ymax : None,
248 zmin : None,
250 zmin : None,
249 zmax : None
251 zmax : None
250 """
252 """
251
253
252 if channelList == None:
254 if channelList == None:
253 channelIndexList = dataOut.channelIndexList
255 channelIndexList = dataOut.channelIndexList
254 else:
256 else:
255 channelIndexList = []
257 channelIndexList = []
256 for channel in channelList:
258 for channel in channelList:
257 if channel not in dataOut.channelList:
259 if channel not in dataOut.channelList:
258 raise ValueError, "Channel %d is not in dataOut.channelList"
260 raise ValueError, "Channel %d is not in dataOut.channelList"
259 channelIndexList.append(dataOut.channelList.index(channel))
261 channelIndexList.append(dataOut.channelList.index(channel))
260
262
261 if timerange != None:
263 if timerange != None:
262 self.timerange = timerange
264 self.timerange = timerange
263
265
264 tmin = None
266 tmin = None
265 tmax = None
267 tmax = None
266 x = dataOut.getTimeRange()
268 x = dataOut.getTimeRange()
267 y = dataOut.getHeiRange()
269 y = dataOut.getHeiRange()
268 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
270 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
269 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
271 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
270 avg = numpy.average(z, axis=1)
272 avg = numpy.average(z, axis=1)
271
273
272 noise = dataOut.getNoise()
274 noise = dataOut.getNoise()
273
275
276 thisDatetime = dataOut.datatime
277 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
278 xlabel = "Velocity (m/s)"
279 ylabel = "Range (Km)"
280
274 if not self.__isConfig:
281 if not self.__isConfig:
275
282
276 nplots = len(channelIndexList)
283 nplots = len(channelIndexList)
277
284
278 self.setup(idfigure=idfigure,
285 self.setup(idfigure=idfigure,
279 nplots=nplots,
286 nplots=nplots,
280 wintitle=wintitle,
287 wintitle=wintitle,
281 showprofile=showprofile)
288 showprofile=showprofile)
282
289
283 tmin, tmax = self.getTimeLim(x, xmin, xmax)
290 tmin, tmax = self.getTimeLim(x, xmin, xmax)
284 if ymin == None: ymin = numpy.nanmin(y)
291 if ymin == None: ymin = numpy.nanmin(y)
285 if ymax == None: ymax = numpy.nanmax(y)
292 if ymax == None: ymax = numpy.nanmax(y)
286 if zmin == None: zmin = numpy.nanmin(avg)*0.9
293 if zmin == None: zmin = numpy.nanmin(avg)*0.9
287 if zmax == None: zmax = numpy.nanmax(avg)*0.9
294 if zmax == None: zmax = numpy.nanmax(avg)*0.9
288
295
289 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
296 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
290 self.__isConfig = True
297 self.__isConfig = True
291
298
292 thisDatetime = dataOut.datatime
293 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
294 xlabel = "Velocity (m/s)"
295 ylabel = "Range (Km)"
296
299
297 self.setWinTitle(title)
300 self.setWinTitle(title)
298
301
299 for i in range(self.nplots):
302 for i in range(self.nplots):
300 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
303 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
301 axes = self.axesList[i*self.__nsubplots]
304 axes = self.axesList[i*self.__nsubplots]
302 z = avg[i].reshape((1,-1))
305 z = avg[i].reshape((1,-1))
303 axes.pcolor(x, y, z,
306 axes.pcolor(x, y, z,
304 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
307 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
305 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
308 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
306 ticksize=9, cblabel='', cbsize="1%")
309 ticksize=9, cblabel='', cbsize="1%")
307
310
308 if self.__showprofile:
311 if self.__showprofile:
309 axes = self.axesList[i*self.__nsubplots +1]
312 axes = self.axesList[i*self.__nsubplots +1]
310 axes.pline(avg[i], y,
313 axes.pline(avg[i], y,
311 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
314 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
312 xlabel='dB', ylabel='', title='',
315 xlabel='dB', ylabel='', title='',
313 ytick_visible=False,
316 ytick_visible=False,
314 grid='x')
317 grid='x')
315
318
316 self.draw()
319 self.draw()
317
320
318 if save:
321 if save:
319
322
320 if figfile == None:
323 if figfile == None:
321 figfile = self.getFilename(name = self.name)
324 figfile = self.getFilename(name = self.name)
322
325
323 self.saveFigure(figpath, figfile)
326 self.saveFigure(figpath, figfile)
324
327
325 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
328 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
326 self.__isConfig = False
329 self.__isConfig = False
327
330
328 class SpectraPlot(Figure):
331 class SpectraPlot(Figure):
329
332
330 __isConfig = None
333 __isConfig = None
331 __nsubplots = None
334 __nsubplots = None
332
335
333 WIDTHPROF = None
336 WIDTHPROF = None
334 HEIGHTPROF = None
337 HEIGHTPROF = None
335 PREFIX = 'spc'
338 PREFIX = 'spc'
336
339
337 def __init__(self):
340 def __init__(self):
338
341
339 self.__isConfig = False
342 self.__isConfig = False
340 self.__nsubplots = 1
343 self.__nsubplots = 1
341
344
342 self.WIDTH = 300
345 self.WIDTH = 230
343 self.HEIGHT = 400
346 self.HEIGHT = 250
344 self.WIDTHPROF = 120
347 self.WIDTHPROF = 120
345 self.HEIGHTPROF = 0
348 self.HEIGHTPROF = 0
346
349
347 def getSubplots(self):
350 def getSubplots(self):
348
351
349 ncol = int(numpy.sqrt(self.nplots)+0.9)
352 ncol = int(numpy.sqrt(self.nplots)+0.9)
350 nrow = int(self.nplots*1./ncol + 0.9)
353 nrow = int(self.nplots*1./ncol + 0.9)
351
354
352 return nrow, ncol
355 return nrow, ncol
353
356
354 def setup(self, idfigure, nplots, wintitle, showprofile=True):
357 def setup(self, idfigure, nplots, wintitle, showprofile=True):
355
358
356 self.__showprofile = showprofile
359 self.__showprofile = showprofile
357 self.nplots = nplots
360 self.nplots = nplots
358
361
359 ncolspan = 1
362 ncolspan = 1
360 colspan = 1
363 colspan = 1
361 if showprofile:
364 if showprofile:
362 ncolspan = 3
365 ncolspan = 3
363 colspan = 2
366 colspan = 2
364 self.__nsubplots = 2
367 self.__nsubplots = 2
365
368
366 self.createFigure(idfigure = idfigure,
369 self.createFigure(idfigure = idfigure,
367 wintitle = wintitle,
370 wintitle = wintitle,
368 widthplot = self.WIDTH + self.WIDTHPROF,
371 widthplot = self.WIDTH + self.WIDTHPROF,
369 heightplot = self.HEIGHT + self.HEIGHTPROF)
372 heightplot = self.HEIGHT + self.HEIGHTPROF)
370
373
371 nrow, ncol = self.getSubplots()
374 nrow, ncol = self.getSubplots()
372
375
373 counter = 0
376 counter = 0
374 for y in range(nrow):
377 for y in range(nrow):
375 for x in range(ncol):
378 for x in range(ncol):
376
379
377 if counter >= self.nplots:
380 if counter >= self.nplots:
378 break
381 break
379
382
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
383 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
381
384
382 if showprofile:
385 if showprofile:
383 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
386 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
384
387
385 counter += 1
388 counter += 1
386
389
387 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
390 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
388 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
391 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
389 save=False, figpath='./', figfile=None):
392 save=False, figpath='./', figfile=None):
390
393
391 """
394 """
392
395
393 Input:
396 Input:
394 dataOut :
397 dataOut :
395 idfigure :
398 idfigure :
396 wintitle :
399 wintitle :
397 channelList :
400 channelList :
398 showProfile :
401 showProfile :
399 xmin : None,
402 xmin : None,
400 xmax : None,
403 xmax : None,
401 ymin : None,
404 ymin : None,
402 ymax : None,
405 ymax : None,
403 zmin : None,
406 zmin : None,
404 zmax : None
407 zmax : None
405 """
408 """
406
409
407 if channelList == None:
410 if channelList == None:
408 channelIndexList = dataOut.channelIndexList
411 channelIndexList = dataOut.channelIndexList
409 else:
412 else:
410 channelIndexList = []
413 channelIndexList = []
411 for channel in channelList:
414 for channel in channelList:
412 if channel not in dataOut.channelList:
415 if channel not in dataOut.channelList:
413 raise ValueError, "Channel %d is not in dataOut.channelList"
416 raise ValueError, "Channel %d is not in dataOut.channelList"
414 channelIndexList.append(dataOut.channelList.index(channel))
417 channelIndexList.append(dataOut.channelList.index(channel))
415
418
416 x = dataOut.getVelRange(1)
419 x = dataOut.getVelRange(1)
417 y = dataOut.getHeiRange()
420 y = dataOut.getHeiRange()
418
421
419 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
422 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
420 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
423 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
421 avg = numpy.average(z, axis=1)
424 avg = numpy.average(z, axis=1)
422
425
423 noise = dataOut.getNoise()
426 noise = dataOut.getNoise()
424
427
425 if not self.__isConfig:
428 if not self.__isConfig:
426
429
427 nplots = len(channelIndexList)
430 nplots = len(channelIndexList)
428
431
429 self.setup(idfigure=idfigure,
432 self.setup(idfigure=idfigure,
430 nplots=nplots,
433 nplots=nplots,
431 wintitle=wintitle,
434 wintitle=wintitle,
432 showprofile=showprofile)
435 showprofile=showprofile)
433
436
434 if xmin == None: xmin = numpy.nanmin(x)
437 if xmin == None: xmin = numpy.nanmin(x)
435 if xmax == None: xmax = numpy.nanmax(x)
438 if xmax == None: xmax = numpy.nanmax(x)
436 if ymin == None: ymin = numpy.nanmin(y)
439 if ymin == None: ymin = numpy.nanmin(y)
437 if ymax == None: ymax = numpy.nanmax(y)
440 if ymax == None: ymax = numpy.nanmax(y)
438 if zmin == None: zmin = numpy.nanmin(avg)*0.9
441 if zmin == None: zmin = numpy.nanmin(avg)*0.9
439 if zmax == None: zmax = numpy.nanmax(avg)*0.9
442 if zmax == None: zmax = numpy.nanmax(avg)*0.9
440
443
441 self.__isConfig = True
444 self.__isConfig = True
442
445
443 thisDatetime = dataOut.datatime
446 thisDatetime = dataOut.datatime
444 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
447 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
445 xlabel = "Velocity (m/s)"
448 xlabel = "Velocity (m/s)"
446 ylabel = "Range (Km)"
449 ylabel = "Range (Km)"
447
450
448 self.setWinTitle(title)
451 self.setWinTitle(title)
449
452
450 for i in range(self.nplots):
453 for i in range(self.nplots):
451 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
454 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
452 axes = self.axesList[i*self.__nsubplots]
455 axes = self.axesList[i*self.__nsubplots]
453 axes.pcolor(x, y, z[i,:,:],
456 axes.pcolor(x, y, z[i,:,:],
454 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
457 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
455 xlabel=xlabel, ylabel=ylabel, title=title,
458 xlabel=xlabel, ylabel=ylabel, title=title,
456 ticksize=9, cblabel='')
459 ticksize=9, cblabel='')
457
460
458 if self.__showprofile:
461 if self.__showprofile:
459 axes = self.axesList[i*self.__nsubplots +1]
462 axes = self.axesList[i*self.__nsubplots +1]
460 axes.pline(avg[i], y,
463 axes.pline(avg[i], y,
461 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
464 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
462 xlabel='dB', ylabel='', title='',
465 xlabel='dB', ylabel='', title='',
463 ytick_visible=False,
466 ytick_visible=False,
464 grid='x')
467 grid='x')
465
468
466 self.draw()
469 self.draw()
467
470
468 if save:
471 if save:
469 date = thisDatetime.strftime("%Y%m%d")
472 date = thisDatetime.strftime("%Y%m%d")
470 if figfile == None:
473 if figfile == None:
471 figfile = self.getFilename(name = date)
474 figfile = self.getFilename(name = date)
472
475
473 self.saveFigure(figpath, figfile)
476 self.saveFigure(figpath, figfile)
474
477
475 class Scope(Figure):
478 class Scope(Figure):
476
479
477 __isConfig = None
480 __isConfig = None
478
481
479 def __init__(self):
482 def __init__(self):
480
483
481 self.__isConfig = False
484 self.__isConfig = False
482 self.WIDTH = 600
485 self.WIDTH = 600
483 self.HEIGHT = 200
486 self.HEIGHT = 200
484
487
485 def getSubplots(self):
488 def getSubplots(self):
486
489
487 nrow = self.nplots
490 nrow = self.nplots
488 ncol = 3
491 ncol = 3
489 return nrow, ncol
492 return nrow, ncol
490
493
491 def setup(self, idfigure, nplots, wintitle):
494 def setup(self, idfigure, nplots, wintitle):
492
495
493 self.nplots = nplots
496 self.nplots = nplots
494
497
495 self.createFigure(idfigure, wintitle)
498 self.createFigure(idfigure, wintitle)
496
499
497 nrow,ncol = self.getSubplots()
500 nrow,ncol = self.getSubplots()
498 colspan = 3
501 colspan = 3
499 rowspan = 1
502 rowspan = 1
500
503
501 for i in range(nplots):
504 for i in range(nplots):
502 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
505 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
503
506
504
507
505
508
506 def run(self, dataOut, idfigure, wintitle="", channelList=None,
509 def run(self, dataOut, idfigure, wintitle="", channelList=None,
507 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
510 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
508
511
509 """
512 """
510
513
511 Input:
514 Input:
512 dataOut :
515 dataOut :
513 idfigure :
516 idfigure :
514 wintitle :
517 wintitle :
515 channelList :
518 channelList :
516 xmin : None,
519 xmin : None,
517 xmax : None,
520 xmax : None,
518 ymin : None,
521 ymin : None,
519 ymax : None,
522 ymax : None,
520 """
523 """
521
524
522 if channelList == None:
525 if channelList == None:
523 channelIndexList = dataOut.channelIndexList
526 channelIndexList = dataOut.channelIndexList
524 else:
527 else:
525 channelIndexList = []
528 channelIndexList = []
526 for channel in channelList:
529 for channel in channelList:
527 if channel not in dataOut.channelList:
530 if channel not in dataOut.channelList:
528 raise ValueError, "Channel %d is not in dataOut.channelList"
531 raise ValueError, "Channel %d is not in dataOut.channelList"
529 channelIndexList.append(dataOut.channelList.index(channel))
532 channelIndexList.append(dataOut.channelList.index(channel))
530
533
531 x = dataOut.heightList
534 x = dataOut.heightList
532 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
535 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
533 y = y.real
536 y = y.real
534
537
535 if not self.__isConfig:
538 if not self.__isConfig:
536 nplots = len(channelIndexList)
539 nplots = len(channelIndexList)
537
540
538 self.setup(idfigure=idfigure,
541 self.setup(idfigure=idfigure,
539 nplots=nplots,
542 nplots=nplots,
540 wintitle=wintitle)
543 wintitle=wintitle)
541
544
542 if xmin == None: xmin = numpy.nanmin(x)
545 if xmin == None: xmin = numpy.nanmin(x)
543 if xmax == None: xmax = numpy.nanmax(x)
546 if xmax == None: xmax = numpy.nanmax(x)
544 if ymin == None: ymin = numpy.nanmin(y)
547 if ymin == None: ymin = numpy.nanmin(y)
545 if ymax == None: ymax = numpy.nanmax(y)
548 if ymax == None: ymax = numpy.nanmax(y)
546
549
547 self.__isConfig = True
550 self.__isConfig = True
548
551
549
552
550 thisDatetime = dataOut.datatime
553 thisDatetime = dataOut.datatime
551 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
554 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
552 xlabel = "Range (Km)"
555 xlabel = "Range (Km)"
553 ylabel = "Intensity"
556 ylabel = "Intensity"
554
557
555 self.setWinTitle(title)
558 self.setWinTitle(title)
556
559
557 for i in range(len(self.axesList)):
560 for i in range(len(self.axesList)):
558 title = "Channel %d" %(i)
561 title = "Channel %d" %(i)
559 axes = self.axesList[i]
562 axes = self.axesList[i]
560 ychannel = y[i,:]
563 ychannel = y[i,:]
561 axes.pline(x, ychannel,
564 axes.pline(x, ychannel,
562 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
565 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
563 xlabel=xlabel, ylabel=ylabel, title=title)
566 xlabel=xlabel, ylabel=ylabel, title=title)
564
567
565 self.draw()
568 self.draw()
566
569
567 if save:
570 if save:
568 self.saveFigure(filename)
571 self.saveFigure(filename)
569
572
570 class ProfilePlot(Figure):
573 class ProfilePlot(Figure):
571 __isConfig = None
574 __isConfig = None
572 __nsubplots = None
575 __nsubplots = None
573
576
574 WIDTHPROF = None
577 WIDTHPROF = None
575 HEIGHTPROF = None
578 HEIGHTPROF = None
576 PREFIX = 'spcprofile'
579 PREFIX = 'spcprofile'
577
580
578 def __init__(self):
581 def __init__(self):
579 self.__isConfig = False
582 self.__isConfig = False
580 self.__nsubplots = 1
583 self.__nsubplots = 1
581
584
582 self.WIDTH = 300
585 self.WIDTH = 300
583 self.HEIGHT = 500
586 self.HEIGHT = 500
584
587
585 def getSubplots(self):
588 def getSubplots(self):
586 ncol = 1
589 ncol = 1
587 nrow = 1
590 nrow = 1
588
591
589 return nrow, ncol
592 return nrow, ncol
590
593
591 def setup(self, idfigure, nplots, wintitle):
594 def setup(self, idfigure, nplots, wintitle):
592
595
593 self.nplots = nplots
596 self.nplots = nplots
594
597
595 ncolspan = 1
598 ncolspan = 1
596 colspan = 1
599 colspan = 1
597
600
598 self.createFigure(idfigure = idfigure,
601 self.createFigure(idfigure = idfigure,
599 wintitle = wintitle,
602 wintitle = wintitle,
600 widthplot = self.WIDTH,
603 widthplot = self.WIDTH,
601 heightplot = self.HEIGHT)
604 heightplot = self.HEIGHT)
602
605
603 nrow, ncol = self.getSubplots()
606 nrow, ncol = self.getSubplots()
604
607
605 counter = 0
608 counter = 0
606 for y in range(nrow):
609 for y in range(nrow):
607 for x in range(ncol):
610 for x in range(ncol):
608 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
611 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
609
612
610 def run(self, dataOut, idfigure, wintitle="", channelList=None,
613 def run(self, dataOut, idfigure, wintitle="", channelList=None,
611 xmin=None, xmax=None, ymin=None, ymax=None,
614 xmin=None, xmax=None, ymin=None, ymax=None,
612 save=False, figpath='./', figfile=None):
615 save=False, figpath='./', figfile=None):
613
616
614 if channelList == None:
617 if channelList == None:
615 channelIndexList = dataOut.channelIndexList
618 channelIndexList = dataOut.channelIndexList
616 channelList = dataOut.channelList
619 channelList = dataOut.channelList
617 else:
620 else:
618 channelIndexList = []
621 channelIndexList = []
619 for channel in channelList:
622 for channel in channelList:
620 if channel not in dataOut.channelList:
623 if channel not in dataOut.channelList:
621 raise ValueError, "Channel %d is not in dataOut.channelList"
624 raise ValueError, "Channel %d is not in dataOut.channelList"
622 channelIndexList.append(dataOut.channelList.index(channel))
625 channelIndexList.append(dataOut.channelList.index(channel))
623
626
624
627
625 y = dataOut.getHeiRange()
628 y = dataOut.getHeiRange()
626 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
629 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
627 avg = numpy.average(x, axis=1)
630 avg = numpy.average(x, axis=1)
628
631
629
632
630 if not self.__isConfig:
633 if not self.__isConfig:
631
634
632 nplots = 1
635 nplots = 1
633
636
634 self.setup(idfigure=idfigure,
637 self.setup(idfigure=idfigure,
635 nplots=nplots,
638 nplots=nplots,
636 wintitle=wintitle)
639 wintitle=wintitle)
637
640
638 if ymin == None: ymin = numpy.nanmin(y)
641 if ymin == None: ymin = numpy.nanmin(y)
639 if ymax == None: ymax = numpy.nanmax(y)
642 if ymax == None: ymax = numpy.nanmax(y)
640 if xmin == None: xmin = numpy.nanmin(avg)*0.9
643 if xmin == None: xmin = numpy.nanmin(avg)*0.9
641 if xmax == None: xmax = numpy.nanmax(avg)*0.9
644 if xmax == None: xmax = numpy.nanmax(avg)*0.9
642
645
643 self.__isConfig = True
646 self.__isConfig = True
644
647
645 thisDatetime = dataOut.datatime
648 thisDatetime = dataOut.datatime
646 title = "Power Profile"
649 title = "Power Profile"
647 xlabel = "dB"
650 xlabel = "dB"
648 ylabel = "Range (Km)"
651 ylabel = "Range (Km)"
649
652
650 self.setWinTitle(title)
653 self.setWinTitle(title)
651
654
652
655
653 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
656 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
654 axes = self.axesList[0]
657 axes = self.axesList[0]
655
658
656 legendlabels = ["channel %d"%x for x in channelList]
659 legendlabels = ["channel %d"%x for x in channelList]
657 axes.pmultiline(avg, y,
660 axes.pmultiline(avg, y,
658 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
661 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
659 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
662 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
660 ytick_visible=True, nxticks=5,
663 ytick_visible=True, nxticks=5,
661 grid='x')
664 grid='x')
662
665
663 self.draw()
666 self.draw()
664
667
665 if save:
668 if save:
666 date = thisDatetime.strftime("%Y%m%d")
669 date = thisDatetime.strftime("%Y%m%d")
667 if figfile == None:
670 if figfile == None:
668 figfile = self.getFilename(name = date)
671 figfile = self.getFilename(name = date)
669
672
670 self.saveFigure(figpath, figfile)
673 self.saveFigure(figpath, figfile)
671
674
672 class CoherencePlot(Figure):
675 class CoherenceMap(Figure):
673 __isConfig = None
676 __isConfig = None
674 __nsubplots = None
677 __nsubplots = None
675
678
676 WIDTHPROF = None
679 WIDTHPROF = None
677 HEIGHTPROF = None
680 HEIGHTPROF = None
678 PREFIX = 'coherencemap'
681 PREFIX = 'coherencemap'
679
682
680 def __init__(self):
683 def __init__(self):
681 self.timerange = 24*60*60
684 self.timerange = 24*60*60
682 self.__isConfig = False
685 self.__isConfig = False
683 self.__nsubplots = 1
686 self.__nsubplots = 1
684
687
685 self.WIDTH = 800
688 self.WIDTH = 800
686 self.HEIGHT = 200
689 self.HEIGHT = 200
687 self.WIDTHPROF = 120
690 self.WIDTHPROF = 120
688 self.HEIGHTPROF = 0
691 self.HEIGHTPROF = 0
689
692
690 def getSubplots(self):
693 def getSubplots(self):
691 ncol = 1
694 ncol = 1
692 nrow = self.nplots*2
695 nrow = self.nplots*2
693
696
694 return nrow, ncol
697 return nrow, ncol
695
698
696 def setup(self, idfigure, nplots, wintitle, showprofile=True):
699 def setup(self, idfigure, nplots, wintitle, showprofile=True):
697 self.__showprofile = showprofile
700 self.__showprofile = showprofile
698 self.nplots = nplots
701 self.nplots = nplots
699
702
700 ncolspan = 1
703 ncolspan = 1
701 colspan = 1
704 colspan = 1
702 if showprofile:
705 if showprofile:
703 ncolspan = 7
706 ncolspan = 7
704 colspan = 6
707 colspan = 6
705 self.__nsubplots = 2
708 self.__nsubplots = 2
706
709
707 self.createFigure(idfigure = idfigure,
710 self.createFigure(idfigure = idfigure,
708 wintitle = wintitle,
711 wintitle = wintitle,
709 widthplot = self.WIDTH + self.WIDTHPROF,
712 widthplot = self.WIDTH + self.WIDTHPROF,
710 heightplot = self.HEIGHT + self.HEIGHTPROF)
713 heightplot = self.HEIGHT + self.HEIGHTPROF)
711
714
712 nrow, ncol = self.getSubplots()
715 nrow, ncol = self.getSubplots()
713
716
714 for y in range(nrow):
717 for y in range(nrow):
715 for x in range(ncol):
718 for x in range(ncol):
716
719
717 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
720 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
718
721
719 if showprofile:
722 if showprofile:
720 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
723 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
721
724
722 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
725 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
723 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
726 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
724 timerange=None,
727 timerange=None,
725 save=False, figpath='./', figfile=None):
728 save=False, figpath='./', figfile=None):
726
729
727 if pairsList == None:
730 if pairsList == None:
728 pairsIndexList = dataOut.pairsIndexList
731 pairsIndexList = dataOut.pairsIndexList
729 else:
732 else:
730 pairsIndexList = []
733 pairsIndexList = []
731 for pair in pairsList:
734 for pair in pairsList:
732 if pair not in dataOut.pairsList:
735 if pair not in dataOut.pairsList:
733 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
736 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
734 pairsIndexList.append(dataOut.pairsList.index(pair))
737 pairsIndexList.append(dataOut.pairsList.index(pair))
735
738
736 if timerange != None:
739 if timerange != None:
737 self.timerange = timerange
740 self.timerange = timerange
738
741
742 if pairsIndexList == []:
743 return
744
745 if len(pairsIndexList) > 4:
746 pairsIndexList = pairsIndexList[0:4]
747
739 tmin = None
748 tmin = None
740 tmax = None
749 tmax = None
741 x = dataOut.getTimeRange()
750 x = dataOut.getTimeRange()
742 y = dataOut.getHeiRange()
751 y = dataOut.getHeiRange()
743
752
744 if not self.__isConfig:
753 if not self.__isConfig:
745 nplots = len(pairsIndexList)
754 nplots = len(pairsIndexList)
746 self.setup(idfigure=idfigure,
755 self.setup(idfigure=idfigure,
747 nplots=nplots,
756 nplots=nplots,
748 wintitle=wintitle,
757 wintitle=wintitle,
749 showprofile=showprofile)
758 showprofile=showprofile)
750
759
751 tmin, tmax = self.getTimeLim(x, xmin, xmax)
760 tmin, tmax = self.getTimeLim(x, xmin, xmax)
752 if ymin == None: ymin = numpy.nanmin(y)
761 if ymin == None: ymin = numpy.nanmin(y)
753 if ymax == None: ymax = numpy.nanmax(y)
762 if ymax == None: ymax = numpy.nanmax(y)
754
763
755 self.__isConfig = True
764 self.__isConfig = True
756
765
757 thisDatetime = dataOut.datatime
766 thisDatetime = dataOut.datatime
758 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
767 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
759 xlabel = ""
768 xlabel = ""
760 ylabel = "Range (Km)"
769 ylabel = "Range (Km)"
761
770
762 self.setWinTitle(title)
771 self.setWinTitle(title)
763
772
764 for i in range(self.nplots):
773 for i in range(self.nplots):
765
774
766 pair = dataOut.pairsList[pairsIndexList[i]]
775 pair = dataOut.pairsList[pairsIndexList[i]]
767 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
776 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
768 coherence = numpy.abs(coherenceComplex)
777 coherence = numpy.abs(coherenceComplex)
769 avg = numpy.average(coherence, axis=0)
778 avg = numpy.average(coherence, axis=0)
770 z = avg.reshape((1,-1))
779 z = avg.reshape((1,-1))
771
780
772 counter = 0
781 counter = 0
773
782
774 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
783 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
775 axes = self.axesList[i*self.__nsubplots*2]
784 axes = self.axesList[i*self.__nsubplots*2]
776 axes.pcolor(x, y, z,
785 axes.pcolor(x, y, z,
777 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
786 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
778 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
787 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
779 ticksize=9, cblabel='', cbsize="1%")
788 ticksize=9, cblabel='', cbsize="1%")
780
789
781 if self.__showprofile:
790 if self.__showprofile:
782 counter += 1
791 counter += 1
783 axes = self.axesList[i*self.__nsubplots*2 + counter]
792 axes = self.axesList[i*self.__nsubplots*2 + counter]
784 axes.pline(avg, y,
793 axes.pline(avg, y,
785 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
794 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
786 xlabel='', ylabel='', title='', ticksize=7,
795 xlabel='', ylabel='', title='', ticksize=7,
787 ytick_visible=False, nxticks=5,
796 ytick_visible=False, nxticks=5,
788 grid='x')
797 grid='x')
789
798
790 counter += 1
799 counter += 1
791 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
800 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
792 avg = numpy.average(phase, axis=0)
801 avg = numpy.average(phase, axis=0)
793 z = avg.reshape((1,-1))
802 z = avg.reshape((1,-1))
794
803
795 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
804 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
796 axes = self.axesList[i*self.__nsubplots*2 + counter]
805 axes = self.axesList[i*self.__nsubplots*2 + counter]
797 axes.pcolor(x, y, z,
806 axes.pcolor(x, y, z,
798 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
807 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
799 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
808 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
800 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
809 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
801
810
802 if self.__showprofile:
811 if self.__showprofile:
803 counter += 1
812 counter += 1
804 axes = self.axesList[i*self.__nsubplots*2 + counter]
813 axes = self.axesList[i*self.__nsubplots*2 + counter]
805 axes.pline(avg, y,
814 axes.pline(avg, y,
806 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
815 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
807 xlabel='', ylabel='', title='', ticksize=7,
816 xlabel='', ylabel='', title='', ticksize=7,
808 ytick_visible=False, nxticks=4,
817 ytick_visible=False, nxticks=4,
809 grid='x')
818 grid='x')
810
819
811 self.draw()
820 self.draw()
812
821
813 if save:
822 if save:
814 date = thisDatetime.strftime("%Y%m%d")
823 date = thisDatetime.strftime("%Y%m%d")
815 if figfile == None:
824 if figfile == None:
816 figfile = self.getFilename(name = date)
825 figfile = self.getFilename(name = date)
817
826
818 self.saveFigure(figpath, figfile)
827 self.saveFigure(figpath, figfile)
819
828
820 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
829 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
821 self.__isConfig = False
830 self.__isConfig = False
822
831
823 class RTIfromNoise(Figure):
832 class RTIfromNoise(Figure):
824
833
825 __isConfig = None
834 __isConfig = None
826 __nsubplots = None
835 __nsubplots = None
827
836
828 WIDTHPROF = None
837 WIDTHPROF = None
829 HEIGHTPROF = None
838 HEIGHTPROF = None
830 PREFIX = 'rti'
839 PREFIX = 'rti'
831
840
832 def __init__(self):
841 def __init__(self):
833
842
834 self.__timerange = 24*60*60
843 self.__timerange = 24*60*60
835 self.__isConfig = False
844 self.__isConfig = False
836 self.__nsubplots = 1
845 self.__nsubplots = 1
837
846
838 self.WIDTH = 800
847 self.WIDTH = 800
839 self.HEIGHT = 200
848 self.HEIGHT = 200
840
849
841 def getSubplots(self):
850 def getSubplots(self):
842
851
843 ncol = 1
852 ncol = 1
844 nrow = self.nplots
853 nrow = self.nplots
845
854
846 return nrow, ncol
855 return nrow, ncol
847
856
848 def setup(self, idfigure, nplots, wintitle, showprofile=True):
857 def setup(self, idfigure, nplots, wintitle, showprofile=True):
849
858
850 self.__showprofile = showprofile
859 self.__showprofile = showprofile
851 self.nplots = nplots
860 self.nplots = nplots
852
861
853 ncolspan = 1
862 ncolspan = 1
854 colspan = 1
863 colspan = 1
855
864
856 self.createFigure(idfigure = idfigure,
865 self.createFigure(idfigure = idfigure,
857 wintitle = wintitle,
866 wintitle = wintitle,
858 widthplot = self.WIDTH + self.WIDTHPROF,
867 widthplot = self.WIDTH + self.WIDTHPROF,
859 heightplot = self.HEIGHT + self.HEIGHTPROF)
868 heightplot = self.HEIGHT + self.HEIGHTPROF)
860
869
861 nrow, ncol = self.getSubplots()
870 nrow, ncol = self.getSubplots()
862
871
863 self.addAxes(nrow, ncol, 0, 0, 1, 1)
872 self.addAxes(nrow, ncol, 0, 0, 1, 1)
864
873
865
874
866
875
867 def __getTimeLim(self, x, xmin, xmax):
876 def __getTimeLim(self, x, xmin, xmax):
868
877
869 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
878 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
870 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
879 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
871
880
872 ####################################################
881 ####################################################
873 #If the x is out of xrange
882 #If the x is out of xrange
874 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
883 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
875 xmin = None
884 xmin = None
876 xmax = None
885 xmax = None
877
886
878 if xmin == None:
887 if xmin == None:
879 td = thisdatetime - thisdate
888 td = thisdatetime - thisdate
880 xmin = td.seconds/(60*60.)
889 xmin = td.seconds/(60*60.)
881
890
882 if xmax == None:
891 if xmax == None:
883 xmax = xmin + self.__timerange/(60*60.)
892 xmax = xmin + self.__timerange/(60*60.)
884
893
885 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
894 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
886 tmin = time.mktime(mindt.timetuple())
895 tmin = time.mktime(mindt.timetuple())
887
896
888 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
897 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
889 tmax = time.mktime(maxdt.timetuple())
898 tmax = time.mktime(maxdt.timetuple())
890
899
891 self.__timerange = tmax - tmin
900 self.__timerange = tmax - tmin
892
901
893 return tmin, tmax
902 return tmin, tmax
894
903
895 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
904 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
896 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
905 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
897 timerange=None,
906 timerange=None,
898 save=False, figpath='./', figfile=None):
907 save=False, figpath='./', figfile=None):
899
908
900 if channelList == None:
909 if channelList == None:
901 channelIndexList = dataOut.channelIndexList
910 channelIndexList = dataOut.channelIndexList
902 else:
911 else:
903 channelIndexList = []
912 channelIndexList = []
904 for channel in channelList:
913 for channel in channelList:
905 if channel not in dataOut.channelList:
914 if channel not in dataOut.channelList:
906 raise ValueError, "Channel %d is not in dataOut.channelList"
915 raise ValueError, "Channel %d is not in dataOut.channelList"
907 channelIndexList.append(dataOut.channelList.index(channel))
916 channelIndexList.append(dataOut.channelList.index(channel))
908
917
909 if timerange != None:
918 if timerange != None:
910 self.__timerange = timerange
919 self.__timerange = timerange
911
920
912 tmin = None
921 tmin = None
913 tmax = None
922 tmax = None
914 x = dataOut.getTimeRange()
923 x = dataOut.getTimeRange()
915 y = dataOut.getHeiRange()
924 y = dataOut.getHeiRange()
916 x1 = dataOut.datatime
925 x1 = dataOut.datatime
917 # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
926 # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
918 # avg = numpy.average(z, axis=1)
927 # avg = numpy.average(z, axis=1)
919
928
920 noise = dataOut.getNoise()
929 noise = dataOut.getNoise()
921
930
922 if not self.__isConfig:
931 if not self.__isConfig:
923
932
924 nplots = len(channelIndexList)
933 nplots = len(channelIndexList)
925
934
926 self.setup(idfigure=idfigure,
935 self.setup(idfigure=idfigure,
927 nplots=nplots,
936 nplots=nplots,
928 wintitle=wintitle,
937 wintitle=wintitle,
929 showprofile=showprofile)
938 showprofile=showprofile)
930
939
931 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
940 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
932 if ymin == None: ymin = numpy.nanmin(y)
941 if ymin == None: ymin = numpy.nanmin(y)
933 if ymax == None: ymax = numpy.nanmax(y)
942 if ymax == None: ymax = numpy.nanmax(y)
934 if zmin == None: zmin = numpy.nanmin(avg)*0.9
943 if zmin == None: zmin = numpy.nanmin(avg)*0.9
935 if zmax == None: zmax = numpy.nanmax(avg)*0.9
944 if zmax == None: zmax = numpy.nanmax(avg)*0.9
936
945
937 self.__isConfig = True
946 self.__isConfig = True
938
947
939 thisDatetime = dataOut.datatime
948 thisDatetime = dataOut.datatime
940 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
949 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
941 xlabel = "Velocity (m/s)"
950 xlabel = "Velocity (m/s)"
942 ylabel = "Range (Km)"
951 ylabel = "Range (Km)"
943
952
944 self.setWinTitle(title)
953 self.setWinTitle(title)
945
954
946 for i in range(self.nplots):
955 for i in range(self.nplots):
947 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
956 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
948 axes = self.axesList[i*self.__nsubplots]
957 axes = self.axesList[i*self.__nsubplots]
949 z = avg[i].reshape((1,-1))
958 z = avg[i].reshape((1,-1))
950 axes.pcolor(x, y, z,
959 axes.pcolor(x, y, z,
951 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
960 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
952 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
961 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
953 ticksize=9, cblabel='', cbsize="1%")
962 ticksize=9, cblabel='', cbsize="1%")
954
963
955
964
956 self.draw()
965 self.draw()
957
966
958 if save:
967 if save:
959 date = thisDatetime.strftime("%Y%m%d")
968 date = thisDatetime.strftime("%Y%m%d")
960 if figfile == None:
969 if figfile == None:
961 figfile = self.getFilename(name = date)
970 figfile = self.getFilename(name = date)
962
971
963 self.saveFigure(figpath, figfile)
972 self.saveFigure(figpath, figfile)
964
973
965 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
974 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
966 self.__isConfig = False
975 self.__isConfig = False
967 No newline at end of file
976
@@ -1,1150 +1,1151
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 class ProcessingUnit:
15 class ProcessingUnit:
16
16
17 """
17 """
18 Esta es la clase base para el procesamiento de datos.
18 Esta es la clase base para el procesamiento de datos.
19
19
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
21 - Metodos internos (callMethod)
21 - Metodos internos (callMethod)
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
23 tienen que ser agreagados con el metodo "add".
23 tienen que ser agreagados con el metodo "add".
24
24
25 """
25 """
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
27 dataIn = None
27 dataIn = None
28
28
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
30 dataOut = None
30 dataOut = None
31
31
32
32
33 objectDict = None
33 objectDict = None
34
34
35 def __init__(self):
35 def __init__(self):
36
36
37 self.objectDict = {}
37 self.objectDict = {}
38
38
39 def init(self):
39 def init(self):
40
40
41 raise ValueError, "Not implemented"
41 raise ValueError, "Not implemented"
42
42
43 def addOperation(self, object, objId):
43 def addOperation(self, object, objId):
44
44
45 """
45 """
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
47 identificador asociado a este objeto.
47 identificador asociado a este objeto.
48
48
49 Input:
49 Input:
50
50
51 object : objeto de la clase "Operation"
51 object : objeto de la clase "Operation"
52
52
53 Return:
53 Return:
54
54
55 objId : identificador del objeto, necesario para ejecutar la operacion
55 objId : identificador del objeto, necesario para ejecutar la operacion
56 """
56 """
57
57
58 self.objectDict[objId] = object
58 self.objectDict[objId] = object
59
59
60 return objId
60 return objId
61
61
62 def operation(self, **kwargs):
62 def operation(self, **kwargs):
63
63
64 """
64 """
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
66 atributos del objeto dataOut
66 atributos del objeto dataOut
67
67
68 Input:
68 Input:
69
69
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
71 """
71 """
72
72
73 raise ValueError, "ImplementedError"
73 raise ValueError, "ImplementedError"
74
74
75 def callMethod(self, name, **kwargs):
75 def callMethod(self, name, **kwargs):
76
76
77 """
77 """
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
79
79
80 Input:
80 Input:
81 name : nombre del metodo a ejecutar
81 name : nombre del metodo a ejecutar
82
82
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
84
84
85 """
85 """
86 if name != 'run':
86 if name != 'run':
87
87
88 if name == 'init' and self.dataIn.isEmpty():
88 if name == 'init' and self.dataIn.isEmpty():
89 self.dataOut.flagNoData = True
89 self.dataOut.flagNoData = True
90 return False
90 return False
91
91
92 if name != 'init' and self.dataOut.isEmpty():
92 if name != 'init' and self.dataOut.isEmpty():
93 return False
93 return False
94
94
95 methodToCall = getattr(self, name)
95 methodToCall = getattr(self, name)
96
96
97 methodToCall(**kwargs)
97 methodToCall(**kwargs)
98
98
99 if name != 'run':
99 if name != 'run':
100 return True
100 return True
101
101
102 if self.dataOut.isEmpty():
102 if self.dataOut.isEmpty():
103 return False
103 return False
104
104
105 return True
105 return True
106
106
107 def callObject(self, objId, **kwargs):
107 def callObject(self, objId, **kwargs):
108
108
109 """
109 """
110 Ejecuta la operacion asociada al identificador del objeto "objId"
110 Ejecuta la operacion asociada al identificador del objeto "objId"
111
111
112 Input:
112 Input:
113
113
114 objId : identificador del objeto a ejecutar
114 objId : identificador del objeto a ejecutar
115
115
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
117
117
118 Return:
118 Return:
119
119
120 None
120 None
121 """
121 """
122
122
123 if self.dataOut.isEmpty():
123 if self.dataOut.isEmpty():
124 return False
124 return False
125
125
126 object = self.objectDict[objId]
126 object = self.objectDict[objId]
127
127
128 object.run(self.dataOut, **kwargs)
128 object.run(self.dataOut, **kwargs)
129
129
130 return True
130 return True
131
131
132 def call(self, operationConf, **kwargs):
132 def call(self, operationConf, **kwargs):
133
133
134 """
134 """
135 Return True si ejecuta la operacion "operationConf.name" con los
135 Return True si ejecuta la operacion "operationConf.name" con los
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 La operacion puede ser de dos tipos:
137 La operacion puede ser de dos tipos:
138
138
139 1. Un metodo propio de esta clase:
139 1. Un metodo propio de esta clase:
140
140
141 operation.type = "self"
141 operation.type = "self"
142
142
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
144 operation.type = "other".
144 operation.type = "other".
145
145
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
147 "addOperation" e identificado con el operation.id
147 "addOperation" e identificado con el operation.id
148
148
149
149
150 con el id de la operacion.
150 con el id de la operacion.
151
151
152 Input:
152 Input:
153
153
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
155
155
156 """
156 """
157
157
158 if operationConf.type == 'self':
158 if operationConf.type == 'self':
159 sts = self.callMethod(operationConf.name, **kwargs)
159 sts = self.callMethod(operationConf.name, **kwargs)
160
160
161 if operationConf.type == 'other':
161 if operationConf.type == 'other':
162 sts = self.callObject(operationConf.id, **kwargs)
162 sts = self.callObject(operationConf.id, **kwargs)
163
163
164 return sts
164 return sts
165
165
166 def setInput(self, dataIn):
166 def setInput(self, dataIn):
167
167
168 self.dataIn = dataIn
168 self.dataIn = dataIn
169
169
170 def getOutput(self):
170 def getOutput(self):
171
171
172 return self.dataOut
172 return self.dataOut
173
173
174 class Operation():
174 class Operation():
175
175
176 """
176 """
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
179 acumulacion dentro de esta clase
179 acumulacion dentro de esta clase
180
180
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
182
182
183 """
183 """
184
184
185 __buffer = None
185 __buffer = None
186 __isConfig = False
186 __isConfig = False
187
187
188 def __init__(self):
188 def __init__(self):
189
189
190 pass
190 pass
191
191
192 def run(self, dataIn, **kwargs):
192 def run(self, dataIn, **kwargs):
193
193
194 """
194 """
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
196
196
197 Input:
197 Input:
198
198
199 dataIn : objeto del tipo JROData
199 dataIn : objeto del tipo JROData
200
200
201 Return:
201 Return:
202
202
203 None
203 None
204
204
205 Affected:
205 Affected:
206 __buffer : buffer de recepcion de datos.
206 __buffer : buffer de recepcion de datos.
207
207
208 """
208 """
209
209
210 raise ValueError, "ImplementedError"
210 raise ValueError, "ImplementedError"
211
211
212 class VoltageProc(ProcessingUnit):
212 class VoltageProc(ProcessingUnit):
213
213
214
214
215 def __init__(self):
215 def __init__(self):
216
216
217 self.objectDict = {}
217 self.objectDict = {}
218 self.dataOut = Voltage()
218 self.dataOut = Voltage()
219
219
220 def init(self):
220 def init(self):
221
221
222 self.dataOut.copy(self.dataIn)
222 self.dataOut.copy(self.dataIn)
223 # No necesita copiar en cada init() los atributos de dataIn
223 # No necesita copiar en cada init() los atributos de dataIn
224 # la copia deberia hacerse por cada nuevo bloque de datos
224 # la copia deberia hacerse por cada nuevo bloque de datos
225
225
226 def selectChannels(self, channelList):
226 def selectChannels(self, channelList):
227
227
228 channelIndexList = []
228 channelIndexList = []
229
229
230 for channel in channelList:
230 for channel in channelList:
231 index = self.dataOut.channelList.index(channel)
231 index = self.dataOut.channelList.index(channel)
232 channelIndexList.append(index)
232 channelIndexList.append(index)
233
233
234 self.selectChannelsByIndex(channelIndexList)
234 self.selectChannelsByIndex(channelIndexList)
235
235
236 def selectChannelsByIndex(self, channelIndexList):
236 def selectChannelsByIndex(self, channelIndexList):
237 """
237 """
238 Selecciona un bloque de datos en base a canales segun el channelIndexList
238 Selecciona un bloque de datos en base a canales segun el channelIndexList
239
239
240 Input:
240 Input:
241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
242
242
243 Affected:
243 Affected:
244 self.dataOut.data
244 self.dataOut.data
245 self.dataOut.channelIndexList
245 self.dataOut.channelIndexList
246 self.dataOut.nChannels
246 self.dataOut.nChannels
247 self.dataOut.m_ProcessingHeader.totalSpectra
247 self.dataOut.m_ProcessingHeader.totalSpectra
248 self.dataOut.systemHeaderObj.numChannels
248 self.dataOut.systemHeaderObj.numChannels
249 self.dataOut.m_ProcessingHeader.blockSize
249 self.dataOut.m_ProcessingHeader.blockSize
250
250
251 Return:
251 Return:
252 None
252 None
253 """
253 """
254
254
255 for channelIndex in channelIndexList:
255 for channelIndex in channelIndexList:
256 if channelIndex not in self.dataOut.channelIndexList:
256 if channelIndex not in self.dataOut.channelIndexList:
257 print channelIndexList
257 print channelIndexList
258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
259
259
260 nChannels = len(channelIndexList)
260 nChannels = len(channelIndexList)
261
261
262 data = self.dataOut.data[channelIndexList,:]
262 data = self.dataOut.data[channelIndexList,:]
263
263
264 self.dataOut.data = data
264 self.dataOut.data = data
265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
266 # self.dataOut.nChannels = nChannels
266 # self.dataOut.nChannels = nChannels
267
267
268 return 1
268 return 1
269
269
270 def selectHeights(self, minHei, maxHei):
270 def selectHeights(self, minHei, maxHei):
271 """
271 """
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
273 minHei <= height <= maxHei
273 minHei <= height <= maxHei
274
274
275 Input:
275 Input:
276 minHei : valor minimo de altura a considerar
276 minHei : valor minimo de altura a considerar
277 maxHei : valor maximo de altura a considerar
277 maxHei : valor maximo de altura a considerar
278
278
279 Affected:
279 Affected:
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
281
281
282 Return:
282 Return:
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
284 """
284 """
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
287
287
288 if (maxHei > self.dataOut.heightList[-1]):
288 if (maxHei > self.dataOut.heightList[-1]):
289 maxHei = self.dataOut.heightList[-1]
289 maxHei = self.dataOut.heightList[-1]
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
291
291
292 minIndex = 0
292 minIndex = 0
293 maxIndex = 0
293 maxIndex = 0
294 data = self.dataOut.heightList
294 data = self.dataOut.heightList
295
295
296 for i,val in enumerate(data):
296 for i,val in enumerate(data):
297 if val < minHei:
297 if val < minHei:
298 continue
298 continue
299 else:
299 else:
300 minIndex = i;
300 minIndex = i;
301 break
301 break
302
302
303 for i,val in enumerate(data):
303 for i,val in enumerate(data):
304 if val <= maxHei:
304 if val <= maxHei:
305 maxIndex = i;
305 maxIndex = i;
306 else:
306 else:
307 break
307 break
308
308
309 self.selectHeightsByIndex(minIndex, maxIndex)
309 self.selectHeightsByIndex(minIndex, maxIndex)
310
310
311 return 1
311 return 1
312
312
313
313
314 def selectHeightsByIndex(self, minIndex, maxIndex):
314 def selectHeightsByIndex(self, minIndex, maxIndex):
315 """
315 """
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
317 minIndex <= index <= maxIndex
317 minIndex <= index <= maxIndex
318
318
319 Input:
319 Input:
320 minIndex : valor de indice minimo de altura a considerar
320 minIndex : valor de indice minimo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
322
322
323 Affected:
323 Affected:
324 self.dataOut.data
324 self.dataOut.data
325 self.dataOut.heightList
325 self.dataOut.heightList
326
326
327 Return:
327 Return:
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
329 """
329 """
330
330
331 if (minIndex < 0) or (minIndex > maxIndex):
331 if (minIndex < 0) or (minIndex > maxIndex):
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
333
333
334 if (maxIndex >= self.dataOut.nHeights):
334 if (maxIndex >= self.dataOut.nHeights):
335 maxIndex = self.dataOut.nHeights-1
335 maxIndex = self.dataOut.nHeights-1
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
337
337
338 nHeights = maxIndex - minIndex + 1
338 nHeights = maxIndex - minIndex + 1
339
339
340 #voltage
340 #voltage
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
342
342
343 firstHeight = self.dataOut.heightList[minIndex]
343 firstHeight = self.dataOut.heightList[minIndex]
344
344
345 self.dataOut.data = data
345 self.dataOut.data = data
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
347
347
348 return 1
348 return 1
349
349
350
350
351 def filterByHeights(self, window):
351 def filterByHeights(self, window):
352 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
352 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
353
353
354 if window == None:
354 if window == None:
355 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
355 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
356
356
357 newdelta = deltaHeight * window
357 newdelta = deltaHeight * window
358 r = self.dataOut.data.shape[1] % window
358 r = self.dataOut.data.shape[1] % window
359 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
359 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
360 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
360 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
361 buffer = numpy.average(buffer,2)
361 buffer = numpy.average(buffer,2)
362 self.dataOut.data = buffer
362 self.dataOut.data = buffer
363 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
363 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
364
364
365
365
366
366
367 class CohInt(Operation):
367 class CohInt(Operation):
368
368
369 __isConfig = False
369 __isConfig = False
370
370
371 __profIndex = 0
371 __profIndex = 0
372 __withOverapping = False
372 __withOverapping = False
373
373
374 __byTime = False
374 __byTime = False
375 __initime = None
375 __initime = None
376 __lastdatatime = None
376 __lastdatatime = None
377 __integrationtime = None
377 __integrationtime = None
378
378
379 __buffer = None
379 __buffer = None
380
380
381 __dataReady = False
381 __dataReady = False
382
382
383 n = None
383 n = None
384
384
385
385
386 def __init__(self):
386 def __init__(self):
387
387
388 self.__isConfig = False
388 self.__isConfig = False
389
389
390 def setup(self, n=None, timeInterval=None, overlapping=False):
390 def setup(self, n=None, timeInterval=None, overlapping=False):
391 """
391 """
392 Set the parameters of the integration class.
392 Set the parameters of the integration class.
393
393
394 Inputs:
394 Inputs:
395
395
396 n : Number of coherent integrations
396 n : Number of coherent integrations
397 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
397 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
398 overlapping :
398 overlapping :
399
399
400 """
400 """
401
401
402 self.__initime = None
402 self.__initime = None
403 self.__lastdatatime = 0
403 self.__lastdatatime = 0
404 self.__buffer = None
404 self.__buffer = None
405 self.__dataReady = False
405 self.__dataReady = False
406
406
407
407
408 if n == None and timeInterval == None:
408 if n == None and timeInterval == None:
409 raise ValueError, "n or timeInterval should be specified ..."
409 raise ValueError, "n or timeInterval should be specified ..."
410
410
411 if n != None:
411 if n != None:
412 self.n = n
412 self.n = n
413 self.__byTime = False
413 self.__byTime = False
414 else:
414 else:
415 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
415 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
416 self.n = 9999
416 self.n = 9999
417 self.__byTime = True
417 self.__byTime = True
418
418
419 if overlapping:
419 if overlapping:
420 self.__withOverapping = True
420 self.__withOverapping = True
421 self.__buffer = None
421 self.__buffer = None
422 else:
422 else:
423 self.__withOverapping = False
423 self.__withOverapping = False
424 self.__buffer = 0
424 self.__buffer = 0
425
425
426 self.__profIndex = 0
426 self.__profIndex = 0
427
427
428 def putData(self, data):
428 def putData(self, data):
429
429
430 """
430 """
431 Add a profile to the __buffer and increase in one the __profileIndex
431 Add a profile to the __buffer and increase in one the __profileIndex
432
432
433 """
433 """
434
434
435 if not self.__withOverapping:
435 if not self.__withOverapping:
436 self.__buffer += data.copy()
436 self.__buffer += data.copy()
437 self.__profIndex += 1
437 self.__profIndex += 1
438 return
438 return
439
439
440 #Overlapping data
440 #Overlapping data
441 nChannels, nHeis = data.shape
441 nChannels, nHeis = data.shape
442 data = numpy.reshape(data, (1, nChannels, nHeis))
442 data = numpy.reshape(data, (1, nChannels, nHeis))
443
443
444 #If the buffer is empty then it takes the data value
444 #If the buffer is empty then it takes the data value
445 if self.__buffer == None:
445 if self.__buffer == None:
446 self.__buffer = data
446 self.__buffer = data
447 self.__profIndex += 1
447 self.__profIndex += 1
448 return
448 return
449
449
450 #If the buffer length is lower than n then stakcing the data value
450 #If the buffer length is lower than n then stakcing the data value
451 if self.__profIndex < self.n:
451 if self.__profIndex < self.n:
452 self.__buffer = numpy.vstack((self.__buffer, data))
452 self.__buffer = numpy.vstack((self.__buffer, data))
453 self.__profIndex += 1
453 self.__profIndex += 1
454 return
454 return
455
455
456 #If the buffer length is equal to n then replacing the last buffer value with the data value
456 #If the buffer length is equal to n then replacing the last buffer value with the data value
457 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
457 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
458 self.__buffer[self.n-1] = data
458 self.__buffer[self.n-1] = data
459 self.__profIndex = self.n
459 self.__profIndex = self.n
460 return
460 return
461
461
462
462
463 def pushData(self):
463 def pushData(self):
464 """
464 """
465 Return the sum of the last profiles and the profiles used in the sum.
465 Return the sum of the last profiles and the profiles used in the sum.
466
466
467 Affected:
467 Affected:
468
468
469 self.__profileIndex
469 self.__profileIndex
470
470
471 """
471 """
472
472
473 if not self.__withOverapping:
473 if not self.__withOverapping:
474 data = self.__buffer
474 data = self.__buffer
475 n = self.__profIndex
475 n = self.__profIndex
476
476
477 self.__buffer = 0
477 self.__buffer = 0
478 self.__profIndex = 0
478 self.__profIndex = 0
479
479
480 return data, n
480 return data, n
481
481
482 #Integration with Overlapping
482 #Integration with Overlapping
483 data = numpy.sum(self.__buffer, axis=0)
483 data = numpy.sum(self.__buffer, axis=0)
484 n = self.__profIndex
484 n = self.__profIndex
485
485
486 return data, n
486 return data, n
487
487
488 def byProfiles(self, data):
488 def byProfiles(self, data):
489
489
490 self.__dataReady = False
490 self.__dataReady = False
491 avgdata = None
491 avgdata = None
492 n = None
492 n = None
493
493
494 self.putData(data)
494 self.putData(data)
495
495
496 if self.__profIndex == self.n:
496 if self.__profIndex == self.n:
497
497
498 avgdata, n = self.pushData()
498 avgdata, n = self.pushData()
499 self.__dataReady = True
499 self.__dataReady = True
500
500
501 return avgdata
501 return avgdata
502
502
503 def byTime(self, data, datatime):
503 def byTime(self, data, datatime):
504
504
505 self.__dataReady = False
505 self.__dataReady = False
506 avgdata = None
506 avgdata = None
507 n = None
507 n = None
508
508
509 self.putData(data)
509 self.putData(data)
510
510
511 if (datatime - self.__initime) >= self.__integrationtime:
511 if (datatime - self.__initime) >= self.__integrationtime:
512 avgdata, n = self.pushData()
512 avgdata, n = self.pushData()
513 self.n = n
513 self.n = n
514 self.__dataReady = True
514 self.__dataReady = True
515
515
516 return avgdata
516 return avgdata
517
517
518 def integrate(self, data, datatime=None):
518 def integrate(self, data, datatime=None):
519
519
520 if self.__initime == None:
520 if self.__initime == None:
521 self.__initime = datatime
521 self.__initime = datatime
522
522
523 if self.__byTime:
523 if self.__byTime:
524 avgdata = self.byTime(data, datatime)
524 avgdata = self.byTime(data, datatime)
525 else:
525 else:
526 avgdata = self.byProfiles(data)
526 avgdata = self.byProfiles(data)
527
527
528
528
529 self.__lastdatatime = datatime
529 self.__lastdatatime = datatime
530
530
531 if avgdata == None:
531 if avgdata == None:
532 return None, None
532 return None, None
533
533
534 avgdatatime = self.__initime
534 avgdatatime = self.__initime
535
535
536 deltatime = datatime -self.__lastdatatime
536 deltatime = datatime -self.__lastdatatime
537
537
538 if not self.__withOverapping:
538 if not self.__withOverapping:
539 self.__initime = datatime
539 self.__initime = datatime
540 else:
540 else:
541 self.__initime += deltatime
541 self.__initime += deltatime
542
542
543 return avgdata, avgdatatime
543 return avgdata, avgdatatime
544
544
545 def run(self, dataOut, **kwargs):
545 def run(self, dataOut, **kwargs):
546
546
547 if not self.__isConfig:
547 if not self.__isConfig:
548 self.setup(**kwargs)
548 self.setup(**kwargs)
549 self.__isConfig = True
549 self.__isConfig = True
550
550
551 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
551 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
552
552
553 # dataOut.timeInterval *= n
553 # dataOut.timeInterval *= n
554 dataOut.flagNoData = True
554 dataOut.flagNoData = True
555
555
556 if self.__dataReady:
556 if self.__dataReady:
557 dataOut.data = avgdata
557 dataOut.data = avgdata
558 dataOut.nCohInt *= self.n
558 dataOut.nCohInt *= self.n
559 dataOut.utctime = avgdatatime
559 dataOut.utctime = avgdatatime
560 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
560 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
561 dataOut.flagNoData = False
561 dataOut.flagNoData = False
562
562
563
563
564 class Decoder(Operation):
564 class Decoder(Operation):
565
565
566 __isConfig = False
566 __isConfig = False
567 __profIndex = 0
567 __profIndex = 0
568
568
569 code = None
569 code = None
570
570
571 nCode = None
571 nCode = None
572 nBaud = None
572 nBaud = None
573
573
574 def __init__(self):
574 def __init__(self):
575
575
576 self.__isConfig = False
576 self.__isConfig = False
577
577
578 def setup(self, code):
578 def setup(self, code):
579
579
580 self.__profIndex = 0
580 self.__profIndex = 0
581
581
582 self.code = code
582 self.code = code
583
583
584 self.nCode = len(code)
584 self.nCode = len(code)
585 self.nBaud = len(code[0])
585 self.nBaud = len(code[0])
586
586
587 def convolutionInFreq(self, data):
587 def convolutionInFreq(self, data):
588
588
589 ndata = data.shape[1]
589 ndata = data.shape[1]
590 newcode = numpy.zeros(ndata)
590 newcode = numpy.zeros(ndata)
591 newcode[0:self.nBaud] = self.code[self.__profIndex]
591 newcode[0:self.nBaud] = self.code[self.__profIndex]
592
592
593 fft_data = numpy.fft.fft(data, axis=1)
593 fft_data = numpy.fft.fft(data, axis=1)
594 fft_code = numpy.conj(numpy.fft.fft(newcode))
594 fft_code = numpy.conj(numpy.fft.fft(newcode))
595 fft_code = fft_code.reshape(1,len(fft_code))
595 fft_code = fft_code.reshape(1,len(fft_code))
596
596
597 # conv = fft_data.copy()
597 # conv = fft_data.copy()
598 # conv.fill(0)
598 # conv.fill(0)
599
599
600 conv = fft_data*fft_code
600 conv = fft_data*fft_code
601
601
602 data = numpy.fft.ifft(conv,axis=1)
602 data = numpy.fft.ifft(conv,axis=1)
603
603
604 datadec = data[:,:-self.nBaud+1]
604 datadec = data[:,:-self.nBaud+1]
605 ndatadec = ndata - self.nBaud + 1
605 ndatadec = ndata - self.nBaud + 1
606
606
607 if self.__profIndex == self.nCode:
607 if self.__profIndex == self.nCode:
608 self.__profIndex = 0
608 self.__profIndex = 0
609
609
610 self.__profIndex += 1
610 self.__profIndex += 1
611
611
612 return ndatadec, datadec
612 return ndatadec, datadec
613
613
614
614
615 def convolutionInTime(self, data):
615 def convolutionInTime(self, data):
616
616
617 nchannel = data.shape[1]
617 nchannel = data.shape[1]
618 newcode = self.code[self.__profIndex]
618 newcode = self.code[self.__profIndex]
619
619
620 datadec = data.copy()
620 datadec = data.copy()
621
621
622 for i in range(nchannel):
622 for i in range(nchannel):
623 datadec[i,:] = numpy.correlate(data[i,:], newcode)
623 datadec[i,:] = numpy.correlate(data[i,:], newcode)
624
624
625 ndatadec = ndata - self.nBaud + 1
625 ndatadec = ndata - self.nBaud + 1
626
626
627 if self.__profIndex == self.nCode:
627 if self.__profIndex == self.nCode:
628 self.__profIndex = 0
628 self.__profIndex = 0
629
629
630 self.__profIndex += 1
630 self.__profIndex += 1
631
631
632 return ndatadec, datadec
632 return ndatadec, datadec
633
633
634 def run(self, dataOut, code=None, mode = 0):
634 def run(self, dataOut, code=None, mode = 0):
635
635
636 if not self.__isConfig:
636 if not self.__isConfig:
637
637
638 if code == None:
638 if code == None:
639 code = dataOut.code
639 code = dataOut.code
640
640
641 self.setup(code)
641 self.setup(code)
642 self.__isConfig = True
642 self.__isConfig = True
643
643
644 if mode == 0:
644 if mode == 0:
645 ndatadec, datadec = self.convolutionInFreq(data)
645 ndatadec, datadec = self.convolutionInFreq(data)
646
646
647 if mode == 1:
647 if mode == 1:
648 ndatadec, datadec = self.convolutionInTime(data)
648 ndatadec, datadec = self.convolutionInTime(data)
649
649
650 dataOut.data = datadec
650 dataOut.data = datadec
651
651
652 dataOut.heightList = dataOut.heightList[0:ndatadec+1]
652 dataOut.heightList = dataOut.heightList[0:ndatadec+1]
653
653
654 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
654 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
655
655
656 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
656 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
657
657
658
658
659 class SpectraProc(ProcessingUnit):
659 class SpectraProc(ProcessingUnit):
660
660
661 def __init__(self):
661 def __init__(self):
662
662
663 self.objectDict = {}
663 self.objectDict = {}
664 self.buffer = None
664 self.buffer = None
665 self.firstdatatime = None
665 self.firstdatatime = None
666 self.profIndex = 0
666 self.profIndex = 0
667 self.dataOut = Spectra()
667 self.dataOut = Spectra()
668
668
669 def __updateObjFromInput(self):
669 def __updateObjFromInput(self):
670
670
671 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
671 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
672 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
672 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
673 self.dataOut.channelList = self.dataIn.channelList
673 self.dataOut.channelList = self.dataIn.channelList
674 self.dataOut.heightList = self.dataIn.heightList
674 self.dataOut.heightList = self.dataIn.heightList
675 self.dataOut.dtype = self.dataIn.dtype
675 self.dataOut.dtype = self.dataIn.dtype
676 # self.dataOut.nHeights = self.dataIn.nHeights
676 # self.dataOut.nHeights = self.dataIn.nHeights
677 # self.dataOut.nChannels = self.dataIn.nChannels
677 # self.dataOut.nChannels = self.dataIn.nChannels
678 self.dataOut.nBaud = self.dataIn.nBaud
678 self.dataOut.nBaud = self.dataIn.nBaud
679 self.dataOut.nCode = self.dataIn.nCode
679 self.dataOut.nCode = self.dataIn.nCode
680 self.dataOut.code = self.dataIn.code
680 self.dataOut.code = self.dataIn.code
681 self.dataOut.nProfiles = self.dataOut.nFFTPoints
681 self.dataOut.nProfiles = self.dataOut.nFFTPoints
682 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
682 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
683 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
683 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
684 self.dataOut.utctime = self.firstdatatime
684 self.dataOut.utctime = self.firstdatatime
685 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
685 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
686 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
686 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
687 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
687 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
688 self.dataOut.nCohInt = self.dataIn.nCohInt
688 self.dataOut.nCohInt = self.dataIn.nCohInt
689 self.dataOut.nIncohInt = 1
689 self.dataOut.nIncohInt = 1
690 self.dataOut.ippSeconds = self.dataIn.ippSeconds
690 self.dataOut.ippSeconds = self.dataIn.ippSeconds
691
691
692 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
692 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
693
693
694 def __getFft(self):
694 def __getFft(self):
695 """
695 """
696 Convierte valores de Voltaje a Spectra
696 Convierte valores de Voltaje a Spectra
697
697
698 Affected:
698 Affected:
699 self.dataOut.data_spc
699 self.dataOut.data_spc
700 self.dataOut.data_cspc
700 self.dataOut.data_cspc
701 self.dataOut.data_dc
701 self.dataOut.data_dc
702 self.dataOut.heightList
702 self.dataOut.heightList
703 self.profIndex
703 self.profIndex
704 self.buffer
704 self.buffer
705 self.dataOut.flagNoData
705 self.dataOut.flagNoData
706 """
706 """
707 fft_volt = numpy.fft.fft(self.buffer,axis=1)
707 fft_volt = numpy.fft.fft(self.buffer,axis=1)
708 dc = fft_volt[:,0,:]
708 dc = fft_volt[:,0,:]
709
709
710 #calculo de self-spectra
710 #calculo de self-spectra
711 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
711 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
712 spc = fft_volt * numpy.conjugate(fft_volt)
712 spc = fft_volt * numpy.conjugate(fft_volt)
713 spc = spc.real
713 spc = spc.real
714
714
715 blocksize = 0
715 blocksize = 0
716 blocksize += dc.size
716 blocksize += dc.size
717 blocksize += spc.size
717 blocksize += spc.size
718
718
719 cspc = None
719 cspc = None
720 pairIndex = 0
720 pairIndex = 0
721 if self.dataOut.pairsList != None:
721 if self.dataOut.pairsList != None:
722 #calculo de cross-spectra
722 #calculo de cross-spectra
723 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
723 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
724 for pair in self.dataOut.pairsList:
724 for pair in self.dataOut.pairsList:
725 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
725 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
726 pairIndex += 1
726 pairIndex += 1
727 blocksize += cspc.size
727 blocksize += cspc.size
728
728
729 self.dataOut.data_spc = spc
729 self.dataOut.data_spc = spc
730 self.dataOut.data_cspc = cspc
730 self.dataOut.data_cspc = cspc
731 self.dataOut.data_dc = dc
731 self.dataOut.data_dc = dc
732 self.dataOut.blockSize = blocksize
732 self.dataOut.blockSize = blocksize
733
733
734 def init(self, nFFTPoints=None, pairsList=None):
734 def init(self, nFFTPoints=None, pairsList=None):
735
735
736 self.dataOut.flagNoData = True
736 self.dataOut.flagNoData = True
737
737
738 if self.dataIn.type == "Spectra":
738 if self.dataIn.type == "Spectra":
739 self.dataOut.copy(self.dataIn)
739 self.dataOut.copy(self.dataIn)
740 return
740 return
741
741
742 if self.dataIn.type == "Voltage":
742 if self.dataIn.type == "Voltage":
743
743
744 if nFFTPoints == None:
744 if nFFTPoints == None:
745 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
745 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
746
746
747 if pairsList == None:
747 if pairsList == None:
748 nPairs = 0
748 nPairs = 0
749 else:
749 else:
750 nPairs = len(pairsList)
750 nPairs = len(pairsList)
751
751
752 self.dataOut.nFFTPoints = nFFTPoints
752 self.dataOut.nFFTPoints = nFFTPoints
753 self.dataOut.pairsList = pairsList
753 self.dataOut.pairsList = pairsList
754 self.dataOut.nPairs = nPairs
754 self.dataOut.nPairs = nPairs
755
755
756 if self.buffer == None:
756 if self.buffer == None:
757 self.buffer = numpy.zeros((self.dataIn.nChannels,
757 self.buffer = numpy.zeros((self.dataIn.nChannels,
758 self.dataOut.nFFTPoints,
758 self.dataOut.nFFTPoints,
759 self.dataIn.nHeights),
759 self.dataIn.nHeights),
760 dtype='complex')
760 dtype='complex')
761
761
762
762
763 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
763 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
764 self.profIndex += 1
764 self.profIndex += 1
765
765
766 if self.firstdatatime == None:
766 if self.firstdatatime == None:
767 self.firstdatatime = self.dataIn.utctime
767 self.firstdatatime = self.dataIn.utctime
768
768
769 if self.profIndex == self.dataOut.nFFTPoints:
769 if self.profIndex == self.dataOut.nFFTPoints:
770 self.__updateObjFromInput()
770 self.__updateObjFromInput()
771 self.__getFft()
771 self.__getFft()
772
772
773 self.dataOut.flagNoData = False
773 self.dataOut.flagNoData = False
774
774
775 self.buffer = None
775 self.buffer = None
776 self.firstdatatime = None
776 self.firstdatatime = None
777 self.profIndex = 0
777 self.profIndex = 0
778
778
779 return
779 return
780
780
781 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
781 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
782
782
783 def selectChannels(self, channelList):
783 def selectChannels(self, channelList):
784
784
785 channelIndexList = []
785 channelIndexList = []
786
786
787 for channel in channelList:
787 for channel in channelList:
788 index = self.dataOut.channelList.index(channel)
788 index = self.dataOut.channelList.index(channel)
789 channelIndexList.append(index)
789 channelIndexList.append(index)
790
790
791 self.selectChannelsByIndex(channelIndexList)
791 self.selectChannelsByIndex(channelIndexList)
792
792
793 def selectChannelsByIndex(self, channelIndexList):
793 def selectChannelsByIndex(self, channelIndexList):
794 """
794 """
795 Selecciona un bloque de datos en base a canales segun el channelIndexList
795 Selecciona un bloque de datos en base a canales segun el channelIndexList
796
796
797 Input:
797 Input:
798 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
798 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
799
799
800 Affected:
800 Affected:
801 self.dataOut.data_spc
801 self.dataOut.data_spc
802 self.dataOut.channelIndexList
802 self.dataOut.channelIndexList
803 self.dataOut.nChannels
803 self.dataOut.nChannels
804
804
805 Return:
805 Return:
806 None
806 None
807 """
807 """
808
808
809 for channelIndex in channelIndexList:
809 for channelIndex in channelIndexList:
810 if channelIndex not in self.dataOut.channelIndexList:
810 if channelIndex not in self.dataOut.channelIndexList:
811 print channelIndexList
811 print channelIndexList
812 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
812 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
813
813
814 nChannels = len(channelIndexList)
814 nChannels = len(channelIndexList)
815
815
816 data_spc = self.dataOut.data_spc[channelIndexList,:]
816 data_spc = self.dataOut.data_spc[channelIndexList,:]
817
817
818 self.dataOut.data_spc = data_spc
818 self.dataOut.data_spc = data_spc
819 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
819 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
820 # self.dataOut.nChannels = nChannels
820 # self.dataOut.nChannels = nChannels
821
821
822 return 1
822 return 1
823
823
824
824
825 class IncohInt(Operation):
825 class IncohInt(Operation):
826
826
827
827
828 __profIndex = 0
828 __profIndex = 0
829 __withOverapping = False
829 __withOverapping = False
830
830
831 __byTime = False
831 __byTime = False
832 __initime = None
832 __initime = None
833 __lastdatatime = None
833 __lastdatatime = None
834 __integrationtime = None
834 __integrationtime = None
835
835
836 __buffer_spc = None
836 __buffer_spc = None
837 __buffer_cspc = None
837 __buffer_cspc = None
838 __buffer_dc = None
838 __buffer_dc = None
839
839
840 __dataReady = False
840 __dataReady = False
841
841
842 n = None
842 n = None
843
843
844
844
845 def __init__(self):
845 def __init__(self):
846
846
847 self.__isConfig = False
847 self.__isConfig = False
848
848
849 def setup(self, n=None, timeInterval=None, overlapping=False):
849 def setup(self, n=None, timeInterval=None, overlapping=False):
850 """
850 """
851 Set the parameters of the integration class.
851 Set the parameters of the integration class.
852
852
853 Inputs:
853 Inputs:
854
854
855 n : Number of coherent integrations
855 n : Number of coherent integrations
856 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
856 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
857 overlapping :
857 overlapping :
858
858
859 """
859 """
860
860
861 self.__initime = None
861 self.__initime = None
862 self.__lastdatatime = 0
862 self.__lastdatatime = 0
863 self.__buffer_spc = None
863 self.__buffer_spc = None
864 self.__buffer_cspc = None
864 self.__buffer_cspc = None
865 self.__buffer_dc = None
865 self.__buffer_dc = None
866 self.__dataReady = False
866 self.__dataReady = False
867
867
868
868
869 if n == None and timeInterval == None:
869 if n == None and timeInterval == None:
870 raise ValueError, "n or timeInterval should be specified ..."
870 raise ValueError, "n or timeInterval should be specified ..."
871
871
872 if n != None:
872 if n != None:
873 self.n = n
873 self.n = n
874 self.__byTime = False
874 self.__byTime = False
875 else:
875 else:
876 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
876 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
877 self.n = 9999
877 self.n = 9999
878 self.__byTime = True
878 self.__byTime = True
879
879
880 if overlapping:
880 if overlapping:
881 self.__withOverapping = True
881 self.__withOverapping = True
882 else:
882 else:
883 self.__withOverapping = False
883 self.__withOverapping = False
884 self.__buffer_spc = 0
884 self.__buffer_spc = 0
885 self.__buffer_cspc = 0
885 self.__buffer_cspc = 0
886 self.__buffer_dc = 0
886 self.__buffer_dc = 0
887
887
888 self.__profIndex = 0
888 self.__profIndex = 0
889
889
890 def putData(self, data_spc, data_cspc, data_dc):
890 def putData(self, data_spc, data_cspc, data_dc):
891
891
892 """
892 """
893 Add a profile to the __buffer_spc and increase in one the __profileIndex
893 Add a profile to the __buffer_spc and increase in one the __profileIndex
894
894
895 """
895 """
896
896
897 if not self.__withOverapping:
897 if not self.__withOverapping:
898 self.__buffer_spc += data_spc
898 self.__buffer_spc += data_spc
899
899
900 if data_cspc == None:
900 if data_cspc == None:
901 self.__buffer_cspc = None
901 self.__buffer_cspc = None
902 else:
902 else:
903 self.__buffer_cspc += data_cspc
903 self.__buffer_cspc += data_cspc
904
904
905 if data_dc == None:
905 if data_dc == None:
906 self.__buffer_dc = None
906 self.__buffer_dc = None
907 else:
907 else:
908 self.__buffer_dc += data_dc
908 self.__buffer_dc += data_dc
909
909
910 self.__profIndex += 1
910 self.__profIndex += 1
911 return
911 return
912
912
913 #Overlapping data
913 #Overlapping data
914 nChannels, nFFTPoints, nHeis = data_spc.shape
914 nChannels, nFFTPoints, nHeis = data_spc.shape
915 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
915 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
916 if data_cspc != None:
916 if data_cspc != None:
917 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
917 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
918 if data_dc != None:
918 if data_dc != None:
919 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
919 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
920
920
921 #If the buffer is empty then it takes the data value
921 #If the buffer is empty then it takes the data value
922 if self.__buffer_spc == None:
922 if self.__buffer_spc == None:
923 self.__buffer_spc = data_spc
923 self.__buffer_spc = data_spc
924
924
925 if data_cspc == None:
925 if data_cspc == None:
926 self.__buffer_cspc = None
926 self.__buffer_cspc = None
927 else:
927 else:
928 self.__buffer_cspc += data_cspc
928 self.__buffer_cspc += data_cspc
929
929
930 if data_dc == None:
930 if data_dc == None:
931 self.__buffer_dc = None
931 self.__buffer_dc = None
932 else:
932 else:
933 self.__buffer_dc += data_dc
933 self.__buffer_dc += data_dc
934
934
935 self.__profIndex += 1
935 self.__profIndex += 1
936 return
936 return
937
937
938 #If the buffer length is lower than n then stakcing the data value
938 #If the buffer length is lower than n then stakcing the data value
939 if self.__profIndex < self.n:
939 if self.__profIndex < self.n:
940 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
940 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
941
941
942 if data_cspc != None:
942 if data_cspc != None:
943 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
943 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
944
944
945 if data_dc != None:
945 if data_dc != None:
946 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
946 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
947
947
948 self.__profIndex += 1
948 self.__profIndex += 1
949 return
949 return
950
950
951 #If the buffer length is equal to n then replacing the last buffer value with the data value
951 #If the buffer length is equal to n then replacing the last buffer value with the data value
952 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
952 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
953 self.__buffer_spc[self.n-1] = data_spc
953 self.__buffer_spc[self.n-1] = data_spc
954
954
955 if data_cspc != None:
955 if data_cspc != None:
956 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
956 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
957 self.__buffer_cspc[self.n-1] = data_cspc
957 self.__buffer_cspc[self.n-1] = data_cspc
958
958
959 if data_dc != None:
959 if data_dc != None:
960 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
960 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
961 self.__buffer_dc[self.n-1] = data_dc
961 self.__buffer_dc[self.n-1] = data_dc
962
962
963 self.__profIndex = self.n
963 self.__profIndex = self.n
964 return
964 return
965
965
966
966
967 def pushData(self):
967 def pushData(self):
968 """
968 """
969 Return the sum of the last profiles and the profiles used in the sum.
969 Return the sum of the last profiles and the profiles used in the sum.
970
970
971 Affected:
971 Affected:
972
972
973 self.__profileIndex
973 self.__profileIndex
974
974
975 """
975 """
976 data_spc = None
976 data_spc = None
977 data_cspc = None
977 data_cspc = None
978 data_dc = None
978 data_dc = None
979
979
980 if not self.__withOverapping:
980 if not self.__withOverapping:
981 data_spc = self.__buffer_spc
981 data_spc = self.__buffer_spc
982 data_cspc = self.__buffer_cspc
982 data_cspc = self.__buffer_cspc
983 data_dc = self.__buffer_dc
983 data_dc = self.__buffer_dc
984
984
985 n = self.__profIndex
985 n = self.__profIndex
986
986
987 self.__buffer_spc = 0
987 self.__buffer_spc = 0
988 self.__buffer_cspc = 0
988 self.__buffer_cspc = 0
989 self.__buffer_dc = 0
989 self.__buffer_dc = 0
990 self.__profIndex = 0
990 self.__profIndex = 0
991
991
992 return data_spc, data_cspc, data_dc, n
992 return data_spc, data_cspc, data_dc, n
993
993
994 #Integration with Overlapping
994 #Integration with Overlapping
995 data_spc = numpy.sum(self.__buffer_spc, axis=0)
995 data_spc = numpy.sum(self.__buffer_spc, axis=0)
996
996
997 if self.__buffer_cspc != None:
997 if self.__buffer_cspc != None:
998 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
998 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
999
999
1000 if self.__buffer_dc != None:
1000 if self.__buffer_dc != None:
1001 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1001 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1002
1002
1003 n = self.__profIndex
1003 n = self.__profIndex
1004
1004
1005 return data_spc, data_cspc, data_dc, n
1005 return data_spc, data_cspc, data_dc, n
1006
1006
1007 def byProfiles(self, *args):
1007 def byProfiles(self, *args):
1008
1008
1009 self.__dataReady = False
1009 self.__dataReady = False
1010 avgdata_spc = None
1010 avgdata_spc = None
1011 avgdata_cspc = None
1011 avgdata_cspc = None
1012 avgdata_dc = None
1012 avgdata_dc = None
1013 n = None
1013 n = None
1014
1014
1015 self.putData(*args)
1015 self.putData(*args)
1016
1016
1017 if self.__profIndex == self.n:
1017 if self.__profIndex == self.n:
1018
1018
1019 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1019 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1020 self.__dataReady = True
1020 self.__dataReady = True
1021
1021
1022 return avgdata_spc, avgdata_cspc, avgdata_dc
1022 return avgdata_spc, avgdata_cspc, avgdata_dc
1023
1023
1024 def byTime(self, datatime, *args):
1024 def byTime(self, datatime, *args):
1025
1025
1026 self.__dataReady = False
1026 self.__dataReady = False
1027 avgdata_spc = None
1027 avgdata_spc = None
1028 avgdata_cspc = None
1028 avgdata_cspc = None
1029 avgdata_dc = None
1029 avgdata_dc = None
1030 n = None
1030 n = None
1031
1031
1032 self.putData(*args)
1032 self.putData(*args)
1033
1033
1034 if (datatime - self.__initime) >= self.__integrationtime:
1034 if (datatime - self.__initime) >= self.__integrationtime:
1035 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1035 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1036 self.n = n
1036 self.n = n
1037 self.__dataReady = True
1037 self.__dataReady = True
1038
1038
1039 return avgdata_spc, avgdata_cspc, avgdata_dc
1039 return avgdata_spc, avgdata_cspc, avgdata_dc
1040
1040
1041 def integrate(self, datatime, *args):
1041 def integrate(self, datatime, *args):
1042
1042
1043 if self.__initime == None:
1043 if self.__initime == None:
1044 self.__initime = datatime
1044 self.__initime = datatime
1045
1045
1046 if self.__byTime:
1046 if self.__byTime:
1047 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1047 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1048 else:
1048 else:
1049 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1049 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1050
1050
1051 self.__lastdatatime = datatime
1051 self.__lastdatatime = datatime
1052
1052
1053 if avgdata_spc == None:
1053 if avgdata_spc == None:
1054 return None, None, None, None
1054 return None, None, None, None
1055
1055
1056 avgdatatime = self.__initime
1056 avgdatatime = self.__initime
1057
1057
1058 deltatime = datatime -self.__lastdatatime
1058 deltatime = datatime -self.__lastdatatime
1059
1059
1060 if not self.__withOverapping:
1060 if not self.__withOverapping:
1061 self.__initime = datatime
1061 self.__initime = datatime
1062 else:
1062 else:
1063 self.__initime += deltatime
1063 self.__initime += deltatime
1064
1064
1065 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1065 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1066
1066
1067 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1067 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1068
1068
1069 if not self.__isConfig:
1069 if not self.__isConfig:
1070 self.setup(n, timeInterval, overlapping)
1070 self.setup(n, timeInterval, overlapping)
1071 self.__isConfig = True
1071 self.__isConfig = True
1072
1072
1073 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1073 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1074 dataOut.data_spc,
1074 dataOut.data_spc,
1075 dataOut.data_cspc,
1075 dataOut.data_cspc,
1076 dataOut.data_dc)
1076 dataOut.data_dc)
1077
1077
1078 # dataOut.timeInterval *= n
1078 # dataOut.timeInterval *= n
1079 dataOut.flagNoData = True
1079 dataOut.flagNoData = True
1080
1080
1081 if self.__dataReady:
1081 if self.__dataReady:
1082 dataOut.data_spc = avgdata_spc
1082
1083 dataOut.data_cspc = avgdata_cspc
1083 dataOut.data_spc = avgdata_spc / self.n
1084 dataOut.data_dc = avgdata_dc
1084 dataOut.data_cspc = avgdata_cspc / self.n
1085 dataOut.data_dc = avgdata_dc / self.n
1085
1086
1086 dataOut.nIncohInt *= self.n
1087 dataOut.nIncohInt *= self.n
1087 dataOut.utctime = avgdatatime
1088 dataOut.utctime = avgdatatime
1088 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1089 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1089 dataOut.flagNoData = False
1090 dataOut.flagNoData = False
1090
1091
1091 class ProfileSelector(Operation):
1092 class ProfileSelector(Operation):
1092
1093
1093 profileIndex = None
1094 profileIndex = None
1094 # Tamanho total de los perfiles
1095 # Tamanho total de los perfiles
1095 nProfiles = None
1096 nProfiles = None
1096
1097
1097 def __init__(self):
1098 def __init__(self):
1098
1099
1099 self.profileIndex = 0
1100 self.profileIndex = 0
1100
1101
1101 def incIndex(self):
1102 def incIndex(self):
1102 self.profileIndex += 1
1103 self.profileIndex += 1
1103
1104
1104 if self.profileIndex >= self.nProfiles:
1105 if self.profileIndex >= self.nProfiles:
1105 self.profileIndex = 0
1106 self.profileIndex = 0
1106
1107
1107 def isProfileInRange(self, minIndex, maxIndex):
1108 def isProfileInRange(self, minIndex, maxIndex):
1108
1109
1109 if self.profileIndex < minIndex:
1110 if self.profileIndex < minIndex:
1110 return False
1111 return False
1111
1112
1112 if self.profileIndex > maxIndex:
1113 if self.profileIndex > maxIndex:
1113 return False
1114 return False
1114
1115
1115 return True
1116 return True
1116
1117
1117 def isProfileInList(self, profileList):
1118 def isProfileInList(self, profileList):
1118
1119
1119 if self.profileIndex not in profileList:
1120 if self.profileIndex not in profileList:
1120 return False
1121 return False
1121
1122
1122 return True
1123 return True
1123
1124
1124 def run(self, dataOut, profileList=None, profileRangeList=None):
1125 def run(self, dataOut, profileList=None, profileRangeList=None):
1125
1126
1127 dataOut.flagNoData = True
1126 self.nProfiles = dataOut.nProfiles
1128 self.nProfiles = dataOut.nProfiles
1127
1129
1128 if profileList != None:
1130 if profileList != None:
1129 if not(self.isProfileInList(profileList)):
1131 if self.isProfileInList(profileList):
1130 dataOut.flagNoData = True
1131 else:
1132 dataOut.flagNoData = False
1132 dataOut.flagNoData = False
1133
1133 self.incIndex()
1134 self.incIndex()
1134 return 1
1135 return 1
1135
1136
1136
1137
1137 elif profileRangeList != None:
1138 elif profileRangeList != None:
1138 minIndex = profileRangeList[0]
1139 minIndex = profileRangeList[0]
1139 maxIndex = profileRangeList[1]
1140 maxIndex = profileRangeList[1]
1140 if not(self.isProfileInRange(minIndex, maxIndex)):
1141 if self.isProfileInRange(minIndex, maxIndex):
1141 dataOut.flagNoData = True
1142 else:
1143 dataOut.flagNoData = False
1142 dataOut.flagNoData = False
1143
1144 self.incIndex()
1144 self.incIndex()
1145 return 1
1145 return 1
1146
1146 else:
1147 else:
1147 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1148 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1148
1149
1149 return 0
1150 return 0
1150
1151
General Comments 0
You need to be logged in to leave comments. Login now