##// END OF EJS Templates
Now we can merge ProcUnits for Double Pulse Experiments
rflores -
r1452:d596eb625435
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,662 +1,665
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 """API to create signal chain projects
5 """API to create signal chain projects
6
6
7 The API is provide through class: Project
7 The API is provide through class: Project
8 """
8 """
9
9
10 import re
10 import re
11 import sys
11 import sys
12 import ast
12 import ast
13 import datetime
13 import datetime
14 import traceback
14 import traceback
15 import time
15 import time
16 import multiprocessing
16 import multiprocessing
17 from multiprocessing import Process, Queue
17 from multiprocessing import Process, Queue
18 from threading import Thread
18 from threading import Thread
19 from xml.etree.ElementTree import ElementTree, Element, SubElement
19 from xml.etree.ElementTree import ElementTree, Element, SubElement
20
20
21 from schainpy.admin import Alarm, SchainWarning
21 from schainpy.admin import Alarm, SchainWarning
22 from schainpy.model import *
22 from schainpy.model import *
23 from schainpy.utils import log
23 from schainpy.utils import log
24
24
25 if 'darwin' in sys.platform and sys.version_info[0] == 3 and sys.version_info[1] > 7:
25 if 'darwin' in sys.platform and sys.version_info[0] == 3 and sys.version_info[1] > 7:
26 multiprocessing.set_start_method('fork')
26 multiprocessing.set_start_method('fork')
27
27
28 class ConfBase():
28 class ConfBase():
29
29
30 def __init__(self):
30 def __init__(self):
31
31
32 self.id = '0'
32 self.id = '0'
33 self.name = None
33 self.name = None
34 self.priority = None
34 self.priority = None
35 self.parameters = {}
35 self.parameters = {}
36 self.object = None
36 self.object = None
37 self.operations = []
37 self.operations = []
38
38
39 def getId(self):
39 def getId(self):
40
40
41 return self.id
41 return self.id
42
42
43 def getNewId(self):
43 def getNewId(self):
44
44
45 return int(self.id) * 10 + len(self.operations) + 1
45 return int(self.id) * 10 + len(self.operations) + 1
46
46
47 def updateId(self, new_id):
47 def updateId(self, new_id):
48
48
49 self.id = str(new_id)
49 self.id = str(new_id)
50
50
51 n = 1
51 n = 1
52 for conf in self.operations:
52 for conf in self.operations:
53 conf_id = str(int(new_id) * 10 + n)
53 conf_id = str(int(new_id) * 10 + n)
54 conf.updateId(conf_id)
54 conf.updateId(conf_id)
55 n += 1
55 n += 1
56
56
57 def getKwargs(self):
57 def getKwargs(self):
58
58
59 params = {}
59 params = {}
60
60
61 for key, value in self.parameters.items():
61 for key, value in self.parameters.items():
62 if value not in (None, '', ' '):
62 if value not in (None, '', ' '):
63 params[key] = value
63 params[key] = value
64
64
65 return params
65 return params
66
66
67 def update(self, **kwargs):
67 def update(self, **kwargs):
68
68
69 if 'format' not in kwargs:
69 if 'format' not in kwargs:
70 kwargs['format'] = None
70 kwargs['format'] = None
71 for key, value, fmt in kwargs.items():
71 for key, value, fmt in kwargs.items():
72 self.addParameter(name=key, value=value, format=fmt)
72 self.addParameter(name=key, value=value, format=fmt)
73
73
74 def addParameter(self, name, value, format=None):
74 def addParameter(self, name, value, format=None):
75 '''
75 '''
76 '''
76 '''
77 if format is not None:
77 if format is not None:
78 self.parameters[name] = eval(format)(value)
78 self.parameters[name] = eval(format)(value)
79 elif isinstance(value, str) and re.search(r'(\d+/\d+/\d+)', value):
79 elif isinstance(value, str) and re.search(r'(\d+/\d+/\d+)', value):
80 self.parameters[name] = datetime.date(*[int(x) for x in value.split('/')])
80 self.parameters[name] = datetime.date(*[int(x) for x in value.split('/')])
81 elif isinstance(value, str) and re.search(r'(\d+:\d+:\d+)', value):
81 elif isinstance(value, str) and re.search(r'(\d+:\d+:\d+)', value):
82 self.parameters[name] = datetime.time(*[int(x) for x in value.split(':')])
82 self.parameters[name] = datetime.time(*[int(x) for x in value.split(':')])
83 else:
83 else:
84 try:
84 try:
85 self.parameters[name] = ast.literal_eval(value)
85 self.parameters[name] = ast.literal_eval(value)
86 except:
86 except:
87 if isinstance(value, str) and ',' in value:
87 if isinstance(value, str) and ',' in value:
88 self.parameters[name] = value.split(',')
88 self.parameters[name] = value.split(',')
89 else:
89 else:
90 self.parameters[name] = value
90 self.parameters[name] = value
91
91
92 def getParameters(self):
92 def getParameters(self):
93
93
94 params = {}
94 params = {}
95 for key, value in self.parameters.items():
95 for key, value in self.parameters.items():
96 s = type(value).__name__
96 s = type(value).__name__
97 if s == 'date':
97 if s == 'date':
98 params[key] = value.strftime('%Y/%m/%d')
98 params[key] = value.strftime('%Y/%m/%d')
99 elif s == 'time':
99 elif s == 'time':
100 params[key] = value.strftime('%H:%M:%S')
100 params[key] = value.strftime('%H:%M:%S')
101 else:
101 else:
102 params[key] = str(value)
102 params[key] = str(value)
103
103
104 return params
104 return params
105
105
106 def makeXml(self, element):
106 def makeXml(self, element):
107
107
108 xml = SubElement(element, self.ELEMENTNAME)
108 xml = SubElement(element, self.ELEMENTNAME)
109 for label in self.xml_labels:
109 for label in self.xml_labels:
110 xml.set(label, str(getattr(self, label)))
110 xml.set(label, str(getattr(self, label)))
111
111
112 for key, value in self.getParameters().items():
112 for key, value in self.getParameters().items():
113 xml_param = SubElement(xml, 'Parameter')
113 xml_param = SubElement(xml, 'Parameter')
114 xml_param.set('name', key)
114 xml_param.set('name', key)
115 xml_param.set('value', value)
115 xml_param.set('value', value)
116
116
117 for conf in self.operations:
117 for conf in self.operations:
118 conf.makeXml(xml)
118 conf.makeXml(xml)
119
119
120 def __str__(self):
120 def __str__(self):
121
121
122 if self.ELEMENTNAME == 'Operation':
122 if self.ELEMENTNAME == 'Operation':
123 s = ' {}[id={}]\n'.format(self.name, self.id)
123 s = ' {}[id={}]\n'.format(self.name, self.id)
124 else:
124 else:
125 s = '{}[id={}, inputId={}]\n'.format(self.name, self.id, self.inputId)
125 s = '{}[id={}, inputId={}]\n'.format(self.name, self.id, self.inputId)
126
126
127 for key, value in self.parameters.items():
127 for key, value in self.parameters.items():
128 if self.ELEMENTNAME == 'Operation':
128 if self.ELEMENTNAME == 'Operation':
129 s += ' {}: {}\n'.format(key, value)
129 s += ' {}: {}\n'.format(key, value)
130 else:
130 else:
131 s += ' {}: {}\n'.format(key, value)
131 s += ' {}: {}\n'.format(key, value)
132
132
133 for conf in self.operations:
133 for conf in self.operations:
134 s += str(conf)
134 s += str(conf)
135
135
136 return s
136 return s
137
137
138 class OperationConf(ConfBase):
138 class OperationConf(ConfBase):
139
139
140 ELEMENTNAME = 'Operation'
140 ELEMENTNAME = 'Operation'
141 xml_labels = ['id', 'name']
141 xml_labels = ['id', 'name']
142
142
143 def setup(self, id, name, priority, project_id, err_queue):
143 def setup(self, id, name, priority, project_id, err_queue):
144
144
145 self.id = str(id)
145 self.id = str(id)
146 self.project_id = project_id
146 self.project_id = project_id
147 self.name = name
147 self.name = name
148 self.type = 'other'
148 self.type = 'other'
149 self.err_queue = err_queue
149 self.err_queue = err_queue
150
150
151 def readXml(self, element, project_id, err_queue):
151 def readXml(self, element, project_id, err_queue):
152
152
153 self.id = element.get('id')
153 self.id = element.get('id')
154 self.name = element.get('name')
154 self.name = element.get('name')
155 self.type = 'other'
155 self.type = 'other'
156 self.project_id = str(project_id)
156 self.project_id = str(project_id)
157 self.err_queue = err_queue
157 self.err_queue = err_queue
158
158
159 for elm in element.iter('Parameter'):
159 for elm in element.iter('Parameter'):
160 self.addParameter(elm.get('name'), elm.get('value'))
160 self.addParameter(elm.get('name'), elm.get('value'))
161
161
162 def createObject(self):
162 def createObject(self):
163
163
164 className = eval(self.name)
164 className = eval(self.name)
165
165
166 if 'Plot' in self.name or 'Writer' in self.name or 'Send' in self.name or 'print' in self.name:
166 if 'Plot' in self.name or 'Writer' in self.name or 'Send' in self.name or 'print' in self.name:
167 kwargs = self.getKwargs()
167 kwargs = self.getKwargs()
168 opObj = className(self.id, self.id, self.project_id, self.err_queue, **kwargs)
168 opObj = className(self.id, self.id, self.project_id, self.err_queue, **kwargs)
169 opObj.start()
169 opObj.start()
170 self.type = 'external'
170 self.type = 'external'
171 else:
171 else:
172 opObj = className()
172 opObj = className()
173
173
174 self.object = opObj
174 self.object = opObj
175 return opObj
175 return opObj
176
176
177 class ProcUnitConf(ConfBase):
177 class ProcUnitConf(ConfBase):
178
178
179 ELEMENTNAME = 'ProcUnit'
179 ELEMENTNAME = 'ProcUnit'
180 xml_labels = ['id', 'inputId', 'name']
180 xml_labels = ['id', 'inputId', 'name']
181
181
182 def setup(self, project_id, id, name, datatype, inputId, err_queue):
182 def setup(self, project_id, id, name, datatype, inputId, err_queue):
183 '''
183 '''
184 '''
184 '''
185
185
186 if datatype == None and name == None:
186 if datatype == None and name == None:
187 raise ValueError('datatype or name should be defined')
187 raise ValueError('datatype or name should be defined')
188
188
189 if name == None:
189 if name == None:
190 if 'Proc' in datatype:
190 if 'Proc' in datatype:
191 name = datatype
191 name = datatype
192 else:
192 else:
193 name = '%sProc' % (datatype)
193 name = '%sProc' % (datatype)
194
194
195 if datatype == None:
195 if datatype == None:
196 datatype = name.replace('Proc', '')
196 datatype = name.replace('Proc', '')
197
197
198 self.id = str(id)
198 self.id = str(id)
199 self.project_id = project_id
199 self.project_id = project_id
200 self.name = name
200 self.name = name
201 self.datatype = datatype
201 self.datatype = datatype
202 self.inputId = inputId
202 self.inputId = inputId
203 self.err_queue = err_queue
203 self.err_queue = err_queue
204 self.operations = []
204 self.operations = []
205 self.parameters = {}
205 self.parameters = {}
206
206
207 def removeOperation(self, id):
207 def removeOperation(self, id):
208
208
209 i = [1 if x.id==id else 0 for x in self.operations]
209 i = [1 if x.id==id else 0 for x in self.operations]
210 self.operations.pop(i.index(1))
210 self.operations.pop(i.index(1))
211
211
212 def getOperation(self, id):
212 def getOperation(self, id):
213
213
214 for conf in self.operations:
214 for conf in self.operations:
215 if conf.id == id:
215 if conf.id == id:
216 return conf
216 return conf
217
217
218 def addOperation(self, name, optype='self'):
218 def addOperation(self, name, optype='self'):
219 '''
219 '''
220 '''
220 '''
221
221
222 id = self.getNewId()
222 id = self.getNewId()
223 conf = OperationConf()
223 conf = OperationConf()
224 conf.setup(id, name=name, priority='0', project_id=self.project_id, err_queue=self.err_queue)
224 conf.setup(id, name=name, priority='0', project_id=self.project_id, err_queue=self.err_queue)
225 self.operations.append(conf)
225 self.operations.append(conf)
226
226
227 return conf
227 return conf
228
228
229 def readXml(self, element, project_id, err_queue):
229 def readXml(self, element, project_id, err_queue):
230
230
231 self.id = element.get('id')
231 self.id = element.get('id')
232 self.name = element.get('name')
232 self.name = element.get('name')
233 self.inputId = None if element.get('inputId') == 'None' else element.get('inputId')
233 self.inputId = None if element.get('inputId') == 'None' else element.get('inputId')
234 self.datatype = element.get('datatype', self.name.replace(self.ELEMENTNAME.replace('Unit', ''), ''))
234 self.datatype = element.get('datatype', self.name.replace(self.ELEMENTNAME.replace('Unit', ''), ''))
235 self.project_id = str(project_id)
235 self.project_id = str(project_id)
236 self.err_queue = err_queue
236 self.err_queue = err_queue
237 self.operations = []
237 self.operations = []
238 self.parameters = {}
238 self.parameters = {}
239
239
240 for elm in element:
240 for elm in element:
241 if elm.tag == 'Parameter':
241 if elm.tag == 'Parameter':
242 self.addParameter(elm.get('name'), elm.get('value'))
242 self.addParameter(elm.get('name'), elm.get('value'))
243 elif elm.tag == 'Operation':
243 elif elm.tag == 'Operation':
244 conf = OperationConf()
244 conf = OperationConf()
245 conf.readXml(elm, project_id, err_queue)
245 conf.readXml(elm, project_id, err_queue)
246 self.operations.append(conf)
246 self.operations.append(conf)
247
247
248 def createObjects(self):
248 def createObjects(self):
249 '''
249 '''
250 Instancia de unidades de procesamiento.
250 Instancia de unidades de procesamiento.
251 '''
251 '''
252
252
253 className = eval(self.name)
253 className = eval(self.name)
254 kwargs = self.getKwargs()
254 kwargs = self.getKwargs()
255 procUnitObj = className()
255 procUnitObj = className()
256 procUnitObj.name = self.name
256 procUnitObj.name = self.name
257 log.success('creating process...', self.name)
257 log.success('creating process...', self.name)
258
258
259 for conf in self.operations:
259 for conf in self.operations:
260
260
261 opObj = conf.createObject()
261 opObj = conf.createObject()
262
262
263 log.success('adding operation: {}, type:{}'.format(
263 log.success('adding operation: {}, type:{}'.format(
264 conf.name,
264 conf.name,
265 conf.type), self.name)
265 conf.type), self.name)
266
266
267 procUnitObj.addOperation(conf, opObj)
267 procUnitObj.addOperation(conf, opObj)
268
268
269 self.object = procUnitObj
269 self.object = procUnitObj
270
270
271 def run(self):
271 def run(self):
272 '''
272 '''
273 '''
273 '''
274
274
275 return self.object.call(**self.getKwargs())
275 return self.object.call(**self.getKwargs())
276
276
277
277
278 class ReadUnitConf(ProcUnitConf):
278 class ReadUnitConf(ProcUnitConf):
279
279
280 ELEMENTNAME = 'ReadUnit'
280 ELEMENTNAME = 'ReadUnit'
281
281
282 def __init__(self):
282 def __init__(self):
283
283
284 self.id = None
284 self.id = None
285 self.datatype = None
285 self.datatype = None
286 self.name = None
286 self.name = None
287 self.inputId = None
287 self.inputId = None
288 self.operations = []
288 self.operations = []
289 self.parameters = {}
289 self.parameters = {}
290
290
291 def setup(self, project_id, id, name, datatype, err_queue, path='', startDate='', endDate='',
291 def setup(self, project_id, id, name, datatype, err_queue, path='', startDate='', endDate='',
292 startTime='', endTime='', server=None, **kwargs):
292 startTime='', endTime='', server=None, **kwargs):
293
293
294 if datatype == None and name == None:
294 if datatype == None and name == None:
295 raise ValueError('datatype or name should be defined')
295 raise ValueError('datatype or name should be defined')
296 if name == None:
296 if name == None:
297 if 'Reader' in datatype:
297 if 'Reader' in datatype:
298 name = datatype
298 name = datatype
299 datatype = name.replace('Reader','')
299 datatype = name.replace('Reader','')
300 else:
300 else:
301 name = '{}Reader'.format(datatype)
301 name = '{}Reader'.format(datatype)
302 if datatype == None:
302 if datatype == None:
303 if 'Reader' in name:
303 if 'Reader' in name:
304 datatype = name.replace('Reader','')
304 datatype = name.replace('Reader','')
305 else:
305 else:
306 datatype = name
306 datatype = name
307 name = '{}Reader'.format(name)
307 name = '{}Reader'.format(name)
308
308
309 self.id = id
309 self.id = id
310 self.project_id = project_id
310 self.project_id = project_id
311 self.name = name
311 self.name = name
312 self.datatype = datatype
312 self.datatype = datatype
313 self.err_queue = err_queue
313 self.err_queue = err_queue
314
314
315 self.addParameter(name='path', value=path, format='str')
315 self.addParameter(name='path', value=path, format='str')
316 self.addParameter(name='startDate', value=startDate)
316 self.addParameter(name='startDate', value=startDate)
317 self.addParameter(name='endDate', value=endDate)
317 self.addParameter(name='endDate', value=endDate)
318 self.addParameter(name='startTime', value=startTime)
318 self.addParameter(name='startTime', value=startTime)
319 self.addParameter(name='endTime', value=endTime)
319 self.addParameter(name='endTime', value=endTime)
320
320
321 for key, value in kwargs.items():
321 for key, value in kwargs.items():
322 self.addParameter(name=key, value=value)
322 self.addParameter(name=key, value=value)
323
323
324
324
325 class Project(Process):
325 class Project(Process):
326 """API to create signal chain projects"""
326 """API to create signal chain projects"""
327
327
328 ELEMENTNAME = 'Project'
328 ELEMENTNAME = 'Project'
329
329
330 def __init__(self, name=''):
330 def __init__(self, name=''):
331
331
332 Process.__init__(self)
332 Process.__init__(self)
333 self.id = '1'
333 self.id = '1'
334 if name:
334 if name:
335 self.name = '{} ({})'.format(Process.__name__, name)
335 self.name = '{} ({})'.format(Process.__name__, name)
336 self.filename = None
336 self.filename = None
337 self.description = None
337 self.description = None
338 self.email = None
338 self.email = None
339 self.alarm = []
339 self.alarm = []
340 self.configurations = {}
340 self.configurations = {}
341 # self.err_queue = Queue()
341 # self.err_queue = Queue()
342 self.err_queue = None
342 self.err_queue = None
343 self.started = False
343 self.started = False
344
344
345 def getNewId(self):
345 def getNewId(self):
346
346
347 idList = list(self.configurations.keys())
347 idList = list(self.configurations.keys())
348 id = int(self.id) * 10
348 id = int(self.id) * 10
349
349
350 while True:
350 while True:
351 id += 1
351 id += 1
352
352
353 if str(id) in idList:
353 if str(id) in idList:
354 continue
354 continue
355
355
356 break
356 break
357
357
358 return str(id)
358 return str(id)
359
359
360 def updateId(self, new_id):
360 def updateId(self, new_id):
361
361
362 self.id = str(new_id)
362 self.id = str(new_id)
363
363
364 keyList = list(self.configurations.keys())
364 keyList = list(self.configurations.keys())
365 keyList.sort()
365 keyList.sort()
366
366
367 n = 1
367 n = 1
368 new_confs = {}
368 new_confs = {}
369
369
370 for procKey in keyList:
370 for procKey in keyList:
371
371
372 conf = self.configurations[procKey]
372 conf = self.configurations[procKey]
373 idProcUnit = str(int(self.id) * 10 + n)
373 idProcUnit = str(int(self.id) * 10 + n)
374 conf.updateId(idProcUnit)
374 conf.updateId(idProcUnit)
375 new_confs[idProcUnit] = conf
375 new_confs[idProcUnit] = conf
376 n += 1
376 n += 1
377
377
378 self.configurations = new_confs
378 self.configurations = new_confs
379
379
380 def setup(self, id=1, name='', description='', email=None, alarm=[]):
380 def setup(self, id=1, name='', description='', email=None, alarm=[]):
381
381
382 self.id = str(id)
382 self.id = str(id)
383 self.description = description
383 self.description = description
384 self.email = email
384 self.email = email
385 self.alarm = alarm
385 self.alarm = alarm
386 if name:
386 if name:
387 self.name = '{} ({})'.format(Process.__name__, name)
387 self.name = '{} ({})'.format(Process.__name__, name)
388
388
389 def update(self, **kwargs):
389 def update(self, **kwargs):
390
390
391 for key, value in kwargs.items():
391 for key, value in kwargs.items():
392 setattr(self, key, value)
392 setattr(self, key, value)
393
393
394 def clone(self):
394 def clone(self):
395
395
396 p = Project()
396 p = Project()
397 p.id = self.id
397 p.id = self.id
398 p.name = self.name
398 p.name = self.name
399 p.description = self.description
399 p.description = self.description
400 p.configurations = self.configurations.copy()
400 p.configurations = self.configurations.copy()
401
401
402 return p
402 return p
403
403
404 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
404 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
405
405
406 '''
406 '''
407 '''
407 '''
408
408
409 if id is None:
409 if id is None:
410 idReadUnit = self.getNewId()
410 idReadUnit = self.getNewId()
411 else:
411 else:
412 idReadUnit = str(id)
412 idReadUnit = str(id)
413
413
414 conf = ReadUnitConf()
414 conf = ReadUnitConf()
415 conf.setup(self.id, idReadUnit, name, datatype, self.err_queue, **kwargs)
415 conf.setup(self.id, idReadUnit, name, datatype, self.err_queue, **kwargs)
416 self.configurations[conf.id] = conf
416 self.configurations[conf.id] = conf
417
417
418 return conf
418 return conf
419
419
420 def addProcUnit(self, id=None, inputId='0', datatype=None, name=None):
420 def addProcUnit(self, id=None, inputId='0', datatype=None, name=None):
421
421
422 '''
422 '''
423 '''
423 '''
424
424
425 if id is None:
425 if id is None:
426 idProcUnit = self.getNewId()
426 idProcUnit = self.getNewId()
427 else:
427 else:
428 idProcUnit = id
428 idProcUnit = id
429
429
430 conf = ProcUnitConf()
430 conf = ProcUnitConf()
431 conf.setup(self.id, idProcUnit, name, datatype, inputId, self.err_queue)
431 conf.setup(self.id, idProcUnit, name, datatype, inputId, self.err_queue)
432 self.configurations[conf.id] = conf
432 self.configurations[conf.id] = conf
433
433
434 return conf
434 return conf
435
435
436 def removeProcUnit(self, id):
436 def removeProcUnit(self, id):
437
437
438 if id in self.configurations:
438 if id in self.configurations:
439 self.configurations.pop(id)
439 self.configurations.pop(id)
440
440
441 def getReadUnit(self):
441 def getReadUnit(self):
442
442
443 for obj in list(self.configurations.values()):
443 for obj in list(self.configurations.values()):
444 if obj.ELEMENTNAME == 'ReadUnit':
444 if obj.ELEMENTNAME == 'ReadUnit':
445 return obj
445 return obj
446
446
447 return None
447 return None
448
448
449 def getProcUnit(self, id):
449 def getProcUnit(self, id):
450
450
451 return self.configurations[id]
451 return self.configurations[id]
452
452
453 def getUnits(self):
453 def getUnits(self):
454
454
455 keys = list(self.configurations)
455 keys = list(self.configurations)
456 keys.sort()
456 keys.sort()
457
457
458 for key in keys:
458 for key in keys:
459 yield self.configurations[key]
459 yield self.configurations[key]
460
460
461 def updateUnit(self, id, **kwargs):
461 def updateUnit(self, id, **kwargs):
462
462
463 conf = self.configurations[id].update(**kwargs)
463 conf = self.configurations[id].update(**kwargs)
464
464
465 def makeXml(self):
465 def makeXml(self):
466
466
467 xml = Element('Project')
467 xml = Element('Project')
468 xml.set('id', str(self.id))
468 xml.set('id', str(self.id))
469 xml.set('name', self.name)
469 xml.set('name', self.name)
470 xml.set('description', self.description)
470 xml.set('description', self.description)
471
471
472 for conf in self.configurations.values():
472 for conf in self.configurations.values():
473 conf.makeXml(xml)
473 conf.makeXml(xml)
474
474
475 self.xml = xml
475 self.xml = xml
476
476
477 def writeXml(self, filename=None):
477 def writeXml(self, filename=None):
478
478
479 if filename == None:
479 if filename == None:
480 if self.filename:
480 if self.filename:
481 filename = self.filename
481 filename = self.filename
482 else:
482 else:
483 filename = 'schain.xml'
483 filename = 'schain.xml'
484
484
485 if not filename:
485 if not filename:
486 print('filename has not been defined. Use setFilename(filename) for do it.')
486 print('filename has not been defined. Use setFilename(filename) for do it.')
487 return 0
487 return 0
488
488
489 abs_file = os.path.abspath(filename)
489 abs_file = os.path.abspath(filename)
490
490
491 if not os.access(os.path.dirname(abs_file), os.W_OK):
491 if not os.access(os.path.dirname(abs_file), os.W_OK):
492 print('No write permission on %s' % os.path.dirname(abs_file))
492 print('No write permission on %s' % os.path.dirname(abs_file))
493 return 0
493 return 0
494
494
495 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
495 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
496 print('File %s already exists and it could not be overwriten' % abs_file)
496 print('File %s already exists and it could not be overwriten' % abs_file)
497 return 0
497 return 0
498
498
499 self.makeXml()
499 self.makeXml()
500
500
501 ElementTree(self.xml).write(abs_file, method='xml')
501 ElementTree(self.xml).write(abs_file, method='xml')
502
502
503 self.filename = abs_file
503 self.filename = abs_file
504
504
505 return 1
505 return 1
506
506
507 def readXml(self, filename):
507 def readXml(self, filename):
508
508
509 abs_file = os.path.abspath(filename)
509 abs_file = os.path.abspath(filename)
510
510
511 self.configurations = {}
511 self.configurations = {}
512
512
513 try:
513 try:
514 self.xml = ElementTree().parse(abs_file)
514 self.xml = ElementTree().parse(abs_file)
515 except:
515 except:
516 log.error('Error reading %s, verify file format' % filename)
516 log.error('Error reading %s, verify file format' % filename)
517 return 0
517 return 0
518
518
519 self.id = self.xml.get('id')
519 self.id = self.xml.get('id')
520 self.name = self.xml.get('name')
520 self.name = self.xml.get('name')
521 self.description = self.xml.get('description')
521 self.description = self.xml.get('description')
522
522
523 for element in self.xml:
523 for element in self.xml:
524 if element.tag == 'ReadUnit':
524 if element.tag == 'ReadUnit':
525 conf = ReadUnitConf()
525 conf = ReadUnitConf()
526 conf.readXml(element, self.id, self.err_queue)
526 conf.readXml(element, self.id, self.err_queue)
527 self.configurations[conf.id] = conf
527 self.configurations[conf.id] = conf
528 elif element.tag == 'ProcUnit':
528 elif element.tag == 'ProcUnit':
529 conf = ProcUnitConf()
529 conf = ProcUnitConf()
530 input_proc = self.configurations[element.get('inputId')]
530 input_proc = self.configurations[element.get('inputId')]
531 conf.readXml(element, self.id, self.err_queue)
531 conf.readXml(element, self.id, self.err_queue)
532 self.configurations[conf.id] = conf
532 self.configurations[conf.id] = conf
533
533
534 self.filename = abs_file
534 self.filename = abs_file
535
535
536 return 1
536 return 1
537
537
538 def __str__(self):
538 def __str__(self):
539
539
540 text = '\nProject[id=%s, name=%s, description=%s]\n\n' % (
540 text = '\nProject[id=%s, name=%s, description=%s]\n\n' % (
541 self.id,
541 self.id,
542 self.name,
542 self.name,
543 self.description,
543 self.description,
544 )
544 )
545
545
546 for conf in self.configurations.values():
546 for conf in self.configurations.values():
547 text += '{}'.format(conf)
547 text += '{}'.format(conf)
548
548
549 return text
549 return text
550
550
551 def createObjects(self):
551 def createObjects(self):
552
552
553 keys = list(self.configurations.keys())
553 keys = list(self.configurations.keys())
554 keys.sort()
554 keys.sort()
555 for key in keys:
555 for key in keys:
556 conf = self.configurations[key]
556 conf = self.configurations[key]
557 conf.createObjects()
557 conf.createObjects()
558 if conf.inputId is not None:
558 if conf.inputId is not None:
559 conf.object.setInput(self.configurations[conf.inputId].object)
559 if isinstance(conf.inputId, list):
560 conf.object.setInput([self.configurations[x].object for x in conf.inputId])
561 else:
562 conf.object.setInput([self.configurations[conf.inputId].object])
560
563
561 def monitor(self):
564 def monitor(self):
562
565
563 t = Thread(target=self._monitor, args=(self.err_queue, self.ctx))
566 t = Thread(target=self._monitor, args=(self.err_queue, self.ctx))
564 t.start()
567 t.start()
565
568
566 def _monitor(self, queue, ctx):
569 def _monitor(self, queue, ctx):
567
570
568 import socket
571 import socket
569
572
570 procs = 0
573 procs = 0
571 err_msg = ''
574 err_msg = ''
572
575
573 while True:
576 while True:
574 msg = queue.get()
577 msg = queue.get()
575 if '#_start_#' in msg:
578 if '#_start_#' in msg:
576 procs += 1
579 procs += 1
577 elif '#_end_#' in msg:
580 elif '#_end_#' in msg:
578 procs -=1
581 procs -=1
579 else:
582 else:
580 err_msg = msg
583 err_msg = msg
581
584
582 if procs == 0 or 'Traceback' in err_msg:
585 if procs == 0 or 'Traceback' in err_msg:
583 break
586 break
584 time.sleep(0.1)
587 time.sleep(0.1)
585
588
586 if '|' in err_msg:
589 if '|' in err_msg:
587 name, err = err_msg.split('|')
590 name, err = err_msg.split('|')
588 if 'SchainWarning' in err:
591 if 'SchainWarning' in err:
589 log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), name)
592 log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), name)
590 elif 'SchainError' in err:
593 elif 'SchainError' in err:
591 log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), name)
594 log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), name)
592 else:
595 else:
593 log.error(err, name)
596 log.error(err, name)
594 else:
597 else:
595 name, err = self.name, err_msg
598 name, err = self.name, err_msg
596
599
597 time.sleep(1)
600 time.sleep(1)
598
601
599 ctx.term()
602 ctx.term()
600
603
601 message = ''.join(err)
604 message = ''.join(err)
602
605
603 if err_msg:
606 if err_msg:
604 subject = 'SChain v%s: Error running %s\n' % (
607 subject = 'SChain v%s: Error running %s\n' % (
605 schainpy.__version__, self.name)
608 schainpy.__version__, self.name)
606
609
607 subtitle = 'Hostname: %s\n' % socket.gethostbyname(
610 subtitle = 'Hostname: %s\n' % socket.gethostbyname(
608 socket.gethostname())
611 socket.gethostname())
609 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
612 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
610 subtitle += 'Configuration file: %s\n' % self.filename
613 subtitle += 'Configuration file: %s\n' % self.filename
611 subtitle += 'Time: %s\n' % str(datetime.datetime.now())
614 subtitle += 'Time: %s\n' % str(datetime.datetime.now())
612
615
613 readUnitConfObj = self.getReadUnit()
616 readUnitConfObj = self.getReadUnit()
614 if readUnitConfObj:
617 if readUnitConfObj:
615 subtitle += '\nInput parameters:\n'
618 subtitle += '\nInput parameters:\n'
616 subtitle += '[Data path = %s]\n' % readUnitConfObj.parameters['path']
619 subtitle += '[Data path = %s]\n' % readUnitConfObj.parameters['path']
617 subtitle += '[Start date = %s]\n' % readUnitConfObj.parameters['startDate']
620 subtitle += '[Start date = %s]\n' % readUnitConfObj.parameters['startDate']
618 subtitle += '[End date = %s]\n' % readUnitConfObj.parameters['endDate']
621 subtitle += '[End date = %s]\n' % readUnitConfObj.parameters['endDate']
619 subtitle += '[Start time = %s]\n' % readUnitConfObj.parameters['startTime']
622 subtitle += '[Start time = %s]\n' % readUnitConfObj.parameters['startTime']
620 subtitle += '[End time = %s]\n' % readUnitConfObj.parameters['endTime']
623 subtitle += '[End time = %s]\n' % readUnitConfObj.parameters['endTime']
621
624
622 a = Alarm(
625 a = Alarm(
623 modes=self.alarm,
626 modes=self.alarm,
624 email=self.email,
627 email=self.email,
625 message=message,
628 message=message,
626 subject=subject,
629 subject=subject,
627 subtitle=subtitle,
630 subtitle=subtitle,
628 filename=self.filename
631 filename=self.filename
629 )
632 )
630
633
631 a.start()
634 a.start()
632
635
633 def setFilename(self, filename):
636 def setFilename(self, filename):
634
637
635 self.filename = filename
638 self.filename = filename
636
639
637 def runProcs(self):
640 def runProcs(self):
638
641
639 err = False
642 err = False
640 n = len(self.configurations)
643 n = len(self.configurations)
641
644
642 while not err:
645 while not err:
643 for conf in self.getUnits():
646 for conf in self.getUnits():
644 ok = conf.run()
647 ok = conf.run()
645 if ok == 'Error':
648 if ok == 'Error':
646 n -= 1
649 n -= 1
647 continue
650 continue
648 elif not ok:
651 elif not ok:
649 break
652 break
650 if n == 0:
653 if n == 0:
651 err = True
654 err = True
652
655
653 def run(self):
656 def run(self):
654
657
655 log.success('\nStarting Project {} [id={}]'.format(self.name, self.id), tag='')
658 log.success('\nStarting Project {} [id={}]'.format(self.name, self.id), tag='')
656 self.started = True
659 self.started = True
657 self.start_time = time.time()
660 self.start_time = time.time()
658 self.createObjects()
661 self.createObjects()
659 self.runProcs()
662 self.runProcs()
660 log.success('{} Done (Time: {:4.2f}s)'.format(
663 log.success('{} Done (Time: {:4.2f}s)'.format(
661 self.name,
664 self.name,
662 time.time()-self.start_time), '')
665 time.time()-self.start_time), '')
@@ -1,1788 +1,1788
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
4 from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
5
5
6 from schainpy.model.graphics.jroplot_base import Plot, plt
6 from schainpy.model.graphics.jroplot_base import Plot, plt
7 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
7 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
8 from schainpy.utils import log
8 from schainpy.utils import log
9 # libreria wradlib
9 # libreria wradlib
10 import wradlib as wrl
10 import wradlib as wrl
11
11
12 EARTH_RADIUS = 6.3710e3
12 EARTH_RADIUS = 6.3710e3
13
13
14
14
15 def ll2xy(lat1, lon1, lat2, lon2):
15 def ll2xy(lat1, lon1, lat2, lon2):
16
16
17 p = 0.017453292519943295
17 p = 0.017453292519943295
18 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
18 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
19 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
19 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
20 r = 12742 * numpy.arcsin(numpy.sqrt(a))
20 r = 12742 * numpy.arcsin(numpy.sqrt(a))
21 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
21 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
22 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
22 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
23 theta = -theta + numpy.pi/2
23 theta = -theta + numpy.pi/2
24 return r*numpy.cos(theta), r*numpy.sin(theta)
24 return r*numpy.cos(theta), r*numpy.sin(theta)
25
25
26
26
27 def km2deg(km):
27 def km2deg(km):
28 '''
28 '''
29 Convert distance in km to degrees
29 Convert distance in km to degrees
30 '''
30 '''
31
31
32 return numpy.rad2deg(km/EARTH_RADIUS)
32 return numpy.rad2deg(km/EARTH_RADIUS)
33
33
34
34
35
35
36 class SpectralMomentsPlot(SpectraPlot):
36 class SpectralMomentsPlot(SpectraPlot):
37 '''
37 '''
38 Plot for Spectral Moments
38 Plot for Spectral Moments
39 '''
39 '''
40 CODE = 'spc_moments'
40 CODE = 'spc_moments'
41 # colormap = 'jet'
41 # colormap = 'jet'
42 # plot_type = 'pcolor'
42 # plot_type = 'pcolor'
43
43
44 class DobleGaussianPlot(SpectraPlot):
44 class DobleGaussianPlot(SpectraPlot):
45 '''
45 '''
46 Plot for Double Gaussian Plot
46 Plot for Double Gaussian Plot
47 '''
47 '''
48 CODE = 'gaussian_fit'
48 CODE = 'gaussian_fit'
49 # colormap = 'jet'
49 # colormap = 'jet'
50 # plot_type = 'pcolor'
50 # plot_type = 'pcolor'
51
51
52 class DoubleGaussianSpectraCutPlot(SpectraCutPlot):
52 class DoubleGaussianSpectraCutPlot(SpectraCutPlot):
53 '''
53 '''
54 Plot SpectraCut with Double Gaussian Fit
54 Plot SpectraCut with Double Gaussian Fit
55 '''
55 '''
56 CODE = 'cut_gaussian_fit'
56 CODE = 'cut_gaussian_fit'
57
57
58 class SnrPlot(RTIPlot):
58 class SnrPlot(RTIPlot):
59 '''
59 '''
60 Plot for SNR Data
60 Plot for SNR Data
61 '''
61 '''
62
62
63 CODE = 'snr'
63 CODE = 'snr'
64 colormap = 'jet'
64 colormap = 'jet'
65
65
66 def update(self, dataOut):
66 def update(self, dataOut):
67
67
68 data = {
68 data = {
69 'snr': 10*numpy.log10(dataOut.data_snr)
69 'snr': 10*numpy.log10(dataOut.data_snr)
70 }
70 }
71
71
72 return data, {}
72 return data, {}
73
73
74 class DopplerPlot(RTIPlot):
74 class DopplerPlot(RTIPlot):
75 '''
75 '''
76 Plot for DOPPLER Data (1st moment)
76 Plot for DOPPLER Data (1st moment)
77 '''
77 '''
78
78
79 CODE = 'dop'
79 CODE = 'dop'
80 colormap = 'jet'
80 colormap = 'jet'
81
81
82 def update(self, dataOut):
82 def update(self, dataOut):
83
83
84 data = {
84 data = {
85 'dop': 10*numpy.log10(dataOut.data_dop)
85 'dop': 10*numpy.log10(dataOut.data_dop)
86 }
86 }
87
87
88 return data, {}
88 return data, {}
89
89
90 class PowerPlot(RTIPlot):
90 class PowerPlot(RTIPlot):
91 '''
91 '''
92 Plot for Power Data (0 moment)
92 Plot for Power Data (0 moment)
93 '''
93 '''
94
94
95 CODE = 'pow'
95 CODE = 'pow'
96 colormap = 'jet'
96 colormap = 'jet'
97
97
98 def update(self, dataOut):
98 def update(self, dataOut):
99 data = {
99 data = {
100 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor)
100 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor)
101 }
101 }
102 return data, {}
102 return data, {}
103
103
104 class SpectralWidthPlot(RTIPlot):
104 class SpectralWidthPlot(RTIPlot):
105 '''
105 '''
106 Plot for Spectral Width Data (2nd moment)
106 Plot for Spectral Width Data (2nd moment)
107 '''
107 '''
108
108
109 CODE = 'width'
109 CODE = 'width'
110 colormap = 'jet'
110 colormap = 'jet'
111
111
112 def update(self, dataOut):
112 def update(self, dataOut):
113
113
114 data = {
114 data = {
115 'width': dataOut.data_width
115 'width': dataOut.data_width
116 }
116 }
117
117
118 return data, {}
118 return data, {}
119
119
120 class SkyMapPlot(Plot):
120 class SkyMapPlot(Plot):
121 '''
121 '''
122 Plot for meteors detection data
122 Plot for meteors detection data
123 '''
123 '''
124
124
125 CODE = 'param'
125 CODE = 'param'
126
126
127 def setup(self):
127 def setup(self):
128
128
129 self.ncols = 1
129 self.ncols = 1
130 self.nrows = 1
130 self.nrows = 1
131 self.width = 7.2
131 self.width = 7.2
132 self.height = 7.2
132 self.height = 7.2
133 self.nplots = 1
133 self.nplots = 1
134 self.xlabel = 'Zonal Zenith Angle (deg)'
134 self.xlabel = 'Zonal Zenith Angle (deg)'
135 self.ylabel = 'Meridional Zenith Angle (deg)'
135 self.ylabel = 'Meridional Zenith Angle (deg)'
136 self.polar = True
136 self.polar = True
137 self.ymin = -180
137 self.ymin = -180
138 self.ymax = 180
138 self.ymax = 180
139 self.colorbar = False
139 self.colorbar = False
140
140
141 def plot(self):
141 def plot(self):
142
142
143 arrayParameters = numpy.concatenate(self.data['param'])
143 arrayParameters = numpy.concatenate(self.data['param'])
144 error = arrayParameters[:, -1]
144 error = arrayParameters[:, -1]
145 indValid = numpy.where(error == 0)[0]
145 indValid = numpy.where(error == 0)[0]
146 finalMeteor = arrayParameters[indValid, :]
146 finalMeteor = arrayParameters[indValid, :]
147 finalAzimuth = finalMeteor[:, 3]
147 finalAzimuth = finalMeteor[:, 3]
148 finalZenith = finalMeteor[:, 4]
148 finalZenith = finalMeteor[:, 4]
149
149
150 x = finalAzimuth * numpy.pi / 180
150 x = finalAzimuth * numpy.pi / 180
151 y = finalZenith
151 y = finalZenith
152
152
153 ax = self.axes[0]
153 ax = self.axes[0]
154
154
155 if ax.firsttime:
155 if ax.firsttime:
156 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
156 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
157 else:
157 else:
158 ax.plot.set_data(x, y)
158 ax.plot.set_data(x, y)
159
159
160 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
160 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
161 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
161 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
162 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
162 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
163 dt2,
163 dt2,
164 len(x))
164 len(x))
165 self.titles[0] = title
165 self.titles[0] = title
166
166
167
167
168 class GenericRTIPlot(Plot):
168 class GenericRTIPlot(Plot):
169 '''
169 '''
170 Plot for data_xxxx object
170 Plot for data_xxxx object
171 '''
171 '''
172
172
173 CODE = 'param'
173 CODE = 'param'
174 colormap = 'viridis'
174 colormap = 'viridis'
175 plot_type = 'pcolorbuffer'
175 plot_type = 'pcolorbuffer'
176
176
177 def setup(self):
177 def setup(self):
178 self.xaxis = 'time'
178 self.xaxis = 'time'
179 self.ncols = 1
179 self.ncols = 1
180 self.nrows = self.data.shape('param')[0]
180 self.nrows = self.data.shape('param')[0]
181 self.nplots = self.nrows
181 self.nplots = self.nrows
182 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
182 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
183
183
184 if not self.xlabel:
184 if not self.xlabel:
185 self.xlabel = 'Time'
185 self.xlabel = 'Time'
186
186
187 self.ylabel = 'Range [km]'
187 self.ylabel = 'Range [km]'
188 if not self.titles:
188 if not self.titles:
189 self.titles = ['Param {}'.format(x) for x in range(self.nrows)]
189 self.titles = ['Param {}'.format(x) for x in range(self.nrows)]
190
190
191 def update(self, dataOut):
191 def update(self, dataOut):
192
192
193 data = {
193 data = {
194 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0)
194 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0)
195 }
195 }
196
196
197 meta = {}
197 meta = {}
198
198
199 return data, meta
199 return data, meta
200
200
201 def plot(self):
201 def plot(self):
202 # self.data.normalize_heights()
202 # self.data.normalize_heights()
203 self.x = self.data.times
203 self.x = self.data.times
204 self.y = self.data.yrange
204 self.y = self.data.yrange
205 self.z = self.data['param']
205 self.z = self.data['param']
206 self.z = 10*numpy.log10(self.z)
206 self.z = 10*numpy.log10(self.z)
207 self.z = numpy.ma.masked_invalid(self.z)
207 self.z = numpy.ma.masked_invalid(self.z)
208
208
209 if self.decimation is None:
209 if self.decimation is None:
210 x, y, z = self.fill_gaps(self.x, self.y, self.z)
210 x, y, z = self.fill_gaps(self.x, self.y, self.z)
211 else:
211 else:
212 x, y, z = self.fill_gaps(*self.decimate())
212 x, y, z = self.fill_gaps(*self.decimate())
213
213
214 for n, ax in enumerate(self.axes):
214 for n, ax in enumerate(self.axes):
215
215
216 self.zmax = self.zmax if self.zmax is not None else numpy.max(
216 self.zmax = self.zmax if self.zmax is not None else numpy.max(
217 self.z[n])
217 self.z[n])
218 self.zmin = self.zmin if self.zmin is not None else numpy.min(
218 self.zmin = self.zmin if self.zmin is not None else numpy.min(
219 self.z[n])
219 self.z[n])
220
220
221 if ax.firsttime:
221 if ax.firsttime:
222 if self.zlimits is not None:
222 if self.zlimits is not None:
223 self.zmin, self.zmax = self.zlimits[n]
223 self.zmin, self.zmax = self.zlimits[n]
224
224
225 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
225 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
226 vmin=self.zmin,
226 vmin=self.zmin,
227 vmax=self.zmax,
227 vmax=self.zmax,
228 cmap=self.cmaps[n]
228 cmap=self.cmaps[n]
229 )
229 )
230 else:
230 else:
231 if self.zlimits is not None:
231 if self.zlimits is not None:
232 self.zmin, self.zmax = self.zlimits[n]
232 self.zmin, self.zmax = self.zlimits[n]
233 ax.collections.remove(ax.collections[0])
233 ax.collections.remove(ax.collections[0])
234 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
234 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
235 vmin=self.zmin,
235 vmin=self.zmin,
236 vmax=self.zmax,
236 vmax=self.zmax,
237 cmap=self.cmaps[n]
237 cmap=self.cmaps[n]
238 )
238 )
239
239
240
240
241 class PolarMapPlot(Plot):
241 class PolarMapPlot(Plot):
242 '''
242 '''
243 Plot for weather radar
243 Plot for weather radar
244 '''
244 '''
245
245
246 CODE = 'param'
246 CODE = 'param'
247 colormap = 'seismic'
247 colormap = 'seismic'
248
248
249 def setup(self):
249 def setup(self):
250 self.ncols = 1
250 self.ncols = 1
251 self.nrows = 1
251 self.nrows = 1
252 self.width = 9
252 self.width = 9
253 self.height = 8
253 self.height = 8
254 self.mode = self.data.meta['mode']
254 self.mode = self.data.meta['mode']
255 if self.channels is not None:
255 if self.channels is not None:
256 self.nplots = len(self.channels)
256 self.nplots = len(self.channels)
257 self.nrows = len(self.channels)
257 self.nrows = len(self.channels)
258 else:
258 else:
259 self.nplots = self.data.shape(self.CODE)[0]
259 self.nplots = self.data.shape(self.CODE)[0]
260 self.nrows = self.nplots
260 self.nrows = self.nplots
261 self.channels = list(range(self.nplots))
261 self.channels = list(range(self.nplots))
262 if self.mode == 'E':
262 if self.mode == 'E':
263 self.xlabel = 'Longitude'
263 self.xlabel = 'Longitude'
264 self.ylabel = 'Latitude'
264 self.ylabel = 'Latitude'
265 else:
265 else:
266 self.xlabel = 'Range (km)'
266 self.xlabel = 'Range (km)'
267 self.ylabel = 'Height (km)'
267 self.ylabel = 'Height (km)'
268 self.bgcolor = 'white'
268 self.bgcolor = 'white'
269 self.cb_labels = self.data.meta['units']
269 self.cb_labels = self.data.meta['units']
270 self.lat = self.data.meta['latitude']
270 self.lat = self.data.meta['latitude']
271 self.lon = self.data.meta['longitude']
271 self.lon = self.data.meta['longitude']
272 self.xmin, self.xmax = float(
272 self.xmin, self.xmax = float(
273 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
273 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
274 self.ymin, self.ymax = float(
274 self.ymin, self.ymax = float(
275 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
275 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
276 # self.polar = True
276 # self.polar = True
277
277
278 def plot(self):
278 def plot(self):
279
279
280 for n, ax in enumerate(self.axes):
280 for n, ax in enumerate(self.axes):
281 data = self.data['param'][self.channels[n]]
281 data = self.data['param'][self.channels[n]]
282
282
283 zeniths = numpy.linspace(
283 zeniths = numpy.linspace(
284 0, self.data.meta['max_range'], data.shape[1])
284 0, self.data.meta['max_range'], data.shape[1])
285 if self.mode == 'E':
285 if self.mode == 'E':
286 azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2
286 azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2
287 r, theta = numpy.meshgrid(zeniths, azimuths)
287 r, theta = numpy.meshgrid(zeniths, azimuths)
288 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
288 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
289 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
289 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
290 x = km2deg(x) + self.lon
290 x = km2deg(x) + self.lon
291 y = km2deg(y) + self.lat
291 y = km2deg(y) + self.lat
292 else:
292 else:
293 azimuths = numpy.radians(self.data.yrange)
293 azimuths = numpy.radians(self.data.yrange)
294 r, theta = numpy.meshgrid(zeniths, azimuths)
294 r, theta = numpy.meshgrid(zeniths, azimuths)
295 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
295 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
296 self.y = zeniths
296 self.y = zeniths
297
297
298 if ax.firsttime:
298 if ax.firsttime:
299 if self.zlimits is not None:
299 if self.zlimits is not None:
300 self.zmin, self.zmax = self.zlimits[n]
300 self.zmin, self.zmax = self.zlimits[n]
301 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
301 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
302 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
302 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
303 vmin=self.zmin,
303 vmin=self.zmin,
304 vmax=self.zmax,
304 vmax=self.zmax,
305 cmap=self.cmaps[n])
305 cmap=self.cmaps[n])
306 else:
306 else:
307 if self.zlimits is not None:
307 if self.zlimits is not None:
308 self.zmin, self.zmax = self.zlimits[n]
308 self.zmin, self.zmax = self.zlimits[n]
309 ax.collections.remove(ax.collections[0])
309 ax.collections.remove(ax.collections[0])
310 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
310 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
311 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
311 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
312 vmin=self.zmin,
312 vmin=self.zmin,
313 vmax=self.zmax,
313 vmax=self.zmax,
314 cmap=self.cmaps[n])
314 cmap=self.cmaps[n])
315
315
316 if self.mode == 'A':
316 if self.mode == 'A':
317 continue
317 continue
318
318
319 # plot district names
319 # plot district names
320 f = open('/data/workspace/schain_scripts/distrito.csv')
320 f = open('/data/workspace/schain_scripts/distrito.csv')
321 for line in f:
321 for line in f:
322 label, lon, lat = [s.strip() for s in line.split(',') if s]
322 label, lon, lat = [s.strip() for s in line.split(',') if s]
323 lat = float(lat)
323 lat = float(lat)
324 lon = float(lon)
324 lon = float(lon)
325 # ax.plot(lon, lat, '.b', ms=2)
325 # ax.plot(lon, lat, '.b', ms=2)
326 ax.text(lon, lat, label.decode('utf8'), ha='center',
326 ax.text(lon, lat, label.decode('utf8'), ha='center',
327 va='bottom', size='8', color='black')
327 va='bottom', size='8', color='black')
328
328
329 # plot limites
329 # plot limites
330 limites = []
330 limites = []
331 tmp = []
331 tmp = []
332 for line in open('/data/workspace/schain_scripts/lima.csv'):
332 for line in open('/data/workspace/schain_scripts/lima.csv'):
333 if '#' in line:
333 if '#' in line:
334 if tmp:
334 if tmp:
335 limites.append(tmp)
335 limites.append(tmp)
336 tmp = []
336 tmp = []
337 continue
337 continue
338 values = line.strip().split(',')
338 values = line.strip().split(',')
339 tmp.append((float(values[0]), float(values[1])))
339 tmp.append((float(values[0]), float(values[1])))
340 for points in limites:
340 for points in limites:
341 ax.add_patch(
341 ax.add_patch(
342 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
342 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
343
343
344 # plot Cuencas
344 # plot Cuencas
345 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
345 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
346 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
346 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
347 values = [line.strip().split(',') for line in f]
347 values = [line.strip().split(',') for line in f]
348 points = [(float(s[0]), float(s[1])) for s in values]
348 points = [(float(s[0]), float(s[1])) for s in values]
349 ax.add_patch(Polygon(points, ec='b', fc='none'))
349 ax.add_patch(Polygon(points, ec='b', fc='none'))
350
350
351 # plot grid
351 # plot grid
352 for r in (15, 30, 45, 60):
352 for r in (15, 30, 45, 60):
353 ax.add_artist(plt.Circle((self.lon, self.lat),
353 ax.add_artist(plt.Circle((self.lon, self.lat),
354 km2deg(r), color='0.6', fill=False, lw=0.2))
354 km2deg(r), color='0.6', fill=False, lw=0.2))
355 ax.text(
355 ax.text(
356 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
356 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
357 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
357 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
358 '{}km'.format(r),
358 '{}km'.format(r),
359 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
359 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
360
360
361 if self.mode == 'E':
361 if self.mode == 'E':
362 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
362 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
363 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
363 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
364 else:
364 else:
365 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
365 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
366 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
366 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
367
367
368 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
368 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
369 self.titles = ['{} {}'.format(
369 self.titles = ['{} {}'.format(
370 self.data.parameters[x], title) for x in self.channels]
370 self.data.parameters[x], title) for x in self.channels]
371
371
372 class WeatherPlot(Plot):
372 class WeatherPlot(Plot):
373 CODE = 'weather'
373 CODE = 'weather'
374 plot_name = 'weather'
374 plot_name = 'weather'
375 plot_type = 'ppistyle'
375 plot_type = 'ppistyle'
376 buffering = False
376 buffering = False
377
377
378 def setup(self):
378 def setup(self):
379 self.ncols = 1
379 self.ncols = 1
380 self.nrows = 1
380 self.nrows = 1
381 self.width =8
381 self.width =8
382 self.height =8
382 self.height =8
383 self.nplots= 1
383 self.nplots= 1
384 self.ylabel= 'Range [Km]'
384 self.ylabel= 'Range [Km]'
385 self.titles= ['Weather']
385 self.titles= ['Weather']
386 self.colorbar=False
386 self.colorbar=False
387 self.ini =0
387 self.ini =0
388 self.len_azi =0
388 self.len_azi =0
389 self.buffer_ini = None
389 self.buffer_ini = None
390 self.buffer_azi = None
390 self.buffer_azi = None
391 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
391 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
392 self.flag =0
392 self.flag =0
393 self.indicador= 0
393 self.indicador= 0
394 self.last_data_azi = None
394 self.last_data_azi = None
395 self.val_mean = None
395 self.val_mean = None
396
396
397 def update(self, dataOut):
397 def update(self, dataOut):
398
398
399 data = {}
399 data = {}
400 meta = {}
400 meta = {}
401 if hasattr(dataOut, 'dataPP_POWER'):
401 if hasattr(dataOut, 'dataPP_POWER'):
402 factor = 1
402 factor = 1
403 if hasattr(dataOut, 'nFFTPoints'):
403 if hasattr(dataOut, 'nFFTPoints'):
404 factor = dataOut.normFactor
404 factor = dataOut.normFactor
405 #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape)
405 #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape)
406 data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor))
406 data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor))
407 data['azi'] = dataOut.data_azi
407 data['azi'] = dataOut.data_azi
408 data['ele'] = dataOut.data_ele
408 data['ele'] = dataOut.data_ele
409 return data, meta
409 return data, meta
410
410
411 def get2List(self,angulos):
411 def get2List(self,angulos):
412 list1=[]
412 list1=[]
413 list2=[]
413 list2=[]
414 for i in reversed(range(len(angulos))):
414 for i in reversed(range(len(angulos))):
415 diff_ = angulos[i]-angulos[i-1]
415 diff_ = angulos[i]-angulos[i-1]
416 if diff_ >1.5:
416 if diff_ >1.5:
417 list1.append(i-1)
417 list1.append(i-1)
418 list2.append(diff_)
418 list2.append(diff_)
419 return list(reversed(list1)),list(reversed(list2))
419 return list(reversed(list1)),list(reversed(list2))
420
420
421 def fixData360(self,list_,ang_):
421 def fixData360(self,list_,ang_):
422 if list_[0]==-1:
422 if list_[0]==-1:
423 vec = numpy.where(ang_<ang_[0])
423 vec = numpy.where(ang_<ang_[0])
424 ang_[vec] = ang_[vec]+360
424 ang_[vec] = ang_[vec]+360
425 return ang_
425 return ang_
426 return ang_
426 return ang_
427
427
428 def fixData360HL(self,angulos):
428 def fixData360HL(self,angulos):
429 vec = numpy.where(angulos>=360)
429 vec = numpy.where(angulos>=360)
430 angulos[vec]=angulos[vec]-360
430 angulos[vec]=angulos[vec]-360
431 return angulos
431 return angulos
432
432
433 def search_pos(self,pos,list_):
433 def search_pos(self,pos,list_):
434 for i in range(len(list_)):
434 for i in range(len(list_)):
435 if pos == list_[i]:
435 if pos == list_[i]:
436 return True,i
436 return True,i
437 i=None
437 i=None
438 return False,i
438 return False,i
439
439
440 def fixDataComp(self,ang_,list1_,list2_):
440 def fixDataComp(self,ang_,list1_,list2_):
441 size = len(ang_)
441 size = len(ang_)
442 size2 = 0
442 size2 = 0
443 for i in range(len(list2_)):
443 for i in range(len(list2_)):
444 size2=size2+round(list2_[i])-1
444 size2=size2+round(list2_[i])-1
445 new_size= size+size2
445 new_size= size+size2
446 ang_new = numpy.zeros(new_size)
446 ang_new = numpy.zeros(new_size)
447 ang_new2 = numpy.zeros(new_size)
447 ang_new2 = numpy.zeros(new_size)
448
448
449 tmp = 0
449 tmp = 0
450 c = 0
450 c = 0
451 for i in range(len(ang_)):
451 for i in range(len(ang_)):
452 ang_new[tmp +c] = ang_[i]
452 ang_new[tmp +c] = ang_[i]
453 ang_new2[tmp+c] = ang_[i]
453 ang_new2[tmp+c] = ang_[i]
454 condition , value = self.search_pos(i,list1_)
454 condition , value = self.search_pos(i,list1_)
455 if condition:
455 if condition:
456 pos = tmp + c + 1
456 pos = tmp + c + 1
457 for k in range(round(list2_[value])-1):
457 for k in range(round(list2_[value])-1):
458 ang_new[pos+k] = ang_new[pos+k-1]+1
458 ang_new[pos+k] = ang_new[pos+k-1]+1
459 ang_new2[pos+k] = numpy.nan
459 ang_new2[pos+k] = numpy.nan
460 tmp = pos +k
460 tmp = pos +k
461 c = 0
461 c = 0
462 c=c+1
462 c=c+1
463 return ang_new,ang_new2
463 return ang_new,ang_new2
464
464
465 def globalCheckPED(self,angulos):
465 def globalCheckPED(self,angulos):
466 l1,l2 = self.get2List(angulos)
466 l1,l2 = self.get2List(angulos)
467 if len(l1)>0:
467 if len(l1)>0:
468 angulos2 = self.fixData360(list_=l1,ang_=angulos)
468 angulos2 = self.fixData360(list_=l1,ang_=angulos)
469 l1,l2 = self.get2List(angulos2)
469 l1,l2 = self.get2List(angulos2)
470
470
471 ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2)
471 ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2)
472 ang1_ = self.fixData360HL(ang1_)
472 ang1_ = self.fixData360HL(ang1_)
473 ang2_ = self.fixData360HL(ang2_)
473 ang2_ = self.fixData360HL(ang2_)
474 else:
474 else:
475 ang1_= angulos
475 ang1_= angulos
476 ang2_= angulos
476 ang2_= angulos
477 return ang1_,ang2_
477 return ang1_,ang2_
478
478
479 def analizeDATA(self,data_azi):
479 def analizeDATA(self,data_azi):
480 list1 = []
480 list1 = []
481 list2 = []
481 list2 = []
482 dat = data_azi
482 dat = data_azi
483 for i in reversed(range(1,len(dat))):
483 for i in reversed(range(1,len(dat))):
484 if dat[i]>dat[i-1]:
484 if dat[i]>dat[i-1]:
485 diff = int(dat[i])-int(dat[i-1])
485 diff = int(dat[i])-int(dat[i-1])
486 else:
486 else:
487 diff = 360+int(dat[i])-int(dat[i-1])
487 diff = 360+int(dat[i])-int(dat[i-1])
488 if diff > 1:
488 if diff > 1:
489 list1.append(i-1)
489 list1.append(i-1)
490 list2.append(diff-1)
490 list2.append(diff-1)
491 return list1,list2
491 return list1,list2
492
492
493 def fixDATANEW(self,data_azi,data_weather):
493 def fixDATANEW(self,data_azi,data_weather):
494 list1,list2 = self.analizeDATA(data_azi)
494 list1,list2 = self.analizeDATA(data_azi)
495 if len(list1)== 0:
495 if len(list1)== 0:
496 return data_azi,data_weather
496 return data_azi,data_weather
497 else:
497 else:
498 resize = 0
498 resize = 0
499 for i in range(len(list2)):
499 for i in range(len(list2)):
500 resize= resize + list2[i]
500 resize= resize + list2[i]
501 new_data_azi = numpy.resize(data_azi,resize)
501 new_data_azi = numpy.resize(data_azi,resize)
502 new_data_weather= numpy.resize(date_weather,resize)
502 new_data_weather= numpy.resize(date_weather,resize)
503
503
504 for i in range(len(list2)):
504 for i in range(len(list2)):
505 j=0
505 j=0
506 position=list1[i]+1
506 position=list1[i]+1
507 for j in range(list2[i]):
507 for j in range(list2[i]):
508 new_data_azi[position+j]=new_data_azi[position+j-1]+1
508 new_data_azi[position+j]=new_data_azi[position+j-1]+1
509 return new_data_azi
509 return new_data_azi
510
510
511 def fixDATA(self,data_azi):
511 def fixDATA(self,data_azi):
512 data=data_azi
512 data=data_azi
513 for i in range(len(data)):
513 for i in range(len(data)):
514 if numpy.isnan(data[i]):
514 if numpy.isnan(data[i]):
515 data[i]=data[i-1]+1
515 data[i]=data[i-1]+1
516 return data
516 return data
517
517
518 def replaceNAN(self,data_weather,data_azi,val):
518 def replaceNAN(self,data_weather,data_azi,val):
519 data= data_azi
519 data= data_azi
520 data_T= data_weather
520 data_T= data_weather
521 if data.shape[0]> data_T.shape[0]:
521 if data.shape[0]> data_T.shape[0]:
522 data_N = numpy.ones( [data.shape[0],data_T.shape[1]])
522 data_N = numpy.ones( [data.shape[0],data_T.shape[1]])
523 c = 0
523 c = 0
524 for i in range(len(data)):
524 for i in range(len(data)):
525 if numpy.isnan(data[i]):
525 if numpy.isnan(data[i]):
526 data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
526 data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
527 else:
527 else:
528 data_N[i,:]=data_T[c,:]
528 data_N[i,:]=data_T[c,:]
529 c=c+1
529 c=c+1
530 return data_N
530 return data_N
531 else:
531 else:
532 for i in range(len(data)):
532 for i in range(len(data)):
533 if numpy.isnan(data[i]):
533 if numpy.isnan(data[i]):
534 data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
534 data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
535 return data_T
535 return data_T
536
536
537 def const_ploteo(self,data_weather,data_azi,step,res):
537 def const_ploteo(self,data_weather,data_azi,step,res):
538 if self.ini==0:
538 if self.ini==0:
539 #-------
539 #-------
540 n = (360/res)-len(data_azi)
540 n = (360/res)-len(data_azi)
541 #--------------------- new -------------------------
541 #--------------------- new -------------------------
542 data_azi_new ,data_azi_old= self.globalCheckPED(data_azi)
542 data_azi_new ,data_azi_old= self.globalCheckPED(data_azi)
543 #------------------------
543 #------------------------
544 start = data_azi_new[-1] + res
544 start = data_azi_new[-1] + res
545 end = data_azi_new[0] - res
545 end = data_azi_new[0] - res
546 #------ new
546 #------ new
547 self.last_data_azi = end
547 self.last_data_azi = end
548 if start>end:
548 if start>end:
549 end = end + 360
549 end = end + 360
550 azi_vacia = numpy.linspace(start,end,int(n))
550 azi_vacia = numpy.linspace(start,end,int(n))
551 azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia)
551 azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia)
552 data_azi = numpy.hstack((data_azi_new,azi_vacia))
552 data_azi = numpy.hstack((data_azi_new,azi_vacia))
553 # RADAR
553 # RADAR
554 val_mean = numpy.mean(data_weather[:,-1])
554 val_mean = numpy.mean(data_weather[:,-1])
555 self.val_mean = val_mean
555 self.val_mean = val_mean
556 data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean
556 data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean
557 data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean)
557 data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean)
558 data_weather = numpy.vstack((data_weather,data_weather_cmp))
558 data_weather = numpy.vstack((data_weather,data_weather_cmp))
559 else:
559 else:
560 # azimuth
560 # azimuth
561 flag=0
561 flag=0
562 start_azi = self.res_azi[0]
562 start_azi = self.res_azi[0]
563 #-----------new------------
563 #-----------new------------
564 data_azi ,data_azi_old= self.globalCheckPED(data_azi)
564 data_azi ,data_azi_old= self.globalCheckPED(data_azi)
565 data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean)
565 data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean)
566 #--------------------------
566 #--------------------------
567 start = data_azi[0]
567 start = data_azi[0]
568 end = data_azi[-1]
568 end = data_azi[-1]
569 self.last_data_azi= end
569 self.last_data_azi= end
570 if start< start_azi:
570 if start< start_azi:
571 start = start +360
571 start = start +360
572 if end <start_azi:
572 if end <start_azi:
573 end = end +360
573 end = end +360
574
574
575 pos_ini = int((start-start_azi)/res)
575 pos_ini = int((start-start_azi)/res)
576 len_azi = len(data_azi)
576 len_azi = len(data_azi)
577 if (360-pos_ini)<len_azi:
577 if (360-pos_ini)<len_azi:
578 if pos_ini+1==360:
578 if pos_ini+1==360:
579 pos_ini=0
579 pos_ini=0
580 else:
580 else:
581 flag=1
581 flag=1
582 dif= 360-pos_ini
582 dif= 360-pos_ini
583 comp= len_azi-dif
583 comp= len_azi-dif
584 #-----------------
584 #-----------------
585 if flag==0:
585 if flag==0:
586 # AZIMUTH
586 # AZIMUTH
587 self.res_azi[pos_ini:pos_ini+len_azi] = data_azi
587 self.res_azi[pos_ini:pos_ini+len_azi] = data_azi
588 # RADAR
588 # RADAR
589 self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather
589 self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather
590 else:
590 else:
591 # AZIMUTH
591 # AZIMUTH
592 self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif]
592 self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif]
593 self.res_azi[0:comp] = data_azi[dif:]
593 self.res_azi[0:comp] = data_azi[dif:]
594 # RADAR
594 # RADAR
595 self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:]
595 self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:]
596 self.res_weather[0:comp,:] = data_weather[dif:,:]
596 self.res_weather[0:comp,:] = data_weather[dif:,:]
597 flag=0
597 flag=0
598 data_azi = self.res_azi
598 data_azi = self.res_azi
599 data_weather = self.res_weather
599 data_weather = self.res_weather
600
600
601 return data_weather,data_azi
601 return data_weather,data_azi
602
602
603 def plot(self):
603 def plot(self):
604 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S')
604 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S')
605 data = self.data[-1]
605 data = self.data[-1]
606 r = self.data.yrange
606 r = self.data.yrange
607 delta_height = r[1]-r[0]
607 delta_height = r[1]-r[0]
608 r_mask = numpy.where(r>=0)[0]
608 r_mask = numpy.where(r>=0)[0]
609 r = numpy.arange(len(r_mask))*delta_height
609 r = numpy.arange(len(r_mask))*delta_height
610 self.y = 2*r
610 self.y = 2*r
611 # RADAR
611 # RADAR
612 #data_weather = data['weather']
612 #data_weather = data['weather']
613 # PEDESTAL
613 # PEDESTAL
614 #data_azi = data['azi']
614 #data_azi = data['azi']
615 res = 1
615 res = 1
616 # STEP
616 # STEP
617 step = (360/(res*data['weather'].shape[0]))
617 step = (360/(res*data['weather'].shape[0]))
618
618
619 self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_azi=data['azi'],step=step,res=res)
619 self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_azi=data['azi'],step=step,res=res)
620 self.res_ele = numpy.mean(data['ele'])
620 self.res_ele = numpy.mean(data['ele'])
621 ################# PLOTEO ###################
621 ################# PLOTEO ###################
622 for i,ax in enumerate(self.axes):
622 for i,ax in enumerate(self.axes):
623 self.zmin = self.zmin if self.zmin else 20
623 self.zmin = self.zmin if self.zmin else 20
624 self.zmax = self.zmax if self.zmax else 80
624 self.zmax = self.zmax if self.zmax else 80
625 if ax.firsttime:
625 if ax.firsttime:
626 plt.clf()
626 plt.clf()
627 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=self.zmin, vmax=self.zmax)
627 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=self.zmin, vmax=self.zmax)
628 else:
628 else:
629 plt.clf()
629 plt.clf()
630 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=self.zmin, vmax=self.zmax)
630 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=self.zmin, vmax=self.zmax)
631 caax = cgax.parasites[0]
631 caax = cgax.parasites[0]
632 paax = cgax.parasites[1]
632 paax = cgax.parasites[1]
633 cbar = plt.gcf().colorbar(pm, pad=0.075)
633 cbar = plt.gcf().colorbar(pm, pad=0.075)
634 caax.set_xlabel('x_range [km]')
634 caax.set_xlabel('x_range [km]')
635 caax.set_ylabel('y_range [km]')
635 caax.set_ylabel('y_range [km]')
636 plt.text(1.0, 1.05, 'Azimuth '+str(thisDatetime)+" Step "+str(self.ini)+ " EL: "+str(round(self.res_ele, 1)), transform=caax.transAxes, va='bottom',ha='right')
636 plt.text(1.0, 1.05, 'Azimuth '+str(thisDatetime)+" Step "+str(self.ini)+ " EL: "+str(round(self.res_ele, 1)), transform=caax.transAxes, va='bottom',ha='right')
637
637
638 self.ini= self.ini+1
638 self.ini= self.ini+1
639
639
640
640
641 class WeatherRHIPlot(Plot):
641 class WeatherRHIPlot(Plot):
642 CODE = 'weather'
642 CODE = 'weather'
643 plot_name = 'weather'
643 plot_name = 'weather'
644 plot_type = 'rhistyle'
644 plot_type = 'rhistyle'
645 buffering = False
645 buffering = False
646 data_ele_tmp = None
646 data_ele_tmp = None
647
647
648 def setup(self):
648 def setup(self):
649 print("********************")
649 print("********************")
650 print("********************")
650 print("********************")
651 print("********************")
651 print("********************")
652 print("SETUP WEATHER PLOT")
652 print("SETUP WEATHER PLOT")
653 self.ncols = 1
653 self.ncols = 1
654 self.nrows = 1
654 self.nrows = 1
655 self.nplots= 1
655 self.nplots= 1
656 self.ylabel= 'Range [Km]'
656 self.ylabel= 'Range [Km]'
657 self.titles= ['Weather']
657 self.titles= ['Weather']
658 if self.channels is not None:
658 if self.channels is not None:
659 self.nplots = len(self.channels)
659 self.nplots = len(self.channels)
660 self.nrows = len(self.channels)
660 self.nrows = len(self.channels)
661 else:
661 else:
662 self.nplots = self.data.shape(self.CODE)[0]
662 self.nplots = self.data.shape(self.CODE)[0]
663 self.nrows = self.nplots
663 self.nrows = self.nplots
664 self.channels = list(range(self.nplots))
664 self.channels = list(range(self.nplots))
665 print("channels",self.channels)
665 print("channels",self.channels)
666 print("que saldra", self.data.shape(self.CODE)[0])
666 print("que saldra", self.data.shape(self.CODE)[0])
667 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
667 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
668 print("self.titles",self.titles)
668 print("self.titles",self.titles)
669 self.colorbar=False
669 self.colorbar=False
670 self.width =12
670 self.width =12
671 self.height =8
671 self.height =8
672 self.ini =0
672 self.ini =0
673 self.len_azi =0
673 self.len_azi =0
674 self.buffer_ini = None
674 self.buffer_ini = None
675 self.buffer_ele = None
675 self.buffer_ele = None
676 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
676 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
677 self.flag =0
677 self.flag =0
678 self.indicador= 0
678 self.indicador= 0
679 self.last_data_ele = None
679 self.last_data_ele = None
680 self.val_mean = None
680 self.val_mean = None
681
681
682 def update(self, dataOut):
682 def update(self, dataOut):
683
683
684 data = {}
684 data = {}
685 meta = {}
685 meta = {}
686 if hasattr(dataOut, 'dataPP_POWER'):
686 if hasattr(dataOut, 'dataPP_POWER'):
687 factor = 1
687 factor = 1
688 if hasattr(dataOut, 'nFFTPoints'):
688 if hasattr(dataOut, 'nFFTPoints'):
689 factor = dataOut.normFactor
689 factor = dataOut.normFactor
690 print("dataOut",dataOut.data_360.shape)
690 print("dataOut",dataOut.data_360.shape)
691 #
691 #
692 data['weather'] = 10*numpy.log10(dataOut.data_360/(factor))
692 data['weather'] = 10*numpy.log10(dataOut.data_360/(factor))
693 #
693 #
694 #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor))
694 #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor))
695 data['azi'] = dataOut.data_azi
695 data['azi'] = dataOut.data_azi
696 data['ele'] = dataOut.data_ele
696 data['ele'] = dataOut.data_ele
697 #print("UPDATE")
697 #print("UPDATE")
698 #print("data[weather]",data['weather'].shape)
698 #print("data[weather]",data['weather'].shape)
699 #print("data[azi]",data['azi'])
699 #print("data[azi]",data['azi'])
700 return data, meta
700 return data, meta
701
701
702 def get2List(self,angulos):
702 def get2List(self,angulos):
703 list1=[]
703 list1=[]
704 list2=[]
704 list2=[]
705 for i in reversed(range(len(angulos))):
705 for i in reversed(range(len(angulos))):
706 if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante
706 if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante
707 diff_ = angulos[i]-angulos[i-1]
707 diff_ = angulos[i]-angulos[i-1]
708 if abs(diff_) >1.5:
708 if abs(diff_) >1.5:
709 list1.append(i-1)
709 list1.append(i-1)
710 list2.append(diff_)
710 list2.append(diff_)
711 return list(reversed(list1)),list(reversed(list2))
711 return list(reversed(list1)),list(reversed(list2))
712
712
713 def fixData90(self,list_,ang_):
713 def fixData90(self,list_,ang_):
714 if list_[0]==-1:
714 if list_[0]==-1:
715 vec = numpy.where(ang_<ang_[0])
715 vec = numpy.where(ang_<ang_[0])
716 ang_[vec] = ang_[vec]+90
716 ang_[vec] = ang_[vec]+90
717 return ang_
717 return ang_
718 return ang_
718 return ang_
719
719
720 def fixData90HL(self,angulos):
720 def fixData90HL(self,angulos):
721 vec = numpy.where(angulos>=90)
721 vec = numpy.where(angulos>=90)
722 angulos[vec]=angulos[vec]-90
722 angulos[vec]=angulos[vec]-90
723 return angulos
723 return angulos
724
724
725
725
726 def search_pos(self,pos,list_):
726 def search_pos(self,pos,list_):
727 for i in range(len(list_)):
727 for i in range(len(list_)):
728 if pos == list_[i]:
728 if pos == list_[i]:
729 return True,i
729 return True,i
730 i=None
730 i=None
731 return False,i
731 return False,i
732
732
733 def fixDataComp(self,ang_,list1_,list2_,tipo_case):
733 def fixDataComp(self,ang_,list1_,list2_,tipo_case):
734 size = len(ang_)
734 size = len(ang_)
735 size2 = 0
735 size2 = 0
736 for i in range(len(list2_)):
736 for i in range(len(list2_)):
737 size2=size2+round(abs(list2_[i]))-1
737 size2=size2+round(abs(list2_[i]))-1
738 new_size= size+size2
738 new_size= size+size2
739 ang_new = numpy.zeros(new_size)
739 ang_new = numpy.zeros(new_size)
740 ang_new2 = numpy.zeros(new_size)
740 ang_new2 = numpy.zeros(new_size)
741
741
742 tmp = 0
742 tmp = 0
743 c = 0
743 c = 0
744 for i in range(len(ang_)):
744 for i in range(len(ang_)):
745 ang_new[tmp +c] = ang_[i]
745 ang_new[tmp +c] = ang_[i]
746 ang_new2[tmp+c] = ang_[i]
746 ang_new2[tmp+c] = ang_[i]
747 condition , value = self.search_pos(i,list1_)
747 condition , value = self.search_pos(i,list1_)
748 if condition:
748 if condition:
749 pos = tmp + c + 1
749 pos = tmp + c + 1
750 for k in range(round(abs(list2_[value]))-1):
750 for k in range(round(abs(list2_[value]))-1):
751 if tipo_case==0 or tipo_case==3:#subida
751 if tipo_case==0 or tipo_case==3:#subida
752 ang_new[pos+k] = ang_new[pos+k-1]+1
752 ang_new[pos+k] = ang_new[pos+k-1]+1
753 ang_new2[pos+k] = numpy.nan
753 ang_new2[pos+k] = numpy.nan
754 elif tipo_case==1 or tipo_case==2:#bajada
754 elif tipo_case==1 or tipo_case==2:#bajada
755 ang_new[pos+k] = ang_new[pos+k-1]-1
755 ang_new[pos+k] = ang_new[pos+k-1]-1
756 ang_new2[pos+k] = numpy.nan
756 ang_new2[pos+k] = numpy.nan
757
757
758 tmp = pos +k
758 tmp = pos +k
759 c = 0
759 c = 0
760 c=c+1
760 c=c+1
761 return ang_new,ang_new2
761 return ang_new,ang_new2
762
762
763 def globalCheckPED(self,angulos,tipo_case):
763 def globalCheckPED(self,angulos,tipo_case):
764 l1,l2 = self.get2List(angulos)
764 l1,l2 = self.get2List(angulos)
765 ##print("l1",l1)
765 ##print("l1",l1)
766 ##print("l2",l2)
766 ##print("l2",l2)
767 if len(l1)>0:
767 if len(l1)>0:
768 #angulos2 = self.fixData90(list_=l1,ang_=angulos)
768 #angulos2 = self.fixData90(list_=l1,ang_=angulos)
769 #l1,l2 = self.get2List(angulos2)
769 #l1,l2 = self.get2List(angulos2)
770 ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case)
770 ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case)
771 #ang1_ = self.fixData90HL(ang1_)
771 #ang1_ = self.fixData90HL(ang1_)
772 #ang2_ = self.fixData90HL(ang2_)
772 #ang2_ = self.fixData90HL(ang2_)
773 else:
773 else:
774 ang1_= angulos
774 ang1_= angulos
775 ang2_= angulos
775 ang2_= angulos
776 return ang1_,ang2_
776 return ang1_,ang2_
777
777
778
778
779 def replaceNAN(self,data_weather,data_ele,val):
779 def replaceNAN(self,data_weather,data_ele,val):
780 data= data_ele
780 data= data_ele
781 data_T= data_weather
781 data_T= data_weather
782 if data.shape[0]> data_T.shape[0]:
782 if data.shape[0]> data_T.shape[0]:
783 data_N = numpy.ones( [data.shape[0],data_T.shape[1]])
783 data_N = numpy.ones( [data.shape[0],data_T.shape[1]])
784 c = 0
784 c = 0
785 for i in range(len(data)):
785 for i in range(len(data)):
786 if numpy.isnan(data[i]):
786 if numpy.isnan(data[i]):
787 data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
787 data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
788 else:
788 else:
789 data_N[i,:]=data_T[c,:]
789 data_N[i,:]=data_T[c,:]
790 c=c+1
790 c=c+1
791 return data_N
791 return data_N
792 else:
792 else:
793 for i in range(len(data)):
793 for i in range(len(data)):
794 if numpy.isnan(data[i]):
794 if numpy.isnan(data[i]):
795 data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
795 data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
796 return data_T
796 return data_T
797
797
798 def check_case(self,data_ele,ang_max,ang_min):
798 def check_case(self,data_ele,ang_max,ang_min):
799 start = data_ele[0]
799 start = data_ele[0]
800 end = data_ele[-1]
800 end = data_ele[-1]
801 number = (end-start)
801 number = (end-start)
802 len_ang=len(data_ele)
802 len_ang=len(data_ele)
803 print("start",start)
803 print("start",start)
804 print("end",end)
804 print("end",end)
805 print("number",number)
805 print("number",number)
806
806
807 print("len_ang",len_ang)
807 print("len_ang",len_ang)
808
808
809 #exit(1)
809 #exit(1)
810
810
811 if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida
811 if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida
812 return 0
812 return 0
813 #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada
813 #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada
814 # return 1
814 # return 1
815 elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada
815 elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada
816 return 1
816 return 1
817 elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX
817 elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX
818 return 2
818 return 2
819 elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN
819 elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN
820 return 3
820 return 3
821
821
822
822
823 def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min):
823 def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min):
824 ang_max= ang_max
824 ang_max= ang_max
825 ang_min= ang_min
825 ang_min= ang_min
826 data_weather=data_weather
826 data_weather=data_weather
827 val_ch=val_ch
827 val_ch=val_ch
828 ##print("*********************DATA WEATHER**************************************")
828 ##print("*********************DATA WEATHER**************************************")
829 ##print(data_weather)
829 ##print(data_weather)
830 if self.ini==0:
830 if self.ini==0:
831 '''
831 '''
832 print("**********************************************")
832 print("**********************************************")
833 print("**********************************************")
833 print("**********************************************")
834 print("***************ini**************")
834 print("***************ini**************")
835 print("**********************************************")
835 print("**********************************************")
836 print("**********************************************")
836 print("**********************************************")
837 '''
837 '''
838 #print("data_ele",data_ele)
838 #print("data_ele",data_ele)
839 #----------------------------------------------------------
839 #----------------------------------------------------------
840 tipo_case = self.check_case(data_ele,ang_max,ang_min)
840 tipo_case = self.check_case(data_ele,ang_max,ang_min)
841 print("check_case",tipo_case)
841 print("check_case",tipo_case)
842 #exit(1)
842 #exit(1)
843 #--------------------- new -------------------------
843 #--------------------- new -------------------------
844 data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case)
844 data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case)
845
845
846 #-------------------------CAMBIOS RHI---------------------------------
846 #-------------------------CAMBIOS RHI---------------------------------
847 start= ang_min
847 start= ang_min
848 end = ang_max
848 end = ang_max
849 n= (ang_max-ang_min)/res
849 n= (ang_max-ang_min)/res
850 #------ new
850 #------ new
851 self.start_data_ele = data_ele_new[0]
851 self.start_data_ele = data_ele_new[0]
852 self.end_data_ele = data_ele_new[-1]
852 self.end_data_ele = data_ele_new[-1]
853 if tipo_case==0 or tipo_case==3: # SUBIDA
853 if tipo_case==0 or tipo_case==3: # SUBIDA
854 n1= round(self.start_data_ele)- start
854 n1= round(self.start_data_ele)- start
855 n2= end - round(self.end_data_ele)
855 n2= end - round(self.end_data_ele)
856 print(self.start_data_ele)
856 print(self.start_data_ele)
857 print(self.end_data_ele)
857 print(self.end_data_ele)
858 if n1>0:
858 if n1>0:
859 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
859 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
860 ele1_nan= numpy.ones(n1)*numpy.nan
860 ele1_nan= numpy.ones(n1)*numpy.nan
861 data_ele = numpy.hstack((ele1,data_ele_new))
861 data_ele = numpy.hstack((ele1,data_ele_new))
862 print("ele1_nan",ele1_nan.shape)
862 print("ele1_nan",ele1_nan.shape)
863 print("data_ele_old",data_ele_old.shape)
863 print("data_ele_old",data_ele_old.shape)
864 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
864 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
865 if n2>0:
865 if n2>0:
866 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
866 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
867 ele2_nan= numpy.ones(n2)*numpy.nan
867 ele2_nan= numpy.ones(n2)*numpy.nan
868 data_ele = numpy.hstack((data_ele,ele2))
868 data_ele = numpy.hstack((data_ele,ele2))
869 print("ele2_nan",ele2_nan.shape)
869 print("ele2_nan",ele2_nan.shape)
870 print("data_ele_old",data_ele_old.shape)
870 print("data_ele_old",data_ele_old.shape)
871 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
871 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
872
872
873 if tipo_case==1 or tipo_case==2: # BAJADA
873 if tipo_case==1 or tipo_case==2: # BAJADA
874 data_ele_new = data_ele_new[::-1] # reversa
874 data_ele_new = data_ele_new[::-1] # reversa
875 data_ele_old = data_ele_old[::-1]# reversa
875 data_ele_old = data_ele_old[::-1]# reversa
876 data_weather = data_weather[::-1,:]# reversa
876 data_weather = data_weather[::-1,:]# reversa
877 vec= numpy.where(data_ele_new<ang_max)
877 vec= numpy.where(data_ele_new<ang_max)
878 data_ele_new = data_ele_new[vec]
878 data_ele_new = data_ele_new[vec]
879 data_ele_old = data_ele_old[vec]
879 data_ele_old = data_ele_old[vec]
880 data_weather = data_weather[vec[0]]
880 data_weather = data_weather[vec[0]]
881 vec2= numpy.where(0<data_ele_new)
881 vec2= numpy.where(0<data_ele_new)
882 data_ele_new = data_ele_new[vec2]
882 data_ele_new = data_ele_new[vec2]
883 data_ele_old = data_ele_old[vec2]
883 data_ele_old = data_ele_old[vec2]
884 data_weather = data_weather[vec2[0]]
884 data_weather = data_weather[vec2[0]]
885 self.start_data_ele = data_ele_new[0]
885 self.start_data_ele = data_ele_new[0]
886 self.end_data_ele = data_ele_new[-1]
886 self.end_data_ele = data_ele_new[-1]
887
887
888 n1= round(self.start_data_ele)- start
888 n1= round(self.start_data_ele)- start
889 n2= end - round(self.end_data_ele)-1
889 n2= end - round(self.end_data_ele)-1
890 print(self.start_data_ele)
890 print(self.start_data_ele)
891 print(self.end_data_ele)
891 print(self.end_data_ele)
892 if n1>0:
892 if n1>0:
893 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
893 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
894 ele1_nan= numpy.ones(n1)*numpy.nan
894 ele1_nan= numpy.ones(n1)*numpy.nan
895 data_ele = numpy.hstack((ele1,data_ele_new))
895 data_ele = numpy.hstack((ele1,data_ele_new))
896 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
896 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
897 if n2>0:
897 if n2>0:
898 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
898 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
899 ele2_nan= numpy.ones(n2)*numpy.nan
899 ele2_nan= numpy.ones(n2)*numpy.nan
900 data_ele = numpy.hstack((data_ele,ele2))
900 data_ele = numpy.hstack((data_ele,ele2))
901 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
901 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
902 # RADAR
902 # RADAR
903 # NOTA data_ele y data_weather es la variable que retorna
903 # NOTA data_ele y data_weather es la variable que retorna
904 val_mean = numpy.mean(data_weather[:,-1])
904 val_mean = numpy.mean(data_weather[:,-1])
905 self.val_mean = val_mean
905 self.val_mean = val_mean
906 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
906 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
907 self.data_ele_tmp[val_ch]= data_ele_old
907 self.data_ele_tmp[val_ch]= data_ele_old
908 else:
908 else:
909 #print("**********************************************")
909 #print("**********************************************")
910 #print("****************VARIABLE**********************")
910 #print("****************VARIABLE**********************")
911 #-------------------------CAMBIOS RHI---------------------------------
911 #-------------------------CAMBIOS RHI---------------------------------
912 #---------------------------------------------------------------------
912 #---------------------------------------------------------------------
913 ##print("INPUT data_ele",data_ele)
913 ##print("INPUT data_ele",data_ele)
914 flag=0
914 flag=0
915 start_ele = self.res_ele[0]
915 start_ele = self.res_ele[0]
916 tipo_case = self.check_case(data_ele,ang_max,ang_min)
916 tipo_case = self.check_case(data_ele,ang_max,ang_min)
917 #print("TIPO DE DATA",tipo_case)
917 #print("TIPO DE DATA",tipo_case)
918 #-----------new------------
918 #-----------new------------
919 data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case)
919 data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case)
920 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
920 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
921
921
922 #-------------------------------NEW RHI ITERATIVO-------------------------
922 #-------------------------------NEW RHI ITERATIVO-------------------------
923
923
924 if tipo_case==0 : # SUBIDA
924 if tipo_case==0 : # SUBIDA
925 vec = numpy.where(data_ele<ang_max)
925 vec = numpy.where(data_ele<ang_max)
926 data_ele = data_ele[vec]
926 data_ele = data_ele[vec]
927 data_ele_old = data_ele_old[vec]
927 data_ele_old = data_ele_old[vec]
928 data_weather = data_weather[vec[0]]
928 data_weather = data_weather[vec[0]]
929
929
930 vec2 = numpy.where(0<data_ele)
930 vec2 = numpy.where(0<data_ele)
931 data_ele= data_ele[vec2]
931 data_ele= data_ele[vec2]
932 data_ele_old= data_ele_old[vec2]
932 data_ele_old= data_ele_old[vec2]
933 ##print(data_ele_new)
933 ##print(data_ele_new)
934 data_weather= data_weather[vec2[0]]
934 data_weather= data_weather[vec2[0]]
935
935
936 new_i_ele = int(round(data_ele[0]))
936 new_i_ele = int(round(data_ele[0]))
937 new_f_ele = int(round(data_ele[-1]))
937 new_f_ele = int(round(data_ele[-1]))
938 #print(new_i_ele)
938 #print(new_i_ele)
939 #print(new_f_ele)
939 #print(new_f_ele)
940 #print(data_ele,len(data_ele))
940 #print(data_ele,len(data_ele))
941 #print(data_ele_old,len(data_ele_old))
941 #print(data_ele_old,len(data_ele_old))
942 if new_i_ele< 2:
942 if new_i_ele< 2:
943 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
943 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
944 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
944 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
945 self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old
945 self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old
946 self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele
946 self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele
947 self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather
947 self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather
948 data_ele = self.res_ele
948 data_ele = self.res_ele
949 data_weather = self.res_weather[val_ch]
949 data_weather = self.res_weather[val_ch]
950
950
951 elif tipo_case==1 : #BAJADA
951 elif tipo_case==1 : #BAJADA
952 data_ele = data_ele[::-1] # reversa
952 data_ele = data_ele[::-1] # reversa
953 data_ele_old = data_ele_old[::-1]# reversa
953 data_ele_old = data_ele_old[::-1]# reversa
954 data_weather = data_weather[::-1,:]# reversa
954 data_weather = data_weather[::-1,:]# reversa
955 vec= numpy.where(data_ele<ang_max)
955 vec= numpy.where(data_ele<ang_max)
956 data_ele = data_ele[vec]
956 data_ele = data_ele[vec]
957 data_ele_old = data_ele_old[vec]
957 data_ele_old = data_ele_old[vec]
958 data_weather = data_weather[vec[0]]
958 data_weather = data_weather[vec[0]]
959 vec2= numpy.where(0<data_ele)
959 vec2= numpy.where(0<data_ele)
960 data_ele = data_ele[vec2]
960 data_ele = data_ele[vec2]
961 data_ele_old = data_ele_old[vec2]
961 data_ele_old = data_ele_old[vec2]
962 data_weather = data_weather[vec2[0]]
962 data_weather = data_weather[vec2[0]]
963
963
964
964
965 new_i_ele = int(round(data_ele[0]))
965 new_i_ele = int(round(data_ele[0]))
966 new_f_ele = int(round(data_ele[-1]))
966 new_f_ele = int(round(data_ele[-1]))
967 #print(data_ele)
967 #print(data_ele)
968 #print(ang_max)
968 #print(ang_max)
969 #print(data_ele_old)
969 #print(data_ele_old)
970 if new_i_ele <= 1:
970 if new_i_ele <= 1:
971 new_i_ele = 1
971 new_i_ele = 1
972 if round(data_ele[-1])>=ang_max-1:
972 if round(data_ele[-1])>=ang_max-1:
973 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
973 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
974 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
974 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
975 self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old
975 self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old
976 self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele
976 self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele
977 self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather
977 self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather
978 data_ele = self.res_ele
978 data_ele = self.res_ele
979 data_weather = self.res_weather[val_ch]
979 data_weather = self.res_weather[val_ch]
980
980
981 elif tipo_case==2: #bajada
981 elif tipo_case==2: #bajada
982 vec = numpy.where(data_ele<ang_max)
982 vec = numpy.where(data_ele<ang_max)
983 data_ele = data_ele[vec]
983 data_ele = data_ele[vec]
984 data_weather= data_weather[vec[0]]
984 data_weather= data_weather[vec[0]]
985
985
986 len_vec = len(vec)
986 len_vec = len(vec)
987 data_ele_new = data_ele[::-1] # reversa
987 data_ele_new = data_ele[::-1] # reversa
988 data_weather = data_weather[::-1,:]
988 data_weather = data_weather[::-1,:]
989 new_i_ele = int(data_ele_new[0])
989 new_i_ele = int(data_ele_new[0])
990 new_f_ele = int(data_ele_new[-1])
990 new_f_ele = int(data_ele_new[-1])
991
991
992 n1= new_i_ele- ang_min
992 n1= new_i_ele- ang_min
993 n2= ang_max - new_f_ele-1
993 n2= ang_max - new_f_ele-1
994 if n1>0:
994 if n1>0:
995 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
995 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
996 ele1_nan= numpy.ones(n1)*numpy.nan
996 ele1_nan= numpy.ones(n1)*numpy.nan
997 data_ele = numpy.hstack((ele1,data_ele_new))
997 data_ele = numpy.hstack((ele1,data_ele_new))
998 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
998 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
999 if n2>0:
999 if n2>0:
1000 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1000 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1001 ele2_nan= numpy.ones(n2)*numpy.nan
1001 ele2_nan= numpy.ones(n2)*numpy.nan
1002 data_ele = numpy.hstack((data_ele,ele2))
1002 data_ele = numpy.hstack((data_ele,ele2))
1003 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1003 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1004
1004
1005 self.data_ele_tmp[val_ch] = data_ele_old
1005 self.data_ele_tmp[val_ch] = data_ele_old
1006 self.res_ele = data_ele
1006 self.res_ele = data_ele
1007 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1007 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1008 data_ele = self.res_ele
1008 data_ele = self.res_ele
1009 data_weather = self.res_weather[val_ch]
1009 data_weather = self.res_weather[val_ch]
1010
1010
1011 elif tipo_case==3:#subida
1011 elif tipo_case==3:#subida
1012 vec = numpy.where(0<data_ele)
1012 vec = numpy.where(0<data_ele)
1013 data_ele= data_ele[vec]
1013 data_ele= data_ele[vec]
1014 data_ele_new = data_ele
1014 data_ele_new = data_ele
1015 data_ele_old= data_ele_old[vec]
1015 data_ele_old= data_ele_old[vec]
1016 data_weather= data_weather[vec[0]]
1016 data_weather= data_weather[vec[0]]
1017 pos_ini = numpy.argmin(data_ele)
1017 pos_ini = numpy.argmin(data_ele)
1018 if pos_ini>0:
1018 if pos_ini>0:
1019 len_vec= len(data_ele)
1019 len_vec= len(data_ele)
1020 vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int)
1020 vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int)
1021 #print(vec3)
1021 #print(vec3)
1022 data_ele= data_ele[vec3]
1022 data_ele= data_ele[vec3]
1023 data_ele_new = data_ele
1023 data_ele_new = data_ele
1024 data_ele_old= data_ele_old[vec3]
1024 data_ele_old= data_ele_old[vec3]
1025 data_weather= data_weather[vec3]
1025 data_weather= data_weather[vec3]
1026
1026
1027 new_i_ele = int(data_ele_new[0])
1027 new_i_ele = int(data_ele_new[0])
1028 new_f_ele = int(data_ele_new[-1])
1028 new_f_ele = int(data_ele_new[-1])
1029 n1= new_i_ele- ang_min
1029 n1= new_i_ele- ang_min
1030 n2= ang_max - new_f_ele-1
1030 n2= ang_max - new_f_ele-1
1031 if n1>0:
1031 if n1>0:
1032 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
1032 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
1033 ele1_nan= numpy.ones(n1)*numpy.nan
1033 ele1_nan= numpy.ones(n1)*numpy.nan
1034 data_ele = numpy.hstack((ele1,data_ele_new))
1034 data_ele = numpy.hstack((ele1,data_ele_new))
1035 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
1035 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
1036 if n2>0:
1036 if n2>0:
1037 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1037 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1038 ele2_nan= numpy.ones(n2)*numpy.nan
1038 ele2_nan= numpy.ones(n2)*numpy.nan
1039 data_ele = numpy.hstack((data_ele,ele2))
1039 data_ele = numpy.hstack((data_ele,ele2))
1040 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1040 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1041
1041
1042 self.data_ele_tmp[val_ch] = data_ele_old
1042 self.data_ele_tmp[val_ch] = data_ele_old
1043 self.res_ele = data_ele
1043 self.res_ele = data_ele
1044 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1044 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1045 data_ele = self.res_ele
1045 data_ele = self.res_ele
1046 data_weather = self.res_weather[val_ch]
1046 data_weather = self.res_weather[val_ch]
1047 #print("self.data_ele_tmp",self.data_ele_tmp)
1047 #print("self.data_ele_tmp",self.data_ele_tmp)
1048 return data_weather,data_ele
1048 return data_weather,data_ele
1049
1049
1050
1050
1051 def plot(self):
1051 def plot(self):
1052 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S')
1052 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S')
1053 data = self.data[-1]
1053 data = self.data[-1]
1054 r = self.data.yrange
1054 r = self.data.yrange
1055 delta_height = r[1]-r[0]
1055 delta_height = r[1]-r[0]
1056 r_mask = numpy.where(r>=0)[0]
1056 r_mask = numpy.where(r>=0)[0]
1057 ##print("delta_height",delta_height)
1057 ##print("delta_height",delta_height)
1058 #print("r_mask",r_mask,len(r_mask))
1058 #print("r_mask",r_mask,len(r_mask))
1059 r = numpy.arange(len(r_mask))*delta_height
1059 r = numpy.arange(len(r_mask))*delta_height
1060 self.y = 2*r
1060 self.y = 2*r
1061 res = 1
1061 res = 1
1062 ###print("data['weather'].shape[0]",data['weather'].shape[0])
1062 ###print("data['weather'].shape[0]",data['weather'].shape[0])
1063 ang_max = self.ang_max
1063 ang_max = self.ang_max
1064 ang_min = self.ang_min
1064 ang_min = self.ang_min
1065 var_ang =ang_max - ang_min
1065 var_ang =ang_max - ang_min
1066 step = (int(var_ang)/(res*data['weather'].shape[0]))
1066 step = (int(var_ang)/(res*data['weather'].shape[0]))
1067 ###print("step",step)
1067 ###print("step",step)
1068 #--------------------------------------------------------
1068 #--------------------------------------------------------
1069 ##print('weather',data['weather'].shape)
1069 ##print('weather',data['weather'].shape)
1070 ##print('ele',data['ele'].shape)
1070 ##print('ele',data['ele'].shape)
1071
1071
1072 ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min)
1072 ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min)
1073 ###self.res_azi = numpy.mean(data['azi'])
1073 ###self.res_azi = numpy.mean(data['azi'])
1074 ###print("self.res_ele",self.res_ele)
1074 ###print("self.res_ele",self.res_ele)
1075 plt.clf()
1075 plt.clf()
1076 subplots = [121, 122]
1076 subplots = [121, 122]
1077 cg={'angular_spacing': 20.}
1077 cg={'angular_spacing': 20.}
1078 if self.ini==0:
1078 if self.ini==0:
1079 self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan
1079 self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan
1080 self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan
1080 self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan
1081 print("SHAPE",self.data_ele_tmp.shape)
1081 print("SHAPE",self.data_ele_tmp.shape)
1082
1082
1083 for i,ax in enumerate(self.axes):
1083 for i,ax in enumerate(self.axes):
1084 self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min)
1084 self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min)
1085 self.res_azi = numpy.mean(data['azi'])
1085 self.res_azi = numpy.mean(data['azi'])
1086 if i==0:
1086 if i==0:
1087 print("*****************************************************************************to plot**************************",self.res_weather[i].shape)
1087 print("*****************************************************************************to plot**************************",self.res_weather[i].shape)
1088 self.zmin = self.zmin if self.zmin else 20
1088 self.zmin = self.zmin if self.zmin else 20
1089 self.zmax = self.zmax if self.zmax else 80
1089 self.zmax = self.zmax if self.zmax else 80
1090 if ax.firsttime:
1090 if ax.firsttime:
1091 #plt.clf()
1091 #plt.clf()
1092 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj=cg,vmin=self.zmin, vmax=self.zmax)
1092 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj=cg,vmin=self.zmin, vmax=self.zmax)
1093 #fig=self.figures[0]
1093 #fig=self.figures[0]
1094 else:
1094 else:
1095 #plt.clf()
1095 #plt.clf()
1096 if i==0:
1096 if i==0:
1097 print(self.res_weather[i])
1097 print(self.res_weather[i])
1098 print(self.res_ele)
1098 print(self.res_ele)
1099 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj=cg,vmin=self.zmin, vmax=self.zmax)
1099 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj=cg,vmin=self.zmin, vmax=self.zmax)
1100 caax = cgax.parasites[0]
1100 caax = cgax.parasites[0]
1101 paax = cgax.parasites[1]
1101 paax = cgax.parasites[1]
1102 cbar = plt.gcf().colorbar(pm, pad=0.075)
1102 cbar = plt.gcf().colorbar(pm, pad=0.075)
1103 caax.set_xlabel('x_range [km]')
1103 caax.set_xlabel('x_range [km]')
1104 caax.set_ylabel('y_range [km]')
1104 caax.set_ylabel('y_range [km]')
1105 plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right')
1105 plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right')
1106 print("***************************self.ini****************************",self.ini)
1106 print("***************************self.ini****************************",self.ini)
1107 self.ini= self.ini+1
1107 self.ini= self.ini+1
1108
1108
1109 class Weather_vRF_Plot(Plot):
1109 class Weather_vRF_Plot(Plot):
1110 CODE = 'PPI'
1110 CODE = 'PPI'
1111 plot_name = 'PPI'
1111 plot_name = 'PPI'
1112 #plot_type = 'ppistyle'
1112 #plot_type = 'ppistyle'
1113 buffering = False
1113 buffering = False
1114
1114
1115 def setup(self):
1115 def setup(self):
1116
1116
1117 self.ncols = 1
1117 self.ncols = 1
1118 self.nrows = 1
1118 self.nrows = 1
1119 self.width =8
1119 self.width =8
1120 self.height =8
1120 self.height =8
1121 self.nplots= 1
1121 self.nplots= 1
1122 self.ylabel= 'Range [Km]'
1122 self.ylabel= 'Range [Km]'
1123 self.xlabel= 'Range [Km]'
1123 self.xlabel= 'Range [Km]'
1124 self.titles= ['PPI']
1124 self.titles= ['PPI']
1125 self.polar = True
1125 self.polar = True
1126 if self.channels is not None:
1126 if self.channels is not None:
1127 self.nplots = len(self.channels)
1127 self.nplots = len(self.channels)
1128 self.nrows = len(self.channels)
1128 self.nrows = len(self.channels)
1129 else:
1129 else:
1130 self.nplots = self.data.shape(self.CODE)[0]
1130 self.nplots = self.data.shape(self.CODE)[0]
1131 self.nrows = self.nplots
1131 self.nrows = self.nplots
1132 self.channels = list(range(self.nplots))
1132 self.channels = list(range(self.nplots))
1133
1133
1134 if self.CODE == 'POWER':
1134 if self.CODE == 'POWER':
1135 self.cb_label = r'Power (dB)'
1135 self.cb_label = r'Power (dB)'
1136 elif self.CODE == 'DOPPLER':
1136 elif self.CODE == 'DOPPLER':
1137 self.cb_label = r'Velocity (m/s)'
1137 self.cb_label = r'Velocity (m/s)'
1138 self.colorbar=True
1138 self.colorbar=True
1139 self.width = 9
1139 self.width = 9
1140 self.height =8
1140 self.height =8
1141 self.ini =0
1141 self.ini =0
1142 self.len_azi =0
1142 self.len_azi =0
1143 self.buffer_ini = None
1143 self.buffer_ini = None
1144 self.buffer_ele = None
1144 self.buffer_ele = None
1145 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.15, 'right': 0.9, 'bottom': 0.08})
1145 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.15, 'right': 0.9, 'bottom': 0.08})
1146 self.flag =0
1146 self.flag =0
1147 self.indicador= 0
1147 self.indicador= 0
1148 self.last_data_ele = None
1148 self.last_data_ele = None
1149 self.val_mean = None
1149 self.val_mean = None
1150
1150
1151 def update(self, dataOut):
1151 def update(self, dataOut):
1152
1152
1153 data = {}
1153 data = {}
1154 meta = {}
1154 meta = {}
1155 if hasattr(dataOut, 'dataPP_POWER'):
1155 if hasattr(dataOut, 'dataPP_POWER'):
1156 factor = 1
1156 factor = 1
1157 if hasattr(dataOut, 'nFFTPoints'):
1157 if hasattr(dataOut, 'nFFTPoints'):
1158 factor = dataOut.normFactor
1158 factor = dataOut.normFactor
1159
1159
1160 if 'pow' in self.attr_data[0].lower():
1160 if 'pow' in self.attr_data[0].lower():
1161 data['data'] = 10*numpy.log10(getattr(dataOut, self.attr_data[0])/(factor))
1161 data['data'] = 10*numpy.log10(getattr(dataOut, self.attr_data[0])/(factor))
1162 else:
1162 else:
1163 data['data'] = getattr(dataOut, self.attr_data[0])/(factor)
1163 data['data'] = getattr(dataOut, self.attr_data[0])/(factor)
1164
1164
1165 data['azi'] = dataOut.data_azi
1165 data['azi'] = dataOut.data_azi
1166 data['ele'] = dataOut.data_ele
1166 data['ele'] = dataOut.data_ele
1167
1167
1168 return data, meta
1168 return data, meta
1169
1169
1170 def plot(self):
1170 def plot(self):
1171 data = self.data[-1]
1171 data = self.data[-1]
1172 r = self.data.yrange
1172 r = self.data.yrange
1173 delta_height = r[1]-r[0]
1173 delta_height = r[1]-r[0]
1174 r_mask = numpy.where(r>=0)[0]
1174 r_mask = numpy.where(r>=0)[0]
1175 self.r_mask = r_mask
1175 self.r_mask = r_mask
1176 r = numpy.arange(len(r_mask))*delta_height
1176 r = numpy.arange(len(r_mask))*delta_height
1177 self.y = 2*r
1177 self.y = 2*r
1178
1178
1179 z = data['data'][self.channels[0]][:,r_mask]
1179 z = data['data'][self.channels[0]][:,r_mask]
1180
1180
1181 self.titles = []
1181 self.titles = []
1182
1182
1183 self.ymax = self.ymax if self.ymax else numpy.nanmax(r)
1183 self.ymax = self.ymax if self.ymax else numpy.nanmax(r)
1184 self.ymin = self.ymin if self.ymin else numpy.nanmin(r)
1184 self.ymin = self.ymin if self.ymin else numpy.nanmin(r)
1185 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1185 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1186 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1186 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1187 self.ang_min = self.ang_min if self.ang_min else 0
1187 self.ang_min = self.ang_min if self.ang_min else 0
1188 self.ang_max = self.ang_max if self.ang_max else 360
1188 self.ang_max = self.ang_max if self.ang_max else 360
1189
1189
1190 r, theta = numpy.meshgrid(r, numpy.radians(data['azi']) )
1190 r, theta = numpy.meshgrid(r, numpy.radians(data['azi']) )
1191
1191
1192 for i,ax in enumerate(self.axes):
1192 for i,ax in enumerate(self.axes):
1193
1193
1194 if ax.firsttime:
1194 if ax.firsttime:
1195 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1195 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1196 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1196 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1197
1197
1198 else:
1198 else:
1199 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1199 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1200 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1200 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1201
1201
1202 ax.grid(True)
1202 ax.grid(True)
1203
1203
1204 if len(self.channels) !=1:
1204 if len(self.channels) !=1:
1205 self.titles = ['PPI {} at EL: {} Channel {}'.format(self.self.labels[x], str(round(numpy.mean(data['ele']),1)), x) for x in range(self.nrows)]
1205 self.titles = ['PPI {} at EL: {} Channel {}'.format(self.self.labels[x], str(round(numpy.mean(data['ele']),1)), x) for x in range(self.nrows)]
1206 else:
1206 else:
1207 self.titles = ['PPI {} at EL: {} Channel {}'.format(self.labels[0], str(round(numpy.mean(data['ele']),1)), self.channels[0])]
1207 self.titles = ['PPI {} at EL: {} Channel {}'.format(self.labels[0], str(round(numpy.mean(data['ele']),1)), self.channels[0])]
1208
1208
1209 class WeatherRHI_vRF2_Plot(Plot):
1209 class WeatherRHI_vRF2_Plot(Plot):
1210 CODE = 'weather'
1210 CODE = 'weather'
1211 plot_name = 'weather'
1211 plot_name = 'weather'
1212 plot_type = 'rhistyle'
1212 plot_type = 'rhistyle'
1213 buffering = False
1213 buffering = False
1214 data_ele_tmp = None
1214 data_ele_tmp = None
1215
1215
1216 def setup(self):
1216 def setup(self):
1217 print("********************")
1217 print("********************")
1218 print("********************")
1218 print("********************")
1219 print("********************")
1219 print("********************")
1220 print("SETUP WEATHER PLOT")
1220 print("SETUP WEATHER PLOT")
1221 self.ncols = 1
1221 self.ncols = 1
1222 self.nrows = 1
1222 self.nrows = 1
1223 self.nplots= 1
1223 self.nplots= 1
1224 self.ylabel= 'Range [Km]'
1224 self.ylabel= 'Range [Km]'
1225 self.titles= ['Weather']
1225 self.titles= ['Weather']
1226 if self.channels is not None:
1226 if self.channels is not None:
1227 self.nplots = len(self.channels)
1227 self.nplots = len(self.channels)
1228 self.nrows = len(self.channels)
1228 self.nrows = len(self.channels)
1229 else:
1229 else:
1230 self.nplots = self.data.shape(self.CODE)[0]
1230 self.nplots = self.data.shape(self.CODE)[0]
1231 self.nrows = self.nplots
1231 self.nrows = self.nplots
1232 self.channels = list(range(self.nplots))
1232 self.channels = list(range(self.nplots))
1233 print("channels",self.channels)
1233 print("channels",self.channels)
1234 print("que saldra", self.data.shape(self.CODE)[0])
1234 print("que saldra", self.data.shape(self.CODE)[0])
1235 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
1235 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
1236 print("self.titles",self.titles)
1236 print("self.titles",self.titles)
1237 self.colorbar=False
1237 self.colorbar=False
1238 self.width =8
1238 self.width =8
1239 self.height =8
1239 self.height =8
1240 self.ini =0
1240 self.ini =0
1241 self.len_azi =0
1241 self.len_azi =0
1242 self.buffer_ini = None
1242 self.buffer_ini = None
1243 self.buffer_ele = None
1243 self.buffer_ele = None
1244 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
1244 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
1245 self.flag =0
1245 self.flag =0
1246 self.indicador= 0
1246 self.indicador= 0
1247 self.last_data_ele = None
1247 self.last_data_ele = None
1248 self.val_mean = None
1248 self.val_mean = None
1249
1249
1250 def update(self, dataOut):
1250 def update(self, dataOut):
1251
1251
1252 data = {}
1252 data = {}
1253 meta = {}
1253 meta = {}
1254 if hasattr(dataOut, 'dataPP_POWER'):
1254 if hasattr(dataOut, 'dataPP_POWER'):
1255 factor = 1
1255 factor = 1
1256 if hasattr(dataOut, 'nFFTPoints'):
1256 if hasattr(dataOut, 'nFFTPoints'):
1257 factor = dataOut.normFactor
1257 factor = dataOut.normFactor
1258 print("dataOut",dataOut.data_360.shape)
1258 print("dataOut",dataOut.data_360.shape)
1259 #
1259 #
1260 data['weather'] = 10*numpy.log10(dataOut.data_360/(factor))
1260 data['weather'] = 10*numpy.log10(dataOut.data_360/(factor))
1261 #
1261 #
1262 #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor))
1262 #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor))
1263 data['azi'] = dataOut.data_azi
1263 data['azi'] = dataOut.data_azi
1264 data['ele'] = dataOut.data_ele
1264 data['ele'] = dataOut.data_ele
1265 data['case_flag'] = dataOut.case_flag
1265 data['case_flag'] = dataOut.case_flag
1266 #print("UPDATE")
1266 #print("UPDATE")
1267 #print("data[weather]",data['weather'].shape)
1267 #print("data[weather]",data['weather'].shape)
1268 #print("data[azi]",data['azi'])
1268 #print("data[azi]",data['azi'])
1269 return data, meta
1269 return data, meta
1270
1270
1271 def get2List(self,angulos):
1271 def get2List(self,angulos):
1272 list1=[]
1272 list1=[]
1273 list2=[]
1273 list2=[]
1274 for i in reversed(range(len(angulos))):
1274 for i in reversed(range(len(angulos))):
1275 if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante
1275 if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante
1276 diff_ = angulos[i]-angulos[i-1]
1276 diff_ = angulos[i]-angulos[i-1]
1277 if abs(diff_) >1.5:
1277 if abs(diff_) >1.5:
1278 list1.append(i-1)
1278 list1.append(i-1)
1279 list2.append(diff_)
1279 list2.append(diff_)
1280 return list(reversed(list1)),list(reversed(list2))
1280 return list(reversed(list1)),list(reversed(list2))
1281
1281
1282 def fixData90(self,list_,ang_):
1282 def fixData90(self,list_,ang_):
1283 if list_[0]==-1:
1283 if list_[0]==-1:
1284 vec = numpy.where(ang_<ang_[0])
1284 vec = numpy.where(ang_<ang_[0])
1285 ang_[vec] = ang_[vec]+90
1285 ang_[vec] = ang_[vec]+90
1286 return ang_
1286 return ang_
1287 return ang_
1287 return ang_
1288
1288
1289 def fixData90HL(self,angulos):
1289 def fixData90HL(self,angulos):
1290 vec = numpy.where(angulos>=90)
1290 vec = numpy.where(angulos>=90)
1291 angulos[vec]=angulos[vec]-90
1291 angulos[vec]=angulos[vec]-90
1292 return angulos
1292 return angulos
1293
1293
1294
1294
1295 def search_pos(self,pos,list_):
1295 def search_pos(self,pos,list_):
1296 for i in range(len(list_)):
1296 for i in range(len(list_)):
1297 if pos == list_[i]:
1297 if pos == list_[i]:
1298 return True,i
1298 return True,i
1299 i=None
1299 i=None
1300 return False,i
1300 return False,i
1301
1301
1302 def fixDataComp(self,ang_,list1_,list2_,tipo_case):
1302 def fixDataComp(self,ang_,list1_,list2_,tipo_case):
1303 size = len(ang_)
1303 size = len(ang_)
1304 size2 = 0
1304 size2 = 0
1305 for i in range(len(list2_)):
1305 for i in range(len(list2_)):
1306 size2=size2+round(abs(list2_[i]))-1
1306 size2=size2+round(abs(list2_[i]))-1
1307 new_size= size+size2
1307 new_size= size+size2
1308 ang_new = numpy.zeros(new_size)
1308 ang_new = numpy.zeros(new_size)
1309 ang_new2 = numpy.zeros(new_size)
1309 ang_new2 = numpy.zeros(new_size)
1310
1310
1311 tmp = 0
1311 tmp = 0
1312 c = 0
1312 c = 0
1313 for i in range(len(ang_)):
1313 for i in range(len(ang_)):
1314 ang_new[tmp +c] = ang_[i]
1314 ang_new[tmp +c] = ang_[i]
1315 ang_new2[tmp+c] = ang_[i]
1315 ang_new2[tmp+c] = ang_[i]
1316 condition , value = self.search_pos(i,list1_)
1316 condition , value = self.search_pos(i,list1_)
1317 if condition:
1317 if condition:
1318 pos = tmp + c + 1
1318 pos = tmp + c + 1
1319 for k in range(round(abs(list2_[value]))-1):
1319 for k in range(round(abs(list2_[value]))-1):
1320 if tipo_case==0 or tipo_case==3:#subida
1320 if tipo_case==0 or tipo_case==3:#subida
1321 ang_new[pos+k] = ang_new[pos+k-1]+1
1321 ang_new[pos+k] = ang_new[pos+k-1]+1
1322 ang_new2[pos+k] = numpy.nan
1322 ang_new2[pos+k] = numpy.nan
1323 elif tipo_case==1 or tipo_case==2:#bajada
1323 elif tipo_case==1 or tipo_case==2:#bajada
1324 ang_new[pos+k] = ang_new[pos+k-1]-1
1324 ang_new[pos+k] = ang_new[pos+k-1]-1
1325 ang_new2[pos+k] = numpy.nan
1325 ang_new2[pos+k] = numpy.nan
1326
1326
1327 tmp = pos +k
1327 tmp = pos +k
1328 c = 0
1328 c = 0
1329 c=c+1
1329 c=c+1
1330 return ang_new,ang_new2
1330 return ang_new,ang_new2
1331
1331
1332 def globalCheckPED(self,angulos,tipo_case):
1332 def globalCheckPED(self,angulos,tipo_case):
1333 l1,l2 = self.get2List(angulos)
1333 l1,l2 = self.get2List(angulos)
1334 ##print("l1",l1)
1334 ##print("l1",l1)
1335 ##print("l2",l2)
1335 ##print("l2",l2)
1336 if len(l1)>0:
1336 if len(l1)>0:
1337 #angulos2 = self.fixData90(list_=l1,ang_=angulos)
1337 #angulos2 = self.fixData90(list_=l1,ang_=angulos)
1338 #l1,l2 = self.get2List(angulos2)
1338 #l1,l2 = self.get2List(angulos2)
1339 ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case)
1339 ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case)
1340 #ang1_ = self.fixData90HL(ang1_)
1340 #ang1_ = self.fixData90HL(ang1_)
1341 #ang2_ = self.fixData90HL(ang2_)
1341 #ang2_ = self.fixData90HL(ang2_)
1342 else:
1342 else:
1343 ang1_= angulos
1343 ang1_= angulos
1344 ang2_= angulos
1344 ang2_= angulos
1345 return ang1_,ang2_
1345 return ang1_,ang2_
1346
1346
1347
1347
1348 def replaceNAN(self,data_weather,data_ele,val):
1348 def replaceNAN(self,data_weather,data_ele,val):
1349 data= data_ele
1349 data= data_ele
1350 data_T= data_weather
1350 data_T= data_weather
1351 if data.shape[0]> data_T.shape[0]:
1351 if data.shape[0]> data_T.shape[0]:
1352 data_N = numpy.ones( [data.shape[0],data_T.shape[1]])
1352 data_N = numpy.ones( [data.shape[0],data_T.shape[1]])
1353 c = 0
1353 c = 0
1354 for i in range(len(data)):
1354 for i in range(len(data)):
1355 if numpy.isnan(data[i]):
1355 if numpy.isnan(data[i]):
1356 data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
1356 data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
1357 else:
1357 else:
1358 data_N[i,:]=data_T[c,:]
1358 data_N[i,:]=data_T[c,:]
1359 c=c+1
1359 c=c+1
1360 return data_N
1360 return data_N
1361 else:
1361 else:
1362 for i in range(len(data)):
1362 for i in range(len(data)):
1363 if numpy.isnan(data[i]):
1363 if numpy.isnan(data[i]):
1364 data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
1364 data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan
1365 return data_T
1365 return data_T
1366
1366
1367 def check_case(self,data_ele,ang_max,ang_min):
1367 def check_case(self,data_ele,ang_max,ang_min):
1368 start = data_ele[0]
1368 start = data_ele[0]
1369 end = data_ele[-1]
1369 end = data_ele[-1]
1370 number = (end-start)
1370 number = (end-start)
1371 len_ang=len(data_ele)
1371 len_ang=len(data_ele)
1372 print("start",start)
1372 print("start",start)
1373 print("end",end)
1373 print("end",end)
1374 print("number",number)
1374 print("number",number)
1375
1375
1376 print("len_ang",len_ang)
1376 print("len_ang",len_ang)
1377
1377
1378 #exit(1)
1378 #exit(1)
1379
1379
1380 if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida
1380 if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida
1381 return 0
1381 return 0
1382 #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada
1382 #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada
1383 # return 1
1383 # return 1
1384 elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada
1384 elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada
1385 return 1
1385 return 1
1386 elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX
1386 elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX
1387 return 2
1387 return 2
1388 elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN
1388 elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN
1389 return 3
1389 return 3
1390
1390
1391
1391
1392 def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag):
1392 def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag):
1393 ang_max= ang_max
1393 ang_max= ang_max
1394 ang_min= ang_min
1394 ang_min= ang_min
1395 data_weather=data_weather
1395 data_weather=data_weather
1396 val_ch=val_ch
1396 val_ch=val_ch
1397 ##print("*********************DATA WEATHER**************************************")
1397 ##print("*********************DATA WEATHER**************************************")
1398 ##print(data_weather)
1398 ##print(data_weather)
1399 if self.ini==0:
1399 if self.ini==0:
1400 '''
1400 '''
1401 print("**********************************************")
1401 print("**********************************************")
1402 print("**********************************************")
1402 print("**********************************************")
1403 print("***************ini**************")
1403 print("***************ini**************")
1404 print("**********************************************")
1404 print("**********************************************")
1405 print("**********************************************")
1405 print("**********************************************")
1406 '''
1406 '''
1407 #print("data_ele",data_ele)
1407 #print("data_ele",data_ele)
1408 #----------------------------------------------------------
1408 #----------------------------------------------------------
1409 tipo_case = case_flag[-1]
1409 tipo_case = case_flag[-1]
1410 #tipo_case = self.check_case(data_ele,ang_max,ang_min)
1410 #tipo_case = self.check_case(data_ele,ang_max,ang_min)
1411 print("check_case",tipo_case)
1411 print("check_case",tipo_case)
1412 #exit(1)
1412 #exit(1)
1413 #--------------------- new -------------------------
1413 #--------------------- new -------------------------
1414 data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case)
1414 data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case)
1415
1415
1416 #-------------------------CAMBIOS RHI---------------------------------
1416 #-------------------------CAMBIOS RHI---------------------------------
1417 start= ang_min
1417 start= ang_min
1418 end = ang_max
1418 end = ang_max
1419 n= (ang_max-ang_min)/res
1419 n= (ang_max-ang_min)/res
1420 #------ new
1420 #------ new
1421 self.start_data_ele = data_ele_new[0]
1421 self.start_data_ele = data_ele_new[0]
1422 self.end_data_ele = data_ele_new[-1]
1422 self.end_data_ele = data_ele_new[-1]
1423 if tipo_case==0 or tipo_case==3: # SUBIDA
1423 if tipo_case==0 or tipo_case==3: # SUBIDA
1424 n1= round(self.start_data_ele)- start
1424 n1= round(self.start_data_ele)- start
1425 n2= end - round(self.end_data_ele)
1425 n2= end - round(self.end_data_ele)
1426 print(self.start_data_ele)
1426 print(self.start_data_ele)
1427 print(self.end_data_ele)
1427 print(self.end_data_ele)
1428 if n1>0:
1428 if n1>0:
1429 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
1429 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
1430 ele1_nan= numpy.ones(n1)*numpy.nan
1430 ele1_nan= numpy.ones(n1)*numpy.nan
1431 data_ele = numpy.hstack((ele1,data_ele_new))
1431 data_ele = numpy.hstack((ele1,data_ele_new))
1432 print("ele1_nan",ele1_nan.shape)
1432 print("ele1_nan",ele1_nan.shape)
1433 print("data_ele_old",data_ele_old.shape)
1433 print("data_ele_old",data_ele_old.shape)
1434 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
1434 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
1435 if n2>0:
1435 if n2>0:
1436 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
1436 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
1437 ele2_nan= numpy.ones(n2)*numpy.nan
1437 ele2_nan= numpy.ones(n2)*numpy.nan
1438 data_ele = numpy.hstack((data_ele,ele2))
1438 data_ele = numpy.hstack((data_ele,ele2))
1439 print("ele2_nan",ele2_nan.shape)
1439 print("ele2_nan",ele2_nan.shape)
1440 print("data_ele_old",data_ele_old.shape)
1440 print("data_ele_old",data_ele_old.shape)
1441 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1441 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1442
1442
1443 if tipo_case==1 or tipo_case==2: # BAJADA
1443 if tipo_case==1 or tipo_case==2: # BAJADA
1444 data_ele_new = data_ele_new[::-1] # reversa
1444 data_ele_new = data_ele_new[::-1] # reversa
1445 data_ele_old = data_ele_old[::-1]# reversa
1445 data_ele_old = data_ele_old[::-1]# reversa
1446 data_weather = data_weather[::-1,:]# reversa
1446 data_weather = data_weather[::-1,:]# reversa
1447 vec= numpy.where(data_ele_new<ang_max)
1447 vec= numpy.where(data_ele_new<ang_max)
1448 data_ele_new = data_ele_new[vec]
1448 data_ele_new = data_ele_new[vec]
1449 data_ele_old = data_ele_old[vec]
1449 data_ele_old = data_ele_old[vec]
1450 data_weather = data_weather[vec[0]]
1450 data_weather = data_weather[vec[0]]
1451 vec2= numpy.where(0<data_ele_new)
1451 vec2= numpy.where(0<data_ele_new)
1452 data_ele_new = data_ele_new[vec2]
1452 data_ele_new = data_ele_new[vec2]
1453 data_ele_old = data_ele_old[vec2]
1453 data_ele_old = data_ele_old[vec2]
1454 data_weather = data_weather[vec2[0]]
1454 data_weather = data_weather[vec2[0]]
1455 self.start_data_ele = data_ele_new[0]
1455 self.start_data_ele = data_ele_new[0]
1456 self.end_data_ele = data_ele_new[-1]
1456 self.end_data_ele = data_ele_new[-1]
1457
1457
1458 n1= round(self.start_data_ele)- start
1458 n1= round(self.start_data_ele)- start
1459 n2= end - round(self.end_data_ele)-1
1459 n2= end - round(self.end_data_ele)-1
1460 print(self.start_data_ele)
1460 print(self.start_data_ele)
1461 print(self.end_data_ele)
1461 print(self.end_data_ele)
1462 if n1>0:
1462 if n1>0:
1463 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
1463 ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1)
1464 ele1_nan= numpy.ones(n1)*numpy.nan
1464 ele1_nan= numpy.ones(n1)*numpy.nan
1465 data_ele = numpy.hstack((ele1,data_ele_new))
1465 data_ele = numpy.hstack((ele1,data_ele_new))
1466 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
1466 data_ele_old = numpy.hstack((ele1_nan,data_ele_old))
1467 if n2>0:
1467 if n2>0:
1468 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
1468 ele2= numpy.linspace(self.end_data_ele+1,end,n2)
1469 ele2_nan= numpy.ones(n2)*numpy.nan
1469 ele2_nan= numpy.ones(n2)*numpy.nan
1470 data_ele = numpy.hstack((data_ele,ele2))
1470 data_ele = numpy.hstack((data_ele,ele2))
1471 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1471 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1472 # RADAR
1472 # RADAR
1473 # NOTA data_ele y data_weather es la variable que retorna
1473 # NOTA data_ele y data_weather es la variable que retorna
1474 val_mean = numpy.mean(data_weather[:,-1])
1474 val_mean = numpy.mean(data_weather[:,-1])
1475 self.val_mean = val_mean
1475 self.val_mean = val_mean
1476 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1476 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1477 print("eleold",data_ele_old)
1477 print("eleold",data_ele_old)
1478 print(self.data_ele_tmp[val_ch])
1478 print(self.data_ele_tmp[val_ch])
1479 print(data_ele_old.shape[0])
1479 print(data_ele_old.shape[0])
1480 print(self.data_ele_tmp[val_ch].shape[0])
1480 print(self.data_ele_tmp[val_ch].shape[0])
1481 if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91):
1481 if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91):
1482 import sys
1482 import sys
1483 print("EXIT",self.ini)
1483 print("EXIT",self.ini)
1484
1484
1485 sys.exit(1)
1485 sys.exit(1)
1486 self.data_ele_tmp[val_ch]= data_ele_old
1486 self.data_ele_tmp[val_ch]= data_ele_old
1487 else:
1487 else:
1488 #print("**********************************************")
1488 #print("**********************************************")
1489 #print("****************VARIABLE**********************")
1489 #print("****************VARIABLE**********************")
1490 #-------------------------CAMBIOS RHI---------------------------------
1490 #-------------------------CAMBIOS RHI---------------------------------
1491 #---------------------------------------------------------------------
1491 #---------------------------------------------------------------------
1492 ##print("INPUT data_ele",data_ele)
1492 ##print("INPUT data_ele",data_ele)
1493 flag=0
1493 flag=0
1494 start_ele = self.res_ele[0]
1494 start_ele = self.res_ele[0]
1495 #tipo_case = self.check_case(data_ele,ang_max,ang_min)
1495 #tipo_case = self.check_case(data_ele,ang_max,ang_min)
1496 tipo_case = case_flag[-1]
1496 tipo_case = case_flag[-1]
1497 #print("TIPO DE DATA",tipo_case)
1497 #print("TIPO DE DATA",tipo_case)
1498 #-----------new------------
1498 #-----------new------------
1499 data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case)
1499 data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case)
1500 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1500 data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1501
1501
1502 #-------------------------------NEW RHI ITERATIVO-------------------------
1502 #-------------------------------NEW RHI ITERATIVO-------------------------
1503
1503
1504 if tipo_case==0 : # SUBIDA
1504 if tipo_case==0 : # SUBIDA
1505 vec = numpy.where(data_ele<ang_max)
1505 vec = numpy.where(data_ele<ang_max)
1506 data_ele = data_ele[vec]
1506 data_ele = data_ele[vec]
1507 data_ele_old = data_ele_old[vec]
1507 data_ele_old = data_ele_old[vec]
1508 data_weather = data_weather[vec[0]]
1508 data_weather = data_weather[vec[0]]
1509
1509
1510 vec2 = numpy.where(0<data_ele)
1510 vec2 = numpy.where(0<data_ele)
1511 data_ele= data_ele[vec2]
1511 data_ele= data_ele[vec2]
1512 data_ele_old= data_ele_old[vec2]
1512 data_ele_old= data_ele_old[vec2]
1513 ##print(data_ele_new)
1513 ##print(data_ele_new)
1514 data_weather= data_weather[vec2[0]]
1514 data_weather= data_weather[vec2[0]]
1515
1515
1516 new_i_ele = int(round(data_ele[0]))
1516 new_i_ele = int(round(data_ele[0]))
1517 new_f_ele = int(round(data_ele[-1]))
1517 new_f_ele = int(round(data_ele[-1]))
1518 #print(new_i_ele)
1518 #print(new_i_ele)
1519 #print(new_f_ele)
1519 #print(new_f_ele)
1520 #print(data_ele,len(data_ele))
1520 #print(data_ele,len(data_ele))
1521 #print(data_ele_old,len(data_ele_old))
1521 #print(data_ele_old,len(data_ele_old))
1522 if new_i_ele< 2:
1522 if new_i_ele< 2:
1523 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
1523 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
1524 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
1524 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
1525 self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old
1525 self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old
1526 self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele
1526 self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele
1527 self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather
1527 self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather
1528 data_ele = self.res_ele
1528 data_ele = self.res_ele
1529 data_weather = self.res_weather[val_ch]
1529 data_weather = self.res_weather[val_ch]
1530
1530
1531 elif tipo_case==1 : #BAJADA
1531 elif tipo_case==1 : #BAJADA
1532 data_ele = data_ele[::-1] # reversa
1532 data_ele = data_ele[::-1] # reversa
1533 data_ele_old = data_ele_old[::-1]# reversa
1533 data_ele_old = data_ele_old[::-1]# reversa
1534 data_weather = data_weather[::-1,:]# reversa
1534 data_weather = data_weather[::-1,:]# reversa
1535 vec= numpy.where(data_ele<ang_max)
1535 vec= numpy.where(data_ele<ang_max)
1536 data_ele = data_ele[vec]
1536 data_ele = data_ele[vec]
1537 data_ele_old = data_ele_old[vec]
1537 data_ele_old = data_ele_old[vec]
1538 data_weather = data_weather[vec[0]]
1538 data_weather = data_weather[vec[0]]
1539 vec2= numpy.where(0<data_ele)
1539 vec2= numpy.where(0<data_ele)
1540 data_ele = data_ele[vec2]
1540 data_ele = data_ele[vec2]
1541 data_ele_old = data_ele_old[vec2]
1541 data_ele_old = data_ele_old[vec2]
1542 data_weather = data_weather[vec2[0]]
1542 data_weather = data_weather[vec2[0]]
1543
1543
1544
1544
1545 new_i_ele = int(round(data_ele[0]))
1545 new_i_ele = int(round(data_ele[0]))
1546 new_f_ele = int(round(data_ele[-1]))
1546 new_f_ele = int(round(data_ele[-1]))
1547 #print(data_ele)
1547 #print(data_ele)
1548 #print(ang_max)
1548 #print(ang_max)
1549 #print(data_ele_old)
1549 #print(data_ele_old)
1550 if new_i_ele <= 1:
1550 if new_i_ele <= 1:
1551 new_i_ele = 1
1551 new_i_ele = 1
1552 if round(data_ele[-1])>=ang_max-1:
1552 if round(data_ele[-1])>=ang_max-1:
1553 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
1553 self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan
1554 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
1554 self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean)
1555 self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old
1555 self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old
1556 self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele
1556 self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele
1557 self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather
1557 self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather
1558 data_ele = self.res_ele
1558 data_ele = self.res_ele
1559 data_weather = self.res_weather[val_ch]
1559 data_weather = self.res_weather[val_ch]
1560
1560
1561 elif tipo_case==2: #bajada
1561 elif tipo_case==2: #bajada
1562 vec = numpy.where(data_ele<ang_max)
1562 vec = numpy.where(data_ele<ang_max)
1563 data_ele = data_ele[vec]
1563 data_ele = data_ele[vec]
1564 data_weather= data_weather[vec[0]]
1564 data_weather= data_weather[vec[0]]
1565
1565
1566 len_vec = len(vec)
1566 len_vec = len(vec)
1567 data_ele_new = data_ele[::-1] # reversa
1567 data_ele_new = data_ele[::-1] # reversa
1568 data_weather = data_weather[::-1,:]
1568 data_weather = data_weather[::-1,:]
1569 new_i_ele = int(data_ele_new[0])
1569 new_i_ele = int(data_ele_new[0])
1570 new_f_ele = int(data_ele_new[-1])
1570 new_f_ele = int(data_ele_new[-1])
1571
1571
1572 n1= new_i_ele- ang_min
1572 n1= new_i_ele- ang_min
1573 n2= ang_max - new_f_ele-1
1573 n2= ang_max - new_f_ele-1
1574 if n1>0:
1574 if n1>0:
1575 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
1575 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
1576 ele1_nan= numpy.ones(n1)*numpy.nan
1576 ele1_nan= numpy.ones(n1)*numpy.nan
1577 data_ele = numpy.hstack((ele1,data_ele_new))
1577 data_ele = numpy.hstack((ele1,data_ele_new))
1578 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
1578 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
1579 if n2>0:
1579 if n2>0:
1580 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1580 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1581 ele2_nan= numpy.ones(n2)*numpy.nan
1581 ele2_nan= numpy.ones(n2)*numpy.nan
1582 data_ele = numpy.hstack((data_ele,ele2))
1582 data_ele = numpy.hstack((data_ele,ele2))
1583 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1583 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1584
1584
1585 self.data_ele_tmp[val_ch] = data_ele_old
1585 self.data_ele_tmp[val_ch] = data_ele_old
1586 self.res_ele = data_ele
1586 self.res_ele = data_ele
1587 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1587 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1588 data_ele = self.res_ele
1588 data_ele = self.res_ele
1589 data_weather = self.res_weather[val_ch]
1589 data_weather = self.res_weather[val_ch]
1590
1590
1591 elif tipo_case==3:#subida
1591 elif tipo_case==3:#subida
1592 vec = numpy.where(0<data_ele)
1592 vec = numpy.where(0<data_ele)
1593 data_ele= data_ele[vec]
1593 data_ele= data_ele[vec]
1594 data_ele_new = data_ele
1594 data_ele_new = data_ele
1595 data_ele_old= data_ele_old[vec]
1595 data_ele_old= data_ele_old[vec]
1596 data_weather= data_weather[vec[0]]
1596 data_weather= data_weather[vec[0]]
1597 pos_ini = numpy.argmin(data_ele)
1597 pos_ini = numpy.argmin(data_ele)
1598 if pos_ini>0:
1598 if pos_ini>0:
1599 len_vec= len(data_ele)
1599 len_vec= len(data_ele)
1600 vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int)
1600 vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int)
1601 #print(vec3)
1601 #print(vec3)
1602 data_ele= data_ele[vec3]
1602 data_ele= data_ele[vec3]
1603 data_ele_new = data_ele
1603 data_ele_new = data_ele
1604 data_ele_old= data_ele_old[vec3]
1604 data_ele_old= data_ele_old[vec3]
1605 data_weather= data_weather[vec3]
1605 data_weather= data_weather[vec3]
1606
1606
1607 new_i_ele = int(data_ele_new[0])
1607 new_i_ele = int(data_ele_new[0])
1608 new_f_ele = int(data_ele_new[-1])
1608 new_f_ele = int(data_ele_new[-1])
1609 n1= new_i_ele- ang_min
1609 n1= new_i_ele- ang_min
1610 n2= ang_max - new_f_ele-1
1610 n2= ang_max - new_f_ele-1
1611 if n1>0:
1611 if n1>0:
1612 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
1612 ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1)
1613 ele1_nan= numpy.ones(n1)*numpy.nan
1613 ele1_nan= numpy.ones(n1)*numpy.nan
1614 data_ele = numpy.hstack((ele1,data_ele_new))
1614 data_ele = numpy.hstack((ele1,data_ele_new))
1615 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
1615 data_ele_old = numpy.hstack((ele1_nan,data_ele_new))
1616 if n2>0:
1616 if n2>0:
1617 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1617 ele2= numpy.linspace(new_f_ele+1,ang_max,n2)
1618 ele2_nan= numpy.ones(n2)*numpy.nan
1618 ele2_nan= numpy.ones(n2)*numpy.nan
1619 data_ele = numpy.hstack((data_ele,ele2))
1619 data_ele = numpy.hstack((data_ele,ele2))
1620 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1620 data_ele_old = numpy.hstack((data_ele_old,ele2_nan))
1621
1621
1622 self.data_ele_tmp[val_ch] = data_ele_old
1622 self.data_ele_tmp[val_ch] = data_ele_old
1623 self.res_ele = data_ele
1623 self.res_ele = data_ele
1624 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1624 self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean)
1625 data_ele = self.res_ele
1625 data_ele = self.res_ele
1626 data_weather = self.res_weather[val_ch]
1626 data_weather = self.res_weather[val_ch]
1627 #print("self.data_ele_tmp",self.data_ele_tmp)
1627 #print("self.data_ele_tmp",self.data_ele_tmp)
1628 return data_weather,data_ele
1628 return data_weather,data_ele
1629
1629
1630
1630
1631 def plot(self):
1631 def plot(self):
1632 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S')
1632 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S')
1633 data = self.data[-1]
1633 data = self.data[-1]
1634 r = self.data.yrange
1634 r = self.data.yrange
1635 delta_height = r[1]-r[0]
1635 delta_height = r[1]-r[0]
1636 r_mask = numpy.where(r>=0)[0]
1636 r_mask = numpy.where(r>=0)[0]
1637 ##print("delta_height",delta_height)
1637 ##print("delta_height",delta_height)
1638 #print("r_mask",r_mask,len(r_mask))
1638 #print("r_mask",r_mask,len(r_mask))
1639 r = numpy.arange(len(r_mask))*delta_height
1639 r = numpy.arange(len(r_mask))*delta_height
1640 self.y = 2*r
1640 self.y = 2*r
1641 res = 1
1641 res = 1
1642 ###print("data['weather'].shape[0]",data['weather'].shape[0])
1642 ###print("data['weather'].shape[0]",data['weather'].shape[0])
1643 ang_max = self.ang_max
1643 ang_max = self.ang_max
1644 ang_min = self.ang_min
1644 ang_min = self.ang_min
1645 var_ang =ang_max - ang_min
1645 var_ang =ang_max - ang_min
1646 step = (int(var_ang)/(res*data['weather'].shape[0]))
1646 step = (int(var_ang)/(res*data['weather'].shape[0]))
1647 ###print("step",step)
1647 ###print("step",step)
1648 #--------------------------------------------------------
1648 #--------------------------------------------------------
1649 ##print('weather',data['weather'].shape)
1649 ##print('weather',data['weather'].shape)
1650 ##print('ele',data['ele'].shape)
1650 ##print('ele',data['ele'].shape)
1651
1651
1652 ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min)
1652 ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min)
1653 ###self.res_azi = numpy.mean(data['azi'])
1653 ###self.res_azi = numpy.mean(data['azi'])
1654 ###print("self.res_ele",self.res_ele)
1654 ###print("self.res_ele",self.res_ele)
1655 plt.clf()
1655 plt.clf()
1656 subplots = [121, 122]
1656 subplots = [121, 122]
1657 try:
1657 try:
1658 if self.data[-2]['ele'].max()<data['ele'].max():
1658 if self.data[-2]['ele'].max()<data['ele'].max():
1659 self.ini=0
1659 self.ini=0
1660 except:
1660 except:
1661 pass
1661 pass
1662 if self.ini==0:
1662 if self.ini==0:
1663 self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan
1663 self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan
1664 self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan
1664 self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan
1665 print("SHAPE",self.data_ele_tmp.shape)
1665 print("SHAPE",self.data_ele_tmp.shape)
1666
1666
1667 for i,ax in enumerate(self.axes):
1667 for i,ax in enumerate(self.axes):
1668 self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag'])
1668 self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag'])
1669 self.res_azi = numpy.mean(data['azi'])
1669 self.res_azi = numpy.mean(data['azi'])
1670
1670
1671 if ax.firsttime:
1671 if ax.firsttime:
1672 #plt.clf()
1672 #plt.clf()
1673 print("Frist Plot")
1673 print("Frist Plot")
1674 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80)
1674 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80)
1675 #fig=self.figures[0]
1675 #fig=self.figures[0]
1676 else:
1676 else:
1677 #plt.clf()
1677 #plt.clf()
1678 print("ELSE PLOT")
1678 print("ELSE PLOT")
1679 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80)
1679 cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80)
1680 caax = cgax.parasites[0]
1680 caax = cgax.parasites[0]
1681 paax = cgax.parasites[1]
1681 paax = cgax.parasites[1]
1682 cbar = plt.gcf().colorbar(pm, pad=0.075)
1682 cbar = plt.gcf().colorbar(pm, pad=0.075)
1683 caax.set_xlabel('x_range [km]')
1683 caax.set_xlabel('x_range [km]')
1684 caax.set_ylabel('y_range [km]')
1684 caax.set_ylabel('y_range [km]')
1685 plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right')
1685 plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right')
1686 print("***************************self.ini****************************",self.ini)
1686 print("***************************self.ini****************************",self.ini)
1687 self.ini= self.ini+1
1687 self.ini= self.ini+1
1688
1688
1689
1689
1690
1690
1691
1691
1692
1692
1693 class WeatherRHI_vRF4_Plot(Plot):
1693 class WeatherRHI_vRF4_Plot(Plot):
1694 CODE = 'RHI'
1694 CODE = 'RHI'
1695 plot_name = 'RHI'
1695 plot_name = 'RHI'
1696 #plot_type = 'rhistyle'
1696 #plot_type = 'rhistyle'
1697 buffering = False
1697 buffering = False
1698
1698
1699 def setup(self):
1699 def setup(self):
1700
1700
1701 self.ncols = 1
1701 self.ncols = 1
1702 self.nrows = 1
1702 self.nrows = 1
1703 self.nplots= 1
1703 self.nplots= 1
1704 self.ylabel= 'Range [Km]'
1704 self.ylabel= 'Range [Km]'
1705 self.xlabel= 'Range [Km]'
1705 self.xlabel= 'Range [Km]'
1706 self.titles= ['RHI']
1706 self.titles= ['RHI']
1707 self.polar = True
1707 self.polar = True
1708 self.grid = True
1708 self.grid = True
1709 if self.channels is not None:
1709 if self.channels is not None:
1710 self.nplots = len(self.channels)
1710 self.nplots = len(self.channels)
1711 self.nrows = len(self.channels)
1711 self.nrows = len(self.channels)
1712 else:
1712 else:
1713 self.nplots = self.data.shape(self.CODE)[0]
1713 self.nplots = self.data.shape(self.CODE)[0]
1714 self.nrows = self.nplots
1714 self.nrows = self.nplots
1715 self.channels = list(range(self.nplots))
1715 self.channels = list(range(self.nplots))
1716
1716
1717 if self.CODE == 'Power':
1717 if self.CODE == 'Power':
1718 self.cb_label = r'Power (dB)'
1718 self.cb_label = r'Power (dB)'
1719 elif self.CODE == 'Doppler':
1719 elif self.CODE == 'Doppler':
1720 self.cb_label = r'Velocity (m/s)'
1720 self.cb_label = r'Velocity (m/s)'
1721 self.colorbar=True
1721 self.colorbar=True
1722 self.width =8
1722 self.width =8
1723 self.height =8
1723 self.height =8
1724 self.ini =0
1724 self.ini =0
1725 self.len_azi =0
1725 self.len_azi =0
1726 self.buffer_ini = None
1726 self.buffer_ini = None
1727 self.buffer_ele = None
1727 self.buffer_ele = None
1728 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
1728 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
1729 self.flag =0
1729 self.flag =0
1730 self.indicador= 0
1730 self.indicador= 0
1731 self.last_data_ele = None
1731 self.last_data_ele = None
1732 self.val_mean = None
1732 self.val_mean = None
1733
1733
1734 def update(self, dataOut):
1734 def update(self, dataOut):
1735
1735
1736 data = {}
1736 data = {}
1737 meta = {}
1737 meta = {}
1738 if hasattr(dataOut, 'dataPP_POWER'):
1738 if hasattr(dataOut, 'dataPP_POWER'):
1739 factor = 1
1739 factor = 1
1740 if hasattr(dataOut, 'nFFTPoints'):
1740 if hasattr(dataOut, 'nFFTPoints'):
1741 factor = dataOut.normFactor
1741 factor = dataOut.normFactor
1742
1742
1743 if 'pow' in self.attr_data[0].lower():
1743 if 'pow' in self.attr_data[0].lower():
1744 data['data'] = 10*numpy.log10(getattr(dataOut, self.attr_data[0])/(factor))
1744 data['data'] = 10*numpy.log10(getattr(dataOut, self.attr_data[0])/(factor))
1745 else:
1745 else:
1746 data['data'] = getattr(dataOut, self.attr_data[0])/(factor)
1746 data['data'] = getattr(dataOut, self.attr_data[0])/(factor)
1747
1747
1748 data['azi'] = dataOut.data_azi
1748 data['azi'] = dataOut.data_azi
1749 data['ele'] = dataOut.data_ele
1749 data['ele'] = dataOut.data_ele
1750
1750
1751 return data, meta
1751 return data, meta
1752
1752
1753 def plot(self):
1753 def plot(self):
1754 data = self.data[-1]
1754 data = self.data[-1]
1755 r = self.data.yrange
1755 r = self.data.yrange
1756 delta_height = r[1]-r[0]
1756 delta_height = r[1]-r[0]
1757 r_mask = numpy.where(r>=0)[0]
1757 r_mask = numpy.where(r>=0)[0]
1758 self.r_mask =r_mask
1758 self.r_mask =r_mask
1759 r = numpy.arange(len(r_mask))*delta_height
1759 r = numpy.arange(len(r_mask))*delta_height
1760 self.y = 2*r
1760 self.y = 2*r
1761
1761
1762 z = data['data'][self.channels[0]][:,r_mask]
1762 z = data['data'][self.channels[0]][:,r_mask]
1763
1763
1764 self.titles = []
1764 self.titles = []
1765
1765
1766 self.ymax = self.ymax if self.ymax else numpy.nanmax(r)
1766 self.ymax = self.ymax if self.ymax else numpy.nanmax(r)
1767 self.ymin = self.ymin if self.ymin else numpy.nanmin(r)
1767 self.ymin = self.ymin if self.ymin else numpy.nanmin(r)
1768 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1768 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1769 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1769 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1770 self.ang_min = self.ang_min if self.ang_min else 0
1770 self.ang_min = self.ang_min if self.ang_min else 0
1771 self.ang_max = self.ang_max if self.ang_max else 90
1771 self.ang_max = self.ang_max if self.ang_max else 90
1772
1772
1773 r, theta = numpy.meshgrid(r, numpy.radians(data['ele']) )
1773 r, theta = numpy.meshgrid(r, numpy.radians(data['ele']) )
1774
1774
1775 for i,ax in enumerate(self.axes):
1775 for i,ax in enumerate(self.axes):
1776
1776
1777 if ax.firsttime:
1777 if ax.firsttime:
1778 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1778 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1779 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1779 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1780
1780
1781 else:
1781 else:
1782 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1782 ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max))
1783 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1783 ax.plt = ax.pcolormesh(theta, r, z, cmap=self.colormap, vmin=self.zmin, vmax=self.zmax)
1784 ax.grid(True)
1784 ax.grid(True)
1785 if len(self.channels) !=1:
1785 if len(self.channels) !=1:
1786 self.titles = ['RHI {} at AZ: {} Channel {}'.format(self.labels[x], str(round(numpy.mean(data['azi']),1)), x) for x in range(self.nrows)]
1786 self.titles = ['RHI {} at AZ: {} Channel {}'.format(self.labels[x], str(round(numpy.mean(data['azi']),1)), x) for x in range(self.nrows)]
1787 else:
1787 else:
1788 self.titles = ['RHI {} at AZ: {} Channel {}'.format(self.labels[0], str(round(numpy.mean(data['azi']),1)), self.channels[0])]
1788 self.titles = ['RHI {} at AZ: {} Channel {}'.format(self.labels[0], str(round(numpy.mean(data['azi']),1)), self.channels[0])]
@@ -1,208 +1,226
1 '''
1 '''
2 Base clases to create Processing units and operations, the MPDecorator
2 Base clases to create Processing units and operations, the MPDecorator
3 must be used in plotting and writing operations to allow to run as an
3 must be used in plotting and writing operations to allow to run as an
4 external process.
4 external process.
5 '''
5 '''
6
6
7 import os
7 import os
8 import inspect
8 import inspect
9 import zmq
9 import zmq
10 import time
10 import time
11 import pickle
11 import pickle
12 import traceback
12 import traceback
13 from threading import Thread
13 from threading import Thread
14 from multiprocessing import Process, Queue
14 from multiprocessing import Process, Queue
15 from schainpy.utils import log
15 from schainpy.utils import log
16
16
17 QUEUE_SIZE = int(os.environ.get('QUEUE_MAX_SIZE', '10'))
17 QUEUE_SIZE = int(os.environ.get('QUEUE_MAX_SIZE', '10'))
18
18
19 class ProcessingUnit(object):
19 class ProcessingUnit(object):
20 '''
20 '''
21 Base class to create Signal Chain Units
21 Base class to create Signal Chain Units
22 '''
22 '''
23
23
24 proc_type = 'processing'
24 proc_type = 'processing'
25
25
26 def __init__(self):
26 def __init__(self):
27
27
28 self.dataIn = None
28 self.dataIn = None
29 self.dataOut = None
29 self.dataOut = None
30 self.isConfig = False
30 self.isConfig = False
31 self.operations = []
31 self.operations = []
32 self.name = 'Test'
33 self.inputs = []
32
34
33 def setInput(self, unit):
35 def setInput(self, unit):
34
36
35 self.dataIn = unit.dataOut
37 attr = 'dataIn'
38 for i, u in enumerate(unit):
39 if i==0:
40 self.dataIn = u.dataOut
41 self.inputs.append('dataIn')
42 else:
43 setattr(self, 'dataIn{}'.format(i), u.dataOut)
44 self.inputs.append('dataIn{}'.format(i))
36
45
37 def getAllowedArgs(self):
46 def getAllowedArgs(self):
38 if hasattr(self, '__attrs__'):
47 if hasattr(self, '__attrs__'):
39 return self.__attrs__
48 return self.__attrs__
40 else:
49 else:
41 return inspect.getargspec(self.run).args
50 return inspect.getargspec(self.run).args
42
51
43 def addOperation(self, conf, operation):
52 def addOperation(self, conf, operation):
44 '''
53 '''
45 '''
54 '''
46
55
47 self.operations.append((operation, conf.type, conf.getKwargs()))
56 self.operations.append((operation, conf.type, conf.getKwargs()))
48
57
49 def getOperationObj(self, objId):
58 def getOperationObj(self, objId):
50
59
51 if objId not in list(self.operations.keys()):
60 if objId not in list(self.operations.keys()):
52 return None
61 return None
53
62
54 return self.operations[objId]
63 return self.operations[objId]
55
64
56 def call(self, **kwargs):
65 def call(self, **kwargs):
57 '''
66 '''
58 '''
67 '''
59
68
60 try:
69 try:
61 if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error:
70 if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error:
62 return self.dataIn.isReady()
71 return self.dataIn.isReady()
63 elif self.dataIn is None or not self.dataIn.error:
72 elif self.dataIn is None or not self.dataIn.error:
64 self.run(**kwargs)
73 self.run(**kwargs)
65 elif self.dataIn.error:
74 elif self.dataIn.error:
66 self.dataOut.error = self.dataIn.error
75 self.dataOut.error = self.dataIn.error
67 self.dataOut.flagNoData = True
76 self.dataOut.flagNoData = True
68 except:
77 except:
69 err = traceback.format_exc()
78 err = traceback.format_exc()
70 if 'SchainWarning' in err:
79 if 'SchainWarning' in err:
71 log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name)
80 log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name)
72 elif 'SchainError' in err:
81 elif 'SchainError' in err:
73 log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), self.name)
82 log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), self.name)
74 else:
83 else:
75 log.error(err, self.name)
84 log.error(err, self.name)
76 self.dataOut.error = True
85 self.dataOut.error = True
77 ##### correcion de la declaracion Out
86 ##### correcion de la declaracion Out
78 for op, optype, opkwargs in self.operations:
87 for op, optype, opkwargs in self.operations:
79 aux = self.dataOut.copy()
88 aux = self.dataOut.copy()
80 if optype == 'other' and not self.dataOut.flagNoData:
89 if optype == 'other' and not self.dataOut.flagNoData:
81 self.dataOut = op.run(self.dataOut, **opkwargs)
90 self.dataOut = op.run(self.dataOut, **opkwargs)
82 elif optype == 'external' and not self.dataOut.flagNoData:
91 elif optype == 'external' and not self.dataOut.flagNoData:
83 #op.queue.put(self.dataOut)
92 #op.queue.put(self.dataOut)
84 op.queue.put(aux)
93 op.queue.put(aux)
85 elif optype == 'external' and self.dataOut.error:
94 elif optype == 'external' and self.dataOut.error:
86 #op.queue.put(self.dataOut)
95 #op.queue.put(self.dataOut)
87 op.queue.put(aux)
96 op.queue.put(aux)
88
97
89 return 'Error' if self.dataOut.error else self.dataOut.isReady()
98 try:
99 if self.dataOut.runNextUnit:
100 runNextUnit = self.dataOut.runNextUnit
101
102 else:
103 runNextUnit = self.dataOut.isReady()
104 except:
105 runNextUnit = self.dataOut.isReady()
106
107 return 'Error' if self.dataOut.error else runNextUnit
90
108
91 def setup(self):
109 def setup(self):
92
110
93 raise NotImplementedError
111 raise NotImplementedError
94
112
95 def run(self):
113 def run(self):
96
114
97 raise NotImplementedError
115 raise NotImplementedError
98
116
99 def close(self):
117 def close(self):
100
118
101 return
119 return
102
120
103
121
104 class Operation(object):
122 class Operation(object):
105
123
106 '''
124 '''
107 '''
125 '''
108
126
109 proc_type = 'operation'
127 proc_type = 'operation'
110
128
111 def __init__(self):
129 def __init__(self):
112
130
113 self.id = None
131 self.id = None
114 self.isConfig = False
132 self.isConfig = False
115
133
116 if not hasattr(self, 'name'):
134 if not hasattr(self, 'name'):
117 self.name = self.__class__.__name__
135 self.name = self.__class__.__name__
118
136
119 def getAllowedArgs(self):
137 def getAllowedArgs(self):
120 if hasattr(self, '__attrs__'):
138 if hasattr(self, '__attrs__'):
121 return self.__attrs__
139 return self.__attrs__
122 else:
140 else:
123 return inspect.getargspec(self.run).args
141 return inspect.getargspec(self.run).args
124
142
125 def setup(self):
143 def setup(self):
126
144
127 self.isConfig = True
145 self.isConfig = True
128
146
129 raise NotImplementedError
147 raise NotImplementedError
130
148
131 def run(self, dataIn, **kwargs):
149 def run(self, dataIn, **kwargs):
132 """
150 """
133 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
151 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
134 atributos del objeto dataIn.
152 atributos del objeto dataIn.
135
153
136 Input:
154 Input:
137
155
138 dataIn : objeto del tipo JROData
156 dataIn : objeto del tipo JROData
139
157
140 Return:
158 Return:
141
159
142 None
160 None
143
161
144 Affected:
162 Affected:
145 __buffer : buffer de recepcion de datos.
163 __buffer : buffer de recepcion de datos.
146
164
147 """
165 """
148 if not self.isConfig:
166 if not self.isConfig:
149 self.setup(**kwargs)
167 self.setup(**kwargs)
150
168
151 raise NotImplementedError
169 raise NotImplementedError
152
170
153 def close(self):
171 def close(self):
154
172
155 return
173 return
156
174
157
175
158 def MPDecorator(BaseClass):
176 def MPDecorator(BaseClass):
159 """
177 """
160 Multiprocessing class decorator
178 Multiprocessing class decorator
161
179
162 This function add multiprocessing features to a BaseClass.
180 This function add multiprocessing features to a BaseClass.
163 """
181 """
164
182
165 class MPClass(BaseClass, Process):
183 class MPClass(BaseClass, Process):
166
184
167 def __init__(self, *args, **kwargs):
185 def __init__(self, *args, **kwargs):
168 super(MPClass, self).__init__()
186 super(MPClass, self).__init__()
169 Process.__init__(self)
187 Process.__init__(self)
170
188
171 self.args = args
189 self.args = args
172 self.kwargs = kwargs
190 self.kwargs = kwargs
173 self.t = time.time()
191 self.t = time.time()
174 self.op_type = 'external'
192 self.op_type = 'external'
175 self.name = BaseClass.__name__
193 self.name = BaseClass.__name__
176 self.__doc__ = BaseClass.__doc__
194 self.__doc__ = BaseClass.__doc__
177
195
178 if 'plot' in self.name.lower() and not self.name.endswith('_'):
196 if 'plot' in self.name.lower() and not self.name.endswith('_'):
179 self.name = '{}{}'.format(self.CODE.upper(), 'Plot')
197 self.name = '{}{}'.format(self.CODE.upper(), 'Plot')
180
198
181 self.start_time = time.time()
199 self.start_time = time.time()
182 self.err_queue = args[3]
200 self.err_queue = args[3]
183 self.queue = Queue(maxsize=QUEUE_SIZE)
201 self.queue = Queue(maxsize=QUEUE_SIZE)
184 self.myrun = BaseClass.run
202 self.myrun = BaseClass.run
185
203
186 def run(self):
204 def run(self):
187
205
188 while True:
206 while True:
189
207
190 dataOut = self.queue.get()
208 dataOut = self.queue.get()
191
209
192 if not dataOut.error:
210 if not dataOut.error:
193 try:
211 try:
194 BaseClass.run(self, dataOut, **self.kwargs)
212 BaseClass.run(self, dataOut, **self.kwargs)
195 except:
213 except:
196 err = traceback.format_exc()
214 err = traceback.format_exc()
197 log.error(err, self.name)
215 log.error(err, self.name)
198 else:
216 else:
199 break
217 break
200
218
201 self.close()
219 self.close()
202
220
203 def close(self):
221 def close(self):
204
222
205 BaseClass.close(self)
223 BaseClass.close(self)
206 log.success('Done...(Time:{:4.2f} secs)'.format(time.time()-self.start_time), self.name)
224 log.success('Done...(Time:{:4.2f} secs)'.format(time.time()-self.start_time), self.name)
207
225
208 return MPClass
226 return MPClass
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,1862 +1,1860
1 import sys
1 import sys
2 import numpy,math
2 import numpy,math
3 from scipy import interpolate
3 from scipy import interpolate
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
6 from schainpy.utils import log
6 from schainpy.utils import log
7 from time import time
7 from time import time
8
8
9
9
10
10
11 class VoltageProc(ProcessingUnit):
11 class VoltageProc(ProcessingUnit):
12
12
13 def __init__(self):
13 def __init__(self):
14
14
15 ProcessingUnit.__init__(self)
15 ProcessingUnit.__init__(self)
16
16
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19 self.setupReq = False
19 self.setupReq = False
20
20
21 def run(self):
21 def run(self):
22
22
23 if self.dataIn.type == 'AMISR':
23 if self.dataIn.type == 'AMISR':
24 self.__updateObjFromAmisrInput()
24 self.__updateObjFromAmisrInput()
25
25
26 if self.dataIn.type == 'Voltage':
26 if self.dataIn.type == 'Voltage':
27 self.dataOut.copy(self.dataIn)
27 self.dataOut.copy(self.dataIn)
28
28
29 def __updateObjFromAmisrInput(self):
29 def __updateObjFromAmisrInput(self):
30
30
31 self.dataOut.timeZone = self.dataIn.timeZone
31 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.dstFlag = self.dataIn.dstFlag
32 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.errorCount = self.dataIn.errorCount
33 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35
35
36 self.dataOut.flagNoData = self.dataIn.flagNoData
36 self.dataOut.flagNoData = self.dataIn.flagNoData
37 self.dataOut.data = self.dataIn.data
37 self.dataOut.data = self.dataIn.data
38 self.dataOut.utctime = self.dataIn.utctime
38 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.channelList = self.dataIn.channelList
40 #self.dataOut.timeInterval = self.dataIn.timeInterval
40 #self.dataOut.timeInterval = self.dataIn.timeInterval
41 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.nProfiles = self.dataIn.nProfiles
42 self.dataOut.nProfiles = self.dataIn.nProfiles
43
43
44 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.frequency = self.dataIn.frequency
46 self.dataOut.frequency = self.dataIn.frequency
47
47
48 self.dataOut.azimuth = self.dataIn.azimuth
48 self.dataOut.azimuth = self.dataIn.azimuth
49 self.dataOut.zenith = self.dataIn.zenith
49 self.dataOut.zenith = self.dataIn.zenith
50
50
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54
54
55
55
56 class selectChannels(Operation):
56 class selectChannels(Operation):
57
57
58 def run(self, dataOut, channelList):
58 def run(self, dataOut, channelList):
59
59
60 channelIndexList = []
60 channelIndexList = []
61 self.dataOut = dataOut
61 self.dataOut = dataOut
62 for channel in channelList:
62 for channel in channelList:
63 if channel not in self.dataOut.channelList:
63 if channel not in self.dataOut.channelList:
64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
65
65
66 index = self.dataOut.channelList.index(channel)
66 index = self.dataOut.channelList.index(channel)
67 channelIndexList.append(index)
67 channelIndexList.append(index)
68 self.selectChannelsByIndex(channelIndexList)
68 self.selectChannelsByIndex(channelIndexList)
69 return self.dataOut
69 return self.dataOut
70
70
71 def selectChannelsByIndex(self, channelIndexList):
71 def selectChannelsByIndex(self, channelIndexList):
72 """
72 """
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
74
74
75 Input:
75 Input:
76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
77
77
78 Affected:
78 Affected:
79 self.dataOut.data
79 self.dataOut.data
80 self.dataOut.channelIndexList
80 self.dataOut.channelIndexList
81 self.dataOut.nChannels
81 self.dataOut.nChannels
82 self.dataOut.m_ProcessingHeader.totalSpectra
82 self.dataOut.m_ProcessingHeader.totalSpectra
83 self.dataOut.systemHeaderObj.numChannels
83 self.dataOut.systemHeaderObj.numChannels
84 self.dataOut.m_ProcessingHeader.blockSize
84 self.dataOut.m_ProcessingHeader.blockSize
85
85
86 Return:
86 Return:
87 None
87 None
88 """
88 """
89
89
90 for channelIndex in channelIndexList:
90 for channelIndex in channelIndexList:
91 if channelIndex not in self.dataOut.channelIndexList:
91 if channelIndex not in self.dataOut.channelIndexList:
92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
93
93
94 if self.dataOut.type == 'Voltage':
94 if self.dataOut.type == 'Voltage':
95 if self.dataOut.flagDataAsBlock:
95 if self.dataOut.flagDataAsBlock:
96 """
96 """
97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
98 """
98 """
99 data = self.dataOut.data[channelIndexList,:,:]
99 data = self.dataOut.data[channelIndexList,:,:]
100 else:
100 else:
101 data = self.dataOut.data[channelIndexList,:]
101 data = self.dataOut.data[channelIndexList,:]
102
102
103 self.dataOut.data = data
103 self.dataOut.data = data
104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
105 self.dataOut.channelList = range(len(channelIndexList))
105 self.dataOut.channelList = range(len(channelIndexList))
106
106
107 elif self.dataOut.type == 'Spectra':
107 elif self.dataOut.type == 'Spectra':
108 data_spc = self.dataOut.data_spc[channelIndexList, :]
108 data_spc = self.dataOut.data_spc[channelIndexList, :]
109 data_dc = self.dataOut.data_dc[channelIndexList, :]
109 data_dc = self.dataOut.data_dc[channelIndexList, :]
110
110
111 self.dataOut.data_spc = data_spc
111 self.dataOut.data_spc = data_spc
112 self.dataOut.data_dc = data_dc
112 self.dataOut.data_dc = data_dc
113
113
114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 self.dataOut.channelList = range(len(channelIndexList))
115 self.dataOut.channelList = range(len(channelIndexList))
116 self.__selectPairsByChannel(channelIndexList)
116 self.__selectPairsByChannel(channelIndexList)
117
117
118 return 1
118 return 1
119
119
120 def __selectPairsByChannel(self, channelList=None):
120 def __selectPairsByChannel(self, channelList=None):
121
121
122 if channelList == None:
122 if channelList == None:
123 return
123 return
124
124
125 pairsIndexListSelected = []
125 pairsIndexListSelected = []
126 for pairIndex in self.dataOut.pairsIndexList:
126 for pairIndex in self.dataOut.pairsIndexList:
127 # First pair
127 # First pair
128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
129 continue
129 continue
130 # Second pair
130 # Second pair
131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
132 continue
132 continue
133
133
134 pairsIndexListSelected.append(pairIndex)
134 pairsIndexListSelected.append(pairIndex)
135
135
136 if not pairsIndexListSelected:
136 if not pairsIndexListSelected:
137 self.dataOut.data_cspc = None
137 self.dataOut.data_cspc = None
138 self.dataOut.pairsList = []
138 self.dataOut.pairsList = []
139 return
139 return
140
140
141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
143 for i in pairsIndexListSelected]
143 for i in pairsIndexListSelected]
144
144
145 return
145 return
146
146
147 class selectHeights(Operation):
147 class selectHeights(Operation):
148
148
149 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
149 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
150 """
150 """
151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
152 minHei <= height <= maxHei
152 minHei <= height <= maxHei
153
153
154 Input:
154 Input:
155 minHei : valor minimo de altura a considerar
155 minHei : valor minimo de altura a considerar
156 maxHei : valor maximo de altura a considerar
156 maxHei : valor maximo de altura a considerar
157
157
158 Affected:
158 Affected:
159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
160
160
161 Return:
161 Return:
162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
163 """
163 """
164
164
165 self.dataOut = dataOut
165 self.dataOut = dataOut
166
166
167 if minHei and maxHei:
167 if minHei and maxHei:
168
168
169 if (minHei < self.dataOut.heightList[0]):
169 if (minHei < self.dataOut.heightList[0]):
170 minHei = self.dataOut.heightList[0]
170 minHei = self.dataOut.heightList[0]
171
171
172 if (maxHei > self.dataOut.heightList[-1]):
172 if (maxHei > self.dataOut.heightList[-1]):
173 maxHei = self.dataOut.heightList[-1]
173 maxHei = self.dataOut.heightList[-1]
174
174
175 minIndex = 0
175 minIndex = 0
176 maxIndex = 0
176 maxIndex = 0
177 heights = self.dataOut.heightList
177 heights = self.dataOut.heightList
178
178
179 inda = numpy.where(heights >= minHei)
179 inda = numpy.where(heights >= minHei)
180 indb = numpy.where(heights <= maxHei)
180 indb = numpy.where(heights <= maxHei)
181
181
182 try:
182 try:
183 minIndex = inda[0][0]
183 minIndex = inda[0][0]
184 except:
184 except:
185 minIndex = 0
185 minIndex = 0
186
186
187 try:
187 try:
188 maxIndex = indb[0][-1]
188 maxIndex = indb[0][-1]
189 except:
189 except:
190 maxIndex = len(heights)
190 maxIndex = len(heights)
191
191
192 self.selectHeightsByIndex(minIndex, maxIndex)
192 self.selectHeightsByIndex(minIndex, maxIndex)
193
193
194 return self.dataOut
194 return self.dataOut
195
195
196 def selectHeightsByIndex(self, minIndex, maxIndex):
196 def selectHeightsByIndex(self, minIndex, maxIndex):
197 """
197 """
198 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
198 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
199 minIndex <= index <= maxIndex
199 minIndex <= index <= maxIndex
200
200
201 Input:
201 Input:
202 minIndex : valor de indice minimo de altura a considerar
202 minIndex : valor de indice minimo de altura a considerar
203 maxIndex : valor de indice maximo de altura a considerar
203 maxIndex : valor de indice maximo de altura a considerar
204
204
205 Affected:
205 Affected:
206 self.dataOut.data
206 self.dataOut.data
207 self.dataOut.heightList
207 self.dataOut.heightList
208
208
209 Return:
209 Return:
210 1 si el metodo se ejecuto con exito caso contrario devuelve 0
210 1 si el metodo se ejecuto con exito caso contrario devuelve 0
211 """
211 """
212
212
213 if self.dataOut.type == 'Voltage':
213 if self.dataOut.type == 'Voltage':
214 if (minIndex < 0) or (minIndex > maxIndex):
214 if (minIndex < 0) or (minIndex > maxIndex):
215 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
215 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
216
216
217 if (maxIndex >= self.dataOut.nHeights):
217 if (maxIndex >= self.dataOut.nHeights):
218 maxIndex = self.dataOut.nHeights
218 maxIndex = self.dataOut.nHeights
219 #print("shapeeee",self.dataOut.data.shape)
219 #print("shapeeee",self.dataOut.data.shape)
220 #voltage
220 #voltage
221 if self.dataOut.flagDataAsBlock:
221 if self.dataOut.flagDataAsBlock:
222 """
222 """
223 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
223 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
224 """
224 """
225 data = self.dataOut.data[:,:, minIndex:maxIndex]
225 data = self.dataOut.data[:,:, minIndex:maxIndex]
226 else:
226 else:
227 data = self.dataOut.data[:, minIndex:maxIndex]
227 data = self.dataOut.data[:, minIndex:maxIndex]
228
228
229 # firstHeight = self.dataOut.heightList[minIndex]
229 # firstHeight = self.dataOut.heightList[minIndex]
230
230
231 self.dataOut.data = data
231 self.dataOut.data = data
232 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
232 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
233
233
234 if self.dataOut.nHeights <= 1:
234 if self.dataOut.nHeights <= 1:
235 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
235 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
236 elif self.dataOut.type == 'Spectra':
236 elif self.dataOut.type == 'Spectra':
237 if (minIndex < 0) or (minIndex > maxIndex):
237 if (minIndex < 0) or (minIndex > maxIndex):
238 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
238 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
239 minIndex, maxIndex))
239 minIndex, maxIndex))
240
240
241 if (maxIndex >= self.dataOut.nHeights):
241 if (maxIndex >= self.dataOut.nHeights):
242 maxIndex = self.dataOut.nHeights - 1
242 maxIndex = self.dataOut.nHeights - 1
243
243
244 # Spectra
244 # Spectra
245 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
245 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
246
246
247 data_cspc = None
247 data_cspc = None
248 if self.dataOut.data_cspc is not None:
248 if self.dataOut.data_cspc is not None:
249 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
249 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
250
250
251 data_dc = None
251 data_dc = None
252 if self.dataOut.data_dc is not None:
252 if self.dataOut.data_dc is not None:
253 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
253 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
254
254
255 self.dataOut.data_spc = data_spc
255 self.dataOut.data_spc = data_spc
256 self.dataOut.data_cspc = data_cspc
256 self.dataOut.data_cspc = data_cspc
257 self.dataOut.data_dc = data_dc
257 self.dataOut.data_dc = data_dc
258
258
259 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
259 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
260
260
261 return 1
261 return 1
262
262
263
263
264 class filterByHeights(Operation):
264 class filterByHeights(Operation):
265
265
266 def run(self, dataOut, window):
266 def run(self, dataOut, window):
267
267
268 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
268 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
269
269
270 if window == None:
270 if window == None:
271 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
271 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
272
272
273 newdelta = deltaHeight * window
273 newdelta = deltaHeight * window
274 r = dataOut.nHeights % window
274 r = dataOut.nHeights % window
275 newheights = (dataOut.nHeights-r)/window
275 newheights = (dataOut.nHeights-r)/window
276
276
277 if newheights <= 1:
277 if newheights <= 1:
278 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
278 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
279
279
280 if dataOut.flagDataAsBlock:
280 if dataOut.flagDataAsBlock:
281 """
281 """
282 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
282 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
283 """
283 """
284 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
284 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
285 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
285 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
286 buffer = numpy.sum(buffer,3)
286 buffer = numpy.sum(buffer,3)
287
287
288 else:
288 else:
289 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
289 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
290 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
290 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
291 buffer = numpy.sum(buffer,2)
291 buffer = numpy.sum(buffer,2)
292
292
293 dataOut.data = buffer
293 dataOut.data = buffer
294 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
294 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
295 dataOut.windowOfFilter = window
295 dataOut.windowOfFilter = window
296
296
297 return dataOut
297 return dataOut
298
298
299
299
300 class setH0(Operation):
300 class setH0(Operation):
301
301
302 def run(self, dataOut, h0, deltaHeight = None):
302 def run(self, dataOut, h0, deltaHeight = None):
303
303
304 if not deltaHeight:
304 if not deltaHeight:
305 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
305 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
306
306
307 nHeights = dataOut.nHeights
307 nHeights = dataOut.nHeights
308
308
309 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
309 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
310
310
311 dataOut.heightList = newHeiRange
311 dataOut.heightList = newHeiRange
312
312
313 return dataOut
313 return dataOut
314
314
315
315
316 class deFlip(Operation):
316 class deFlip(Operation):
317
317
318 def run(self, dataOut, channelList = []):
318 def run(self, dataOut, channelList = []):
319
319
320 data = dataOut.data.copy()
320 data = dataOut.data.copy()
321
321
322 if dataOut.flagDataAsBlock:
322 if dataOut.flagDataAsBlock:
323 flip = self.flip
323 flip = self.flip
324 profileList = list(range(dataOut.nProfiles))
324 profileList = list(range(dataOut.nProfiles))
325
325
326 if not channelList:
326 if not channelList:
327 for thisProfile in profileList:
327 for thisProfile in profileList:
328 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
328 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
329 flip *= -1.0
329 flip *= -1.0
330 else:
330 else:
331 for thisChannel in channelList:
331 for thisChannel in channelList:
332 if thisChannel not in dataOut.channelList:
332 if thisChannel not in dataOut.channelList:
333 continue
333 continue
334
334
335 for thisProfile in profileList:
335 for thisProfile in profileList:
336 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
336 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
337 flip *= -1.0
337 flip *= -1.0
338
338
339 self.flip = flip
339 self.flip = flip
340
340
341 else:
341 else:
342 if not channelList:
342 if not channelList:
343 data[:,:] = data[:,:]*self.flip
343 data[:,:] = data[:,:]*self.flip
344 else:
344 else:
345 for thisChannel in channelList:
345 for thisChannel in channelList:
346 if thisChannel not in dataOut.channelList:
346 if thisChannel not in dataOut.channelList:
347 continue
347 continue
348
348
349 data[thisChannel,:] = data[thisChannel,:]*self.flip
349 data[thisChannel,:] = data[thisChannel,:]*self.flip
350
350
351 self.flip *= -1.
351 self.flip *= -1.
352
352
353 dataOut.data = data
353 dataOut.data = data
354
354
355 return dataOut
355 return dataOut
356
356
357
357
358 class setAttribute(Operation):
358 class setAttribute(Operation):
359 '''
359 '''
360 Set an arbitrary attribute(s) to dataOut
360 Set an arbitrary attribute(s) to dataOut
361 '''
361 '''
362
362
363 def __init__(self):
363 def __init__(self):
364
364
365 Operation.__init__(self)
365 Operation.__init__(self)
366 self._ready = False
366 self._ready = False
367
367
368 def run(self, dataOut, **kwargs):
368 def run(self, dataOut, **kwargs):
369
369
370 for key, value in kwargs.items():
370 for key, value in kwargs.items():
371 setattr(dataOut, key, value)
371 setattr(dataOut, key, value)
372
372
373 return dataOut
373 return dataOut
374
374
375
375
376 @MPDecorator
376 @MPDecorator
377 class printAttribute(Operation):
377 class printAttribute(Operation):
378 '''
378 '''
379 Print an arbitrary attribute of dataOut
379 Print an arbitrary attribute of dataOut
380 '''
380 '''
381
381
382 def __init__(self):
382 def __init__(self):
383
383
384 Operation.__init__(self)
384 Operation.__init__(self)
385
385
386 def run(self, dataOut, attributes):
386 def run(self, dataOut, attributes):
387
387
388 if isinstance(attributes, str):
388 if isinstance(attributes, str):
389 attributes = [attributes]
389 attributes = [attributes]
390 for attr in attributes:
390 for attr in attributes:
391 if hasattr(dataOut, attr):
391 if hasattr(dataOut, attr):
392 log.log(getattr(dataOut, attr), attr)
392 log.log(getattr(dataOut, attr), attr)
393
393
394
394
395 class interpolateHeights(Operation):
395 class interpolateHeights(Operation):
396
396
397 def run(self, dataOut, topLim, botLim):
397 def run(self, dataOut, topLim, botLim):
398 #69 al 72 para julia
398 #69 al 72 para julia
399 #82-84 para meteoros
399 #82-84 para meteoros
400 if len(numpy.shape(dataOut.data))==2:
400 if len(numpy.shape(dataOut.data))==2:
401 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
401 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
402 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
402 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
403 #dataOut.data[:,botLim:limSup+1] = sampInterp
403 #dataOut.data[:,botLim:limSup+1] = sampInterp
404 dataOut.data[:,botLim:topLim+1] = sampInterp
404 dataOut.data[:,botLim:topLim+1] = sampInterp
405 else:
405 else:
406 nHeights = dataOut.data.shape[2]
406 nHeights = dataOut.data.shape[2]
407 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
407 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
408 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
408 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
409 f = interpolate.interp1d(x, y, axis = 2)
409 f = interpolate.interp1d(x, y, axis = 2)
410 xnew = numpy.arange(botLim,topLim+1)
410 xnew = numpy.arange(botLim,topLim+1)
411 ynew = f(xnew)
411 ynew = f(xnew)
412 dataOut.data[:,:,botLim:topLim+1] = ynew
412 dataOut.data[:,:,botLim:topLim+1] = ynew
413
413
414 return dataOut
414 return dataOut
415
415
416
416
417 class CohInt(Operation):
417 class CohInt(Operation):
418
418
419 isConfig = False
419 isConfig = False
420 __profIndex = 0
420 __profIndex = 0
421 __byTime = False
421 __byTime = False
422 __initime = None
422 __initime = None
423 __lastdatatime = None
423 __lastdatatime = None
424 __integrationtime = None
424 __integrationtime = None
425 __buffer = None
425 __buffer = None
426 __bufferStride = []
426 __bufferStride = []
427 __dataReady = False
427 __dataReady = False
428 __profIndexStride = 0
428 __profIndexStride = 0
429 __dataToPutStride = False
429 __dataToPutStride = False
430 n = None
430 n = None
431
431
432 def __init__(self, **kwargs):
432 def __init__(self, **kwargs):
433
433
434 Operation.__init__(self, **kwargs)
434 Operation.__init__(self, **kwargs)
435
435
436 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
436 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
437 """
437 """
438 Set the parameters of the integration class.
438 Set the parameters of the integration class.
439
439
440 Inputs:
440 Inputs:
441
441
442 n : Number of coherent integrations
442 n : Number of coherent integrations
443 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
443 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
444 overlapping :
444 overlapping :
445 """
445 """
446
446
447 self.__initime = None
447 self.__initime = None
448 self.__lastdatatime = 0
448 self.__lastdatatime = 0
449 self.__buffer = None
449 self.__buffer = None
450 self.__dataReady = False
450 self.__dataReady = False
451 self.byblock = byblock
451 self.byblock = byblock
452 self.stride = stride
452 self.stride = stride
453
453
454 if n == None and timeInterval == None:
454 if n == None and timeInterval == None:
455 raise ValueError("n or timeInterval should be specified ...")
455 raise ValueError("n or timeInterval should be specified ...")
456
456
457 if n != None:
457 if n != None:
458 self.n = n
458 self.n = n
459 self.__byTime = False
459 self.__byTime = False
460 else:
460 else:
461 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
461 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
462 self.n = 9999
462 self.n = 9999
463 self.__byTime = True
463 self.__byTime = True
464
464
465 if overlapping:
465 if overlapping:
466 self.__withOverlapping = True
466 self.__withOverlapping = True
467 self.__buffer = None
467 self.__buffer = None
468 else:
468 else:
469 self.__withOverlapping = False
469 self.__withOverlapping = False
470 self.__buffer = 0
470 self.__buffer = 0
471
471
472 self.__profIndex = 0
472 self.__profIndex = 0
473
473
474 def putData(self, data):
474 def putData(self, data):
475
475
476 """
476 """
477 Add a profile to the __buffer and increase in one the __profileIndex
477 Add a profile to the __buffer and increase in one the __profileIndex
478
478
479 """
479 """
480
480
481 if not self.__withOverlapping:
481 if not self.__withOverlapping:
482 self.__buffer += data.copy()
482 self.__buffer += data.copy()
483 self.__profIndex += 1
483 self.__profIndex += 1
484 return
484 return
485
485
486 #Overlapping data
486 #Overlapping data
487 nChannels, nHeis = data.shape
487 nChannels, nHeis = data.shape
488 data = numpy.reshape(data, (1, nChannels, nHeis))
488 data = numpy.reshape(data, (1, nChannels, nHeis))
489
489
490 #If the buffer is empty then it takes the data value
490 #If the buffer is empty then it takes the data value
491 if self.__buffer is None:
491 if self.__buffer is None:
492 self.__buffer = data
492 self.__buffer = data
493 self.__profIndex += 1
493 self.__profIndex += 1
494 return
494 return
495
495
496 #If the buffer length is lower than n then stakcing the data value
496 #If the buffer length is lower than n then stakcing the data value
497 if self.__profIndex < self.n:
497 if self.__profIndex < self.n:
498 self.__buffer = numpy.vstack((self.__buffer, data))
498 self.__buffer = numpy.vstack((self.__buffer, data))
499 self.__profIndex += 1
499 self.__profIndex += 1
500 return
500 return
501
501
502 #If the buffer length is equal to n then replacing the last buffer value with the data value
502 #If the buffer length is equal to n then replacing the last buffer value with the data value
503 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
503 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
504 self.__buffer[self.n-1] = data
504 self.__buffer[self.n-1] = data
505 self.__profIndex = self.n
505 self.__profIndex = self.n
506 return
506 return
507
507
508
508
509 def pushData(self):
509 def pushData(self):
510 """
510 """
511 Return the sum of the last profiles and the profiles used in the sum.
511 Return the sum of the last profiles and the profiles used in the sum.
512
512
513 Affected:
513 Affected:
514
514
515 self.__profileIndex
515 self.__profileIndex
516
516
517 """
517 """
518
518
519 if not self.__withOverlapping:
519 if not self.__withOverlapping:
520 data = self.__buffer
520 data = self.__buffer
521 n = self.__profIndex
521 n = self.__profIndex
522
522
523 self.__buffer = 0
523 self.__buffer = 0
524 self.__profIndex = 0
524 self.__profIndex = 0
525
525
526 return data, n
526 return data, n
527
527
528 #Integration with Overlapping
528 #Integration with Overlapping
529 data = numpy.sum(self.__buffer, axis=0)
529 data = numpy.sum(self.__buffer, axis=0)
530 # print data
530 # print data
531 # raise
531 # raise
532 n = self.__profIndex
532 n = self.__profIndex
533
533
534 return data, n
534 return data, n
535
535
536 def byProfiles(self, data):
536 def byProfiles(self, data):
537
537
538 self.__dataReady = False
538 self.__dataReady = False
539 avgdata = None
539 avgdata = None
540 # n = None
540 # n = None
541 # print data
541 # print data
542 # raise
542 # raise
543 self.putData(data)
543 self.putData(data)
544
544
545 if self.__profIndex == self.n:
545 if self.__profIndex == self.n:
546 avgdata, n = self.pushData()
546 avgdata, n = self.pushData()
547 self.__dataReady = True
547 self.__dataReady = True
548
548
549 return avgdata
549 return avgdata
550
550
551 def byTime(self, data, datatime):
551 def byTime(self, data, datatime):
552
552
553 self.__dataReady = False
553 self.__dataReady = False
554 avgdata = None
554 avgdata = None
555 n = None
555 n = None
556
556
557 self.putData(data)
557 self.putData(data)
558
558
559 if (datatime - self.__initime) >= self.__integrationtime:
559 if (datatime - self.__initime) >= self.__integrationtime:
560 avgdata, n = self.pushData()
560 avgdata, n = self.pushData()
561 self.n = n
561 self.n = n
562 self.__dataReady = True
562 self.__dataReady = True
563
563
564 return avgdata
564 return avgdata
565
565
566 def integrateByStride(self, data, datatime):
566 def integrateByStride(self, data, datatime):
567 # print data
567 # print data
568 if self.__profIndex == 0:
568 if self.__profIndex == 0:
569 self.__buffer = [[data.copy(), datatime]]
569 self.__buffer = [[data.copy(), datatime]]
570 else:
570 else:
571 self.__buffer.append([data.copy(),datatime])
571 self.__buffer.append([data.copy(),datatime])
572 self.__profIndex += 1
572 self.__profIndex += 1
573 self.__dataReady = False
573 self.__dataReady = False
574
574
575 if self.__profIndex == self.n * self.stride :
575 if self.__profIndex == self.n * self.stride :
576 self.__dataToPutStride = True
576 self.__dataToPutStride = True
577 self.__profIndexStride = 0
577 self.__profIndexStride = 0
578 self.__profIndex = 0
578 self.__profIndex = 0
579 self.__bufferStride = []
579 self.__bufferStride = []
580 for i in range(self.stride):
580 for i in range(self.stride):
581 current = self.__buffer[i::self.stride]
581 current = self.__buffer[i::self.stride]
582 data = numpy.sum([t[0] for t in current], axis=0)
582 data = numpy.sum([t[0] for t in current], axis=0)
583 avgdatatime = numpy.average([t[1] for t in current])
583 avgdatatime = numpy.average([t[1] for t in current])
584 # print data
584 # print data
585 self.__bufferStride.append((data, avgdatatime))
585 self.__bufferStride.append((data, avgdatatime))
586
586
587 if self.__dataToPutStride:
587 if self.__dataToPutStride:
588 self.__dataReady = True
588 self.__dataReady = True
589 self.__profIndexStride += 1
589 self.__profIndexStride += 1
590 if self.__profIndexStride == self.stride:
590 if self.__profIndexStride == self.stride:
591 self.__dataToPutStride = False
591 self.__dataToPutStride = False
592 # print self.__bufferStride[self.__profIndexStride - 1]
592 # print self.__bufferStride[self.__profIndexStride - 1]
593 # raise
593 # raise
594 return self.__bufferStride[self.__profIndexStride - 1]
594 return self.__bufferStride[self.__profIndexStride - 1]
595
595
596
596
597 return None, None
597 return None, None
598
598
599 def integrate(self, data, datatime=None):
599 def integrate(self, data, datatime=None):
600
600
601 if self.__initime == None:
601 if self.__initime == None:
602 self.__initime = datatime
602 self.__initime = datatime
603
603
604 if self.__byTime:
604 if self.__byTime:
605 avgdata = self.byTime(data, datatime)
605 avgdata = self.byTime(data, datatime)
606 else:
606 else:
607 avgdata = self.byProfiles(data)
607 avgdata = self.byProfiles(data)
608
608
609
609
610 self.__lastdatatime = datatime
610 self.__lastdatatime = datatime
611
611
612 if avgdata is None:
612 if avgdata is None:
613 return None, None
613 return None, None
614
614
615 avgdatatime = self.__initime
615 avgdatatime = self.__initime
616
616
617 deltatime = datatime - self.__lastdatatime
617 deltatime = datatime - self.__lastdatatime
618
618
619 if not self.__withOverlapping:
619 if not self.__withOverlapping:
620 self.__initime = datatime
620 self.__initime = datatime
621 else:
621 else:
622 self.__initime += deltatime
622 self.__initime += deltatime
623
623
624 return avgdata, avgdatatime
624 return avgdata, avgdatatime
625
625
626 def integrateByBlock(self, dataOut):
626 def integrateByBlock(self, dataOut):
627
627
628 times = int(dataOut.data.shape[1]/self.n)
628 times = int(dataOut.data.shape[1]/self.n)
629 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
629 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
630
630
631 id_min = 0
631 id_min = 0
632 id_max = self.n
632 id_max = self.n
633
633
634 for i in range(times):
634 for i in range(times):
635 junk = dataOut.data[:,id_min:id_max,:]
635 junk = dataOut.data[:,id_min:id_max,:]
636 avgdata[:,i,:] = junk.sum(axis=1)
636 avgdata[:,i,:] = junk.sum(axis=1)
637 id_min += self.n
637 id_min += self.n
638 id_max += self.n
638 id_max += self.n
639
639
640 timeInterval = dataOut.ippSeconds*self.n
640 timeInterval = dataOut.ippSeconds*self.n
641 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
641 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
642 self.__dataReady = True
642 self.__dataReady = True
643 return avgdata, avgdatatime
643 return avgdata, avgdatatime
644
644
645 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
645 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
646
646
647 if not self.isConfig:
647 if not self.isConfig:
648 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
648 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
649 self.isConfig = True
649 self.isConfig = True
650
650
651 if dataOut.flagDataAsBlock:
651 if dataOut.flagDataAsBlock:
652 """
652 """
653 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
653 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
654 """
654 """
655 avgdata, avgdatatime = self.integrateByBlock(dataOut)
655 avgdata, avgdatatime = self.integrateByBlock(dataOut)
656 dataOut.nProfiles /= self.n
656 dataOut.nProfiles /= self.n
657 else:
657 else:
658 if stride is None:
658 if stride is None:
659 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
659 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
660 else:
660 else:
661 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
661 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
662
662
663
663
664 # dataOut.timeInterval *= n
664 # dataOut.timeInterval *= n
665 dataOut.flagNoData = True
665 dataOut.flagNoData = True
666
666
667 if self.__dataReady:
667 if self.__dataReady:
668 dataOut.data = avgdata
668 dataOut.data = avgdata
669 if not dataOut.flagCohInt:
669 if not dataOut.flagCohInt:
670 dataOut.nCohInt *= self.n
670 dataOut.nCohInt *= self.n
671 dataOut.flagCohInt = True
671 dataOut.flagCohInt = True
672 dataOut.utctime = avgdatatime
672 dataOut.utctime = avgdatatime
673 # print avgdata, avgdatatime
673 # print avgdata, avgdatatime
674 # raise
674 # raise
675 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
675 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
676 dataOut.flagNoData = False
676 dataOut.flagNoData = False
677 return dataOut
677 return dataOut
678
678
679 class Decoder(Operation):
679 class Decoder(Operation):
680
680
681 isConfig = False
681 isConfig = False
682 __profIndex = 0
682 __profIndex = 0
683
683
684 code = None
684 code = None
685
685
686 nCode = None
686 nCode = None
687 nBaud = None
687 nBaud = None
688
688
689 def __init__(self, **kwargs):
689 def __init__(self, **kwargs):
690
690
691 Operation.__init__(self, **kwargs)
691 Operation.__init__(self, **kwargs)
692
692
693 self.times = None
693 self.times = None
694 self.osamp = None
694 self.osamp = None
695 # self.__setValues = False
695 # self.__setValues = False
696 self.isConfig = False
696 self.isConfig = False
697 self.setupReq = False
697 self.setupReq = False
698 def setup(self, code, osamp, dataOut):
698 def setup(self, code, osamp, dataOut):
699
699
700 self.__profIndex = 0
700 self.__profIndex = 0
701
701
702 self.code = code
702 self.code = code
703
703
704 self.nCode = len(code)
704 self.nCode = len(code)
705 self.nBaud = len(code[0])
705 self.nBaud = len(code[0])
706
706
707 if (osamp != None) and (osamp >1):
707 if (osamp != None) and (osamp >1):
708 self.osamp = osamp
708 self.osamp = osamp
709 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
709 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
710 self.nBaud = self.nBaud*self.osamp
710 self.nBaud = self.nBaud*self.osamp
711
711
712 self.__nChannels = dataOut.nChannels
712 self.__nChannels = dataOut.nChannels
713 self.__nProfiles = dataOut.nProfiles
713 self.__nProfiles = dataOut.nProfiles
714 self.__nHeis = dataOut.nHeights
714 self.__nHeis = dataOut.nHeights
715
715
716 if self.__nHeis < self.nBaud:
716 if self.__nHeis < self.nBaud:
717 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
717 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
718
718
719 #Frequency
719 #Frequency
720 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
720 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
721
721
722 __codeBuffer[:,0:self.nBaud] = self.code
722 __codeBuffer[:,0:self.nBaud] = self.code
723
723
724 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
724 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
725
725
726 if dataOut.flagDataAsBlock:
726 if dataOut.flagDataAsBlock:
727
727
728 self.ndatadec = self.__nHeis #- self.nBaud + 1
728 self.ndatadec = self.__nHeis #- self.nBaud + 1
729
729
730 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
730 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
731
731
732 else:
732 else:
733
733
734 #Time
734 #Time
735 self.ndatadec = self.__nHeis #- self.nBaud + 1
735 self.ndatadec = self.__nHeis #- self.nBaud + 1
736
736
737 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
737 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
738
738
739 def __convolutionInFreq(self, data):
739 def __convolutionInFreq(self, data):
740
740
741 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
741 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
742
742
743 fft_data = numpy.fft.fft(data, axis=1)
743 fft_data = numpy.fft.fft(data, axis=1)
744
744
745 conv = fft_data*fft_code
745 conv = fft_data*fft_code
746
746
747 data = numpy.fft.ifft(conv,axis=1)
747 data = numpy.fft.ifft(conv,axis=1)
748
748
749 return data
749 return data
750
750
751 def __convolutionInFreqOpt(self, data):
751 def __convolutionInFreqOpt(self, data):
752
752
753 raise NotImplementedError
753 raise NotImplementedError
754
754
755 def __convolutionInTime(self, data):
755 def __convolutionInTime(self, data):
756
756
757 code = self.code[self.__profIndex]
757 code = self.code[self.__profIndex]
758 for i in range(self.__nChannels):
758 for i in range(self.__nChannels):
759 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
759 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
760
760
761 return self.datadecTime
761 return self.datadecTime
762
762
763 def __convolutionByBlockInTime(self, data):
763 def __convolutionByBlockInTime(self, data):
764
764
765 repetitions = int(self.__nProfiles / self.nCode)
765 repetitions = int(self.__nProfiles / self.nCode)
766 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
766 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
767 junk = junk.flatten()
767 junk = junk.flatten()
768 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
768 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
769 profilesList = range(self.__nProfiles)
769 profilesList = range(self.__nProfiles)
770
770
771 for i in range(self.__nChannels):
771 for i in range(self.__nChannels):
772 for j in profilesList:
772 for j in profilesList:
773 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
773 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
774 return self.datadecTime
774 return self.datadecTime
775
775
776 def __convolutionByBlockInFreq(self, data):
776 def __convolutionByBlockInFreq(self, data):
777
777
778 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
778 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
779
779
780
780
781 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
781 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
782
782
783 fft_data = numpy.fft.fft(data, axis=2)
783 fft_data = numpy.fft.fft(data, axis=2)
784
784
785 conv = fft_data*fft_code
785 conv = fft_data*fft_code
786
786
787 data = numpy.fft.ifft(conv,axis=2)
787 data = numpy.fft.ifft(conv,axis=2)
788
788
789 return data
789 return data
790
790
791
791
792 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
792 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
793
793
794 if dataOut.flagDecodeData:
794 if dataOut.flagDecodeData:
795 print("This data is already decoded, recoding again ...")
795 print("This data is already decoded, recoding again ...")
796
796
797 if not self.isConfig:
797 if not self.isConfig:
798
798
799 if code is None:
799 if code is None:
800 if dataOut.code is None:
800 if dataOut.code is None:
801 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
801 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
802
802
803 code = dataOut.code
803 code = dataOut.code
804 else:
804 else:
805 code = numpy.array(code).reshape(nCode,nBaud)
805 code = numpy.array(code).reshape(nCode,nBaud)
806 self.setup(code, osamp, dataOut)
806 self.setup(code, osamp, dataOut)
807
807
808 self.isConfig = True
808 self.isConfig = True
809
809
810 if mode == 3:
810 if mode == 3:
811 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
811 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
812
812
813 if times != None:
813 if times != None:
814 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
814 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
815
815
816 if self.code is None:
816 if self.code is None:
817 print("Fail decoding: Code is not defined.")
817 print("Fail decoding: Code is not defined.")
818 return
818 return
819
819
820 self.__nProfiles = dataOut.nProfiles
820 self.__nProfiles = dataOut.nProfiles
821 datadec = None
821 datadec = None
822
822
823 if mode == 3:
823 if mode == 3:
824 mode = 0
824 mode = 0
825
825
826 if dataOut.flagDataAsBlock:
826 if dataOut.flagDataAsBlock:
827 """
827 """
828 Decoding when data have been read as block,
828 Decoding when data have been read as block,
829 """
829 """
830
830
831 if mode == 0:
831 if mode == 0:
832 datadec = self.__convolutionByBlockInTime(dataOut.data)
832 datadec = self.__convolutionByBlockInTime(dataOut.data)
833 if mode == 1:
833 if mode == 1:
834 datadec = self.__convolutionByBlockInFreq(dataOut.data)
834 datadec = self.__convolutionByBlockInFreq(dataOut.data)
835 else:
835 else:
836 """
836 """
837 Decoding when data have been read profile by profile
837 Decoding when data have been read profile by profile
838 """
838 """
839 if mode == 0:
839 if mode == 0:
840 datadec = self.__convolutionInTime(dataOut.data)
840 datadec = self.__convolutionInTime(dataOut.data)
841
841
842 if mode == 1:
842 if mode == 1:
843 datadec = self.__convolutionInFreq(dataOut.data)
843 datadec = self.__convolutionInFreq(dataOut.data)
844
844
845 if mode == 2:
845 if mode == 2:
846 datadec = self.__convolutionInFreqOpt(dataOut.data)
846 datadec = self.__convolutionInFreqOpt(dataOut.data)
847
847
848 if datadec is None:
848 if datadec is None:
849 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
849 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
850
850
851 dataOut.code = self.code
851 dataOut.code = self.code
852 dataOut.nCode = self.nCode
852 dataOut.nCode = self.nCode
853 dataOut.nBaud = self.nBaud
853 dataOut.nBaud = self.nBaud
854
854
855 dataOut.data = datadec
855 dataOut.data = datadec
856
856
857 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
857 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
858
858
859 dataOut.flagDecodeData = True #asumo q la data esta decodificada
859 dataOut.flagDecodeData = True #asumo q la data esta decodificada
860
860
861 if self.__profIndex == self.nCode-1:
861 if self.__profIndex == self.nCode-1:
862 self.__profIndex = 0
862 self.__profIndex = 0
863 return dataOut
863 return dataOut
864
864
865 self.__profIndex += 1
865 self.__profIndex += 1
866
866
867 return dataOut
867 return dataOut
868 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
868 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
869
869
870
870
871 class ProfileConcat(Operation):
871 class ProfileConcat(Operation):
872
872
873 isConfig = False
873 isConfig = False
874 buffer = None
874 buffer = None
875
875
876 def __init__(self, **kwargs):
876 def __init__(self, **kwargs):
877
877
878 Operation.__init__(self, **kwargs)
878 Operation.__init__(self, **kwargs)
879 self.profileIndex = 0
879 self.profileIndex = 0
880
880
881 def reset(self):
881 def reset(self):
882 self.buffer = numpy.zeros_like(self.buffer)
882 self.buffer = numpy.zeros_like(self.buffer)
883 self.start_index = 0
883 self.start_index = 0
884 self.times = 1
884 self.times = 1
885
885
886 def setup(self, data, m, n=1):
886 def setup(self, data, m, n=1):
887 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
887 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
888 self.nHeights = data.shape[1]#.nHeights
888 self.nHeights = data.shape[1]#.nHeights
889 self.start_index = 0
889 self.start_index = 0
890 self.times = 1
890 self.times = 1
891
891
892 def concat(self, data):
892 def concat(self, data):
893
893
894 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
894 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
895 self.start_index = self.start_index + self.nHeights
895 self.start_index = self.start_index + self.nHeights
896
896
897 def run(self, dataOut, m):
897 def run(self, dataOut, m):
898 dataOut.flagNoData = True
898 dataOut.flagNoData = True
899
899
900 if not self.isConfig:
900 if not self.isConfig:
901 self.setup(dataOut.data, m, 1)
901 self.setup(dataOut.data, m, 1)
902 self.isConfig = True
902 self.isConfig = True
903
903
904 if dataOut.flagDataAsBlock:
904 if dataOut.flagDataAsBlock:
905 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
905 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
906
906
907 else:
907 else:
908 self.concat(dataOut.data)
908 self.concat(dataOut.data)
909 self.times += 1
909 self.times += 1
910 if self.times > m:
910 if self.times > m:
911 dataOut.data = self.buffer
911 dataOut.data = self.buffer
912 self.reset()
912 self.reset()
913 dataOut.flagNoData = False
913 dataOut.flagNoData = False
914 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
914 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
915 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
915 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
916 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
916 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
917 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
917 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
918 dataOut.ippSeconds *= m
918 dataOut.ippSeconds *= m
919 return dataOut
919 return dataOut
920
920
921 class ProfileSelector(Operation):
921 class ProfileSelector(Operation):
922
922
923 profileIndex = None
923 profileIndex = None
924 # Tamanho total de los perfiles
924 # Tamanho total de los perfiles
925 nProfiles = None
925 nProfiles = None
926
926
927 def __init__(self, **kwargs):
927 def __init__(self, **kwargs):
928
928
929 Operation.__init__(self, **kwargs)
929 Operation.__init__(self, **kwargs)
930 self.profileIndex = 0
930 self.profileIndex = 0
931
931
932 def incProfileIndex(self):
932 def incProfileIndex(self):
933
933
934 self.profileIndex += 1
934 self.profileIndex += 1
935
935
936 if self.profileIndex >= self.nProfiles:
936 if self.profileIndex >= self.nProfiles:
937 self.profileIndex = 0
937 self.profileIndex = 0
938
938
939 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
939 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
940
940
941 if profileIndex < minIndex:
941 if profileIndex < minIndex:
942 return False
942 return False
943
943
944 if profileIndex > maxIndex:
944 if profileIndex > maxIndex:
945 return False
945 return False
946
946
947 return True
947 return True
948
948
949 def isThisProfileInList(self, profileIndex, profileList):
949 def isThisProfileInList(self, profileIndex, profileList):
950
950
951 if profileIndex not in profileList:
951 if profileIndex not in profileList:
952 return False
952 return False
953
953
954 return True
954 return True
955
955
956 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
956 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
957
957 #print("before",dataOut.data.shape)
958 """
958 """
959 ProfileSelector:
959 ProfileSelector:
960
960
961 Inputs:
961 Inputs:
962 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
962 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
963
963
964 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
964 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
965
965
966 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
966 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
967
967
968 """
968 """
969
969
970 if rangeList is not None:
970 if rangeList is not None:
971 if type(rangeList[0]) not in (tuple, list):
971 if type(rangeList[0]) not in (tuple, list):
972 rangeList = [rangeList]
972 rangeList = [rangeList]
973
973
974 dataOut.flagNoData = True
974 dataOut.flagNoData = True
975
975
976 if dataOut.flagDataAsBlock:
976 if dataOut.flagDataAsBlock:
977 """
977 """
978 data dimension = [nChannels, nProfiles, nHeis]
978 data dimension = [nChannels, nProfiles, nHeis]
979 """
979 """
980 if profileList != None:
980 if profileList != None:
981 dataOut.data = dataOut.data[:,profileList,:]
981 dataOut.data = dataOut.data[:,profileList,:]
982
982
983 if profileRangeList != None:
983 if profileRangeList != None:
984 minIndex = profileRangeList[0]
984 minIndex = profileRangeList[0]
985 maxIndex = profileRangeList[1]
985 maxIndex = profileRangeList[1]
986 profileList = list(range(minIndex, maxIndex+1))
986 profileList = list(range(minIndex, maxIndex+1))
987
987
988 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
988 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
989
989
990 if rangeList != None:
990 if rangeList != None:
991
991
992 profileList = []
992 profileList = []
993
993
994 for thisRange in rangeList:
994 for thisRange in rangeList:
995 minIndex = thisRange[0]
995 minIndex = thisRange[0]
996 maxIndex = thisRange[1]
996 maxIndex = thisRange[1]
997
997
998 profileList.extend(list(range(minIndex, maxIndex+1)))
998 profileList.extend(list(range(minIndex, maxIndex+1)))
999
999
1000 dataOut.data = dataOut.data[:,profileList,:]
1000 dataOut.data = dataOut.data[:,profileList,:]
1001
1001
1002 dataOut.nProfiles = len(profileList)
1002 dataOut.nProfiles = len(profileList)
1003 dataOut.profileIndex = dataOut.nProfiles - 1
1003 dataOut.profileIndex = dataOut.nProfiles - 1
1004 dataOut.flagNoData = False
1004 dataOut.flagNoData = False
1005
1005 #print(dataOut.data.shape)
1006 return dataOut
1006 return dataOut
1007
1007
1008 """
1008 """
1009 data dimension = [nChannels, nHeis]
1009 data dimension = [nChannels, nHeis]
1010 """
1010 """
1011
1011
1012 if profileList != None:
1012 if profileList != None:
1013
1013
1014 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1014 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1015
1015
1016 self.nProfiles = len(profileList)
1016 self.nProfiles = len(profileList)
1017 dataOut.nProfiles = self.nProfiles
1017 dataOut.nProfiles = self.nProfiles
1018 dataOut.profileIndex = self.profileIndex
1018 dataOut.profileIndex = self.profileIndex
1019 dataOut.flagNoData = False
1019 dataOut.flagNoData = False
1020
1020
1021 self.incProfileIndex()
1021 self.incProfileIndex()
1022 return dataOut
1022 return dataOut
1023
1023
1024 if profileRangeList != None:
1024 if profileRangeList != None:
1025
1025
1026 minIndex = profileRangeList[0]
1026 minIndex = profileRangeList[0]
1027 maxIndex = profileRangeList[1]
1027 maxIndex = profileRangeList[1]
1028
1028
1029 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1029 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1030
1030
1031 self.nProfiles = maxIndex - minIndex + 1
1031 self.nProfiles = maxIndex - minIndex + 1
1032 dataOut.nProfiles = self.nProfiles
1032 dataOut.nProfiles = self.nProfiles
1033 dataOut.profileIndex = self.profileIndex
1033 dataOut.profileIndex = self.profileIndex
1034 dataOut.flagNoData = False
1034 dataOut.flagNoData = False
1035
1035
1036 self.incProfileIndex()
1036 self.incProfileIndex()
1037 return dataOut
1037 return dataOut
1038
1038
1039 if rangeList != None:
1039 if rangeList != None:
1040
1040
1041 nProfiles = 0
1041 nProfiles = 0
1042
1042
1043 for thisRange in rangeList:
1043 for thisRange in rangeList:
1044 minIndex = thisRange[0]
1044 minIndex = thisRange[0]
1045 maxIndex = thisRange[1]
1045 maxIndex = thisRange[1]
1046
1046
1047 nProfiles += maxIndex - minIndex + 1
1047 nProfiles += maxIndex - minIndex + 1
1048
1048
1049 for thisRange in rangeList:
1049 for thisRange in rangeList:
1050
1050
1051 minIndex = thisRange[0]
1051 minIndex = thisRange[0]
1052 maxIndex = thisRange[1]
1052 maxIndex = thisRange[1]
1053
1053
1054 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1054 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1055
1055
1056 self.nProfiles = nProfiles
1056 self.nProfiles = nProfiles
1057 dataOut.nProfiles = self.nProfiles
1057 dataOut.nProfiles = self.nProfiles
1058 dataOut.profileIndex = self.profileIndex
1058 dataOut.profileIndex = self.profileIndex
1059 dataOut.flagNoData = False
1059 dataOut.flagNoData = False
1060
1060
1061 self.incProfileIndex()
1061 self.incProfileIndex()
1062
1062
1063 break
1063 break
1064
1064
1065 return dataOut
1065 return dataOut
1066
1066
1067
1067
1068 if beam != None: #beam is only for AMISR data
1068 if beam != None: #beam is only for AMISR data
1069 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1069 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1070 dataOut.flagNoData = False
1070 dataOut.flagNoData = False
1071 dataOut.profileIndex = self.profileIndex
1071 dataOut.profileIndex = self.profileIndex
1072
1072
1073 self.incProfileIndex()
1073 self.incProfileIndex()
1074
1074
1075 return dataOut
1075 return dataOut
1076
1076
1077 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1077 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1078
1078
1079
1079
1080 class Reshaper(Operation):
1080 class Reshaper(Operation):
1081
1081
1082 def __init__(self, **kwargs):
1082 def __init__(self, **kwargs):
1083
1083
1084 Operation.__init__(self, **kwargs)
1084 Operation.__init__(self, **kwargs)
1085
1085
1086 self.__buffer = None
1086 self.__buffer = None
1087 self.__nitems = 0
1087 self.__nitems = 0
1088
1088
1089 def __appendProfile(self, dataOut, nTxs):
1089 def __appendProfile(self, dataOut, nTxs):
1090
1090
1091 if self.__buffer is None:
1091 if self.__buffer is None:
1092 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1092 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1093 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1093 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1094
1094
1095 ini = dataOut.nHeights * self.__nitems
1095 ini = dataOut.nHeights * self.__nitems
1096 end = ini + dataOut.nHeights
1096 end = ini + dataOut.nHeights
1097
1097
1098 self.__buffer[:, ini:end] = dataOut.data
1098 self.__buffer[:, ini:end] = dataOut.data
1099
1099
1100 self.__nitems += 1
1100 self.__nitems += 1
1101
1101
1102 return int(self.__nitems*nTxs)
1102 return int(self.__nitems*nTxs)
1103
1103
1104 def __getBuffer(self):
1104 def __getBuffer(self):
1105
1105
1106 if self.__nitems == int(1./self.__nTxs):
1106 if self.__nitems == int(1./self.__nTxs):
1107
1107
1108 self.__nitems = 0
1108 self.__nitems = 0
1109
1109
1110 return self.__buffer.copy()
1110 return self.__buffer.copy()
1111
1111
1112 return None
1112 return None
1113
1113
1114 def __checkInputs(self, dataOut, shape, nTxs):
1114 def __checkInputs(self, dataOut, shape, nTxs):
1115
1115
1116 if shape is None and nTxs is None:
1116 if shape is None and nTxs is None:
1117 raise ValueError("Reshaper: shape of factor should be defined")
1117 raise ValueError("Reshaper: shape of factor should be defined")
1118
1118
1119 if nTxs:
1119 if nTxs:
1120 if nTxs < 0:
1120 if nTxs < 0:
1121 raise ValueError("nTxs should be greater than 0")
1121 raise ValueError("nTxs should be greater than 0")
1122
1122
1123 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1123 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1124 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1124 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1125
1125
1126 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1126 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1127
1127
1128 return shape, nTxs
1128 return shape, nTxs
1129
1129
1130 if len(shape) != 2 and len(shape) != 3:
1130 if len(shape) != 2 and len(shape) != 3:
1131 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1131 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1132
1132
1133 if len(shape) == 2:
1133 if len(shape) == 2:
1134 shape_tuple = [dataOut.nChannels]
1134 shape_tuple = [dataOut.nChannels]
1135 shape_tuple.extend(shape)
1135 shape_tuple.extend(shape)
1136 else:
1136 else:
1137 shape_tuple = list(shape)
1137 shape_tuple = list(shape)
1138
1138
1139 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1139 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1140
1140
1141 return shape_tuple, nTxs
1141 return shape_tuple, nTxs
1142
1142
1143 def run(self, dataOut, shape=None, nTxs=None):
1143 def run(self, dataOut, shape=None, nTxs=None):
1144
1144
1145 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1145 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1146
1146
1147 dataOut.flagNoData = True
1147 dataOut.flagNoData = True
1148 profileIndex = None
1148 profileIndex = None
1149
1149
1150 if dataOut.flagDataAsBlock:
1150 if dataOut.flagDataAsBlock:
1151
1151
1152 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1152 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1153 dataOut.flagNoData = False
1153 dataOut.flagNoData = False
1154
1154
1155 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1155 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1156
1156
1157 else:
1157 else:
1158
1158
1159 if self.__nTxs < 1:
1159 if self.__nTxs < 1:
1160
1160
1161 self.__appendProfile(dataOut, self.__nTxs)
1161 self.__appendProfile(dataOut, self.__nTxs)
1162 new_data = self.__getBuffer()
1162 new_data = self.__getBuffer()
1163
1163
1164 if new_data is not None:
1164 if new_data is not None:
1165 dataOut.data = new_data
1165 dataOut.data = new_data
1166 dataOut.flagNoData = False
1166 dataOut.flagNoData = False
1167
1167
1168 profileIndex = dataOut.profileIndex*nTxs
1168 profileIndex = dataOut.profileIndex*nTxs
1169
1169
1170 else:
1170 else:
1171 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1171 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1172
1172
1173 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1173 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1174
1174
1175 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1175 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1176
1176
1177 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1177 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1178
1178
1179 dataOut.profileIndex = profileIndex
1179 dataOut.profileIndex = profileIndex
1180
1180
1181 dataOut.ippSeconds /= self.__nTxs
1181 dataOut.ippSeconds /= self.__nTxs
1182
1182
1183 return dataOut
1183 return dataOut
1184
1184
1185 class SplitProfiles(Operation):
1185 class SplitProfiles(Operation):
1186
1186
1187 def __init__(self, **kwargs):
1187 def __init__(self, **kwargs):
1188
1188
1189 Operation.__init__(self, **kwargs)
1189 Operation.__init__(self, **kwargs)
1190
1190
1191 def run(self, dataOut, n):
1191 def run(self, dataOut, n):
1192
1192
1193 dataOut.flagNoData = True
1193 dataOut.flagNoData = True
1194 profileIndex = None
1194 profileIndex = None
1195
1195
1196 if dataOut.flagDataAsBlock:
1196 if dataOut.flagDataAsBlock:
1197
1197
1198 #nchannels, nprofiles, nsamples
1198 #nchannels, nprofiles, nsamples
1199 shape = dataOut.data.shape
1199 shape = dataOut.data.shape
1200
1200
1201 if shape[2] % n != 0:
1201 if shape[2] % n != 0:
1202 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1202 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1203
1203
1204 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1204 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1205
1205
1206 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1206 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1207 dataOut.flagNoData = False
1207 dataOut.flagNoData = False
1208
1208
1209 profileIndex = int(dataOut.nProfiles/n) - 1
1209 profileIndex = int(dataOut.nProfiles/n) - 1
1210
1210
1211 else:
1211 else:
1212
1212
1213 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1213 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1214
1214
1215 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1215 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1216
1216
1217 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1217 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1218
1218
1219 dataOut.nProfiles = int(dataOut.nProfiles*n)
1219 dataOut.nProfiles = int(dataOut.nProfiles*n)
1220
1220
1221 dataOut.profileIndex = profileIndex
1221 dataOut.profileIndex = profileIndex
1222
1222
1223 dataOut.ippSeconds /= n
1223 dataOut.ippSeconds /= n
1224
1224
1225 return dataOut
1225 return dataOut
1226
1226
1227 class CombineProfiles(Operation):
1227 class CombineProfiles(Operation):
1228 def __init__(self, **kwargs):
1228 def __init__(self, **kwargs):
1229
1229
1230 Operation.__init__(self, **kwargs)
1230 Operation.__init__(self, **kwargs)
1231
1231
1232 self.__remData = None
1232 self.__remData = None
1233 self.__profileIndex = 0
1233 self.__profileIndex = 0
1234
1234
1235 def run(self, dataOut, n):
1235 def run(self, dataOut, n):
1236
1236
1237 dataOut.flagNoData = True
1237 dataOut.flagNoData = True
1238 profileIndex = None
1238 profileIndex = None
1239
1239
1240 if dataOut.flagDataAsBlock:
1240 if dataOut.flagDataAsBlock:
1241
1241
1242 #nchannels, nprofiles, nsamples
1242 #nchannels, nprofiles, nsamples
1243 shape = dataOut.data.shape
1243 shape = dataOut.data.shape
1244 new_shape = shape[0], shape[1]/n, shape[2]*n
1244 new_shape = shape[0], shape[1]/n, shape[2]*n
1245
1245
1246 if shape[1] % n != 0:
1246 if shape[1] % n != 0:
1247 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1247 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1248
1248
1249 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1249 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1250 dataOut.flagNoData = False
1250 dataOut.flagNoData = False
1251
1251
1252 profileIndex = int(dataOut.nProfiles*n) - 1
1252 profileIndex = int(dataOut.nProfiles*n) - 1
1253
1253
1254 else:
1254 else:
1255
1255
1256 #nchannels, nsamples
1256 #nchannels, nsamples
1257 if self.__remData is None:
1257 if self.__remData is None:
1258 newData = dataOut.data
1258 newData = dataOut.data
1259 else:
1259 else:
1260 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1260 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1261
1261
1262 self.__profileIndex += 1
1262 self.__profileIndex += 1
1263
1263
1264 if self.__profileIndex < n:
1264 if self.__profileIndex < n:
1265 self.__remData = newData
1265 self.__remData = newData
1266 #continue
1266 #continue
1267 return
1267 return
1268
1268
1269 self.__profileIndex = 0
1269 self.__profileIndex = 0
1270 self.__remData = None
1270 self.__remData = None
1271
1271
1272 dataOut.data = newData
1272 dataOut.data = newData
1273 dataOut.flagNoData = False
1273 dataOut.flagNoData = False
1274
1274
1275 profileIndex = dataOut.profileIndex/n
1275 profileIndex = dataOut.profileIndex/n
1276
1276
1277
1277
1278 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1278 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1279
1279
1280 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1280 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1281
1281
1282 dataOut.nProfiles = int(dataOut.nProfiles/n)
1282 dataOut.nProfiles = int(dataOut.nProfiles/n)
1283
1283
1284 dataOut.profileIndex = profileIndex
1284 dataOut.profileIndex = profileIndex
1285
1285
1286 dataOut.ippSeconds *= n
1286 dataOut.ippSeconds *= n
1287
1287
1288 return dataOut
1288 return dataOut
1289
1289
1290 class PulsePair(Operation):
1290 class PulsePair(Operation):
1291 '''
1291 '''
1292 Function PulsePair(Signal Power, Velocity)
1292 Function PulsePair(Signal Power, Velocity)
1293 The real component of Lag[0] provides Intensity Information
1293 The real component of Lag[0] provides Intensity Information
1294 The imag component of Lag[1] Phase provides Velocity Information
1294 The imag component of Lag[1] Phase provides Velocity Information
1295
1295
1296 Configuration Parameters:
1296 Configuration Parameters:
1297 nPRF = Number of Several PRF
1297 nPRF = Number of Several PRF
1298 theta = Degree Azimuth angel Boundaries
1298 theta = Degree Azimuth angel Boundaries
1299
1299
1300 Input:
1300 Input:
1301 self.dataOut
1301 self.dataOut
1302 lag[N]
1302 lag[N]
1303 Affected:
1303 Affected:
1304 self.dataOut.spc
1304 self.dataOut.spc
1305 '''
1305 '''
1306 isConfig = False
1306 isConfig = False
1307 __profIndex = 0
1307 __profIndex = 0
1308 __initime = None
1308 __initime = None
1309 __lastdatatime = None
1309 __lastdatatime = None
1310 __buffer = None
1310 __buffer = None
1311 noise = None
1311 noise = None
1312 __dataReady = False
1312 __dataReady = False
1313 n = None
1313 n = None
1314 __nch = 0
1314 __nch = 0
1315 __nHeis = 0
1315 __nHeis = 0
1316 removeDC = False
1316 removeDC = False
1317 ipp = None
1317 ipp = None
1318 lambda_ = 0
1318 lambda_ = 0
1319
1319
1320 def __init__(self,**kwargs):
1320 def __init__(self,**kwargs):
1321 Operation.__init__(self,**kwargs)
1321 Operation.__init__(self,**kwargs)
1322
1322
1323 def setup(self, dataOut, n = None, removeDC=False):
1323 def setup(self, dataOut, n = None, removeDC=False):
1324 '''
1324 '''
1325 n= Numero de PRF's de entrada
1325 n= Numero de PRF's de entrada
1326 '''
1326 '''
1327 self.__initime = None
1327 self.__initime = None
1328 ####print("[INICIO]-setup del METODO PULSE PAIR")
1328 ####print("[INICIO]-setup del METODO PULSE PAIR")
1329 self.__lastdatatime = 0
1329 self.__lastdatatime = 0
1330 self.__dataReady = False
1330 self.__dataReady = False
1331 self.__buffer = 0
1331 self.__buffer = 0
1332 self.__profIndex = 0
1332 self.__profIndex = 0
1333 self.noise = None
1333 self.noise = None
1334 self.__nch = dataOut.nChannels
1334 self.__nch = dataOut.nChannels
1335 self.__nHeis = dataOut.nHeights
1335 self.__nHeis = dataOut.nHeights
1336 self.removeDC = removeDC
1336 self.removeDC = removeDC
1337 self.lambda_ = 3.0e8/(9345.0e6)
1337 self.lambda_ = 3.0e8/(9345.0e6)
1338 self.ippSec = dataOut.ippSeconds
1338 self.ippSec = dataOut.ippSeconds
1339 self.nCohInt = dataOut.nCohInt
1339 self.nCohInt = dataOut.nCohInt
1340 ####print("IPPseconds",dataOut.ippSeconds)
1340 ####print("IPPseconds",dataOut.ippSeconds)
1341 ####print("ELVALOR DE n es:", n)
1341 ####print("ELVALOR DE n es:", n)
1342 if n == None:
1342 if n == None:
1343 raise ValueError("n should be specified.")
1343 raise ValueError("n should be specified.")
1344
1344
1345 if n != None:
1345 if n != None:
1346 if n<2:
1346 if n<2:
1347 raise ValueError("n should be greater than 2")
1347 raise ValueError("n should be greater than 2")
1348
1348
1349 self.n = n
1349 self.n = n
1350 self.__nProf = n
1350 self.__nProf = n
1351
1351
1352 self.__buffer = numpy.zeros((dataOut.nChannels,
1352 self.__buffer = numpy.zeros((dataOut.nChannels,
1353 n,
1353 n,
1354 dataOut.nHeights),
1354 dataOut.nHeights),
1355 dtype='complex')
1355 dtype='complex')
1356
1356
1357 def putData(self,data):
1357 def putData(self,data):
1358 '''
1358 '''
1359 Add a profile to he __buffer and increase in one the __profiel Index
1359 Add a profile to he __buffer and increase in one the __profiel Index
1360 '''
1360 '''
1361 self.__buffer[:,self.__profIndex,:]= data
1361 self.__buffer[:,self.__profIndex,:]= data
1362 self.__profIndex += 1
1362 self.__profIndex += 1
1363 return
1363 return
1364
1364
1365 def pushData(self,dataOut):
1365 def pushData(self,dataOut):
1366 '''
1366 '''
1367 Return the PULSEPAIR and the profiles used in the operation
1367 Return the PULSEPAIR and the profiles used in the operation
1368 Affected : self.__profileIndex
1368 Affected : self.__profileIndex
1369 '''
1369 '''
1370 #----------------- Remove DC-----------------------------------
1370 #----------------- Remove DC-----------------------------------
1371 if self.removeDC==True:
1371 if self.removeDC==True:
1372 mean = numpy.mean(self.__buffer,1)
1372 mean = numpy.mean(self.__buffer,1)
1373 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1373 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1374 dc= numpy.tile(tmp,[1,self.__nProf,1])
1374 dc= numpy.tile(tmp,[1,self.__nProf,1])
1375 self.__buffer = self.__buffer - dc
1375 self.__buffer = self.__buffer - dc
1376 #------------------Calculo de Potencia ------------------------
1376 #------------------Calculo de Potencia ------------------------
1377 pair0 = self.__buffer*numpy.conj(self.__buffer)
1377 pair0 = self.__buffer*numpy.conj(self.__buffer)
1378 pair0 = pair0.real
1378 pair0 = pair0.real
1379 lag_0 = numpy.sum(pair0,1)
1379 lag_0 = numpy.sum(pair0,1)
1380 #-----------------Calculo de Cscp------------------------------ New
1380 #-----------------Calculo de Cscp------------------------------ New
1381 cspc_pair01 = self.__buffer[0]*self.__buffer[1]
1381 cspc_pair01 = self.__buffer[0]*self.__buffer[1]
1382 #------------------Calculo de Ruido x canal--------------------
1382 #------------------Calculo de Ruido x canal--------------------
1383 self.noise = numpy.zeros(self.__nch)
1383 self.noise = numpy.zeros(self.__nch)
1384 for i in range(self.__nch):
1384 for i in range(self.__nch):
1385 daux = numpy.sort(pair0[i,:,:],axis= None)
1385 daux = numpy.sort(pair0[i,:,:],axis= None)
1386 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1386 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1387
1387
1388 self.noise = self.noise.reshape(self.__nch,1)
1388 self.noise = self.noise.reshape(self.__nch,1)
1389 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1389 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1390 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1390 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1391 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1391 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1392 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1392 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1393 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1393 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1394 #-------------------- Power --------------------------------------------------
1394 #-------------------- Power --------------------------------------------------
1395 data_power = lag_0/(self.n*self.nCohInt)
1395 data_power = lag_0/(self.n*self.nCohInt)
1396 #--------------------CCF------------------------------------------------------
1396 #--------------------CCF------------------------------------------------------
1397 data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt)
1397 data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt)
1398 #------------------ Senal --------------------------------------------------
1398 #------------------ Senal --------------------------------------------------
1399 data_intensity = pair0 - noise_buffer
1399 data_intensity = pair0 - noise_buffer
1400 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1400 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1401 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1401 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1402 for i in range(self.__nch):
1402 for i in range(self.__nch):
1403 for j in range(self.__nHeis):
1403 for j in range(self.__nHeis):
1404 if data_intensity[i][j] < 0:
1404 if data_intensity[i][j] < 0:
1405 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1405 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1406
1406
1407 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1407 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1408 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1408 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1409 lag_1 = numpy.sum(pair1,1)
1409 lag_1 = numpy.sum(pair1,1)
1410 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1410 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1411 data_velocity = (self.lambda_/2.0)*data_freq
1411 data_velocity = (self.lambda_/2.0)*data_freq
1412
1412
1413 #---------------- Potencia promedio estimada de la Senal-----------
1413 #---------------- Potencia promedio estimada de la Senal-----------
1414 lag_0 = lag_0/self.n
1414 lag_0 = lag_0/self.n
1415 S = lag_0-self.noise
1415 S = lag_0-self.noise
1416
1416
1417 #---------------- Frecuencia Doppler promedio ---------------------
1417 #---------------- Frecuencia Doppler promedio ---------------------
1418 lag_1 = lag_1/(self.n-1)
1418 lag_1 = lag_1/(self.n-1)
1419 R1 = numpy.abs(lag_1)
1419 R1 = numpy.abs(lag_1)
1420
1420
1421 #---------------- Calculo del SNR----------------------------------
1421 #---------------- Calculo del SNR----------------------------------
1422 data_snrPP = S/self.noise
1422 data_snrPP = S/self.noise
1423 for i in range(self.__nch):
1423 for i in range(self.__nch):
1424 for j in range(self.__nHeis):
1424 for j in range(self.__nHeis):
1425 if data_snrPP[i][j] < 1.e-20:
1425 if data_snrPP[i][j] < 1.e-20:
1426 data_snrPP[i][j] = 1.e-20
1426 data_snrPP[i][j] = 1.e-20
1427
1427
1428 #----------------- Calculo del ancho espectral ----------------------
1428 #----------------- Calculo del ancho espectral ----------------------
1429 L = S/R1
1429 L = S/R1
1430 L = numpy.where(L<0,1,L)
1430 L = numpy.where(L<0,1,L)
1431 L = numpy.log(L)
1431 L = numpy.log(L)
1432 tmp = numpy.sqrt(numpy.absolute(L))
1432 tmp = numpy.sqrt(numpy.absolute(L))
1433 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1433 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1434 n = self.__profIndex
1434 n = self.__profIndex
1435
1435
1436 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1436 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1437 self.__profIndex = 0
1437 self.__profIndex = 0
1438 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n
1438 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n
1439
1439
1440
1440
1441 def pulsePairbyProfiles(self,dataOut):
1441 def pulsePairbyProfiles(self,dataOut):
1442
1442
1443 self.__dataReady = False
1443 self.__dataReady = False
1444 data_power = None
1444 data_power = None
1445 data_intensity = None
1445 data_intensity = None
1446 data_velocity = None
1446 data_velocity = None
1447 data_specwidth = None
1447 data_specwidth = None
1448 data_snrPP = None
1448 data_snrPP = None
1449 data_ccf = None
1449 data_ccf = None
1450 self.putData(data=dataOut.data)
1450 self.putData(data=dataOut.data)
1451 if self.__profIndex == self.n:
1451 if self.__profIndex == self.n:
1452 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut)
1452 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut)
1453 self.__dataReady = True
1453 self.__dataReady = True
1454
1454
1455 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf
1455 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf
1456
1456
1457
1457
1458 def pulsePairOp(self, dataOut, datatime= None):
1458 def pulsePairOp(self, dataOut, datatime= None):
1459
1459
1460 if self.__initime == None:
1460 if self.__initime == None:
1461 self.__initime = datatime
1461 self.__initime = datatime
1462 data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut)
1462 data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut)
1463 self.__lastdatatime = datatime
1463 self.__lastdatatime = datatime
1464
1464
1465 if data_power is None:
1465 if data_power is None:
1466 return None, None, None,None,None,None,None
1466 return None, None, None,None,None,None,None
1467
1467
1468 avgdatatime = self.__initime
1468 avgdatatime = self.__initime
1469 deltatime = datatime - self.__lastdatatime
1469 deltatime = datatime - self.__lastdatatime
1470 self.__initime = datatime
1470 self.__initime = datatime
1471
1471
1472 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime
1472 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime
1473
1473
1474 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1474 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1475 #print("hey")
1475 #print("hey")
1476 #print(dataOut.data.shape)
1476 #print(dataOut.data.shape)
1477 #exit(1)
1477 #exit(1)
1478 #print(self.__profIndex)
1478 #print(self.__profIndex)
1479 if not self.isConfig:
1479 if not self.isConfig:
1480 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1480 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1481 self.isConfig = True
1481 self.isConfig = True
1482 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1482 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1483 dataOut.flagNoData = True
1483 dataOut.flagNoData = True
1484
1484
1485 if self.__dataReady:
1485 if self.__dataReady:
1486 ###print("READY ----------------------------------")
1486 ###print("READY ----------------------------------")
1487 dataOut.nCohInt *= self.n
1487 dataOut.nCohInt *= self.n
1488 dataOut.dataPP_POW = data_intensity # S
1488 dataOut.dataPP_POW = data_intensity # S
1489 dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO
1489 dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO
1490 dataOut.dataPP_DOP = data_velocity
1490 dataOut.dataPP_DOP = data_velocity
1491 dataOut.dataPP_SNR = data_snrPP
1491 dataOut.dataPP_SNR = data_snrPP
1492 dataOut.dataPP_WIDTH = data_specwidth
1492 dataOut.dataPP_WIDTH = data_specwidth
1493 dataOut.dataPP_CCF = data_ccf
1493 dataOut.dataPP_CCF = data_ccf
1494 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1494 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1495 dataOut.nProfiles = int(dataOut.nProfiles/n)
1495 dataOut.nProfiles = int(dataOut.nProfiles/n)
1496 dataOut.utctime = avgdatatime
1496 dataOut.utctime = avgdatatime
1497 dataOut.flagNoData = False
1497 dataOut.flagNoData = False
1498 return dataOut
1498 return dataOut
1499
1499
1500 class PulsePair_vRF(Operation):
1500 class PulsePair_vRF(Operation):
1501 '''
1501 '''
1502 Function PulsePair(Signal Power, Velocity)
1502 Function PulsePair(Signal Power, Velocity)
1503 The real component of Lag[0] provides Intensity Information
1503 The real component of Lag[0] provides Intensity Information
1504 The imag component of Lag[1] Phase provides Velocity Information
1504 The imag component of Lag[1] Phase provides Velocity Information
1505
1505
1506 Configuration Parameters:
1506 Configuration Parameters:
1507 nPRF = Number of Several PRF
1507 nPRF = Number of Several PRF
1508 theta = Degree Azimuth angel Boundaries
1508 theta = Degree Azimuth angel Boundaries
1509
1509
1510 Input:
1510 Input:
1511 self.dataOut
1511 self.dataOut
1512 lag[N]
1512 lag[N]
1513 Affected:
1513 Affected:
1514 self.dataOut.spc
1514 self.dataOut.spc
1515 '''
1515 '''
1516 isConfig = False
1516 isConfig = False
1517 __profIndex = 0
1517 __profIndex = 0
1518 __initime = None
1518 __initime = None
1519 __lastdatatime = None
1519 __lastdatatime = None
1520 __buffer = None
1520 __buffer = None
1521 noise = None
1521 noise = None
1522 __dataReady = False
1522 __dataReady = False
1523 n = None
1523 n = None
1524 __nch = 0
1524 __nch = 0
1525 __nHeis = 0
1525 __nHeis = 0
1526 removeDC = False
1526 removeDC = False
1527 ipp = None
1527 ipp = None
1528 lambda_ = 0
1528 lambda_ = 0
1529
1529
1530 def __init__(self,**kwargs):
1530 def __init__(self,**kwargs):
1531 Operation.__init__(self,**kwargs)
1531 Operation.__init__(self,**kwargs)
1532
1532
1533 def setup(self, dataOut, n = None, removeDC=False):
1533 def setup(self, dataOut, n = None, removeDC=False):
1534 '''
1534 '''
1535 n= Numero de PRF's de entrada
1535 n= Numero de PRF's de entrada
1536 '''
1536 '''
1537 self.__initime = None
1537 self.__initime = None
1538 ####print("[INICIO]-setup del METODO PULSE PAIR")
1538 ####print("[INICIO]-setup del METODO PULSE PAIR")
1539 self.__lastdatatime = 0
1539 self.__lastdatatime = 0
1540 self.__dataReady = False
1540 self.__dataReady = False
1541 self.__buffer = 0
1541 self.__buffer = 0
1542 self.__profIndex = 0
1542 self.__profIndex = 0
1543 self.noise = None
1543 self.noise = None
1544 self.__nch = dataOut.nChannels
1544 self.__nch = dataOut.nChannels
1545 self.__nHeis = dataOut.nHeights
1545 self.__nHeis = dataOut.nHeights
1546 self.removeDC = removeDC
1546 self.removeDC = removeDC
1547 self.lambda_ = 3.0e8/(9345.0e6)
1547 self.lambda_ = 3.0e8/(9345.0e6)
1548 self.ippSec = dataOut.ippSeconds
1548 self.ippSec = dataOut.ippSeconds
1549 self.nCohInt = dataOut.nCohInt
1549 self.nCohInt = dataOut.nCohInt
1550 ####print("IPPseconds",dataOut.ippSeconds)
1550 ####print("IPPseconds",dataOut.ippSeconds)
1551 ####print("ELVALOR DE n es:", n)
1551 ####print("ELVALOR DE n es:", n)
1552 if n == None:
1552 if n == None:
1553 raise ValueError("n should be specified.")
1553 raise ValueError("n should be specified.")
1554
1554
1555 if n != None:
1555 if n != None:
1556 if n<2:
1556 if n<2:
1557 raise ValueError("n should be greater than 2")
1557 raise ValueError("n should be greater than 2")
1558
1558
1559 self.n = n
1559 self.n = n
1560 self.__nProf = n
1560 self.__nProf = n
1561
1561
1562 self.__buffer = numpy.zeros((dataOut.nChannels,
1562 self.__buffer = numpy.zeros((dataOut.nChannels,
1563 n,
1563 n,
1564 dataOut.nHeights),
1564 dataOut.nHeights),
1565 dtype='complex')
1565 dtype='complex')
1566
1566
1567 def putData(self,data):
1567 def putData(self,data):
1568 '''
1568 '''
1569 Add a profile to he __buffer and increase in one the __profiel Index
1569 Add a profile to he __buffer and increase in one the __profiel Index
1570 '''
1570 '''
1571 self.__buffer[:,self.__profIndex,:]= data
1571 self.__buffer[:,self.__profIndex,:]= data
1572 self.__profIndex += 1
1572 self.__profIndex += 1
1573 return
1573 return
1574
1574
1575 def putDataByBlock(self,data,n):
1575 def putDataByBlock(self,data,n):
1576 '''
1576 '''
1577 Add a profile to he __buffer and increase in one the __profiel Index
1577 Add a profile to he __buffer and increase in one the __profiel Index
1578 '''
1578 '''
1579 self.__buffer[:]= data
1579 self.__buffer[:]= data
1580 self.__profIndex = n
1580 self.__profIndex = n
1581 return
1581 return
1582
1582
1583 def pushData(self,dataOut):
1583 def pushData(self,dataOut):
1584 '''
1584 '''
1585 Return the PULSEPAIR and the profiles used in the operation
1585 Return the PULSEPAIR and the profiles used in the operation
1586 Affected : self.__profileIndex
1586 Affected : self.__profileIndex
1587 '''
1587 '''
1588 #----------------- Remove DC-----------------------------------
1588 #----------------- Remove DC-----------------------------------
1589 if self.removeDC==True:
1589 if self.removeDC==True:
1590 mean = numpy.mean(self.__buffer,1)
1590 mean = numpy.mean(self.__buffer,1)
1591 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1591 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1592 dc= numpy.tile(tmp,[1,self.__nProf,1])
1592 dc= numpy.tile(tmp,[1,self.__nProf,1])
1593 self.__buffer = self.__buffer - dc
1593 self.__buffer = self.__buffer - dc
1594 #------------------Calculo de Potencia ------------------------
1594 #------------------Calculo de Potencia ------------------------
1595 pair0 = self.__buffer*numpy.conj(self.__buffer)
1595 pair0 = self.__buffer*numpy.conj(self.__buffer)
1596 pair0 = pair0.real
1596 pair0 = pair0.real
1597 lag_0 = numpy.sum(pair0,1)
1597 lag_0 = numpy.sum(pair0,1)
1598 #-----------------Calculo de Cscp------------------------------ New
1598 #-----------------Calculo de Cscp------------------------------ New
1599 cspc_pair01 = self.__buffer[0]*self.__buffer[1]
1599 cspc_pair01 = self.__buffer[0]*self.__buffer[1]
1600 #------------------Calculo de Ruido x canal--------------------
1600 #------------------Calculo de Ruido x canal--------------------
1601 self.noise = numpy.zeros(self.__nch)
1601 self.noise = numpy.zeros(self.__nch)
1602 for i in range(self.__nch):
1602 for i in range(self.__nch):
1603 daux = numpy.sort(pair0[i,:,:],axis= None)
1603 daux = numpy.sort(pair0[i,:,:],axis= None)
1604 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1604 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1605
1605
1606 self.noise = self.noise.reshape(self.__nch,1)
1606 self.noise = self.noise.reshape(self.__nch,1)
1607 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1607 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1608 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1608 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1609 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1609 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1610 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1610 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1611 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1611 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1612 #-------------------- Power --------------------------------------------------
1612 #-------------------- Power --------------------------------------------------
1613 data_power = lag_0/(self.n*self.nCohInt)
1613 data_power = lag_0/(self.n*self.nCohInt)
1614 #--------------------CCF------------------------------------------------------
1614 #--------------------CCF------------------------------------------------------
1615 data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt)
1615 data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt)
1616 #------------------ Senal --------------------------------------------------
1616 #------------------ Senal --------------------------------------------------
1617 data_intensity = pair0 - noise_buffer
1617 data_intensity = pair0 - noise_buffer
1618 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1618 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1619 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1619 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1620 for i in range(self.__nch):
1620 for i in range(self.__nch):
1621 for j in range(self.__nHeis):
1621 for j in range(self.__nHeis):
1622 if data_intensity[i][j] < 0:
1622 if data_intensity[i][j] < 0:
1623 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1623 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1624
1624
1625 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1625 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1626 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1626 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1627 lag_1 = numpy.sum(pair1,1)
1627 lag_1 = numpy.sum(pair1,1)
1628 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1628 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1629 data_velocity = (self.lambda_/2.0)*data_freq
1629 data_velocity = (self.lambda_/2.0)*data_freq
1630
1630
1631 #---------------- Potencia promedio estimada de la Senal-----------
1631 #---------------- Potencia promedio estimada de la Senal-----------
1632 lag_0 = lag_0/self.n
1632 lag_0 = lag_0/self.n
1633 S = lag_0-self.noise
1633 S = lag_0-self.noise
1634
1634
1635 #---------------- Frecuencia Doppler promedio ---------------------
1635 #---------------- Frecuencia Doppler promedio ---------------------
1636 lag_1 = lag_1/(self.n-1)
1636 lag_1 = lag_1/(self.n-1)
1637 R1 = numpy.abs(lag_1)
1637 R1 = numpy.abs(lag_1)
1638
1638
1639 #---------------- Calculo del SNR----------------------------------
1639 #---------------- Calculo del SNR----------------------------------
1640 data_snrPP = S/self.noise
1640 data_snrPP = S/self.noise
1641 for i in range(self.__nch):
1641 for i in range(self.__nch):
1642 for j in range(self.__nHeis):
1642 for j in range(self.__nHeis):
1643 if data_snrPP[i][j] < 1.e-20:
1643 if data_snrPP[i][j] < 1.e-20:
1644 data_snrPP[i][j] = 1.e-20
1644 data_snrPP[i][j] = 1.e-20
1645
1645
1646 #----------------- Calculo del ancho espectral ----------------------
1646 #----------------- Calculo del ancho espectral ----------------------
1647 L = S/R1
1647 L = S/R1
1648 L = numpy.where(L<0,1,L)
1648 L = numpy.where(L<0,1,L)
1649 L = numpy.log(L)
1649 L = numpy.log(L)
1650 tmp = numpy.sqrt(numpy.absolute(L))
1650 tmp = numpy.sqrt(numpy.absolute(L))
1651 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1651 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1652 n = self.__profIndex
1652 n = self.__profIndex
1653
1653
1654 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1654 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1655 self.__profIndex = 0
1655 self.__profIndex = 0
1656 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n
1656 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n
1657
1657
1658
1658
1659 def pulsePairbyProfiles(self,dataOut,n):
1659 def pulsePairbyProfiles(self,dataOut,n):
1660
1660
1661 self.__dataReady = False
1661 self.__dataReady = False
1662 data_power = None
1662 data_power = None
1663 data_intensity = None
1663 data_intensity = None
1664 data_velocity = None
1664 data_velocity = None
1665 data_specwidth = None
1665 data_specwidth = None
1666 data_snrPP = None
1666 data_snrPP = None
1667 data_ccf = None
1667 data_ccf = None
1668
1668
1669 if dataOut.flagDataAsBlock:
1669 if dataOut.flagDataAsBlock:
1670 self.putDataByBlock(data=dataOut.data,n=n)
1670 self.putDataByBlock(data=dataOut.data,n=n)
1671 else:
1671 else:
1672 self.putData(data=dataOut.data)
1672 self.putData(data=dataOut.data)
1673 if self.__profIndex == self.n:
1673 if self.__profIndex == self.n:
1674 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut)
1674 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut)
1675 self.__dataReady = True
1675 self.__dataReady = True
1676
1676
1677 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf
1677 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf
1678
1678
1679
1679
1680 def pulsePairOp(self, dataOut, n, datatime= None):
1680 def pulsePairOp(self, dataOut, n, datatime= None):
1681
1681
1682 if self.__initime == None:
1682 if self.__initime == None:
1683 self.__initime = datatime
1683 self.__initime = datatime
1684 data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut,n)
1684 data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut,n)
1685 self.__lastdatatime = datatime
1685 self.__lastdatatime = datatime
1686
1686
1687 if data_power is None:
1687 if data_power is None:
1688 return None, None, None,None,None,None,None
1688 return None, None, None,None,None,None,None
1689
1689
1690 avgdatatime = self.__initime
1690 avgdatatime = self.__initime
1691 deltatime = datatime - self.__lastdatatime
1691 deltatime = datatime - self.__lastdatatime
1692 self.__initime = datatime
1692 self.__initime = datatime
1693
1693
1694 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime
1694 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime
1695
1695
1696 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1696 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1697 #print("hey")
1697
1698 #print(dataOut.data.shape)
1699 #exit(1)
1700 if dataOut.flagDataAsBlock:
1698 if dataOut.flagDataAsBlock:
1701 n = dataOut.nProfileBlocks
1699 n = dataOut.nProfiles
1702 #print(self.__profIndex)
1700
1703 if not self.isConfig:
1701 if not self.isConfig:
1704 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1702 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1705 self.isConfig = True
1703 self.isConfig = True
1706
1704
1707
1705
1708 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, n, dataOut.utctime)
1706 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, n, dataOut.utctime)
1709
1707
1710
1708
1711 dataOut.flagNoData = True
1709 dataOut.flagNoData = True
1712
1710
1713 if self.__dataReady:
1711 if self.__dataReady:
1714 ###print("READY ----------------------------------")
1712 ###print("READY ----------------------------------")
1715 dataOut.nCohInt *= self.n
1713 dataOut.nCohInt *= self.n
1716 dataOut.dataPP_POW = data_intensity # S
1714 dataOut.dataPP_POW = data_intensity # S
1717 dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO
1715 dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO
1718 dataOut.dataPP_DOP = data_velocity
1716 dataOut.dataPP_DOP = data_velocity
1719 dataOut.dataPP_SNR = data_snrPP
1717 dataOut.dataPP_SNR = data_snrPP
1720 dataOut.dataPP_WIDTH = data_specwidth
1718 dataOut.dataPP_WIDTH = data_specwidth
1721 dataOut.dataPP_CCF = data_ccf
1719 dataOut.dataPP_CCF = data_ccf
1722 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1720 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1723 dataOut.nProfiles = int(dataOut.nProfiles/n)
1721 dataOut.nProfiles = int(dataOut.nProfiles/n)
1724 dataOut.utctime = avgdatatime
1722 dataOut.utctime = avgdatatime
1725 dataOut.flagNoData = False
1723 dataOut.flagNoData = False
1726 return dataOut
1724 return dataOut
1727
1725
1728 # import collections
1726 # import collections
1729 # from scipy.stats import mode
1727 # from scipy.stats import mode
1730 #
1728 #
1731 # class Synchronize(Operation):
1729 # class Synchronize(Operation):
1732 #
1730 #
1733 # isConfig = False
1731 # isConfig = False
1734 # __profIndex = 0
1732 # __profIndex = 0
1735 #
1733 #
1736 # def __init__(self, **kwargs):
1734 # def __init__(self, **kwargs):
1737 #
1735 #
1738 # Operation.__init__(self, **kwargs)
1736 # Operation.__init__(self, **kwargs)
1739 # # self.isConfig = False
1737 # # self.isConfig = False
1740 # self.__powBuffer = None
1738 # self.__powBuffer = None
1741 # self.__startIndex = 0
1739 # self.__startIndex = 0
1742 # self.__pulseFound = False
1740 # self.__pulseFound = False
1743 #
1741 #
1744 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1742 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1745 #
1743 #
1746 # #Read data
1744 # #Read data
1747 #
1745 #
1748 # powerdB = dataOut.getPower(channel = channel)
1746 # powerdB = dataOut.getPower(channel = channel)
1749 # noisedB = dataOut.getNoise(channel = channel)[0]
1747 # noisedB = dataOut.getNoise(channel = channel)[0]
1750 #
1748 #
1751 # self.__powBuffer.extend(powerdB.flatten())
1749 # self.__powBuffer.extend(powerdB.flatten())
1752 #
1750 #
1753 # dataArray = numpy.array(self.__powBuffer)
1751 # dataArray = numpy.array(self.__powBuffer)
1754 #
1752 #
1755 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1753 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1756 #
1754 #
1757 # maxValue = numpy.nanmax(filteredPower)
1755 # maxValue = numpy.nanmax(filteredPower)
1758 #
1756 #
1759 # if maxValue < noisedB + 10:
1757 # if maxValue < noisedB + 10:
1760 # #No se encuentra ningun pulso de transmision
1758 # #No se encuentra ningun pulso de transmision
1761 # return None
1759 # return None
1762 #
1760 #
1763 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1761 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1764 #
1762 #
1765 # if len(maxValuesIndex) < 2:
1763 # if len(maxValuesIndex) < 2:
1766 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1764 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1767 # return None
1765 # return None
1768 #
1766 #
1769 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1767 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1770 #
1768 #
1771 # #Seleccionar solo valores con un espaciamiento de nSamples
1769 # #Seleccionar solo valores con un espaciamiento de nSamples
1772 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1770 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1773 #
1771 #
1774 # if len(pulseIndex) < 2:
1772 # if len(pulseIndex) < 2:
1775 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1773 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1776 # return None
1774 # return None
1777 #
1775 #
1778 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1776 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1779 #
1777 #
1780 # #remover senales que se distancien menos de 10 unidades o muestras
1778 # #remover senales que se distancien menos de 10 unidades o muestras
1781 # #(No deberian existir IPP menor a 10 unidades)
1779 # #(No deberian existir IPP menor a 10 unidades)
1782 #
1780 #
1783 # realIndex = numpy.where(spacing > 10 )[0]
1781 # realIndex = numpy.where(spacing > 10 )[0]
1784 #
1782 #
1785 # if len(realIndex) < 2:
1783 # if len(realIndex) < 2:
1786 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1784 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1787 # return None
1785 # return None
1788 #
1786 #
1789 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1787 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1790 # realPulseIndex = pulseIndex[realIndex]
1788 # realPulseIndex = pulseIndex[realIndex]
1791 #
1789 #
1792 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1790 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1793 #
1791 #
1794 # print "IPP = %d samples" %period
1792 # print "IPP = %d samples" %period
1795 #
1793 #
1796 # self.__newNSamples = dataOut.nHeights #int(period)
1794 # self.__newNSamples = dataOut.nHeights #int(period)
1797 # self.__startIndex = int(realPulseIndex[0])
1795 # self.__startIndex = int(realPulseIndex[0])
1798 #
1796 #
1799 # return 1
1797 # return 1
1800 #
1798 #
1801 #
1799 #
1802 # def setup(self, nSamples, nChannels, buffer_size = 4):
1800 # def setup(self, nSamples, nChannels, buffer_size = 4):
1803 #
1801 #
1804 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1802 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1805 # maxlen = buffer_size*nSamples)
1803 # maxlen = buffer_size*nSamples)
1806 #
1804 #
1807 # bufferList = []
1805 # bufferList = []
1808 #
1806 #
1809 # for i in range(nChannels):
1807 # for i in range(nChannels):
1810 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1808 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1811 # maxlen = buffer_size*nSamples)
1809 # maxlen = buffer_size*nSamples)
1812 #
1810 #
1813 # bufferList.append(bufferByChannel)
1811 # bufferList.append(bufferByChannel)
1814 #
1812 #
1815 # self.__nSamples = nSamples
1813 # self.__nSamples = nSamples
1816 # self.__nChannels = nChannels
1814 # self.__nChannels = nChannels
1817 # self.__bufferList = bufferList
1815 # self.__bufferList = bufferList
1818 #
1816 #
1819 # def run(self, dataOut, channel = 0):
1817 # def run(self, dataOut, channel = 0):
1820 #
1818 #
1821 # if not self.isConfig:
1819 # if not self.isConfig:
1822 # nSamples = dataOut.nHeights
1820 # nSamples = dataOut.nHeights
1823 # nChannels = dataOut.nChannels
1821 # nChannels = dataOut.nChannels
1824 # self.setup(nSamples, nChannels)
1822 # self.setup(nSamples, nChannels)
1825 # self.isConfig = True
1823 # self.isConfig = True
1826 #
1824 #
1827 # #Append new data to internal buffer
1825 # #Append new data to internal buffer
1828 # for thisChannel in range(self.__nChannels):
1826 # for thisChannel in range(self.__nChannels):
1829 # bufferByChannel = self.__bufferList[thisChannel]
1827 # bufferByChannel = self.__bufferList[thisChannel]
1830 # bufferByChannel.extend(dataOut.data[thisChannel])
1828 # bufferByChannel.extend(dataOut.data[thisChannel])
1831 #
1829 #
1832 # if self.__pulseFound:
1830 # if self.__pulseFound:
1833 # self.__startIndex -= self.__nSamples
1831 # self.__startIndex -= self.__nSamples
1834 #
1832 #
1835 # #Finding Tx Pulse
1833 # #Finding Tx Pulse
1836 # if not self.__pulseFound:
1834 # if not self.__pulseFound:
1837 # indexFound = self.__findTxPulse(dataOut, channel)
1835 # indexFound = self.__findTxPulse(dataOut, channel)
1838 #
1836 #
1839 # if indexFound == None:
1837 # if indexFound == None:
1840 # dataOut.flagNoData = True
1838 # dataOut.flagNoData = True
1841 # return
1839 # return
1842 #
1840 #
1843 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1841 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1844 # self.__pulseFound = True
1842 # self.__pulseFound = True
1845 # self.__startIndex = indexFound
1843 # self.__startIndex = indexFound
1846 #
1844 #
1847 # #If pulse was found ...
1845 # #If pulse was found ...
1848 # for thisChannel in range(self.__nChannels):
1846 # for thisChannel in range(self.__nChannels):
1849 # bufferByChannel = self.__bufferList[thisChannel]
1847 # bufferByChannel = self.__bufferList[thisChannel]
1850 # #print self.__startIndex
1848 # #print self.__startIndex
1851 # x = numpy.array(bufferByChannel)
1849 # x = numpy.array(bufferByChannel)
1852 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1850 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1853 #
1851 #
1854 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1852 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1855 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1853 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1856 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1854 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1857 #
1855 #
1858 # dataOut.data = self.__arrayBuffer
1856 # dataOut.data = self.__arrayBuffer
1859 #
1857 #
1860 # self.__startIndex += self.__newNSamples
1858 # self.__startIndex += self.__newNSamples
1861 #
1859 #
1862 # return
1860 # return
General Comments 0
You need to be logged in to leave comments. Login now