##// END OF EJS Templates
Modificaciones para operacion en tiempo real: lectura de archivos, titulo de graficos, timeinterval
Daniel Valdez -
r389:bb39554baf19
parent child
Show More
@@ -1,3317 +1,3372
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 from xml.etree.ElementTree import Element, SubElement, ElementTree
13 from xml.etree.ElementTree import Element, SubElement, ElementTree
14 try:
14 try:
15 import pyfits
15 import pyfits
16 except:
16 except:
17 print "pyfits module has not been imported, it should be installed to save files in fits format"
17 print "pyfits module has not been imported, it should be installed to save files in fits format"
18
18
19 from jrodata import *
19 from jrodata import *
20 from jroheaderIO import *
20 from jroheaderIO import *
21 from jroprocessing import *
21 from jroprocessing import *
22
22
23 LOCALTIME = True #-18000
23 LOCALTIME = True #-18000
24
24
25 def isNumber(str):
25 def isNumber(str):
26 """
26 """
27 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
27 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
28
28
29 Excepciones:
29 Excepciones:
30 Si un determinado string no puede ser convertido a numero
30 Si un determinado string no puede ser convertido a numero
31 Input:
31 Input:
32 str, string al cual se le analiza para determinar si convertible a un numero o no
32 str, string al cual se le analiza para determinar si convertible a un numero o no
33
33
34 Return:
34 Return:
35 True : si el string es uno numerico
35 True : si el string es uno numerico
36 False : no es un string numerico
36 False : no es un string numerico
37 """
37 """
38 try:
38 try:
39 float( str )
39 float( str )
40 return True
40 return True
41 except:
41 except:
42 return False
42 return False
43
43
44 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
44 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
45 """
45 """
46 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
46 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
47
47
48 Inputs:
48 Inputs:
49 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
49 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
50
50
51 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
51 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
52 segundos contados desde 01/01/1970.
52 segundos contados desde 01/01/1970.
53 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
53 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
54 segundos contados desde 01/01/1970.
54 segundos contados desde 01/01/1970.
55
55
56 Return:
56 Return:
57 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
57 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
58 fecha especificado, de lo contrario retorna False.
58 fecha especificado, de lo contrario retorna False.
59
59
60 Excepciones:
60 Excepciones:
61 Si el archivo no existe o no puede ser abierto
61 Si el archivo no existe o no puede ser abierto
62 Si la cabecera no puede ser leida.
62 Si la cabecera no puede ser leida.
63
63
64 """
64 """
65 basicHeaderObj = BasicHeader(LOCALTIME)
65 basicHeaderObj = BasicHeader(LOCALTIME)
66
66
67 try:
67 try:
68 fp = open(filename,'rb')
68 fp = open(filename,'rb')
69 except:
69 except:
70 raise IOError, "The file %s can't be opened" %(filename)
70 raise IOError, "The file %s can't be opened" %(filename)
71
71
72 sts = basicHeaderObj.read(fp)
72 sts = basicHeaderObj.read(fp)
73 fp.close()
73 fp.close()
74
74
75 if not(sts):
75 if not(sts):
76 print "Skipping the file %s because it has not a valid header" %(filename)
76 print "Skipping the file %s because it has not a valid header" %(filename)
77 return 0
77 return 0
78
78
79 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
79 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
80 return 0
80 return 0
81
81
82 return 1
82 return 1
83
83
84 def isFileinThisTime(filename, startTime, endTime):
84 def isFileinThisTime(filename, startTime, endTime):
85 """
85 """
86 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
86 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
87
87
88 Inputs:
88 Inputs:
89 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
89 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
90
90
91 startTime : tiempo inicial del rango seleccionado en formato datetime.time
91 startTime : tiempo inicial del rango seleccionado en formato datetime.time
92
92
93 endTime : tiempo final del rango seleccionado en formato datetime.time
93 endTime : tiempo final del rango seleccionado en formato datetime.time
94
94
95 Return:
95 Return:
96 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
96 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
97 fecha especificado, de lo contrario retorna False.
97 fecha especificado, de lo contrario retorna False.
98
98
99 Excepciones:
99 Excepciones:
100 Si el archivo no existe o no puede ser abierto
100 Si el archivo no existe o no puede ser abierto
101 Si la cabecera no puede ser leida.
101 Si la cabecera no puede ser leida.
102
102
103 """
103 """
104
104
105
105
106 try:
106 try:
107 fp = open(filename,'rb')
107 fp = open(filename,'rb')
108 except:
108 except:
109 raise IOError, "The file %s can't be opened" %(filename)
109 raise IOError, "The file %s can't be opened" %(filename)
110
110
111 basicHeaderObj = BasicHeader(LOCALTIME)
111 basicHeaderObj = BasicHeader(LOCALTIME)
112 sts = basicHeaderObj.read(fp)
112 sts = basicHeaderObj.read(fp)
113 fp.close()
113 fp.close()
114
114
115 thisDatetime = basicHeaderObj.datatime
115 thisDatetime = basicHeaderObj.datatime
116 thisTime = basicHeaderObj.datatime.time()
116 thisTime = basicHeaderObj.datatime.time()
117
117
118 if not(sts):
118 if not(sts):
119 print "Skipping the file %s because it has not a valid header" %(filename)
119 print "Skipping the file %s because it has not a valid header" %(filename)
120 return None
120 return None
121
121
122 if not ((startTime <= thisTime) and (endTime > thisTime)):
122 if not ((startTime <= thisTime) and (endTime > thisTime)):
123 return None
123 return None
124
124
125 return thisDatetime
125 return thisDatetime
126
126
127 def getFileFromSet(path,ext,set):
128 validFilelist = []
129 fileList = os.listdir(path)
130
131 # 0 1234 567 89A BCDE
132 # H YYYY DDD SSS .ext
133
134 for file in fileList:
135 try:
136 year = int(file[1:5])
137 doy = int(file[5:8])
138
139
140 except:
141 continue
142
143 if (os.path.splitext(file)[-1].lower() != ext.lower()):
144 continue
145
146 validFilelist.append(file)
147
148 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
149
150 if len(myfile)!= 0:
151 return myfile[0]
152 else:
153 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
154 print 'the filename %s does not exist'%filename
155 print '...going to the last file: '
156
157 if validFilelist:
158 validFilelist = sorted( validFilelist, key=str.lower )
159 return validFilelist[-1]
160
161 return None
162
163
127 def getlastFileFromPath(path, ext):
164 def getlastFileFromPath(path, ext):
128 """
165 """
129 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
166 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
130 al final de la depuracion devuelve el ultimo file de la lista que quedo.
167 al final de la depuracion devuelve el ultimo file de la lista que quedo.
131
168
132 Input:
169 Input:
133 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
170 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
134 ext : extension de los files contenidos en una carpeta
171 ext : extension de los files contenidos en una carpeta
135
172
136 Return:
173 Return:
137 El ultimo file de una determinada carpeta, no se considera el path.
174 El ultimo file de una determinada carpeta, no se considera el path.
138 """
175 """
139 validFilelist = []
176 validFilelist = []
140 fileList = os.listdir(path)
177 fileList = os.listdir(path)
141
178
142 # 0 1234 567 89A BCDE
179 # 0 1234 567 89A BCDE
143 # H YYYY DDD SSS .ext
180 # H YYYY DDD SSS .ext
144
181
145 for file in fileList:
182 for file in fileList:
146 try:
183 try:
147 year = int(file[1:5])
184 year = int(file[1:5])
148 doy = int(file[5:8])
185 doy = int(file[5:8])
149
186
150
187
151 except:
188 except:
152 continue
189 continue
153
190
154 if (os.path.splitext(file)[-1].lower() != ext.lower()):
191 if (os.path.splitext(file)[-1].lower() != ext.lower()):
155 continue
192 continue
156
193
157 validFilelist.append(file)
194 validFilelist.append(file)
158
195
159 if validFilelist:
196 if validFilelist:
160 validFilelist = sorted( validFilelist, key=str.lower )
197 validFilelist = sorted( validFilelist, key=str.lower )
161 return validFilelist[-1]
198 return validFilelist[-1]
162
199
163 return None
200 return None
164
201
165 def checkForRealPath(path, foldercounter, year, doy, set, ext):
202 def checkForRealPath(path, foldercounter, year, doy, set, ext):
166 """
203 """
167 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
204 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
168 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
205 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
169 el path exacto de un determinado file.
206 el path exacto de un determinado file.
170
207
171 Example :
208 Example :
172 nombre correcto del file es .../.../D2009307/P2009307367.ext
209 nombre correcto del file es .../.../D2009307/P2009307367.ext
173
210
174 Entonces la funcion prueba con las siguientes combinaciones
211 Entonces la funcion prueba con las siguientes combinaciones
175 .../.../y2009307367.ext
212 .../.../y2009307367.ext
176 .../.../Y2009307367.ext
213 .../.../Y2009307367.ext
177 .../.../x2009307/y2009307367.ext
214 .../.../x2009307/y2009307367.ext
178 .../.../x2009307/Y2009307367.ext
215 .../.../x2009307/Y2009307367.ext
179 .../.../X2009307/y2009307367.ext
216 .../.../X2009307/y2009307367.ext
180 .../.../X2009307/Y2009307367.ext
217 .../.../X2009307/Y2009307367.ext
181 siendo para este caso, la ultima combinacion de letras, identica al file buscado
218 siendo para este caso, la ultima combinacion de letras, identica al file buscado
182
219
183 Return:
220 Return:
184 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
221 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
185 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
222 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
186 para el filename
223 para el filename
187 """
224 """
188 fullfilename = None
225 fullfilename = None
189 find_flag = False
226 find_flag = False
190 filename = None
227 filename = None
191
228
192 prefixDirList = [None,'d','D']
229 prefixDirList = [None,'d','D']
193 if ext.lower() == ".r": #voltage
230 if ext.lower() == ".r": #voltage
194 prefixFileList = ['d','D']
231 prefixFileList = ['d','D']
195 elif ext.lower() == ".pdata": #spectra
232 elif ext.lower() == ".pdata": #spectra
196 prefixFileList = ['p','P']
233 prefixFileList = ['p','P']
197 else:
234 else:
198 return None, filename
235 return None, filename
199
236
200 #barrido por las combinaciones posibles
237 #barrido por las combinaciones posibles
201 for prefixDir in prefixDirList:
238 for prefixDir in prefixDirList:
202 thispath = path
239 thispath = path
203 if prefixDir != None:
240 if prefixDir != None:
204 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
241 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
205 if foldercounter == 0:
242 if foldercounter == 0:
206 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
243 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
207 else:
244 else:
208 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
245 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
209 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
246 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
210 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
247 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
211 fullfilename = os.path.join( thispath, filename ) #formo el path completo
248 fullfilename = os.path.join( thispath, filename ) #formo el path completo
212
249
213 if os.path.exists( fullfilename ): #verifico que exista
250 if os.path.exists( fullfilename ): #verifico que exista
214 find_flag = True
251 find_flag = True
215 break
252 break
216 if find_flag:
253 if find_flag:
217 break
254 break
218
255
219 if not(find_flag):
256 if not(find_flag):
220 return None, filename
257 return None, filename
221
258
222 return fullfilename, filename
259 return fullfilename, filename
223
260
224 def isDoyFolder(folder):
261 def isDoyFolder(folder):
225 try:
262 try:
226 year = int(folder[1:5])
263 year = int(folder[1:5])
227 except:
264 except:
228 return 0
265 return 0
229
266
230 try:
267 try:
231 doy = int(folder[5:8])
268 doy = int(folder[5:8])
232 except:
269 except:
233 return 0
270 return 0
234
271
235 return 1
272 return 1
236
273
237 class JRODataIO:
274 class JRODataIO:
238
275
239 c = 3E8
276 c = 3E8
240
277
241 isConfig = False
278 isConfig = False
242
279
243 basicHeaderObj = BasicHeader(LOCALTIME)
280 basicHeaderObj = BasicHeader(LOCALTIME)
244
281
245 systemHeaderObj = SystemHeader()
282 systemHeaderObj = SystemHeader()
246
283
247 radarControllerHeaderObj = RadarControllerHeader()
284 radarControllerHeaderObj = RadarControllerHeader()
248
285
249 processingHeaderObj = ProcessingHeader()
286 processingHeaderObj = ProcessingHeader()
250
287
251 online = 0
288 online = 0
252
289
253 dtype = None
290 dtype = None
254
291
255 pathList = []
292 pathList = []
256
293
257 filenameList = []
294 filenameList = []
258
295
259 filename = None
296 filename = None
260
297
261 ext = None
298 ext = None
262
299
263 flagIsNewFile = 1
300 flagIsNewFile = 1
264
301
265 flagTimeBlock = 0
302 flagTimeBlock = 0
266
303
267 flagIsNewBlock = 0
304 flagIsNewBlock = 0
268
305
269 fp = None
306 fp = None
270
307
271 firstHeaderSize = 0
308 firstHeaderSize = 0
272
309
273 basicHeaderSize = 24
310 basicHeaderSize = 24
274
311
275 versionFile = 1103
312 versionFile = 1103
276
313
277 fileSize = None
314 fileSize = None
278
315
279 ippSeconds = None
316 ippSeconds = None
280
317
281 fileSizeByHeader = None
318 fileSizeByHeader = None
282
319
283 fileIndex = None
320 fileIndex = None
284
321
285 profileIndex = None
322 profileIndex = None
286
323
287 blockIndex = None
324 blockIndex = None
288
325
289 nTotalBlocks = None
326 nTotalBlocks = None
290
327
291 maxTimeStep = 30
328 maxTimeStep = 30
292
329
293 lastUTTime = None
330 lastUTTime = None
294
331
295 datablock = None
332 datablock = None
296
333
297 dataOut = None
334 dataOut = None
298
335
299 blocksize = None
336 blocksize = None
300
337
301 def __init__(self):
338 def __init__(self):
302
339
303 raise ValueError, "Not implemented"
340 raise ValueError, "Not implemented"
304
341
305 def run(self):
342 def run(self):
306
343
307 raise ValueError, "Not implemented"
344 raise ValueError, "Not implemented"
308
345
309 def getOutput(self):
346 def getOutput(self):
310
347
311 return self.dataOut
348 return self.dataOut
312
349
313 class JRODataReader(JRODataIO, ProcessingUnit):
350 class JRODataReader(JRODataIO, ProcessingUnit):
314
351
315 nReadBlocks = 0
352 nReadBlocks = 0
316
353
317 delay = 10 #number of seconds waiting a new file
354 delay = 10 #number of seconds waiting a new file
318
355
319 nTries = 3 #quantity tries
356 nTries = 3 #quantity tries
320
357
321 nFiles = 3 #number of files for searching
358 nFiles = 3 #number of files for searching
322
359
323 path = None
360 path = None
324
361
325 foldercounter = 0
362 foldercounter = 0
326
363
327 flagNoMoreFiles = 0
364 flagNoMoreFiles = 0
328
365
329 datetimeList = []
366 datetimeList = []
330
367
331 __isFirstTimeOnline = 1
368 __isFirstTimeOnline = 1
332
369
333 __printInfo = True
370 __printInfo = True
334
371
335 profileIndex = None
372 profileIndex = None
336
373
337 def __init__(self):
374 def __init__(self):
338
375
339 """
376 """
340
377
341 """
378 """
342
379
343 raise ValueError, "This method has not been implemented"
380 raise ValueError, "This method has not been implemented"
344
381
345
382
346 def createObjByDefault(self):
383 def createObjByDefault(self):
347 """
384 """
348
385
349 """
386 """
350 raise ValueError, "This method has not been implemented"
387 raise ValueError, "This method has not been implemented"
351
388
352 def getBlockDimension(self):
389 def getBlockDimension(self):
353
390
354 raise ValueError, "No implemented"
391 raise ValueError, "No implemented"
355
392
356 def __searchFilesOffLine(self,
393 def __searchFilesOffLine(self,
357 path,
394 path,
358 startDate,
395 startDate,
359 endDate,
396 endDate,
360 startTime=datetime.time(0,0,0),
397 startTime=datetime.time(0,0,0),
361 endTime=datetime.time(23,59,59),
398 endTime=datetime.time(23,59,59),
362 set=None,
399 set=None,
363 expLabel='',
400 expLabel='',
364 ext='.r',
401 ext='.r',
365 walk=True):
402 walk=True):
366
403
367 pathList = []
404 pathList = []
368
405
369 if not walk:
406 if not walk:
370 pathList.append(path)
407 pathList.append(path)
371
408
372 else:
409 else:
373 dirList = []
410 dirList = []
374 for thisPath in os.listdir(path):
411 for thisPath in os.listdir(path):
375 if not os.path.isdir(os.path.join(path,thisPath)):
412 if not os.path.isdir(os.path.join(path,thisPath)):
376 continue
413 continue
377 if not isDoyFolder(thisPath):
414 if not isDoyFolder(thisPath):
378 continue
415 continue
379
416
380 dirList.append(thisPath)
417 dirList.append(thisPath)
381
418
382 if not(dirList):
419 if not(dirList):
383 return None, None
420 return None, None
384
421
385 thisDate = startDate
422 thisDate = startDate
386
423
387 while(thisDate <= endDate):
424 while(thisDate <= endDate):
388 year = thisDate.timetuple().tm_year
425 year = thisDate.timetuple().tm_year
389 doy = thisDate.timetuple().tm_yday
426 doy = thisDate.timetuple().tm_yday
390
427
391 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
428 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
392 if len(matchlist) == 0:
429 if len(matchlist) == 0:
393 thisDate += datetime.timedelta(1)
430 thisDate += datetime.timedelta(1)
394 continue
431 continue
395 for match in matchlist:
432 for match in matchlist:
396 pathList.append(os.path.join(path,match,expLabel))
433 pathList.append(os.path.join(path,match,expLabel))
397
434
398 thisDate += datetime.timedelta(1)
435 thisDate += datetime.timedelta(1)
399
436
400 if pathList == []:
437 if pathList == []:
401 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
438 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
402 return None, None
439 return None, None
403
440
404 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
441 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
405
442
406 filenameList = []
443 filenameList = []
407 datetimeList = []
444 datetimeList = []
408
445
409 for i in range(len(pathList)):
446 for i in range(len(pathList)):
410
447
411 thisPath = pathList[i]
448 thisPath = pathList[i]
412
449
413 fileList = glob.glob1(thisPath, "*%s" %ext)
450 fileList = glob.glob1(thisPath, "*%s" %ext)
414 fileList.sort()
451 fileList.sort()
415
452
416 for file in fileList:
453 for file in fileList:
417
454
418 filename = os.path.join(thisPath,file)
455 filename = os.path.join(thisPath,file)
419 thisDatetime = isFileinThisTime(filename, startTime, endTime)
456 thisDatetime = isFileinThisTime(filename, startTime, endTime)
420
457
421 if not(thisDatetime):
458 if not(thisDatetime):
422 continue
459 continue
423
460
424 filenameList.append(filename)
461 filenameList.append(filename)
425 datetimeList.append(thisDatetime)
462 datetimeList.append(thisDatetime)
426
463
427 if not(filenameList):
464 if not(filenameList):
428 print "Any file was found for the time range %s - %s" %(startTime, endTime)
465 print "Any file was found for the time range %s - %s" %(startTime, endTime)
429 return None, None
466 return None, None
430
467
431 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
468 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
432 print
469 print
433
470
434 for i in range(len(filenameList)):
471 for i in range(len(filenameList)):
435 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
472 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
436
473
437 self.filenameList = filenameList
474 self.filenameList = filenameList
438 self.datetimeList = datetimeList
475 self.datetimeList = datetimeList
439
476
440 return pathList, filenameList
477 return pathList, filenameList
441
478
442 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
479 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
443
480
444 """
481 """
445 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
482 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
446 devuelve el archivo encontrado ademas de otros datos.
483 devuelve el archivo encontrado ademas de otros datos.
447
484
448 Input:
485 Input:
449 path : carpeta donde estan contenidos los files que contiene data
486 path : carpeta donde estan contenidos los files que contiene data
450
487
451 expLabel : Nombre del subexperimento (subfolder)
488 expLabel : Nombre del subexperimento (subfolder)
452
489
453 ext : extension de los files
490 ext : extension de los files
454
491
455 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
492 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
456
493
457 Return:
494 Return:
458 directory : eL directorio donde esta el file encontrado
495 directory : eL directorio donde esta el file encontrado
459 filename : el ultimo file de una determinada carpeta
496 filename : el ultimo file de una determinada carpeta
460 year : el anho
497 year : el anho
461 doy : el numero de dia del anho
498 doy : el numero de dia del anho
462 set : el set del archivo
499 set : el set del archivo
463
500
464
501
465 """
502 """
466 dirList = []
503 dirList = []
467
504
468 if not walk:
505 if not walk:
469 fullpath = path
506 fullpath = path
470 foldercounter = ''
507 foldercounter = 0
471 else:
508 else:
472 #Filtra solo los directorios
509 #Filtra solo los directorios
473 for thisPath in os.listdir(path):
510 for thisPath in os.listdir(path):
474 if not os.path.isdir(os.path.join(path,thisPath)):
511 if not os.path.isdir(os.path.join(path,thisPath)):
475 continue
512 continue
476 if not isDoyFolder(thisPath):
513 if not isDoyFolder(thisPath):
477 continue
514 continue
478
515
479 dirList.append(thisPath)
516 dirList.append(thisPath)
480
517
481 if not(dirList):
518 if not(dirList):
482 return None, None, None, None, None, None
519 return None, None, None, None, None, None
483
520
484 dirList = sorted( dirList, key=str.lower )
521 dirList = sorted( dirList, key=str.lower )
485
522
486 doypath = dirList[-1]
523 doypath = dirList[-1]
487 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
524 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
488 fullpath = os.path.join(path, doypath, expLabel)
525 fullpath = os.path.join(path, doypath, expLabel)
489
526
490
527
491 print "%s folder was found: " %(fullpath )
528 print "%s folder was found: " %(fullpath )
492
529
493 filename = getlastFileFromPath(fullpath, ext)
530 if set == None:
531 filename = getlastFileFromPath(fullpath, ext)
532 else:
533 filename = getFileFromSet(fullpath, ext, set)
494
534
495 if not(filename):
535 if not(filename):
496 return None, None, None, None, None
536 return None, None, None, None, None, None
497
537
498 print "%s file was found" %(filename)
538 print "%s file was found" %(filename)
499
539
500 if not(self.__verifyFile(os.path.join(fullpath, filename))):
540 if not(self.__verifyFile(os.path.join(fullpath, filename))):
501 return None, None, None, None, None
541 return None, None, None, None, None, None
502
542
503 year = int( filename[1:5] )
543 year = int( filename[1:5] )
504 doy = int( filename[5:8] )
544 doy = int( filename[5:8] )
505 set = int( filename[8:11] )
545 set = int( filename[8:11] )
506
546
507 return fullpath, foldercounter, filename, year, doy, set
547 return fullpath, foldercounter, filename, year, doy, set
508
548
509 def __setNextFileOffline(self):
549 def __setNextFileOffline(self):
510
550
511 idFile = self.fileIndex
551 idFile = self.fileIndex
512
552
513 while (True):
553 while (True):
514 idFile += 1
554 idFile += 1
515 if not(idFile < len(self.filenameList)):
555 if not(idFile < len(self.filenameList)):
516 self.flagNoMoreFiles = 1
556 self.flagNoMoreFiles = 1
517 print "No more Files"
557 print "No more Files"
518 return 0
558 return 0
519
559
520 filename = self.filenameList[idFile]
560 filename = self.filenameList[idFile]
521
561
522 if not(self.__verifyFile(filename)):
562 if not(self.__verifyFile(filename)):
523 continue
563 continue
524
564
525 fileSize = os.path.getsize(filename)
565 fileSize = os.path.getsize(filename)
526 fp = open(filename,'rb')
566 fp = open(filename,'rb')
527 break
567 break
528
568
529 self.flagIsNewFile = 1
569 self.flagIsNewFile = 1
530 self.fileIndex = idFile
570 self.fileIndex = idFile
531 self.filename = filename
571 self.filename = filename
532 self.fileSize = fileSize
572 self.fileSize = fileSize
533 self.fp = fp
573 self.fp = fp
534
574
535 print "Setting the file: %s"%self.filename
575 print "Setting the file: %s"%self.filename
536
576
537 return 1
577 return 1
538
578
539 def __setNextFileOnline(self):
579 def __setNextFileOnline(self):
540 """
580 """
541 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
581 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
542 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
582 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
543 siguientes.
583 siguientes.
544
584
545 Affected:
585 Affected:
546 self.flagIsNewFile
586 self.flagIsNewFile
547 self.filename
587 self.filename
548 self.fileSize
588 self.fileSize
549 self.fp
589 self.fp
550 self.set
590 self.set
551 self.flagNoMoreFiles
591 self.flagNoMoreFiles
552
592
553 Return:
593 Return:
554 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
594 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
555 1 : si el file fue abierto con exito y esta listo a ser leido
595 1 : si el file fue abierto con exito y esta listo a ser leido
556
596
557 Excepciones:
597 Excepciones:
558 Si un determinado file no puede ser abierto
598 Si un determinado file no puede ser abierto
559 """
599 """
560 nFiles = 0
600 nFiles = 0
561 fileOk_flag = False
601 fileOk_flag = False
562 firstTime_flag = True
602 firstTime_flag = True
563
603
564 self.set += 1
604 self.set += 1
565
605
566 if self.set > 999:
606 if self.set > 999:
567 self.set = 0
607 self.set = 0
568 self.foldercounter += 1
608 self.foldercounter += 1
569
609
570 #busca el 1er file disponible
610 #busca el 1er file disponible
571 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
611 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
572 if fullfilename:
612 if fullfilename:
573 if self.__verifyFile(fullfilename, False):
613 if self.__verifyFile(fullfilename, False):
574 fileOk_flag = True
614 fileOk_flag = True
575
615
576 #si no encuentra un file entonces espera y vuelve a buscar
616 #si no encuentra un file entonces espera y vuelve a buscar
577 if not(fileOk_flag):
617 if not(fileOk_flag):
578 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
618 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
579
619
580 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
620 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
581 tries = self.nTries
621 tries = self.nTries
582 else:
622 else:
583 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
623 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
584
624
585 for nTries in range( tries ):
625 for nTries in range( tries ):
586 if firstTime_flag:
626 if firstTime_flag:
587 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
627 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
588 time.sleep( self.delay )
628 time.sleep( self.delay )
589 else:
629 else:
590 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
630 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
591
631
592 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
632 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
593 if fullfilename:
633 if fullfilename:
594 if self.__verifyFile(fullfilename):
634 if self.__verifyFile(fullfilename):
595 fileOk_flag = True
635 fileOk_flag = True
596 break
636 break
597
637
598 if fileOk_flag:
638 if fileOk_flag:
599 break
639 break
600
640
601 firstTime_flag = False
641 firstTime_flag = False
602
642
603 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
643 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
604 self.set += 1
644 self.set += 1
605
645
606 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
646 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
607 self.set = 0
647 self.set = 0
608 self.doy += 1
648 self.doy += 1
609 self.foldercounter = 0
649 self.foldercounter = 0
610
650
611 if fileOk_flag:
651 if fileOk_flag:
612 self.fileSize = os.path.getsize( fullfilename )
652 self.fileSize = os.path.getsize( fullfilename )
613 self.filename = fullfilename
653 self.filename = fullfilename
614 self.flagIsNewFile = 1
654 self.flagIsNewFile = 1
615 if self.fp != None: self.fp.close()
655 if self.fp != None: self.fp.close()
616 self.fp = open(fullfilename, 'rb')
656 self.fp = open(fullfilename, 'rb')
617 self.flagNoMoreFiles = 0
657 self.flagNoMoreFiles = 0
618 print 'Setting the file: %s' % fullfilename
658 print 'Setting the file: %s' % fullfilename
619 else:
659 else:
620 self.fileSize = 0
660 self.fileSize = 0
621 self.filename = None
661 self.filename = None
622 self.flagIsNewFile = 0
662 self.flagIsNewFile = 0
623 self.fp = None
663 self.fp = None
624 self.flagNoMoreFiles = 1
664 self.flagNoMoreFiles = 1
625 print 'No more Files'
665 print 'No more Files'
626
666
627 return fileOk_flag
667 return fileOk_flag
628
668
629
669
630 def setNextFile(self):
670 def setNextFile(self):
631 if self.fp != None:
671 if self.fp != None:
632 self.fp.close()
672 self.fp.close()
633
673
634 if self.online:
674 if self.online:
635 newFile = self.__setNextFileOnline()
675 newFile = self.__setNextFileOnline()
636 else:
676 else:
637 newFile = self.__setNextFileOffline()
677 newFile = self.__setNextFileOffline()
638
678
639 if not(newFile):
679 if not(newFile):
640 return 0
680 return 0
641
681
642 self.__readFirstHeader()
682 self.__readFirstHeader()
643 self.nReadBlocks = 0
683 self.nReadBlocks = 0
644 return 1
684 return 1
645
685
646 def __waitNewBlock(self):
686 def __waitNewBlock(self):
647 """
687 """
648 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
688 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
649
689
650 Si el modo de lectura es OffLine siempre retorn 0
690 Si el modo de lectura es OffLine siempre retorn 0
651 """
691 """
652 if not self.online:
692 if not self.online:
653 return 0
693 return 0
654
694
655 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
695 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
656 return 0
696 return 0
657
697
658 currentPointer = self.fp.tell()
698 currentPointer = self.fp.tell()
659
699
660 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
700 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
661
701
662 for nTries in range( self.nTries ):
702 for nTries in range( self.nTries ):
663
703
664 self.fp.close()
704 self.fp.close()
665 self.fp = open( self.filename, 'rb' )
705 self.fp = open( self.filename, 'rb' )
666 self.fp.seek( currentPointer )
706 self.fp.seek( currentPointer )
667
707
668 self.fileSize = os.path.getsize( self.filename )
708 self.fileSize = os.path.getsize( self.filename )
669 currentSize = self.fileSize - currentPointer
709 currentSize = self.fileSize - currentPointer
670
710
671 if ( currentSize >= neededSize ):
711 if ( currentSize >= neededSize ):
672 self.__rdBasicHeader()
712 self.__rdBasicHeader()
673 return 1
713 return 1
674
714
715 if self.fileSize == self.fileSizeByHeader:
716 # self.flagEoF = True
717 return 0
718
675 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
719 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
676 time.sleep( self.delay )
720 time.sleep( self.delay )
677
721
678
722
679 return 0
723 return 0
680
724
681 def __jumpToLastBlock(self):
725 def __jumpToLastBlock(self):
682
726
683 if not(self.__isFirstTimeOnline):
727 if not(self.__isFirstTimeOnline):
684 return
728 return
685
729
686 csize = self.fileSize - self.fp.tell()
730 csize = self.fileSize - self.fp.tell()
731 blocksize = self.processingHeaderObj.blockSize
687
732
688 #sata el primer bloque de datos
733 #salta el primer bloque de datos
689 if csize > self.processingHeaderObj.blockSize:
734 if csize > self.processingHeaderObj.blockSize:
690 self.fp.seek(self.fp.tell() + self.processingHeaderObj.blockSize)
735 self.fp.seek(self.fp.tell() + blocksize)
691 else:
736 else:
692 return
737 return
693
738
694 csize = self.fileSize - self.fp.tell()
739 csize = self.fileSize - self.fp.tell()
695 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
740 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
696 factor = int(csize/neededsize)
741 while True:
697 if factor > 0:
742
698 self.fp.seek(self.fp.tell() + factor*neededsize)
743 if self.fp.tell()<self.fileSize:
744 self.fp.seek(self.fp.tell() + neededsize)
745 else:
746 self.fp.seek(self.fp.tell() - neededsize)
747 break
748
749 # csize = self.fileSize - self.fp.tell()
750 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
751 # factor = int(csize/neededsize)
752 # if factor > 0:
753 # self.fp.seek(self.fp.tell() + factor*neededsize)
699
754
700 self.flagIsNewFile = 0
755 self.flagIsNewFile = 0
701 self.__isFirstTimeOnline = 0
756 self.__isFirstTimeOnline = 0
702
757
703
758
704 def __setNewBlock(self):
759 def __setNewBlock(self):
705
760
706 if self.fp == None:
761 if self.fp == None:
707 return 0
762 return 0
708
763
709 if self.online:
764 if self.online:
710 self.__jumpToLastBlock()
765 self.__jumpToLastBlock()
711
766
712 if self.flagIsNewFile:
767 if self.flagIsNewFile:
713 return 1
768 return 1
714
769
715 self.lastUTTime = self.basicHeaderObj.utc
770 self.lastUTTime = self.basicHeaderObj.utc
716 currentSize = self.fileSize - self.fp.tell()
771 currentSize = self.fileSize - self.fp.tell()
717 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
772 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
718
773
719 if (currentSize >= neededSize):
774 if (currentSize >= neededSize):
720 self.__rdBasicHeader()
775 self.__rdBasicHeader()
721 return 1
776 return 1
722
777
723 if self.__waitNewBlock():
778 if self.__waitNewBlock():
724 return 1
779 return 1
725
780
726 if not(self.setNextFile()):
781 if not(self.setNextFile()):
727 return 0
782 return 0
728
783
729 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
784 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
730
785
731 self.flagTimeBlock = 0
786 self.flagTimeBlock = 0
732
787
733 if deltaTime > self.maxTimeStep:
788 if deltaTime > self.maxTimeStep:
734 self.flagTimeBlock = 1
789 self.flagTimeBlock = 1
735
790
736 return 1
791 return 1
737
792
738
793
739 def readNextBlock(self):
794 def readNextBlock(self):
740 if not(self.__setNewBlock()):
795 if not(self.__setNewBlock()):
741 return 0
796 return 0
742
797
743 if not(self.readBlock()):
798 if not(self.readBlock()):
744 return 0
799 return 0
745
800
746 return 1
801 return 1
747
802
748 def __rdProcessingHeader(self, fp=None):
803 def __rdProcessingHeader(self, fp=None):
749 if fp == None:
804 if fp == None:
750 fp = self.fp
805 fp = self.fp
751
806
752 self.processingHeaderObj.read(fp)
807 self.processingHeaderObj.read(fp)
753
808
754 def __rdRadarControllerHeader(self, fp=None):
809 def __rdRadarControllerHeader(self, fp=None):
755 if fp == None:
810 if fp == None:
756 fp = self.fp
811 fp = self.fp
757
812
758 self.radarControllerHeaderObj.read(fp)
813 self.radarControllerHeaderObj.read(fp)
759
814
760 def __rdSystemHeader(self, fp=None):
815 def __rdSystemHeader(self, fp=None):
761 if fp == None:
816 if fp == None:
762 fp = self.fp
817 fp = self.fp
763
818
764 self.systemHeaderObj.read(fp)
819 self.systemHeaderObj.read(fp)
765
820
766 def __rdBasicHeader(self, fp=None):
821 def __rdBasicHeader(self, fp=None):
767 if fp == None:
822 if fp == None:
768 fp = self.fp
823 fp = self.fp
769
824
770 self.basicHeaderObj.read(fp)
825 self.basicHeaderObj.read(fp)
771
826
772
827
773 def __readFirstHeader(self):
828 def __readFirstHeader(self):
774 self.__rdBasicHeader()
829 self.__rdBasicHeader()
775 self.__rdSystemHeader()
830 self.__rdSystemHeader()
776 self.__rdRadarControllerHeader()
831 self.__rdRadarControllerHeader()
777 self.__rdProcessingHeader()
832 self.__rdProcessingHeader()
778
833
779 self.firstHeaderSize = self.basicHeaderObj.size
834 self.firstHeaderSize = self.basicHeaderObj.size
780
835
781 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
836 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
782 if datatype == 0:
837 if datatype == 0:
783 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
838 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
784 elif datatype == 1:
839 elif datatype == 1:
785 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
840 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
786 elif datatype == 2:
841 elif datatype == 2:
787 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
842 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
788 elif datatype == 3:
843 elif datatype == 3:
789 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
844 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
790 elif datatype == 4:
845 elif datatype == 4:
791 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
846 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
792 elif datatype == 5:
847 elif datatype == 5:
793 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
848 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
794 else:
849 else:
795 raise ValueError, 'Data type was not defined'
850 raise ValueError, 'Data type was not defined'
796
851
797 self.dtype = datatype_str
852 self.dtype = datatype_str
798 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
853 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
799 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
854 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
800 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
855 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
801 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
856 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
802 self.getBlockDimension()
857 self.getBlockDimension()
803
858
804
859
805 def __verifyFile(self, filename, msgFlag=True):
860 def __verifyFile(self, filename, msgFlag=True):
806 msg = None
861 msg = None
807 try:
862 try:
808 fp = open(filename, 'rb')
863 fp = open(filename, 'rb')
809 currentPosition = fp.tell()
864 currentPosition = fp.tell()
810 except:
865 except:
811 if msgFlag:
866 if msgFlag:
812 print "The file %s can't be opened" % (filename)
867 print "The file %s can't be opened" % (filename)
813 return False
868 return False
814
869
815 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
870 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
816
871
817 if neededSize == 0:
872 if neededSize == 0:
818 basicHeaderObj = BasicHeader(LOCALTIME)
873 basicHeaderObj = BasicHeader(LOCALTIME)
819 systemHeaderObj = SystemHeader()
874 systemHeaderObj = SystemHeader()
820 radarControllerHeaderObj = RadarControllerHeader()
875 radarControllerHeaderObj = RadarControllerHeader()
821 processingHeaderObj = ProcessingHeader()
876 processingHeaderObj = ProcessingHeader()
822
877
823 try:
878 try:
824 if not( basicHeaderObj.read(fp) ): raise IOError
879 if not( basicHeaderObj.read(fp) ): raise IOError
825 if not( systemHeaderObj.read(fp) ): raise IOError
880 if not( systemHeaderObj.read(fp) ): raise IOError
826 if not( radarControllerHeaderObj.read(fp) ): raise IOError
881 if not( radarControllerHeaderObj.read(fp) ): raise IOError
827 if not( processingHeaderObj.read(fp) ): raise IOError
882 if not( processingHeaderObj.read(fp) ): raise IOError
828 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
883 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
829
884
830 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
885 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
831
886
832 except:
887 except:
833 if msgFlag:
888 if msgFlag:
834 print "\tThe file %s is empty or it hasn't enough data" % filename
889 print "\tThe file %s is empty or it hasn't enough data" % filename
835
890
836 fp.close()
891 fp.close()
837 return False
892 return False
838 else:
893 else:
839 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
894 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
840
895
841 fp.close()
896 fp.close()
842 fileSize = os.path.getsize(filename)
897 fileSize = os.path.getsize(filename)
843 currentSize = fileSize - currentPosition
898 currentSize = fileSize - currentPosition
844 if currentSize < neededSize:
899 if currentSize < neededSize:
845 if msgFlag and (msg != None):
900 if msgFlag and (msg != None):
846 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
901 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
847 return False
902 return False
848
903
849 return True
904 return True
850
905
851 def setup(self,
906 def setup(self,
852 path=None,
907 path=None,
853 startDate=None,
908 startDate=None,
854 endDate=None,
909 endDate=None,
855 startTime=datetime.time(0,0,0),
910 startTime=datetime.time(0,0,0),
856 endTime=datetime.time(23,59,59),
911 endTime=datetime.time(23,59,59),
857 set=0,
912 set=None,
858 expLabel = "",
913 expLabel = "",
859 ext = None,
914 ext = None,
860 online = False,
915 online = False,
861 delay = 60,
916 delay = 60,
862 walk = True):
917 walk = True):
863
918
864 if path == None:
919 if path == None:
865 raise ValueError, "The path is not valid"
920 raise ValueError, "The path is not valid"
866
921
867 if ext == None:
922 if ext == None:
868 ext = self.ext
923 ext = self.ext
869
924
870 if online:
925 if online:
871 print "Searching files in online mode..."
926 print "Searching files in online mode..."
872
927
873 for nTries in range( self.nTries ):
928 for nTries in range( self.nTries ):
874 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
929 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
875
930
876 if fullpath:
931 if fullpath:
877 break
932 break
878
933
879 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
934 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
880 time.sleep( self.delay )
935 time.sleep( self.delay )
881
936
882 if not(fullpath):
937 if not(fullpath):
883 print "There 'isn't valied files in %s" % path
938 print "There 'isn't valied files in %s" % path
884 return None
939 return None
885
940
886 self.year = year
941 self.year = year
887 self.doy = doy
942 self.doy = doy
888 self.set = set - 1
943 self.set = set - 1
889 self.path = path
944 self.path = path
890 self.foldercounter = foldercounter
945 self.foldercounter = foldercounter
891
946
892 else:
947 else:
893 print "Searching files in offline mode ..."
948 print "Searching files in offline mode ..."
894 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
949 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
895 startTime=startTime, endTime=endTime,
950 startTime=startTime, endTime=endTime,
896 set=set, expLabel=expLabel, ext=ext,
951 set=set, expLabel=expLabel, ext=ext,
897 walk=walk)
952 walk=walk)
898
953
899 if not(pathList):
954 if not(pathList):
900 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
955 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
901 datetime.datetime.combine(startDate,startTime).ctime(),
956 datetime.datetime.combine(startDate,startTime).ctime(),
902 datetime.datetime.combine(endDate,endTime).ctime())
957 datetime.datetime.combine(endDate,endTime).ctime())
903
958
904 sys.exit(-1)
959 sys.exit(-1)
905
960
906
961
907 self.fileIndex = -1
962 self.fileIndex = -1
908 self.pathList = pathList
963 self.pathList = pathList
909 self.filenameList = filenameList
964 self.filenameList = filenameList
910
965
911 self.online = online
966 self.online = online
912 self.delay = delay
967 self.delay = delay
913 ext = ext.lower()
968 ext = ext.lower()
914 self.ext = ext
969 self.ext = ext
915
970
916 if not(self.setNextFile()):
971 if not(self.setNextFile()):
917 if (startDate!=None) and (endDate!=None):
972 if (startDate!=None) and (endDate!=None):
918 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
973 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
919 elif startDate != None:
974 elif startDate != None:
920 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
975 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
921 else:
976 else:
922 print "No files"
977 print "No files"
923
978
924 sys.exit(-1)
979 sys.exit(-1)
925
980
926 # self.updateDataHeader()
981 # self.updateDataHeader()
927
982
928 return self.dataOut
983 return self.dataOut
929
984
930 def getBasicHeader(self):
985 def getBasicHeader(self):
931
986
932 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
987 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
933
988
934 self.dataOut.flagTimeBlock = self.flagTimeBlock
989 self.dataOut.flagTimeBlock = self.flagTimeBlock
935
990
936 self.dataOut.timeZone = self.basicHeaderObj.timeZone
991 self.dataOut.timeZone = self.basicHeaderObj.timeZone
937
992
938 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
993 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
939
994
940 self.dataOut.errorCount = self.basicHeaderObj.errorCount
995 self.dataOut.errorCount = self.basicHeaderObj.errorCount
941
996
942 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
997 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
943
998
944 def getFirstHeader(self):
999 def getFirstHeader(self):
945
1000
946 raise ValueError, "This method has not been implemented"
1001 raise ValueError, "This method has not been implemented"
947
1002
948 def getData():
1003 def getData():
949
1004
950 raise ValueError, "This method has not been implemented"
1005 raise ValueError, "This method has not been implemented"
951
1006
952 def hasNotDataInBuffer():
1007 def hasNotDataInBuffer():
953
1008
954 raise ValueError, "This method has not been implemented"
1009 raise ValueError, "This method has not been implemented"
955
1010
956 def readBlock():
1011 def readBlock():
957
1012
958 raise ValueError, "This method has not been implemented"
1013 raise ValueError, "This method has not been implemented"
959
1014
960 def isEndProcess(self):
1015 def isEndProcess(self):
961
1016
962 return self.flagNoMoreFiles
1017 return self.flagNoMoreFiles
963
1018
964 def printReadBlocks(self):
1019 def printReadBlocks(self):
965
1020
966 print "Number of read blocks per file %04d" %self.nReadBlocks
1021 print "Number of read blocks per file %04d" %self.nReadBlocks
967
1022
968 def printTotalBlocks(self):
1023 def printTotalBlocks(self):
969
1024
970 print "Number of read blocks %04d" %self.nTotalBlocks
1025 print "Number of read blocks %04d" %self.nTotalBlocks
971
1026
972 def printNumberOfBlock(self):
1027 def printNumberOfBlock(self):
973
1028
974 if self.flagIsNewBlock:
1029 if self.flagIsNewBlock:
975 print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime())
1030 print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime())
976
1031
977 def printInfo(self):
1032 def printInfo(self):
978
1033
979 if self.__printInfo == False:
1034 if self.__printInfo == False:
980 return
1035 return
981
1036
982 self.basicHeaderObj.printInfo()
1037 self.basicHeaderObj.printInfo()
983 self.systemHeaderObj.printInfo()
1038 self.systemHeaderObj.printInfo()
984 self.radarControllerHeaderObj.printInfo()
1039 self.radarControllerHeaderObj.printInfo()
985 self.processingHeaderObj.printInfo()
1040 self.processingHeaderObj.printInfo()
986
1041
987 self.__printInfo = False
1042 self.__printInfo = False
988
1043
989
1044
990 def run(self, **kwargs):
1045 def run(self, **kwargs):
991
1046
992 if not(self.isConfig):
1047 if not(self.isConfig):
993
1048
994 # self.dataOut = dataOut
1049 # self.dataOut = dataOut
995 self.setup(**kwargs)
1050 self.setup(**kwargs)
996 self.isConfig = True
1051 self.isConfig = True
997
1052
998 self.getData()
1053 self.getData()
999
1054
1000 class JRODataWriter(JRODataIO, Operation):
1055 class JRODataWriter(JRODataIO, Operation):
1001
1056
1002 """
1057 """
1003 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1058 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1004 de los datos siempre se realiza por bloques.
1059 de los datos siempre se realiza por bloques.
1005 """
1060 """
1006
1061
1007 blockIndex = 0
1062 blockIndex = 0
1008
1063
1009 path = None
1064 path = None
1010
1065
1011 setFile = None
1066 setFile = None
1012
1067
1013 profilesPerBlock = None
1068 profilesPerBlock = None
1014
1069
1015 blocksPerFile = None
1070 blocksPerFile = None
1016
1071
1017 nWriteBlocks = 0
1072 nWriteBlocks = 0
1018
1073
1019 def __init__(self, dataOut=None):
1074 def __init__(self, dataOut=None):
1020 raise ValueError, "Not implemented"
1075 raise ValueError, "Not implemented"
1021
1076
1022
1077
1023 def hasAllDataInBuffer(self):
1078 def hasAllDataInBuffer(self):
1024 raise ValueError, "Not implemented"
1079 raise ValueError, "Not implemented"
1025
1080
1026
1081
1027 def setBlockDimension(self):
1082 def setBlockDimension(self):
1028 raise ValueError, "Not implemented"
1083 raise ValueError, "Not implemented"
1029
1084
1030
1085
1031 def writeBlock(self):
1086 def writeBlock(self):
1032 raise ValueError, "No implemented"
1087 raise ValueError, "No implemented"
1033
1088
1034
1089
1035 def putData(self):
1090 def putData(self):
1036 raise ValueError, "No implemented"
1091 raise ValueError, "No implemented"
1037
1092
1038
1093
1039 def setBasicHeader(self):
1094 def setBasicHeader(self):
1040
1095
1041 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1096 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1042 self.basicHeaderObj.version = self.versionFile
1097 self.basicHeaderObj.version = self.versionFile
1043 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1098 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1044
1099
1045 utc = numpy.floor(self.dataOut.utctime)
1100 utc = numpy.floor(self.dataOut.utctime)
1046 milisecond = (self.dataOut.utctime - utc)* 1000.0
1101 milisecond = (self.dataOut.utctime - utc)* 1000.0
1047
1102
1048 self.basicHeaderObj.utc = utc
1103 self.basicHeaderObj.utc = utc
1049 self.basicHeaderObj.miliSecond = milisecond
1104 self.basicHeaderObj.miliSecond = milisecond
1050 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1105 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1051 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1106 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1052 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1107 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1053
1108
1054 def setFirstHeader(self):
1109 def setFirstHeader(self):
1055 """
1110 """
1056 Obtiene una copia del First Header
1111 Obtiene una copia del First Header
1057
1112
1058 Affected:
1113 Affected:
1059
1114
1060 self.basicHeaderObj
1115 self.basicHeaderObj
1061 self.systemHeaderObj
1116 self.systemHeaderObj
1062 self.radarControllerHeaderObj
1117 self.radarControllerHeaderObj
1063 self.processingHeaderObj self.
1118 self.processingHeaderObj self.
1064
1119
1065 Return:
1120 Return:
1066 None
1121 None
1067 """
1122 """
1068
1123
1069 raise ValueError, "No implemented"
1124 raise ValueError, "No implemented"
1070
1125
1071 def __writeFirstHeader(self):
1126 def __writeFirstHeader(self):
1072 """
1127 """
1073 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1128 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1074
1129
1075 Affected:
1130 Affected:
1076 __dataType
1131 __dataType
1077
1132
1078 Return:
1133 Return:
1079 None
1134 None
1080 """
1135 """
1081
1136
1082 # CALCULAR PARAMETROS
1137 # CALCULAR PARAMETROS
1083
1138
1084 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1139 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1085 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1140 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1086
1141
1087 self.basicHeaderObj.write(self.fp)
1142 self.basicHeaderObj.write(self.fp)
1088 self.systemHeaderObj.write(self.fp)
1143 self.systemHeaderObj.write(self.fp)
1089 self.radarControllerHeaderObj.write(self.fp)
1144 self.radarControllerHeaderObj.write(self.fp)
1090 self.processingHeaderObj.write(self.fp)
1145 self.processingHeaderObj.write(self.fp)
1091
1146
1092 self.dtype = self.dataOut.dtype
1147 self.dtype = self.dataOut.dtype
1093
1148
1094 def __setNewBlock(self):
1149 def __setNewBlock(self):
1095 """
1150 """
1096 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1151 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1097
1152
1098 Return:
1153 Return:
1099 0 : si no pudo escribir nada
1154 0 : si no pudo escribir nada
1100 1 : Si escribio el Basic el First Header
1155 1 : Si escribio el Basic el First Header
1101 """
1156 """
1102 if self.fp == None:
1157 if self.fp == None:
1103 self.setNextFile()
1158 self.setNextFile()
1104
1159
1105 if self.flagIsNewFile:
1160 if self.flagIsNewFile:
1106 return 1
1161 return 1
1107
1162
1108 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1163 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1109 self.basicHeaderObj.write(self.fp)
1164 self.basicHeaderObj.write(self.fp)
1110 return 1
1165 return 1
1111
1166
1112 if not( self.setNextFile() ):
1167 if not( self.setNextFile() ):
1113 return 0
1168 return 0
1114
1169
1115 return 1
1170 return 1
1116
1171
1117
1172
1118 def writeNextBlock(self):
1173 def writeNextBlock(self):
1119 """
1174 """
1120 Selecciona el bloque siguiente de datos y los escribe en un file
1175 Selecciona el bloque siguiente de datos y los escribe en un file
1121
1176
1122 Return:
1177 Return:
1123 0 : Si no hizo pudo escribir el bloque de datos
1178 0 : Si no hizo pudo escribir el bloque de datos
1124 1 : Si no pudo escribir el bloque de datos
1179 1 : Si no pudo escribir el bloque de datos
1125 """
1180 """
1126 if not( self.__setNewBlock() ):
1181 if not( self.__setNewBlock() ):
1127 return 0
1182 return 0
1128
1183
1129 self.writeBlock()
1184 self.writeBlock()
1130
1185
1131 return 1
1186 return 1
1132
1187
1133 def setNextFile(self):
1188 def setNextFile(self):
1134 """
1189 """
1135 Determina el siguiente file que sera escrito
1190 Determina el siguiente file que sera escrito
1136
1191
1137 Affected:
1192 Affected:
1138 self.filename
1193 self.filename
1139 self.subfolder
1194 self.subfolder
1140 self.fp
1195 self.fp
1141 self.setFile
1196 self.setFile
1142 self.flagIsNewFile
1197 self.flagIsNewFile
1143
1198
1144 Return:
1199 Return:
1145 0 : Si el archivo no puede ser escrito
1200 0 : Si el archivo no puede ser escrito
1146 1 : Si el archivo esta listo para ser escrito
1201 1 : Si el archivo esta listo para ser escrito
1147 """
1202 """
1148 ext = self.ext
1203 ext = self.ext
1149 path = self.path
1204 path = self.path
1150
1205
1151 if self.fp != None:
1206 if self.fp != None:
1152 self.fp.close()
1207 self.fp.close()
1153
1208
1154 timeTuple = time.localtime( self.dataOut.utctime)
1209 timeTuple = time.localtime( self.dataOut.utctime)
1155 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1210 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1156
1211
1157 fullpath = os.path.join( path, subfolder )
1212 fullpath = os.path.join( path, subfolder )
1158 if not( os.path.exists(fullpath) ):
1213 if not( os.path.exists(fullpath) ):
1159 os.mkdir(fullpath)
1214 os.mkdir(fullpath)
1160 self.setFile = -1 #inicializo mi contador de seteo
1215 self.setFile = -1 #inicializo mi contador de seteo
1161 else:
1216 else:
1162 filesList = os.listdir( fullpath )
1217 filesList = os.listdir( fullpath )
1163 if len( filesList ) > 0:
1218 if len( filesList ) > 0:
1164 filesList = sorted( filesList, key=str.lower )
1219 filesList = sorted( filesList, key=str.lower )
1165 filen = filesList[-1]
1220 filen = filesList[-1]
1166 # el filename debera tener el siguiente formato
1221 # el filename debera tener el siguiente formato
1167 # 0 1234 567 89A BCDE (hex)
1222 # 0 1234 567 89A BCDE (hex)
1168 # x YYYY DDD SSS .ext
1223 # x YYYY DDD SSS .ext
1169 if isNumber( filen[8:11] ):
1224 if isNumber( filen[8:11] ):
1170 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1225 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1171 else:
1226 else:
1172 self.setFile = -1
1227 self.setFile = -1
1173 else:
1228 else:
1174 self.setFile = -1 #inicializo mi contador de seteo
1229 self.setFile = -1 #inicializo mi contador de seteo
1175
1230
1176 setFile = self.setFile
1231 setFile = self.setFile
1177 setFile += 1
1232 setFile += 1
1178
1233
1179 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1234 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1180 timeTuple.tm_year,
1235 timeTuple.tm_year,
1181 timeTuple.tm_yday,
1236 timeTuple.tm_yday,
1182 setFile,
1237 setFile,
1183 ext )
1238 ext )
1184
1239
1185 filename = os.path.join( path, subfolder, file )
1240 filename = os.path.join( path, subfolder, file )
1186
1241
1187 fp = open( filename,'wb' )
1242 fp = open( filename,'wb' )
1188
1243
1189 self.blockIndex = 0
1244 self.blockIndex = 0
1190
1245
1191 #guardando atributos
1246 #guardando atributos
1192 self.filename = filename
1247 self.filename = filename
1193 self.subfolder = subfolder
1248 self.subfolder = subfolder
1194 self.fp = fp
1249 self.fp = fp
1195 self.setFile = setFile
1250 self.setFile = setFile
1196 self.flagIsNewFile = 1
1251 self.flagIsNewFile = 1
1197
1252
1198 self.setFirstHeader()
1253 self.setFirstHeader()
1199
1254
1200 print 'Writing the file: %s'%self.filename
1255 print 'Writing the file: %s'%self.filename
1201
1256
1202 self.__writeFirstHeader()
1257 self.__writeFirstHeader()
1203
1258
1204 return 1
1259 return 1
1205
1260
1206 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1261 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1207 """
1262 """
1208 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1263 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1209
1264
1210 Inputs:
1265 Inputs:
1211 path : el path destino en el cual se escribiran los files a crear
1266 path : el path destino en el cual se escribiran los files a crear
1212 format : formato en el cual sera salvado un file
1267 format : formato en el cual sera salvado un file
1213 set : el setebo del file
1268 set : el setebo del file
1214
1269
1215 Return:
1270 Return:
1216 0 : Si no realizo un buen seteo
1271 0 : Si no realizo un buen seteo
1217 1 : Si realizo un buen seteo
1272 1 : Si realizo un buen seteo
1218 """
1273 """
1219
1274
1220 if ext == None:
1275 if ext == None:
1221 ext = self.ext
1276 ext = self.ext
1222
1277
1223 ext = ext.lower()
1278 ext = ext.lower()
1224
1279
1225 self.ext = ext
1280 self.ext = ext
1226
1281
1227 self.path = path
1282 self.path = path
1228
1283
1229 self.setFile = set - 1
1284 self.setFile = set - 1
1230
1285
1231 self.blocksPerFile = blocksPerFile
1286 self.blocksPerFile = blocksPerFile
1232
1287
1233 self.profilesPerBlock = profilesPerBlock
1288 self.profilesPerBlock = profilesPerBlock
1234
1289
1235 self.dataOut = dataOut
1290 self.dataOut = dataOut
1236
1291
1237 if not(self.setNextFile()):
1292 if not(self.setNextFile()):
1238 print "There isn't a next file"
1293 print "There isn't a next file"
1239 return 0
1294 return 0
1240
1295
1241 self.setBlockDimension()
1296 self.setBlockDimension()
1242
1297
1243 return 1
1298 return 1
1244
1299
1245 def run(self, dataOut, **kwargs):
1300 def run(self, dataOut, **kwargs):
1246
1301
1247 if not(self.isConfig):
1302 if not(self.isConfig):
1248
1303
1249 self.setup(dataOut, **kwargs)
1304 self.setup(dataOut, **kwargs)
1250 self.isConfig = True
1305 self.isConfig = True
1251
1306
1252 self.putData()
1307 self.putData()
1253
1308
1254 class VoltageReader(JRODataReader):
1309 class VoltageReader(JRODataReader):
1255 """
1310 """
1256 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1311 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1257 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1312 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1258 perfiles*alturas*canales) son almacenados en la variable "buffer".
1313 perfiles*alturas*canales) son almacenados en la variable "buffer".
1259
1314
1260 perfiles * alturas * canales
1315 perfiles * alturas * canales
1261
1316
1262 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1317 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1263 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1318 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1264 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1319 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1265 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1320 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1266
1321
1267 Example:
1322 Example:
1268
1323
1269 dpath = "/home/myuser/data"
1324 dpath = "/home/myuser/data"
1270
1325
1271 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1326 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1272
1327
1273 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1328 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1274
1329
1275 readerObj = VoltageReader()
1330 readerObj = VoltageReader()
1276
1331
1277 readerObj.setup(dpath, startTime, endTime)
1332 readerObj.setup(dpath, startTime, endTime)
1278
1333
1279 while(True):
1334 while(True):
1280
1335
1281 #to get one profile
1336 #to get one profile
1282 profile = readerObj.getData()
1337 profile = readerObj.getData()
1283
1338
1284 #print the profile
1339 #print the profile
1285 print profile
1340 print profile
1286
1341
1287 #If you want to see all datablock
1342 #If you want to see all datablock
1288 print readerObj.datablock
1343 print readerObj.datablock
1289
1344
1290 if readerObj.flagNoMoreFiles:
1345 if readerObj.flagNoMoreFiles:
1291 break
1346 break
1292
1347
1293 """
1348 """
1294
1349
1295 ext = ".r"
1350 ext = ".r"
1296
1351
1297 optchar = "D"
1352 optchar = "D"
1298 dataOut = None
1353 dataOut = None
1299
1354
1300
1355
1301 def __init__(self):
1356 def __init__(self):
1302 """
1357 """
1303 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1358 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1304
1359
1305 Input:
1360 Input:
1306 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1361 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1307 almacenar un perfil de datos cada vez que se haga un requerimiento
1362 almacenar un perfil de datos cada vez que se haga un requerimiento
1308 (getData). El perfil sera obtenido a partir del buffer de datos,
1363 (getData). El perfil sera obtenido a partir del buffer de datos,
1309 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1364 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1310 bloque de datos.
1365 bloque de datos.
1311 Si este parametro no es pasado se creara uno internamente.
1366 Si este parametro no es pasado se creara uno internamente.
1312
1367
1313 Variables afectadas:
1368 Variables afectadas:
1314 self.dataOut
1369 self.dataOut
1315
1370
1316 Return:
1371 Return:
1317 None
1372 None
1318 """
1373 """
1319
1374
1320 self.isConfig = False
1375 self.isConfig = False
1321
1376
1322 self.datablock = None
1377 self.datablock = None
1323
1378
1324 self.utc = 0
1379 self.utc = 0
1325
1380
1326 self.ext = ".r"
1381 self.ext = ".r"
1327
1382
1328 self.optchar = "D"
1383 self.optchar = "D"
1329
1384
1330 self.basicHeaderObj = BasicHeader(LOCALTIME)
1385 self.basicHeaderObj = BasicHeader(LOCALTIME)
1331
1386
1332 self.systemHeaderObj = SystemHeader()
1387 self.systemHeaderObj = SystemHeader()
1333
1388
1334 self.radarControllerHeaderObj = RadarControllerHeader()
1389 self.radarControllerHeaderObj = RadarControllerHeader()
1335
1390
1336 self.processingHeaderObj = ProcessingHeader()
1391 self.processingHeaderObj = ProcessingHeader()
1337
1392
1338 self.online = 0
1393 self.online = 0
1339
1394
1340 self.fp = None
1395 self.fp = None
1341
1396
1342 self.idFile = None
1397 self.idFile = None
1343
1398
1344 self.dtype = None
1399 self.dtype = None
1345
1400
1346 self.fileSizeByHeader = None
1401 self.fileSizeByHeader = None
1347
1402
1348 self.filenameList = []
1403 self.filenameList = []
1349
1404
1350 self.filename = None
1405 self.filename = None
1351
1406
1352 self.fileSize = None
1407 self.fileSize = None
1353
1408
1354 self.firstHeaderSize = 0
1409 self.firstHeaderSize = 0
1355
1410
1356 self.basicHeaderSize = 24
1411 self.basicHeaderSize = 24
1357
1412
1358 self.pathList = []
1413 self.pathList = []
1359
1414
1360 self.filenameList = []
1415 self.filenameList = []
1361
1416
1362 self.lastUTTime = 0
1417 self.lastUTTime = 0
1363
1418
1364 self.maxTimeStep = 30
1419 self.maxTimeStep = 30
1365
1420
1366 self.flagNoMoreFiles = 0
1421 self.flagNoMoreFiles = 0
1367
1422
1368 self.set = 0
1423 self.set = 0
1369
1424
1370 self.path = None
1425 self.path = None
1371
1426
1372 self.profileIndex = 2**32-1
1427 self.profileIndex = 2**32-1
1373
1428
1374 self.delay = 3 #seconds
1429 self.delay = 3 #seconds
1375
1430
1376 self.nTries = 3 #quantity tries
1431 self.nTries = 3 #quantity tries
1377
1432
1378 self.nFiles = 3 #number of files for searching
1433 self.nFiles = 3 #number of files for searching
1379
1434
1380 self.nReadBlocks = 0
1435 self.nReadBlocks = 0
1381
1436
1382 self.flagIsNewFile = 1
1437 self.flagIsNewFile = 1
1383
1438
1384 self.__isFirstTimeOnline = 1
1439 self.__isFirstTimeOnline = 1
1385
1440
1386 self.ippSeconds = 0
1441 self.ippSeconds = 0
1387
1442
1388 self.flagTimeBlock = 0
1443 self.flagTimeBlock = 0
1389
1444
1390 self.flagIsNewBlock = 0
1445 self.flagIsNewBlock = 0
1391
1446
1392 self.nTotalBlocks = 0
1447 self.nTotalBlocks = 0
1393
1448
1394 self.blocksize = 0
1449 self.blocksize = 0
1395
1450
1396 self.dataOut = self.createObjByDefault()
1451 self.dataOut = self.createObjByDefault()
1397
1452
1398 def createObjByDefault(self):
1453 def createObjByDefault(self):
1399
1454
1400 dataObj = Voltage()
1455 dataObj = Voltage()
1401
1456
1402 return dataObj
1457 return dataObj
1403
1458
1404 def __hasNotDataInBuffer(self):
1459 def __hasNotDataInBuffer(self):
1405 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1460 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1406 return 1
1461 return 1
1407 return 0
1462 return 0
1408
1463
1409
1464
1410 def getBlockDimension(self):
1465 def getBlockDimension(self):
1411 """
1466 """
1412 Obtiene la cantidad de puntos a leer por cada bloque de datos
1467 Obtiene la cantidad de puntos a leer por cada bloque de datos
1413
1468
1414 Affected:
1469 Affected:
1415 self.blocksize
1470 self.blocksize
1416
1471
1417 Return:
1472 Return:
1418 None
1473 None
1419 """
1474 """
1420 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1475 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1421 self.blocksize = pts2read
1476 self.blocksize = pts2read
1422
1477
1423
1478
1424 def readBlock(self):
1479 def readBlock(self):
1425 """
1480 """
1426 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1481 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1427 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1482 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1428 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1483 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1429 es seteado a 0
1484 es seteado a 0
1430
1485
1431 Inputs:
1486 Inputs:
1432 None
1487 None
1433
1488
1434 Return:
1489 Return:
1435 None
1490 None
1436
1491
1437 Affected:
1492 Affected:
1438 self.profileIndex
1493 self.profileIndex
1439 self.datablock
1494 self.datablock
1440 self.flagIsNewFile
1495 self.flagIsNewFile
1441 self.flagIsNewBlock
1496 self.flagIsNewBlock
1442 self.nTotalBlocks
1497 self.nTotalBlocks
1443
1498
1444 Exceptions:
1499 Exceptions:
1445 Si un bloque leido no es un bloque valido
1500 Si un bloque leido no es un bloque valido
1446 """
1501 """
1447
1502
1448 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1503 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1449
1504
1450 try:
1505 try:
1451 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1506 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1452 except:
1507 except:
1453 print "The read block (%3d) has not enough data" %self.nReadBlocks
1508 print "The read block (%3d) has not enough data" %self.nReadBlocks
1454 return 0
1509 return 0
1455
1510
1456 junk = numpy.transpose(junk, (2,0,1))
1511 junk = numpy.transpose(junk, (2,0,1))
1457 self.datablock = junk['real'] + junk['imag']*1j
1512 self.datablock = junk['real'] + junk['imag']*1j
1458
1513
1459 self.profileIndex = 0
1514 self.profileIndex = 0
1460
1515
1461 self.flagIsNewFile = 0
1516 self.flagIsNewFile = 0
1462 self.flagIsNewBlock = 1
1517 self.flagIsNewBlock = 1
1463
1518
1464 self.nTotalBlocks += 1
1519 self.nTotalBlocks += 1
1465 self.nReadBlocks += 1
1520 self.nReadBlocks += 1
1466
1521
1467 return 1
1522 return 1
1468
1523
1469 def getFirstHeader(self):
1524 def getFirstHeader(self):
1470
1525
1471 self.dataOut.dtype = self.dtype
1526 self.dataOut.dtype = self.dtype
1472
1527
1473 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1528 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1474
1529
1475 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1530 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1476
1531
1477 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1532 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1478
1533
1479 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1534 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1480
1535
1481 self.dataOut.ippSeconds = self.ippSeconds
1536 self.dataOut.ippSeconds = self.ippSeconds
1482
1537
1483 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1538 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1484
1539
1485 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1540 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1486
1541
1487 self.dataOut.flagShiftFFT = False
1542 self.dataOut.flagShiftFFT = False
1488
1543
1489 if self.radarControllerHeaderObj.code != None:
1544 if self.radarControllerHeaderObj.code != None:
1490
1545
1491 self.dataOut.nCode = self.radarControllerHeaderObj.nCode
1546 self.dataOut.nCode = self.radarControllerHeaderObj.nCode
1492
1547
1493 self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
1548 self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
1494
1549
1495 self.dataOut.code = self.radarControllerHeaderObj.code
1550 self.dataOut.code = self.radarControllerHeaderObj.code
1496
1551
1497 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1552 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1498
1553
1499 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1554 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1500
1555
1501 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1556 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1502
1557
1503 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1558 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1504
1559
1505 self.dataOut.flagShiftFFT = False
1560 self.dataOut.flagShiftFFT = False
1506
1561
1507 def getData(self):
1562 def getData(self):
1508 """
1563 """
1509 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1564 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1510 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1565 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1511 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1566 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1512
1567
1513 Ademas incrementa el contador del buffer en 1.
1568 Ademas incrementa el contador del buffer en 1.
1514
1569
1515 Return:
1570 Return:
1516 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1571 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1517 buffer. Si no hay mas archivos a leer retorna None.
1572 buffer. Si no hay mas archivos a leer retorna None.
1518
1573
1519 Variables afectadas:
1574 Variables afectadas:
1520 self.dataOut
1575 self.dataOut
1521 self.profileIndex
1576 self.profileIndex
1522
1577
1523 Affected:
1578 Affected:
1524 self.dataOut
1579 self.dataOut
1525 self.profileIndex
1580 self.profileIndex
1526 self.flagTimeBlock
1581 self.flagTimeBlock
1527 self.flagIsNewBlock
1582 self.flagIsNewBlock
1528 """
1583 """
1529
1584
1530 if self.flagNoMoreFiles:
1585 if self.flagNoMoreFiles:
1531 self.dataOut.flagNoData = True
1586 self.dataOut.flagNoData = True
1532 print 'Process finished'
1587 print 'Process finished'
1533 return 0
1588 return 0
1534
1589
1535 self.flagTimeBlock = 0
1590 self.flagTimeBlock = 0
1536 self.flagIsNewBlock = 0
1591 self.flagIsNewBlock = 0
1537
1592
1538 if self.__hasNotDataInBuffer():
1593 if self.__hasNotDataInBuffer():
1539
1594
1540 if not( self.readNextBlock() ):
1595 if not( self.readNextBlock() ):
1541 return 0
1596 return 0
1542
1597
1543 self.getFirstHeader()
1598 self.getFirstHeader()
1544
1599
1545 if self.datablock == None:
1600 if self.datablock == None:
1546 self.dataOut.flagNoData = True
1601 self.dataOut.flagNoData = True
1547 return 0
1602 return 0
1548
1603
1549 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1604 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1550
1605
1551 self.dataOut.flagNoData = False
1606 self.dataOut.flagNoData = False
1552
1607
1553 self.getBasicHeader()
1608 self.getBasicHeader()
1554
1609
1555 self.profileIndex += 1
1610 self.profileIndex += 1
1556
1611
1557 self.dataOut.realtime = self.online
1612 self.dataOut.realtime = self.online
1558
1613
1559 return self.dataOut.data
1614 return self.dataOut.data
1560
1615
1561
1616
1562 class VoltageWriter(JRODataWriter):
1617 class VoltageWriter(JRODataWriter):
1563 """
1618 """
1564 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1619 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1565 de los datos siempre se realiza por bloques.
1620 de los datos siempre se realiza por bloques.
1566 """
1621 """
1567
1622
1568 ext = ".r"
1623 ext = ".r"
1569
1624
1570 optchar = "D"
1625 optchar = "D"
1571
1626
1572 shapeBuffer = None
1627 shapeBuffer = None
1573
1628
1574
1629
1575 def __init__(self):
1630 def __init__(self):
1576 """
1631 """
1577 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1632 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1578
1633
1579 Affected:
1634 Affected:
1580 self.dataOut
1635 self.dataOut
1581
1636
1582 Return: None
1637 Return: None
1583 """
1638 """
1584
1639
1585 self.nTotalBlocks = 0
1640 self.nTotalBlocks = 0
1586
1641
1587 self.profileIndex = 0
1642 self.profileIndex = 0
1588
1643
1589 self.isConfig = False
1644 self.isConfig = False
1590
1645
1591 self.fp = None
1646 self.fp = None
1592
1647
1593 self.flagIsNewFile = 1
1648 self.flagIsNewFile = 1
1594
1649
1595 self.nTotalBlocks = 0
1650 self.nTotalBlocks = 0
1596
1651
1597 self.flagIsNewBlock = 0
1652 self.flagIsNewBlock = 0
1598
1653
1599 self.setFile = None
1654 self.setFile = None
1600
1655
1601 self.dtype = None
1656 self.dtype = None
1602
1657
1603 self.path = None
1658 self.path = None
1604
1659
1605 self.filename = None
1660 self.filename = None
1606
1661
1607 self.basicHeaderObj = BasicHeader(LOCALTIME)
1662 self.basicHeaderObj = BasicHeader(LOCALTIME)
1608
1663
1609 self.systemHeaderObj = SystemHeader()
1664 self.systemHeaderObj = SystemHeader()
1610
1665
1611 self.radarControllerHeaderObj = RadarControllerHeader()
1666 self.radarControllerHeaderObj = RadarControllerHeader()
1612
1667
1613 self.processingHeaderObj = ProcessingHeader()
1668 self.processingHeaderObj = ProcessingHeader()
1614
1669
1615 def hasAllDataInBuffer(self):
1670 def hasAllDataInBuffer(self):
1616 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1671 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1617 return 1
1672 return 1
1618 return 0
1673 return 0
1619
1674
1620
1675
1621 def setBlockDimension(self):
1676 def setBlockDimension(self):
1622 """
1677 """
1623 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1678 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1624
1679
1625 Affected:
1680 Affected:
1626 self.shape_spc_Buffer
1681 self.shape_spc_Buffer
1627 self.shape_cspc_Buffer
1682 self.shape_cspc_Buffer
1628 self.shape_dc_Buffer
1683 self.shape_dc_Buffer
1629
1684
1630 Return: None
1685 Return: None
1631 """
1686 """
1632 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1687 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1633 self.processingHeaderObj.nHeights,
1688 self.processingHeaderObj.nHeights,
1634 self.systemHeaderObj.nChannels)
1689 self.systemHeaderObj.nChannels)
1635
1690
1636 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1691 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1637 self.processingHeaderObj.profilesPerBlock,
1692 self.processingHeaderObj.profilesPerBlock,
1638 self.processingHeaderObj.nHeights),
1693 self.processingHeaderObj.nHeights),
1639 dtype=numpy.dtype('complex64'))
1694 dtype=numpy.dtype('complex64'))
1640
1695
1641
1696
1642 def writeBlock(self):
1697 def writeBlock(self):
1643 """
1698 """
1644 Escribe el buffer en el file designado
1699 Escribe el buffer en el file designado
1645
1700
1646 Affected:
1701 Affected:
1647 self.profileIndex
1702 self.profileIndex
1648 self.flagIsNewFile
1703 self.flagIsNewFile
1649 self.flagIsNewBlock
1704 self.flagIsNewBlock
1650 self.nTotalBlocks
1705 self.nTotalBlocks
1651 self.blockIndex
1706 self.blockIndex
1652
1707
1653 Return: None
1708 Return: None
1654 """
1709 """
1655 data = numpy.zeros( self.shapeBuffer, self.dtype )
1710 data = numpy.zeros( self.shapeBuffer, self.dtype )
1656
1711
1657 junk = numpy.transpose(self.datablock, (1,2,0))
1712 junk = numpy.transpose(self.datablock, (1,2,0))
1658
1713
1659 data['real'] = junk.real
1714 data['real'] = junk.real
1660 data['imag'] = junk.imag
1715 data['imag'] = junk.imag
1661
1716
1662 data = data.reshape( (-1) )
1717 data = data.reshape( (-1) )
1663
1718
1664 data.tofile( self.fp )
1719 data.tofile( self.fp )
1665
1720
1666 self.datablock.fill(0)
1721 self.datablock.fill(0)
1667
1722
1668 self.profileIndex = 0
1723 self.profileIndex = 0
1669 self.flagIsNewFile = 0
1724 self.flagIsNewFile = 0
1670 self.flagIsNewBlock = 1
1725 self.flagIsNewBlock = 1
1671
1726
1672 self.blockIndex += 1
1727 self.blockIndex += 1
1673 self.nTotalBlocks += 1
1728 self.nTotalBlocks += 1
1674
1729
1675 def putData(self):
1730 def putData(self):
1676 """
1731 """
1677 Setea un bloque de datos y luego los escribe en un file
1732 Setea un bloque de datos y luego los escribe en un file
1678
1733
1679 Affected:
1734 Affected:
1680 self.flagIsNewBlock
1735 self.flagIsNewBlock
1681 self.profileIndex
1736 self.profileIndex
1682
1737
1683 Return:
1738 Return:
1684 0 : Si no hay data o no hay mas files que puedan escribirse
1739 0 : Si no hay data o no hay mas files que puedan escribirse
1685 1 : Si se escribio la data de un bloque en un file
1740 1 : Si se escribio la data de un bloque en un file
1686 """
1741 """
1687 if self.dataOut.flagNoData:
1742 if self.dataOut.flagNoData:
1688 return 0
1743 return 0
1689
1744
1690 self.flagIsNewBlock = 0
1745 self.flagIsNewBlock = 0
1691
1746
1692 if self.dataOut.flagTimeBlock:
1747 if self.dataOut.flagTimeBlock:
1693
1748
1694 self.datablock.fill(0)
1749 self.datablock.fill(0)
1695 self.profileIndex = 0
1750 self.profileIndex = 0
1696 self.setNextFile()
1751 self.setNextFile()
1697
1752
1698 if self.profileIndex == 0:
1753 if self.profileIndex == 0:
1699 self.setBasicHeader()
1754 self.setBasicHeader()
1700
1755
1701 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1756 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1702
1757
1703 self.profileIndex += 1
1758 self.profileIndex += 1
1704
1759
1705 if self.hasAllDataInBuffer():
1760 if self.hasAllDataInBuffer():
1706 #if self.flagIsNewFile:
1761 #if self.flagIsNewFile:
1707 self.writeNextBlock()
1762 self.writeNextBlock()
1708 # self.setFirstHeader()
1763 # self.setFirstHeader()
1709
1764
1710 return 1
1765 return 1
1711
1766
1712 def __getProcessFlags(self):
1767 def __getProcessFlags(self):
1713
1768
1714 processFlags = 0
1769 processFlags = 0
1715
1770
1716 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1771 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1717 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1772 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1718 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1773 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1719 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1774 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1720 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1775 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1721 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1776 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1722
1777
1723 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1778 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1724
1779
1725
1780
1726
1781
1727 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1782 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1728 PROCFLAG.DATATYPE_SHORT,
1783 PROCFLAG.DATATYPE_SHORT,
1729 PROCFLAG.DATATYPE_LONG,
1784 PROCFLAG.DATATYPE_LONG,
1730 PROCFLAG.DATATYPE_INT64,
1785 PROCFLAG.DATATYPE_INT64,
1731 PROCFLAG.DATATYPE_FLOAT,
1786 PROCFLAG.DATATYPE_FLOAT,
1732 PROCFLAG.DATATYPE_DOUBLE]
1787 PROCFLAG.DATATYPE_DOUBLE]
1733
1788
1734
1789
1735 for index in range(len(dtypeList)):
1790 for index in range(len(dtypeList)):
1736 if self.dataOut.dtype == dtypeList[index]:
1791 if self.dataOut.dtype == dtypeList[index]:
1737 dtypeValue = datatypeValueList[index]
1792 dtypeValue = datatypeValueList[index]
1738 break
1793 break
1739
1794
1740 processFlags += dtypeValue
1795 processFlags += dtypeValue
1741
1796
1742 if self.dataOut.flagDecodeData:
1797 if self.dataOut.flagDecodeData:
1743 processFlags += PROCFLAG.DECODE_DATA
1798 processFlags += PROCFLAG.DECODE_DATA
1744
1799
1745 if self.dataOut.flagDeflipData:
1800 if self.dataOut.flagDeflipData:
1746 processFlags += PROCFLAG.DEFLIP_DATA
1801 processFlags += PROCFLAG.DEFLIP_DATA
1747
1802
1748 if self.dataOut.code != None:
1803 if self.dataOut.code != None:
1749 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1804 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1750
1805
1751 if self.dataOut.nCohInt > 1:
1806 if self.dataOut.nCohInt > 1:
1752 processFlags += PROCFLAG.COHERENT_INTEGRATION
1807 processFlags += PROCFLAG.COHERENT_INTEGRATION
1753
1808
1754 return processFlags
1809 return processFlags
1755
1810
1756
1811
1757 def __getBlockSize(self):
1812 def __getBlockSize(self):
1758 '''
1813 '''
1759 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1814 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1760 '''
1815 '''
1761
1816
1762 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1817 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1763 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1818 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1764 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1819 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1765 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1820 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1766 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1821 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1767 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1822 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1768
1823
1769 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1824 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1770 datatypeValueList = [1,2,4,8,4,8]
1825 datatypeValueList = [1,2,4,8,4,8]
1771 for index in range(len(dtypeList)):
1826 for index in range(len(dtypeList)):
1772 if self.dataOut.dtype == dtypeList[index]:
1827 if self.dataOut.dtype == dtypeList[index]:
1773 datatypeValue = datatypeValueList[index]
1828 datatypeValue = datatypeValueList[index]
1774 break
1829 break
1775
1830
1776 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1831 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1777
1832
1778 return blocksize
1833 return blocksize
1779
1834
1780 def setFirstHeader(self):
1835 def setFirstHeader(self):
1781
1836
1782 """
1837 """
1783 Obtiene una copia del First Header
1838 Obtiene una copia del First Header
1784
1839
1785 Affected:
1840 Affected:
1786 self.systemHeaderObj
1841 self.systemHeaderObj
1787 self.radarControllerHeaderObj
1842 self.radarControllerHeaderObj
1788 self.dtype
1843 self.dtype
1789
1844
1790 Return:
1845 Return:
1791 None
1846 None
1792 """
1847 """
1793
1848
1794 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1849 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1795 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1850 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1796 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1851 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1797
1852
1798 self.setBasicHeader()
1853 self.setBasicHeader()
1799
1854
1800 processingHeaderSize = 40 # bytes
1855 processingHeaderSize = 40 # bytes
1801 self.processingHeaderObj.dtype = 0 # Voltage
1856 self.processingHeaderObj.dtype = 0 # Voltage
1802 self.processingHeaderObj.blockSize = self.__getBlockSize()
1857 self.processingHeaderObj.blockSize = self.__getBlockSize()
1803 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1858 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1804 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1859 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1805 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1860 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1806 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1861 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1807 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1862 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1808 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1863 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1809 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1864 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1810
1865
1811 if self.dataOut.code != None:
1866 if self.dataOut.code != None:
1812 self.processingHeaderObj.code = self.dataOut.code
1867 self.processingHeaderObj.code = self.dataOut.code
1813 self.processingHeaderObj.nCode = self.dataOut.nCode
1868 self.processingHeaderObj.nCode = self.dataOut.nCode
1814 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1869 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1815 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1870 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1816 processingHeaderSize += codesize
1871 processingHeaderSize += codesize
1817
1872
1818 if self.processingHeaderObj.nWindows != 0:
1873 if self.processingHeaderObj.nWindows != 0:
1819 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1874 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1820 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1875 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1821 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1876 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1822 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1877 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1823 processingHeaderSize += 12
1878 processingHeaderSize += 12
1824
1879
1825 self.processingHeaderObj.size = processingHeaderSize
1880 self.processingHeaderObj.size = processingHeaderSize
1826
1881
1827 class SpectraReader(JRODataReader):
1882 class SpectraReader(JRODataReader):
1828 """
1883 """
1829 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1884 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1830 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1885 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1831 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1886 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1832
1887
1833 paresCanalesIguales * alturas * perfiles (Self Spectra)
1888 paresCanalesIguales * alturas * perfiles (Self Spectra)
1834 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1889 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1835 canales * alturas (DC Channels)
1890 canales * alturas (DC Channels)
1836
1891
1837 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1892 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1838 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1893 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1839 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1894 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1840 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1895 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1841
1896
1842 Example:
1897 Example:
1843 dpath = "/home/myuser/data"
1898 dpath = "/home/myuser/data"
1844
1899
1845 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1900 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1846
1901
1847 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1902 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1848
1903
1849 readerObj = SpectraReader()
1904 readerObj = SpectraReader()
1850
1905
1851 readerObj.setup(dpath, startTime, endTime)
1906 readerObj.setup(dpath, startTime, endTime)
1852
1907
1853 while(True):
1908 while(True):
1854
1909
1855 readerObj.getData()
1910 readerObj.getData()
1856
1911
1857 print readerObj.data_spc
1912 print readerObj.data_spc
1858
1913
1859 print readerObj.data_cspc
1914 print readerObj.data_cspc
1860
1915
1861 print readerObj.data_dc
1916 print readerObj.data_dc
1862
1917
1863 if readerObj.flagNoMoreFiles:
1918 if readerObj.flagNoMoreFiles:
1864 break
1919 break
1865
1920
1866 """
1921 """
1867
1922
1868 pts2read_SelfSpectra = 0
1923 pts2read_SelfSpectra = 0
1869
1924
1870 pts2read_CrossSpectra = 0
1925 pts2read_CrossSpectra = 0
1871
1926
1872 pts2read_DCchannels = 0
1927 pts2read_DCchannels = 0
1873
1928
1874 ext = ".pdata"
1929 ext = ".pdata"
1875
1930
1876 optchar = "P"
1931 optchar = "P"
1877
1932
1878 dataOut = None
1933 dataOut = None
1879
1934
1880 nRdChannels = None
1935 nRdChannels = None
1881
1936
1882 nRdPairs = None
1937 nRdPairs = None
1883
1938
1884 rdPairList = []
1939 rdPairList = []
1885
1940
1886 def __init__(self):
1941 def __init__(self):
1887 """
1942 """
1888 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1943 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1889
1944
1890 Inputs:
1945 Inputs:
1891 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1946 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1892 almacenar un perfil de datos cada vez que se haga un requerimiento
1947 almacenar un perfil de datos cada vez que se haga un requerimiento
1893 (getData). El perfil sera obtenido a partir del buffer de datos,
1948 (getData). El perfil sera obtenido a partir del buffer de datos,
1894 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1949 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1895 bloque de datos.
1950 bloque de datos.
1896 Si este parametro no es pasado se creara uno internamente.
1951 Si este parametro no es pasado se creara uno internamente.
1897
1952
1898 Affected:
1953 Affected:
1899 self.dataOut
1954 self.dataOut
1900
1955
1901 Return : None
1956 Return : None
1902 """
1957 """
1903
1958
1904 self.isConfig = False
1959 self.isConfig = False
1905
1960
1906 self.pts2read_SelfSpectra = 0
1961 self.pts2read_SelfSpectra = 0
1907
1962
1908 self.pts2read_CrossSpectra = 0
1963 self.pts2read_CrossSpectra = 0
1909
1964
1910 self.pts2read_DCchannels = 0
1965 self.pts2read_DCchannels = 0
1911
1966
1912 self.datablock = None
1967 self.datablock = None
1913
1968
1914 self.utc = None
1969 self.utc = None
1915
1970
1916 self.ext = ".pdata"
1971 self.ext = ".pdata"
1917
1972
1918 self.optchar = "P"
1973 self.optchar = "P"
1919
1974
1920 self.basicHeaderObj = BasicHeader(LOCALTIME)
1975 self.basicHeaderObj = BasicHeader(LOCALTIME)
1921
1976
1922 self.systemHeaderObj = SystemHeader()
1977 self.systemHeaderObj = SystemHeader()
1923
1978
1924 self.radarControllerHeaderObj = RadarControllerHeader()
1979 self.radarControllerHeaderObj = RadarControllerHeader()
1925
1980
1926 self.processingHeaderObj = ProcessingHeader()
1981 self.processingHeaderObj = ProcessingHeader()
1927
1982
1928 self.online = 0
1983 self.online = 0
1929
1984
1930 self.fp = None
1985 self.fp = None
1931
1986
1932 self.idFile = None
1987 self.idFile = None
1933
1988
1934 self.dtype = None
1989 self.dtype = None
1935
1990
1936 self.fileSizeByHeader = None
1991 self.fileSizeByHeader = None
1937
1992
1938 self.filenameList = []
1993 self.filenameList = []
1939
1994
1940 self.filename = None
1995 self.filename = None
1941
1996
1942 self.fileSize = None
1997 self.fileSize = None
1943
1998
1944 self.firstHeaderSize = 0
1999 self.firstHeaderSize = 0
1945
2000
1946 self.basicHeaderSize = 24
2001 self.basicHeaderSize = 24
1947
2002
1948 self.pathList = []
2003 self.pathList = []
1949
2004
1950 self.lastUTTime = 0
2005 self.lastUTTime = 0
1951
2006
1952 self.maxTimeStep = 30
2007 self.maxTimeStep = 30
1953
2008
1954 self.flagNoMoreFiles = 0
2009 self.flagNoMoreFiles = 0
1955
2010
1956 self.set = 0
2011 self.set = 0
1957
2012
1958 self.path = None
2013 self.path = None
1959
2014
1960 self.delay = 60 #seconds
2015 self.delay = 60 #seconds
1961
2016
1962 self.nTries = 3 #quantity tries
2017 self.nTries = 3 #quantity tries
1963
2018
1964 self.nFiles = 3 #number of files for searching
2019 self.nFiles = 3 #number of files for searching
1965
2020
1966 self.nReadBlocks = 0
2021 self.nReadBlocks = 0
1967
2022
1968 self.flagIsNewFile = 1
2023 self.flagIsNewFile = 1
1969
2024
1970 self.__isFirstTimeOnline = 1
2025 self.__isFirstTimeOnline = 1
1971
2026
1972 self.ippSeconds = 0
2027 self.ippSeconds = 0
1973
2028
1974 self.flagTimeBlock = 0
2029 self.flagTimeBlock = 0
1975
2030
1976 self.flagIsNewBlock = 0
2031 self.flagIsNewBlock = 0
1977
2032
1978 self.nTotalBlocks = 0
2033 self.nTotalBlocks = 0
1979
2034
1980 self.blocksize = 0
2035 self.blocksize = 0
1981
2036
1982 self.dataOut = self.createObjByDefault()
2037 self.dataOut = self.createObjByDefault()
1983
2038
1984 self.profileIndex = 1 #Always
2039 self.profileIndex = 1 #Always
1985
2040
1986
2041
1987 def createObjByDefault(self):
2042 def createObjByDefault(self):
1988
2043
1989 dataObj = Spectra()
2044 dataObj = Spectra()
1990
2045
1991 return dataObj
2046 return dataObj
1992
2047
1993 def __hasNotDataInBuffer(self):
2048 def __hasNotDataInBuffer(self):
1994 return 1
2049 return 1
1995
2050
1996
2051
1997 def getBlockDimension(self):
2052 def getBlockDimension(self):
1998 """
2053 """
1999 Obtiene la cantidad de puntos a leer por cada bloque de datos
2054 Obtiene la cantidad de puntos a leer por cada bloque de datos
2000
2055
2001 Affected:
2056 Affected:
2002 self.nRdChannels
2057 self.nRdChannels
2003 self.nRdPairs
2058 self.nRdPairs
2004 self.pts2read_SelfSpectra
2059 self.pts2read_SelfSpectra
2005 self.pts2read_CrossSpectra
2060 self.pts2read_CrossSpectra
2006 self.pts2read_DCchannels
2061 self.pts2read_DCchannels
2007 self.blocksize
2062 self.blocksize
2008 self.dataOut.nChannels
2063 self.dataOut.nChannels
2009 self.dataOut.nPairs
2064 self.dataOut.nPairs
2010
2065
2011 Return:
2066 Return:
2012 None
2067 None
2013 """
2068 """
2014 self.nRdChannels = 0
2069 self.nRdChannels = 0
2015 self.nRdPairs = 0
2070 self.nRdPairs = 0
2016 self.rdPairList = []
2071 self.rdPairList = []
2017
2072
2018 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
2073 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
2019 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
2074 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
2020 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
2075 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
2021 else:
2076 else:
2022 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
2077 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
2023 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
2078 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
2024
2079
2025 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
2080 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
2026
2081
2027 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
2082 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
2028 self.blocksize = self.pts2read_SelfSpectra
2083 self.blocksize = self.pts2read_SelfSpectra
2029
2084
2030 if self.processingHeaderObj.flag_cspc:
2085 if self.processingHeaderObj.flag_cspc:
2031 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
2086 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
2032 self.blocksize += self.pts2read_CrossSpectra
2087 self.blocksize += self.pts2read_CrossSpectra
2033
2088
2034 if self.processingHeaderObj.flag_dc:
2089 if self.processingHeaderObj.flag_dc:
2035 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
2090 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
2036 self.blocksize += self.pts2read_DCchannels
2091 self.blocksize += self.pts2read_DCchannels
2037
2092
2038 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
2093 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
2039
2094
2040
2095
2041 def readBlock(self):
2096 def readBlock(self):
2042 """
2097 """
2043 Lee el bloque de datos desde la posicion actual del puntero del archivo
2098 Lee el bloque de datos desde la posicion actual del puntero del archivo
2044 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
2099 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
2045 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
2100 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
2046 es seteado a 0
2101 es seteado a 0
2047
2102
2048 Return: None
2103 Return: None
2049
2104
2050 Variables afectadas:
2105 Variables afectadas:
2051
2106
2052 self.flagIsNewFile
2107 self.flagIsNewFile
2053 self.flagIsNewBlock
2108 self.flagIsNewBlock
2054 self.nTotalBlocks
2109 self.nTotalBlocks
2055 self.data_spc
2110 self.data_spc
2056 self.data_cspc
2111 self.data_cspc
2057 self.data_dc
2112 self.data_dc
2058
2113
2059 Exceptions:
2114 Exceptions:
2060 Si un bloque leido no es un bloque valido
2115 Si un bloque leido no es un bloque valido
2061 """
2116 """
2062 blockOk_flag = False
2117 blockOk_flag = False
2063 fpointer = self.fp.tell()
2118 fpointer = self.fp.tell()
2064
2119
2065 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
2120 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
2066 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2121 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2067
2122
2068 if self.processingHeaderObj.flag_cspc:
2123 if self.processingHeaderObj.flag_cspc:
2069 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
2124 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
2070 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2125 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2071
2126
2072 if self.processingHeaderObj.flag_dc:
2127 if self.processingHeaderObj.flag_dc:
2073 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
2128 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
2074 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
2129 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
2075
2130
2076
2131
2077 if not(self.processingHeaderObj.shif_fft):
2132 if not(self.processingHeaderObj.shif_fft):
2078 #desplaza a la derecha en el eje 2 determinadas posiciones
2133 #desplaza a la derecha en el eje 2 determinadas posiciones
2079 shift = int(self.processingHeaderObj.profilesPerBlock/2)
2134 shift = int(self.processingHeaderObj.profilesPerBlock/2)
2080 spc = numpy.roll( spc, shift , axis=2 )
2135 spc = numpy.roll( spc, shift , axis=2 )
2081
2136
2082 if self.processingHeaderObj.flag_cspc:
2137 if self.processingHeaderObj.flag_cspc:
2083 #desplaza a la derecha en el eje 2 determinadas posiciones
2138 #desplaza a la derecha en el eje 2 determinadas posiciones
2084 cspc = numpy.roll( cspc, shift, axis=2 )
2139 cspc = numpy.roll( cspc, shift, axis=2 )
2085
2140
2086 # self.processingHeaderObj.shif_fft = True
2141 # self.processingHeaderObj.shif_fft = True
2087
2142
2088 spc = numpy.transpose( spc, (0,2,1) )
2143 spc = numpy.transpose( spc, (0,2,1) )
2089 self.data_spc = spc
2144 self.data_spc = spc
2090
2145
2091 if self.processingHeaderObj.flag_cspc:
2146 if self.processingHeaderObj.flag_cspc:
2092 cspc = numpy.transpose( cspc, (0,2,1) )
2147 cspc = numpy.transpose( cspc, (0,2,1) )
2093 self.data_cspc = cspc['real'] + cspc['imag']*1j
2148 self.data_cspc = cspc['real'] + cspc['imag']*1j
2094 else:
2149 else:
2095 self.data_cspc = None
2150 self.data_cspc = None
2096
2151
2097 if self.processingHeaderObj.flag_dc:
2152 if self.processingHeaderObj.flag_dc:
2098 self.data_dc = dc['real'] + dc['imag']*1j
2153 self.data_dc = dc['real'] + dc['imag']*1j
2099 else:
2154 else:
2100 self.data_dc = None
2155 self.data_dc = None
2101
2156
2102 self.flagIsNewFile = 0
2157 self.flagIsNewFile = 0
2103 self.flagIsNewBlock = 1
2158 self.flagIsNewBlock = 1
2104
2159
2105 self.nTotalBlocks += 1
2160 self.nTotalBlocks += 1
2106 self.nReadBlocks += 1
2161 self.nReadBlocks += 1
2107
2162
2108 return 1
2163 return 1
2109
2164
2110 def getFirstHeader(self):
2165 def getFirstHeader(self):
2111
2166
2112 self.dataOut.dtype = self.dtype
2167 self.dataOut.dtype = self.dtype
2113
2168
2114 self.dataOut.nPairs = self.nRdPairs
2169 self.dataOut.nPairs = self.nRdPairs
2115
2170
2116 self.dataOut.pairsList = self.rdPairList
2171 self.dataOut.pairsList = self.rdPairList
2117
2172
2118 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2173 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2119
2174
2120 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2175 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2121
2176
2122 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2177 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2123
2178
2124 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2179 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2125
2180
2126 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2181 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2127
2182
2128 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2183 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2129
2184
2130 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2185 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2131
2186
2132 self.dataOut.ippSeconds = self.ippSeconds
2187 self.dataOut.ippSeconds = self.ippSeconds
2133
2188
2134 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2189 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2135
2190
2136 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2191 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2137
2192
2138 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2193 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2139
2194
2140 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2195 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2141
2196
2142 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
2197 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
2143
2198
2144 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2199 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2145
2200
2146 if self.processingHeaderObj.code != None:
2201 if self.processingHeaderObj.code != None:
2147
2202
2148 self.dataOut.nCode = self.processingHeaderObj.nCode
2203 self.dataOut.nCode = self.processingHeaderObj.nCode
2149
2204
2150 self.dataOut.nBaud = self.processingHeaderObj.nBaud
2205 self.dataOut.nBaud = self.processingHeaderObj.nBaud
2151
2206
2152 self.dataOut.code = self.processingHeaderObj.code
2207 self.dataOut.code = self.processingHeaderObj.code
2153
2208
2154 self.dataOut.flagDecodeData = True
2209 self.dataOut.flagDecodeData = True
2155
2210
2156 def getData(self):
2211 def getData(self):
2157 """
2212 """
2158 Copia el buffer de lectura a la clase "Spectra",
2213 Copia el buffer de lectura a la clase "Spectra",
2159 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
2214 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
2160 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
2215 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
2161
2216
2162 Return:
2217 Return:
2163 0 : Si no hay mas archivos disponibles
2218 0 : Si no hay mas archivos disponibles
2164 1 : Si hizo una buena copia del buffer
2219 1 : Si hizo una buena copia del buffer
2165
2220
2166 Affected:
2221 Affected:
2167 self.dataOut
2222 self.dataOut
2168
2223
2169 self.flagTimeBlock
2224 self.flagTimeBlock
2170 self.flagIsNewBlock
2225 self.flagIsNewBlock
2171 """
2226 """
2172
2227
2173 if self.flagNoMoreFiles:
2228 if self.flagNoMoreFiles:
2174 self.dataOut.flagNoData = True
2229 self.dataOut.flagNoData = True
2175 print 'Process finished'
2230 print 'Process finished'
2176 return 0
2231 return 0
2177
2232
2178 self.flagTimeBlock = 0
2233 self.flagTimeBlock = 0
2179 self.flagIsNewBlock = 0
2234 self.flagIsNewBlock = 0
2180
2235
2181 if self.__hasNotDataInBuffer():
2236 if self.__hasNotDataInBuffer():
2182
2237
2183 if not( self.readNextBlock() ):
2238 if not( self.readNextBlock() ):
2184 self.dataOut.flagNoData = True
2239 self.dataOut.flagNoData = True
2185 return 0
2240 return 0
2186
2241
2187 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2242 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2188
2243
2189 if self.data_dc == None:
2244 if self.data_dc == None:
2190 self.dataOut.flagNoData = True
2245 self.dataOut.flagNoData = True
2191 return 0
2246 return 0
2192
2247
2193 self.getBasicHeader()
2248 self.getBasicHeader()
2194
2249
2195 self.getFirstHeader()
2250 self.getFirstHeader()
2196
2251
2197 self.dataOut.data_spc = self.data_spc
2252 self.dataOut.data_spc = self.data_spc
2198
2253
2199 self.dataOut.data_cspc = self.data_cspc
2254 self.dataOut.data_cspc = self.data_cspc
2200
2255
2201 self.dataOut.data_dc = self.data_dc
2256 self.dataOut.data_dc = self.data_dc
2202
2257
2203 self.dataOut.flagNoData = False
2258 self.dataOut.flagNoData = False
2204
2259
2205 self.dataOut.realtime = self.online
2260 self.dataOut.realtime = self.online
2206
2261
2207 return self.dataOut.data_spc
2262 return self.dataOut.data_spc
2208
2263
2209
2264
2210 class SpectraWriter(JRODataWriter):
2265 class SpectraWriter(JRODataWriter):
2211
2266
2212 """
2267 """
2213 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2268 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2214 de los datos siempre se realiza por bloques.
2269 de los datos siempre se realiza por bloques.
2215 """
2270 """
2216
2271
2217 ext = ".pdata"
2272 ext = ".pdata"
2218
2273
2219 optchar = "P"
2274 optchar = "P"
2220
2275
2221 shape_spc_Buffer = None
2276 shape_spc_Buffer = None
2222
2277
2223 shape_cspc_Buffer = None
2278 shape_cspc_Buffer = None
2224
2279
2225 shape_dc_Buffer = None
2280 shape_dc_Buffer = None
2226
2281
2227 data_spc = None
2282 data_spc = None
2228
2283
2229 data_cspc = None
2284 data_cspc = None
2230
2285
2231 data_dc = None
2286 data_dc = None
2232
2287
2233 # dataOut = None
2288 # dataOut = None
2234
2289
2235 def __init__(self):
2290 def __init__(self):
2236 """
2291 """
2237 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2292 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2238
2293
2239 Affected:
2294 Affected:
2240 self.dataOut
2295 self.dataOut
2241 self.basicHeaderObj
2296 self.basicHeaderObj
2242 self.systemHeaderObj
2297 self.systemHeaderObj
2243 self.radarControllerHeaderObj
2298 self.radarControllerHeaderObj
2244 self.processingHeaderObj
2299 self.processingHeaderObj
2245
2300
2246 Return: None
2301 Return: None
2247 """
2302 """
2248
2303
2249 self.isConfig = False
2304 self.isConfig = False
2250
2305
2251 self.nTotalBlocks = 0
2306 self.nTotalBlocks = 0
2252
2307
2253 self.data_spc = None
2308 self.data_spc = None
2254
2309
2255 self.data_cspc = None
2310 self.data_cspc = None
2256
2311
2257 self.data_dc = None
2312 self.data_dc = None
2258
2313
2259 self.fp = None
2314 self.fp = None
2260
2315
2261 self.flagIsNewFile = 1
2316 self.flagIsNewFile = 1
2262
2317
2263 self.nTotalBlocks = 0
2318 self.nTotalBlocks = 0
2264
2319
2265 self.flagIsNewBlock = 0
2320 self.flagIsNewBlock = 0
2266
2321
2267 self.setFile = None
2322 self.setFile = None
2268
2323
2269 self.dtype = None
2324 self.dtype = None
2270
2325
2271 self.path = None
2326 self.path = None
2272
2327
2273 self.noMoreFiles = 0
2328 self.noMoreFiles = 0
2274
2329
2275 self.filename = None
2330 self.filename = None
2276
2331
2277 self.basicHeaderObj = BasicHeader(LOCALTIME)
2332 self.basicHeaderObj = BasicHeader(LOCALTIME)
2278
2333
2279 self.systemHeaderObj = SystemHeader()
2334 self.systemHeaderObj = SystemHeader()
2280
2335
2281 self.radarControllerHeaderObj = RadarControllerHeader()
2336 self.radarControllerHeaderObj = RadarControllerHeader()
2282
2337
2283 self.processingHeaderObj = ProcessingHeader()
2338 self.processingHeaderObj = ProcessingHeader()
2284
2339
2285
2340
2286 def hasAllDataInBuffer(self):
2341 def hasAllDataInBuffer(self):
2287 return 1
2342 return 1
2288
2343
2289
2344
2290 def setBlockDimension(self):
2345 def setBlockDimension(self):
2291 """
2346 """
2292 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2347 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2293
2348
2294 Affected:
2349 Affected:
2295 self.shape_spc_Buffer
2350 self.shape_spc_Buffer
2296 self.shape_cspc_Buffer
2351 self.shape_cspc_Buffer
2297 self.shape_dc_Buffer
2352 self.shape_dc_Buffer
2298
2353
2299 Return: None
2354 Return: None
2300 """
2355 """
2301 self.shape_spc_Buffer = (self.dataOut.nChannels,
2356 self.shape_spc_Buffer = (self.dataOut.nChannels,
2302 self.processingHeaderObj.nHeights,
2357 self.processingHeaderObj.nHeights,
2303 self.processingHeaderObj.profilesPerBlock)
2358 self.processingHeaderObj.profilesPerBlock)
2304
2359
2305 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2360 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2306 self.processingHeaderObj.nHeights,
2361 self.processingHeaderObj.nHeights,
2307 self.processingHeaderObj.profilesPerBlock)
2362 self.processingHeaderObj.profilesPerBlock)
2308
2363
2309 self.shape_dc_Buffer = (self.dataOut.nChannels,
2364 self.shape_dc_Buffer = (self.dataOut.nChannels,
2310 self.processingHeaderObj.nHeights)
2365 self.processingHeaderObj.nHeights)
2311
2366
2312
2367
2313 def writeBlock(self):
2368 def writeBlock(self):
2314 """
2369 """
2315 Escribe el buffer en el file designado
2370 Escribe el buffer en el file designado
2316
2371
2317 Affected:
2372 Affected:
2318 self.data_spc
2373 self.data_spc
2319 self.data_cspc
2374 self.data_cspc
2320 self.data_dc
2375 self.data_dc
2321 self.flagIsNewFile
2376 self.flagIsNewFile
2322 self.flagIsNewBlock
2377 self.flagIsNewBlock
2323 self.nTotalBlocks
2378 self.nTotalBlocks
2324 self.nWriteBlocks
2379 self.nWriteBlocks
2325
2380
2326 Return: None
2381 Return: None
2327 """
2382 """
2328
2383
2329 spc = numpy.transpose( self.data_spc, (0,2,1) )
2384 spc = numpy.transpose( self.data_spc, (0,2,1) )
2330 if not( self.processingHeaderObj.shif_fft ):
2385 if not( self.processingHeaderObj.shif_fft ):
2331 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2386 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2332 data = spc.reshape((-1))
2387 data = spc.reshape((-1))
2333 data = data.astype(self.dtype[0])
2388 data = data.astype(self.dtype[0])
2334 data.tofile(self.fp)
2389 data.tofile(self.fp)
2335
2390
2336 if self.data_cspc != None:
2391 if self.data_cspc != None:
2337 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2392 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2338 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2393 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2339 if not( self.processingHeaderObj.shif_fft ):
2394 if not( self.processingHeaderObj.shif_fft ):
2340 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2395 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2341 data['real'] = cspc.real
2396 data['real'] = cspc.real
2342 data['imag'] = cspc.imag
2397 data['imag'] = cspc.imag
2343 data = data.reshape((-1))
2398 data = data.reshape((-1))
2344 data.tofile(self.fp)
2399 data.tofile(self.fp)
2345
2400
2346 if self.data_dc != None:
2401 if self.data_dc != None:
2347 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2402 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2348 dc = self.data_dc
2403 dc = self.data_dc
2349 data['real'] = dc.real
2404 data['real'] = dc.real
2350 data['imag'] = dc.imag
2405 data['imag'] = dc.imag
2351 data = data.reshape((-1))
2406 data = data.reshape((-1))
2352 data.tofile(self.fp)
2407 data.tofile(self.fp)
2353
2408
2354 self.data_spc.fill(0)
2409 self.data_spc.fill(0)
2355 self.data_dc.fill(0)
2410 self.data_dc.fill(0)
2356 if self.data_cspc != None:
2411 if self.data_cspc != None:
2357 self.data_cspc.fill(0)
2412 self.data_cspc.fill(0)
2358
2413
2359 self.flagIsNewFile = 0
2414 self.flagIsNewFile = 0
2360 self.flagIsNewBlock = 1
2415 self.flagIsNewBlock = 1
2361 self.nTotalBlocks += 1
2416 self.nTotalBlocks += 1
2362 self.nWriteBlocks += 1
2417 self.nWriteBlocks += 1
2363 self.blockIndex += 1
2418 self.blockIndex += 1
2364
2419
2365
2420
2366 def putData(self):
2421 def putData(self):
2367 """
2422 """
2368 Setea un bloque de datos y luego los escribe en un file
2423 Setea un bloque de datos y luego los escribe en un file
2369
2424
2370 Affected:
2425 Affected:
2371 self.data_spc
2426 self.data_spc
2372 self.data_cspc
2427 self.data_cspc
2373 self.data_dc
2428 self.data_dc
2374
2429
2375 Return:
2430 Return:
2376 0 : Si no hay data o no hay mas files que puedan escribirse
2431 0 : Si no hay data o no hay mas files que puedan escribirse
2377 1 : Si se escribio la data de un bloque en un file
2432 1 : Si se escribio la data de un bloque en un file
2378 """
2433 """
2379
2434
2380 if self.dataOut.flagNoData:
2435 if self.dataOut.flagNoData:
2381 return 0
2436 return 0
2382
2437
2383 self.flagIsNewBlock = 0
2438 self.flagIsNewBlock = 0
2384
2439
2385 if self.dataOut.flagTimeBlock:
2440 if self.dataOut.flagTimeBlock:
2386 self.data_spc.fill(0)
2441 self.data_spc.fill(0)
2387 self.data_cspc.fill(0)
2442 self.data_cspc.fill(0)
2388 self.data_dc.fill(0)
2443 self.data_dc.fill(0)
2389 self.setNextFile()
2444 self.setNextFile()
2390
2445
2391 if self.flagIsNewFile == 0:
2446 if self.flagIsNewFile == 0:
2392 self.setBasicHeader()
2447 self.setBasicHeader()
2393
2448
2394 self.data_spc = self.dataOut.data_spc.copy()
2449 self.data_spc = self.dataOut.data_spc.copy()
2395 self.data_cspc = self.dataOut.data_cspc.copy()
2450 self.data_cspc = self.dataOut.data_cspc.copy()
2396 self.data_dc = self.dataOut.data_dc.copy()
2451 self.data_dc = self.dataOut.data_dc.copy()
2397
2452
2398 # #self.processingHeaderObj.dataBlocksPerFile)
2453 # #self.processingHeaderObj.dataBlocksPerFile)
2399 if self.hasAllDataInBuffer():
2454 if self.hasAllDataInBuffer():
2400 # self.setFirstHeader()
2455 # self.setFirstHeader()
2401 self.writeNextBlock()
2456 self.writeNextBlock()
2402
2457
2403 return 1
2458 return 1
2404
2459
2405
2460
2406 def __getProcessFlags(self):
2461 def __getProcessFlags(self):
2407
2462
2408 processFlags = 0
2463 processFlags = 0
2409
2464
2410 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2465 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2411 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2466 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2412 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2467 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2413 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2468 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2414 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2469 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2415 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2470 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2416
2471
2417 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2472 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2418
2473
2419
2474
2420
2475
2421 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2476 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2422 PROCFLAG.DATATYPE_SHORT,
2477 PROCFLAG.DATATYPE_SHORT,
2423 PROCFLAG.DATATYPE_LONG,
2478 PROCFLAG.DATATYPE_LONG,
2424 PROCFLAG.DATATYPE_INT64,
2479 PROCFLAG.DATATYPE_INT64,
2425 PROCFLAG.DATATYPE_FLOAT,
2480 PROCFLAG.DATATYPE_FLOAT,
2426 PROCFLAG.DATATYPE_DOUBLE]
2481 PROCFLAG.DATATYPE_DOUBLE]
2427
2482
2428
2483
2429 for index in range(len(dtypeList)):
2484 for index in range(len(dtypeList)):
2430 if self.dataOut.dtype == dtypeList[index]:
2485 if self.dataOut.dtype == dtypeList[index]:
2431 dtypeValue = datatypeValueList[index]
2486 dtypeValue = datatypeValueList[index]
2432 break
2487 break
2433
2488
2434 processFlags += dtypeValue
2489 processFlags += dtypeValue
2435
2490
2436 if self.dataOut.flagDecodeData:
2491 if self.dataOut.flagDecodeData:
2437 processFlags += PROCFLAG.DECODE_DATA
2492 processFlags += PROCFLAG.DECODE_DATA
2438
2493
2439 if self.dataOut.flagDeflipData:
2494 if self.dataOut.flagDeflipData:
2440 processFlags += PROCFLAG.DEFLIP_DATA
2495 processFlags += PROCFLAG.DEFLIP_DATA
2441
2496
2442 if self.dataOut.code != None:
2497 if self.dataOut.code != None:
2443 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2498 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2444
2499
2445 if self.dataOut.nIncohInt > 1:
2500 if self.dataOut.nIncohInt > 1:
2446 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2501 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2447
2502
2448 if self.dataOut.data_dc != None:
2503 if self.dataOut.data_dc != None:
2449 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2504 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2450
2505
2451 return processFlags
2506 return processFlags
2452
2507
2453
2508
2454 def __getBlockSize(self):
2509 def __getBlockSize(self):
2455 '''
2510 '''
2456 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2511 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2457 '''
2512 '''
2458
2513
2459 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2514 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2460 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2515 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2461 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2516 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2462 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2517 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2463 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2518 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2464 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2519 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2465
2520
2466 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2521 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2467 datatypeValueList = [1,2,4,8,4,8]
2522 datatypeValueList = [1,2,4,8,4,8]
2468 for index in range(len(dtypeList)):
2523 for index in range(len(dtypeList)):
2469 if self.dataOut.dtype == dtypeList[index]:
2524 if self.dataOut.dtype == dtypeList[index]:
2470 datatypeValue = datatypeValueList[index]
2525 datatypeValue = datatypeValueList[index]
2471 break
2526 break
2472
2527
2473
2528
2474 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2529 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2475
2530
2476 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2531 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2477 blocksize = (pts2write_SelfSpectra*datatypeValue)
2532 blocksize = (pts2write_SelfSpectra*datatypeValue)
2478
2533
2479 if self.dataOut.data_cspc != None:
2534 if self.dataOut.data_cspc != None:
2480 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2535 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2481 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2536 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2482
2537
2483 if self.dataOut.data_dc != None:
2538 if self.dataOut.data_dc != None:
2484 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2539 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2485 blocksize += (pts2write_DCchannels*datatypeValue*2)
2540 blocksize += (pts2write_DCchannels*datatypeValue*2)
2486
2541
2487 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2542 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2488
2543
2489 return blocksize
2544 return blocksize
2490
2545
2491 def setFirstHeader(self):
2546 def setFirstHeader(self):
2492
2547
2493 """
2548 """
2494 Obtiene una copia del First Header
2549 Obtiene una copia del First Header
2495
2550
2496 Affected:
2551 Affected:
2497 self.systemHeaderObj
2552 self.systemHeaderObj
2498 self.radarControllerHeaderObj
2553 self.radarControllerHeaderObj
2499 self.dtype
2554 self.dtype
2500
2555
2501 Return:
2556 Return:
2502 None
2557 None
2503 """
2558 """
2504
2559
2505 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2560 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2506 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2561 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2507 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2562 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2508
2563
2509 self.setBasicHeader()
2564 self.setBasicHeader()
2510
2565
2511 processingHeaderSize = 40 # bytes
2566 processingHeaderSize = 40 # bytes
2512 self.processingHeaderObj.dtype = 1 # Spectra
2567 self.processingHeaderObj.dtype = 1 # Spectra
2513 self.processingHeaderObj.blockSize = self.__getBlockSize()
2568 self.processingHeaderObj.blockSize = self.__getBlockSize()
2514 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2569 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2515 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2570 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2516 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2571 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2517 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2572 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2518 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2573 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2519 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2574 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2520 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2575 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2521 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
2576 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
2522
2577
2523 if self.processingHeaderObj.totalSpectra > 0:
2578 if self.processingHeaderObj.totalSpectra > 0:
2524 channelList = []
2579 channelList = []
2525 for channel in range(self.dataOut.nChannels):
2580 for channel in range(self.dataOut.nChannels):
2526 channelList.append(channel)
2581 channelList.append(channel)
2527 channelList.append(channel)
2582 channelList.append(channel)
2528
2583
2529 pairsList = []
2584 pairsList = []
2530 for pair in self.dataOut.pairsList:
2585 for pair in self.dataOut.pairsList:
2531 pairsList.append(pair[0])
2586 pairsList.append(pair[0])
2532 pairsList.append(pair[1])
2587 pairsList.append(pair[1])
2533 spectraComb = channelList + pairsList
2588 spectraComb = channelList + pairsList
2534 spectraComb = numpy.array(spectraComb,dtype="u1")
2589 spectraComb = numpy.array(spectraComb,dtype="u1")
2535 self.processingHeaderObj.spectraComb = spectraComb
2590 self.processingHeaderObj.spectraComb = spectraComb
2536 sizeOfSpcComb = len(spectraComb)
2591 sizeOfSpcComb = len(spectraComb)
2537 processingHeaderSize += sizeOfSpcComb
2592 processingHeaderSize += sizeOfSpcComb
2538
2593
2539 # The processing header should not have information about code
2594 # The processing header should not have information about code
2540 # if self.dataOut.code != None:
2595 # if self.dataOut.code != None:
2541 # self.processingHeaderObj.code = self.dataOut.code
2596 # self.processingHeaderObj.code = self.dataOut.code
2542 # self.processingHeaderObj.nCode = self.dataOut.nCode
2597 # self.processingHeaderObj.nCode = self.dataOut.nCode
2543 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
2598 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
2544 # nCodeSize = 4 # bytes
2599 # nCodeSize = 4 # bytes
2545 # nBaudSize = 4 # bytes
2600 # nBaudSize = 4 # bytes
2546 # codeSize = 4 # bytes
2601 # codeSize = 4 # bytes
2547 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2602 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2548 # processingHeaderSize += sizeOfCode
2603 # processingHeaderSize += sizeOfCode
2549
2604
2550 if self.processingHeaderObj.nWindows != 0:
2605 if self.processingHeaderObj.nWindows != 0:
2551 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2606 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2552 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2607 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2553 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2608 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2554 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2609 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2555 sizeOfFirstHeight = 4
2610 sizeOfFirstHeight = 4
2556 sizeOfdeltaHeight = 4
2611 sizeOfdeltaHeight = 4
2557 sizeOfnHeights = 4
2612 sizeOfnHeights = 4
2558 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2613 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2559 processingHeaderSize += sizeOfWindows
2614 processingHeaderSize += sizeOfWindows
2560
2615
2561 self.processingHeaderObj.size = processingHeaderSize
2616 self.processingHeaderObj.size = processingHeaderSize
2562
2617
2563 class SpectraHeisWriter(Operation):
2618 class SpectraHeisWriter(Operation):
2564 # set = None
2619 # set = None
2565 setFile = None
2620 setFile = None
2566 idblock = None
2621 idblock = None
2567 doypath = None
2622 doypath = None
2568 subfolder = None
2623 subfolder = None
2569
2624
2570 def __init__(self):
2625 def __init__(self):
2571 self.wrObj = FITS()
2626 self.wrObj = FITS()
2572 # self.dataOut = dataOut
2627 # self.dataOut = dataOut
2573 self.nTotalBlocks=0
2628 self.nTotalBlocks=0
2574 # self.set = None
2629 # self.set = None
2575 self.setFile = None
2630 self.setFile = None
2576 self.idblock = 0
2631 self.idblock = 0
2577 self.wrpath = None
2632 self.wrpath = None
2578 self.doypath = None
2633 self.doypath = None
2579 self.subfolder = None
2634 self.subfolder = None
2580 self.isConfig = False
2635 self.isConfig = False
2581
2636
2582 def isNumber(str):
2637 def isNumber(str):
2583 """
2638 """
2584 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2639 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2585
2640
2586 Excepciones:
2641 Excepciones:
2587 Si un determinado string no puede ser convertido a numero
2642 Si un determinado string no puede ser convertido a numero
2588 Input:
2643 Input:
2589 str, string al cual se le analiza para determinar si convertible a un numero o no
2644 str, string al cual se le analiza para determinar si convertible a un numero o no
2590
2645
2591 Return:
2646 Return:
2592 True : si el string es uno numerico
2647 True : si el string es uno numerico
2593 False : no es un string numerico
2648 False : no es un string numerico
2594 """
2649 """
2595 try:
2650 try:
2596 float( str )
2651 float( str )
2597 return True
2652 return True
2598 except:
2653 except:
2599 return False
2654 return False
2600
2655
2601 def setup(self, dataOut, wrpath):
2656 def setup(self, dataOut, wrpath):
2602
2657
2603 if not(os.path.exists(wrpath)):
2658 if not(os.path.exists(wrpath)):
2604 os.mkdir(wrpath)
2659 os.mkdir(wrpath)
2605
2660
2606 self.wrpath = wrpath
2661 self.wrpath = wrpath
2607 # self.setFile = 0
2662 # self.setFile = 0
2608 self.dataOut = dataOut
2663 self.dataOut = dataOut
2609
2664
2610 def putData(self):
2665 def putData(self):
2611 name= time.localtime( self.dataOut.utctime)
2666 name= time.localtime( self.dataOut.utctime)
2612 ext=".fits"
2667 ext=".fits"
2613
2668
2614 if self.doypath == None:
2669 if self.doypath == None:
2615 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
2670 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
2616 self.doypath = os.path.join( self.wrpath, self.subfolder )
2671 self.doypath = os.path.join( self.wrpath, self.subfolder )
2617 os.mkdir(self.doypath)
2672 os.mkdir(self.doypath)
2618
2673
2619 if self.setFile == None:
2674 if self.setFile == None:
2620 # self.set = self.dataOut.set
2675 # self.set = self.dataOut.set
2621 self.setFile = 0
2676 self.setFile = 0
2622 # if self.set != self.dataOut.set:
2677 # if self.set != self.dataOut.set:
2623 ## self.set = self.dataOut.set
2678 ## self.set = self.dataOut.set
2624 # self.setFile = 0
2679 # self.setFile = 0
2625
2680
2626 #make the filename
2681 #make the filename
2627 file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2682 file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2628
2683
2629 filename = os.path.join(self.wrpath,self.subfolder, file)
2684 filename = os.path.join(self.wrpath,self.subfolder, file)
2630
2685
2631 idblock = numpy.array([self.idblock],dtype="int64")
2686 idblock = numpy.array([self.idblock],dtype="int64")
2632 header=self.wrObj.cFImage(idblock=idblock,
2687 header=self.wrObj.cFImage(idblock=idblock,
2633 year=time.gmtime(self.dataOut.utctime).tm_year,
2688 year=time.gmtime(self.dataOut.utctime).tm_year,
2634 month=time.gmtime(self.dataOut.utctime).tm_mon,
2689 month=time.gmtime(self.dataOut.utctime).tm_mon,
2635 day=time.gmtime(self.dataOut.utctime).tm_mday,
2690 day=time.gmtime(self.dataOut.utctime).tm_mday,
2636 hour=time.gmtime(self.dataOut.utctime).tm_hour,
2691 hour=time.gmtime(self.dataOut.utctime).tm_hour,
2637 minute=time.gmtime(self.dataOut.utctime).tm_min,
2692 minute=time.gmtime(self.dataOut.utctime).tm_min,
2638 second=time.gmtime(self.dataOut.utctime).tm_sec)
2693 second=time.gmtime(self.dataOut.utctime).tm_sec)
2639
2694
2640 c=3E8
2695 c=3E8
2641 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2696 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2642 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
2697 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
2643
2698
2644 colList = []
2699 colList = []
2645
2700
2646 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2701 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2647
2702
2648 colList.append(colFreq)
2703 colList.append(colFreq)
2649
2704
2650 nchannel=self.dataOut.nChannels
2705 nchannel=self.dataOut.nChannels
2651
2706
2652 for i in range(nchannel):
2707 for i in range(nchannel):
2653 col = self.wrObj.writeData(name="PCh"+str(i+1),
2708 col = self.wrObj.writeData(name="PCh"+str(i+1),
2654 format=str(self.dataOut.nFFTPoints)+'E',
2709 format=str(self.dataOut.nFFTPoints)+'E',
2655 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
2710 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
2656
2711
2657 colList.append(col)
2712 colList.append(col)
2658
2713
2659 data=self.wrObj.Ctable(colList=colList)
2714 data=self.wrObj.Ctable(colList=colList)
2660
2715
2661 self.wrObj.CFile(header,data)
2716 self.wrObj.CFile(header,data)
2662
2717
2663 self.wrObj.wFile(filename)
2718 self.wrObj.wFile(filename)
2664
2719
2665 #update the setFile
2720 #update the setFile
2666 self.setFile += 1
2721 self.setFile += 1
2667 self.idblock += 1
2722 self.idblock += 1
2668
2723
2669 return 1
2724 return 1
2670
2725
2671 def run(self, dataOut, **kwargs):
2726 def run(self, dataOut, **kwargs):
2672
2727
2673 if not(self.isConfig):
2728 if not(self.isConfig):
2674
2729
2675 self.setup(dataOut, **kwargs)
2730 self.setup(dataOut, **kwargs)
2676 self.isConfig = True
2731 self.isConfig = True
2677
2732
2678 self.putData()
2733 self.putData()
2679
2734
2680
2735
2681 class FITS:
2736 class FITS:
2682 name=None
2737 name=None
2683 format=None
2738 format=None
2684 array =None
2739 array =None
2685 data =None
2740 data =None
2686 thdulist=None
2741 thdulist=None
2687 prihdr=None
2742 prihdr=None
2688 hdu=None
2743 hdu=None
2689
2744
2690 def __init__(self):
2745 def __init__(self):
2691
2746
2692 pass
2747 pass
2693
2748
2694 def setColF(self,name,format,array):
2749 def setColF(self,name,format,array):
2695 self.name=name
2750 self.name=name
2696 self.format=format
2751 self.format=format
2697 self.array=array
2752 self.array=array
2698 a1=numpy.array([self.array],dtype=numpy.float32)
2753 a1=numpy.array([self.array],dtype=numpy.float32)
2699 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2754 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2700 return self.col1
2755 return self.col1
2701
2756
2702 # def setColP(self,name,format,data):
2757 # def setColP(self,name,format,data):
2703 # self.name=name
2758 # self.name=name
2704 # self.format=format
2759 # self.format=format
2705 # self.data=data
2760 # self.data=data
2706 # a2=numpy.array([self.data],dtype=numpy.float32)
2761 # a2=numpy.array([self.data],dtype=numpy.float32)
2707 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2762 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2708 # return self.col2
2763 # return self.col2
2709
2764
2710
2765
2711 def writeData(self,name,format,data):
2766 def writeData(self,name,format,data):
2712 self.name=name
2767 self.name=name
2713 self.format=format
2768 self.format=format
2714 self.data=data
2769 self.data=data
2715 a2=numpy.array([self.data],dtype=numpy.float32)
2770 a2=numpy.array([self.data],dtype=numpy.float32)
2716 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2771 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2717 return self.col2
2772 return self.col2
2718
2773
2719 def cFImage(self,idblock,year,month,day,hour,minute,second):
2774 def cFImage(self,idblock,year,month,day,hour,minute,second):
2720 self.hdu= pyfits.PrimaryHDU(idblock)
2775 self.hdu= pyfits.PrimaryHDU(idblock)
2721 self.hdu.header.set("Year",year)
2776 self.hdu.header.set("Year",year)
2722 self.hdu.header.set("Month",month)
2777 self.hdu.header.set("Month",month)
2723 self.hdu.header.set("Day",day)
2778 self.hdu.header.set("Day",day)
2724 self.hdu.header.set("Hour",hour)
2779 self.hdu.header.set("Hour",hour)
2725 self.hdu.header.set("Minute",minute)
2780 self.hdu.header.set("Minute",minute)
2726 self.hdu.header.set("Second",second)
2781 self.hdu.header.set("Second",second)
2727 return self.hdu
2782 return self.hdu
2728
2783
2729
2784
2730 def Ctable(self,colList):
2785 def Ctable(self,colList):
2731 self.cols=pyfits.ColDefs(colList)
2786 self.cols=pyfits.ColDefs(colList)
2732 self.tbhdu = pyfits.new_table(self.cols)
2787 self.tbhdu = pyfits.new_table(self.cols)
2733 return self.tbhdu
2788 return self.tbhdu
2734
2789
2735
2790
2736 def CFile(self,hdu,tbhdu):
2791 def CFile(self,hdu,tbhdu):
2737 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2792 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2738
2793
2739 def wFile(self,filename):
2794 def wFile(self,filename):
2740 if os.path.isfile(filename):
2795 if os.path.isfile(filename):
2741 os.remove(filename)
2796 os.remove(filename)
2742 self.thdulist.writeto(filename)
2797 self.thdulist.writeto(filename)
2743
2798
2744
2799
2745 class ParameterConf:
2800 class ParameterConf:
2746 ELEMENTNAME = 'Parameter'
2801 ELEMENTNAME = 'Parameter'
2747 def __init__(self):
2802 def __init__(self):
2748 self.name = ''
2803 self.name = ''
2749 self.value = ''
2804 self.value = ''
2750
2805
2751 def readXml(self, parmElement):
2806 def readXml(self, parmElement):
2752 self.name = parmElement.get('name')
2807 self.name = parmElement.get('name')
2753 self.value = parmElement.get('value')
2808 self.value = parmElement.get('value')
2754
2809
2755 def getElementName(self):
2810 def getElementName(self):
2756 return self.ELEMENTNAME
2811 return self.ELEMENTNAME
2757
2812
2758 class Metadata:
2813 class Metadata:
2759
2814
2760 def __init__(self, filename):
2815 def __init__(self, filename):
2761 self.parmConfObjList = []
2816 self.parmConfObjList = []
2762 self.readXml(filename)
2817 self.readXml(filename)
2763
2818
2764 def readXml(self, filename):
2819 def readXml(self, filename):
2765 self.projectElement = None
2820 self.projectElement = None
2766 self.procUnitConfObjDict = {}
2821 self.procUnitConfObjDict = {}
2767 self.projectElement = ElementTree().parse(filename)
2822 self.projectElement = ElementTree().parse(filename)
2768 self.project = self.projectElement.tag
2823 self.project = self.projectElement.tag
2769
2824
2770 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
2825 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
2771
2826
2772 for parmElement in parmElementList:
2827 for parmElement in parmElementList:
2773 parmConfObj = ParameterConf()
2828 parmConfObj = ParameterConf()
2774 parmConfObj.readXml(parmElement)
2829 parmConfObj.readXml(parmElement)
2775 self.parmConfObjList.append(parmConfObj)
2830 self.parmConfObjList.append(parmConfObj)
2776
2831
2777 class FitsWriter(Operation):
2832 class FitsWriter(Operation):
2778
2833
2779 def __init__(self):
2834 def __init__(self):
2780 self.isConfig = False
2835 self.isConfig = False
2781 self.dataBlocksPerFile = None
2836 self.dataBlocksPerFile = None
2782 self.blockIndex = 0
2837 self.blockIndex = 0
2783 self.flagIsNewFile = 1
2838 self.flagIsNewFile = 1
2784 self.fitsObj = None
2839 self.fitsObj = None
2785 self.optchar = 'P'
2840 self.optchar = 'P'
2786 self.ext = '.fits'
2841 self.ext = '.fits'
2787 self.setFile = 0
2842 self.setFile = 0
2788
2843
2789 def setFitsHeader(self, dataOut, metadatafile):
2844 def setFitsHeader(self, dataOut, metadatafile):
2790
2845
2791 header_data = pyfits.PrimaryHDU()
2846 header_data = pyfits.PrimaryHDU()
2792
2847
2793 metadata4fits = Metadata(metadatafile)
2848 metadata4fits = Metadata(metadatafile)
2794 for parameter in metadata4fits.parmConfObjList:
2849 for parameter in metadata4fits.parmConfObjList:
2795 parm_name = parameter.name
2850 parm_name = parameter.name
2796 parm_value = parameter.value
2851 parm_value = parameter.value
2797
2852
2798 if parm_value == 'fromdatadatetime':
2853 if parm_value == 'fromdatadatetime':
2799 value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
2854 value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
2800 elif parm_value == 'fromdataheights':
2855 elif parm_value == 'fromdataheights':
2801 value = dataOut.nHeights
2856 value = dataOut.nHeights
2802 elif parm_value == 'fromdatachannel':
2857 elif parm_value == 'fromdatachannel':
2803 value = dataOut.nChannels
2858 value = dataOut.nChannels
2804 elif parm_value == 'fromdatasamples':
2859 elif parm_value == 'fromdatasamples':
2805 value = dataOut.nFFTPoints
2860 value = dataOut.nFFTPoints
2806 else:
2861 else:
2807 value = parm_value
2862 value = parm_value
2808
2863
2809 header_data.header[parm_name] = value
2864 header_data.header[parm_name] = value
2810
2865
2811 header_data.header['NBLOCK'] = self.blockIndex
2866 header_data.header['NBLOCK'] = self.blockIndex
2812
2867
2813 header_data.writeto(self.filename)
2868 header_data.writeto(self.filename)
2814
2869
2815
2870
2816 def setup(self, dataOut, path, dataBlocksPerFile, metadatafile):
2871 def setup(self, dataOut, path, dataBlocksPerFile, metadatafile):
2817
2872
2818 self.path = path
2873 self.path = path
2819 self.dataOut = dataOut
2874 self.dataOut = dataOut
2820 self.metadatafile = metadatafile
2875 self.metadatafile = metadatafile
2821 self.dataBlocksPerFile = dataBlocksPerFile
2876 self.dataBlocksPerFile = dataBlocksPerFile
2822
2877
2823 def open(self):
2878 def open(self):
2824 self.fitsObj = pyfits.open(self.filename, mode='update')
2879 self.fitsObj = pyfits.open(self.filename, mode='update')
2825
2880
2826
2881
2827 def addData(self, data):
2882 def addData(self, data):
2828 self.open()
2883 self.open()
2829 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATA'])
2884 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATA'])
2830 extension.header['UTCTIME'] = self.dataOut.utctime
2885 extension.header['UTCTIME'] = self.dataOut.utctime
2831 self.fitsObj.append(extension)
2886 self.fitsObj.append(extension)
2832 self.blockIndex += 1
2887 self.blockIndex += 1
2833 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
2888 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
2834
2889
2835 self.write()
2890 self.write()
2836
2891
2837 def write(self):
2892 def write(self):
2838
2893
2839 self.fitsObj.flush(verbose=True)
2894 self.fitsObj.flush(verbose=True)
2840 self.fitsObj.close()
2895 self.fitsObj.close()
2841
2896
2842
2897
2843 def setNextFile(self):
2898 def setNextFile(self):
2844
2899
2845 ext = self.ext
2900 ext = self.ext
2846 path = self.path
2901 path = self.path
2847
2902
2848 timeTuple = time.localtime( self.dataOut.utctime)
2903 timeTuple = time.localtime( self.dataOut.utctime)
2849 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
2904 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
2850
2905
2851 fullpath = os.path.join( path, subfolder )
2906 fullpath = os.path.join( path, subfolder )
2852 if not( os.path.exists(fullpath) ):
2907 if not( os.path.exists(fullpath) ):
2853 os.mkdir(fullpath)
2908 os.mkdir(fullpath)
2854 self.setFile = -1 #inicializo mi contador de seteo
2909 self.setFile = -1 #inicializo mi contador de seteo
2855 else:
2910 else:
2856 filesList = os.listdir( fullpath )
2911 filesList = os.listdir( fullpath )
2857 if len( filesList ) > 0:
2912 if len( filesList ) > 0:
2858 filesList = sorted( filesList, key=str.lower )
2913 filesList = sorted( filesList, key=str.lower )
2859 filen = filesList[-1]
2914 filen = filesList[-1]
2860
2915
2861 if isNumber( filen[8:11] ):
2916 if isNumber( filen[8:11] ):
2862 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
2917 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
2863 else:
2918 else:
2864 self.setFile = -1
2919 self.setFile = -1
2865 else:
2920 else:
2866 self.setFile = -1 #inicializo mi contador de seteo
2921 self.setFile = -1 #inicializo mi contador de seteo
2867
2922
2868 setFile = self.setFile
2923 setFile = self.setFile
2869 setFile += 1
2924 setFile += 1
2870
2925
2871 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
2926 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
2872 timeTuple.tm_year,
2927 timeTuple.tm_year,
2873 timeTuple.tm_yday,
2928 timeTuple.tm_yday,
2874 setFile,
2929 setFile,
2875 ext )
2930 ext )
2876
2931
2877 filename = os.path.join( path, subfolder, file )
2932 filename = os.path.join( path, subfolder, file )
2878
2933
2879 self.blockIndex = 0
2934 self.blockIndex = 0
2880 self.filename = filename
2935 self.filename = filename
2881 self.setFile = setFile
2936 self.setFile = setFile
2882 self.flagIsNewFile = 1
2937 self.flagIsNewFile = 1
2883
2938
2884 print 'Writing the file: %s'%self.filename
2939 print 'Writing the file: %s'%self.filename
2885
2940
2886 self.setFitsHeader(self.dataOut, self.metadatafile)
2941 self.setFitsHeader(self.dataOut, self.metadatafile)
2887
2942
2888 return 1
2943 return 1
2889
2944
2890 def writeBlock(self):
2945 def writeBlock(self):
2891 self.addData(self.dataOut.data_spc)
2946 self.addData(self.dataOut.data_spc)
2892 self.flagIsNewFile = 0
2947 self.flagIsNewFile = 0
2893
2948
2894
2949
2895 def __setNewBlock(self):
2950 def __setNewBlock(self):
2896
2951
2897 if self.flagIsNewFile:
2952 if self.flagIsNewFile:
2898 return 1
2953 return 1
2899
2954
2900 if self.blockIndex < self.dataBlocksPerFile:
2955 if self.blockIndex < self.dataBlocksPerFile:
2901 return 1
2956 return 1
2902
2957
2903 if not( self.setNextFile() ):
2958 if not( self.setNextFile() ):
2904 return 0
2959 return 0
2905
2960
2906 return 1
2961 return 1
2907
2962
2908 def writeNextBlock(self):
2963 def writeNextBlock(self):
2909 if not( self.__setNewBlock() ):
2964 if not( self.__setNewBlock() ):
2910 return 0
2965 return 0
2911 self.writeBlock()
2966 self.writeBlock()
2912 return 1
2967 return 1
2913
2968
2914 def putData(self):
2969 def putData(self):
2915 if self.flagIsNewFile:
2970 if self.flagIsNewFile:
2916 self.setNextFile()
2971 self.setNextFile()
2917 self.writeNextBlock()
2972 self.writeNextBlock()
2918
2973
2919 def run(self, dataOut, **kwargs):
2974 def run(self, dataOut, **kwargs):
2920 if not(self.isConfig):
2975 if not(self.isConfig):
2921 self.setup(dataOut, **kwargs)
2976 self.setup(dataOut, **kwargs)
2922 self.isConfig = True
2977 self.isConfig = True
2923 self.putData()
2978 self.putData()
2924
2979
2925
2980
2926 class FitsReader(ProcessingUnit):
2981 class FitsReader(ProcessingUnit):
2927
2982
2928 __TIMEZONE = time.timezone
2983 __TIMEZONE = time.timezone
2929
2984
2930 expName = None
2985 expName = None
2931 datetimestr = None
2986 datetimestr = None
2932 utc = None
2987 utc = None
2933 nChannels = None
2988 nChannels = None
2934 nSamples = None
2989 nSamples = None
2935 dataBlocksPerFile = None
2990 dataBlocksPerFile = None
2936 comments = None
2991 comments = None
2937 lastUTTime = None
2992 lastUTTime = None
2938 header_dict = None
2993 header_dict = None
2939 data = None
2994 data = None
2940 data_header_dict = None
2995 data_header_dict = None
2941
2996
2942 def __init__(self):
2997 def __init__(self):
2943 self.isConfig = False
2998 self.isConfig = False
2944 self.ext = '.fits'
2999 self.ext = '.fits'
2945 self.setFile = 0
3000 self.setFile = 0
2946 self.flagNoMoreFiles = 0
3001 self.flagNoMoreFiles = 0
2947 self.flagIsNewFile = 1
3002 self.flagIsNewFile = 1
2948 self.flagTimeBlock = None
3003 self.flagTimeBlock = None
2949 self.fileIndex = None
3004 self.fileIndex = None
2950 self.filename = None
3005 self.filename = None
2951 self.fileSize = None
3006 self.fileSize = None
2952 self.fitsObj = None
3007 self.fitsObj = None
2953 self.nReadBlocks = 0
3008 self.nReadBlocks = 0
2954 self.nTotalBlocks = 0
3009 self.nTotalBlocks = 0
2955 self.dataOut = self.createObjByDefault()
3010 self.dataOut = self.createObjByDefault()
2956 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
3011 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
2957 self.blockIndex = 1
3012 self.blockIndex = 1
2958
3013
2959 def createObjByDefault(self):
3014 def createObjByDefault(self):
2960
3015
2961 dataObj = Fits()
3016 dataObj = Fits()
2962
3017
2963 return dataObj
3018 return dataObj
2964
3019
2965 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
3020 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
2966 try:
3021 try:
2967 fitsObj = pyfits.open(filename,'readonly')
3022 fitsObj = pyfits.open(filename,'readonly')
2968 except:
3023 except:
2969 raise IOError, "The file %s can't be opened" %(filename)
3024 raise IOError, "The file %s can't be opened" %(filename)
2970
3025
2971 header = fitsObj[0].header
3026 header = fitsObj[0].header
2972 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
3027 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
2973 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
3028 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
2974
3029
2975 ltc = utc
3030 ltc = utc
2976 if useLocalTime:
3031 if useLocalTime:
2977 ltc -= time.timezone
3032 ltc -= time.timezone
2978 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
3033 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
2979 thisTime = thisDatetime.time()
3034 thisTime = thisDatetime.time()
2980
3035
2981 if not ((startTime <= thisTime) and (endTime > thisTime)):
3036 if not ((startTime <= thisTime) and (endTime > thisTime)):
2982 return None
3037 return None
2983
3038
2984 return thisDatetime
3039 return thisDatetime
2985
3040
2986 def __setNextFileOnline(self):
3041 def __setNextFileOnline(self):
2987 raise ValueError, "No implemented"
3042 raise ValueError, "No implemented"
2988
3043
2989 def __setNextFileOffline(self):
3044 def __setNextFileOffline(self):
2990 idFile = self.fileIndex
3045 idFile = self.fileIndex
2991
3046
2992 while (True):
3047 while (True):
2993 idFile += 1
3048 idFile += 1
2994 if not(idFile < len(self.filenameList)):
3049 if not(idFile < len(self.filenameList)):
2995 self.flagNoMoreFiles = 1
3050 self.flagNoMoreFiles = 1
2996 print "No more Files"
3051 print "No more Files"
2997 return 0
3052 return 0
2998
3053
2999 filename = self.filenameList[idFile]
3054 filename = self.filenameList[idFile]
3000
3055
3001 # if not(self.__verifyFile(filename)):
3056 # if not(self.__verifyFile(filename)):
3002 # continue
3057 # continue
3003
3058
3004 fileSize = os.path.getsize(filename)
3059 fileSize = os.path.getsize(filename)
3005 fitsObj = pyfits.open(filename,'readonly')
3060 fitsObj = pyfits.open(filename,'readonly')
3006 break
3061 break
3007
3062
3008 self.flagIsNewFile = 1
3063 self.flagIsNewFile = 1
3009 self.fileIndex = idFile
3064 self.fileIndex = idFile
3010 self.filename = filename
3065 self.filename = filename
3011 self.fileSize = fileSize
3066 self.fileSize = fileSize
3012 self.fitsObj = fitsObj
3067 self.fitsObj = fitsObj
3013
3068
3014 print "Setting the file: %s"%self.filename
3069 print "Setting the file: %s"%self.filename
3015
3070
3016 return 1
3071 return 1
3017
3072
3018 def readHeader(self):
3073 def readHeader(self):
3019 headerObj = self.fitsObj[0]
3074 headerObj = self.fitsObj[0]
3020
3075
3021 self.header_dict = headerObj.header
3076 self.header_dict = headerObj.header
3022 self.expName = headerObj.header['EXPNAME']
3077 self.expName = headerObj.header['EXPNAME']
3023 self.datetimestr = headerObj.header['DATETIME']
3078 self.datetimestr = headerObj.header['DATETIME']
3024 struct_time = time.strptime(headerObj.header['DATETIME'], "%b %d %Y %H:%M:%S")
3079 struct_time = time.strptime(headerObj.header['DATETIME'], "%b %d %Y %H:%M:%S")
3025 # self.utc = time.mktime(struct_time) - self.__TIMEZONE
3080 # self.utc = time.mktime(struct_time) - self.__TIMEZONE
3026 self.nChannels = headerObj.header['NCHANNEL']
3081 self.nChannels = headerObj.header['NCHANNEL']
3027 self.nSamples = headerObj.header['NSAMPLE']
3082 self.nSamples = headerObj.header['NSAMPLE']
3028 self.dataBlocksPerFile = headerObj.header['NBLOCK']
3083 self.dataBlocksPerFile = headerObj.header['NBLOCK']
3029 self.comments = headerObj.header['COMMENT']
3084 self.comments = headerObj.header['COMMENT']
3030
3085
3031
3086
3032 def setNextFile(self):
3087 def setNextFile(self):
3033
3088
3034 if self.online:
3089 if self.online:
3035 newFile = self.__setNextFileOnline()
3090 newFile = self.__setNextFileOnline()
3036 else:
3091 else:
3037 newFile = self.__setNextFileOffline()
3092 newFile = self.__setNextFileOffline()
3038
3093
3039 if not(newFile):
3094 if not(newFile):
3040 return 0
3095 return 0
3041
3096
3042 self.readHeader()
3097 self.readHeader()
3043
3098
3044 self.nReadBlocks = 0
3099 self.nReadBlocks = 0
3045 self.blockIndex = 1
3100 self.blockIndex = 1
3046 return 1
3101 return 1
3047
3102
3048 def __searchFilesOffLine(self,
3103 def __searchFilesOffLine(self,
3049 path,
3104 path,
3050 startDate,
3105 startDate,
3051 endDate,
3106 endDate,
3052 startTime=datetime.time(0,0,0),
3107 startTime=datetime.time(0,0,0),
3053 endTime=datetime.time(23,59,59),
3108 endTime=datetime.time(23,59,59),
3054 set=None,
3109 set=None,
3055 expLabel='',
3110 expLabel='',
3056 ext='.fits',
3111 ext='.fits',
3057 walk=True):
3112 walk=True):
3058
3113
3059 pathList = []
3114 pathList = []
3060
3115
3061 if not walk:
3116 if not walk:
3062 pathList.append(path)
3117 pathList.append(path)
3063
3118
3064 else:
3119 else:
3065 dirList = []
3120 dirList = []
3066 for thisPath in os.listdir(path):
3121 for thisPath in os.listdir(path):
3067 if not os.path.isdir(os.path.join(path,thisPath)):
3122 if not os.path.isdir(os.path.join(path,thisPath)):
3068 continue
3123 continue
3069 if not isDoyFolder(thisPath):
3124 if not isDoyFolder(thisPath):
3070 continue
3125 continue
3071
3126
3072 dirList.append(thisPath)
3127 dirList.append(thisPath)
3073
3128
3074 if not(dirList):
3129 if not(dirList):
3075 return None, None
3130 return None, None
3076
3131
3077 thisDate = startDate
3132 thisDate = startDate
3078
3133
3079 while(thisDate <= endDate):
3134 while(thisDate <= endDate):
3080 year = thisDate.timetuple().tm_year
3135 year = thisDate.timetuple().tm_year
3081 doy = thisDate.timetuple().tm_yday
3136 doy = thisDate.timetuple().tm_yday
3082
3137
3083 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
3138 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
3084 if len(matchlist) == 0:
3139 if len(matchlist) == 0:
3085 thisDate += datetime.timedelta(1)
3140 thisDate += datetime.timedelta(1)
3086 continue
3141 continue
3087 for match in matchlist:
3142 for match in matchlist:
3088 pathList.append(os.path.join(path,match,expLabel))
3143 pathList.append(os.path.join(path,match,expLabel))
3089
3144
3090 thisDate += datetime.timedelta(1)
3145 thisDate += datetime.timedelta(1)
3091
3146
3092 if pathList == []:
3147 if pathList == []:
3093 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
3148 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
3094 return None, None
3149 return None, None
3095
3150
3096 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
3151 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
3097
3152
3098 filenameList = []
3153 filenameList = []
3099 datetimeList = []
3154 datetimeList = []
3100
3155
3101 for i in range(len(pathList)):
3156 for i in range(len(pathList)):
3102
3157
3103 thisPath = pathList[i]
3158 thisPath = pathList[i]
3104
3159
3105 fileList = glob.glob1(thisPath, "*%s" %ext)
3160 fileList = glob.glob1(thisPath, "*%s" %ext)
3106 fileList.sort()
3161 fileList.sort()
3107
3162
3108 for file in fileList:
3163 for file in fileList:
3109
3164
3110 filename = os.path.join(thisPath,file)
3165 filename = os.path.join(thisPath,file)
3111 thisDatetime = self.isFileinThisTime(filename, startTime, endTime, useLocalTime=True)
3166 thisDatetime = self.isFileinThisTime(filename, startTime, endTime, useLocalTime=True)
3112
3167
3113 if not(thisDatetime):
3168 if not(thisDatetime):
3114 continue
3169 continue
3115
3170
3116 filenameList.append(filename)
3171 filenameList.append(filename)
3117 datetimeList.append(thisDatetime)
3172 datetimeList.append(thisDatetime)
3118
3173
3119 if not(filenameList):
3174 if not(filenameList):
3120 print "Any file was found for the time range %s - %s" %(startTime, endTime)
3175 print "Any file was found for the time range %s - %s" %(startTime, endTime)
3121 return None, None
3176 return None, None
3122
3177
3123 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
3178 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
3124 print
3179 print
3125
3180
3126 for i in range(len(filenameList)):
3181 for i in range(len(filenameList)):
3127 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
3182 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
3128
3183
3129 self.filenameList = filenameList
3184 self.filenameList = filenameList
3130 self.datetimeList = datetimeList
3185 self.datetimeList = datetimeList
3131
3186
3132 return pathList, filenameList
3187 return pathList, filenameList
3133
3188
3134 def setup(self, path=None,
3189 def setup(self, path=None,
3135 startDate=None,
3190 startDate=None,
3136 endDate=None,
3191 endDate=None,
3137 startTime=datetime.time(0,0,0),
3192 startTime=datetime.time(0,0,0),
3138 endTime=datetime.time(23,59,59),
3193 endTime=datetime.time(23,59,59),
3139 set=0,
3194 set=0,
3140 expLabel = "",
3195 expLabel = "",
3141 ext = None,
3196 ext = None,
3142 online = False,
3197 online = False,
3143 delay = 60,
3198 delay = 60,
3144 walk = True):
3199 walk = True):
3145
3200
3146 if path == None:
3201 if path == None:
3147 raise ValueError, "The path is not valid"
3202 raise ValueError, "The path is not valid"
3148
3203
3149 if ext == None:
3204 if ext == None:
3150 ext = self.ext
3205 ext = self.ext
3151
3206
3152 if not(online):
3207 if not(online):
3153 print "Searching files in offline mode ..."
3208 print "Searching files in offline mode ..."
3154 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
3209 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
3155 startTime=startTime, endTime=endTime,
3210 startTime=startTime, endTime=endTime,
3156 set=set, expLabel=expLabel, ext=ext,
3211 set=set, expLabel=expLabel, ext=ext,
3157 walk=walk)
3212 walk=walk)
3158
3213
3159 if not(pathList):
3214 if not(pathList):
3160 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
3215 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
3161 datetime.datetime.combine(startDate,startTime).ctime(),
3216 datetime.datetime.combine(startDate,startTime).ctime(),
3162 datetime.datetime.combine(endDate,endTime).ctime())
3217 datetime.datetime.combine(endDate,endTime).ctime())
3163
3218
3164 sys.exit(-1)
3219 sys.exit(-1)
3165
3220
3166 self.fileIndex = -1
3221 self.fileIndex = -1
3167 self.pathList = pathList
3222 self.pathList = pathList
3168 self.filenameList = filenameList
3223 self.filenameList = filenameList
3169
3224
3170 self.online = online
3225 self.online = online
3171 self.delay = delay
3226 self.delay = delay
3172 ext = ext.lower()
3227 ext = ext.lower()
3173 self.ext = ext
3228 self.ext = ext
3174
3229
3175 if not(self.setNextFile()):
3230 if not(self.setNextFile()):
3176 if (startDate!=None) and (endDate!=None):
3231 if (startDate!=None) and (endDate!=None):
3177 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
3232 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
3178 elif startDate != None:
3233 elif startDate != None:
3179 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
3234 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
3180 else:
3235 else:
3181 print "No files"
3236 print "No files"
3182
3237
3183 sys.exit(-1)
3238 sys.exit(-1)
3184
3239
3185
3240
3186
3241
3187 def readBlock(self):
3242 def readBlock(self):
3188 dataObj = self.fitsObj[self.blockIndex]
3243 dataObj = self.fitsObj[self.blockIndex]
3189
3244
3190 self.data = dataObj.data
3245 self.data = dataObj.data
3191 self.data_header_dict = dataObj.header
3246 self.data_header_dict = dataObj.header
3192 self.utc = self.data_header_dict['UTCTIME']
3247 self.utc = self.data_header_dict['UTCTIME']
3193
3248
3194 self.flagIsNewFile = 0
3249 self.flagIsNewFile = 0
3195 self.blockIndex += 1
3250 self.blockIndex += 1
3196 self.nTotalBlocks += 1
3251 self.nTotalBlocks += 1
3197 self.nReadBlocks += 1
3252 self.nReadBlocks += 1
3198
3253
3199 return 1
3254 return 1
3200
3255
3201 def __jumpToLastBlock(self):
3256 def __jumpToLastBlock(self):
3202 raise ValueError, "No implemented"
3257 raise ValueError, "No implemented"
3203
3258
3204 def __waitNewBlock(self):
3259 def __waitNewBlock(self):
3205 """
3260 """
3206 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
3261 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
3207
3262
3208 Si el modo de lectura es OffLine siempre retorn 0
3263 Si el modo de lectura es OffLine siempre retorn 0
3209 """
3264 """
3210 if not self.online:
3265 if not self.online:
3211 return 0
3266 return 0
3212
3267
3213 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
3268 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
3214 return 0
3269 return 0
3215
3270
3216 currentPointer = self.fp.tell()
3271 currentPointer = self.fp.tell()
3217
3272
3218 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
3273 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
3219
3274
3220 for nTries in range( self.nTries ):
3275 for nTries in range( self.nTries ):
3221
3276
3222 self.fp.close()
3277 self.fp.close()
3223 self.fp = open( self.filename, 'rb' )
3278 self.fp = open( self.filename, 'rb' )
3224 self.fp.seek( currentPointer )
3279 self.fp.seek( currentPointer )
3225
3280
3226 self.fileSize = os.path.getsize( self.filename )
3281 self.fileSize = os.path.getsize( self.filename )
3227 currentSize = self.fileSize - currentPointer
3282 currentSize = self.fileSize - currentPointer
3228
3283
3229 if ( currentSize >= neededSize ):
3284 if ( currentSize >= neededSize ):
3230 self.__rdBasicHeader()
3285 self.__rdBasicHeader()
3231 return 1
3286 return 1
3232
3287
3233 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
3288 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
3234 time.sleep( self.delay )
3289 time.sleep( self.delay )
3235
3290
3236
3291
3237 return 0
3292 return 0
3238
3293
3239 def __setNewBlock(self):
3294 def __setNewBlock(self):
3240
3295
3241 if self.online:
3296 if self.online:
3242 self.__jumpToLastBlock()
3297 self.__jumpToLastBlock()
3243
3298
3244 if self.flagIsNewFile:
3299 if self.flagIsNewFile:
3245 return 1
3300 return 1
3246
3301
3247 self.lastUTTime = self.utc
3302 self.lastUTTime = self.utc
3248
3303
3249 if self.online:
3304 if self.online:
3250 if self.__waitNewBlock():
3305 if self.__waitNewBlock():
3251 return 1
3306 return 1
3252
3307
3253 if self.nReadBlocks < self.dataBlocksPerFile:
3308 if self.nReadBlocks < self.dataBlocksPerFile:
3254 return 1
3309 return 1
3255
3310
3256 if not(self.setNextFile()):
3311 if not(self.setNextFile()):
3257 return 0
3312 return 0
3258
3313
3259 deltaTime = self.utc - self.lastUTTime
3314 deltaTime = self.utc - self.lastUTTime
3260
3315
3261 self.flagTimeBlock = 0
3316 self.flagTimeBlock = 0
3262
3317
3263 if deltaTime > self.maxTimeStep:
3318 if deltaTime > self.maxTimeStep:
3264 self.flagTimeBlock = 1
3319 self.flagTimeBlock = 1
3265
3320
3266 return 1
3321 return 1
3267
3322
3268
3323
3269 def readNextBlock(self):
3324 def readNextBlock(self):
3270 if not(self.__setNewBlock()):
3325 if not(self.__setNewBlock()):
3271 return 0
3326 return 0
3272
3327
3273 if not(self.readBlock()):
3328 if not(self.readBlock()):
3274 return 0
3329 return 0
3275
3330
3276 return 1
3331 return 1
3277
3332
3278
3333
3279 def getData(self):
3334 def getData(self):
3280
3335
3281 if self.flagNoMoreFiles:
3336 if self.flagNoMoreFiles:
3282 self.dataOut.flagNoData = True
3337 self.dataOut.flagNoData = True
3283 print 'Process finished'
3338 print 'Process finished'
3284 return 0
3339 return 0
3285
3340
3286 self.flagTimeBlock = 0
3341 self.flagTimeBlock = 0
3287 self.flagIsNewBlock = 0
3342 self.flagIsNewBlock = 0
3288
3343
3289 if not(self.readNextBlock()):
3344 if not(self.readNextBlock()):
3290 return 0
3345 return 0
3291
3346
3292 if self.data == None:
3347 if self.data == None:
3293 self.dataOut.flagNoData = True
3348 self.dataOut.flagNoData = True
3294 return 0
3349 return 0
3295
3350
3296 self.dataOut.data = self.data
3351 self.dataOut.data = self.data
3297 self.dataOut.data_header = self.data_header_dict
3352 self.dataOut.data_header = self.data_header_dict
3298 self.dataOut.utctime = self.utc
3353 self.dataOut.utctime = self.utc
3299
3354
3300 self.dataOut.header = self.header_dict
3355 self.dataOut.header = self.header_dict
3301 self.dataOut.expName = self.expName
3356 self.dataOut.expName = self.expName
3302 self.dataOut.nChannels = self.nChannels
3357 self.dataOut.nChannels = self.nChannels
3303 self.dataOut.nSamples = self.nSamples
3358 self.dataOut.nSamples = self.nSamples
3304 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
3359 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
3305 self.dataOut.comments = self.comments
3360 self.dataOut.comments = self.comments
3306
3361
3307 self.dataOut.flagNoData = False
3362 self.dataOut.flagNoData = False
3308
3363
3309 return self.dataOut.data
3364 return self.dataOut.data
3310
3365
3311 def run(self, **kwargs):
3366 def run(self, **kwargs):
3312
3367
3313 if not(self.isConfig):
3368 if not(self.isConfig):
3314 self.setup(**kwargs)
3369 self.setup(**kwargs)
3315 self.isConfig = True
3370 self.isConfig = True
3316
3371
3317 self.getData() No newline at end of file
3372 self.getData()
@@ -1,1354 +1,1355
1 import numpy
1 import numpy
2 import time, datetime, os
2 import time, datetime, os
3 from graphics.figure import *
3 from graphics.figure import *
4 def isRealtime(utcdatatime):
4 def isRealtime(utcdatatime):
5 utcnow = time.mktime(datetime.datetime.utcnow().timetuple())
5 utcnow = time.mktime(datetime.datetime.utcnow().timetuple())
6 delta = utcnow - utcdatatime # abs
6 delta = utcnow - utcdatatime # abs
7 if delta >= 5*60.:
7 if delta >= 5*60.:
8 return False
8 return False
9 return True
9 return True
10
10
11 class CrossSpectraPlot(Figure):
11 class CrossSpectraPlot(Figure):
12
12
13 __isConfig = None
13 __isConfig = None
14 __nsubplots = None
14 __nsubplots = None
15
15
16 WIDTH = None
16 WIDTH = None
17 HEIGHT = None
17 HEIGHT = None
18 WIDTHPROF = None
18 WIDTHPROF = None
19 HEIGHTPROF = None
19 HEIGHTPROF = None
20 PREFIX = 'cspc'
20 PREFIX = 'cspc'
21
21
22 def __init__(self):
22 def __init__(self):
23
23
24 self.__isConfig = False
24 self.__isConfig = False
25 self.__nsubplots = 4
25 self.__nsubplots = 4
26
26
27 self.WIDTH = 250
27 self.WIDTH = 250
28 self.HEIGHT = 250
28 self.HEIGHT = 250
29 self.WIDTHPROF = 0
29 self.WIDTHPROF = 0
30 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
31
31
32 def getSubplots(self):
32 def getSubplots(self):
33
33
34 ncol = 4
34 ncol = 4
35 nrow = self.nplots
35 nrow = self.nplots
36
36
37 return nrow, ncol
37 return nrow, ncol
38
38
39 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
39 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
40
40
41 self.__showprofile = showprofile
41 self.__showprofile = showprofile
42 self.nplots = nplots
42 self.nplots = nplots
43
43
44 ncolspan = 1
44 ncolspan = 1
45 colspan = 1
45 colspan = 1
46
46
47 self.createFigure(idfigure = idfigure,
47 self.createFigure(idfigure = idfigure,
48 wintitle = wintitle,
48 wintitle = wintitle,
49 widthplot = self.WIDTH + self.WIDTHPROF,
49 widthplot = self.WIDTH + self.WIDTHPROF,
50 heightplot = self.HEIGHT + self.HEIGHTPROF,
50 heightplot = self.HEIGHT + self.HEIGHTPROF,
51 show=True)
51 show=True)
52
52
53 nrow, ncol = self.getSubplots()
53 nrow, ncol = self.getSubplots()
54
54
55 counter = 0
55 counter = 0
56 for y in range(nrow):
56 for y in range(nrow):
57 for x in range(ncol):
57 for x in range(ncol):
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
59
59
60 counter += 1
60 counter += 1
61
61
62 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
62 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
64 save=False, figpath='./', figfile=None,
64 save=False, figpath='./', figfile=None,
65 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
65 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
66
66
67 """
67 """
68
68
69 Input:
69 Input:
70 dataOut :
70 dataOut :
71 idfigure :
71 idfigure :
72 wintitle :
72 wintitle :
73 channelList :
73 channelList :
74 showProfile :
74 showProfile :
75 xmin : None,
75 xmin : None,
76 xmax : None,
76 xmax : None,
77 ymin : None,
77 ymin : None,
78 ymax : None,
78 ymax : None,
79 zmin : None,
79 zmin : None,
80 zmax : None
80 zmax : None
81 """
81 """
82
82
83 if pairsList == None:
83 if pairsList == None:
84 pairsIndexList = dataOut.pairsIndexList
84 pairsIndexList = dataOut.pairsIndexList
85 else:
85 else:
86 pairsIndexList = []
86 pairsIndexList = []
87 for pair in pairsList:
87 for pair in pairsList:
88 if pair not in dataOut.pairsList:
88 if pair not in dataOut.pairsList:
89 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
89 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
90 pairsIndexList.append(dataOut.pairsList.index(pair))
90 pairsIndexList.append(dataOut.pairsList.index(pair))
91
91
92 if pairsIndexList == []:
92 if pairsIndexList == []:
93 return
93 return
94
94
95 if len(pairsIndexList) > 4:
95 if len(pairsIndexList) > 4:
96 pairsIndexList = pairsIndexList[0:4]
96 pairsIndexList = pairsIndexList[0:4]
97 factor = dataOut.normFactor
97 factor = dataOut.normFactor
98 x = dataOut.getVelRange(1)
98 x = dataOut.getVelRange(1)
99 y = dataOut.getHeiRange()
99 y = dataOut.getHeiRange()
100 z = dataOut.data_spc[:,:,:]/factor
100 z = dataOut.data_spc[:,:,:]/factor
101 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
101 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
102 avg = numpy.abs(numpy.average(z, axis=1))
102 avg = numpy.abs(numpy.average(z, axis=1))
103 noise = dataOut.getNoise()/factor
103 noise = dataOut.getNoise()/factor
104
104
105 zdB = 10*numpy.log10(z)
105 zdB = 10*numpy.log10(z)
106 avgdB = 10*numpy.log10(avg)
106 avgdB = 10*numpy.log10(avg)
107 noisedB = 10*numpy.log10(noise)
107 noisedB = 10*numpy.log10(noise)
108
108
109
109
110 thisDatetime = dataOut.datatime
110 thisDatetime = dataOut.datatime
111 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
111 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
112 xlabel = "Velocity (m/s)"
112 xlabel = "Velocity (m/s)"
113 ylabel = "Range (Km)"
113 ylabel = "Range (Km)"
114
114
115 if not self.__isConfig:
115 if not self.__isConfig:
116
116
117 nplots = len(pairsIndexList)
117 nplots = len(pairsIndexList)
118
118
119 self.setup(idfigure=idfigure,
119 self.setup(idfigure=idfigure,
120 nplots=nplots,
120 nplots=nplots,
121 wintitle=wintitle,
121 wintitle=wintitle,
122 showprofile=showprofile,
122 showprofile=showprofile,
123 show=show)
123 show=show)
124
124
125 if xmin == None: xmin = numpy.nanmin(x)
125 if xmin == None: xmin = numpy.nanmin(x)
126 if xmax == None: xmax = numpy.nanmax(x)
126 if xmax == None: xmax = numpy.nanmax(x)
127 if ymin == None: ymin = numpy.nanmin(y)
127 if ymin == None: ymin = numpy.nanmin(y)
128 if ymax == None: ymax = numpy.nanmax(y)
128 if ymax == None: ymax = numpy.nanmax(y)
129 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
129 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
130 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
130 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
131
131
132 self.__isConfig = True
132 self.__isConfig = True
133
133
134 self.setWinTitle(title)
134 self.setWinTitle(title)
135
135
136 for i in range(self.nplots):
136 for i in range(self.nplots):
137 pair = dataOut.pairsList[pairsIndexList[i]]
137 pair = dataOut.pairsList[pairsIndexList[i]]
138
138
139 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
139 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
141 axes0 = self.axesList[i*self.__nsubplots]
141 axes0 = self.axesList[i*self.__nsubplots]
142 axes0.pcolor(x, y, zdB,
142 axes0.pcolor(x, y, zdB,
143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
144 xlabel=xlabel, ylabel=ylabel, title=title,
144 xlabel=xlabel, ylabel=ylabel, title=title,
145 ticksize=9, colormap=power_cmap, cblabel='')
145 ticksize=9, colormap=power_cmap, cblabel='')
146
146
147 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
147 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
148 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
148 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
149 axes0 = self.axesList[i*self.__nsubplots+1]
149 axes0 = self.axesList[i*self.__nsubplots+1]
150 axes0.pcolor(x, y, zdB,
150 axes0.pcolor(x, y, zdB,
151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
152 xlabel=xlabel, ylabel=ylabel, title=title,
152 xlabel=xlabel, ylabel=ylabel, title=title,
153 ticksize=9, colormap=power_cmap, cblabel='')
153 ticksize=9, colormap=power_cmap, cblabel='')
154
154
155 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
155 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
156 coherence = numpy.abs(coherenceComplex)
156 coherence = numpy.abs(coherenceComplex)
157 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
157 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
158 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
158 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
159
159
160 title = "Coherence %d%d" %(pair[0], pair[1])
160 title = "Coherence %d%d" %(pair[0], pair[1])
161 axes0 = self.axesList[i*self.__nsubplots+2]
161 axes0 = self.axesList[i*self.__nsubplots+2]
162 axes0.pcolor(x, y, coherence,
162 axes0.pcolor(x, y, coherence,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
164 xlabel=xlabel, ylabel=ylabel, title=title,
164 xlabel=xlabel, ylabel=ylabel, title=title,
165 ticksize=9, colormap=coherence_cmap, cblabel='')
165 ticksize=9, colormap=coherence_cmap, cblabel='')
166
166
167 title = "Phase %d%d" %(pair[0], pair[1])
167 title = "Phase %d%d" %(pair[0], pair[1])
168 axes0 = self.axesList[i*self.__nsubplots+3]
168 axes0 = self.axesList[i*self.__nsubplots+3]
169 axes0.pcolor(x, y, phase,
169 axes0.pcolor(x, y, phase,
170 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
170 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
171 xlabel=xlabel, ylabel=ylabel, title=title,
171 xlabel=xlabel, ylabel=ylabel, title=title,
172 ticksize=9, colormap=phase_cmap, cblabel='')
172 ticksize=9, colormap=phase_cmap, cblabel='')
173
173
174
174
175
175
176 self.draw()
176 self.draw()
177
177
178 if save:
178 if save:
179 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
179 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
180 if figfile == None:
180 if figfile == None:
181 figfile = self.getFilename(name = date)
181 figfile = self.getFilename(name = date)
182
182
183 self.saveFigure(figpath, figfile)
183 self.saveFigure(figpath, figfile)
184
184
185
185
186 class RTIPlot(Figure):
186 class RTIPlot(Figure):
187
187
188 __isConfig = None
188 __isConfig = None
189 __nsubplots = None
189 __nsubplots = None
190
190
191 WIDTHPROF = None
191 WIDTHPROF = None
192 HEIGHTPROF = None
192 HEIGHTPROF = None
193 PREFIX = 'rti'
193 PREFIX = 'rti'
194
194
195 def __init__(self):
195 def __init__(self):
196
196
197 self.timerange = 2*60*60
197 self.timerange = 2*60*60
198 self.__isConfig = False
198 self.__isConfig = False
199 self.__nsubplots = 1
199 self.__nsubplots = 1
200
200
201 self.WIDTH = 800
201 self.WIDTH = 800
202 self.HEIGHT = 150
202 self.HEIGHT = 150
203 self.WIDTHPROF = 120
203 self.WIDTHPROF = 120
204 self.HEIGHTPROF = 0
204 self.HEIGHTPROF = 0
205 self.counterftp = 0
205 self.counterftp = 0
206
206
207 def getSubplots(self):
207 def getSubplots(self):
208
208
209 ncol = 1
209 ncol = 1
210 nrow = self.nplots
210 nrow = self.nplots
211
211
212 return nrow, ncol
212 return nrow, ncol
213
213
214 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
214 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
215
215
216 self.__showprofile = showprofile
216 self.__showprofile = showprofile
217 self.nplots = nplots
217 self.nplots = nplots
218
218
219 ncolspan = 1
219 ncolspan = 1
220 colspan = 1
220 colspan = 1
221 if showprofile:
221 if showprofile:
222 ncolspan = 7
222 ncolspan = 7
223 colspan = 6
223 colspan = 6
224 self.__nsubplots = 2
224 self.__nsubplots = 2
225
225
226 self.createFigure(idfigure = idfigure,
226 self.createFigure(idfigure = idfigure,
227 wintitle = wintitle,
227 wintitle = wintitle,
228 widthplot = self.WIDTH + self.WIDTHPROF,
228 widthplot = self.WIDTH + self.WIDTHPROF,
229 heightplot = self.HEIGHT + self.HEIGHTPROF,
229 heightplot = self.HEIGHT + self.HEIGHTPROF,
230 show=show)
230 show=show)
231
231
232 nrow, ncol = self.getSubplots()
232 nrow, ncol = self.getSubplots()
233
233
234 counter = 0
234 counter = 0
235 for y in range(nrow):
235 for y in range(nrow):
236 for x in range(ncol):
236 for x in range(ncol):
237
237
238 if counter >= self.nplots:
238 if counter >= self.nplots:
239 break
239 break
240
240
241 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
241 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
242
242
243 if showprofile:
243 if showprofile:
244 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
244 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
245
245
246 counter += 1
246 counter += 1
247
247
248 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
248 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
249 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
249 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
250 timerange=None,
250 timerange=None,
251 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
251 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
252
252
253 """
253 """
254
254
255 Input:
255 Input:
256 dataOut :
256 dataOut :
257 idfigure :
257 idfigure :
258 wintitle :
258 wintitle :
259 channelList :
259 channelList :
260 showProfile :
260 showProfile :
261 xmin : None,
261 xmin : None,
262 xmax : None,
262 xmax : None,
263 ymin : None,
263 ymin : None,
264 ymax : None,
264 ymax : None,
265 zmin : None,
265 zmin : None,
266 zmax : None
266 zmax : None
267 """
267 """
268
268
269 if channelList == None:
269 if channelList == None:
270 channelIndexList = dataOut.channelIndexList
270 channelIndexList = dataOut.channelIndexList
271 else:
271 else:
272 channelIndexList = []
272 channelIndexList = []
273 for channel in channelList:
273 for channel in channelList:
274 if channel not in dataOut.channelList:
274 if channel not in dataOut.channelList:
275 raise ValueError, "Channel %d is not in dataOut.channelList"
275 raise ValueError, "Channel %d is not in dataOut.channelList"
276 channelIndexList.append(dataOut.channelList.index(channel))
276 channelIndexList.append(dataOut.channelList.index(channel))
277
277
278 if timerange != None:
278 if timerange != None:
279 self.timerange = timerange
279 self.timerange = timerange
280
280
281 tmin = None
281 tmin = None
282 tmax = None
282 tmax = None
283 factor = dataOut.normFactor
283 factor = dataOut.normFactor
284 x = dataOut.getTimeRange()
284 x = dataOut.getTimeRange()
285 y = dataOut.getHeiRange()
285 y = dataOut.getHeiRange()
286
286
287 z = dataOut.data_spc[channelIndexList,:,:]/factor
287 z = dataOut.data_spc[channelIndexList,:,:]/factor
288 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
288 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
289 avg = numpy.average(z, axis=1)
289 avg = numpy.average(z, axis=1)
290
290
291 avgdB = 10.*numpy.log10(avg)
291 avgdB = 10.*numpy.log10(avg)
292
292
293
293
294 thisDatetime = dataOut.datatime
294 # thisDatetime = dataOut.datatime
295 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
295 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
296 title = wintitle+' ' + "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
296 xlabel = ""
297 xlabel = ""
297 ylabel = "Range (Km)"
298 ylabel = "Range (Km)"
298
299
299 if not self.__isConfig:
300 if not self.__isConfig:
300
301
301 nplots = len(channelIndexList)
302 nplots = len(channelIndexList)
302
303
303 self.setup(idfigure=idfigure,
304 self.setup(idfigure=idfigure,
304 nplots=nplots,
305 nplots=nplots,
305 wintitle=wintitle,
306 wintitle=wintitle,
306 showprofile=showprofile,
307 showprofile=showprofile,
307 show=show)
308 show=show)
308
309
309 tmin, tmax = self.getTimeLim(x, xmin, xmax)
310 tmin, tmax = self.getTimeLim(x, xmin, xmax)
310 if ymin == None: ymin = numpy.nanmin(y)
311 if ymin == None: ymin = numpy.nanmin(y)
311 if ymax == None: ymax = numpy.nanmax(y)
312 if ymax == None: ymax = numpy.nanmax(y)
312 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
313 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
313 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
314 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
314
315
315 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
316 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
316 self.__isConfig = True
317 self.__isConfig = True
317
318
318
319
319 self.setWinTitle(title)
320 self.setWinTitle(title)
320
321
321 for i in range(self.nplots):
322 for i in range(self.nplots):
322 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
323 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
323 axes = self.axesList[i*self.__nsubplots]
324 axes = self.axesList[i*self.__nsubplots]
324 zdB = avgdB[i].reshape((1,-1))
325 zdB = avgdB[i].reshape((1,-1))
325 axes.pcolorbuffer(x, y, zdB,
326 axes.pcolorbuffer(x, y, zdB,
326 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
327 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
327 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
328 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
328 ticksize=9, cblabel='', cbsize="1%")
329 ticksize=9, cblabel='', cbsize="1%")
329
330
330 if self.__showprofile:
331 if self.__showprofile:
331 axes = self.axesList[i*self.__nsubplots +1]
332 axes = self.axesList[i*self.__nsubplots +1]
332 axes.pline(avgdB[i], y,
333 axes.pline(avgdB[i], y,
333 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
334 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
334 xlabel='dB', ylabel='', title='',
335 xlabel='dB', ylabel='', title='',
335 ytick_visible=False,
336 ytick_visible=False,
336 grid='x')
337 grid='x')
337
338
338 self.draw()
339 self.draw()
339
340
340 if save:
341 if save:
341
342
342 if figfile == None:
343 if figfile == None:
343 figfile = self.getFilename(name = self.name)
344 figfile = self.getFilename(name = self.name)
344
345
345 self.saveFigure(figpath, figfile)
346 self.saveFigure(figpath, figfile)
346
347
347 self.counterftp += 1
348 self.counterftp += 1
348 if (ftp and (self.counterftp==ftpratio)):
349 if (ftp and (self.counterftp==ftpratio)):
349 figfilename = os.path.join(figpath,figfile)
350 figfilename = os.path.join(figpath,figfile)
350 self.sendByFTP(figfilename)
351 self.sendByFTP(figfilename)
351 self.counterftp = 0
352 self.counterftp = 0
352
353
353 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
354 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
354 self.__isConfig = False
355 self.__isConfig = False
355
356
356 class SpectraPlot(Figure):
357 class SpectraPlot(Figure):
357
358
358 __isConfig = None
359 __isConfig = None
359 __nsubplots = None
360 __nsubplots = None
360
361
361 WIDTHPROF = None
362 WIDTHPROF = None
362 HEIGHTPROF = None
363 HEIGHTPROF = None
363 PREFIX = 'spc'
364 PREFIX = 'spc'
364
365
365 def __init__(self):
366 def __init__(self):
366
367
367 self.__isConfig = False
368 self.__isConfig = False
368 self.__nsubplots = 1
369 self.__nsubplots = 1
369
370
370 self.WIDTH = 230
371 self.WIDTH = 230
371 self.HEIGHT = 250
372 self.HEIGHT = 250
372 self.WIDTHPROF = 120
373 self.WIDTHPROF = 120
373 self.HEIGHTPROF = 0
374 self.HEIGHTPROF = 0
374
375
375 def getSubplots(self):
376 def getSubplots(self):
376
377
377 ncol = int(numpy.sqrt(self.nplots)+0.9)
378 ncol = int(numpy.sqrt(self.nplots)+0.9)
378 nrow = int(self.nplots*1./ncol + 0.9)
379 nrow = int(self.nplots*1./ncol + 0.9)
379
380
380 return nrow, ncol
381 return nrow, ncol
381
382
382 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
383 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
383
384
384 self.__showprofile = showprofile
385 self.__showprofile = showprofile
385 self.nplots = nplots
386 self.nplots = nplots
386
387
387 ncolspan = 1
388 ncolspan = 1
388 colspan = 1
389 colspan = 1
389 if showprofile:
390 if showprofile:
390 ncolspan = 3
391 ncolspan = 3
391 colspan = 2
392 colspan = 2
392 self.__nsubplots = 2
393 self.__nsubplots = 2
393
394
394 self.createFigure(idfigure = idfigure,
395 self.createFigure(idfigure = idfigure,
395 wintitle = wintitle,
396 wintitle = wintitle,
396 widthplot = self.WIDTH + self.WIDTHPROF,
397 widthplot = self.WIDTH + self.WIDTHPROF,
397 heightplot = self.HEIGHT + self.HEIGHTPROF,
398 heightplot = self.HEIGHT + self.HEIGHTPROF,
398 show=show)
399 show=show)
399
400
400 nrow, ncol = self.getSubplots()
401 nrow, ncol = self.getSubplots()
401
402
402 counter = 0
403 counter = 0
403 for y in range(nrow):
404 for y in range(nrow):
404 for x in range(ncol):
405 for x in range(ncol):
405
406
406 if counter >= self.nplots:
407 if counter >= self.nplots:
407 break
408 break
408
409
409 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
410 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
410
411
411 if showprofile:
412 if showprofile:
412 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
413 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
413
414
414 counter += 1
415 counter += 1
415
416
416 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
417 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
417 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
418 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
418 save=False, figpath='./', figfile=None, show=True):
419 save=False, figpath='./', figfile=None, show=True):
419
420
420 """
421 """
421
422
422 Input:
423 Input:
423 dataOut :
424 dataOut :
424 idfigure :
425 idfigure :
425 wintitle :
426 wintitle :
426 channelList :
427 channelList :
427 showProfile :
428 showProfile :
428 xmin : None,
429 xmin : None,
429 xmax : None,
430 xmax : None,
430 ymin : None,
431 ymin : None,
431 ymax : None,
432 ymax : None,
432 zmin : None,
433 zmin : None,
433 zmax : None
434 zmax : None
434 """
435 """
435
436
436 if channelList == None:
437 if channelList == None:
437 channelIndexList = dataOut.channelIndexList
438 channelIndexList = dataOut.channelIndexList
438 else:
439 else:
439 channelIndexList = []
440 channelIndexList = []
440 for channel in channelList:
441 for channel in channelList:
441 if channel not in dataOut.channelList:
442 if channel not in dataOut.channelList:
442 raise ValueError, "Channel %d is not in dataOut.channelList"
443 raise ValueError, "Channel %d is not in dataOut.channelList"
443 channelIndexList.append(dataOut.channelList.index(channel))
444 channelIndexList.append(dataOut.channelList.index(channel))
444 factor = dataOut.normFactor
445 factor = dataOut.normFactor
445 x = dataOut.getVelRange(1)
446 x = dataOut.getVelRange(1)
446 y = dataOut.getHeiRange()
447 y = dataOut.getHeiRange()
447
448
448 z = dataOut.data_spc[channelIndexList,:,:]/factor
449 z = dataOut.data_spc[channelIndexList,:,:]/factor
449 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
450 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
450 avg = numpy.average(z, axis=1)
451 avg = numpy.average(z, axis=1)
451 noise = dataOut.getNoise()/factor
452 noise = dataOut.getNoise()/factor
452
453
453 zdB = 10*numpy.log10(z)
454 zdB = 10*numpy.log10(z)
454 avgdB = 10*numpy.log10(avg)
455 avgdB = 10*numpy.log10(avg)
455 noisedB = 10*numpy.log10(noise)
456 noisedB = 10*numpy.log10(noise)
456
457
457 thisDatetime = dataOut.datatime
458 thisDatetime = dataOut.datatime
458 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
459 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
459 xlabel = "Velocity (m/s)"
460 xlabel = "Velocity (m/s)"
460 ylabel = "Range (Km)"
461 ylabel = "Range (Km)"
461
462
462 if not self.__isConfig:
463 if not self.__isConfig:
463
464
464 nplots = len(channelIndexList)
465 nplots = len(channelIndexList)
465
466
466 self.setup(idfigure=idfigure,
467 self.setup(idfigure=idfigure,
467 nplots=nplots,
468 nplots=nplots,
468 wintitle=wintitle,
469 wintitle=wintitle,
469 showprofile=showprofile,
470 showprofile=showprofile,
470 show=show)
471 show=show)
471
472
472 if xmin == None: xmin = numpy.nanmin(x)
473 if xmin == None: xmin = numpy.nanmin(x)
473 if xmax == None: xmax = numpy.nanmax(x)
474 if xmax == None: xmax = numpy.nanmax(x)
474 if ymin == None: ymin = numpy.nanmin(y)
475 if ymin == None: ymin = numpy.nanmin(y)
475 if ymax == None: ymax = numpy.nanmax(y)
476 if ymax == None: ymax = numpy.nanmax(y)
476 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
477 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
477 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
478 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
478
479
479 self.__isConfig = True
480 self.__isConfig = True
480
481
481 self.setWinTitle(title)
482 self.setWinTitle(title)
482
483
483 for i in range(self.nplots):
484 for i in range(self.nplots):
484 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
485 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
485 axes = self.axesList[i*self.__nsubplots]
486 axes = self.axesList[i*self.__nsubplots]
486 axes.pcolor(x, y, zdB[i,:,:],
487 axes.pcolor(x, y, zdB[i,:,:],
487 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
488 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
488 xlabel=xlabel, ylabel=ylabel, title=title,
489 xlabel=xlabel, ylabel=ylabel, title=title,
489 ticksize=9, cblabel='')
490 ticksize=9, cblabel='')
490
491
491 if self.__showprofile:
492 if self.__showprofile:
492 axes = self.axesList[i*self.__nsubplots +1]
493 axes = self.axesList[i*self.__nsubplots +1]
493 axes.pline(avgdB[i], y,
494 axes.pline(avgdB[i], y,
494 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
495 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
495 xlabel='dB', ylabel='', title='',
496 xlabel='dB', ylabel='', title='',
496 ytick_visible=False,
497 ytick_visible=False,
497 grid='x')
498 grid='x')
498
499
499 noiseline = numpy.repeat(noisedB[i], len(y))
500 noiseline = numpy.repeat(noisedB[i], len(y))
500 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
501 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
501
502
502 self.draw()
503 self.draw()
503
504
504 if save:
505 if save:
505 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
506 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
506 if figfile == None:
507 if figfile == None:
507 figfile = self.getFilename(name = date)
508 figfile = self.getFilename(name = date)
508
509
509 self.saveFigure(figpath, figfile)
510 self.saveFigure(figpath, figfile)
510
511
511 class Scope(Figure):
512 class Scope(Figure):
512
513
513 __isConfig = None
514 __isConfig = None
514
515
515 def __init__(self):
516 def __init__(self):
516
517
517 self.__isConfig = False
518 self.__isConfig = False
518 self.WIDTH = 600
519 self.WIDTH = 600
519 self.HEIGHT = 200
520 self.HEIGHT = 200
520
521
521 def getSubplots(self):
522 def getSubplots(self):
522
523
523 nrow = self.nplots
524 nrow = self.nplots
524 ncol = 3
525 ncol = 3
525 return nrow, ncol
526 return nrow, ncol
526
527
527 def setup(self, idfigure, nplots, wintitle, show):
528 def setup(self, idfigure, nplots, wintitle, show):
528
529
529 self.nplots = nplots
530 self.nplots = nplots
530
531
531 self.createFigure(idfigure=idfigure,
532 self.createFigure(idfigure=idfigure,
532 wintitle=wintitle,
533 wintitle=wintitle,
533 show=show)
534 show=show)
534
535
535 nrow,ncol = self.getSubplots()
536 nrow,ncol = self.getSubplots()
536 colspan = 3
537 colspan = 3
537 rowspan = 1
538 rowspan = 1
538
539
539 for i in range(nplots):
540 for i in range(nplots):
540 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
541 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
541
542
542
543
543
544
544 def run(self, dataOut, idfigure, wintitle="", channelList=None,
545 def run(self, dataOut, idfigure, wintitle="", channelList=None,
545 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
546 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
546 figpath='./', figfile=None, show=True):
547 figpath='./', figfile=None, show=True):
547
548
548 """
549 """
549
550
550 Input:
551 Input:
551 dataOut :
552 dataOut :
552 idfigure :
553 idfigure :
553 wintitle :
554 wintitle :
554 channelList :
555 channelList :
555 xmin : None,
556 xmin : None,
556 xmax : None,
557 xmax : None,
557 ymin : None,
558 ymin : None,
558 ymax : None,
559 ymax : None,
559 """
560 """
560
561
561 if channelList == None:
562 if channelList == None:
562 channelIndexList = dataOut.channelIndexList
563 channelIndexList = dataOut.channelIndexList
563 else:
564 else:
564 channelIndexList = []
565 channelIndexList = []
565 for channel in channelList:
566 for channel in channelList:
566 if channel not in dataOut.channelList:
567 if channel not in dataOut.channelList:
567 raise ValueError, "Channel %d is not in dataOut.channelList"
568 raise ValueError, "Channel %d is not in dataOut.channelList"
568 channelIndexList.append(dataOut.channelList.index(channel))
569 channelIndexList.append(dataOut.channelList.index(channel))
569
570
570 x = dataOut.heightList
571 x = dataOut.heightList
571 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
572 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
572 y = y.real
573 y = y.real
573
574
574 thisDatetime = dataOut.datatime
575 thisDatetime = dataOut.datatime
575 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
576 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
576 xlabel = "Range (Km)"
577 xlabel = "Range (Km)"
577 ylabel = "Intensity"
578 ylabel = "Intensity"
578
579
579 if not self.__isConfig:
580 if not self.__isConfig:
580 nplots = len(channelIndexList)
581 nplots = len(channelIndexList)
581
582
582 self.setup(idfigure=idfigure,
583 self.setup(idfigure=idfigure,
583 nplots=nplots,
584 nplots=nplots,
584 wintitle=wintitle,
585 wintitle=wintitle,
585 show=show)
586 show=show)
586
587
587 if xmin == None: xmin = numpy.nanmin(x)
588 if xmin == None: xmin = numpy.nanmin(x)
588 if xmax == None: xmax = numpy.nanmax(x)
589 if xmax == None: xmax = numpy.nanmax(x)
589 if ymin == None: ymin = numpy.nanmin(y)
590 if ymin == None: ymin = numpy.nanmin(y)
590 if ymax == None: ymax = numpy.nanmax(y)
591 if ymax == None: ymax = numpy.nanmax(y)
591
592
592 self.__isConfig = True
593 self.__isConfig = True
593
594
594 self.setWinTitle(title)
595 self.setWinTitle(title)
595
596
596 for i in range(len(self.axesList)):
597 for i in range(len(self.axesList)):
597 title = "Channel %d" %(i)
598 title = "Channel %d" %(i)
598 axes = self.axesList[i]
599 axes = self.axesList[i]
599 ychannel = y[i,:]
600 ychannel = y[i,:]
600 axes.pline(x, ychannel,
601 axes.pline(x, ychannel,
601 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
602 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
602 xlabel=xlabel, ylabel=ylabel, title=title)
603 xlabel=xlabel, ylabel=ylabel, title=title)
603
604
604 self.draw()
605 self.draw()
605
606
606 if save:
607 if save:
607 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
608 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
608 if figfile == None:
609 if figfile == None:
609 figfile = self.getFilename(name = date)
610 figfile = self.getFilename(name = date)
610
611
611 self.saveFigure(figpath, figfile)
612 self.saveFigure(figpath, figfile)
612
613
613 class PowerProfilePlot(Figure):
614 class PowerProfilePlot(Figure):
614 __isConfig = None
615 __isConfig = None
615 __nsubplots = None
616 __nsubplots = None
616
617
617 WIDTHPROF = None
618 WIDTHPROF = None
618 HEIGHTPROF = None
619 HEIGHTPROF = None
619 PREFIX = 'spcprofile'
620 PREFIX = 'spcprofile'
620
621
621 def __init__(self):
622 def __init__(self):
622 self.__isConfig = False
623 self.__isConfig = False
623 self.__nsubplots = 1
624 self.__nsubplots = 1
624
625
625 self.WIDTH = 300
626 self.WIDTH = 300
626 self.HEIGHT = 500
627 self.HEIGHT = 500
627
628
628 def getSubplots(self):
629 def getSubplots(self):
629 ncol = 1
630 ncol = 1
630 nrow = 1
631 nrow = 1
631
632
632 return nrow, ncol
633 return nrow, ncol
633
634
634 def setup(self, idfigure, nplots, wintitle, show):
635 def setup(self, idfigure, nplots, wintitle, show):
635
636
636 self.nplots = nplots
637 self.nplots = nplots
637
638
638 ncolspan = 1
639 ncolspan = 1
639 colspan = 1
640 colspan = 1
640
641
641 self.createFigure(idfigure = idfigure,
642 self.createFigure(idfigure = idfigure,
642 wintitle = wintitle,
643 wintitle = wintitle,
643 widthplot = self.WIDTH,
644 widthplot = self.WIDTH,
644 heightplot = self.HEIGHT,
645 heightplot = self.HEIGHT,
645 show=show)
646 show=show)
646
647
647 nrow, ncol = self.getSubplots()
648 nrow, ncol = self.getSubplots()
648
649
649 counter = 0
650 counter = 0
650 for y in range(nrow):
651 for y in range(nrow):
651 for x in range(ncol):
652 for x in range(ncol):
652 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
653 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
653
654
654 def run(self, dataOut, idfigure, wintitle="", channelList=None,
655 def run(self, dataOut, idfigure, wintitle="", channelList=None,
655 xmin=None, xmax=None, ymin=None, ymax=None,
656 xmin=None, xmax=None, ymin=None, ymax=None,
656 save=False, figpath='./', figfile=None, show=True):
657 save=False, figpath='./', figfile=None, show=True):
657
658
658 if channelList == None:
659 if channelList == None:
659 channelIndexList = dataOut.channelIndexList
660 channelIndexList = dataOut.channelIndexList
660 channelList = dataOut.channelList
661 channelList = dataOut.channelList
661 else:
662 else:
662 channelIndexList = []
663 channelIndexList = []
663 for channel in channelList:
664 for channel in channelList:
664 if channel not in dataOut.channelList:
665 if channel not in dataOut.channelList:
665 raise ValueError, "Channel %d is not in dataOut.channelList"
666 raise ValueError, "Channel %d is not in dataOut.channelList"
666 channelIndexList.append(dataOut.channelList.index(channel))
667 channelIndexList.append(dataOut.channelList.index(channel))
667
668
668 factor = dataOut.normFactor
669 factor = dataOut.normFactor
669 y = dataOut.getHeiRange()
670 y = dataOut.getHeiRange()
670 x = dataOut.data_spc[channelIndexList,:,:]/factor
671 x = dataOut.data_spc[channelIndexList,:,:]/factor
671 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
672 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
672 avg = numpy.average(x, axis=1)
673 avg = numpy.average(x, axis=1)
673
674
674 avgdB = 10*numpy.log10(avg)
675 avgdB = 10*numpy.log10(avg)
675
676
676 thisDatetime = dataOut.datatime
677 thisDatetime = dataOut.datatime
677 title = "Power Profile"
678 title = "Power Profile"
678 xlabel = "dB"
679 xlabel = "dB"
679 ylabel = "Range (Km)"
680 ylabel = "Range (Km)"
680
681
681 if not self.__isConfig:
682 if not self.__isConfig:
682
683
683 nplots = 1
684 nplots = 1
684
685
685 self.setup(idfigure=idfigure,
686 self.setup(idfigure=idfigure,
686 nplots=nplots,
687 nplots=nplots,
687 wintitle=wintitle,
688 wintitle=wintitle,
688 show=show)
689 show=show)
689
690
690 if ymin == None: ymin = numpy.nanmin(y)
691 if ymin == None: ymin = numpy.nanmin(y)
691 if ymax == None: ymax = numpy.nanmax(y)
692 if ymax == None: ymax = numpy.nanmax(y)
692 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
693 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
693 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
694 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
694
695
695 self.__isConfig = True
696 self.__isConfig = True
696
697
697 self.setWinTitle(title)
698 self.setWinTitle(title)
698
699
699
700
700 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
701 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
701 axes = self.axesList[0]
702 axes = self.axesList[0]
702
703
703 legendlabels = ["channel %d"%x for x in channelList]
704 legendlabels = ["channel %d"%x for x in channelList]
704 axes.pmultiline(avgdB, y,
705 axes.pmultiline(avgdB, y,
705 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
706 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
706 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
707 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
707 ytick_visible=True, nxticks=5,
708 ytick_visible=True, nxticks=5,
708 grid='x')
709 grid='x')
709
710
710 self.draw()
711 self.draw()
711
712
712 if save:
713 if save:
713 date = thisDatetime.strftime("%Y%m%d")
714 date = thisDatetime.strftime("%Y%m%d")
714 if figfile == None:
715 if figfile == None:
715 figfile = self.getFilename(name = date)
716 figfile = self.getFilename(name = date)
716
717
717 self.saveFigure(figpath, figfile)
718 self.saveFigure(figpath, figfile)
718
719
719 class CoherenceMap(Figure):
720 class CoherenceMap(Figure):
720 __isConfig = None
721 __isConfig = None
721 __nsubplots = None
722 __nsubplots = None
722
723
723 WIDTHPROF = None
724 WIDTHPROF = None
724 HEIGHTPROF = None
725 HEIGHTPROF = None
725 PREFIX = 'cmap'
726 PREFIX = 'cmap'
726
727
727 def __init__(self):
728 def __init__(self):
728 self.timerange = 2*60*60
729 self.timerange = 2*60*60
729 self.__isConfig = False
730 self.__isConfig = False
730 self.__nsubplots = 1
731 self.__nsubplots = 1
731
732
732 self.WIDTH = 800
733 self.WIDTH = 800
733 self.HEIGHT = 150
734 self.HEIGHT = 150
734 self.WIDTHPROF = 120
735 self.WIDTHPROF = 120
735 self.HEIGHTPROF = 0
736 self.HEIGHTPROF = 0
736 self.counterftp = 0
737 self.counterftp = 0
737
738
738 def getSubplots(self):
739 def getSubplots(self):
739 ncol = 1
740 ncol = 1
740 nrow = self.nplots*2
741 nrow = self.nplots*2
741
742
742 return nrow, ncol
743 return nrow, ncol
743
744
744 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
745 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
745 self.__showprofile = showprofile
746 self.__showprofile = showprofile
746 self.nplots = nplots
747 self.nplots = nplots
747
748
748 ncolspan = 1
749 ncolspan = 1
749 colspan = 1
750 colspan = 1
750 if showprofile:
751 if showprofile:
751 ncolspan = 7
752 ncolspan = 7
752 colspan = 6
753 colspan = 6
753 self.__nsubplots = 2
754 self.__nsubplots = 2
754
755
755 self.createFigure(idfigure = idfigure,
756 self.createFigure(idfigure = idfigure,
756 wintitle = wintitle,
757 wintitle = wintitle,
757 widthplot = self.WIDTH + self.WIDTHPROF,
758 widthplot = self.WIDTH + self.WIDTHPROF,
758 heightplot = self.HEIGHT + self.HEIGHTPROF,
759 heightplot = self.HEIGHT + self.HEIGHTPROF,
759 show=True)
760 show=True)
760
761
761 nrow, ncol = self.getSubplots()
762 nrow, ncol = self.getSubplots()
762
763
763 for y in range(nrow):
764 for y in range(nrow):
764 for x in range(ncol):
765 for x in range(ncol):
765
766
766 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
767 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
767
768
768 if showprofile:
769 if showprofile:
769 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
770 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
770
771
771 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
772 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
772 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
773 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
773 timerange=None,
774 timerange=None,
774 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
775 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
775 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
776 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
776
777
777 if pairsList == None:
778 if pairsList == None:
778 pairsIndexList = dataOut.pairsIndexList
779 pairsIndexList = dataOut.pairsIndexList
779 else:
780 else:
780 pairsIndexList = []
781 pairsIndexList = []
781 for pair in pairsList:
782 for pair in pairsList:
782 if pair not in dataOut.pairsList:
783 if pair not in dataOut.pairsList:
783 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
784 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
784 pairsIndexList.append(dataOut.pairsList.index(pair))
785 pairsIndexList.append(dataOut.pairsList.index(pair))
785
786
786 if timerange != None:
787 if timerange != None:
787 self.timerange = timerange
788 self.timerange = timerange
788
789
789 if pairsIndexList == []:
790 if pairsIndexList == []:
790 return
791 return
791
792
792 if len(pairsIndexList) > 4:
793 if len(pairsIndexList) > 4:
793 pairsIndexList = pairsIndexList[0:4]
794 pairsIndexList = pairsIndexList[0:4]
794
795
795 tmin = None
796 tmin = None
796 tmax = None
797 tmax = None
797 x = dataOut.getTimeRange()
798 x = dataOut.getTimeRange()
798 y = dataOut.getHeiRange()
799 y = dataOut.getHeiRange()
799
800
800 thisDatetime = dataOut.datatime
801 thisDatetime = dataOut.datatime
801 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
802 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
802 xlabel = ""
803 xlabel = ""
803 ylabel = "Range (Km)"
804 ylabel = "Range (Km)"
804
805
805 if not self.__isConfig:
806 if not self.__isConfig:
806 nplots = len(pairsIndexList)
807 nplots = len(pairsIndexList)
807 self.setup(idfigure=idfigure,
808 self.setup(idfigure=idfigure,
808 nplots=nplots,
809 nplots=nplots,
809 wintitle=wintitle,
810 wintitle=wintitle,
810 showprofile=showprofile,
811 showprofile=showprofile,
811 show=show)
812 show=show)
812
813
813 tmin, tmax = self.getTimeLim(x, xmin, xmax)
814 tmin, tmax = self.getTimeLim(x, xmin, xmax)
814 if ymin == None: ymin = numpy.nanmin(y)
815 if ymin == None: ymin = numpy.nanmin(y)
815 if ymax == None: ymax = numpy.nanmax(y)
816 if ymax == None: ymax = numpy.nanmax(y)
816
817
817 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
818 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
818
819
819 self.__isConfig = True
820 self.__isConfig = True
820
821
821 self.setWinTitle(title)
822 self.setWinTitle(title)
822
823
823 for i in range(self.nplots):
824 for i in range(self.nplots):
824
825
825 pair = dataOut.pairsList[pairsIndexList[i]]
826 pair = dataOut.pairsList[pairsIndexList[i]]
826 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
827 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
827 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
828 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
828 coherence = numpy.abs(avgcoherenceComplex)
829 coherence = numpy.abs(avgcoherenceComplex)
829 # coherence = numpy.abs(coherenceComplex)
830 # coherence = numpy.abs(coherenceComplex)
830 # avg = numpy.average(coherence, axis=0)
831 # avg = numpy.average(coherence, axis=0)
831
832
832 z = coherence.reshape((1,-1))
833 z = coherence.reshape((1,-1))
833
834
834 counter = 0
835 counter = 0
835
836
836 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
837 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
837 axes = self.axesList[i*self.__nsubplots*2]
838 axes = self.axesList[i*self.__nsubplots*2]
838 axes.pcolorbuffer(x, y, z,
839 axes.pcolorbuffer(x, y, z,
839 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
840 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
840 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
841 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
841 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
842 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
842
843
843 if self.__showprofile:
844 if self.__showprofile:
844 counter += 1
845 counter += 1
845 axes = self.axesList[i*self.__nsubplots*2 + counter]
846 axes = self.axesList[i*self.__nsubplots*2 + counter]
846 axes.pline(coherence, y,
847 axes.pline(coherence, y,
847 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
848 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
848 xlabel='', ylabel='', title='', ticksize=7,
849 xlabel='', ylabel='', title='', ticksize=7,
849 ytick_visible=False, nxticks=5,
850 ytick_visible=False, nxticks=5,
850 grid='x')
851 grid='x')
851
852
852 counter += 1
853 counter += 1
853 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
854 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
854 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
855 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
855 # avg = numpy.average(phase, axis=0)
856 # avg = numpy.average(phase, axis=0)
856 z = phase.reshape((1,-1))
857 z = phase.reshape((1,-1))
857
858
858 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
859 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
859 axes = self.axesList[i*self.__nsubplots*2 + counter]
860 axes = self.axesList[i*self.__nsubplots*2 + counter]
860 axes.pcolorbuffer(x, y, z,
861 axes.pcolorbuffer(x, y, z,
861 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
862 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
862 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
863 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
863 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
864 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
864
865
865 if self.__showprofile:
866 if self.__showprofile:
866 counter += 1
867 counter += 1
867 axes = self.axesList[i*self.__nsubplots*2 + counter]
868 axes = self.axesList[i*self.__nsubplots*2 + counter]
868 axes.pline(phase, y,
869 axes.pline(phase, y,
869 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
870 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
870 xlabel='', ylabel='', title='', ticksize=7,
871 xlabel='', ylabel='', title='', ticksize=7,
871 ytick_visible=False, nxticks=4,
872 ytick_visible=False, nxticks=4,
872 grid='x')
873 grid='x')
873
874
874 self.draw()
875 self.draw()
875
876
876 if save:
877 if save:
877
878
878 if figfile == None:
879 if figfile == None:
879 figfile = self.getFilename(name = self.name)
880 figfile = self.getFilename(name = self.name)
880
881
881 self.saveFigure(figpath, figfile)
882 self.saveFigure(figpath, figfile)
882
883
883 self.counterftp += 1
884 self.counterftp += 1
884 if (ftp and (self.counterftp==ftpratio)):
885 if (ftp and (self.counterftp==ftpratio)):
885 figfilename = os.path.join(figpath,figfile)
886 figfilename = os.path.join(figpath,figfile)
886 self.sendByFTP(figfilename)
887 self.sendByFTP(figfilename)
887 self.counterftp = 0
888 self.counterftp = 0
888
889
889 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
890 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
890 self.__isConfig = False
891 self.__isConfig = False
891
892
892 class RTIfromNoise(Figure):
893 class RTIfromNoise(Figure):
893
894
894 __isConfig = None
895 __isConfig = None
895 __nsubplots = None
896 __nsubplots = None
896
897
897 PREFIX = 'rtinoise'
898 PREFIX = 'rtinoise'
898
899
899 def __init__(self):
900 def __init__(self):
900
901
901 self.timerange = 24*60*60
902 self.timerange = 24*60*60
902 self.__isConfig = False
903 self.__isConfig = False
903 self.__nsubplots = 1
904 self.__nsubplots = 1
904
905
905 self.WIDTH = 820
906 self.WIDTH = 820
906 self.HEIGHT = 200
907 self.HEIGHT = 200
907 self.WIDTHPROF = 120
908 self.WIDTHPROF = 120
908 self.HEIGHTPROF = 0
909 self.HEIGHTPROF = 0
909 self.xdata = None
910 self.xdata = None
910 self.ydata = None
911 self.ydata = None
911
912
912 def getSubplots(self):
913 def getSubplots(self):
913
914
914 ncol = 1
915 ncol = 1
915 nrow = 1
916 nrow = 1
916
917
917 return nrow, ncol
918 return nrow, ncol
918
919
919 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
920 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
920
921
921 self.__showprofile = showprofile
922 self.__showprofile = showprofile
922 self.nplots = nplots
923 self.nplots = nplots
923
924
924 ncolspan = 7
925 ncolspan = 7
925 colspan = 6
926 colspan = 6
926 self.__nsubplots = 2
927 self.__nsubplots = 2
927
928
928 self.createFigure(idfigure = idfigure,
929 self.createFigure(idfigure = idfigure,
929 wintitle = wintitle,
930 wintitle = wintitle,
930 widthplot = self.WIDTH+self.WIDTHPROF,
931 widthplot = self.WIDTH+self.WIDTHPROF,
931 heightplot = self.HEIGHT+self.HEIGHTPROF,
932 heightplot = self.HEIGHT+self.HEIGHTPROF,
932 show=show)
933 show=show)
933
934
934 nrow, ncol = self.getSubplots()
935 nrow, ncol = self.getSubplots()
935
936
936 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
937 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
937
938
938
939
939 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
940 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
940 xmin=None, xmax=None, ymin=None, ymax=None,
941 xmin=None, xmax=None, ymin=None, ymax=None,
941 timerange=None,
942 timerange=None,
942 save=False, figpath='./', figfile=None, show=True):
943 save=False, figpath='./', figfile=None, show=True):
943
944
944 if channelList == None:
945 if channelList == None:
945 channelIndexList = dataOut.channelIndexList
946 channelIndexList = dataOut.channelIndexList
946 channelList = dataOut.channelList
947 channelList = dataOut.channelList
947 else:
948 else:
948 channelIndexList = []
949 channelIndexList = []
949 for channel in channelList:
950 for channel in channelList:
950 if channel not in dataOut.channelList:
951 if channel not in dataOut.channelList:
951 raise ValueError, "Channel %d is not in dataOut.channelList"
952 raise ValueError, "Channel %d is not in dataOut.channelList"
952 channelIndexList.append(dataOut.channelList.index(channel))
953 channelIndexList.append(dataOut.channelList.index(channel))
953
954
954 if timerange != None:
955 if timerange != None:
955 self.timerange = timerange
956 self.timerange = timerange
956
957
957 tmin = None
958 tmin = None
958 tmax = None
959 tmax = None
959 x = dataOut.getTimeRange()
960 x = dataOut.getTimeRange()
960 y = dataOut.getHeiRange()
961 y = dataOut.getHeiRange()
961 factor = dataOut.normFactor
962 factor = dataOut.normFactor
962 noise = dataOut.getNoise()/factor
963 noise = dataOut.getNoise()/factor
963 noisedB = 10*numpy.log10(noise)
964 noisedB = 10*numpy.log10(noise)
964
965
965 thisDatetime = dataOut.datatime
966 thisDatetime = dataOut.datatime
966 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
967 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
967 xlabel = ""
968 xlabel = ""
968 ylabel = "Range (Km)"
969 ylabel = "Range (Km)"
969
970
970 if not self.__isConfig:
971 if not self.__isConfig:
971
972
972 nplots = 1
973 nplots = 1
973
974
974 self.setup(idfigure=idfigure,
975 self.setup(idfigure=idfigure,
975 nplots=nplots,
976 nplots=nplots,
976 wintitle=wintitle,
977 wintitle=wintitle,
977 showprofile=showprofile,
978 showprofile=showprofile,
978 show=show)
979 show=show)
979
980
980 tmin, tmax = self.getTimeLim(x, xmin, xmax)
981 tmin, tmax = self.getTimeLim(x, xmin, xmax)
981 if ymin == None: ymin = numpy.nanmin(noisedB)
982 if ymin == None: ymin = numpy.nanmin(noisedB)
982 if ymax == None: ymax = numpy.nanmax(noisedB)
983 if ymax == None: ymax = numpy.nanmax(noisedB)
983
984
984 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
985 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
985 self.__isConfig = True
986 self.__isConfig = True
986
987
987 self.xdata = numpy.array([])
988 self.xdata = numpy.array([])
988 self.ydata = numpy.array([])
989 self.ydata = numpy.array([])
989
990
990 self.setWinTitle(title)
991 self.setWinTitle(title)
991
992
992
993
993 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
994 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
994
995
995 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
996 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
996 axes = self.axesList[0]
997 axes = self.axesList[0]
997
998
998 self.xdata = numpy.hstack((self.xdata, x[0:1]))
999 self.xdata = numpy.hstack((self.xdata, x[0:1]))
999
1000
1000 if len(self.ydata)==0:
1001 if len(self.ydata)==0:
1001 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1002 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1002 else:
1003 else:
1003 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1004 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1004
1005
1005
1006
1006 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1007 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1007 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1008 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1008 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1009 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1009 XAxisAsTime=True
1010 XAxisAsTime=True
1010 )
1011 )
1011
1012
1012 self.draw()
1013 self.draw()
1013
1014
1014 if save:
1015 if save:
1015
1016
1016 if figfile == None:
1017 if figfile == None:
1017 figfile = self.getFilename(name = self.name)
1018 figfile = self.getFilename(name = self.name)
1018
1019
1019 self.saveFigure(figpath, figfile)
1020 self.saveFigure(figpath, figfile)
1020
1021
1021 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1022 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1022 self.__isConfig = False
1023 self.__isConfig = False
1023 del self.xdata
1024 del self.xdata
1024 del self.ydata
1025 del self.ydata
1025
1026
1026
1027
1027 class SpectraHeisScope(Figure):
1028 class SpectraHeisScope(Figure):
1028
1029
1029
1030
1030 __isConfig = None
1031 __isConfig = None
1031 __nsubplots = None
1032 __nsubplots = None
1032
1033
1033 WIDTHPROF = None
1034 WIDTHPROF = None
1034 HEIGHTPROF = None
1035 HEIGHTPROF = None
1035 PREFIX = 'spc'
1036 PREFIX = 'spc'
1036
1037
1037 def __init__(self):
1038 def __init__(self):
1038
1039
1039 self.__isConfig = False
1040 self.__isConfig = False
1040 self.__nsubplots = 1
1041 self.__nsubplots = 1
1041
1042
1042 self.WIDTH = 230
1043 self.WIDTH = 230
1043 self.HEIGHT = 250
1044 self.HEIGHT = 250
1044 self.WIDTHPROF = 120
1045 self.WIDTHPROF = 120
1045 self.HEIGHTPROF = 0
1046 self.HEIGHTPROF = 0
1046 self.counterftp = 0
1047 self.counterftp = 0
1047
1048
1048 def getSubplots(self):
1049 def getSubplots(self):
1049
1050
1050 ncol = int(numpy.sqrt(self.nplots)+0.9)
1051 ncol = int(numpy.sqrt(self.nplots)+0.9)
1051 nrow = int(self.nplots*1./ncol + 0.9)
1052 nrow = int(self.nplots*1./ncol + 0.9)
1052
1053
1053 return nrow, ncol
1054 return nrow, ncol
1054
1055
1055 def setup(self, idfigure, nplots, wintitle, show):
1056 def setup(self, idfigure, nplots, wintitle, show):
1056
1057
1057 showprofile = False
1058 showprofile = False
1058 self.__showprofile = showprofile
1059 self.__showprofile = showprofile
1059 self.nplots = nplots
1060 self.nplots = nplots
1060
1061
1061 ncolspan = 1
1062 ncolspan = 1
1062 colspan = 1
1063 colspan = 1
1063 if showprofile:
1064 if showprofile:
1064 ncolspan = 3
1065 ncolspan = 3
1065 colspan = 2
1066 colspan = 2
1066 self.__nsubplots = 2
1067 self.__nsubplots = 2
1067
1068
1068 self.createFigure(idfigure = idfigure,
1069 self.createFigure(idfigure = idfigure,
1069 wintitle = wintitle,
1070 wintitle = wintitle,
1070 widthplot = self.WIDTH + self.WIDTHPROF,
1071 widthplot = self.WIDTH + self.WIDTHPROF,
1071 heightplot = self.HEIGHT + self.HEIGHTPROF,
1072 heightplot = self.HEIGHT + self.HEIGHTPROF,
1072 show = show)
1073 show = show)
1073
1074
1074 nrow, ncol = self.getSubplots()
1075 nrow, ncol = self.getSubplots()
1075
1076
1076 counter = 0
1077 counter = 0
1077 for y in range(nrow):
1078 for y in range(nrow):
1078 for x in range(ncol):
1079 for x in range(ncol):
1079
1080
1080 if counter >= self.nplots:
1081 if counter >= self.nplots:
1081 break
1082 break
1082
1083
1083 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1084 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1084
1085
1085 if showprofile:
1086 if showprofile:
1086 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1087 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1087
1088
1088 counter += 1
1089 counter += 1
1089
1090
1090 # __isConfig = None
1091 # __isConfig = None
1091 # def __init__(self):
1092 # def __init__(self):
1092 #
1093 #
1093 # self.__isConfig = False
1094 # self.__isConfig = False
1094 # self.WIDTH = 600
1095 # self.WIDTH = 600
1095 # self.HEIGHT = 200
1096 # self.HEIGHT = 200
1096 #
1097 #
1097 # def getSubplots(self):
1098 # def getSubplots(self):
1098 #
1099 #
1099 # nrow = self.nplots
1100 # nrow = self.nplots
1100 # ncol = 3
1101 # ncol = 3
1101 # return nrow, ncol
1102 # return nrow, ncol
1102 #
1103 #
1103 # def setup(self, idfigure, nplots, wintitle):
1104 # def setup(self, idfigure, nplots, wintitle):
1104 #
1105 #
1105 # self.nplots = nplots
1106 # self.nplots = nplots
1106 #
1107 #
1107 # self.createFigure(idfigure, wintitle)
1108 # self.createFigure(idfigure, wintitle)
1108 #
1109 #
1109 # nrow,ncol = self.getSubplots()
1110 # nrow,ncol = self.getSubplots()
1110 # colspan = 3
1111 # colspan = 3
1111 # rowspan = 1
1112 # rowspan = 1
1112 #
1113 #
1113 # for i in range(nplots):
1114 # for i in range(nplots):
1114 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1115 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1115
1116
1116 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1117 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1117 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1118 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1118 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1119 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1119
1120
1120 """
1121 """
1121
1122
1122 Input:
1123 Input:
1123 dataOut :
1124 dataOut :
1124 idfigure :
1125 idfigure :
1125 wintitle :
1126 wintitle :
1126 channelList :
1127 channelList :
1127 xmin : None,
1128 xmin : None,
1128 xmax : None,
1129 xmax : None,
1129 ymin : None,
1130 ymin : None,
1130 ymax : None,
1131 ymax : None,
1131 """
1132 """
1132
1133
1133 if dataOut.realtime:
1134 if dataOut.realtime:
1134 if not(isRealtime(utcdatatime = dataOut.utctime)):
1135 if not(isRealtime(utcdatatime = dataOut.utctime)):
1135 print 'Skipping this plot function'
1136 print 'Skipping this plot function'
1136 return
1137 return
1137
1138
1138 if channelList == None:
1139 if channelList == None:
1139 channelIndexList = dataOut.channelIndexList
1140 channelIndexList = dataOut.channelIndexList
1140 else:
1141 else:
1141 channelIndexList = []
1142 channelIndexList = []
1142 for channel in channelList:
1143 for channel in channelList:
1143 if channel not in dataOut.channelList:
1144 if channel not in dataOut.channelList:
1144 raise ValueError, "Channel %d is not in dataOut.channelList"
1145 raise ValueError, "Channel %d is not in dataOut.channelList"
1145 channelIndexList.append(dataOut.channelList.index(channel))
1146 channelIndexList.append(dataOut.channelList.index(channel))
1146
1147
1147 # x = dataOut.heightList
1148 # x = dataOut.heightList
1148 c = 3E8
1149 c = 3E8
1149 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1150 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1150 #deberia cambiar para el caso de 1Mhz y 100KHz
1151 #deberia cambiar para el caso de 1Mhz y 100KHz
1151 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1152 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1152 x= x/(10000.0)
1153 x= x/(10000.0)
1153 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1154 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1154 # y = y.real
1155 # y = y.real
1155 datadB = 10.*numpy.log10(dataOut.data_spc)
1156 datadB = 10.*numpy.log10(dataOut.data_spc)
1156 y = datadB
1157 y = datadB
1157
1158
1158 thisDatetime = dataOut.datatime
1159 thisDatetime = dataOut.datatime
1159 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1160 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1160 xlabel = "Frequency x 10000"
1161 xlabel = "Frequency x 10000"
1161 ylabel = "Intensity (dB)"
1162 ylabel = "Intensity (dB)"
1162
1163
1163 if not self.__isConfig:
1164 if not self.__isConfig:
1164 nplots = len(channelIndexList)
1165 nplots = len(channelIndexList)
1165
1166
1166 self.setup(idfigure=idfigure,
1167 self.setup(idfigure=idfigure,
1167 nplots=nplots,
1168 nplots=nplots,
1168 wintitle=wintitle,
1169 wintitle=wintitle,
1169 show=show)
1170 show=show)
1170
1171
1171 if xmin == None: xmin = numpy.nanmin(x)
1172 if xmin == None: xmin = numpy.nanmin(x)
1172 if xmax == None: xmax = numpy.nanmax(x)
1173 if xmax == None: xmax = numpy.nanmax(x)
1173 if ymin == None: ymin = numpy.nanmin(y)
1174 if ymin == None: ymin = numpy.nanmin(y)
1174 if ymax == None: ymax = numpy.nanmax(y)
1175 if ymax == None: ymax = numpy.nanmax(y)
1175
1176
1176 self.__isConfig = True
1177 self.__isConfig = True
1177
1178
1178 self.setWinTitle(title)
1179 self.setWinTitle(title)
1179
1180
1180 for i in range(len(self.axesList)):
1181 for i in range(len(self.axesList)):
1181 ychannel = y[i,:]
1182 ychannel = y[i,:]
1182 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1183 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1183 axes = self.axesList[i]
1184 axes = self.axesList[i]
1184 axes.pline(x, ychannel,
1185 axes.pline(x, ychannel,
1185 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1186 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1186 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1187 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1187
1188
1188
1189
1189 self.draw()
1190 self.draw()
1190
1191
1191 if save:
1192 if save:
1192 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1193 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1193 if figfile == None:
1194 if figfile == None:
1194 figfile = self.getFilename(name = date)
1195 figfile = self.getFilename(name = date)
1195
1196
1196 self.saveFigure(figpath, figfile)
1197 self.saveFigure(figpath, figfile)
1197
1198
1198 self.counterftp += 1
1199 self.counterftp += 1
1199 if (ftp and (self.counterftp==ftpratio)):
1200 if (ftp and (self.counterftp==ftpratio)):
1200 figfilename = os.path.join(figpath,figfile)
1201 figfilename = os.path.join(figpath,figfile)
1201 self.sendByFTP(figfilename)
1202 self.sendByFTP(figfilename)
1202 self.counterftp = 0
1203 self.counterftp = 0
1203
1204
1204
1205
1205 class RTIfromSpectraHeis(Figure):
1206 class RTIfromSpectraHeis(Figure):
1206
1207
1207 __isConfig = None
1208 __isConfig = None
1208 __nsubplots = None
1209 __nsubplots = None
1209
1210
1210 PREFIX = 'rtinoise'
1211 PREFIX = 'rtinoise'
1211
1212
1212 def __init__(self):
1213 def __init__(self):
1213
1214
1214 self.timerange = 24*60*60
1215 self.timerange = 24*60*60
1215 self.__isConfig = False
1216 self.__isConfig = False
1216 self.__nsubplots = 1
1217 self.__nsubplots = 1
1217
1218
1218 self.WIDTH = 820
1219 self.WIDTH = 820
1219 self.HEIGHT = 200
1220 self.HEIGHT = 200
1220 self.WIDTHPROF = 120
1221 self.WIDTHPROF = 120
1221 self.HEIGHTPROF = 0
1222 self.HEIGHTPROF = 0
1222 self.counterftp = 0
1223 self.counterftp = 0
1223 self.xdata = None
1224 self.xdata = None
1224 self.ydata = None
1225 self.ydata = None
1225
1226
1226 def getSubplots(self):
1227 def getSubplots(self):
1227
1228
1228 ncol = 1
1229 ncol = 1
1229 nrow = 1
1230 nrow = 1
1230
1231
1231 return nrow, ncol
1232 return nrow, ncol
1232
1233
1233 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1234 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1234
1235
1235 self.__showprofile = showprofile
1236 self.__showprofile = showprofile
1236 self.nplots = nplots
1237 self.nplots = nplots
1237
1238
1238 ncolspan = 7
1239 ncolspan = 7
1239 colspan = 6
1240 colspan = 6
1240 self.__nsubplots = 2
1241 self.__nsubplots = 2
1241
1242
1242 self.createFigure(idfigure = idfigure,
1243 self.createFigure(idfigure = idfigure,
1243 wintitle = wintitle,
1244 wintitle = wintitle,
1244 widthplot = self.WIDTH+self.WIDTHPROF,
1245 widthplot = self.WIDTH+self.WIDTHPROF,
1245 heightplot = self.HEIGHT+self.HEIGHTPROF,
1246 heightplot = self.HEIGHT+self.HEIGHTPROF,
1246 show = show)
1247 show = show)
1247
1248
1248 nrow, ncol = self.getSubplots()
1249 nrow, ncol = self.getSubplots()
1249
1250
1250 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1251 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1251
1252
1252
1253
1253 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1254 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1254 xmin=None, xmax=None, ymin=None, ymax=None,
1255 xmin=None, xmax=None, ymin=None, ymax=None,
1255 timerange=None,
1256 timerange=None,
1256 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1257 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1257
1258
1258 if channelList == None:
1259 if channelList == None:
1259 channelIndexList = dataOut.channelIndexList
1260 channelIndexList = dataOut.channelIndexList
1260 channelList = dataOut.channelList
1261 channelList = dataOut.channelList
1261 else:
1262 else:
1262 channelIndexList = []
1263 channelIndexList = []
1263 for channel in channelList:
1264 for channel in channelList:
1264 if channel not in dataOut.channelList:
1265 if channel not in dataOut.channelList:
1265 raise ValueError, "Channel %d is not in dataOut.channelList"
1266 raise ValueError, "Channel %d is not in dataOut.channelList"
1266 channelIndexList.append(dataOut.channelList.index(channel))
1267 channelIndexList.append(dataOut.channelList.index(channel))
1267
1268
1268 if timerange != None:
1269 if timerange != None:
1269 self.timerange = timerange
1270 self.timerange = timerange
1270
1271
1271 tmin = None
1272 tmin = None
1272 tmax = None
1273 tmax = None
1273 x = dataOut.getTimeRange()
1274 x = dataOut.getTimeRange()
1274 y = dataOut.getHeiRange()
1275 y = dataOut.getHeiRange()
1275
1276
1276 factor = 1
1277 factor = 1
1277 data = dataOut.data_spc/factor
1278 data = dataOut.data_spc/factor
1278 data = numpy.average(data,axis=1)
1279 data = numpy.average(data,axis=1)
1279 datadB = 10*numpy.log10(data)
1280 datadB = 10*numpy.log10(data)
1280
1281
1281 # factor = dataOut.normFactor
1282 # factor = dataOut.normFactor
1282 # noise = dataOut.getNoise()/factor
1283 # noise = dataOut.getNoise()/factor
1283 # noisedB = 10*numpy.log10(noise)
1284 # noisedB = 10*numpy.log10(noise)
1284
1285
1285 thisDatetime = dataOut.datatime
1286 thisDatetime = dataOut.datatime
1286 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1287 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1287 xlabel = "Local Time"
1288 xlabel = "Local Time"
1288 ylabel = "Intensity (dB)"
1289 ylabel = "Intensity (dB)"
1289
1290
1290 if not self.__isConfig:
1291 if not self.__isConfig:
1291
1292
1292 nplots = 1
1293 nplots = 1
1293
1294
1294 self.setup(idfigure=idfigure,
1295 self.setup(idfigure=idfigure,
1295 nplots=nplots,
1296 nplots=nplots,
1296 wintitle=wintitle,
1297 wintitle=wintitle,
1297 showprofile=showprofile,
1298 showprofile=showprofile,
1298 show=show)
1299 show=show)
1299
1300
1300 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1301 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1301 if ymin == None: ymin = numpy.nanmin(datadB)
1302 if ymin == None: ymin = numpy.nanmin(datadB)
1302 if ymax == None: ymax = numpy.nanmax(datadB)
1303 if ymax == None: ymax = numpy.nanmax(datadB)
1303
1304
1304 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1305 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1305 self.__isConfig = True
1306 self.__isConfig = True
1306
1307
1307 self.xdata = numpy.array([])
1308 self.xdata = numpy.array([])
1308 self.ydata = numpy.array([])
1309 self.ydata = numpy.array([])
1309
1310
1310 self.setWinTitle(title)
1311 self.setWinTitle(title)
1311
1312
1312
1313
1313 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1314 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1314 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1315 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1315
1316
1316 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1317 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1317 axes = self.axesList[0]
1318 axes = self.axesList[0]
1318
1319
1319 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1320 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1320
1321
1321 if len(self.ydata)==0:
1322 if len(self.ydata)==0:
1322 self.ydata = datadB[channelIndexList].reshape(-1,1)
1323 self.ydata = datadB[channelIndexList].reshape(-1,1)
1323 else:
1324 else:
1324 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1325 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1325
1326
1326
1327
1327 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1328 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1328 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1329 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1329 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1330 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1330 XAxisAsTime=True
1331 XAxisAsTime=True
1331 )
1332 )
1332
1333
1333 self.draw()
1334 self.draw()
1334
1335
1335 if save:
1336 if save:
1336
1337
1337 if figfile == None:
1338 if figfile == None:
1338 figfile = self.getFilename(name = self.name)
1339 figfile = self.getFilename(name = self.name)
1339
1340
1340 self.saveFigure(figpath, figfile)
1341 self.saveFigure(figpath, figfile)
1341
1342
1342 self.counterftp += 1
1343 self.counterftp += 1
1343 if (ftp and (self.counterftp==ftpratio)):
1344 if (ftp and (self.counterftp==ftpratio)):
1344 figfilename = os.path.join(figpath,figfile)
1345 figfilename = os.path.join(figpath,figfile)
1345 self.sendByFTP(figfilename)
1346 self.sendByFTP(figfilename)
1346 self.counterftp = 0
1347 self.counterftp = 0
1347
1348
1348 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1349 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1349 self.__isConfig = False
1350 self.__isConfig = False
1350 del self.xdata
1351 del self.xdata
1351 del self.ydata
1352 del self.ydata
1352
1353
1353
1354
1354 No newline at end of file
1355
@@ -1,1632 +1,1635
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 try:
15 try:
16 import cfunctions
16 import cfunctions
17 except:
17 except:
18 pass
18 pass
19
19
20 class ProcessingUnit:
20 class ProcessingUnit:
21
21
22 """
22 """
23 Esta es la clase base para el procesamiento de datos.
23 Esta es la clase base para el procesamiento de datos.
24
24
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
26 - Metodos internos (callMethod)
26 - Metodos internos (callMethod)
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
28 tienen que ser agreagados con el metodo "add".
28 tienen que ser agreagados con el metodo "add".
29
29
30 """
30 """
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
32 dataIn = None
32 dataIn = None
33
33
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
35 dataOut = None
35 dataOut = None
36
36
37
37
38 objectDict = None
38 objectDict = None
39
39
40 def __init__(self):
40 def __init__(self):
41
41
42 self.objectDict = {}
42 self.objectDict = {}
43
43
44 def init(self):
44 def init(self):
45
45
46 raise ValueError, "Not implemented"
46 raise ValueError, "Not implemented"
47
47
48 def addOperation(self, object, objId):
48 def addOperation(self, object, objId):
49
49
50 """
50 """
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
52 identificador asociado a este objeto.
52 identificador asociado a este objeto.
53
53
54 Input:
54 Input:
55
55
56 object : objeto de la clase "Operation"
56 object : objeto de la clase "Operation"
57
57
58 Return:
58 Return:
59
59
60 objId : identificador del objeto, necesario para ejecutar la operacion
60 objId : identificador del objeto, necesario para ejecutar la operacion
61 """
61 """
62
62
63 self.objectDict[objId] = object
63 self.objectDict[objId] = object
64
64
65 return objId
65 return objId
66
66
67 def operation(self, **kwargs):
67 def operation(self, **kwargs):
68
68
69 """
69 """
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 atributos del objeto dataOut
71 atributos del objeto dataOut
72
72
73 Input:
73 Input:
74
74
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 """
76 """
77
77
78 raise ValueError, "ImplementedError"
78 raise ValueError, "ImplementedError"
79
79
80 def callMethod(self, name, **kwargs):
80 def callMethod(self, name, **kwargs):
81
81
82 """
82 """
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84
84
85 Input:
85 Input:
86 name : nombre del metodo a ejecutar
86 name : nombre del metodo a ejecutar
87
87
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89
89
90 """
90 """
91 if name != 'run':
91 if name != 'run':
92
92
93 if name == 'init' and self.dataIn.isEmpty():
93 if name == 'init' and self.dataIn.isEmpty():
94 self.dataOut.flagNoData = True
94 self.dataOut.flagNoData = True
95 return False
95 return False
96
96
97 if name != 'init' and self.dataOut.isEmpty():
97 if name != 'init' and self.dataOut.isEmpty():
98 return False
98 return False
99
99
100 methodToCall = getattr(self, name)
100 methodToCall = getattr(self, name)
101
101
102 methodToCall(**kwargs)
102 methodToCall(**kwargs)
103
103
104 if name != 'run':
104 if name != 'run':
105 return True
105 return True
106
106
107 if self.dataOut.isEmpty():
107 if self.dataOut.isEmpty():
108 return False
108 return False
109
109
110 return True
110 return True
111
111
112 def callObject(self, objId, **kwargs):
112 def callObject(self, objId, **kwargs):
113
113
114 """
114 """
115 Ejecuta la operacion asociada al identificador del objeto "objId"
115 Ejecuta la operacion asociada al identificador del objeto "objId"
116
116
117 Input:
117 Input:
118
118
119 objId : identificador del objeto a ejecutar
119 objId : identificador del objeto a ejecutar
120
120
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
122
122
123 Return:
123 Return:
124
124
125 None
125 None
126 """
126 """
127
127
128 if self.dataOut.isEmpty():
128 if self.dataOut.isEmpty():
129 return False
129 return False
130
130
131 object = self.objectDict[objId]
131 object = self.objectDict[objId]
132
132
133 object.run(self.dataOut, **kwargs)
133 object.run(self.dataOut, **kwargs)
134
134
135 return True
135 return True
136
136
137 def call(self, operationConf, **kwargs):
137 def call(self, operationConf, **kwargs):
138
138
139 """
139 """
140 Return True si ejecuta la operacion "operationConf.name" con los
140 Return True si ejecuta la operacion "operationConf.name" con los
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
142 La operacion puede ser de dos tipos:
142 La operacion puede ser de dos tipos:
143
143
144 1. Un metodo propio de esta clase:
144 1. Un metodo propio de esta clase:
145
145
146 operation.type = "self"
146 operation.type = "self"
147
147
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
149 operation.type = "other".
149 operation.type = "other".
150
150
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
152 "addOperation" e identificado con el operation.id
152 "addOperation" e identificado con el operation.id
153
153
154
154
155 con el id de la operacion.
155 con el id de la operacion.
156
156
157 Input:
157 Input:
158
158
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
160
160
161 """
161 """
162
162
163 if operationConf.type == 'self':
163 if operationConf.type == 'self':
164 sts = self.callMethod(operationConf.name, **kwargs)
164 sts = self.callMethod(operationConf.name, **kwargs)
165
165
166 if operationConf.type == 'other':
166 if operationConf.type == 'other':
167 sts = self.callObject(operationConf.id, **kwargs)
167 sts = self.callObject(operationConf.id, **kwargs)
168
168
169 return sts
169 return sts
170
170
171 def setInput(self, dataIn):
171 def setInput(self, dataIn):
172
172
173 self.dataIn = dataIn
173 self.dataIn = dataIn
174
174
175 def getOutput(self):
175 def getOutput(self):
176
176
177 return self.dataOut
177 return self.dataOut
178
178
179 class Operation():
179 class Operation():
180
180
181 """
181 """
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
184 acumulacion dentro de esta clase
184 acumulacion dentro de esta clase
185
185
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
187
187
188 """
188 """
189
189
190 __buffer = None
190 __buffer = None
191 __isConfig = False
191 __isConfig = False
192
192
193 def __init__(self):
193 def __init__(self):
194
194
195 pass
195 pass
196
196
197 def run(self, dataIn, **kwargs):
197 def run(self, dataIn, **kwargs):
198
198
199 """
199 """
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
201
201
202 Input:
202 Input:
203
203
204 dataIn : objeto del tipo JROData
204 dataIn : objeto del tipo JROData
205
205
206 Return:
206 Return:
207
207
208 None
208 None
209
209
210 Affected:
210 Affected:
211 __buffer : buffer de recepcion de datos.
211 __buffer : buffer de recepcion de datos.
212
212
213 """
213 """
214
214
215 raise ValueError, "ImplementedError"
215 raise ValueError, "ImplementedError"
216
216
217 class VoltageProc(ProcessingUnit):
217 class VoltageProc(ProcessingUnit):
218
218
219
219
220 def __init__(self):
220 def __init__(self):
221
221
222 self.objectDict = {}
222 self.objectDict = {}
223 self.dataOut = Voltage()
223 self.dataOut = Voltage()
224 self.flip = 1
224 self.flip = 1
225
225
226 def init(self):
226 def init(self):
227
227
228 self.dataOut.copy(self.dataIn)
228 self.dataOut.copy(self.dataIn)
229 # No necesita copiar en cada init() los atributos de dataIn
229 # No necesita copiar en cada init() los atributos de dataIn
230 # la copia deberia hacerse por cada nuevo bloque de datos
230 # la copia deberia hacerse por cada nuevo bloque de datos
231
231
232 def selectChannels(self, channelList):
232 def selectChannels(self, channelList):
233
233
234 channelIndexList = []
234 channelIndexList = []
235
235
236 for channel in channelList:
236 for channel in channelList:
237 index = self.dataOut.channelList.index(channel)
237 index = self.dataOut.channelList.index(channel)
238 channelIndexList.append(index)
238 channelIndexList.append(index)
239
239
240 self.selectChannelsByIndex(channelIndexList)
240 self.selectChannelsByIndex(channelIndexList)
241
241
242 def selectChannelsByIndex(self, channelIndexList):
242 def selectChannelsByIndex(self, channelIndexList):
243 """
243 """
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
245
245
246 Input:
246 Input:
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
248
248
249 Affected:
249 Affected:
250 self.dataOut.data
250 self.dataOut.data
251 self.dataOut.channelIndexList
251 self.dataOut.channelIndexList
252 self.dataOut.nChannels
252 self.dataOut.nChannels
253 self.dataOut.m_ProcessingHeader.totalSpectra
253 self.dataOut.m_ProcessingHeader.totalSpectra
254 self.dataOut.systemHeaderObj.numChannels
254 self.dataOut.systemHeaderObj.numChannels
255 self.dataOut.m_ProcessingHeader.blockSize
255 self.dataOut.m_ProcessingHeader.blockSize
256
256
257 Return:
257 Return:
258 None
258 None
259 """
259 """
260
260
261 for channelIndex in channelIndexList:
261 for channelIndex in channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
263 print channelIndexList
263 print channelIndexList
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
265
265
266 nChannels = len(channelIndexList)
266 nChannels = len(channelIndexList)
267
267
268 data = self.dataOut.data[channelIndexList,:]
268 data = self.dataOut.data[channelIndexList,:]
269
269
270 self.dataOut.data = data
270 self.dataOut.data = data
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
272 # self.dataOut.nChannels = nChannels
272 # self.dataOut.nChannels = nChannels
273
273
274 return 1
274 return 1
275
275
276 def selectHeights(self, minHei, maxHei):
276 def selectHeights(self, minHei, maxHei):
277 """
277 """
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
279 minHei <= height <= maxHei
279 minHei <= height <= maxHei
280
280
281 Input:
281 Input:
282 minHei : valor minimo de altura a considerar
282 minHei : valor minimo de altura a considerar
283 maxHei : valor maximo de altura a considerar
283 maxHei : valor maximo de altura a considerar
284
284
285 Affected:
285 Affected:
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
287
287
288 Return:
288 Return:
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
290 """
290 """
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
293
293
294 if (maxHei > self.dataOut.heightList[-1]):
294 if (maxHei > self.dataOut.heightList[-1]):
295 maxHei = self.dataOut.heightList[-1]
295 maxHei = self.dataOut.heightList[-1]
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
297
297
298 minIndex = 0
298 minIndex = 0
299 maxIndex = 0
299 maxIndex = 0
300 heights = self.dataOut.heightList
300 heights = self.dataOut.heightList
301
301
302 inda = numpy.where(heights >= minHei)
302 inda = numpy.where(heights >= minHei)
303 indb = numpy.where(heights <= maxHei)
303 indb = numpy.where(heights <= maxHei)
304
304
305 try:
305 try:
306 minIndex = inda[0][0]
306 minIndex = inda[0][0]
307 except:
307 except:
308 minIndex = 0
308 minIndex = 0
309
309
310 try:
310 try:
311 maxIndex = indb[0][-1]
311 maxIndex = indb[0][-1]
312 except:
312 except:
313 maxIndex = len(heights)
313 maxIndex = len(heights)
314
314
315 self.selectHeightsByIndex(minIndex, maxIndex)
315 self.selectHeightsByIndex(minIndex, maxIndex)
316
316
317 return 1
317 return 1
318
318
319
319
320 def selectHeightsByIndex(self, minIndex, maxIndex):
320 def selectHeightsByIndex(self, minIndex, maxIndex):
321 """
321 """
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
323 minIndex <= index <= maxIndex
323 minIndex <= index <= maxIndex
324
324
325 Input:
325 Input:
326 minIndex : valor de indice minimo de altura a considerar
326 minIndex : valor de indice minimo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
328
328
329 Affected:
329 Affected:
330 self.dataOut.data
330 self.dataOut.data
331 self.dataOut.heightList
331 self.dataOut.heightList
332
332
333 Return:
333 Return:
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
335 """
335 """
336
336
337 if (minIndex < 0) or (minIndex > maxIndex):
337 if (minIndex < 0) or (minIndex > maxIndex):
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
339
339
340 if (maxIndex >= self.dataOut.nHeights):
340 if (maxIndex >= self.dataOut.nHeights):
341 maxIndex = self.dataOut.nHeights-1
341 maxIndex = self.dataOut.nHeights-1
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
343
343
344 nHeights = maxIndex - minIndex + 1
344 nHeights = maxIndex - minIndex + 1
345
345
346 #voltage
346 #voltage
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
348
348
349 firstHeight = self.dataOut.heightList[minIndex]
349 firstHeight = self.dataOut.heightList[minIndex]
350
350
351 self.dataOut.data = data
351 self.dataOut.data = data
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
353
353
354 return 1
354 return 1
355
355
356
356
357 def filterByHeights(self, window):
357 def filterByHeights(self, window):
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
359
359
360 if window == None:
360 if window == None:
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
362
362
363 newdelta = deltaHeight * window
363 newdelta = deltaHeight * window
364 r = self.dataOut.data.shape[1] % window
364 r = self.dataOut.data.shape[1] % window
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
367 buffer = numpy.sum(buffer,2)
367 buffer = numpy.sum(buffer,2)
368 self.dataOut.data = buffer
368 self.dataOut.data = buffer
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
370 self.dataOut.windowOfFilter = window
370 self.dataOut.windowOfFilter = window
371
371
372 def deFlip(self):
372 def deFlip(self):
373 self.dataOut.data *= self.flip
373 self.dataOut.data *= self.flip
374 self.flip *= -1.
374 self.flip *= -1.
375
375
376
376
377 class CohInt(Operation):
377 class CohInt(Operation):
378
378
379 __isConfig = False
379 __isConfig = False
380
380
381 __profIndex = 0
381 __profIndex = 0
382 __withOverapping = False
382 __withOverapping = False
383
383
384 __byTime = False
384 __byTime = False
385 __initime = None
385 __initime = None
386 __lastdatatime = None
386 __lastdatatime = None
387 __integrationtime = None
387 __integrationtime = None
388
388
389 __buffer = None
389 __buffer = None
390
390
391 __dataReady = False
391 __dataReady = False
392
392
393 n = None
393 n = None
394
394
395
395
396 def __init__(self):
396 def __init__(self):
397
397
398 self.__isConfig = False
398 self.__isConfig = False
399
399
400 def setup(self, n=None, timeInterval=None, overlapping=False):
400 def setup(self, n=None, timeInterval=None, overlapping=False):
401 """
401 """
402 Set the parameters of the integration class.
402 Set the parameters of the integration class.
403
403
404 Inputs:
404 Inputs:
405
405
406 n : Number of coherent integrations
406 n : Number of coherent integrations
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
408 overlapping :
408 overlapping :
409
409
410 """
410 """
411
411
412 self.__initime = None
412 self.__initime = None
413 self.__lastdatatime = 0
413 self.__lastdatatime = 0
414 self.__buffer = None
414 self.__buffer = None
415 self.__dataReady = False
415 self.__dataReady = False
416
416
417
417
418 if n == None and timeInterval == None:
418 if n == None and timeInterval == None:
419 raise ValueError, "n or timeInterval should be specified ..."
419 raise ValueError, "n or timeInterval should be specified ..."
420
420
421 if n != None:
421 if n != None:
422 self.n = n
422 self.n = n
423 self.__byTime = False
423 self.__byTime = False
424 else:
424 else:
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
426 self.n = 9999
426 self.n = 9999
427 self.__byTime = True
427 self.__byTime = True
428
428
429 if overlapping:
429 if overlapping:
430 self.__withOverapping = True
430 self.__withOverapping = True
431 self.__buffer = None
431 self.__buffer = None
432 else:
432 else:
433 self.__withOverapping = False
433 self.__withOverapping = False
434 self.__buffer = 0
434 self.__buffer = 0
435
435
436 self.__profIndex = 0
436 self.__profIndex = 0
437
437
438 def putData(self, data):
438 def putData(self, data):
439
439
440 """
440 """
441 Add a profile to the __buffer and increase in one the __profileIndex
441 Add a profile to the __buffer and increase in one the __profileIndex
442
442
443 """
443 """
444
444
445 if not self.__withOverapping:
445 if not self.__withOverapping:
446 self.__buffer += data.copy()
446 self.__buffer += data.copy()
447 self.__profIndex += 1
447 self.__profIndex += 1
448 return
448 return
449
449
450 #Overlapping data
450 #Overlapping data
451 nChannels, nHeis = data.shape
451 nChannels, nHeis = data.shape
452 data = numpy.reshape(data, (1, nChannels, nHeis))
452 data = numpy.reshape(data, (1, nChannels, nHeis))
453
453
454 #If the buffer is empty then it takes the data value
454 #If the buffer is empty then it takes the data value
455 if self.__buffer == None:
455 if self.__buffer == None:
456 self.__buffer = data
456 self.__buffer = data
457 self.__profIndex += 1
457 self.__profIndex += 1
458 return
458 return
459
459
460 #If the buffer length is lower than n then stakcing the data value
460 #If the buffer length is lower than n then stakcing the data value
461 if self.__profIndex < self.n:
461 if self.__profIndex < self.n:
462 self.__buffer = numpy.vstack((self.__buffer, data))
462 self.__buffer = numpy.vstack((self.__buffer, data))
463 self.__profIndex += 1
463 self.__profIndex += 1
464 return
464 return
465
465
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
468 self.__buffer[self.n-1] = data
468 self.__buffer[self.n-1] = data
469 self.__profIndex = self.n
469 self.__profIndex = self.n
470 return
470 return
471
471
472
472
473 def pushData(self):
473 def pushData(self):
474 """
474 """
475 Return the sum of the last profiles and the profiles used in the sum.
475 Return the sum of the last profiles and the profiles used in the sum.
476
476
477 Affected:
477 Affected:
478
478
479 self.__profileIndex
479 self.__profileIndex
480
480
481 """
481 """
482
482
483 if not self.__withOverapping:
483 if not self.__withOverapping:
484 data = self.__buffer
484 data = self.__buffer
485 n = self.__profIndex
485 n = self.__profIndex
486
486
487 self.__buffer = 0
487 self.__buffer = 0
488 self.__profIndex = 0
488 self.__profIndex = 0
489
489
490 return data, n
490 return data, n
491
491
492 #Integration with Overlapping
492 #Integration with Overlapping
493 data = numpy.sum(self.__buffer, axis=0)
493 data = numpy.sum(self.__buffer, axis=0)
494 n = self.__profIndex
494 n = self.__profIndex
495
495
496 return data, n
496 return data, n
497
497
498 def byProfiles(self, data):
498 def byProfiles(self, data):
499
499
500 self.__dataReady = False
500 self.__dataReady = False
501 avgdata = None
501 avgdata = None
502 n = None
502 n = None
503
503
504 self.putData(data)
504 self.putData(data)
505
505
506 if self.__profIndex == self.n:
506 if self.__profIndex == self.n:
507
507
508 avgdata, n = self.pushData()
508 avgdata, n = self.pushData()
509 self.__dataReady = True
509 self.__dataReady = True
510
510
511 return avgdata
511 return avgdata
512
512
513 def byTime(self, data, datatime):
513 def byTime(self, data, datatime):
514
514
515 self.__dataReady = False
515 self.__dataReady = False
516 avgdata = None
516 avgdata = None
517 n = None
517 n = None
518
518
519 self.putData(data)
519 self.putData(data)
520
520
521 if (datatime - self.__initime) >= self.__integrationtime:
521 if (datatime - self.__initime) >= self.__integrationtime:
522 avgdata, n = self.pushData()
522 avgdata, n = self.pushData()
523 self.n = n
523 self.n = n
524 self.__dataReady = True
524 self.__dataReady = True
525
525
526 return avgdata
526 return avgdata
527
527
528 def integrate(self, data, datatime=None):
528 def integrate(self, data, datatime=None):
529
529
530 if self.__initime == None:
530 if self.__initime == None:
531 self.__initime = datatime
531 self.__initime = datatime
532
532
533 if self.__byTime:
533 if self.__byTime:
534 avgdata = self.byTime(data, datatime)
534 avgdata = self.byTime(data, datatime)
535 else:
535 else:
536 avgdata = self.byProfiles(data)
536 avgdata = self.byProfiles(data)
537
537
538
538
539 self.__lastdatatime = datatime
539 self.__lastdatatime = datatime
540
540
541 if avgdata == None:
541 if avgdata == None:
542 return None, None
542 return None, None
543
543
544 avgdatatime = self.__initime
544 avgdatatime = self.__initime
545
545
546 deltatime = datatime -self.__lastdatatime
546 deltatime = datatime -self.__lastdatatime
547
547
548 if not self.__withOverapping:
548 if not self.__withOverapping:
549 self.__initime = datatime
549 self.__initime = datatime
550 else:
550 else:
551 self.__initime += deltatime
551 self.__initime += deltatime
552
552
553 return avgdata, avgdatatime
553 return avgdata, avgdatatime
554
554
555 def run(self, dataOut, **kwargs):
555 def run(self, dataOut, **kwargs):
556
556
557 if not self.__isConfig:
557 if not self.__isConfig:
558 self.setup(**kwargs)
558 self.setup(**kwargs)
559 self.__isConfig = True
559 self.__isConfig = True
560
560
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
562
562
563 # dataOut.timeInterval *= n
563 # dataOut.timeInterval *= n
564 dataOut.flagNoData = True
564 dataOut.flagNoData = True
565
565
566 if self.__dataReady:
566 if self.__dataReady:
567 dataOut.data = avgdata
567 dataOut.data = avgdata
568 dataOut.nCohInt *= self.n
568 dataOut.nCohInt *= self.n
569 dataOut.utctime = avgdatatime
569 dataOut.utctime = avgdatatime
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
571 dataOut.flagNoData = False
571 dataOut.flagNoData = False
572
572
573
573
574 class Decoder(Operation):
574 class Decoder(Operation):
575
575
576 __isConfig = False
576 __isConfig = False
577 __profIndex = 0
577 __profIndex = 0
578
578
579 code = None
579 code = None
580
580
581 nCode = None
581 nCode = None
582 nBaud = None
582 nBaud = None
583
583
584 def __init__(self):
584 def __init__(self):
585
585
586 self.__isConfig = False
586 self.__isConfig = False
587
587
588 def setup(self, code, shape):
588 def setup(self, code, shape):
589
589
590 self.__profIndex = 0
590 self.__profIndex = 0
591
591
592 self.code = code
592 self.code = code
593
593
594 self.nCode = len(code)
594 self.nCode = len(code)
595 self.nBaud = len(code[0])
595 self.nBaud = len(code[0])
596
596
597 self.__nChannels, self.__nHeis = shape
597 self.__nChannels, self.__nHeis = shape
598
598
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
600
600
601 __codeBuffer[:,0:self.nBaud] = self.code
601 __codeBuffer[:,0:self.nBaud] = self.code
602
602
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
604
604
605 self.ndatadec = self.__nHeis - self.nBaud + 1
605 self.ndatadec = self.__nHeis - self.nBaud + 1
606
606
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
608
608
609 def convolutionInFreq(self, data):
609 def convolutionInFreq(self, data):
610
610
611 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
611 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
612
612
613 fft_data = numpy.fft.fft(data, axis=1)
613 fft_data = numpy.fft.fft(data, axis=1)
614
614
615 conv = fft_data*fft_code
615 conv = fft_data*fft_code
616
616
617 data = numpy.fft.ifft(conv,axis=1)
617 data = numpy.fft.ifft(conv,axis=1)
618
618
619 datadec = data[:,:-self.nBaud+1]
619 datadec = data[:,:-self.nBaud+1]
620
620
621 return datadec
621 return datadec
622
622
623 def convolutionInFreqOpt(self, data):
623 def convolutionInFreqOpt(self, data):
624
624
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
626
626
627 data = cfunctions.decoder(fft_code, data)
627 data = cfunctions.decoder(fft_code, data)
628
628
629 datadec = data[:,:-self.nBaud+1]
629 datadec = data[:,:-self.nBaud+1]
630
630
631 return datadec
631 return datadec
632
632
633 def convolutionInTime(self, data):
633 def convolutionInTime(self, data):
634
634
635 code = self.code[self.__profIndex]
635 code = self.code[self.__profIndex]
636
636
637 for i in range(self.__nChannels):
637 for i in range(self.__nChannels):
638 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
638 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
639
639
640 return self.datadecTime
640 return self.datadecTime
641
641
642 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
642 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
643
643
644 if not self.__isConfig:
644 if not self.__isConfig:
645
645
646 if code == None:
646 if code == None:
647 code = dataOut.code
647 code = dataOut.code
648 else:
648 else:
649 code = numpy.array(code).reshape(nCode,nBaud)
649 code = numpy.array(code).reshape(nCode,nBaud)
650 dataOut.code = code
650 dataOut.code = code
651 dataOut.nCode = nCode
651 dataOut.nCode = nCode
652 dataOut.nBaud = nBaud
652 dataOut.nBaud = nBaud
653
653
654 if code == None:
654 if code == None:
655 return 1
655 return 1
656
656
657 self.setup(code, dataOut.data.shape)
657 self.setup(code, dataOut.data.shape)
658 self.__isConfig = True
658 self.__isConfig = True
659
659
660 if mode == 0:
660 if mode == 0:
661 datadec = self.convolutionInTime(dataOut.data)
661 datadec = self.convolutionInTime(dataOut.data)
662
662
663 if mode == 1:
663 if mode == 1:
664 datadec = self.convolutionInFreq(dataOut.data)
664 datadec = self.convolutionInFreq(dataOut.data)
665
665
666 if mode == 2:
666 if mode == 2:
667 datadec = self.convolutionInFreqOpt(dataOut.data)
667 datadec = self.convolutionInFreqOpt(dataOut.data)
668
668
669 dataOut.data = datadec
669 dataOut.data = datadec
670
670
671 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
671 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
672
672
673 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
673 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
674
674
675 if self.__profIndex == self.nCode-1:
675 if self.__profIndex == self.nCode-1:
676 self.__profIndex = 0
676 self.__profIndex = 0
677 return 1
677 return 1
678
678
679 self.__profIndex += 1
679 self.__profIndex += 1
680
680
681 return 1
681 return 1
682 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
682 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
683
683
684
684
685
685
686 class SpectraProc(ProcessingUnit):
686 class SpectraProc(ProcessingUnit):
687
687
688 def __init__(self):
688 def __init__(self):
689
689
690 self.objectDict = {}
690 self.objectDict = {}
691 self.buffer = None
691 self.buffer = None
692 self.firstdatatime = None
692 self.firstdatatime = None
693 self.profIndex = 0
693 self.profIndex = 0
694 self.dataOut = Spectra()
694 self.dataOut = Spectra()
695
695
696 def __updateObjFromInput(self):
696 def __updateObjFromInput(self):
697
697
698 self.dataOut.timeZone = self.dataIn.timeZone
698 self.dataOut.timeZone = self.dataIn.timeZone
699 self.dataOut.dstFlag = self.dataIn.dstFlag
699 self.dataOut.dstFlag = self.dataIn.dstFlag
700 self.dataOut.errorCount = self.dataIn.errorCount
700 self.dataOut.errorCount = self.dataIn.errorCount
701 self.dataOut.useLocalTime = self.dataIn.useLocalTime
701 self.dataOut.useLocalTime = self.dataIn.useLocalTime
702
702
703 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
703 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
704 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
704 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
705 self.dataOut.channelList = self.dataIn.channelList
705 self.dataOut.channelList = self.dataIn.channelList
706 self.dataOut.heightList = self.dataIn.heightList
706 self.dataOut.heightList = self.dataIn.heightList
707 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
707 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
708 # self.dataOut.nHeights = self.dataIn.nHeights
708 # self.dataOut.nHeights = self.dataIn.nHeights
709 # self.dataOut.nChannels = self.dataIn.nChannels
709 # self.dataOut.nChannels = self.dataIn.nChannels
710 self.dataOut.nBaud = self.dataIn.nBaud
710 self.dataOut.nBaud = self.dataIn.nBaud
711 self.dataOut.nCode = self.dataIn.nCode
711 self.dataOut.nCode = self.dataIn.nCode
712 self.dataOut.code = self.dataIn.code
712 self.dataOut.code = self.dataIn.code
713 self.dataOut.nProfiles = self.dataOut.nFFTPoints
713 self.dataOut.nProfiles = self.dataOut.nFFTPoints
714 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
714 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
715 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
715 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
716 self.dataOut.utctime = self.firstdatatime
716 self.dataOut.utctime = self.firstdatatime
717 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
717 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
718 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
718 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
719 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
719 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
720 self.dataOut.nCohInt = self.dataIn.nCohInt
720 self.dataOut.nCohInt = self.dataIn.nCohInt
721 self.dataOut.nIncohInt = 1
721 self.dataOut.nIncohInt = 1
722 self.dataOut.ippSeconds = self.dataIn.ippSeconds
722 self.dataOut.ippSeconds = self.dataIn.ippSeconds
723 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
723 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
724
724
725 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
725 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
726
726
727 def __getFft(self):
727 def __getFft(self):
728 """
728 """
729 Convierte valores de Voltaje a Spectra
729 Convierte valores de Voltaje a Spectra
730
730
731 Affected:
731 Affected:
732 self.dataOut.data_spc
732 self.dataOut.data_spc
733 self.dataOut.data_cspc
733 self.dataOut.data_cspc
734 self.dataOut.data_dc
734 self.dataOut.data_dc
735 self.dataOut.heightList
735 self.dataOut.heightList
736 self.profIndex
736 self.profIndex
737 self.buffer
737 self.buffer
738 self.dataOut.flagNoData
738 self.dataOut.flagNoData
739 """
739 """
740 fft_volt = numpy.fft.fft(self.buffer,axis=1)
740 fft_volt = numpy.fft.fft(self.buffer,axis=1)
741 fft_volt = fft_volt.astype(numpy.dtype('complex'))
741 fft_volt = fft_volt.astype(numpy.dtype('complex'))
742 dc = fft_volt[:,0,:]
742 dc = fft_volt[:,0,:]
743
743
744 #calculo de self-spectra
744 #calculo de self-spectra
745 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
745 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
746 spc = fft_volt * numpy.conjugate(fft_volt)
746 spc = fft_volt * numpy.conjugate(fft_volt)
747 spc = spc.real
747 spc = spc.real
748
748
749 blocksize = 0
749 blocksize = 0
750 blocksize += dc.size
750 blocksize += dc.size
751 blocksize += spc.size
751 blocksize += spc.size
752
752
753 cspc = None
753 cspc = None
754 pairIndex = 0
754 pairIndex = 0
755 if self.dataOut.pairsList != None:
755 if self.dataOut.pairsList != None:
756 #calculo de cross-spectra
756 #calculo de cross-spectra
757 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
757 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
758 for pair in self.dataOut.pairsList:
758 for pair in self.dataOut.pairsList:
759 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
759 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
760 pairIndex += 1
760 pairIndex += 1
761 blocksize += cspc.size
761 blocksize += cspc.size
762
762
763 self.dataOut.data_spc = spc
763 self.dataOut.data_spc = spc
764 self.dataOut.data_cspc = cspc
764 self.dataOut.data_cspc = cspc
765 self.dataOut.data_dc = dc
765 self.dataOut.data_dc = dc
766 self.dataOut.blockSize = blocksize
766 self.dataOut.blockSize = blocksize
767 self.dataOut.flagShiftFFT = False
767 self.dataOut.flagShiftFFT = False
768
768
769 def init(self, nFFTPoints=None, pairsList=None):
769 def init(self, nFFTPoints=None, pairsList=None):
770
770
771 self.dataOut.flagNoData = True
771 self.dataOut.flagNoData = True
772
772
773 if self.dataIn.type == "Spectra":
773 if self.dataIn.type == "Spectra":
774 self.dataOut.copy(self.dataIn)
774 self.dataOut.copy(self.dataIn)
775 return
775 return
776
776
777 if self.dataIn.type == "Voltage":
777 if self.dataIn.type == "Voltage":
778
778
779 if nFFTPoints == None:
779 if nFFTPoints == None:
780 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
780 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
781
781
782 if pairsList == None:
782 if pairsList == None:
783 nPairs = 0
783 nPairs = 0
784 else:
784 else:
785 nPairs = len(pairsList)
785 nPairs = len(pairsList)
786
786
787 self.dataOut.nFFTPoints = nFFTPoints
787 self.dataOut.nFFTPoints = nFFTPoints
788 self.dataOut.pairsList = pairsList
788 self.dataOut.pairsList = pairsList
789 self.dataOut.nPairs = nPairs
789 self.dataOut.nPairs = nPairs
790
790
791 if self.buffer == None:
791 if self.buffer == None:
792 self.buffer = numpy.zeros((self.dataIn.nChannels,
792 self.buffer = numpy.zeros((self.dataIn.nChannels,
793 self.dataOut.nFFTPoints,
793 self.dataOut.nFFTPoints,
794 self.dataIn.nHeights),
794 self.dataIn.nHeights),
795 dtype='complex')
795 dtype='complex')
796
796
797
797
798 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
798 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
799 self.profIndex += 1
799 self.profIndex += 1
800
800
801 if self.firstdatatime == None:
801 if self.firstdatatime == None:
802 self.firstdatatime = self.dataIn.utctime
802 self.firstdatatime = self.dataIn.utctime
803
803
804 if self.profIndex == self.dataOut.nFFTPoints:
804 if self.profIndex == self.dataOut.nFFTPoints:
805 self.__updateObjFromInput()
805 self.__updateObjFromInput()
806 self.__getFft()
806 self.__getFft()
807
807
808 self.dataOut.flagNoData = False
808 self.dataOut.flagNoData = False
809
809
810 self.buffer = None
810 self.buffer = None
811 self.firstdatatime = None
811 self.firstdatatime = None
812 self.profIndex = 0
812 self.profIndex = 0
813
813
814 return
814 return
815
815
816 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
816 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
817
817
818 def selectChannels(self, channelList):
818 def selectChannels(self, channelList):
819
819
820 channelIndexList = []
820 channelIndexList = []
821
821
822 for channel in channelList:
822 for channel in channelList:
823 index = self.dataOut.channelList.index(channel)
823 index = self.dataOut.channelList.index(channel)
824 channelIndexList.append(index)
824 channelIndexList.append(index)
825
825
826 self.selectChannelsByIndex(channelIndexList)
826 self.selectChannelsByIndex(channelIndexList)
827
827
828 def selectChannelsByIndex(self, channelIndexList):
828 def selectChannelsByIndex(self, channelIndexList):
829 """
829 """
830 Selecciona un bloque de datos en base a canales segun el channelIndexList
830 Selecciona un bloque de datos en base a canales segun el channelIndexList
831
831
832 Input:
832 Input:
833 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
833 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
834
834
835 Affected:
835 Affected:
836 self.dataOut.data_spc
836 self.dataOut.data_spc
837 self.dataOut.channelIndexList
837 self.dataOut.channelIndexList
838 self.dataOut.nChannels
838 self.dataOut.nChannels
839
839
840 Return:
840 Return:
841 None
841 None
842 """
842 """
843
843
844 for channelIndex in channelIndexList:
844 for channelIndex in channelIndexList:
845 if channelIndex not in self.dataOut.channelIndexList:
845 if channelIndex not in self.dataOut.channelIndexList:
846 print channelIndexList
846 print channelIndexList
847 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
847 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
848
848
849 nChannels = len(channelIndexList)
849 nChannels = len(channelIndexList)
850
850
851 data_spc = self.dataOut.data_spc[channelIndexList,:]
851 data_spc = self.dataOut.data_spc[channelIndexList,:]
852
852
853 self.dataOut.data_spc = data_spc
853 self.dataOut.data_spc = data_spc
854 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
854 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
855 # self.dataOut.nChannels = nChannels
855 # self.dataOut.nChannels = nChannels
856
856
857 return 1
857 return 1
858
858
859 def selectHeights(self, minHei, maxHei):
859 def selectHeights(self, minHei, maxHei):
860 """
860 """
861 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
861 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
862 minHei <= height <= maxHei
862 minHei <= height <= maxHei
863
863
864 Input:
864 Input:
865 minHei : valor minimo de altura a considerar
865 minHei : valor minimo de altura a considerar
866 maxHei : valor maximo de altura a considerar
866 maxHei : valor maximo de altura a considerar
867
867
868 Affected:
868 Affected:
869 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
869 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
870
870
871 Return:
871 Return:
872 1 si el metodo se ejecuto con exito caso contrario devuelve 0
872 1 si el metodo se ejecuto con exito caso contrario devuelve 0
873 """
873 """
874 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
874 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
875 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
875 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
876
876
877 if (maxHei > self.dataOut.heightList[-1]):
877 if (maxHei > self.dataOut.heightList[-1]):
878 maxHei = self.dataOut.heightList[-1]
878 maxHei = self.dataOut.heightList[-1]
879 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
879 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
880
880
881 minIndex = 0
881 minIndex = 0
882 maxIndex = 0
882 maxIndex = 0
883 heights = self.dataOut.heightList
883 heights = self.dataOut.heightList
884
884
885 inda = numpy.where(heights >= minHei)
885 inda = numpy.where(heights >= minHei)
886 indb = numpy.where(heights <= maxHei)
886 indb = numpy.where(heights <= maxHei)
887
887
888 try:
888 try:
889 minIndex = inda[0][0]
889 minIndex = inda[0][0]
890 except:
890 except:
891 minIndex = 0
891 minIndex = 0
892
892
893 try:
893 try:
894 maxIndex = indb[0][-1]
894 maxIndex = indb[0][-1]
895 except:
895 except:
896 maxIndex = len(heights)
896 maxIndex = len(heights)
897
897
898 self.selectHeightsByIndex(minIndex, maxIndex)
898 self.selectHeightsByIndex(minIndex, maxIndex)
899
899
900 return 1
900 return 1
901
901
902
902
903 def selectHeightsByIndex(self, minIndex, maxIndex):
903 def selectHeightsByIndex(self, minIndex, maxIndex):
904 """
904 """
905 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
905 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
906 minIndex <= index <= maxIndex
906 minIndex <= index <= maxIndex
907
907
908 Input:
908 Input:
909 minIndex : valor de indice minimo de altura a considerar
909 minIndex : valor de indice minimo de altura a considerar
910 maxIndex : valor de indice maximo de altura a considerar
910 maxIndex : valor de indice maximo de altura a considerar
911
911
912 Affected:
912 Affected:
913 self.dataOut.data_spc
913 self.dataOut.data_spc
914 self.dataOut.data_cspc
914 self.dataOut.data_cspc
915 self.dataOut.data_dc
915 self.dataOut.data_dc
916 self.dataOut.heightList
916 self.dataOut.heightList
917
917
918 Return:
918 Return:
919 1 si el metodo se ejecuto con exito caso contrario devuelve 0
919 1 si el metodo se ejecuto con exito caso contrario devuelve 0
920 """
920 """
921
921
922 if (minIndex < 0) or (minIndex > maxIndex):
922 if (minIndex < 0) or (minIndex > maxIndex):
923 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
923 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
924
924
925 if (maxIndex >= self.dataOut.nHeights):
925 if (maxIndex >= self.dataOut.nHeights):
926 maxIndex = self.dataOut.nHeights-1
926 maxIndex = self.dataOut.nHeights-1
927 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
927 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
928
928
929 nHeights = maxIndex - minIndex + 1
929 nHeights = maxIndex - minIndex + 1
930
930
931 #Spectra
931 #Spectra
932 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
932 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
933
933
934 data_cspc = None
934 data_cspc = None
935 if self.dataOut.data_cspc != None:
935 if self.dataOut.data_cspc != None:
936 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
936 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
937
937
938 data_dc = None
938 data_dc = None
939 if self.dataOut.data_dc != None:
939 if self.dataOut.data_dc != None:
940 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
940 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
941
941
942 self.dataOut.data_spc = data_spc
942 self.dataOut.data_spc = data_spc
943 self.dataOut.data_cspc = data_cspc
943 self.dataOut.data_cspc = data_cspc
944 self.dataOut.data_dc = data_dc
944 self.dataOut.data_dc = data_dc
945
945
946 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
946 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
947
947
948 return 1
948 return 1
949
949
950 def removeDC(self, mode = 1):
950 def removeDC(self, mode = 1):
951
951
952 dc_index = 0
952 dc_index = 0
953 freq_index = numpy.array([-2,-1,1,2])
953 freq_index = numpy.array([-2,-1,1,2])
954 data_spc = self.dataOut.data_spc
954 data_spc = self.dataOut.data_spc
955 data_cspc = self.dataOut.data_cspc
955 data_cspc = self.dataOut.data_cspc
956 data_dc = self.dataOut.data_dc
956 data_dc = self.dataOut.data_dc
957
957
958 if self.dataOut.flagShiftFFT:
958 if self.dataOut.flagShiftFFT:
959 dc_index += self.dataOut.nFFTPoints/2
959 dc_index += self.dataOut.nFFTPoints/2
960 freq_index += self.dataOut.nFFTPoints/2
960 freq_index += self.dataOut.nFFTPoints/2
961
961
962 if mode == 1:
962 if mode == 1:
963 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
963 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
964 if data_cspc != None:
964 if data_cspc != None:
965 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
965 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
966 return 1
966 return 1
967
967
968 if mode == 2:
968 if mode == 2:
969 pass
969 pass
970
970
971 if mode == 3:
971 if mode == 3:
972 pass
972 pass
973
973
974 raise ValueError, "mode parameter has to be 1, 2 or 3"
974 raise ValueError, "mode parameter has to be 1, 2 or 3"
975
975
976 def removeInterference(self):
976 def removeInterference(self):
977
977
978 pass
978 pass
979
979
980
980
981 class IncohInt(Operation):
981 class IncohInt(Operation):
982
982
983
983
984 __profIndex = 0
984 __profIndex = 0
985 __withOverapping = False
985 __withOverapping = False
986
986
987 __byTime = False
987 __byTime = False
988 __initime = None
988 __initime = None
989 __lastdatatime = None
989 __lastdatatime = None
990 __integrationtime = None
990 __integrationtime = None
991
991
992 __buffer_spc = None
992 __buffer_spc = None
993 __buffer_cspc = None
993 __buffer_cspc = None
994 __buffer_dc = None
994 __buffer_dc = None
995
995
996 __dataReady = False
996 __dataReady = False
997
997
998 __timeInterval = None
998 __timeInterval = None
999
999
1000 n = None
1000 n = None
1001
1001
1002
1002
1003
1003
1004 def __init__(self):
1004 def __init__(self):
1005
1005
1006 self.__isConfig = False
1006 self.__isConfig = False
1007
1007
1008 def setup(self, n=None, timeInterval=None, overlapping=False):
1008 def setup(self, n=None, timeInterval=None, overlapping=False):
1009 """
1009 """
1010 Set the parameters of the integration class.
1010 Set the parameters of the integration class.
1011
1011
1012 Inputs:
1012 Inputs:
1013
1013
1014 n : Number of coherent integrations
1014 n : Number of coherent integrations
1015 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1015 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1016 overlapping :
1016 overlapping :
1017
1017
1018 """
1018 """
1019
1019
1020 self.__initime = None
1020 self.__initime = None
1021 self.__lastdatatime = 0
1021 self.__lastdatatime = 0
1022 self.__buffer_spc = None
1022 self.__buffer_spc = None
1023 self.__buffer_cspc = None
1023 self.__buffer_cspc = None
1024 self.__buffer_dc = None
1024 self.__buffer_dc = None
1025 self.__dataReady = False
1025 self.__dataReady = False
1026
1026
1027
1027
1028 if n == None and timeInterval == None:
1028 if n == None and timeInterval == None:
1029 raise ValueError, "n or timeInterval should be specified ..."
1029 raise ValueError, "n or timeInterval should be specified ..."
1030
1030
1031 if n != None:
1031 if n != None:
1032 self.n = n
1032 self.n = n
1033 self.__byTime = False
1033 self.__byTime = False
1034 else:
1034 else:
1035 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1035 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1036 self.n = 9999
1036 self.n = 9999
1037 self.__byTime = True
1037 self.__byTime = True
1038
1038
1039 if overlapping:
1039 if overlapping:
1040 self.__withOverapping = True
1040 self.__withOverapping = True
1041 else:
1041 else:
1042 self.__withOverapping = False
1042 self.__withOverapping = False
1043 self.__buffer_spc = 0
1043 self.__buffer_spc = 0
1044 self.__buffer_cspc = 0
1044 self.__buffer_cspc = 0
1045 self.__buffer_dc = 0
1045 self.__buffer_dc = 0
1046
1046
1047 self.__profIndex = 0
1047 self.__profIndex = 0
1048
1048
1049 def putData(self, data_spc, data_cspc, data_dc):
1049 def putData(self, data_spc, data_cspc, data_dc):
1050
1050
1051 """
1051 """
1052 Add a profile to the __buffer_spc and increase in one the __profileIndex
1052 Add a profile to the __buffer_spc and increase in one the __profileIndex
1053
1053
1054 """
1054 """
1055
1055
1056 if not self.__withOverapping:
1056 if not self.__withOverapping:
1057 self.__buffer_spc += data_spc
1057 self.__buffer_spc += data_spc
1058
1058
1059 if data_cspc == None:
1059 if data_cspc == None:
1060 self.__buffer_cspc = None
1060 self.__buffer_cspc = None
1061 else:
1061 else:
1062 self.__buffer_cspc += data_cspc
1062 self.__buffer_cspc += data_cspc
1063
1063
1064 if data_dc == None:
1064 if data_dc == None:
1065 self.__buffer_dc = None
1065 self.__buffer_dc = None
1066 else:
1066 else:
1067 self.__buffer_dc += data_dc
1067 self.__buffer_dc += data_dc
1068
1068
1069 self.__profIndex += 1
1069 self.__profIndex += 1
1070 return
1070 return
1071
1071
1072 #Overlapping data
1072 #Overlapping data
1073 nChannels, nFFTPoints, nHeis = data_spc.shape
1073 nChannels, nFFTPoints, nHeis = data_spc.shape
1074 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1074 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1075 if data_cspc != None:
1075 if data_cspc != None:
1076 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1076 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1077 if data_dc != None:
1077 if data_dc != None:
1078 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1078 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1079
1079
1080 #If the buffer is empty then it takes the data value
1080 #If the buffer is empty then it takes the data value
1081 if self.__buffer_spc == None:
1081 if self.__buffer_spc == None:
1082 self.__buffer_spc = data_spc
1082 self.__buffer_spc = data_spc
1083
1083
1084 if data_cspc == None:
1084 if data_cspc == None:
1085 self.__buffer_cspc = None
1085 self.__buffer_cspc = None
1086 else:
1086 else:
1087 self.__buffer_cspc += data_cspc
1087 self.__buffer_cspc += data_cspc
1088
1088
1089 if data_dc == None:
1089 if data_dc == None:
1090 self.__buffer_dc = None
1090 self.__buffer_dc = None
1091 else:
1091 else:
1092 self.__buffer_dc += data_dc
1092 self.__buffer_dc += data_dc
1093
1093
1094 self.__profIndex += 1
1094 self.__profIndex += 1
1095 return
1095 return
1096
1096
1097 #If the buffer length is lower than n then stakcing the data value
1097 #If the buffer length is lower than n then stakcing the data value
1098 if self.__profIndex < self.n:
1098 if self.__profIndex < self.n:
1099 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1099 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1100
1100
1101 if data_cspc != None:
1101 if data_cspc != None:
1102 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1102 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1103
1103
1104 if data_dc != None:
1104 if data_dc != None:
1105 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1105 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1106
1106
1107 self.__profIndex += 1
1107 self.__profIndex += 1
1108 return
1108 return
1109
1109
1110 #If the buffer length is equal to n then replacing the last buffer value with the data value
1110 #If the buffer length is equal to n then replacing the last buffer value with the data value
1111 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1111 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1112 self.__buffer_spc[self.n-1] = data_spc
1112 self.__buffer_spc[self.n-1] = data_spc
1113
1113
1114 if data_cspc != None:
1114 if data_cspc != None:
1115 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1115 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1116 self.__buffer_cspc[self.n-1] = data_cspc
1116 self.__buffer_cspc[self.n-1] = data_cspc
1117
1117
1118 if data_dc != None:
1118 if data_dc != None:
1119 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1119 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1120 self.__buffer_dc[self.n-1] = data_dc
1120 self.__buffer_dc[self.n-1] = data_dc
1121
1121
1122 self.__profIndex = self.n
1122 self.__profIndex = self.n
1123 return
1123 return
1124
1124
1125
1125
1126 def pushData(self):
1126 def pushData(self):
1127 """
1127 """
1128 Return the sum of the last profiles and the profiles used in the sum.
1128 Return the sum of the last profiles and the profiles used in the sum.
1129
1129
1130 Affected:
1130 Affected:
1131
1131
1132 self.__profileIndex
1132 self.__profileIndex
1133
1133
1134 """
1134 """
1135 data_spc = None
1135 data_spc = None
1136 data_cspc = None
1136 data_cspc = None
1137 data_dc = None
1137 data_dc = None
1138
1138
1139 if not self.__withOverapping:
1139 if not self.__withOverapping:
1140 data_spc = self.__buffer_spc
1140 data_spc = self.__buffer_spc
1141 data_cspc = self.__buffer_cspc
1141 data_cspc = self.__buffer_cspc
1142 data_dc = self.__buffer_dc
1142 data_dc = self.__buffer_dc
1143
1143
1144 n = self.__profIndex
1144 n = self.__profIndex
1145
1145
1146 self.__buffer_spc = 0
1146 self.__buffer_spc = 0
1147 self.__buffer_cspc = 0
1147 self.__buffer_cspc = 0
1148 self.__buffer_dc = 0
1148 self.__buffer_dc = 0
1149 self.__profIndex = 0
1149 self.__profIndex = 0
1150
1150
1151 return data_spc, data_cspc, data_dc, n
1151 return data_spc, data_cspc, data_dc, n
1152
1152
1153 #Integration with Overlapping
1153 #Integration with Overlapping
1154 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1154 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1155
1155
1156 if self.__buffer_cspc != None:
1156 if self.__buffer_cspc != None:
1157 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1157 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1158
1158
1159 if self.__buffer_dc != None:
1159 if self.__buffer_dc != None:
1160 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1160 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1161
1161
1162 n = self.__profIndex
1162 n = self.__profIndex
1163
1163
1164 return data_spc, data_cspc, data_dc, n
1164 return data_spc, data_cspc, data_dc, n
1165
1165
1166 def byProfiles(self, *args):
1166 def byProfiles(self, *args):
1167
1167
1168 self.__dataReady = False
1168 self.__dataReady = False
1169 avgdata_spc = None
1169 avgdata_spc = None
1170 avgdata_cspc = None
1170 avgdata_cspc = None
1171 avgdata_dc = None
1171 avgdata_dc = None
1172 n = None
1172 n = None
1173
1173
1174 self.putData(*args)
1174 self.putData(*args)
1175
1175
1176 if self.__profIndex == self.n:
1176 if self.__profIndex == self.n:
1177
1177
1178 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1178 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1179 self.__dataReady = True
1179 self.__dataReady = True
1180
1180
1181 return avgdata_spc, avgdata_cspc, avgdata_dc
1181 return avgdata_spc, avgdata_cspc, avgdata_dc
1182
1182
1183 def byTime(self, datatime, *args):
1183 def byTime(self, datatime, *args):
1184
1184
1185 self.__dataReady = False
1185 self.__dataReady = False
1186 avgdata_spc = None
1186 avgdata_spc = None
1187 avgdata_cspc = None
1187 avgdata_cspc = None
1188 avgdata_dc = None
1188 avgdata_dc = None
1189 n = None
1189 n = None
1190
1190
1191 self.putData(*args)
1191 self.putData(*args)
1192
1192
1193 if (datatime - self.__initime) >= self.__integrationtime:
1193 if (datatime - self.__initime) >= self.__integrationtime:
1194 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1194 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1195 self.n = n
1195 self.n = n
1196 self.__dataReady = True
1196 self.__dataReady = True
1197
1197
1198 return avgdata_spc, avgdata_cspc, avgdata_dc
1198 return avgdata_spc, avgdata_cspc, avgdata_dc
1199
1199
1200 def integrate(self, datatime, *args):
1200 def integrate(self, datatime, *args):
1201
1201
1202 if self.__initime == None:
1202 if self.__initime == None:
1203 self.__initime = datatime
1203 self.__initime = datatime
1204
1204
1205 if self.__byTime:
1205 if self.__byTime:
1206 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1206 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1207 else:
1207 else:
1208 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1208 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1209
1209
1210 self.__lastdatatime = datatime
1210 self.__lastdatatime = datatime
1211
1211
1212 if avgdata_spc == None:
1212 if avgdata_spc == None:
1213 return None, None, None, None
1213 return None, None, None, None
1214
1214
1215 avgdatatime = self.__initime
1215 avgdatatime = self.__initime
1216 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1216 try:
1217
1217 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1218 except:
1219 self.__timeInterval = self.__lastdatatime - self.__initime
1220
1218 deltatime = datatime -self.__lastdatatime
1221 deltatime = datatime -self.__lastdatatime
1219
1222
1220 if not self.__withOverapping:
1223 if not self.__withOverapping:
1221 self.__initime = datatime
1224 self.__initime = datatime
1222 else:
1225 else:
1223 self.__initime += deltatime
1226 self.__initime += deltatime
1224
1227
1225 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1228 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1226
1229
1227 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1230 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1228
1231
1229 if n==1:
1232 if n==1:
1230 dataOut.flagNoData = False
1233 dataOut.flagNoData = False
1231 return
1234 return
1232
1235
1233 if not self.__isConfig:
1236 if not self.__isConfig:
1234 self.setup(n, timeInterval, overlapping)
1237 self.setup(n, timeInterval, overlapping)
1235 self.__isConfig = True
1238 self.__isConfig = True
1236
1239
1237 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1240 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1238 dataOut.data_spc,
1241 dataOut.data_spc,
1239 dataOut.data_cspc,
1242 dataOut.data_cspc,
1240 dataOut.data_dc)
1243 dataOut.data_dc)
1241
1244
1242 # dataOut.timeInterval *= n
1245 # dataOut.timeInterval *= n
1243 dataOut.flagNoData = True
1246 dataOut.flagNoData = True
1244
1247
1245 if self.__dataReady:
1248 if self.__dataReady:
1246
1249
1247 dataOut.data_spc = avgdata_spc
1250 dataOut.data_spc = avgdata_spc
1248 dataOut.data_cspc = avgdata_cspc
1251 dataOut.data_cspc = avgdata_cspc
1249 dataOut.data_dc = avgdata_dc
1252 dataOut.data_dc = avgdata_dc
1250
1253
1251 dataOut.nIncohInt *= self.n
1254 dataOut.nIncohInt *= self.n
1252 dataOut.utctime = avgdatatime
1255 dataOut.utctime = avgdatatime
1253 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1256 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1254 dataOut.timeInterval = self.__timeInterval*self.n
1257 dataOut.timeInterval = self.__timeInterval*self.n
1255 dataOut.flagNoData = False
1258 dataOut.flagNoData = False
1256
1259
1257 class ProfileSelector(Operation):
1260 class ProfileSelector(Operation):
1258
1261
1259 profileIndex = None
1262 profileIndex = None
1260 # Tamanho total de los perfiles
1263 # Tamanho total de los perfiles
1261 nProfiles = None
1264 nProfiles = None
1262
1265
1263 def __init__(self):
1266 def __init__(self):
1264
1267
1265 self.profileIndex = 0
1268 self.profileIndex = 0
1266
1269
1267 def incIndex(self):
1270 def incIndex(self):
1268 self.profileIndex += 1
1271 self.profileIndex += 1
1269
1272
1270 if self.profileIndex >= self.nProfiles:
1273 if self.profileIndex >= self.nProfiles:
1271 self.profileIndex = 0
1274 self.profileIndex = 0
1272
1275
1273 def isProfileInRange(self, minIndex, maxIndex):
1276 def isProfileInRange(self, minIndex, maxIndex):
1274
1277
1275 if self.profileIndex < minIndex:
1278 if self.profileIndex < minIndex:
1276 return False
1279 return False
1277
1280
1278 if self.profileIndex > maxIndex:
1281 if self.profileIndex > maxIndex:
1279 return False
1282 return False
1280
1283
1281 return True
1284 return True
1282
1285
1283 def isProfileInList(self, profileList):
1286 def isProfileInList(self, profileList):
1284
1287
1285 if self.profileIndex not in profileList:
1288 if self.profileIndex not in profileList:
1286 return False
1289 return False
1287
1290
1288 return True
1291 return True
1289
1292
1290 def run(self, dataOut, profileList=None, profileRangeList=None):
1293 def run(self, dataOut, profileList=None, profileRangeList=None):
1291
1294
1292 dataOut.flagNoData = True
1295 dataOut.flagNoData = True
1293 self.nProfiles = dataOut.nProfiles
1296 self.nProfiles = dataOut.nProfiles
1294
1297
1295 if profileList != None:
1298 if profileList != None:
1296 if self.isProfileInList(profileList):
1299 if self.isProfileInList(profileList):
1297 dataOut.flagNoData = False
1300 dataOut.flagNoData = False
1298
1301
1299 self.incIndex()
1302 self.incIndex()
1300 return 1
1303 return 1
1301
1304
1302
1305
1303 elif profileRangeList != None:
1306 elif profileRangeList != None:
1304 minIndex = profileRangeList[0]
1307 minIndex = profileRangeList[0]
1305 maxIndex = profileRangeList[1]
1308 maxIndex = profileRangeList[1]
1306 if self.isProfileInRange(minIndex, maxIndex):
1309 if self.isProfileInRange(minIndex, maxIndex):
1307 dataOut.flagNoData = False
1310 dataOut.flagNoData = False
1308
1311
1309 self.incIndex()
1312 self.incIndex()
1310 return 1
1313 return 1
1311
1314
1312 else:
1315 else:
1313 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1316 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1314
1317
1315 return 0
1318 return 0
1316
1319
1317 class SpectraHeisProc(ProcessingUnit):
1320 class SpectraHeisProc(ProcessingUnit):
1318 def __init__(self):
1321 def __init__(self):
1319 self.objectDict = {}
1322 self.objectDict = {}
1320 # self.buffer = None
1323 # self.buffer = None
1321 # self.firstdatatime = None
1324 # self.firstdatatime = None
1322 # self.profIndex = 0
1325 # self.profIndex = 0
1323 self.dataOut = SpectraHeis()
1326 self.dataOut = SpectraHeis()
1324
1327
1325 def __updateObjFromInput(self):
1328 def __updateObjFromInput(self):
1326 self.dataOut.timeZone = self.dataIn.timeZone
1329 self.dataOut.timeZone = self.dataIn.timeZone
1327 self.dataOut.dstFlag = self.dataIn.dstFlag
1330 self.dataOut.dstFlag = self.dataIn.dstFlag
1328 self.dataOut.errorCount = self.dataIn.errorCount
1331 self.dataOut.errorCount = self.dataIn.errorCount
1329 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1332 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1330
1333
1331 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1334 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1332 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1335 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1333 self.dataOut.channelList = self.dataIn.channelList
1336 self.dataOut.channelList = self.dataIn.channelList
1334 self.dataOut.heightList = self.dataIn.heightList
1337 self.dataOut.heightList = self.dataIn.heightList
1335 # self.dataOut.dtype = self.dataIn.dtype
1338 # self.dataOut.dtype = self.dataIn.dtype
1336 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1339 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1337 # self.dataOut.nHeights = self.dataIn.nHeights
1340 # self.dataOut.nHeights = self.dataIn.nHeights
1338 # self.dataOut.nChannels = self.dataIn.nChannels
1341 # self.dataOut.nChannels = self.dataIn.nChannels
1339 self.dataOut.nBaud = self.dataIn.nBaud
1342 self.dataOut.nBaud = self.dataIn.nBaud
1340 self.dataOut.nCode = self.dataIn.nCode
1343 self.dataOut.nCode = self.dataIn.nCode
1341 self.dataOut.code = self.dataIn.code
1344 self.dataOut.code = self.dataIn.code
1342 # self.dataOut.nProfiles = 1
1345 # self.dataOut.nProfiles = 1
1343 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1346 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1344 self.dataOut.nFFTPoints = self.dataIn.nHeights
1347 self.dataOut.nFFTPoints = self.dataIn.nHeights
1345 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1348 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1346 # self.dataOut.flagNoData = self.dataIn.flagNoData
1349 # self.dataOut.flagNoData = self.dataIn.flagNoData
1347 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1350 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1348 self.dataOut.utctime = self.dataIn.utctime
1351 self.dataOut.utctime = self.dataIn.utctime
1349 # self.dataOut.utctime = self.firstdatatime
1352 # self.dataOut.utctime = self.firstdatatime
1350 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1353 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1351 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1354 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1352 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1355 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1353 self.dataOut.nCohInt = self.dataIn.nCohInt
1356 self.dataOut.nCohInt = self.dataIn.nCohInt
1354 self.dataOut.nIncohInt = 1
1357 self.dataOut.nIncohInt = 1
1355 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1358 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1356 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1359 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1357
1360
1358 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1361 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1359 # self.dataOut.set=self.dataIn.set
1362 # self.dataOut.set=self.dataIn.set
1360 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1363 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1361
1364
1362
1365
1363 def __getFft(self):
1366 def __getFft(self):
1364
1367
1365 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1368 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1366 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1369 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1367 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1370 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1368 self.dataOut.data_spc = spc
1371 self.dataOut.data_spc = spc
1369
1372
1370 def init(self):
1373 def init(self):
1371
1374
1372 self.dataOut.flagNoData = True
1375 self.dataOut.flagNoData = True
1373
1376
1374 if self.dataIn.type == "SpectraHeis":
1377 if self.dataIn.type == "SpectraHeis":
1375 self.dataOut.copy(self.dataIn)
1378 self.dataOut.copy(self.dataIn)
1376 return
1379 return
1377
1380
1378 if self.dataIn.type == "Voltage":
1381 if self.dataIn.type == "Voltage":
1379 self.__updateObjFromInput()
1382 self.__updateObjFromInput()
1380 self.__getFft()
1383 self.__getFft()
1381 self.dataOut.flagNoData = False
1384 self.dataOut.flagNoData = False
1382
1385
1383 return
1386 return
1384
1387
1385 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1388 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1386
1389
1387
1390
1388 def selectChannels(self, channelList):
1391 def selectChannels(self, channelList):
1389
1392
1390 channelIndexList = []
1393 channelIndexList = []
1391
1394
1392 for channel in channelList:
1395 for channel in channelList:
1393 index = self.dataOut.channelList.index(channel)
1396 index = self.dataOut.channelList.index(channel)
1394 channelIndexList.append(index)
1397 channelIndexList.append(index)
1395
1398
1396 self.selectChannelsByIndex(channelIndexList)
1399 self.selectChannelsByIndex(channelIndexList)
1397
1400
1398 def selectChannelsByIndex(self, channelIndexList):
1401 def selectChannelsByIndex(self, channelIndexList):
1399 """
1402 """
1400 Selecciona un bloque de datos en base a canales segun el channelIndexList
1403 Selecciona un bloque de datos en base a canales segun el channelIndexList
1401
1404
1402 Input:
1405 Input:
1403 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1406 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1404
1407
1405 Affected:
1408 Affected:
1406 self.dataOut.data
1409 self.dataOut.data
1407 self.dataOut.channelIndexList
1410 self.dataOut.channelIndexList
1408 self.dataOut.nChannels
1411 self.dataOut.nChannels
1409 self.dataOut.m_ProcessingHeader.totalSpectra
1412 self.dataOut.m_ProcessingHeader.totalSpectra
1410 self.dataOut.systemHeaderObj.numChannels
1413 self.dataOut.systemHeaderObj.numChannels
1411 self.dataOut.m_ProcessingHeader.blockSize
1414 self.dataOut.m_ProcessingHeader.blockSize
1412
1415
1413 Return:
1416 Return:
1414 None
1417 None
1415 """
1418 """
1416
1419
1417 for channelIndex in channelIndexList:
1420 for channelIndex in channelIndexList:
1418 if channelIndex not in self.dataOut.channelIndexList:
1421 if channelIndex not in self.dataOut.channelIndexList:
1419 print channelIndexList
1422 print channelIndexList
1420 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1423 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1421
1424
1422 nChannels = len(channelIndexList)
1425 nChannels = len(channelIndexList)
1423
1426
1424 data_spc = self.dataOut.data_spc[channelIndexList,:]
1427 data_spc = self.dataOut.data_spc[channelIndexList,:]
1425
1428
1426 self.dataOut.data_spc = data_spc
1429 self.dataOut.data_spc = data_spc
1427 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1430 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1428
1431
1429 return 1
1432 return 1
1430
1433
1431 class IncohInt4SpectraHeis(Operation):
1434 class IncohInt4SpectraHeis(Operation):
1432
1435
1433 __isConfig = False
1436 __isConfig = False
1434
1437
1435 __profIndex = 0
1438 __profIndex = 0
1436 __withOverapping = False
1439 __withOverapping = False
1437
1440
1438 __byTime = False
1441 __byTime = False
1439 __initime = None
1442 __initime = None
1440 __lastdatatime = None
1443 __lastdatatime = None
1441 __integrationtime = None
1444 __integrationtime = None
1442
1445
1443 __buffer = None
1446 __buffer = None
1444
1447
1445 __dataReady = False
1448 __dataReady = False
1446
1449
1447 n = None
1450 n = None
1448
1451
1449
1452
1450 def __init__(self):
1453 def __init__(self):
1451
1454
1452 self.__isConfig = False
1455 self.__isConfig = False
1453
1456
1454 def setup(self, n=None, timeInterval=None, overlapping=False):
1457 def setup(self, n=None, timeInterval=None, overlapping=False):
1455 """
1458 """
1456 Set the parameters of the integration class.
1459 Set the parameters of the integration class.
1457
1460
1458 Inputs:
1461 Inputs:
1459
1462
1460 n : Number of coherent integrations
1463 n : Number of coherent integrations
1461 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1464 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1462 overlapping :
1465 overlapping :
1463
1466
1464 """
1467 """
1465
1468
1466 self.__initime = None
1469 self.__initime = None
1467 self.__lastdatatime = 0
1470 self.__lastdatatime = 0
1468 self.__buffer = None
1471 self.__buffer = None
1469 self.__dataReady = False
1472 self.__dataReady = False
1470
1473
1471
1474
1472 if n == None and timeInterval == None:
1475 if n == None and timeInterval == None:
1473 raise ValueError, "n or timeInterval should be specified ..."
1476 raise ValueError, "n or timeInterval should be specified ..."
1474
1477
1475 if n != None:
1478 if n != None:
1476 self.n = n
1479 self.n = n
1477 self.__byTime = False
1480 self.__byTime = False
1478 else:
1481 else:
1479 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1482 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1480 self.n = 9999
1483 self.n = 9999
1481 self.__byTime = True
1484 self.__byTime = True
1482
1485
1483 if overlapping:
1486 if overlapping:
1484 self.__withOverapping = True
1487 self.__withOverapping = True
1485 self.__buffer = None
1488 self.__buffer = None
1486 else:
1489 else:
1487 self.__withOverapping = False
1490 self.__withOverapping = False
1488 self.__buffer = 0
1491 self.__buffer = 0
1489
1492
1490 self.__profIndex = 0
1493 self.__profIndex = 0
1491
1494
1492 def putData(self, data):
1495 def putData(self, data):
1493
1496
1494 """
1497 """
1495 Add a profile to the __buffer and increase in one the __profileIndex
1498 Add a profile to the __buffer and increase in one the __profileIndex
1496
1499
1497 """
1500 """
1498
1501
1499 if not self.__withOverapping:
1502 if not self.__withOverapping:
1500 self.__buffer += data.copy()
1503 self.__buffer += data.copy()
1501 self.__profIndex += 1
1504 self.__profIndex += 1
1502 return
1505 return
1503
1506
1504 #Overlapping data
1507 #Overlapping data
1505 nChannels, nHeis = data.shape
1508 nChannels, nHeis = data.shape
1506 data = numpy.reshape(data, (1, nChannels, nHeis))
1509 data = numpy.reshape(data, (1, nChannels, nHeis))
1507
1510
1508 #If the buffer is empty then it takes the data value
1511 #If the buffer is empty then it takes the data value
1509 if self.__buffer == None:
1512 if self.__buffer == None:
1510 self.__buffer = data
1513 self.__buffer = data
1511 self.__profIndex += 1
1514 self.__profIndex += 1
1512 return
1515 return
1513
1516
1514 #If the buffer length is lower than n then stakcing the data value
1517 #If the buffer length is lower than n then stakcing the data value
1515 if self.__profIndex < self.n:
1518 if self.__profIndex < self.n:
1516 self.__buffer = numpy.vstack((self.__buffer, data))
1519 self.__buffer = numpy.vstack((self.__buffer, data))
1517 self.__profIndex += 1
1520 self.__profIndex += 1
1518 return
1521 return
1519
1522
1520 #If the buffer length is equal to n then replacing the last buffer value with the data value
1523 #If the buffer length is equal to n then replacing the last buffer value with the data value
1521 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1524 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1522 self.__buffer[self.n-1] = data
1525 self.__buffer[self.n-1] = data
1523 self.__profIndex = self.n
1526 self.__profIndex = self.n
1524 return
1527 return
1525
1528
1526
1529
1527 def pushData(self):
1530 def pushData(self):
1528 """
1531 """
1529 Return the sum of the last profiles and the profiles used in the sum.
1532 Return the sum of the last profiles and the profiles used in the sum.
1530
1533
1531 Affected:
1534 Affected:
1532
1535
1533 self.__profileIndex
1536 self.__profileIndex
1534
1537
1535 """
1538 """
1536
1539
1537 if not self.__withOverapping:
1540 if not self.__withOverapping:
1538 data = self.__buffer
1541 data = self.__buffer
1539 n = self.__profIndex
1542 n = self.__profIndex
1540
1543
1541 self.__buffer = 0
1544 self.__buffer = 0
1542 self.__profIndex = 0
1545 self.__profIndex = 0
1543
1546
1544 return data, n
1547 return data, n
1545
1548
1546 #Integration with Overlapping
1549 #Integration with Overlapping
1547 data = numpy.sum(self.__buffer, axis=0)
1550 data = numpy.sum(self.__buffer, axis=0)
1548 n = self.__profIndex
1551 n = self.__profIndex
1549
1552
1550 return data, n
1553 return data, n
1551
1554
1552 def byProfiles(self, data):
1555 def byProfiles(self, data):
1553
1556
1554 self.__dataReady = False
1557 self.__dataReady = False
1555 avgdata = None
1558 avgdata = None
1556 n = None
1559 n = None
1557
1560
1558 self.putData(data)
1561 self.putData(data)
1559
1562
1560 if self.__profIndex == self.n:
1563 if self.__profIndex == self.n:
1561
1564
1562 avgdata, n = self.pushData()
1565 avgdata, n = self.pushData()
1563 self.__dataReady = True
1566 self.__dataReady = True
1564
1567
1565 return avgdata
1568 return avgdata
1566
1569
1567 def byTime(self, data, datatime):
1570 def byTime(self, data, datatime):
1568
1571
1569 self.__dataReady = False
1572 self.__dataReady = False
1570 avgdata = None
1573 avgdata = None
1571 n = None
1574 n = None
1572
1575
1573 self.putData(data)
1576 self.putData(data)
1574
1577
1575 if (datatime - self.__initime) >= self.__integrationtime:
1578 if (datatime - self.__initime) >= self.__integrationtime:
1576 avgdata, n = self.pushData()
1579 avgdata, n = self.pushData()
1577 self.n = n
1580 self.n = n
1578 self.__dataReady = True
1581 self.__dataReady = True
1579
1582
1580 return avgdata
1583 return avgdata
1581
1584
1582 def integrate(self, data, datatime=None):
1585 def integrate(self, data, datatime=None):
1583
1586
1584 if self.__initime == None:
1587 if self.__initime == None:
1585 self.__initime = datatime
1588 self.__initime = datatime
1586
1589
1587 if self.__byTime:
1590 if self.__byTime:
1588 avgdata = self.byTime(data, datatime)
1591 avgdata = self.byTime(data, datatime)
1589 else:
1592 else:
1590 avgdata = self.byProfiles(data)
1593 avgdata = self.byProfiles(data)
1591
1594
1592
1595
1593 self.__lastdatatime = datatime
1596 self.__lastdatatime = datatime
1594
1597
1595 if avgdata == None:
1598 if avgdata == None:
1596 return None, None
1599 return None, None
1597
1600
1598 avgdatatime = self.__initime
1601 avgdatatime = self.__initime
1599
1602
1600 deltatime = datatime -self.__lastdatatime
1603 deltatime = datatime -self.__lastdatatime
1601
1604
1602 if not self.__withOverapping:
1605 if not self.__withOverapping:
1603 self.__initime = datatime
1606 self.__initime = datatime
1604 else:
1607 else:
1605 self.__initime += deltatime
1608 self.__initime += deltatime
1606
1609
1607 return avgdata, avgdatatime
1610 return avgdata, avgdatatime
1608
1611
1609 def run(self, dataOut, **kwargs):
1612 def run(self, dataOut, **kwargs):
1610
1613
1611 if not self.__isConfig:
1614 if not self.__isConfig:
1612 self.setup(**kwargs)
1615 self.setup(**kwargs)
1613 self.__isConfig = True
1616 self.__isConfig = True
1614
1617
1615 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1618 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1616
1619
1617 # dataOut.timeInterval *= n
1620 # dataOut.timeInterval *= n
1618 dataOut.flagNoData = True
1621 dataOut.flagNoData = True
1619
1622
1620 if self.__dataReady:
1623 if self.__dataReady:
1621 dataOut.data_spc = avgdata
1624 dataOut.data_spc = avgdata
1622 dataOut.nIncohInt *= self.n
1625 dataOut.nIncohInt *= self.n
1623 # dataOut.nCohInt *= self.n
1626 # dataOut.nCohInt *= self.n
1624 dataOut.utctime = avgdatatime
1627 dataOut.utctime = avgdatatime
1625 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1628 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1626 # dataOut.timeInterval = self.__timeInterval*self.n
1629 # dataOut.timeInterval = self.__timeInterval*self.n
1627 dataOut.flagNoData = False
1630 dataOut.flagNoData = False
1628
1631
1629
1632
1630
1633
1631
1634
1632 No newline at end of file
1635
General Comments 0
You need to be logged in to leave comments. Login now