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