##// END OF EJS Templates
Update test Julia_EEJ.py
Alexander Valdez -
r1685:2ca28c2f318e
parent child
Show More
@@ -1,1575 +1,1572
1 """
1 """
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 """
5 """
6 import os
6 import os
7 import sys
7 import 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 inspect
12 import inspect
13 import time
13 import time
14 import datetime
14 import datetime
15 import zmq
15 import zmq
16
16
17 from schainpy.model.proc.jroproc_base import Operation, MPDecorator
17 from schainpy.model.proc.jroproc_base import Operation, MPDecorator
18 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
18 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
19 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
19 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
20 from schainpy.utils import log
20 from schainpy.utils import log
21 import schainpy.admin
21 import schainpy.admin
22
22
23 LOCALTIME = True
23 LOCALTIME = True
24 DT_DIRECTIVES = {
24 DT_DIRECTIVES = {
25 '%Y': 4,
25 '%Y': 4,
26 '%y': 2,
26 '%y': 2,
27 '%m': 2,
27 '%m': 2,
28 '%d': 2,
28 '%d': 2,
29 '%j': 3,
29 '%j': 3,
30 '%H': 2,
30 '%H': 2,
31 '%M': 2,
31 '%M': 2,
32 '%S': 2,
32 '%S': 2,
33 '%f': 6
33 '%f': 6
34 }
34 }
35
35
36
36
37 def isNumber(cad):
37 def isNumber(cad):
38 """
38 """
39 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
39 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
40
40
41 Excepciones:
41 Excepciones:
42 Si un determinado string no puede ser convertido a numero
42 Si un determinado string no puede ser convertido a numero
43 Input:
43 Input:
44 str, string al cual se le analiza para determinar si convertible a un numero o no
44 str, string al cual se le analiza para determinar si convertible a un numero o no
45
45
46 Return:
46 Return:
47 True : si el string es uno numerico
47 True : si el string es uno numerico
48 False : no es un string numerico
48 False : no es un string numerico
49 """
49 """
50 try:
50 try:
51 float(cad)
51 float(cad)
52 return True
52 return True
53 except:
53 except:
54 return False
54 return False
55
55
56
56
57 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
57 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
58 """
58 """
59 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
59 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
60
60
61 Inputs:
61 Inputs:
62 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
62 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
63
63
64 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
64 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
65 segundos contados desde 01/01/1970.
65 segundos contados desde 01/01/1970.
66 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
66 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
67 segundos contados desde 01/01/1970.
67 segundos contados desde 01/01/1970.
68
68
69 Return:
69 Return:
70 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
70 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
71 fecha especificado, de lo contrario retorna False.
71 fecha especificado, de lo contrario retorna False.
72
72
73 Excepciones:
73 Excepciones:
74 Si el archivo no existe o no puede ser abierto
74 Si el archivo no existe o no puede ser abierto
75 Si la cabecera no puede ser leida.
75 Si la cabecera no puede ser leida.
76
76
77 """
77 """
78 basicHeaderObj = BasicHeader(LOCALTIME)
78 basicHeaderObj = BasicHeader(LOCALTIME)
79
79
80 try:
80 try:
81 fp = open(filename, 'rb')
81 fp = open(filename, 'rb')
82 except IOError:
82 except IOError:
83 print("The file %s can't be opened" % (filename))
83 print("The file %s can't be opened" % (filename))
84 return 0
84 return 0
85
85
86 sts = basicHeaderObj.read(fp)
86 sts = basicHeaderObj.read(fp)
87 fp.close()
87 fp.close()
88
88
89 if not(sts):
89 if not(sts):
90 print("Skipping the file %s because it has not a valid header" % (filename))
90 print("Skipping the file %s because it has not a valid header" % (filename))
91 return 0
91 return 0
92
92
93 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
93 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
94 return 0
94 return 0
95
95
96 return 1
96 return 1
97
97
98
98
99 def isTimeInRange(thisTime, startTime, endTime):
99 def isTimeInRange(thisTime, startTime, endTime):
100 if endTime >= startTime:
100 if endTime >= startTime:
101 if (thisTime < startTime) or (thisTime > endTime):
101 if (thisTime < startTime) or (thisTime > endTime):
102 return 0
102 return 0
103 return 1
103 return 1
104 else:
104 else:
105 if (thisTime < startTime) and (thisTime > endTime):
105 if (thisTime < startTime) and (thisTime > endTime):
106 return 0
106 return 0
107 return 1
107 return 1
108
108
109
109
110 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
110 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
111 """
111 """
112 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
112 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
113
113
114 Inputs:
114 Inputs:
115 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
115 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
116
116
117 startDate : fecha inicial del rango seleccionado en formato datetime.date
117 startDate : fecha inicial del rango seleccionado en formato datetime.date
118
118
119 endDate : fecha final del rango seleccionado en formato datetime.date
119 endDate : fecha final del rango seleccionado en formato datetime.date
120
120
121 startTime : tiempo inicial del rango seleccionado en formato datetime.time
121 startTime : tiempo inicial del rango seleccionado en formato datetime.time
122
122
123 endTime : tiempo final del rango seleccionado en formato datetime.time
123 endTime : tiempo final del rango seleccionado en formato datetime.time
124
124
125 Return:
125 Return:
126 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
126 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
127 fecha especificado, de lo contrario retorna False.
127 fecha especificado, de lo contrario retorna False.
128
128
129 Excepciones:
129 Excepciones:
130 Si el archivo no existe o no puede ser abierto
130 Si el archivo no existe o no puede ser abierto
131 Si la cabecera no puede ser leida.
131 Si la cabecera no puede ser leida.
132
132
133 """
133 """
134
134
135 try:
135 try:
136 fp = open(filename, 'rb')
136 fp = open(filename, 'rb')
137 except IOError:
137 except IOError:
138 print("The file %s can't be opened" % (filename))
138 print("The file %s can't be opened" % (filename))
139 return None
139 return None
140
140
141 firstBasicHeaderObj = BasicHeader(LOCALTIME)
141 firstBasicHeaderObj = BasicHeader(LOCALTIME)
142 systemHeaderObj = SystemHeader()
142 systemHeaderObj = SystemHeader()
143 radarControllerHeaderObj = RadarControllerHeader()
143 radarControllerHeaderObj = RadarControllerHeader()
144 processingHeaderObj = ProcessingHeader()
144 processingHeaderObj = ProcessingHeader()
145
145
146 lastBasicHeaderObj = BasicHeader(LOCALTIME)
146 lastBasicHeaderObj = BasicHeader(LOCALTIME)
147
147
148 sts = firstBasicHeaderObj.read(fp)
148 sts = firstBasicHeaderObj.read(fp)
149
149
150 if not(sts):
150 if not(sts):
151 print("[Reading] Skipping the file %s because it has not a valid header" % (filename))
151 print("[Reading] Skipping the file %s because it has not a valid header" % (filename))
152 return None
152 return None
153
153
154 if not systemHeaderObj.read(fp):
154 if not systemHeaderObj.read(fp):
155 return None
155 return None
156
156
157 if not radarControllerHeaderObj.read(fp):
157 if not radarControllerHeaderObj.read(fp):
158 return None
158 return None
159
159
160 if not processingHeaderObj.read(fp):
160 if not processingHeaderObj.read(fp):
161 return None
161 return None
162
162
163 filesize = os.path.getsize(filename)
163 filesize = os.path.getsize(filename)
164
164
165 offset = processingHeaderObj.blockSize + 24 # header size
165 offset = processingHeaderObj.blockSize + 24 # header size
166
166
167 if filesize <= offset:
167 if filesize <= offset:
168 print("[Reading] %s: This file has not enough data" % filename)
168 print("[Reading] %s: This file has not enough data" % filename)
169 return None
169 return None
170
170
171 fp.seek(-offset, 2)
171 fp.seek(-offset, 2)
172
172
173 sts = lastBasicHeaderObj.read(fp)
173 sts = lastBasicHeaderObj.read(fp)
174
174
175 fp.close()
175 fp.close()
176
176
177 thisDatetime = lastBasicHeaderObj.datatime
177 thisDatetime = lastBasicHeaderObj.datatime
178 thisTime_last_block = thisDatetime.time()
178 thisTime_last_block = thisDatetime.time()
179
179
180 thisDatetime = firstBasicHeaderObj.datatime
180 thisDatetime = firstBasicHeaderObj.datatime
181 thisDate = thisDatetime.date()
181 thisDate = thisDatetime.date()
182 thisTime_first_block = thisDatetime.time()
182 thisTime_first_block = thisDatetime.time()
183
183
184 # General case
184 # General case
185 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
185 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
186 #-----------o----------------------------o-----------
186 #-----------o----------------------------o-----------
187 # startTime endTime
187 # startTime endTime
188
188
189 if endTime >= startTime:
189 if endTime >= startTime:
190 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
190 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
191 return None
191 return None
192
192
193 return thisDatetime
193 return thisDatetime
194
194
195 # If endTime < startTime then endTime belongs to the next day
195 # If endTime < startTime then endTime belongs to the next day
196
196
197 #<<<<<<<<<<<o o>>>>>>>>>>>
197 #<<<<<<<<<<<o o>>>>>>>>>>>
198 #-----------o----------------------------o-----------
198 #-----------o----------------------------o-----------
199 # endTime startTime
199 # endTime startTime
200
200
201 if (thisDate == startDate) and (thisTime_last_block < startTime):
201 if (thisDate == startDate) and (thisTime_last_block < startTime):
202 return None
202 return None
203
203
204 if (thisDate == endDate) and (thisTime_first_block > endTime):
204 if (thisDate == endDate) and (thisTime_first_block > endTime):
205 return None
205 return None
206
206
207 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
207 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
208 return None
208 return None
209
209
210 return thisDatetime
210 return thisDatetime
211
211
212
212
213 def isFolderInDateRange(folder, startDate=None, endDate=None):
213 def isFolderInDateRange(folder, startDate=None, endDate=None):
214 """
214 """
215 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
215 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
216
216
217 Inputs:
217 Inputs:
218 folder : nombre completo del directorio.
218 folder : nombre completo del directorio.
219 Su formato deberia ser "/path_root/?YYYYDDD"
219 Su formato deberia ser "/path_root/?YYYYDDD"
220
220
221 siendo:
221 siendo:
222 YYYY : Anio (ejemplo 2015)
222 YYYY : Anio (ejemplo 2015)
223 DDD : Dia del anio (ejemplo 305)
223 DDD : Dia del anio (ejemplo 305)
224
224
225 startDate : fecha inicial del rango seleccionado en formato datetime.date
225 startDate : fecha inicial del rango seleccionado en formato datetime.date
226
226
227 endDate : fecha final del rango seleccionado en formato datetime.date
227 endDate : fecha final del rango seleccionado en formato datetime.date
228
228
229 Return:
229 Return:
230 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
230 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
231 fecha especificado, de lo contrario retorna False.
231 fecha especificado, de lo contrario retorna False.
232 Excepciones:
232 Excepciones:
233 Si el directorio no tiene el formato adecuado
233 Si el directorio no tiene el formato adecuado
234 """
234 """
235
235
236 basename = os.path.basename(folder)
236 basename = os.path.basename(folder)
237
237
238 if not isRadarFolder(basename):
238 if not isRadarFolder(basename):
239 print("The folder %s has not the rigth format" % folder)
239 print("The folder %s has not the rigth format" % folder)
240 return 0
240 return 0
241
241
242 if startDate and endDate:
242 if startDate and endDate:
243 thisDate = getDateFromRadarFolder(basename)
243 thisDate = getDateFromRadarFolder(basename)
244
244
245 if thisDate < startDate:
245 if thisDate < startDate:
246 return 0
246 return 0
247
247
248 if thisDate > endDate:
248 if thisDate > endDate:
249 return 0
249 return 0
250
250
251 return 1
251 return 1
252
252
253
253
254 def isFileInDateRange(filename, startDate=None, endDate=None):
254 def isFileInDateRange(filename, startDate=None, endDate=None):
255 """
255 """
256 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
256 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
257
257
258 Inputs:
258 Inputs:
259 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
259 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
260
260
261 Su formato deberia ser "?YYYYDDDsss"
261 Su formato deberia ser "?YYYYDDDsss"
262
262
263 siendo:
263 siendo:
264 YYYY : Anio (ejemplo 2015)
264 YYYY : Anio (ejemplo 2015)
265 DDD : Dia del anio (ejemplo 305)
265 DDD : Dia del anio (ejemplo 305)
266 sss : set
266 sss : set
267
267
268 startDate : fecha inicial del rango seleccionado en formato datetime.date
268 startDate : fecha inicial del rango seleccionado en formato datetime.date
269
269
270 endDate : fecha final del rango seleccionado en formato datetime.date
270 endDate : fecha final del rango seleccionado en formato datetime.date
271
271
272 Return:
272 Return:
273 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
273 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
274 fecha especificado, de lo contrario retorna False.
274 fecha especificado, de lo contrario retorna False.
275 Excepciones:
275 Excepciones:
276 Si el archivo no tiene el formato adecuado
276 Si el archivo no tiene el formato adecuado
277 """
277 """
278
278
279 basename = os.path.basename(filename)
279 basename = os.path.basename(filename)
280
280
281 if not isRadarFile(basename):
281 if not isRadarFile(basename):
282 print("The filename %s has not the rigth format" % filename)
282 print("The filename %s has not the rigth format" % filename)
283 return 0
283 return 0
284
284
285 if startDate and endDate:
285 if startDate and endDate:
286 thisDate = getDateFromRadarFile(basename)
286 thisDate = getDateFromRadarFile(basename)
287
287
288 if thisDate < startDate:
288 if thisDate < startDate:
289 return 0
289 return 0
290
290
291 if thisDate > endDate:
291 if thisDate > endDate:
292 return 0
292 return 0
293
293
294 return 1
294 return 1
295
295
296
296
297 def getFileFromSet(path, ext, set):
297 def getFileFromSet(path, ext, set):
298 validFilelist = []
298 validFilelist = []
299 fileList = os.listdir(path)
299 fileList = os.listdir(path)
300
300
301 # 0 1234 567 89A BCDE
301 # 0 1234 567 89A BCDE
302 # H YYYY DDD SSS .ext
302 # H YYYY DDD SSS .ext
303
303
304 for thisFile in fileList:
304 for thisFile in fileList:
305 try:
305 try:
306 year = int(thisFile[1:5])
306 year = int(thisFile[1:5])
307 doy = int(thisFile[5:8])
307 doy = int(thisFile[5:8])
308 except:
308 except:
309 continue
309 continue
310
310
311 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
311 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
312 continue
312 continue
313
313
314 validFilelist.append(thisFile)
314 validFilelist.append(thisFile)
315
315
316 myfile = fnmatch.filter(
316 myfile = fnmatch.filter(
317 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
317 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
318
318
319 if len(myfile) != 0:
319 if len(myfile) != 0:
320 return myfile[0]
320 return myfile[0]
321 else:
321 else:
322 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
322 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
323 print('the filename %s does not exist' % filename)
323 print('the filename %s does not exist' % filename)
324 print('...going to the last file: ')
324 print('...going to the last file: ')
325
325
326 if validFilelist:
326 if validFilelist:
327 validFilelist = sorted(validFilelist, key=str.lower)
327 validFilelist = sorted(validFilelist, key=str.lower)
328 return validFilelist[-1]
328 return validFilelist[-1]
329
329
330 return None
330 return None
331
331
332
332
333 def getlastFileFromPath(path, ext):
333 def getlastFileFromPath(path, ext):
334 """
334 """
335 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
335 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
336 al final de la depuracion devuelve el ultimo file de la lista que quedo.
336 al final de la depuracion devuelve el ultimo file de la lista que quedo.
337
337
338 Input:
338 Input:
339 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
339 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
340 ext : extension de los files contenidos en una carpeta
340 ext : extension de los files contenidos en una carpeta
341
341
342 Return:
342 Return:
343 El ultimo file de una determinada carpeta, no se considera el path.
343 El ultimo file de una determinada carpeta, no se considera el path.
344 """
344 """
345 validFilelist = []
345 validFilelist = []
346 fileList = os.listdir(path)
346 fileList = os.listdir(path)
347
347
348 # 0 1234 567 89A BCDE
348 # 0 1234 567 89A BCDE
349 # H YYYY DDD SSS .ext
349 # H YYYY DDD SSS .ext
350
350
351 for thisFile in fileList:
351 for thisFile in fileList:
352
352
353 year = thisFile[1:5]
353 year = thisFile[1:5]
354 if not isNumber(year):
354 if not isNumber(year):
355 continue
355 continue
356
356
357 doy = thisFile[5:8]
357 doy = thisFile[5:8]
358 if not isNumber(doy):
358 if not isNumber(doy):
359 continue
359 continue
360
360
361 year = int(year)
361 year = int(year)
362 doy = int(doy)
362 doy = int(doy)
363
363
364 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
364 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
365 continue
365 continue
366
366
367 validFilelist.append(thisFile)
367 validFilelist.append(thisFile)
368
368
369 if validFilelist:
369 if validFilelist:
370 validFilelist = sorted(validFilelist, key=str.lower)
370 validFilelist = sorted(validFilelist, key=str.lower)
371 return validFilelist[-1]
371 return validFilelist[-1]
372
372
373 return None
373 return None
374
374
375
375
376 def isRadarFolder(folder):
376 def isRadarFolder(folder):
377 try:
377 try:
378 year = int(folder[1:5])
378 year = int(folder[1:5])
379 doy = int(folder[5:8])
379 doy = int(folder[5:8])
380 except:
380 except:
381 return 0
381 return 0
382
382
383 return 1
383 return 1
384
384
385
385
386 def isRadarFile(file):
386 def isRadarFile(file):
387 try:
387 try:
388 year = int(file[1:5])
388 year = int(file[1:5])
389 doy = int(file[5:8])
389 doy = int(file[5:8])
390 set = int(file[8:11])
390 set = int(file[8:11])
391 except:
391 except:
392 return 0
392 return 0
393
393
394 return 1
394 return 1
395
395
396
396
397 def getDateFromRadarFile(file):
397 def getDateFromRadarFile(file):
398 try:
398 try:
399 year = int(file[1:5])
399 year = int(file[1:5])
400 doy = int(file[5:8])
400 doy = int(file[5:8])
401 set = int(file[8:11])
401 set = int(file[8:11])
402 except:
402 except:
403 return None
403 return None
404
404
405 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
405 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
406 return thisDate
406 return thisDate
407
407
408
408
409 def getDateFromRadarFolder(folder):
409 def getDateFromRadarFolder(folder):
410 try:
410 try:
411 year = int(folder[1:5])
411 year = int(folder[1:5])
412 doy = int(folder[5:8])
412 doy = int(folder[5:8])
413 except:
413 except:
414 return None
414 return None
415
415
416 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
416 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
417 return thisDate
417 return thisDate
418
418
419 def parse_format(s, fmt):
419 def parse_format(s, fmt):
420
420
421 for i in range(fmt.count('%')):
421 for i in range(fmt.count('%')):
422 x = fmt.index('%')
422 x = fmt.index('%')
423 d = DT_DIRECTIVES[fmt[x:x+2]]
423 d = DT_DIRECTIVES[fmt[x:x+2]]
424 fmt = fmt.replace(fmt[x:x+2], s[x:x+d])
424 fmt = fmt.replace(fmt[x:x+2], s[x:x+d])
425 return fmt
425 return fmt
426
426
427 class Reader(object):
427 class Reader(object):
428
428
429 c = 3E8
429 c = 3E8
430 isConfig = False
430 isConfig = False
431 dtype = None
431 dtype = None
432 pathList = []
432 pathList = []
433 filenameList = []
433 filenameList = []
434 datetimeList = []
434 datetimeList = []
435 filename = None
435 filename = None
436 ext = None
436 ext = None
437 flagIsNewFile = 1
437 flagIsNewFile = 1
438 flagDiscontinuousBlock = 0
438 flagDiscontinuousBlock = 0
439 flagIsNewBlock = 0
439 flagIsNewBlock = 0
440 flagNoMoreFiles = 0
440 flagNoMoreFiles = 0
441 fp = None
441 fp = None
442 firstHeaderSize = 0
442 firstHeaderSize = 0
443 basicHeaderSize = 24
443 basicHeaderSize = 24
444 versionFile = 1103
444 versionFile = 1103
445 fileSize = None
445 fileSize = None
446 fileSizeByHeader = None
446 fileSizeByHeader = None
447 fileIndex = -1
447 fileIndex = -1
448 profileIndex = None
448 profileIndex = None
449 blockIndex = 0
449 blockIndex = 0
450 nTotalBlocks = 0
450 nTotalBlocks = 0
451 maxTimeStep = 30
451 maxTimeStep = 30
452 lastUTTime = None
452 lastUTTime = None
453 datablock = None
453 datablock = None
454 dataOut = None
454 dataOut = None
455 getByBlock = False
455 getByBlock = False
456 path = None
456 path = None
457 startDate = None
457 startDate = None
458 endDate = None
458 endDate = None
459 startTime = datetime.time(0, 0, 0)
459 startTime = datetime.time(0, 0, 0)
460 endTime = datetime.time(23, 59, 59)
460 endTime = datetime.time(23, 59, 59)
461 set = None
461 set = None
462 expLabel = ""
462 expLabel = ""
463 online = False
463 online = False
464 delay = 60
464 delay = 60
465 nTries = 3 # quantity tries
465 nTries = 3 # quantity tries
466 nFiles = 3 # number of files for searching
466 nFiles = 3 # number of files for searching
467 walk = True
467 walk = True
468 getblock = False
468 getblock = False
469 nTxs = 1
469 nTxs = 1
470 realtime = False
470 realtime = False
471 blocksize = 0
471 blocksize = 0
472 blocktime = None
472 blocktime = None
473 warnings = True
473 warnings = True
474 verbose = True
474 verbose = True
475 server = None
475 server = None
476 format = None
476 format = None
477 oneDDict = None
477 oneDDict = None
478 twoDDict = None
478 twoDDict = None
479 independentParam = None
479 independentParam = None
480 filefmt = None
480 filefmt = None
481 folderfmt = None
481 folderfmt = None
482 open_file = open
482 open_file = open
483 open_mode = 'rb'
483 open_mode = 'rb'
484
484
485 def run(self):
485 def run(self):
486
486
487 raise NotImplementedError
487 raise NotImplementedError
488
488
489 def getAllowedArgs(self):
489 def getAllowedArgs(self):
490 if hasattr(self, '__attrs__'):
490 if hasattr(self, '__attrs__'):
491 return self.__attrs__
491 return self.__attrs__
492 else:
492 else:
493 return inspect.getargspec(self.run).args
493 return inspect.getargspec(self.run).args
494
494
495 def set_kwargs(self, **kwargs):
495 def set_kwargs(self, **kwargs):
496
496
497 for key, value in kwargs.items():
497 for key, value in kwargs.items():
498 setattr(self, key, value)
498 setattr(self, key, value)
499
499
500 def find_folders(self, path, startDate, endDate, folderfmt, last=False):
500 def find_folders(self, path, startDate, endDate, folderfmt, last=False):
501
501
502 folders = [x for f in path.split(',')
502 folders = [x for f in path.split(',')
503 for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))]
503 for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))]
504 folders.sort()
504 folders.sort()
505
505
506 if last:
506 if last:
507 folders = [folders[-1]]
507 folders = [folders[-1]]
508
508
509 for folder in folders:
509 for folder in folders:
510 try:
510 try:
511 dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date()
511 dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date()
512 if dt >= startDate and dt <= endDate:
512 if dt >= startDate and dt <= endDate:
513 yield os.path.join(path, folder)
513 yield os.path.join(path, folder)
514 else:
514 else:
515 log.log('Skiping folder {}'.format(folder), self.name)
515 log.log('Skiping folder {}'.format(folder), self.name)
516 except Exception as e:
516 except Exception as e:
517 log.log('Skiping folder {}'.format(folder), self.name)
517 log.log('Skiping folder {}'.format(folder), self.name)
518 continue
518 continue
519 return
519 return
520
520
521 def find_files(self, folders, ext, filefmt, startDate=None, endDate=None,
521 def find_files(self, folders, ext, filefmt, startDate=None, endDate=None,
522 expLabel='', last=False):
522 expLabel='', last=False):
523
523 for path in folders:
524 for path in folders:
524 files = glob.glob1(path+'/'+expLabel, '*{}'.format(ext))
525 files = glob.glob1(path, '*{}'.format(ext))
526 files.sort()
525 files.sort()
527 if last:
526 if last:
528 if files:
527 if files:
529 fo = files[-1]
528 fo = files[-1]
530 try:
529 try:
531 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
530 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
532 yield os.path.join(path, expLabel, fo)
531 yield os.path.join(path, expLabel, fo)
533 except Exception as e:
532 except Exception as e:
534 pass
533 pass
535 return
534 return
536 else:
535 else:
537 return
536 return
538
537
539 for fo in files:
538 for fo in files:
540 try:
539 try:
541 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
540 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
542 if dt >= startDate and dt <= endDate:
541 if dt >= startDate and dt <= endDate:
543 yield os.path.join(path, expLabel, fo)
542 yield os.path.join(path, expLabel, fo)
544 else:
543 else:
545 log.log('Skiping file {}'.format(fo), self.name)
544 log.log('Skiping file {}'.format(fo), self.name)
546 except Exception as e:
545 except Exception as e:
547 log.log('Skiping file {}'.format(fo), self.name)
546 log.log('Skiping file {}'.format(fo), self.name)
548 continue
547 continue
549
548
550 def searchFilesOffLine(self, path, startDate, endDate,
549 def searchFilesOffLine(self, path, startDate, endDate,
551 expLabel, ext, walk,
550 expLabel, ext, walk,
552 filefmt, folderfmt):
551 filefmt, folderfmt):
553 """Search files in offline mode for the given arguments
552 """Search files in offline mode for the given arguments
554
553
555 Return:
554 Return:
556 Generator of files
555 Generator of files
557 """
556 """
558
557
559 if walk:
558 if walk:
560 folders = self.find_folders(
559 folders = self.find_folders(
561 path, startDate, endDate, folderfmt)
560 path, startDate, endDate, folderfmt)
562 else:
561 else:
563 folders = path.split(',')
562 folders = path.split(',')
564
563
565 return self.find_files(
564 return self.find_files(
566 folders, ext, filefmt, startDate, endDate, expLabel)
565 folders, ext, filefmt, startDate, endDate, expLabel)
567
566
568 def searchFilesOnLine(self, path, startDate, endDate,
567 def searchFilesOnLine(self, path, startDate, endDate,
569 expLabel, ext, walk,
568 expLabel, ext, walk,
570 filefmt, folderfmt):
569 filefmt, folderfmt):
571 """Search for the last file of the last folder
570 """Search for the last file of the last folder
572
571
573 Arguments:
572 Arguments:
574 path : carpeta donde estan contenidos los files que contiene data
573 path : carpeta donde estan contenidos los files que contiene data
575 expLabel : Nombre del subexperimento (subfolder)
574 expLabel : Nombre del subexperimento (subfolder)
576 ext : extension de los files
575 ext : extension de los files
577 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
576 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
578
577
579 Return:
578 Return:
580 generator with the full path of last filename
579 generator with the full path of last filename
581 """
580 """
582
581
583 if walk:
582 if walk:
584 folders = self.find_folders(
583 folders = self.find_folders(
585 path, startDate, endDate, folderfmt, last=True)
584 path, startDate, endDate, folderfmt, last=True)
586 else:
585 else:
587 folders = path.split(',')
586 folders = path.split(',')
588
587
589 return self.find_files(
588 return self.find_files(
590 folders, ext, filefmt, startDate, endDate, expLabel, last=True)
589 folders, ext, filefmt, startDate, endDate, expLabel, last=True)
591
590
592 def setNextFile(self):
591 def setNextFile(self):
593 """Set the next file to be readed open it and parse de file header"""
592 """Set the next file to be readed open it and parse de file header"""
594
593
595 while True:
594 while True:
596 if self.fp != None:
595 if self.fp != None:
597 self.fp.close()
596 self.fp.close()
598
597
599 if self.online:
598 if self.online:
600 newFile = self.setNextFileOnline()
599 newFile = self.setNextFileOnline()
601 else:
600 else:
602 newFile = self.setNextFileOffline()
601 newFile = self.setNextFileOffline()
603
604 if not(newFile):
602 if not(newFile):
605 if self.online:
603 if self.online:
606 raise schainpy.admin.SchainError('Time to wait for new files reach')
604 raise schainpy.admin.SchainError('Time to wait for new files reach')
607 else:
605 else:
608 if self.fileIndex == -1:
606 if self.fileIndex == -1:
609 raise schainpy.admin.SchainWarning('No files found in the given path')
607 raise schainpy.admin.SchainWarning('No files found in the given path')
610 else:
608 else:
611 raise schainpy.admin.SchainWarning('No more files to read')
609 raise schainpy.admin.SchainWarning('No more files to read')
612
610
613 if self.verifyFile(self.filename):
611 if self.verifyFile(self.filename):
614 break
612 break
615
613
616 log.log('Opening file: %s' % self.filename, self.name)
614 log.log('Opening file: %s' % self.filename, self.name)
617
615
618 self.readFirstHeader()
616 self.readFirstHeader()
619 self.nReadBlocks = 0
617 self.nReadBlocks = 0
620
618
621 def setNextFileOnline(self):
619 def setNextFileOnline(self):
622 """Check for the next file to be readed in online mode.
620 """Check for the next file to be readed in online mode.
623
621
624 Set:
622 Set:
625 self.filename
623 self.filename
626 self.fp
624 self.fp
627 self.filesize
625 self.filesize
628
626
629 Return:
627 Return:
630 boolean
628 boolean
631
629
632 """
630 """
631
633 nextFile = True
632 nextFile = True
634 nextDay = False
633 nextDay = False
635
634
636 for nFiles in range(self.nFiles+1):
635 for nFiles in range(self.nFiles+1):
637 for nTries in range(self.nTries):
636 for nTries in range(self.nTries):
638 fullfilename, filename = self.checkForRealPath(nextFile, nextDay)
637 fullfilename, filename = self.checkForRealPath(nextFile, nextDay)
639 if fullfilename is not None:
638 if fullfilename is not None:
640 break
639 break
641 log.warning(
640 log.warning(
642 "Waiting %0.2f sec for the next file: \"%s\" , try %02d ..." % (self.delay, filename, nTries + 1),
641 "Waiting %0.2f sec for the next file: \"%s\" , try %02d ..." % (self.delay, filename, nTries + 1),
643 self.name)
642 self.name)
644 time.sleep(self.delay)
643 time.sleep(self.delay)
645 nextFile = False
644 nextFile = False
646 continue
645 continue
647
646
648 if fullfilename is not None:
647 if fullfilename is not None:
649 break
648 break
650
649
651 self.nTries = 1
650 self.nTries = 1
652 nextFile = True
651 nextFile = True
653
652
654 if nFiles == (self.nFiles - 1):
653 if nFiles == (self.nFiles - 1):
655 log.log('Trying with next day...', self.name)
654 log.log('Trying with next day...', self.name)
656 nextDay = True
655 nextDay = True
657 self.nTries = 3
656 self.nTries = 3
658
657
659 if fullfilename:
658 if fullfilename:
660 self.fileSize = os.path.getsize(fullfilename)
659 self.fileSize = os.path.getsize(fullfilename)
661 self.filename = fullfilename
660 self.filename = fullfilename
662 self.flagIsNewFile = 1
661 self.flagIsNewFile = 1
663 if self.fp != None:
662 if self.fp != None:
664 self.fp.close()
663 self.fp.close()
665 self.fp = self.open_file(fullfilename, self.open_mode)
664 self.fp = self.open_file(fullfilename, self.open_mode)
666 self.flagNoMoreFiles = 0
665 self.flagNoMoreFiles = 0
667 self.fileIndex += 1
666 self.fileIndex += 1
668 return 1
667 return 1
669 else:
668 else:
670 return 0
669 return 0
671
670
672 def setNextFileOffline(self):
671 def setNextFileOffline(self):
673 """Open the next file to be readed in offline mode"""
672 """Open the next file to be readed in offline mode"""
674
673
675 try:
674 try:
676 filename = next(self.filenameList)
675 filename = next(self.filenameList)
677 self.fileIndex +=1
676 self.fileIndex +=1
678 except StopIteration:
677 except StopIteration:
679 self.flagNoMoreFiles = 1
678 self.flagNoMoreFiles = 1
680 return 0
679 return 0
681
680
682 self.filename = filename
681 self.filename = filename
683 self.fileSize = os.path.getsize(filename)
682 self.fileSize = os.path.getsize(filename)
684 self.fp = self.open_file(filename, self.open_mode)
683 self.fp = self.open_file(filename, self.open_mode)
685 self.flagIsNewFile = 1
684 self.flagIsNewFile = 1
686
685
687 return 1
686 return 1
688
687
689 @staticmethod
688 @staticmethod
690 def isDateTimeInRange(dt, startDate, endDate, startTime, endTime):
689 def isDateTimeInRange(dt, startDate, endDate, startTime, endTime):
691 """Check if the given datetime is in range"""
690 """Check if the given datetime is in range"""
692
691
693 if startDate <= dt.date() <= endDate:
692 if startDate <= dt.date() <= endDate:
694 if startTime <= dt.time() <= endTime:
693 if startTime <= dt.time() <= endTime:
695 return True
694 return True
696 return False
695 return False
697
696
698 def verifyFile(self, filename):
697 def verifyFile(self, filename):
699 """Check for a valid file
698 """Check for a valid file
700
699
701 Arguments:
700 Arguments:
702 filename -- full path filename
701 filename -- full path filename
703
702
704 Return:
703 Return:
705 boolean
704 boolean
706 """
705 """
707
706
708 return True
707 return True
709
708
710 def checkForRealPath(self, nextFile, nextDay):
709 def checkForRealPath(self, nextFile, nextDay):
711 """Check if the next file to be readed exists"""
710 """Check if the next file to be readed exists"""
712
711
713 raise NotImplementedError
712 raise NotImplementedError
714
713
715 def readFirstHeader(self):
714 def readFirstHeader(self):
716 """Parse the file header"""
715 """Parse the file header"""
717
716
718 pass
717 pass
719
718
720 def waitDataBlock(self, pointer_location, blocksize=None):
719 def waitDataBlock(self, pointer_location, blocksize=None):
721 """
720 """
722 """
721 """
723
722
724 currentPointer = pointer_location
723 currentPointer = pointer_location
725 if blocksize is None:
724 if blocksize is None:
726 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
725 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
727 else:
726 else:
728 neededSize = blocksize
727 neededSize = blocksize
729
728
730 for nTries in range(self.nTries):
729 for nTries in range(self.nTries):
731 self.fp.close()
730 self.fp.close()
732 self.fp = open(self.filename, 'rb')
731 self.fp = open(self.filename, 'rb')
733 self.fp.seek(currentPointer)
732 self.fp.seek(currentPointer)
734
733
735 self.fileSize = os.path.getsize(self.filename)
734 self.fileSize = os.path.getsize(self.filename)
736 currentSize = self.fileSize - currentPointer
735 currentSize = self.fileSize - currentPointer
737
736
738 if (currentSize >= neededSize):
737 if (currentSize >= neededSize):
739 return 1
738 return 1
740
739
741 log.warning(
740 log.warning(
742 "Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1),
741 "Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1),
743 self.name
742 self.name
744 )
743 )
745 time.sleep(self.delay)
744 time.sleep(self.delay)
746
745
747 return 0
746 return 0
748
747
749 class JRODataReader(Reader):
748 class JRODataReader(Reader):
750
749
751 utc = 0
750 utc = 0
752 nReadBlocks = 0
751 nReadBlocks = 0
753 foldercounter = 0
752 foldercounter = 0
754 firstHeaderSize = 0
753 firstHeaderSize = 0
755 basicHeaderSize = 24
754 basicHeaderSize = 24
756 __isFirstTimeOnline = 1
755 __isFirstTimeOnline = 1
757 filefmt = "*%Y%j***"
756 filefmt = "*%Y%j***"
758 folderfmt = "*%Y%j"
757 folderfmt = "*%Y%j"
759 __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'online', 'delay', 'walk']
758 __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'online', 'delay', 'walk']
760
759
761 def getDtypeWidth(self):
760 def getDtypeWidth(self):
762
761
763 dtype_index = get_dtype_index(self.dtype)
762 dtype_index = get_dtype_index(self.dtype)
764 dtype_width = get_dtype_width(dtype_index)
763 dtype_width = get_dtype_width(dtype_index)
765
764
766 return dtype_width
765 return dtype_width
767
766
768 def checkForRealPath(self, nextFile, nextDay):
767 def checkForRealPath(self, nextFile, nextDay):
769 """Check if the next file to be readed exists.
768 """Check if the next file to be readed exists.
770
769
771 Example :
770 Example :
772 nombre correcto del file es .../.../D2009307/P2009307367.ext
771 nombre correcto del file es .../.../D2009307/P2009307367.ext
773
772
774 Entonces la funcion prueba con las siguientes combinaciones
773 Entonces la funcion prueba con las siguientes combinaciones
775 .../.../y2009307367.ext
774 .../.../y2009307367.ext
776 .../.../Y2009307367.ext
775 .../.../Y2009307367.ext
777 .../.../x2009307/y2009307367.ext
776 .../.../x2009307/y2009307367.ext
778 .../.../x2009307/Y2009307367.ext
777 .../.../x2009307/Y2009307367.ext
779 .../.../X2009307/y2009307367.ext
778 .../.../X2009307/y2009307367.ext
780 .../.../X2009307/Y2009307367.ext
779 .../.../X2009307/Y2009307367.ext
781 siendo para este caso, la ultima combinacion de letras, identica al file buscado
780 siendo para este caso, la ultima combinacion de letras, identica al file buscado
782
781
783 Return:
782 Return:
784 str -- fullpath of the file
783 str -- fullpath of the file
785 """
784 """
786
785
787
788 if nextFile:
786 if nextFile:
789 self.set += 1
787 self.set += 1
790 if nextDay:
788 if nextDay:
791 self.set = 0
789 self.set = 0
792 self.doy += 1
790 self.doy += 1
793 foldercounter = 0
791 foldercounter = 0
794 prefixDirList = [None, 'd', 'D']
792 prefixDirList = [None, 'd', 'D']
795 if self.ext.lower() == ".r": # voltage
793 if self.ext.lower() == ".r": # voltage
796 prefixFileList = ['d', 'D']
794 prefixFileList = ['d', 'D']
797 elif self.ext.lower() == ".pdata": # spectra
795 elif self.ext.lower() == ".pdata": # spectra
798 prefixFileList = ['p', 'P']
796 prefixFileList = ['p', 'P']
799
797
800 # barrido por las combinaciones posibles
798 # barrido por las combinaciones posibles
801 for prefixDir in prefixDirList:
799 for prefixDir in prefixDirList:
802 thispath = self.path
800 thispath = self.path
803 if prefixDir != None:
801 if prefixDir != None:
804 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
802 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
805 if foldercounter == 0:
803 if foldercounter == 0:
806 thispath = os.path.join(self.path, "%s%04d%03d" %
804 thispath = os.path.join(self.path, "%s%04d%03d" %
807 (prefixDir, self.year, self.doy))
805 (prefixDir, self.year, self.doy))
808 else:
806 else:
809 thispath = os.path.join(self.path, "%s%04d%03d_%02d" % (
807 thispath = os.path.join(self.path, "%s%04d%03d_%02d" % (
810 prefixDir, self.year, self.doy, foldercounter))
808 prefixDir, self.year, self.doy, foldercounter))
811 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
809 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
812 # formo el nombre del file xYYYYDDDSSS.ext
810 # formo el nombre del file xYYYYDDDSSS.ext
813 filename = "%s%04d%03d%03d%s" % (prefixFile, self.year, self.doy, self.set, self.ext)
811 filename = "%s%04d%03d%03d%s" % (prefixFile, self.year, self.doy, self.set, self.ext)
814 fullfilename = os.path.join(
812 fullfilename = os.path.join(
815 thispath, filename)
813 thispath, filename)
816
814
817 if os.path.exists(fullfilename):
815 if os.path.exists(fullfilename):
818 return fullfilename, filename
816 return fullfilename, filename
819
817
820 return None, filename
818 return None, filename
821
819
822 def __waitNewBlock(self):
820 def __waitNewBlock(self):
823 """
821 """
824 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
822 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
825
823
826 Si el modo de lectura es OffLine siempre retorn 0
824 Si el modo de lectura es OffLine siempre retorn 0
827 """
825 """
828 if not self.online:
826 if not self.online:
829 return 0
827 return 0
830
828
831 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
829 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
832 return 0
830 return 0
833
831
834 currentPointer = self.fp.tell()
832 currentPointer = self.fp.tell()
835
833
836 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
834 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
837
835
838 for nTries in range(self.nTries):
836 for nTries in range(self.nTries):
839
837
840 self.fp.close()
838 self.fp.close()
841 self.fp = open(self.filename, 'rb')
839 self.fp = open(self.filename, 'rb')
842 self.fp.seek(currentPointer)
840 self.fp.seek(currentPointer)
843
841
844 self.fileSize = os.path.getsize(self.filename)
842 self.fileSize = os.path.getsize(self.filename)
845 currentSize = self.fileSize - currentPointer
843 currentSize = self.fileSize - currentPointer
846
844
847 if (currentSize >= neededSize):
845 if (currentSize >= neededSize):
848 self.basicHeaderObj.read(self.fp)
846 self.basicHeaderObj.read(self.fp)
849 return 1
847 return 1
850
848
851 if self.fileSize == self.fileSizeByHeader:
849 if self.fileSize == self.fileSizeByHeader:
852 # self.flagEoF = True
850 # self.flagEoF = True
853 return 0
851 return 0
854
852
855 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
853 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
856 time.sleep(self.delay)
854 time.sleep(self.delay)
857
855
858 return 0
856 return 0
859
857
860 def __setNewBlock(self):
858 def __setNewBlock(self):
861
859
862 if self.fp == None:
860 if self.fp == None:
863 return 0
861 return 0
864
862
865 if self.flagIsNewFile:
863 if self.flagIsNewFile:
866 self.lastUTTime = self.basicHeaderObj.utc
864 self.lastUTTime = self.basicHeaderObj.utc
867 return 1
865 return 1
868
866
869 if self.realtime:
867 if self.realtime:
870 self.flagDiscontinuousBlock = 1
868 self.flagDiscontinuousBlock = 1
871 if not(self.setNextFile()):
869 if not(self.setNextFile()):
872 return 0
870 return 0
873 else:
871 else:
874 return 1
872 return 1
875
873
876 currentSize = self.fileSize - self.fp.tell()
874 currentSize = self.fileSize - self.fp.tell()
877 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
875 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
878
876
879 if (currentSize >= neededSize):
877 if (currentSize >= neededSize):
880 self.basicHeaderObj.read(self.fp)
878 self.basicHeaderObj.read(self.fp)
881 self.lastUTTime = self.basicHeaderObj.utc
879 self.lastUTTime = self.basicHeaderObj.utc
882 return 1
880 return 1
883
881
884 if self.__waitNewBlock():
882 if self.__waitNewBlock():
885 self.lastUTTime = self.basicHeaderObj.utc
883 self.lastUTTime = self.basicHeaderObj.utc
886 return 1
884 return 1
887
885
888 if not(self.setNextFile()):
886 if not(self.setNextFile()):
889 return 0
887 return 0
890
888
891 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
889 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
892 self.lastUTTime = self.basicHeaderObj.utc
890 self.lastUTTime = self.basicHeaderObj.utc
893
891
894 self.flagDiscontinuousBlock = 0
892 self.flagDiscontinuousBlock = 0
895
896 if deltaTime > self.maxTimeStep:
893 if deltaTime > self.maxTimeStep:
897 self.flagDiscontinuousBlock = 1
894 self.flagDiscontinuousBlock = 1
898
895
899 return 1
896 return 1
900
897
901 def readNextBlock(self):
898 def readNextBlock(self):
902
899
903 while True:
900 while True:
904 if not(self.__setNewBlock()):
901 if not(self.__setNewBlock()):
905 continue
902 continue
906
903
907 if not(self.readBlock()):
904 if not(self.readBlock()):
908 return 0
905 return 0
909
906
910 self.getBasicHeader()
907 self.getBasicHeader()
911
908
912 if not self.isDateTimeInRange(self.dataOut.datatime, self.startDate, self.endDate, self.startTime, self.endTime):
909 if not self.isDateTimeInRange(self.dataOut.datatime, self.startDate, self.endDate, self.startTime, self.endTime):
913 print("[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
910 print("[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
914 self.processingHeaderObj.dataBlocksPerFile,
911 self.processingHeaderObj.dataBlocksPerFile,
915 self.dataOut.datatime.ctime()))
912 self.dataOut.datatime.ctime()))
916 continue
913 continue
917
914
918 break
915 break
919
916
920 if self.verbose:
917 if self.verbose:
921 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
918 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
922 self.processingHeaderObj.dataBlocksPerFile,
919 self.processingHeaderObj.dataBlocksPerFile,
923 self.dataOut.datatime.ctime()))
920 self.dataOut.datatime.ctime()))
924 return 1
921 return 1
925
922
926 def readFirstHeader(self):
923 def readFirstHeader(self):
927
924
928 self.basicHeaderObj.read(self.fp)
925 self.basicHeaderObj.read(self.fp)
929 self.systemHeaderObj.read(self.fp)
926 self.systemHeaderObj.read(self.fp)
930 self.radarControllerHeaderObj.read(self.fp)
927 self.radarControllerHeaderObj.read(self.fp)
931 self.processingHeaderObj.read(self.fp)
928 self.processingHeaderObj.read(self.fp)
932 self.firstHeaderSize = self.basicHeaderObj.size
929 self.firstHeaderSize = self.basicHeaderObj.size
933
930
934 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
931 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
935 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
932 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
936 if datatype == 0:
933 if datatype == 0:
937 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
934 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
938 elif datatype == 1:
935 elif datatype == 1:
939 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
936 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
940 elif datatype == 2:
937 elif datatype == 2:
941 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
938 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
942 elif datatype == 3:
939 elif datatype == 3:
943 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
940 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
944 elif datatype == 4:
941 elif datatype == 4:
945 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
942 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
946 elif datatype == 5:
943 elif datatype == 5:
947 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
944 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
948 else:
945 else:
949 raise ValueError('Data type was not defined')
946 raise ValueError('Data type was not defined')
950
947
951 self.dtype = datatype_str
948 self.dtype = datatype_str
952 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
949 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
953 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
950 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
954 self.firstHeaderSize + self.basicHeaderSize * \
951 self.firstHeaderSize + self.basicHeaderSize * \
955 (self.processingHeaderObj.dataBlocksPerFile - 1)
952 (self.processingHeaderObj.dataBlocksPerFile - 1)
956 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
953 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
957 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
954 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
958 self.getBlockDimension()
955 self.getBlockDimension()
959
956
960 def verifyFile(self, filename):
957 def verifyFile(self, filename):
961
958
962 flag = True
959 flag = True
963
960
964 try:
961 try:
965 fp = open(filename, 'rb')
962 fp = open(filename, 'rb')
966 except IOError:
963 except IOError:
967 log.error("File {} can't be opened".format(filename), self.name)
964 log.error("File {} can't be opened".format(filename), self.name)
968 return False
965 return False
969
966
970 if self.online and self.waitDataBlock(0):
967 if self.online and self.waitDataBlock(0):
971 pass
968 pass
972
969
973 basicHeaderObj = BasicHeader(LOCALTIME)
970 basicHeaderObj = BasicHeader(LOCALTIME)
974 systemHeaderObj = SystemHeader()
971 systemHeaderObj = SystemHeader()
975 radarControllerHeaderObj = RadarControllerHeader()
972 radarControllerHeaderObj = RadarControllerHeader()
976 processingHeaderObj = ProcessingHeader()
973 processingHeaderObj = ProcessingHeader()
977
974
978 if not(basicHeaderObj.read(fp)):
975 if not(basicHeaderObj.read(fp)):
979 flag = False
976 flag = False
980 if not(systemHeaderObj.read(fp)):
977 if not(systemHeaderObj.read(fp)):
981 flag = False
978 flag = False
982 if not(radarControllerHeaderObj.read(fp)):
979 if not(radarControllerHeaderObj.read(fp)):
983 flag = False
980 flag = False
984 if not(processingHeaderObj.read(fp)):
981 if not(processingHeaderObj.read(fp)):
985 flag = False
982 flag = False
986 if not self.online:
983 if not self.online:
987 dt1 = basicHeaderObj.datatime
984 dt1 = basicHeaderObj.datatime
988 pos = self.fileSize-processingHeaderObj.blockSize-24
985 pos = self.fileSize-processingHeaderObj.blockSize-24
989 if pos<0:
986 if pos<0:
990 flag = False
987 flag = False
991 log.error('Invalid size for file: {}'.format(self.filename), self.name)
988 log.error('Invalid size for file: {}'.format(self.filename), self.name)
992 else:
989 else:
993 fp.seek(pos)
990 fp.seek(pos)
994 if not(basicHeaderObj.read(fp)):
991 if not(basicHeaderObj.read(fp)):
995 flag = False
992 flag = False
996 dt2 = basicHeaderObj.datatime
993 dt2 = basicHeaderObj.datatime
997 if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \
994 if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \
998 self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime):
995 self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime):
999 flag = False
996 flag = False
1000
997
1001 fp.close()
998 fp.close()
1002 return flag
999 return flag
1003
1000
1004 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1001 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1005
1002
1006 path_empty = True
1003 path_empty = True
1007
1004
1008 dateList = []
1005 dateList = []
1009 pathList = []
1006 pathList = []
1010
1007
1011 multi_path = path.split(',')
1008 multi_path = path.split(',')
1012
1009
1013 if not walk:
1010 if not walk:
1014
1011
1015 for single_path in multi_path:
1012 for single_path in multi_path:
1016
1013
1017 if not os.path.isdir(single_path):
1014 if not os.path.isdir(single_path):
1018 continue
1015 continue
1019
1016
1020 fileList = glob.glob1(single_path, "*" + ext)
1017 fileList = glob.glob1(single_path, "*" + ext)
1021
1018
1022 if not fileList:
1019 if not fileList:
1023 continue
1020 continue
1024
1021
1025 path_empty = False
1022 path_empty = False
1026
1023
1027 fileList.sort()
1024 fileList.sort()
1028
1025
1029 for thisFile in fileList:
1026 for thisFile in fileList:
1030
1027
1031 if not os.path.isfile(os.path.join(single_path, thisFile)):
1028 if not os.path.isfile(os.path.join(single_path, thisFile)):
1032 continue
1029 continue
1033
1030
1034 if not isRadarFile(thisFile):
1031 if not isRadarFile(thisFile):
1035 continue
1032 continue
1036
1033
1037 if not isFileInDateRange(thisFile, startDate, endDate):
1034 if not isFileInDateRange(thisFile, startDate, endDate):
1038 continue
1035 continue
1039
1036
1040 thisDate = getDateFromRadarFile(thisFile)
1037 thisDate = getDateFromRadarFile(thisFile)
1041
1038
1042 if thisDate in dateList or single_path in pathList:
1039 if thisDate in dateList or single_path in pathList:
1043 continue
1040 continue
1044
1041
1045 dateList.append(thisDate)
1042 dateList.append(thisDate)
1046 pathList.append(single_path)
1043 pathList.append(single_path)
1047
1044
1048 else:
1045 else:
1049 for single_path in multi_path:
1046 for single_path in multi_path:
1050
1047
1051 if not os.path.isdir(single_path):
1048 if not os.path.isdir(single_path):
1052 continue
1049 continue
1053
1050
1054 dirList = []
1051 dirList = []
1055
1052
1056 for thisPath in os.listdir(single_path):
1053 for thisPath in os.listdir(single_path):
1057
1054
1058 if not os.path.isdir(os.path.join(single_path, thisPath)):
1055 if not os.path.isdir(os.path.join(single_path, thisPath)):
1059 continue
1056 continue
1060
1057
1061 if not isRadarFolder(thisPath):
1058 if not isRadarFolder(thisPath):
1062 continue
1059 continue
1063
1060
1064 if not isFolderInDateRange(thisPath, startDate, endDate):
1061 if not isFolderInDateRange(thisPath, startDate, endDate):
1065 continue
1062 continue
1066
1063
1067 dirList.append(thisPath)
1064 dirList.append(thisPath)
1068
1065
1069 if not dirList:
1066 if not dirList:
1070 continue
1067 continue
1071
1068
1072 dirList.sort()
1069 dirList.sort()
1073
1070
1074 for thisDir in dirList:
1071 for thisDir in dirList:
1075
1072
1076 datapath = os.path.join(single_path, thisDir, expLabel)
1073 datapath = os.path.join(single_path, thisDir, expLabel)
1077 fileList = glob.glob1(datapath, "*" + ext)
1074 fileList = glob.glob1(datapath, "*" + ext)
1078
1075
1079 if not fileList:
1076 if not fileList:
1080 continue
1077 continue
1081
1078
1082 path_empty = False
1079 path_empty = False
1083
1080
1084 thisDate = getDateFromRadarFolder(thisDir)
1081 thisDate = getDateFromRadarFolder(thisDir)
1085
1082
1086 pathList.append(datapath)
1083 pathList.append(datapath)
1087 dateList.append(thisDate)
1084 dateList.append(thisDate)
1088
1085
1089 dateList.sort()
1086 dateList.sort()
1090
1087
1091 if walk:
1088 if walk:
1092 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1089 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1093 else:
1090 else:
1094 pattern_path = multi_path[0]
1091 pattern_path = multi_path[0]
1095
1092
1096 if path_empty:
1093 if path_empty:
1097 raise schainpy.admin.SchainError("[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate))
1094 raise schainpy.admin.SchainError("[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate))
1098 else:
1095 else:
1099 if not dateList:
1096 if not dateList:
1100 raise schainpy.admin.SchainError("[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path))
1097 raise schainpy.admin.SchainError("[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path))
1101
1098
1102 if include_path:
1099 if include_path:
1103 return dateList, pathList
1100 return dateList, pathList
1104
1101
1105 return dateList
1102 return dateList
1106
1103
1107 def setup(self, **kwargs):
1104 def setup(self, **kwargs):
1108
1105
1109 self.set_kwargs(**kwargs)
1106 self.set_kwargs(**kwargs)
1110 if not self.ext.startswith('.'):
1107 if not self.ext.startswith('.'):
1111 self.ext = '.{}'.format(self.ext)
1108 self.ext = '.{}'.format(self.ext)
1112
1109
1113 if self.server is not None:
1110 if self.server is not None:
1114 if 'tcp://' in self.server:
1111 if 'tcp://' in self.server:
1115 address = server
1112 address = server
1116 else:
1113 else:
1117 address = 'ipc:///tmp/%s' % self.server
1114 address = 'ipc:///tmp/%s' % self.server
1118 self.server = address
1115 self.server = address
1119 self.context = zmq.Context()
1116 self.context = zmq.Context()
1120 self.receiver = self.context.socket(zmq.PULL)
1117 self.receiver = self.context.socket(zmq.PULL)
1121 self.receiver.connect(self.server)
1118 self.receiver.connect(self.server)
1122 time.sleep(0.5)
1119 time.sleep(0.5)
1123 print('[Starting] ReceiverData from {}'.format(self.server))
1120 print('[Starting] ReceiverData from {}'.format(self.server))
1124 else:
1121 else:
1125 self.server = None
1122 self.server = None
1126 if self.path == None:
1123 if self.path == None:
1127 raise ValueError("[Reading] The path is not valid")
1124 raise ValueError("[Reading] The path is not valid")
1128
1125
1129 if self.online:
1126 if self.online:
1130 log.log("[Reading] Searching files in online mode...", self.name)
1127 log.log("[Reading] Searching files in online mode...", self.name)
1131
1128
1132 for nTries in range(self.nTries):
1129 for nTries in range(self.nTries):
1133 fullpath = self.searchFilesOnLine(self.path, self.startDate,
1130 fullpath = self.searchFilesOnLine(self.path, self.startDate,
1134 self.endDate, self.expLabel, self.ext, self.walk,
1131 self.endDate, self.expLabel, self.ext, self.walk,
1135 self.filefmt, self.folderfmt)
1132 self.filefmt, self.folderfmt)
1136
1133
1137 try:
1134 try:
1138 fullpath = next(fullpath)
1135 fullpath = next(fullpath)
1139 except:
1136 except:
1140 fullpath = None
1137 fullpath = None
1141
1138
1142 if fullpath:
1139 if fullpath:
1143 break
1140 break
1144
1141
1145 log.warning(
1142 log.warning(
1146 'Waiting {} sec for a valid file in {}: try {} ...'.format(
1143 'Waiting {} sec for a valid file in {}: try {} ...'.format(
1147 self.delay, self.path, nTries + 1),
1144 self.delay, self.path, nTries + 1),
1148 self.name)
1145 self.name)
1149 time.sleep(self.delay)
1146 time.sleep(self.delay)
1150
1147
1151 if not(fullpath):
1148 if not(fullpath):
1152 raise schainpy.admin.SchainError(
1149 raise schainpy.admin.SchainError(
1153 'There isn\'t any valid file in {}'.format(self.path))
1150 'There isn\'t any valid file in {}'.format(self.path))
1154
1151
1155 pathname, filename = os.path.split(fullpath)
1152 pathname, filename = os.path.split(fullpath)
1156 self.year = int(filename[1:5])
1153 self.year = int(filename[1:5])
1157 self.doy = int(filename[5:8])
1154 self.doy = int(filename[5:8])
1158 self.set = int(filename[8:11]) - 1
1155 self.set = int(filename[8:11]) - 1
1159 else:
1156 else:
1160 log.log("Searching files in {}".format(self.path), self.name)
1157 log.log("Searching files in {}".format(self.path), self.name)
1161 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
1158 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
1162 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
1159 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
1163
1160
1164 self.setNextFile()
1161 self.setNextFile()
1165
1162
1166 return
1163 return
1167
1164
1168 def getBasicHeader(self):
1165 def getBasicHeader(self):
1169
1166
1170 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1167 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1171 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1168 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1172
1169
1173 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1170 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1174
1171
1175 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1172 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1176
1173
1177 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1174 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1178
1175
1179 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1176 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1180
1177
1181 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1178 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1182
1179
1183 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1180 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1184
1181
1185 def getFirstHeader(self):
1182 def getFirstHeader(self):
1186
1183
1187 raise NotImplementedError
1184 raise NotImplementedError
1188
1185
1189 def getData(self):
1186 def getData(self):
1190
1187
1191 raise NotImplementedError
1188 raise NotImplementedError
1192
1189
1193 def hasNotDataInBuffer(self):
1190 def hasNotDataInBuffer(self):
1194
1191
1195 raise NotImplementedError
1192 raise NotImplementedError
1196
1193
1197 def readBlock(self):
1194 def readBlock(self):
1198
1195
1199 raise NotImplementedError
1196 raise NotImplementedError
1200
1197
1201 def isEndProcess(self):
1198 def isEndProcess(self):
1202
1199
1203 return self.flagNoMoreFiles
1200 return self.flagNoMoreFiles
1204
1201
1205 def printReadBlocks(self):
1202 def printReadBlocks(self):
1206
1203
1207 print("[Reading] Number of read blocks per file %04d" % self.nReadBlocks)
1204 print("[Reading] Number of read blocks per file %04d" % self.nReadBlocks)
1208
1205
1209 def printTotalBlocks(self):
1206 def printTotalBlocks(self):
1210
1207
1211 print("[Reading] Number of read blocks %04d" % self.nTotalBlocks)
1208 print("[Reading] Number of read blocks %04d" % self.nTotalBlocks)
1212
1209
1213 def run(self, **kwargs):
1210 def run(self, **kwargs):
1214 """
1211 """
1215
1212
1216 Arguments:
1213 Arguments:
1217 path :
1214 path :
1218 startDate :
1215 startDate :
1219 endDate :
1216 endDate :
1220 startTime :
1217 startTime :
1221 endTime :
1218 endTime :
1222 set :
1219 set :
1223 expLabel :
1220 expLabel :
1224 ext :
1221 ext :
1225 online :
1222 online :
1226 delay :
1223 delay :
1227 walk :
1224 walk :
1228 getblock :
1225 getblock :
1229 nTxs :
1226 nTxs :
1230 realtime :
1227 realtime :
1231 blocksize :
1228 blocksize :
1232 blocktime :
1229 blocktime :
1233 skip :
1230 skip :
1234 cursor :
1231 cursor :
1235 warnings :
1232 warnings :
1236 server :
1233 server :
1237 verbose :
1234 verbose :
1238 format :
1235 format :
1239 oneDDict :
1236 oneDDict :
1240 twoDDict :
1237 twoDDict :
1241 independentParam :
1238 independentParam :
1242 """
1239 """
1243
1240
1244 if not(self.isConfig):
1241 if not(self.isConfig):
1245 self.setup(**kwargs)
1242 self.setup(**kwargs)
1246 self.isConfig = True
1243 self.isConfig = True
1247 if self.server is None:
1244 if self.server is None:
1248 self.getData()
1245 self.getData()
1249 else:
1246 else:
1250 self.getFromServer()
1247 self.getFromServer()
1251
1248
1252
1249
1253 class JRODataWriter(Reader):
1250 class JRODataWriter(Reader):
1254
1251
1255 """
1252 """
1256 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1253 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1257 de los datos siempre se realiza por bloques.
1254 de los datos siempre se realiza por bloques.
1258 """
1255 """
1259
1256
1260 setFile = None
1257 setFile = None
1261 profilesPerBlock = None
1258 profilesPerBlock = None
1262 blocksPerFile = None
1259 blocksPerFile = None
1263 nWriteBlocks = 0
1260 nWriteBlocks = 0
1264 fileDate = None
1261 fileDate = None
1265
1262
1266 def __init__(self, dataOut=None):
1263 def __init__(self, dataOut=None):
1267 raise NotImplementedError
1264 raise NotImplementedError
1268
1265
1269 def hasAllDataInBuffer(self):
1266 def hasAllDataInBuffer(self):
1270 raise NotImplementedError
1267 raise NotImplementedError
1271
1268
1272 def setBlockDimension(self):
1269 def setBlockDimension(self):
1273 raise NotImplementedError
1270 raise NotImplementedError
1274
1271
1275 def writeBlock(self):
1272 def writeBlock(self):
1276 raise NotImplementedError
1273 raise NotImplementedError
1277
1274
1278 def putData(self):
1275 def putData(self):
1279 raise NotImplementedError
1276 raise NotImplementedError
1280
1277
1281 def getDtypeWidth(self):
1278 def getDtypeWidth(self):
1282
1279
1283 dtype_index = get_dtype_index(self.dtype)
1280 dtype_index = get_dtype_index(self.dtype)
1284 dtype_width = get_dtype_width(dtype_index)
1281 dtype_width = get_dtype_width(dtype_index)
1285
1282
1286 return dtype_width
1283 return dtype_width
1287
1284
1288 def getProcessFlags(self):
1285 def getProcessFlags(self):
1289
1286
1290 processFlags = 0
1287 processFlags = 0
1291
1288
1292 dtype_index = get_dtype_index(self.dtype)
1289 dtype_index = get_dtype_index(self.dtype)
1293 procflag_dtype = get_procflag_dtype(dtype_index)
1290 procflag_dtype = get_procflag_dtype(dtype_index)
1294
1291
1295 processFlags += procflag_dtype
1292 processFlags += procflag_dtype
1296
1293
1297 if self.dataOut.flagDecodeData:
1294 if self.dataOut.flagDecodeData:
1298 processFlags += PROCFLAG.DECODE_DATA
1295 processFlags += PROCFLAG.DECODE_DATA
1299
1296
1300 if self.dataOut.flagDeflipData:
1297 if self.dataOut.flagDeflipData:
1301 processFlags += PROCFLAG.DEFLIP_DATA
1298 processFlags += PROCFLAG.DEFLIP_DATA
1302
1299
1303 if self.dataOut.code is not None:
1300 if self.dataOut.code is not None:
1304 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1301 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1305
1302
1306 if self.dataOut.nCohInt > 1:
1303 if self.dataOut.nCohInt > 1:
1307 processFlags += PROCFLAG.COHERENT_INTEGRATION
1304 processFlags += PROCFLAG.COHERENT_INTEGRATION
1308
1305
1309 if self.dataOut.type == "Spectra":
1306 if self.dataOut.type == "Spectra":
1310 if self.dataOut.nIncohInt > 1:
1307 if self.dataOut.nIncohInt > 1:
1311 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1308 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1312
1309
1313 if self.dataOut.data_dc is not None:
1310 if self.dataOut.data_dc is not None:
1314 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1311 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1315
1312
1316 if self.dataOut.flagShiftFFT:
1313 if self.dataOut.flagShiftFFT:
1317 processFlags += PROCFLAG.SHIFT_FFT_DATA
1314 processFlags += PROCFLAG.SHIFT_FFT_DATA
1318
1315
1319 return processFlags
1316 return processFlags
1320
1317
1321 def setBasicHeader(self):
1318 def setBasicHeader(self):
1322
1319
1323 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1320 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1324 self.basicHeaderObj.version = self.versionFile
1321 self.basicHeaderObj.version = self.versionFile
1325 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1322 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1326 utc = numpy.floor(self.dataOut.utctime)
1323 utc = numpy.floor(self.dataOut.utctime)
1327 milisecond = (self.dataOut.utctime - utc) * 1000.0
1324 milisecond = (self.dataOut.utctime - utc) * 1000.0
1328 self.basicHeaderObj.utc = utc
1325 self.basicHeaderObj.utc = utc
1329 self.basicHeaderObj.miliSecond = milisecond
1326 self.basicHeaderObj.miliSecond = milisecond
1330 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1327 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1331 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1328 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1332 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1329 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1333
1330
1334 def setFirstHeader(self):
1331 def setFirstHeader(self):
1335 """
1332 """
1336 Obtiene una copia del First Header
1333 Obtiene una copia del First Header
1337
1334
1338 Affected:
1335 Affected:
1339
1336
1340 self.basicHeaderObj
1337 self.basicHeaderObj
1341 self.systemHeaderObj
1338 self.systemHeaderObj
1342 self.radarControllerHeaderObj
1339 self.radarControllerHeaderObj
1343 self.processingHeaderObj self.
1340 self.processingHeaderObj self.
1344
1341
1345 Return:
1342 Return:
1346 None
1343 None
1347 """
1344 """
1348
1345
1349 raise NotImplementedError
1346 raise NotImplementedError
1350
1347
1351 def __writeFirstHeader(self):
1348 def __writeFirstHeader(self):
1352 """
1349 """
1353 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1350 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1354
1351
1355 Affected:
1352 Affected:
1356 __dataType
1353 __dataType
1357
1354
1358 Return:
1355 Return:
1359 None
1356 None
1360 """
1357 """
1361
1358
1362 # CALCULAR PARAMETROS
1359 # CALCULAR PARAMETROS
1363
1360
1364 sizeLongHeader = self.systemHeaderObj.size + \
1361 sizeLongHeader = self.systemHeaderObj.size + \
1365 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1362 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1366 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1363 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1367
1364
1368 self.basicHeaderObj.write(self.fp)
1365 self.basicHeaderObj.write(self.fp)
1369 self.systemHeaderObj.write(self.fp)
1366 self.systemHeaderObj.write(self.fp)
1370 self.radarControllerHeaderObj.write(self.fp)
1367 self.radarControllerHeaderObj.write(self.fp)
1371 self.processingHeaderObj.write(self.fp)
1368 self.processingHeaderObj.write(self.fp)
1372
1369
1373 def __setNewBlock(self):
1370 def __setNewBlock(self):
1374 """
1371 """
1375 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1372 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1376
1373
1377 Return:
1374 Return:
1378 0 : si no pudo escribir nada
1375 0 : si no pudo escribir nada
1379 1 : Si escribio el Basic el First Header
1376 1 : Si escribio el Basic el First Header
1380 """
1377 """
1381 if self.fp == None:
1378 if self.fp == None:
1382 self.setNextFile()
1379 self.setNextFile()
1383
1380
1384 if self.flagIsNewFile:
1381 if self.flagIsNewFile:
1385 return 1
1382 return 1
1386
1383
1387 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1384 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1388 self.basicHeaderObj.write(self.fp)
1385 self.basicHeaderObj.write(self.fp)
1389 return 1
1386 return 1
1390
1387
1391 if not(self.setNextFile()):
1388 if not(self.setNextFile()):
1392 return 0
1389 return 0
1393
1390
1394 return 1
1391 return 1
1395
1392
1396 def writeNextBlock(self):
1393 def writeNextBlock(self):
1397 """
1394 """
1398 Selecciona el bloque siguiente de datos y los escribe en un file
1395 Selecciona el bloque siguiente de datos y los escribe en un file
1399
1396
1400 Return:
1397 Return:
1401 0 : Si no hizo pudo escribir el bloque de datos
1398 0 : Si no hizo pudo escribir el bloque de datos
1402 1 : Si no pudo escribir el bloque de datos
1399 1 : Si no pudo escribir el bloque de datos
1403 """
1400 """
1404 if not(self.__setNewBlock()):
1401 if not(self.__setNewBlock()):
1405 return 0
1402 return 0
1406
1403
1407 self.writeBlock()
1404 self.writeBlock()
1408
1405
1409 print("[Writing] Block No. %d/%d" % (self.blockIndex,
1406 print("[Writing] Block No. %d/%d" % (self.blockIndex,
1410 self.processingHeaderObj.dataBlocksPerFile))
1407 self.processingHeaderObj.dataBlocksPerFile))
1411
1408
1412 return 1
1409 return 1
1413
1410
1414 def setNextFile(self):
1411 def setNextFile(self):
1415 """Determina el siguiente file que sera escrito
1412 """Determina el siguiente file que sera escrito
1416
1413
1417 Affected:
1414 Affected:
1418 self.filename
1415 self.filename
1419 self.subfolder
1416 self.subfolder
1420 self.fp
1417 self.fp
1421 self.setFile
1418 self.setFile
1422 self.flagIsNewFile
1419 self.flagIsNewFile
1423
1420
1424 Return:
1421 Return:
1425 0 : Si el archivo no puede ser escrito
1422 0 : Si el archivo no puede ser escrito
1426 1 : Si el archivo esta listo para ser escrito
1423 1 : Si el archivo esta listo para ser escrito
1427 """
1424 """
1428 ext = self.ext
1425 ext = self.ext
1429 path = self.path
1426 path = self.path
1430
1427
1431 if self.fp != None:
1428 if self.fp != None:
1432 self.fp.close()
1429 self.fp.close()
1433
1430
1434 if not os.path.exists(path):
1431 if not os.path.exists(path):
1435 os.mkdir(path)
1432 os.mkdir(path)
1436
1433
1437 timeTuple = time.localtime(self.dataOut.utctime)
1434 timeTuple = time.localtime(self.dataOut.utctime)
1438 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1435 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1439
1436
1440 fullpath = os.path.join(path, subfolder)
1437 fullpath = os.path.join(path, subfolder)
1441 setFile = self.setFile
1438 setFile = self.setFile
1442
1439
1443 if not(os.path.exists(fullpath)):
1440 if not(os.path.exists(fullpath)):
1444 os.mkdir(fullpath)
1441 os.mkdir(fullpath)
1445 setFile = -1 # inicializo mi contador de seteo
1442 setFile = -1 # inicializo mi contador de seteo
1446 else:
1443 else:
1447 filesList = os.listdir(fullpath)
1444 filesList = os.listdir(fullpath)
1448 if len(filesList) > 0:
1445 if len(filesList) > 0:
1449 filesList = sorted(filesList, key=str.lower)
1446 filesList = sorted(filesList, key=str.lower)
1450 filen = filesList[-1]
1447 filen = filesList[-1]
1451 # el filename debera tener el siguiente formato
1448 # el filename debera tener el siguiente formato
1452 # 0 1234 567 89A BCDE (hex)
1449 # 0 1234 567 89A BCDE (hex)
1453 # x YYYY DDD SSS .ext
1450 # x YYYY DDD SSS .ext
1454 if isNumber(filen[8:11]):
1451 if isNumber(filen[8:11]):
1455 # inicializo mi contador de seteo al seteo del ultimo file
1452 # inicializo mi contador de seteo al seteo del ultimo file
1456 setFile = int(filen[8:11])
1453 setFile = int(filen[8:11])
1457 else:
1454 else:
1458 setFile = -1
1455 setFile = -1
1459 else:
1456 else:
1460 setFile = -1 # inicializo mi contador de seteo
1457 setFile = -1 # inicializo mi contador de seteo
1461
1458
1462 setFile += 1
1459 setFile += 1
1463
1460
1464 # If this is a new day it resets some values
1461 # If this is a new day it resets some values
1465 if self.dataOut.datatime.date() > self.fileDate:
1462 if self.dataOut.datatime.date() > self.fileDate:
1466 setFile = 0
1463 setFile = 0
1467 self.nTotalBlocks = 0
1464 self.nTotalBlocks = 0
1468
1465
1469 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1466 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1470 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1467 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1471
1468
1472 filename = os.path.join(path, subfolder, filen)
1469 filename = os.path.join(path, subfolder, filen)
1473
1470
1474 fp = open(filename, 'wb')
1471 fp = open(filename, 'wb')
1475
1472
1476 self.blockIndex = 0
1473 self.blockIndex = 0
1477 self.filename = filename
1474 self.filename = filename
1478 self.subfolder = subfolder
1475 self.subfolder = subfolder
1479 self.fp = fp
1476 self.fp = fp
1480 self.setFile = setFile
1477 self.setFile = setFile
1481 self.flagIsNewFile = 1
1478 self.flagIsNewFile = 1
1482 self.fileDate = self.dataOut.datatime.date()
1479 self.fileDate = self.dataOut.datatime.date()
1483 self.setFirstHeader()
1480 self.setFirstHeader()
1484
1481
1485 print('[Writing] Opening file: %s' % self.filename)
1482 print('[Writing] Opening file: %s' % self.filename)
1486
1483
1487 self.__writeFirstHeader()
1484 self.__writeFirstHeader()
1488
1485
1489 return 1
1486 return 1
1490
1487
1491 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1488 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1492 """
1489 """
1493 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1490 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1494
1491
1495 Inputs:
1492 Inputs:
1496 path : directory where data will be saved
1493 path : directory where data will be saved
1497 profilesPerBlock : number of profiles per block
1494 profilesPerBlock : number of profiles per block
1498 set : initial file set
1495 set : initial file set
1499 datatype : An integer number that defines data type:
1496 datatype : An integer number that defines data type:
1500 0 : int8 (1 byte)
1497 0 : int8 (1 byte)
1501 1 : int16 (2 bytes)
1498 1 : int16 (2 bytes)
1502 2 : int32 (4 bytes)
1499 2 : int32 (4 bytes)
1503 3 : int64 (8 bytes)
1500 3 : int64 (8 bytes)
1504 4 : float32 (4 bytes)
1501 4 : float32 (4 bytes)
1505 5 : double64 (8 bytes)
1502 5 : double64 (8 bytes)
1506
1503
1507 Return:
1504 Return:
1508 0 : Si no realizo un buen seteo
1505 0 : Si no realizo un buen seteo
1509 1 : Si realizo un buen seteo
1506 1 : Si realizo un buen seteo
1510 """
1507 """
1511
1508
1512 if ext == None:
1509 if ext == None:
1513 ext = self.ext
1510 ext = self.ext
1514
1511
1515 self.ext = ext.lower()
1512 self.ext = ext.lower()
1516
1513
1517 self.path = path
1514 self.path = path
1518
1515
1519 if set is None:
1516 if set is None:
1520 self.setFile = -1
1517 self.setFile = -1
1521 else:
1518 else:
1522 self.setFile = set - 1
1519 self.setFile = set - 1
1523
1520
1524 self.blocksPerFile = blocksPerFile
1521 self.blocksPerFile = blocksPerFile
1525 self.profilesPerBlock = profilesPerBlock
1522 self.profilesPerBlock = profilesPerBlock
1526 self.dataOut = dataOut
1523 self.dataOut = dataOut
1527 self.fileDate = self.dataOut.datatime.date()
1524 self.fileDate = self.dataOut.datatime.date()
1528 self.dtype = self.dataOut.dtype
1525 self.dtype = self.dataOut.dtype
1529
1526
1530 if datatype is not None:
1527 if datatype is not None:
1531 self.dtype = get_numpy_dtype(datatype)
1528 self.dtype = get_numpy_dtype(datatype)
1532
1529
1533 if not(self.setNextFile()):
1530 if not(self.setNextFile()):
1534 print("[Writing] There isn't a next file")
1531 print("[Writing] There isn't a next file")
1535 return 0
1532 return 0
1536
1533
1537 self.setBlockDimension()
1534 self.setBlockDimension()
1538
1535
1539 return 1
1536 return 1
1540
1537
1541 def run(self, dataOut, path, blocksPerFile=100, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1538 def run(self, dataOut, path, blocksPerFile=100, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1542
1539
1543 if not(self.isConfig):
1540 if not(self.isConfig):
1544
1541
1545 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1542 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1546 set=set, ext=ext, datatype=datatype, **kwargs)
1543 set=set, ext=ext, datatype=datatype, **kwargs)
1547 self.isConfig = True
1544 self.isConfig = True
1548
1545
1549 self.dataOut = dataOut
1546 self.dataOut = dataOut
1550 self.putData()
1547 self.putData()
1551 return self.dataOut
1548 return self.dataOut
1552
1549
1553 @MPDecorator
1550 @MPDecorator
1554 class printInfo(Operation):
1551 class printInfo(Operation):
1555
1552
1556 def __init__(self):
1553 def __init__(self):
1557
1554
1558 Operation.__init__(self)
1555 Operation.__init__(self)
1559 self.__printInfo = True
1556 self.__printInfo = True
1560
1557
1561 def run(self, dataOut, headers = ['systemHeaderObj', 'radarControllerHeaderObj', 'processingHeaderObj']):
1558 def run(self, dataOut, headers = ['systemHeaderObj', 'radarControllerHeaderObj', 'processingHeaderObj']):
1562 if self.__printInfo == False:
1559 if self.__printInfo == False:
1563 return
1560 return
1564
1561
1565 for header in headers:
1562 for header in headers:
1566 if hasattr(dataOut, header):
1563 if hasattr(dataOut, header):
1567 obj = getattr(dataOut, header)
1564 obj = getattr(dataOut, header)
1568 if hasattr(obj, 'printInfo'):
1565 if hasattr(obj, 'printInfo'):
1569 obj.printInfo()
1566 obj.printInfo()
1570 else:
1567 else:
1571 print(obj)
1568 print(obj)
1572 else:
1569 else:
1573 log.warning('Header {} Not found in object'.format(header))
1570 log.warning('Header {} Not found in object'.format(header))
1574
1571
1575 self.__printInfo = False
1572 self.__printInfo = False No newline at end of file
@@ -1,967 +1,966
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Spectra processing Unit and operations
5 """Spectra processing Unit and operations
6
6
7 Here you will find the processing unit `SpectraProc` and several operations
7 Here you will find the processing unit `SpectraProc` and several operations
8 to work with Spectra data type
8 to work with Spectra data type
9 """
9 """
10
10
11 import time
11 import time
12 import itertools
12 import itertools
13 import numpy
13 import numpy
14 # repositorio
14 # repositorio
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
16 from schainpy.model.data.jrodata import Spectra
16 from schainpy.model.data.jrodata import Spectra
17 from schainpy.model.data.jrodata import hildebrand_sekhon
17 from schainpy.model.data.jrodata import hildebrand_sekhon
18 from schainpy.utils import log
18 from schainpy.utils import log
19
19
20
20
21 class SpectraProc(ProcessingUnit):
21 class SpectraProc(ProcessingUnit):
22
22
23 def __init__(self):
23 def __init__(self):
24
24
25 ProcessingUnit.__init__(self)
25 ProcessingUnit.__init__(self)
26
26
27 self.buffer = None
27 self.buffer = None
28 self.firstdatatime = None
28 self.firstdatatime = None
29 self.profIndex = 0
29 self.profIndex = 0
30 self.dataOut = Spectra()
30 self.dataOut = Spectra()
31 self.id_min = None
31 self.id_min = None
32 self.id_max = None
32 self.id_max = None
33 self.setupReq = False #Agregar a todas las unidades de proc
33 self.setupReq = False #Agregar a todas las unidades de proc
34
34
35 def __updateSpecFromVoltage(self):
35 def __updateSpecFromVoltage(self):
36
36
37 self.dataOut.timeZone = self.dataIn.timeZone
37 self.dataOut.timeZone = self.dataIn.timeZone
38 self.dataOut.dstFlag = self.dataIn.dstFlag
38 self.dataOut.dstFlag = self.dataIn.dstFlag
39 self.dataOut.errorCount = self.dataIn.errorCount
39 self.dataOut.errorCount = self.dataIn.errorCount
40 self.dataOut.useLocalTime = self.dataIn.useLocalTime
40 self.dataOut.useLocalTime = self.dataIn.useLocalTime
41 try:
41 try:
42 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
42 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
43 except:
43 except:
44 pass
44 pass
45 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
45 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
46 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
46 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
47 self.dataOut.channelList = self.dataIn.channelList
47 self.dataOut.channelList = self.dataIn.channelList
48 self.dataOut.heightList = self.dataIn.heightList
48 self.dataOut.heightList = self.dataIn.heightList
49 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
49 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
50 self.dataOut.nProfiles = self.dataOut.nFFTPoints
50 self.dataOut.nProfiles = self.dataOut.nFFTPoints
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
52 self.dataOut.utctime = self.firstdatatime
52 self.dataOut.utctime = self.firstdatatime
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
55 self.dataOut.flagShiftFFT = False
55 self.dataOut.flagShiftFFT = False
56 self.dataOut.nCohInt = self.dataIn.nCohInt
56 self.dataOut.nCohInt = self.dataIn.nCohInt
57 self.dataOut.nIncohInt = 1
57 self.dataOut.nIncohInt = 1
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
59 self.dataOut.frequency = self.dataIn.frequency
59 self.dataOut.frequency = self.dataIn.frequency
60 self.dataOut.realtime = self.dataIn.realtime
60 self.dataOut.realtime = self.dataIn.realtime
61 self.dataOut.azimuth = self.dataIn.azimuth
61 self.dataOut.azimuth = self.dataIn.azimuth
62 self.dataOut.zenith = self.dataIn.zenith
62 self.dataOut.zenith = self.dataIn.zenith
63 self.dataOut.beam.codeList = self.dataIn.beam.codeList
63 self.dataOut.beam.codeList = self.dataIn.beam.codeList
64 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
64 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
65 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
65 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
66 self.dataOut.runNextUnit = self.dataIn.runNextUnit
66 self.dataOut.runNextUnit = self.dataIn.runNextUnit
67 try:
67 try:
68 self.dataOut.step = self.dataIn.step
68 self.dataOut.step = self.dataIn.step
69 except:
69 except:
70 pass
70 pass
71
71
72 def __getFft(self):
72 def __getFft(self):
73 """
73 """
74 Convierte valores de Voltaje a Spectra
74 Convierte valores de Voltaje a Spectra
75
75
76 Affected:
76 Affected:
77 self.dataOut.data_spc
77 self.dataOut.data_spc
78 self.dataOut.data_cspc
78 self.dataOut.data_cspc
79 self.dataOut.data_dc
79 self.dataOut.data_dc
80 self.dataOut.heightList
80 self.dataOut.heightList
81 self.profIndex
81 self.profIndex
82 self.buffer
82 self.buffer
83 self.dataOut.flagNoData
83 self.dataOut.flagNoData
84 """
84 """
85 fft_volt = numpy.fft.fft(
85 fft_volt = numpy.fft.fft(
86 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
86 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
87 fft_volt = fft_volt.astype(numpy.dtype('complex'))
87 fft_volt = fft_volt.astype(numpy.dtype('complex'))
88 dc = fft_volt[:, 0, :]
88 dc = fft_volt[:, 0, :]
89
89
90 # calculo de self-spectra
90 # calculo de self-spectra
91 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
91 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
92 spc = fft_volt * numpy.conjugate(fft_volt)
92 spc = fft_volt * numpy.conjugate(fft_volt)
93 spc = spc.real
93 spc = spc.real
94
94
95 blocksize = 0
95 blocksize = 0
96 blocksize += dc.size
96 blocksize += dc.size
97 blocksize += spc.size
97 blocksize += spc.size
98
98
99 cspc = None
99 cspc = None
100 pairIndex = 0
100 pairIndex = 0
101 if self.dataOut.pairsList != None:
101 if self.dataOut.pairsList != None:
102 # calculo de cross-spectra
102 # calculo de cross-spectra
103 cspc = numpy.zeros(
103 cspc = numpy.zeros(
104 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
104 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
105 for pair in self.dataOut.pairsList:
105 for pair in self.dataOut.pairsList:
106 if pair[0] not in self.dataOut.channelList:
106 if pair[0] not in self.dataOut.channelList:
107 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
107 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
108 str(pair), str(self.dataOut.channelList)))
108 str(pair), str(self.dataOut.channelList)))
109 if pair[1] not in self.dataOut.channelList:
109 if pair[1] not in self.dataOut.channelList:
110 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
110 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
111 str(pair), str(self.dataOut.channelList)))
111 str(pair), str(self.dataOut.channelList)))
112
112
113 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
113 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
114 numpy.conjugate(fft_volt[pair[1], :, :])
114 numpy.conjugate(fft_volt[pair[1], :, :])
115 pairIndex += 1
115 pairIndex += 1
116 blocksize += cspc.size
116 blocksize += cspc.size
117
117
118 self.dataOut.data_spc = spc
118 self.dataOut.data_spc = spc
119 self.dataOut.data_cspc = cspc
119 self.dataOut.data_cspc = cspc
120 self.dataOut.data_dc = dc
120 self.dataOut.data_dc = dc
121 self.dataOut.blockSize = blocksize
121 self.dataOut.blockSize = blocksize
122 self.dataOut.flagShiftFFT = False
122 self.dataOut.flagShiftFFT = False
123
123
124 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False, runNextUnit = 0):
124 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False, runNextUnit = 0):
125
125
126 self.dataIn.runNextUnit = runNextUnit
126 self.dataIn.runNextUnit = runNextUnit
127 if self.dataIn.type == "Spectra":
127 if self.dataIn.type == "Spectra":
128 self.dataOut.copy(self.dataIn)
128 self.dataOut.copy(self.dataIn)
129 if shift_fft:
129 if shift_fft:
130 #desplaza a la derecha en el eje 2 determinadas posiciones
130 #desplaza a la derecha en el eje 2 determinadas posiciones
131 shift = int(self.dataOut.nFFTPoints/2)
131 shift = int(self.dataOut.nFFTPoints/2)
132 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
132 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
133
133
134 if self.dataOut.data_cspc is not None:
134 if self.dataOut.data_cspc is not None:
135 #desplaza a la derecha en el eje 2 determinadas posiciones
135 #desplaza a la derecha en el eje 2 determinadas posiciones
136 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
136 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
137 if pairsList:
137 if pairsList:
138 self.__selectPairs(pairsList)
138 self.__selectPairs(pairsList)
139
139
140 elif self.dataIn.type == "Voltage":
140 elif self.dataIn.type == "Voltage":
141
141
142 self.dataOut.flagNoData = True
142 self.dataOut.flagNoData = True
143
143
144 if nFFTPoints == None:
144 if nFFTPoints == None:
145 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
145 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
146
146
147 if nProfiles == None:
147 if nProfiles == None:
148 nProfiles = nFFTPoints
148 nProfiles = nFFTPoints
149
149
150 if ippFactor == None:
150 if ippFactor == None:
151 self.dataOut.ippFactor = 1
151 self.dataOut.ippFactor = 1
152
152
153 self.dataOut.nFFTPoints = nFFTPoints
153 self.dataOut.nFFTPoints = nFFTPoints
154
154
155 if self.buffer is None:
155 if self.buffer is None:
156 self.buffer = numpy.zeros((self.dataIn.nChannels,
156 self.buffer = numpy.zeros((self.dataIn.nChannels,
157 nProfiles,
157 nProfiles,
158 self.dataIn.nHeights),
158 self.dataIn.nHeights),
159 dtype='complex')
159 dtype='complex')
160
160
161 if self.dataIn.flagDataAsBlock:
161 if self.dataIn.flagDataAsBlock:
162 nVoltProfiles = self.dataIn.data.shape[1]
162 nVoltProfiles = self.dataIn.data.shape[1]
163 if nVoltProfiles == nProfiles:
163 if nVoltProfiles == nProfiles:
164 self.buffer = self.dataIn.data.copy()
164 self.buffer = self.dataIn.data.copy()
165 self.profIndex = nVoltProfiles
165 self.profIndex = nVoltProfiles
166
166
167 elif nVoltProfiles < nProfiles:
167 elif nVoltProfiles < nProfiles:
168
168
169 if self.profIndex == 0:
169 if self.profIndex == 0:
170 self.id_min = 0
170 self.id_min = 0
171 self.id_max = nVoltProfiles
171 self.id_max = nVoltProfiles
172
172
173 self.buffer[:, self.id_min:self.id_max,
173 self.buffer[:, self.id_min:self.id_max,
174 :] = self.dataIn.data
174 :] = self.dataIn.data
175 self.profIndex += nVoltProfiles
175 self.profIndex += nVoltProfiles
176 self.id_min += nVoltProfiles
176 self.id_min += nVoltProfiles
177 self.id_max += nVoltProfiles
177 self.id_max += nVoltProfiles
178 elif nVoltProfiles > nProfiles:
178 elif nVoltProfiles > nProfiles:
179 self.reader.bypass = True
179 self.reader.bypass = True
180 if self.profIndex == 0:
180 if self.profIndex == 0:
181 self.id_min = 0
181 self.id_min = 0
182 self.id_max = nProfiles
182 self.id_max = nProfiles
183
183
184 self.buffer = self.dataIn.data[:, self.id_min:self.id_max,:]
184 self.buffer = self.dataIn.data[:, self.id_min:self.id_max,:]
185 self.profIndex += nProfiles
185 self.profIndex += nProfiles
186 self.id_min += nProfiles
186 self.id_min += nProfiles
187 self.id_max += nProfiles
187 self.id_max += nProfiles
188 if self.id_max == nVoltProfiles:
188 if self.id_max == nVoltProfiles:
189 self.reader.bypass = False
189 self.reader.bypass = False
190
190
191 else:
191 else:
192 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
192 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
193 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
193 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
194 self.dataOut.flagNoData = True
194 self.dataOut.flagNoData = True
195 else:
195 else:
196 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
196 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
197 self.profIndex += 1
197 self.profIndex += 1
198
198
199 if self.firstdatatime == None:
199 if self.firstdatatime == None:
200 self.firstdatatime = self.dataIn.utctime
200 self.firstdatatime = self.dataIn.utctime
201
201
202 if self.profIndex == nProfiles:
202 if self.profIndex == nProfiles:
203 self.__updateSpecFromVoltage()
203 self.__updateSpecFromVoltage()
204 if pairsList == None:
204 if pairsList == None:
205 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
205 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
206 else:
206 else:
207 self.dataOut.pairsList = pairsList
207 self.dataOut.pairsList = pairsList
208 self.__getFft()
208 self.__getFft()
209 self.dataOut.flagNoData = False
209 self.dataOut.flagNoData = False
210 self.firstdatatime = None
210 self.firstdatatime = None
211 #if not self.reader.bypass:
211 #if not self.reader.bypass:
212 self.profIndex = 0
212 self.profIndex = 0
213 else:
213 else:
214 raise ValueError("The type of input object '%s' is not valid".format(
214 raise ValueError("The type of input object '%s' is not valid".format(
215 self.dataIn.type))
215 self.dataIn.type))
216
216
217 def __selectPairs(self, pairsList):
217 def __selectPairs(self, pairsList):
218
218
219 if not pairsList:
219 if not pairsList:
220 return
220 return
221
221
222 pairs = []
222 pairs = []
223 pairsIndex = []
223 pairsIndex = []
224
224
225 for pair in pairsList:
225 for pair in pairsList:
226 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
226 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
227 continue
227 continue
228 pairs.append(pair)
228 pairs.append(pair)
229 pairsIndex.append(pairs.index(pair))
229 pairsIndex.append(pairs.index(pair))
230
230
231 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
231 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
232 self.dataOut.pairsList = pairs
232 self.dataOut.pairsList = pairs
233
233
234 return
234 return
235
235
236 def selectFFTs(self, minFFT, maxFFT ):
236 def selectFFTs(self, minFFT, maxFFT ):
237 """
237 """
238 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
238 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
239 minFFT<= FFT <= maxFFT
239 minFFT<= FFT <= maxFFT
240 """
240 """
241
241
242 if (minFFT > maxFFT):
242 if (minFFT > maxFFT):
243 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
243 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
244
244
245 if (minFFT < self.dataOut.getFreqRange()[0]):
245 if (minFFT < self.dataOut.getFreqRange()[0]):
246 minFFT = self.dataOut.getFreqRange()[0]
246 minFFT = self.dataOut.getFreqRange()[0]
247
247
248 if (maxFFT > self.dataOut.getFreqRange()[-1]):
248 if (maxFFT > self.dataOut.getFreqRange()[-1]):
249 maxFFT = self.dataOut.getFreqRange()[-1]
249 maxFFT = self.dataOut.getFreqRange()[-1]
250
250
251 minIndex = 0
251 minIndex = 0
252 maxIndex = 0
252 maxIndex = 0
253 FFTs = self.dataOut.getFreqRange()
253 FFTs = self.dataOut.getFreqRange()
254
254
255 inda = numpy.where(FFTs >= minFFT)
255 inda = numpy.where(FFTs >= minFFT)
256 indb = numpy.where(FFTs <= maxFFT)
256 indb = numpy.where(FFTs <= maxFFT)
257
257
258 try:
258 try:
259 minIndex = inda[0][0]
259 minIndex = inda[0][0]
260 except:
260 except:
261 minIndex = 0
261 minIndex = 0
262
262
263 try:
263 try:
264 maxIndex = indb[0][-1]
264 maxIndex = indb[0][-1]
265 except:
265 except:
266 maxIndex = len(FFTs)
266 maxIndex = len(FFTs)
267
267
268 self.selectFFTsByIndex(minIndex, maxIndex)
268 self.selectFFTsByIndex(minIndex, maxIndex)
269
269
270 return 1
270 return 1
271
271
272 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
272 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
273 newheis = numpy.where(
273 newheis = numpy.where(
274 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
274 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
275
275
276 if hei_ref != None:
276 if hei_ref != None:
277 newheis = numpy.where(self.dataOut.heightList > hei_ref)
277 newheis = numpy.where(self.dataOut.heightList > hei_ref)
278
278
279 minIndex = min(newheis[0])
279 minIndex = min(newheis[0])
280 maxIndex = max(newheis[0])
280 maxIndex = max(newheis[0])
281 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
281 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
282 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
282 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
283
283
284 # determina indices
284 # determina indices
285 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
285 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
286 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
286 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
287 avg_dB = 10 * \
287 avg_dB = 10 * \
288 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
288 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
289 beacon_dB = numpy.sort(avg_dB)[-nheis:]
289 beacon_dB = numpy.sort(avg_dB)[-nheis:]
290 beacon_heiIndexList = []
290 beacon_heiIndexList = []
291 for val in avg_dB.tolist():
291 for val in avg_dB.tolist():
292 if val >= beacon_dB[0]:
292 if val >= beacon_dB[0]:
293 beacon_heiIndexList.append(avg_dB.tolist().index(val))
293 beacon_heiIndexList.append(avg_dB.tolist().index(val))
294
294
295 data_cspc = None
295 data_cspc = None
296 if self.dataOut.data_cspc is not None:
296 if self.dataOut.data_cspc is not None:
297 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
297 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
298
298
299 data_dc = None
299 data_dc = None
300 if self.dataOut.data_dc is not None:
300 if self.dataOut.data_dc is not None:
301 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
301 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
302
302
303 self.dataOut.data_spc = data_spc
303 self.dataOut.data_spc = data_spc
304 self.dataOut.data_cspc = data_cspc
304 self.dataOut.data_cspc = data_cspc
305 self.dataOut.data_dc = data_dc
305 self.dataOut.data_dc = data_dc
306 self.dataOut.heightList = heightList
306 self.dataOut.heightList = heightList
307 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
307 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
308
308
309 return 1
309 return 1
310
310
311 def selectFFTsByIndex(self, minIndex, maxIndex):
311 def selectFFTsByIndex(self, minIndex, maxIndex):
312 """
312 """
313
313
314 """
314 """
315
315
316 if (minIndex < 0) or (minIndex > maxIndex):
316 if (minIndex < 0) or (minIndex > maxIndex):
317 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
317 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
318
318
319 if (maxIndex >= self.dataOut.nProfiles):
319 if (maxIndex >= self.dataOut.nProfiles):
320 maxIndex = self.dataOut.nProfiles-1
320 maxIndex = self.dataOut.nProfiles-1
321
321
322 #Spectra
322 #Spectra
323 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
323 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
324
324
325 data_cspc = None
325 data_cspc = None
326 if self.dataOut.data_cspc is not None:
326 if self.dataOut.data_cspc is not None:
327 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
327 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
328
328
329 data_dc = None
329 data_dc = None
330 if self.dataOut.data_dc is not None:
330 if self.dataOut.data_dc is not None:
331 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
331 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
332
332
333 self.dataOut.data_spc = data_spc
333 self.dataOut.data_spc = data_spc
334 self.dataOut.data_cspc = data_cspc
334 self.dataOut.data_cspc = data_cspc
335 self.dataOut.data_dc = data_dc
335 self.dataOut.data_dc = data_dc
336
336
337 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
337 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
338 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
338 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
339 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
339 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
340
340
341 return 1
341 return 1
342
342
343 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
343 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
344 # validacion de rango
344 # validacion de rango
345 if minHei == None:
345 if minHei == None:
346 minHei = self.dataOut.heightList[0]
346 minHei = self.dataOut.heightList[0]
347
347
348 if maxHei == None:
348 if maxHei == None:
349 maxHei = self.dataOut.heightList[-1]
349 maxHei = self.dataOut.heightList[-1]
350
350
351 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
351 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
352 print('minHei: %.2f is out of the heights range' % (minHei))
352 print('minHei: %.2f is out of the heights range' % (minHei))
353 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
353 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
354 minHei = self.dataOut.heightList[0]
354 minHei = self.dataOut.heightList[0]
355
355
356 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
356 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
357 print('maxHei: %.2f is out of the heights range' % (maxHei))
357 print('maxHei: %.2f is out of the heights range' % (maxHei))
358 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
358 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
359 maxHei = self.dataOut.heightList[-1]
359 maxHei = self.dataOut.heightList[-1]
360
360
361 # validacion de velocidades
361 # validacion de velocidades
362 velrange = self.dataOut.getVelRange(1)
362 velrange = self.dataOut.getVelRange(1)
363
363
364 if minVel == None:
364 if minVel == None:
365 minVel = velrange[0]
365 minVel = velrange[0]
366
366
367 if maxVel == None:
367 if maxVel == None:
368 maxVel = velrange[-1]
368 maxVel = velrange[-1]
369
369
370 if (minVel < velrange[0]) or (minVel > maxVel):
370 if (minVel < velrange[0]) or (minVel > maxVel):
371 print('minVel: %.2f is out of the velocity range' % (minVel))
371 print('minVel: %.2f is out of the velocity range' % (minVel))
372 print('minVel is setting to %.2f' % (velrange[0]))
372 print('minVel is setting to %.2f' % (velrange[0]))
373 minVel = velrange[0]
373 minVel = velrange[0]
374
374
375 if (maxVel > velrange[-1]) or (maxVel < minVel):
375 if (maxVel > velrange[-1]) or (maxVel < minVel):
376 print('maxVel: %.2f is out of the velocity range' % (maxVel))
376 print('maxVel: %.2f is out of the velocity range' % (maxVel))
377 print('maxVel is setting to %.2f' % (velrange[-1]))
377 print('maxVel is setting to %.2f' % (velrange[-1]))
378 maxVel = velrange[-1]
378 maxVel = velrange[-1]
379
379
380 # seleccion de indices para rango
380 # seleccion de indices para rango
381 minIndex = 0
381 minIndex = 0
382 maxIndex = 0
382 maxIndex = 0
383 heights = self.dataOut.heightList
383 heights = self.dataOut.heightList
384
384
385 inda = numpy.where(heights >= minHei)
385 inda = numpy.where(heights >= minHei)
386 indb = numpy.where(heights <= maxHei)
386 indb = numpy.where(heights <= maxHei)
387
387
388 try:
388 try:
389 minIndex = inda[0][0]
389 minIndex = inda[0][0]
390 except:
390 except:
391 minIndex = 0
391 minIndex = 0
392
392
393 try:
393 try:
394 maxIndex = indb[0][-1]
394 maxIndex = indb[0][-1]
395 except:
395 except:
396 maxIndex = len(heights)
396 maxIndex = len(heights)
397
397
398 if (minIndex < 0) or (minIndex > maxIndex):
398 if (minIndex < 0) or (minIndex > maxIndex):
399 raise ValueError("some value in (%d,%d) is not valid" % (
399 raise ValueError("some value in (%d,%d) is not valid" % (
400 minIndex, maxIndex))
400 minIndex, maxIndex))
401
401
402 if (maxIndex >= self.dataOut.nHeights):
402 if (maxIndex >= self.dataOut.nHeights):
403 maxIndex = self.dataOut.nHeights - 1
403 maxIndex = self.dataOut.nHeights - 1
404
404
405 # seleccion de indices para velocidades
405 # seleccion de indices para velocidades
406 indminvel = numpy.where(velrange >= minVel)
406 indminvel = numpy.where(velrange >= minVel)
407 indmaxvel = numpy.where(velrange <= maxVel)
407 indmaxvel = numpy.where(velrange <= maxVel)
408 try:
408 try:
409 minIndexVel = indminvel[0][0]
409 minIndexVel = indminvel[0][0]
410 except:
410 except:
411 minIndexVel = 0
411 minIndexVel = 0
412
412
413 try:
413 try:
414 maxIndexVel = indmaxvel[0][-1]
414 maxIndexVel = indmaxvel[0][-1]
415 except:
415 except:
416 maxIndexVel = len(velrange)
416 maxIndexVel = len(velrange)
417
417
418 # seleccion del espectro
418 # seleccion del espectro
419 data_spc = self.dataOut.data_spc[:,
419 data_spc = self.dataOut.data_spc[:,
420 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
420 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
421 # estimacion de ruido
421 # estimacion de ruido
422 noise = numpy.zeros(self.dataOut.nChannels)
422 noise = numpy.zeros(self.dataOut.nChannels)
423
423
424 for channel in range(self.dataOut.nChannels):
424 for channel in range(self.dataOut.nChannels):
425 daux = data_spc[channel, :, :]
425 daux = data_spc[channel, :, :]
426 sortdata = numpy.sort(daux, axis=None)
426 sortdata = numpy.sort(daux, axis=None)
427 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
427 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
428
428
429 self.dataOut.noise_estimation = noise.copy()
429 self.dataOut.noise_estimation = noise.copy()
430
430
431 return 1
431 return 1
432
432
433
434 class GetSNR(Operation):
433 class GetSNR(Operation):
435 '''
434 '''
436 Written by R. Flores
435 Written by R. Flores
437 '''
436 '''
438 """Operation to get SNR.
437 """Operation to get SNR.
439
438
440 Parameters:
439 Parameters:
441 -----------
440 -----------
442
441
443 Example
442 Example
444 --------
443 --------
445
444
446 op = proc_unit.addOperation(name='GetSNR', optype='other')
445 op = proc_unit.addOperation(name='GetSNR', optype='other')
447
446
448 """
447 """
449
448
450 def __init__(self, **kwargs):
449 def __init__(self, **kwargs):
451
450
452 Operation.__init__(self, **kwargs)
451 Operation.__init__(self, **kwargs)
453
452
454 def run(self,dataOut):
453 def run(self,dataOut):
455
454
456 noise = dataOut.getNoise(ymin_index=-10) #RegiΓ³n superior donde solo deberΓ­a de haber ruido
455 noise = dataOut.getNoise(ymin_index=-10) #RegiΓ³n superior donde solo deberΓ­a de haber ruido
457 dataOut.data_snr = (dataOut.data_spc.sum(axis=1)-noise[:,None]*dataOut.nFFTPoints)/(noise[:,None]*dataOut.nFFTPoints) #It works apparently
456 dataOut.data_snr = (dataOut.data_spc.sum(axis=1)-noise[:,None]*dataOut.nFFTPoints)/(noise[:,None]*dataOut.nFFTPoints) #It works apparently
458 dataOut.snl = numpy.log10(dataOut.data_snr)
457 dataOut.snl = numpy.log10(dataOut.data_snr)
459 dataOut.snl = numpy.where(dataOut.data_snr<.01, numpy.nan, dataOut.snl)
458 dataOut.snl = numpy.where(dataOut.data_snr<.01, numpy.nan, dataOut.snl)
460
459
461 return dataOut
460 return dataOut
462
461
463 class removeDC(Operation):
462 class removeDC(Operation):
464
463
465 def run(self, dataOut, mode=2):
464 def run(self, dataOut, mode=2):
466 self.dataOut = dataOut
465 self.dataOut = dataOut
467 jspectra = self.dataOut.data_spc
466 jspectra = self.dataOut.data_spc
468 jcspectra = self.dataOut.data_cspc
467 jcspectra = self.dataOut.data_cspc
469
468
470 num_chan = jspectra.shape[0]
469 num_chan = jspectra.shape[0]
471 num_hei = jspectra.shape[2]
470 num_hei = jspectra.shape[2]
472
471
473 if jcspectra is not None:
472 if jcspectra is not None:
474 jcspectraExist = True
473 jcspectraExist = True
475 num_pairs = jcspectra.shape[0]
474 num_pairs = jcspectra.shape[0]
476 else:
475 else:
477 jcspectraExist = False
476 jcspectraExist = False
478
477
479 freq_dc = int(jspectra.shape[1] / 2)
478 freq_dc = int(jspectra.shape[1] / 2)
480 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
479 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
481 ind_vel = ind_vel.astype(int)
480 ind_vel = ind_vel.astype(int)
482
481
483 if ind_vel[0] < 0:
482 if ind_vel[0] < 0:
484 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
483 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
485
484
486 if mode == 1:
485 if mode == 1:
487 jspectra[:, freq_dc, :] = (
486 jspectra[:, freq_dc, :] = (
488 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
487 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
489
488
490 if jcspectraExist:
489 if jcspectraExist:
491 jcspectra[:, freq_dc, :] = (
490 jcspectra[:, freq_dc, :] = (
492 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
491 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
493
492
494 if mode == 2:
493 if mode == 2:
495
494
496 vel = numpy.array([-2, -1, 1, 2])
495 vel = numpy.array([-2, -1, 1, 2])
497 xx = numpy.zeros([4, 4])
496 xx = numpy.zeros([4, 4])
498
497
499 for fil in range(4):
498 for fil in range(4):
500 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
499 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
501
500
502 xx_inv = numpy.linalg.inv(xx)
501 xx_inv = numpy.linalg.inv(xx)
503 xx_aux = xx_inv[0, :]
502 xx_aux = xx_inv[0, :]
504
503
505 for ich in range(num_chan):
504 for ich in range(num_chan):
506 yy = jspectra[ich, ind_vel, :]
505 yy = jspectra[ich, ind_vel, :]
507 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
506 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
508
507
509 junkid = jspectra[ich, freq_dc, :] <= 0
508 junkid = jspectra[ich, freq_dc, :] <= 0
510 cjunkid = sum(junkid)
509 cjunkid = sum(junkid)
511
510
512 if cjunkid.any():
511 if cjunkid.any():
513 jspectra[ich, freq_dc, junkid.nonzero()] = (
512 jspectra[ich, freq_dc, junkid.nonzero()] = (
514 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
513 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
515
514
516 if jcspectraExist:
515 if jcspectraExist:
517 for ip in range(num_pairs):
516 for ip in range(num_pairs):
518 yy = jcspectra[ip, ind_vel, :]
517 yy = jcspectra[ip, ind_vel, :]
519 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
518 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
520
519
521 self.dataOut.data_spc = jspectra
520 self.dataOut.data_spc = jspectra
522 self.dataOut.data_cspc = jcspectra
521 self.dataOut.data_cspc = jcspectra
523
522
524 return self.dataOut
523 return self.dataOut
525
524
526 class removeInterference(Operation):
525 class removeInterference(Operation):
527
526
528 def removeInterference2(self):
527 def removeInterference2(self):
529
528
530 cspc = self.dataOut.data_cspc
529 cspc = self.dataOut.data_cspc
531 spc = self.dataOut.data_spc
530 spc = self.dataOut.data_spc
532 Heights = numpy.arange(cspc.shape[2])
531 Heights = numpy.arange(cspc.shape[2])
533 realCspc = numpy.abs(cspc)
532 realCspc = numpy.abs(cspc)
534
533
535 for i in range(cspc.shape[0]):
534 for i in range(cspc.shape[0]):
536 LinePower= numpy.sum(realCspc[i], axis=0)
535 LinePower= numpy.sum(realCspc[i], axis=0)
537 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
536 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
538 SelectedHeights = Heights[ numpy.where(LinePower < Threshold) ]
537 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
539 InterferenceSum = numpy.sum(realCspc[i,:,SelectedHeights],axis=0)
538 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
540 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
539 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
541 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
540 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
542
541
543
542
544 InterferenceRange = numpy.where(([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
543 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
545 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
544 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
546 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
545 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
547 cspc[i,InterferenceRange,:] = numpy.NaN
546 cspc[i,InterferenceRange,:] = numpy.NaN
548
547
549 self.dataOut.data_cspc = cspc
548 self.dataOut.data_cspc = cspc
550
549
551 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
550 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
552
551
553 jspectra = self.dataOut.data_spc
552 jspectra = self.dataOut.data_spc
554 jcspectra = self.dataOut.data_cspc
553 jcspectra = self.dataOut.data_cspc
555 jnoise = self.dataOut.getNoise()
554 jnoise = self.dataOut.getNoise()
556 num_incoh = self.dataOut.nIncohInt
555 num_incoh = self.dataOut.nIncohInt
557
556
558 num_channel = jspectra.shape[0]
557 num_channel = jspectra.shape[0]
559 num_prof = jspectra.shape[1]
558 num_prof = jspectra.shape[1]
560 num_hei = jspectra.shape[2]
559 num_hei = jspectra.shape[2]
561
560
562 # hei_interf
561 # hei_interf
563 if hei_interf is None:
562 if hei_interf is None:
564 count_hei = int(num_hei / 2)
563 count_hei = int(num_hei / 2)
565 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
564 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
566 hei_interf = numpy.asarray(hei_interf)[0]
565 hei_interf = numpy.asarray(hei_interf)[0]
567 # nhei_interf
566 # nhei_interf
568 if (nhei_interf == None):
567 if (nhei_interf == None):
569 nhei_interf = 5
568 nhei_interf = 5
570 if (nhei_interf < 1):
569 if (nhei_interf < 1):
571 nhei_interf = 1
570 nhei_interf = 1
572 if (nhei_interf > count_hei):
571 if (nhei_interf > count_hei):
573 nhei_interf = count_hei
572 nhei_interf = count_hei
574 if (offhei_interf == None):
573 if (offhei_interf == None):
575 offhei_interf = 0
574 offhei_interf = 0
576
575
577 ind_hei = list(range(num_hei))
576 ind_hei = list(range(num_hei))
578 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
577 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
579 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
578 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
580 mask_prof = numpy.asarray(list(range(num_prof)))
579 mask_prof = numpy.asarray(list(range(num_prof)))
581 num_mask_prof = mask_prof.size
580 num_mask_prof = mask_prof.size
582 comp_mask_prof = [0, num_prof / 2]
581 comp_mask_prof = [0, num_prof / 2]
583
582
584 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
583 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
585 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
584 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
586 jnoise = numpy.nan
585 jnoise = numpy.nan
587 noise_exist = jnoise[0] < numpy.Inf
586 noise_exist = jnoise[0] < numpy.Inf
588
587
589 # Subrutina de Remocion de la Interferencia
588 # Subrutina de Remocion de la Interferencia
590 for ich in range(num_channel):
589 for ich in range(num_channel):
591 # Se ordena los espectros segun su potencia (menor a mayor)
590 # Se ordena los espectros segun su potencia (menor a mayor)
592 power = jspectra[ich, mask_prof, :]
591 power = jspectra[ich, mask_prof, :]
593 power = power[:, hei_interf]
592 power = power[:, hei_interf]
594 power = power.sum(axis=0)
593 power = power.sum(axis=0)
595 psort = power.ravel().argsort()
594 psort = power.ravel().argsort()
596
595
597 # Se estima la interferencia promedio en los Espectros de Potencia empleando
596 # Se estima la interferencia promedio en los Espectros de Potencia empleando
598 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
597 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
599 offhei_interf, nhei_interf + offhei_interf))]]]
598 offhei_interf, nhei_interf + offhei_interf))]]]
600
599
601 if noise_exist:
600 if noise_exist:
602 # tmp_noise = jnoise[ich] / num_prof
601 # tmp_noise = jnoise[ich] / num_prof
603 tmp_noise = jnoise[ich]
602 tmp_noise = jnoise[ich]
604 junkspc_interf = junkspc_interf - tmp_noise
603 junkspc_interf = junkspc_interf - tmp_noise
605 #junkspc_interf[:,comp_mask_prof] = 0
604 #junkspc_interf[:,comp_mask_prof] = 0
606
605
607 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
606 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
608 jspc_interf = jspc_interf.transpose()
607 jspc_interf = jspc_interf.transpose()
609 # Calculando el espectro de interferencia promedio
608 # Calculando el espectro de interferencia promedio
610 noiseid = numpy.where(
609 noiseid = numpy.where(
611 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
610 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
612 noiseid = noiseid[0]
611 noiseid = noiseid[0]
613 cnoiseid = noiseid.size
612 cnoiseid = noiseid.size
614 interfid = numpy.where(
613 interfid = numpy.where(
615 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
614 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
616 interfid = interfid[0]
615 interfid = interfid[0]
617 cinterfid = interfid.size
616 cinterfid = interfid.size
618
617
619 if (cnoiseid > 0):
618 if (cnoiseid > 0):
620 jspc_interf[noiseid] = 0
619 jspc_interf[noiseid] = 0
621
620
622 # Expandiendo los perfiles a limpiar
621 # Expandiendo los perfiles a limpiar
623 if (cinterfid > 0):
622 if (cinterfid > 0):
624 new_interfid = (
623 new_interfid = (
625 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
624 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
626 new_interfid = numpy.asarray(new_interfid)
625 new_interfid = numpy.asarray(new_interfid)
627 new_interfid = {x for x in new_interfid}
626 new_interfid = {x for x in new_interfid}
628 new_interfid = numpy.array(list(new_interfid))
627 new_interfid = numpy.array(list(new_interfid))
629 new_cinterfid = new_interfid.size
628 new_cinterfid = new_interfid.size
630 else:
629 else:
631 new_cinterfid = 0
630 new_cinterfid = 0
632
631
633 for ip in range(new_cinterfid):
632 for ip in range(new_cinterfid):
634 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
633 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
635 jspc_interf[new_interfid[ip]
634 jspc_interf[new_interfid[ip]
636 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
635 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
637
636
638 jspectra[ich, :, ind_hei] = jspectra[ich, :,
637 jspectra[ich, :, ind_hei] = jspectra[ich, :,
639 ind_hei] - jspc_interf # Corregir indices
638 ind_hei] - jspc_interf # Corregir indices
640
639
641 # Removiendo la interferencia del punto de mayor interferencia
640 # Removiendo la interferencia del punto de mayor interferencia
642 ListAux = jspc_interf[mask_prof].tolist()
641 ListAux = jspc_interf[mask_prof].tolist()
643 maxid = ListAux.index(max(ListAux))
642 maxid = ListAux.index(max(ListAux))
644
643
645 if cinterfid > 0:
644 if cinterfid > 0:
646 for ip in range(cinterfid * (interf == 2) - 1):
645 for ip in range(cinterfid * (interf == 2) - 1):
647 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
646 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
648 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
647 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
649 cind = len(ind)
648 cind = len(ind)
650
649
651 if (cind > 0):
650 if (cind > 0):
652 jspectra[ich, interfid[ip], ind] = tmp_noise * \
651 jspectra[ich, interfid[ip], ind] = tmp_noise * \
653 (1 + (numpy.random.uniform(cind) - 0.5) /
652 (1 + (numpy.random.uniform(cind) - 0.5) /
654 numpy.sqrt(num_incoh))
653 numpy.sqrt(num_incoh))
655
654
656 ind = numpy.array([-2, -1, 1, 2])
655 ind = numpy.array([-2, -1, 1, 2])
657 xx = numpy.zeros([4, 4])
656 xx = numpy.zeros([4, 4])
658
657
659 for id1 in range(4):
658 for id1 in range(4):
660 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
659 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
661
660
662 xx_inv = numpy.linalg.inv(xx)
661 xx_inv = numpy.linalg.inv(xx)
663 xx = xx_inv[:, 0]
662 xx = xx_inv[:, 0]
664 ind = (ind + maxid + num_mask_prof) % num_mask_prof
663 ind = (ind + maxid + num_mask_prof) % num_mask_prof
665 yy = jspectra[ich, mask_prof[ind], :]
664 yy = jspectra[ich, mask_prof[ind], :]
666 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
665 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
667 yy.transpose(), xx)
666 yy.transpose(), xx)
668
667
669 indAux = (jspectra[ich, :, :] < tmp_noise *
668 indAux = (jspectra[ich, :, :] < tmp_noise *
670 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
669 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
671 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
670 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
672 (1 - 1 / numpy.sqrt(num_incoh))
671 (1 - 1 / numpy.sqrt(num_incoh))
673
672
674 # Remocion de Interferencia en el Cross Spectra
673 # Remocion de Interferencia en el Cross Spectra
675 if jcspectra is None:
674 if jcspectra is None:
676 return jspectra, jcspectra
675 return jspectra, jcspectra
677 num_pairs = int(jcspectra.size / (num_prof * num_hei))
676 num_pairs = int(jcspectra.size / (num_prof * num_hei))
678 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
677 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
679
678
680 for ip in range(num_pairs):
679 for ip in range(num_pairs):
681
680
682 #-------------------------------------------
681 #-------------------------------------------
683
682
684 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
683 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
685 cspower = cspower[:, hei_interf]
684 cspower = cspower[:, hei_interf]
686 cspower = cspower.sum(axis=0)
685 cspower = cspower.sum(axis=0)
687
686
688 cspsort = cspower.ravel().argsort()
687 cspsort = cspower.ravel().argsort()
689 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
688 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
690 offhei_interf, nhei_interf + offhei_interf))]]]
689 offhei_interf, nhei_interf + offhei_interf))]]]
691 junkcspc_interf = junkcspc_interf.transpose()
690 junkcspc_interf = junkcspc_interf.transpose()
692 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
691 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
693
692
694 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
693 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
695
694
696 median_real = int(numpy.median(numpy.real(
695 median_real = int(numpy.median(numpy.real(
697 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
696 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
698 median_imag = int(numpy.median(numpy.imag(
697 median_imag = int(numpy.median(numpy.imag(
699 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
698 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
700 comp_mask_prof = [int(e) for e in comp_mask_prof]
699 comp_mask_prof = [int(e) for e in comp_mask_prof]
701 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
700 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
702 median_real, median_imag)
701 median_real, median_imag)
703
702
704 for iprof in range(num_prof):
703 for iprof in range(num_prof):
705 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
704 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
706 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
705 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
707
706
708 # Removiendo la Interferencia
707 # Removiendo la Interferencia
709 jcspectra[ip, :, ind_hei] = jcspectra[ip,
708 jcspectra[ip, :, ind_hei] = jcspectra[ip,
710 :, ind_hei] - jcspc_interf
709 :, ind_hei] - jcspc_interf
711
710
712 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
711 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
713 maxid = ListAux.index(max(ListAux))
712 maxid = ListAux.index(max(ListAux))
714
713
715 ind = numpy.array([-2, -1, 1, 2])
714 ind = numpy.array([-2, -1, 1, 2])
716 xx = numpy.zeros([4, 4])
715 xx = numpy.zeros([4, 4])
717
716
718 for id1 in range(4):
717 for id1 in range(4):
719 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
718 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
720
719
721 xx_inv = numpy.linalg.inv(xx)
720 xx_inv = numpy.linalg.inv(xx)
722 xx = xx_inv[:, 0]
721 xx = xx_inv[:, 0]
723
722
724 ind = (ind + maxid + num_mask_prof) % num_mask_prof
723 ind = (ind + maxid + num_mask_prof) % num_mask_prof
725 yy = jcspectra[ip, mask_prof[ind], :]
724 yy = jcspectra[ip, mask_prof[ind], :]
726 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
725 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
727
726
728 # Guardar Resultados
727 # Guardar Resultados
729 self.dataOut.data_spc = jspectra
728 self.dataOut.data_spc = jspectra
730 self.dataOut.data_cspc = jcspectra
729 self.dataOut.data_cspc = jcspectra
731
730
732 return 1
731 return 1
733
732
734 def run(self, dataOut, interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None, mode=1):
733 def run(self, dataOut, interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None, mode=1):
735
734
736 self.dataOut = dataOut
735 self.dataOut = dataOut
737
736
738 if mode == 1:
737 if mode == 1:
739 self.removeInterference(interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None)
738 self.removeInterference(interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None)
740 elif mode == 2:
739 elif mode == 2:
741 self.removeInterference2()
740 self.removeInterference2()
742
741
743 return self.dataOut
742 return self.dataOut
744
743
745
744
746 class deflip(Operation):
745 class deflip(Operation):
747
746
748 def run(self, dataOut):
747 def run(self, dataOut):
749 # arreglo 1: (num_chan, num_profiles, num_heights)
748 # arreglo 1: (num_chan, num_profiles, num_heights)
750 self.dataOut = dataOut
749 self.dataOut = dataOut
751
750
752 # JULIA-oblicua, indice 2
751 # JULIA-oblicua, indice 2
753 # arreglo 2: (num_profiles, num_heights)
752 # arreglo 2: (num_profiles, num_heights)
754 jspectra = self.dataOut.data_spc[2]
753 jspectra = self.dataOut.data_spc[2]
755 jspectra_tmp=numpy.zeros(jspectra.shape)
754 jspectra_tmp=numpy.zeros(jspectra.shape)
756 num_profiles=jspectra.shape[0]
755 num_profiles=jspectra.shape[0]
757 freq_dc = int(num_profiles / 2)
756 freq_dc = int(num_profiles / 2)
758 # Flip con for
757 # Flip con for
759 for j in range(num_profiles):
758 for j in range(num_profiles):
760 jspectra_tmp[num_profiles-j-1]= jspectra[j]
759 jspectra_tmp[num_profiles-j-1]= jspectra[j]
761 # Intercambio perfil de DC con perfil inmediato anterior
760 # Intercambio perfil de DC con perfil inmediato anterior
762 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
761 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
763 jspectra_tmp[freq_dc]= jspectra[freq_dc]
762 jspectra_tmp[freq_dc]= jspectra[freq_dc]
764 # canal modificado es re-escrito en el arreglo de canales
763 # canal modificado es re-escrito en el arreglo de canales
765 self.dataOut.data_spc[2] = jspectra_tmp
764 self.dataOut.data_spc[2] = jspectra_tmp
766
765
767 return self.dataOut
766 return self.dataOut
768
767
769
768
770 class IncohInt(Operation):
769 class IncohInt(Operation):
771
770
772 __profIndex = 0
771 __profIndex = 0
773 __withOverapping = False
772 __withOverapping = False
774
773
775 __byTime = False
774 __byTime = False
776 __initime = None
775 __initime = None
777 __lastdatatime = None
776 __lastdatatime = None
778 __integrationtime = None
777 __integrationtime = None
779
778
780 __buffer_spc = None
779 __buffer_spc = None
781 __buffer_cspc = None
780 __buffer_cspc = None
782 __buffer_dc = None
781 __buffer_dc = None
783
782
784 __dataReady = False
783 __dataReady = False
785
784
786 __timeInterval = None
785 __timeInterval = None
787
786
788 n = None
787 n = None
789
788
790 def __init__(self):
789 def __init__(self):
791
790
792 Operation.__init__(self)
791 Operation.__init__(self)
793
792
794 def setup(self, n=None, timeInterval=None, overlapping=False):
793 def setup(self, n=None, timeInterval=None, overlapping=False):
795 """
794 """
796 Set the parameters of the integration class.
795 Set the parameters of the integration class.
797
796
798 Inputs:
797 Inputs:
799
798
800 n : Number of coherent integrations
799 n : Number of coherent integrations
801 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
800 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
802 overlapping :
801 overlapping :
803
802
804 """
803 """
805
804
806 self.__initime = None
805 self.__initime = None
807 self.__lastdatatime = 0
806 self.__lastdatatime = 0
808
807
809 self.__buffer_spc = 0
808 self.__buffer_spc = 0
810 self.__buffer_cspc = 0
809 self.__buffer_cspc = 0
811 self.__buffer_dc = 0
810 self.__buffer_dc = 0
812
811
813 self.__profIndex = 0
812 self.__profIndex = 0
814 self.__dataReady = False
813 self.__dataReady = False
815 self.__byTime = False
814 self.__byTime = False
816
815
817 if n is None and timeInterval is None:
816 if n is None and timeInterval is None:
818 raise ValueError("n or timeInterval should be specified ...")
817 raise ValueError("n or timeInterval should be specified ...")
819
818
820 if n is not None:
819 if n is not None:
821 self.n = int(n)
820 self.n = int(n)
822 else:
821 else:
823
822
824 self.__integrationtime = int(timeInterval)
823 self.__integrationtime = int(timeInterval)
825 self.n = None
824 self.n = None
826 self.__byTime = True
825 self.__byTime = True
827
826
828 def putData(self, data_spc, data_cspc, data_dc):
827 def putData(self, data_spc, data_cspc, data_dc):
829 """
828 """
830 Add a profile to the __buffer_spc and increase in one the __profileIndex
829 Add a profile to the __buffer_spc and increase in one the __profileIndex
831
830
832 """
831 """
833
832
834 self.__buffer_spc += data_spc
833 self.__buffer_spc += data_spc
835
834
836 if data_cspc is None:
835 if data_cspc is None:
837 self.__buffer_cspc = None
836 self.__buffer_cspc = None
838 else:
837 else:
839 self.__buffer_cspc += data_cspc
838 self.__buffer_cspc += data_cspc
840
839
841 if data_dc is None:
840 if data_dc is None:
842 self.__buffer_dc = None
841 self.__buffer_dc = None
843 else:
842 else:
844 self.__buffer_dc += data_dc
843 self.__buffer_dc += data_dc
845
844
846 self.__profIndex += 1
845 self.__profIndex += 1
847
846
848 return
847 return
849
848
850 def pushData(self):
849 def pushData(self):
851 """
850 """
852 Return the sum of the last profiles and the profiles used in the sum.
851 Return the sum of the last profiles and the profiles used in the sum.
853
852
854 Affected:
853 Affected:
855
854
856 self.__profileIndex
855 self.__profileIndex
857
856
858 """
857 """
859
858
860 data_spc = self.__buffer_spc
859 data_spc = self.__buffer_spc
861 data_cspc = self.__buffer_cspc
860 data_cspc = self.__buffer_cspc
862 data_dc = self.__buffer_dc
861 data_dc = self.__buffer_dc
863 n = self.__profIndex
862 n = self.__profIndex
864
863
865 self.__buffer_spc = 0
864 self.__buffer_spc = 0
866 self.__buffer_cspc = 0
865 self.__buffer_cspc = 0
867 self.__buffer_dc = 0
866 self.__buffer_dc = 0
868 self.__profIndex = 0
867 self.__profIndex = 0
869
868
870 return data_spc, data_cspc, data_dc, n
869 return data_spc, data_cspc, data_dc, n
871
870
872 def byProfiles(self, *args):
871 def byProfiles(self, *args):
873
872
874 self.__dataReady = False
873 self.__dataReady = False
875 avgdata_spc = None
874 avgdata_spc = None
876 avgdata_cspc = None
875 avgdata_cspc = None
877 avgdata_dc = None
876 avgdata_dc = None
878
877
879 self.putData(*args)
878 self.putData(*args)
880
879
881 if self.__profIndex == self.n:
880 if self.__profIndex == self.n:
882
881
883 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
882 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
884 self.n = n
883 self.n = n
885 self.__dataReady = True
884 self.__dataReady = True
886
885
887 return avgdata_spc, avgdata_cspc, avgdata_dc
886 return avgdata_spc, avgdata_cspc, avgdata_dc
888
887
889 def byTime(self, datatime, *args):
888 def byTime(self, datatime, *args):
890
889
891 self.__dataReady = False
890 self.__dataReady = False
892 avgdata_spc = None
891 avgdata_spc = None
893 avgdata_cspc = None
892 avgdata_cspc = None
894 avgdata_dc = None
893 avgdata_dc = None
895
894
896 self.putData(*args)
895 self.putData(*args)
897
896
898 if (datatime - self.__initime) >= self.__integrationtime:
897 if (datatime - self.__initime) >= self.__integrationtime:
899 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
898 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
900 self.n = n
899 self.n = n
901 self.__dataReady = True
900 self.__dataReady = True
902
901
903 return avgdata_spc, avgdata_cspc, avgdata_dc
902 return avgdata_spc, avgdata_cspc, avgdata_dc
904
903
905 def integrate(self, datatime, *args):
904 def integrate(self, datatime, *args):
906
905
907 if self.__profIndex == 0:
906 if self.__profIndex == 0:
908 self.__initime = datatime
907 self.__initime = datatime
909
908
910 if self.__byTime:
909 if self.__byTime:
911 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
910 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
912 datatime, *args)
911 datatime, *args)
913 else:
912 else:
914 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
913 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
915
914
916 if not self.__dataReady:
915 if not self.__dataReady:
917 return None, None, None, None
916 return None, None, None, None
918
917
919 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
918 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
920
919
921 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
920 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
922 if n == 1:
921 if n == 1:
923 return dataOut
922 return dataOut
924
923
925 dataOut.flagNoData = True
924 dataOut.flagNoData = True
926
925
927 if not self.isConfig:
926 if not self.isConfig:
928 self.setup(n, timeInterval, overlapping)
927 self.setup(n, timeInterval, overlapping)
929 self.isConfig = True
928 self.isConfig = True
930
929
931 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
930 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
932 dataOut.data_spc,
931 dataOut.data_spc,
933 dataOut.data_cspc,
932 dataOut.data_cspc,
934 dataOut.data_dc)
933 dataOut.data_dc)
935
934
936 if self.__dataReady:
935 if self.__dataReady:
937
936
938 dataOut.data_spc = avgdata_spc
937 dataOut.data_spc = avgdata_spc
939 dataOut.data_cspc = avgdata_cspc
938 dataOut.data_cspc = avgdata_cspc
940 dataOut.data_dc = avgdata_dc
939 dataOut.data_dc = avgdata_dc
941 dataOut.nIncohInt *= self.n
940 dataOut.nIncohInt *= self.n
942 dataOut.utctime = avgdatatime
941 dataOut.utctime = avgdatatime
943 dataOut.flagNoData = False
942 dataOut.flagNoData = False
944
943
945 return dataOut
944 return dataOut
946
945
947 class dopplerFlip(Operation):
946 class dopplerFlip(Operation):
948
947
949 def run(self, dataOut):
948 def run(self, dataOut):
950 # arreglo 1: (num_chan, num_profiles, num_heights)
949 # arreglo 1: (num_chan, num_profiles, num_heights)
951 self.dataOut = dataOut
950 self.dataOut = dataOut
952 # JULIA-oblicua, indice 2
951 # JULIA-oblicua, indice 2
953 # arreglo 2: (num_profiles, num_heights)
952 # arreglo 2: (num_profiles, num_heights)
954 jspectra = self.dataOut.data_spc[2]
953 jspectra = self.dataOut.data_spc[2]
955 jspectra_tmp = numpy.zeros(jspectra.shape)
954 jspectra_tmp = numpy.zeros(jspectra.shape)
956 num_profiles = jspectra.shape[0]
955 num_profiles = jspectra.shape[0]
957 freq_dc = int(num_profiles / 2)
956 freq_dc = int(num_profiles / 2)
958 # Flip con for
957 # Flip con for
959 for j in range(num_profiles):
958 for j in range(num_profiles):
960 jspectra_tmp[num_profiles-j-1]= jspectra[j]
959 jspectra_tmp[num_profiles-j-1]= jspectra[j]
961 # Intercambio perfil de DC con perfil inmediato anterior
960 # Intercambio perfil de DC con perfil inmediato anterior
962 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
961 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
963 jspectra_tmp[freq_dc]= jspectra[freq_dc]
962 jspectra_tmp[freq_dc]= jspectra[freq_dc]
964 # canal modificado es re-escrito en el arreglo de canales
963 # canal modificado es re-escrito en el arreglo de canales
965 self.dataOut.data_spc[2] = jspectra_tmp
964 self.dataOut.data_spc[2] = jspectra_tmp
966
965
967 return self.dataOut No newline at end of file
966 return self.dataOut
@@ -1,291 +1,291
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 '''
2 '''
3 Created on Jul 7, 2014
3 Created on Jul 7, 2014
4
4
5 @author: roj-idl71
5 @author: roj-idl71
6 '''
6 '''
7 import os, sys, json
7 import os, sys, json
8
8
9 #path = os.path.dirname(os.getcwd())
9 #path = os.path.dirname(os.getcwd())
10 #path = os.path.join(path, 'source')
10 #path = os.path.join(path, 'source')
11 #sys.path.insert(0, path)
11 #sys.path.insert(0, path)
12
12
13 from schainpy.controller import Project
13 from schainpy.controller import Project
14
14
15 if __name__ == '__main__':
15 if __name__ == '__main__':
16
16
17 desc = "JULIA raw experiment "
17 desc = "JULIA raw experiment "
18 filename = "schain.xml"
18 filename = "schain.xml"
19
19
20 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2022/'
20 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2022/'
21 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2021/'
21 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2021/'
22 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2017/'
22 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2017/'
23 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2021/'
23 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2021/'
24 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2018/'
24 dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2018/'
25 #dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2017/'
25 #dpath = '/home/roberto/puma/JULIA_NEW/JULIA_EW/D2017/'
26 #dpath = '/home/roberto/Folder_aux/D2019/'
26 #dpath = '/home/roberto/Folder_aux/D2019/'
27
27
28 ##dpath = '/home/roberto/puma/JULIA_EW_IMAGING/JULIA_EW/D2017/'
28 ##dpath = '/home/roberto/puma/JULIA_EW_IMAGING/JULIA_EW/D2017/'
29 dpath = '/home/soporte/PUMA/JULIA_EW_IMAGING/JULIA_EW/D2017/'
29 dpath = '/home/soporte/PUMA/JULIA_EW_IMAGING/JULIA_EW/D2017/'
30
30
31 figpath = '/home/soporte/DATA/Pictures/JULIA/EEJ/Skew_but_dop_is_shift'+'/'+dpath[-5:-1]
31 figpath = '/home/soporte/DATA/Pictures/JULIA/EEJ/Skew_but_dop_is_shift'+'/'+dpath[-5:-1]
32 ppath = "/home/soporte/DATA/MLT/Oblique/2022_03/data_reshape"
32 ppath = "/home/soporte/DATA/MLT/Oblique/2022_03/data_reshape"
33 spcdata = '/home/soporte/DATA/JULIA/EEJ/SPC'
33 spcdata = '/home/soporte/DATA/JULIA/EEJ/SPC'
34 path_parameters = '/home/soporte/DATA/JULIA/EEJ/Params'
34 path_parameters = '/home/soporte/DATA/JULIA/EEJ/Params'
35 db_range=['25','35']
35 db_range=['25','35']
36 db_range=['10','20']
36 db_range=['10','20']
37 #db_range=['14','20']
37 #db_range=['14','20']
38 db_range=['10','23']
38 db_range=['10','23']
39 db_range=['13','20']
39 db_range=['13','20']
40 db_range=['21','30']
40 db_range=['21','30']
41 db_range=['15','30']
41 db_range=['15','30']
42 db_range=['13','28']
42 db_range=['13','28']
43 tiempo=['7','18']
43 tiempo=['7','18']
44 altura1=[2,20]
44 altura1=[2,20]
45 altura1=[90,220]
45 altura1=[90,220]
46 velocity=['-80','80']
46 velocity=['-80','80']
47 period=60
47 period=60
48 # PROJECT 1
48 # PROJECT 1
49
49
50 show_spc = 0
50 show_spc = 0
51 save_spc = 0
51 save_spc = 0
52 fitting = 1
52 fitting = 1
53 save_params = 1
53 save_params = 1
54 plot_params = 0
54 plot_params = 0
55
55
56 controllerObj = Project()
56 controllerObj = Project()
57 controllerObj.setup(id = '191', name='altura1', description=desc)
57 controllerObj.setup(id = '191', name='altura1', description=desc)
58
58
59 readUnitConfObj1 = controllerObj.addReadUnit(datatype='SpectraReader',
59 readUnitConfObj1 = controllerObj.addReadUnit(datatype='SpectraReader',
60 path=dpath,
60 path=dpath,
61 startDate='2017/09/01', #Check 21-29 Jun 2021, 18 May 2022
61 startDate='2017/09/01', #Check 21-29 Jun 2021, 18 May 2022
62 endDate='2017/09/30', #05,06,07-01-18
62 endDate='2017/09/30', #05,06,07-01-18
63 #startTime='06:00:00',
63 #startTime='06:00:00',
64 #endTime='18:00:00',
64 #endTime='18:00:00',
65 startTime='07:00:00',
65 startTime='07:00:00',
66 #startTime='10:00:00',
66 #startTime='10:00:00',
67 #startTime='08:38:01',
67 #startTime='08:38:01',
68 #startTime='11:16:00',
68 #startTime='11:16:00',
69 #startTime='08:13:00',
69 #startTime='08:13:00',
70 endTime='17:59:59',
70 endTime='17:59:59',
71 #startTime='16:30:00',
71 #startTime='16:30:00',
72 #endTime='17:30:59',
72 #endTime='17:30:59',
73 online=0,
73 online=0,
74 walk=1,
74 walk=1,
75 expLabel='150EEJ',
75 expLabel='150EEJ',
76 getByBlock=1,
76 getByBlock=1,
77 delay=20)
77 delay=20)
78
78
79 # opObj00 = readUnitConfObj.addOperation(name='printInfo')
79 # opObj00 = readUnitConfObj.addOperation(name='printInfo')
80 # opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
80 # opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
81
81
82 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=readUnitConfObj1.getId())
82 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=readUnitConfObj1.getId())
83
83
84 opObj11 = procUnitConfObj1.addOperation(name='selectChannels')
84 opObj11 = procUnitConfObj1.addOperation(name='selectChannels')
85 opObj11.addParameter(name='channelList', value='2,', format='intlist')
85 opObj11.addParameter(name='channelList', value='2,', format='intlist')
86
86
87 '''
87 '''
88 opObj11 = procUnitConfObj1SPC.addOperation(name='removeDC')
88 opObj11 = procUnitConfObj1SPC.addOperation(name='removeDC')
89 opObj11.addParameter(name='mode', value='2', format='int')
89 opObj11.addParameter(name='mode', value='2', format='int')
90 '''
90 '''
91
91
92 #opObj11 = procUnitConfObj1.addOperation(name='dopplerFlip') #It fixes the Doppler
92 #opObj11 = procUnitConfObj1.addOperation(name='dopplerFlip') #It fixes the Doppler
93 #opObj11.addParameter(name='chann', value='0', format='int')
93 #opObj11.addParameter(name='chann', value='0', format='int')
94
94
95 opObj11 = procUnitConfObj1.addOperation(name='removeInterference')
95 opObj11 = procUnitConfObj1.addOperation(name='removeInterference')
96
96
97 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
97 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
98 #opObj11.addParameter(name='n', value='20', format='int')
98 #opObj11.addParameter(name='n', value='20', format='int')
99 opObj11.addParameter(name='n', value='1', format='int')
99 opObj11.addParameter(name='n', value='1', format='int')
100
100
101 opObj11 = procUnitConfObj1.addOperation(name='GetSNR', optype='other')
101 opObj11 = procUnitConfObj1.addOperation(name='GetSNR', optype='other')
102
102
103 if save_spc:
103 if save_spc:
104 dataList=['data_spc',
104 dataList=['data_spc',
105 'utctime']
105 'utctime']
106 metadataList=['nFFTPoints','VelRange','normFactor',
106 metadataList=['nFFTPoints','VelRange','normFactor',
107 'heightList','timeZone']
107 'heightList','timeZone']
108
108
109 op221 = procUnitConfObj1.addOperation(name='HDFWriter', optype='external')
109 op221 = procUnitConfObj1.addOperation(name='HDFWriter', optype='external')
110 op221.addParameter(name='path', value=spcdata)
110 op221.addParameter(name='path', value=spcdata)
111 #op221.addParameter(name='mode', value=1, format='int')
111 #op221.addParameter(name='mode', value=1, format='int')
112 op221.addParameter(name='dataList', value=dataList)
112 op221.addParameter(name='dataList', value=dataList)
113 op221.addParameter(name='metadataList', value=metadataList)
113 op221.addParameter(name='metadataList', value=metadataList)
114 #op221.addParameter(name='blocksPerFile', value=500)
114 #op221.addParameter(name='blocksPerFile', value=500)
115 op221.addParameter(name='blocksPerFile', value=2000)
115 op221.addParameter(name='blocksPerFile', value=2000)
116
116
117 if show_spc:
117 if show_spc:
118 #'''
118 #'''
119 # opObj11 = procUnitConfObj1SPC.addOperation(name='removeInterference')
119 # opObj11 = procUnitConfObj1SPC.addOperation(name='removeInterference')
120
120
121 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
121 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
122 opObj11.addParameter(name='id', value='1', format='int')
122 opObj11.addParameter(name='id', value='1', format='int')
123 opObj11.addParameter(name='wintitle', value='Oblique', format='str')
123 opObj11.addParameter(name='wintitle', value='Oblique', format='str')
124 opObj11.addParameter(name='zmin', value=db_range[0], format='int')
124 opObj11.addParameter(name='zmin', value=db_range[0], format='int')
125 opObj11.addParameter(name='zmax', value=db_range[1], format='int')
125 opObj11.addParameter(name='zmax', value=db_range[1], format='int')
126 opObj11.addParameter(name='xaxis', value='velocity', format='str')
126 opObj11.addParameter(name='xaxis', value='velocity', format='str')
127 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
127 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
128 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
128 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
129 # opObj11.addParameter(name='xmin', value=velocity[0], format='int')
129 # opObj11.addParameter(name='xmin', value=velocity[0], format='int')
130 # opObj11.addParameter(name='xmax', value=velocity[1], format='int')
130 # opObj11.addParameter(name='xmax', value=velocity[1], format='int')
131 opObj11.addParameter(name='showprofile', value='1', format='int')
131 opObj11.addParameter(name='showprofile', value='1', format='int')
132 opObj11.addParameter(name='save', value=figpath, format='str')
132 opObj11.addParameter(name='save', value=figpath, format='str')
133 #'''
133 #'''
134 #'''
134 #'''
135 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
135 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
136 opObj11.addParameter(name='id', value='10', format='int')
136 opObj11.addParameter(name='id', value='10', format='int')
137 opObj11.addParameter(name='wintitle', value='JULIA EEJ RTI', format='str')
137 opObj11.addParameter(name='wintitle', value='JULIA EEJ RTI', format='str')
138 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
138 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
139 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
139 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
140 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
140 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
141 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
141 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
142 opObj11.addParameter(name='zmin', value=db_range[0], format='int')
142 opObj11.addParameter(name='zmin', value=db_range[0], format='int')
143 opObj11.addParameter(name='zmax', value=db_range[1], format='int')
143 opObj11.addParameter(name='zmax', value=db_range[1], format='int')
144 opObj11.addParameter(name='showprofile', value='1', format='int')
144 opObj11.addParameter(name='showprofile', value='1', format='int')
145 #opObj11.addParameter(name='save_period', value=40, format='str')
145 #opObj11.addParameter(name='save_period', value=40, format='str')
146 opObj11.addParameter(name='save', value=figpath, format='str')
146 opObj11.addParameter(name='save', value=figpath, format='str')
147 #opObj11.addParameter(name='throttle', value=1, format='str')
147 #opObj11.addParameter(name='throttle', value=1, format='str')
148 #'''
148 #'''
149 '''
149 '''
150 opObj11 = procUnitConfObj1.addOperation(name='SnrPlot', optype='other')
150 opObj11 = procUnitConfObj1.addOperation(name='SnrPlot', optype='other')
151 opObj11.addParameter(name='id', value='10', format='int')
151 opObj11.addParameter(name='id', value='10', format='int')
152 opObj11.addParameter(name='wintitle', value='JULIA EEJ SNR', format='str')
152 opObj11.addParameter(name='wintitle', value='JULIA EEJ SNR', format='str')
153 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
153 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
154 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
154 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
155 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
155 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
156 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
156 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
157 opObj11.addParameter(name='zmin', value=0.1, format='int')
157 opObj11.addParameter(name='zmin', value=0.1, format='int')
158 opObj11.addParameter(name='zmax', value=50, format='int')
158 opObj11.addParameter(name='zmax', value=50, format='int')
159 #opObj11.addParameter(name='showprofile', value='1', format='int')
159 #opObj11.addParameter(name='showprofile', value='1', format='int')
160 opObj11.addParameter(name='save', value=figpath, format='str')
160 opObj11.addParameter(name='save', value=figpath, format='str')
161 '''
161 '''
162 if fitting:
162 if fitting:
163 Dop = 'Max' #Plot and Save the Pos[Max_val] as the Doppler Shift
163 Dop = 'Max' #Plot and Save the Pos[Max_val] as the Doppler Shift
164 Dop = 'Shift' #Plot and Save the Skew Gaussian Shift as the Doppler Shift
164 Dop = 'Shift' #Plot and Save the Skew Gaussian Shift as the Doppler Shift
165 opObj11 = procUnitConfObj1.addOperation(name='Oblique_Gauss_Fit', optype='other')
165 opObj11 = procUnitConfObj1.addOperation(name='Oblique_Gauss_Fit', optype='other')
166 opObj11.addParameter(name='mode', value=9, format='int') #Skew
166 opObj11.addParameter(name='mode', value=9, format='int') #Skew
167 opObj11.addParameter(name='Dop', value=Dop)
167 opObj11.addParameter(name='Dop', value=Dop)
168 #opObj11.addParameter(name='mode', value=11, format='int')
168 #opObj11.addParameter(name='mode', value=11, format='int')
169
169
170 if save_params:
170 if save_params:
171 '''
171 '''
172 dataList=['powerdB', 'Oblique_params', 'Oblique_param_errors', 'dplr_2_u', 'data_snr',
172 dataList=['powerdB', 'Oblique_params', 'Oblique_param_errors', 'dplr_2_u', 'data_snr',
173 'utctime']
173 'utctime']
174 metadataList=['VelRange',
174 metadataList=['VelRange',
175 'heightList','timeZone']
175 'heightList','timeZone']
176
176
177 op221 = procUnitConfObj1.addOperation(name='HDFWriter', optype='external')
177 op221 = procUnitConfObj1.addOperation(name='HDFWriter', optype='external')
178 op221.addParameter(name='path', value=path_parameters)
178 op221.addParameter(name='path', value=path_parameters)
179 #op221.addParameter(name='mode', value=1, format='int')
179 #op221.addParameter(name='mode', value=1, format='int')
180 op221.addParameter(name='dataList', value=dataList)
180 op221.addParameter(name='dataList', value=dataList)
181 op221.addParameter(name='metadataList', value=metadataList)
181 op221.addParameter(name='metadataList', value=metadataList)
182 #op221.addParameter(name='blocksPerFile', value=500)
182 #op221.addParameter(name='blocksPerFile', value=500)
183 op221.addParameter(name='blocksPerFile', value=2000)
183 op221.addParameter(name='blocksPerFile', value=2000)
184 '''
184 '''
185
185
186 one = {'gdlatr': 'lat', 'gdlonr': 'lon', 'inttms': 'paramInterval'} #reader gdlatr-->lat only 1D
186 one = {'gdlatr': 'lat', 'gdlonr': 'lon', 'inttms': 'paramInterval'} #reader gdlatr-->lat only 1D
187
187
188 two = {
188 two = {
189 'snl': 'snl', #DeberΓ­a salir como el original pero mΓ‘s limpio
189 'snl': 'snl', #DeberΓ­a salir como el original pero mΓ‘s limpio
190 'RANGE': 'heightList', #<----- nmonics
190 'RANGE': 'heightList', #<----- nmonics
191 'DOPP_T1_EEJ': ('Dop_EEJ_T1', (0)),
191 'DOPP_T1_EEJ': ('Dop_EEJ_T1', (0)),
192 'DDOPP_T1_EEJ': ('Err_Dop_EEJ_T1', (0)),
192 'DDOPP_T1_EEJ': ('Err_Dop_EEJ_T1', (0)),
193 'SPEC_W_T1_EEJ': ('Spec_W_T1', (0)),
193 'SPEC_W_T1_EEJ': ('Spec_W_T1', (0)),
194 'DSPEC_W_T1_EEJ': ('Err_Spec_W_T1', (0)),
194 'DSPEC_W_T1_EEJ': ('Err_Spec_W_T1', (0)),
195 'DOPP_T2_EEJ': ('Dop_EEJ_T2', (0)),
195 'DOPP_T2_EEJ': ('Dop_EEJ_T2', (0)),
196 'DDOPP_T2_EEJ': ('Err_Dop_EEJ_T2', (0)),
196 'DDOPP_T2_EEJ': ('Err_Dop_EEJ_T2', (0)),
197 'SPEC_W_T2_EEJ': ('Spec_W_T2', (0)),
197 'SPEC_W_T2_EEJ': ('Spec_W_T2', (0)),
198 'DSPEC_W_T2_EEJ': ('Err_Spec_W_T2', (0)),
198 'DSPEC_W_T2_EEJ': ('Err_Spec_W_T2', (0)),
199 } #writer
199 } #writer
200
200
201
201
202 ind = ['range']
202 ind = ['range']
203
203
204 meta = {
204 meta = {
205 'kinst': 840, #instrumnet code, 840 for JULIA, 14 for JULIA MP CSR
205 'kinst': 840, #instrumnet code, 840 for JULIA, 14 for JULIA MP CSR
206 'kindat': 1962, #type of data #Este es el nuevo e igual para JULIA y JULIA CSR
206 'kindat': 1962, #type of data #Este es el nuevo e igual para JULIA y JULIA CSR
207 'catalog': {
207 'catalog': {
208 'principleInvestigator': 'Danny ScipiΓ³n',
208 'principleInvestigator': 'Danny ScipiΓ³n',
209 'expPurpose': 'Equatorial Electrojet Parameters',
209 'expPurpose': 'Equatorial Electrojet Parameters',
210 },
210 },
211 'header': {
211 'header': {
212 'analyst': 'D. Hysell'
212 'analyst': 'D. Hysell'
213 }
213 }
214 }
214 }
215
215
216
216
217 op_writer = procUnitConfObj1.addOperation(name='MADWriter', optype='external')
217 op_writer = procUnitConfObj1.addOperation(name='MADWriter', optype='external')
218 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ')
218 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ')
219 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ/Dop_Max_Val')
219 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ/Dop_Max_Val')
220 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ/'+Dop+'/'+dpath[-5:-1])
220 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ/'+Dop+'/'+dpath[-5:-1])
221 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ/CorrectFiles/no_snl_Test/01/'+Dop+'/'+dpath[-5:-1])
221 #op_writer.addParameter(name='path', value='/home/roberto/DATA/hdf5_outputs/Madrigal/EEJ/CorrectFiles/no_snl_Test/01/'+Dop+'/'+dpath[-5:-1])
222 op_writer.addParameter(name='path', value='/home/soporte/DATA/hdf5_outputs/Madrigal/EEJ/FinalFiles/'+Dop+'/'+dpath[-5:-1])
222 op_writer.addParameter(name='path', value='/home/soporte/DATA/hdf5_outputs/Madrigal/EEJ/FinalFiles/'+Dop+'/'+dpath[-5:-1])
223 op_writer.addParameter(name='format', value='hdf5', format='str')
223 op_writer.addParameter(name='format', value='hdf5', format='str')
224 op_writer.addParameter(name='oneDDict', value=json.dumps(one), format='str')
224 op_writer.addParameter(name='oneDDict', value=json.dumps(one), format='str')
225 op_writer.addParameter(name='twoDDict', value=json.dumps(two), format='str')
225 op_writer.addParameter(name='twoDDict', value=json.dumps(two), format='str')
226 op_writer.addParameter(name='ind2DList', value=json.dumps(ind), format='str')
226 op_writer.addParameter(name='ind2DList', value=json.dumps(ind), format='str')
227 op_writer.addParameter(name='metadata', value=json.dumps(meta), format='str')
227 op_writer.addParameter(name='metadata', value=json.dumps(meta), format='str')
228
228
229
229
230 if plot_params:
230 if plot_params:
231 '''
231 '''
232 opObj11 = procUnitConfObj1.addOperation(name='DopplerEEJPlot', optype='other')
232 opObj11 = procUnitConfObj1.addOperation(name='DopplerEEJPlot', optype='other')
233 opObj11.addParameter(name='id', value='10', format='int')
233 opObj11.addParameter(name='id', value='10', format='int')
234 opObj11.addParameter(name='wintitle', value='Doppler EEJ', format='str')
234 opObj11.addParameter(name='wintitle', value='Doppler EEJ', format='str')
235 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
235 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
236 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
236 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
237 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
237 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
238 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
238 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
239 #opObj11.addParameter(name='zmin', value=-250, format='int')
239 #opObj11.addParameter(name='zmin', value=-250, format='int')
240 #opObj11.addParameter(name='zmax', value=250, format='int')
240 #opObj11.addParameter(name='zmax', value=250, format='int')
241 opObj11.addParameter(name='zlimits', value='(-400,400),(-250,250)')
241 opObj11.addParameter(name='zlimits', value='(-400,400),(-250,250)')
242 #opObj11.addParameter(name='showprofile', value='1', format='int')
242 #opObj11.addParameter(name='showprofile', value='1', format='int')
243 opObj11.addParameter(name='save', value=figpath, format='str')
243 opObj11.addParameter(name='save', value=figpath, format='str')
244 #opObj11.addParameter(name='EEJtype', value=1, format='int')
244 #opObj11.addParameter(name='EEJtype', value=1, format='int')
245
245
246 opObj11 = procUnitConfObj1.addOperation(name='SpcWidthEEJPlot', optype='other')
246 opObj11 = procUnitConfObj1.addOperation(name='SpcWidthEEJPlot', optype='other')
247 opObj11.addParameter(name='id', value='10', format='int')
247 opObj11.addParameter(name='id', value='10', format='int')
248 opObj11.addParameter(name='wintitle', value='Spectral Width EEJ', format='str')
248 opObj11.addParameter(name='wintitle', value='Spectral Width EEJ', format='str')
249 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
249 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
250 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
250 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
251 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
251 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
252 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
252 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
253 #opObj11.addParameter(name='zmin', value=0., format='int')
253 #opObj11.addParameter(name='zmin', value=0., format='int')
254 #opObj11.addParameter(name='zmax', value=250, format='int')
254 #opObj11.addParameter(name='zmax', value=250, format='int')
255 opObj11.addParameter(name='zlimits', value='(0.1,100),(0.1,250)')
255 opObj11.addParameter(name='zlimits', value='(0.1,100),(0.1,250)')
256 #opObj11.addParameter(name='showprofile', value='1', format='int')
256 #opObj11.addParameter(name='showprofile', value='1', format='int')
257 opObj11.addParameter(name='save', value=figpath, format='str')
257 opObj11.addParameter(name='save', value=figpath, format='str')
258 #opObj11.addParameter(name='EEJtype', value=1, format='int')
258 #opObj11.addParameter(name='EEJtype', value=1, format='int')
259 '''
259 '''
260 opObj11 = procUnitConfObj1.addOperation(name='SpectraObliquePlot', optype='other')
260 opObj11 = procUnitConfObj1.addOperation(name='SpectraObliquePlot', optype='other')
261 opObj11.addParameter(name='id', value='1', format='int')
261 opObj11.addParameter(name='id', value='1', format='int')
262 opObj11.addParameter(name='wintitle', value='Oblique', format='str')
262 opObj11.addParameter(name='wintitle', value='Oblique', format='str')
263 opObj11.addParameter(name='zmin', value=db_range[0], format='int')
263 opObj11.addParameter(name='zmin', value=db_range[0], format='int')
264 opObj11.addParameter(name='zmax', value=db_range[1], format='int')
264 opObj11.addParameter(name='zmax', value=db_range[1], format='int')
265 opObj11.addParameter(name='xaxis', value='velocity', format='str')
265 opObj11.addParameter(name='xaxis', value='velocity', format='str')
266 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
266 opObj11.addParameter(name='ymin', value=altura1[0], format='int')
267 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
267 opObj11.addParameter(name='ymax', value=altura1[1], format='int')
268 # opObj11.addParameter(name='xmin', value=velocity[0], format='int')
268 # opObj11.addParameter(name='xmin', value=velocity[0], format='int')
269 # opObj11.addParameter(name='xmax', value=velocity[1], format='int')
269 # opObj11.addParameter(name='xmax', value=velocity[1], format='int')
270 opObj11.addParameter(name='showprofile', value='1', format='int')
270 opObj11.addParameter(name='showprofile', value='1', format='int')
271 opObj11.addParameter(name='save', value=figpath+'/400', format='str')
271 opObj11.addParameter(name='save', value=figpath+'/400', format='str')
272
272
273 '''
273 '''
274 opObj11 = procUnitConfObj1.addOperation(name='DopplerEEJPlot', optype='other')
274 opObj11 = procUnitConfObj1.addOperation(name='DopplerEEJPlot', optype='other')
275 opObj11.addParameter(name='id', value='10', format='int')
275 opObj11.addParameter(name='id', value='10', format='int')
276 opObj11.addParameter(name='wintitle', value='Doppler EEJ Type II', format='str')
276 opObj11.addParameter(name='wintitle', value='Doppler EEJ Type II', format='str')
277 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
277 opObj11.addParameter(name='xmin', value=tiempo[0], format='float')
278 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
278 opObj11.addParameter(name='xmax', value=tiempo[1], format='float')
279 # opObj11.addParameter(name='ymin', value=altura1[0], format='int')
279 # opObj11.addParameter(name='ymin', value=altura1[0], format='int')
280 # opObj11.addParameter(name='ymax', value=altura1[1], format='int')
280 # opObj11.addParameter(name='ymax', value=altura1[1], format='int')
281 opObj11.addParameter(name='zmin', value=-250, format='int')
281 opObj11.addParameter(name='zmin', value=-250, format='int')
282 opObj11.addParameter(name='zmax', value=250, format='int')
282 opObj11.addParameter(name='zmax', value=250, format='int')
283 #opObj11.addParameter(name='showprofile', value='1', format='int')
283 #opObj11.addParameter(name='showprofile', value='1', format='int')
284 opObj11.addParameter(name='save', value=figpath, format='str')
284 opObj11.addParameter(name='save', value=figpath, format='str')
285 opObj11.addParameter(name='EEJtype', value=2, format='int')
285 opObj11.addParameter(name='EEJtype', value=2, format='int')
286 '''
286 '''
287
287
288
288
289
289
290
290
291 controllerObj.start() No newline at end of file
291 controllerObj.start()
General Comments 0
You need to be logged in to leave comments. Login now