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