##// END OF EJS Templates
Version 2.2.5 Fixed several bugs, add jro colormap for spectra/rti, add ParamWriter, TODO: Fix decimation currently disabled
Juan C. Valdez -
r860:5c2852893069
parent child
Show More
@@ -1,36 +1,19
1 Prerequisites:
2
3 Core:
4 -numpy 1.8.0
5 -scipy
6 -math
7 -matplotlib
8 -h5py
9 -ftplib
10 -paramiko (optional for SendTFilesToServer)
11 -stuffr (optional for jroIO_hf)
12 -pyfits (Fits data)
13
14 GUI:
15 -PyQt4
16 -wxPython
17
18 Signal Chain Installation:
1 Signal Chain Installation:
19
2
20 1. Install numpy, matplotlib, TKAgg
3 1. Install system dependencies: python-pip python-dev gfortran libpng-dev freetype* libblas-dev liblapack-dev libatlas-base-dev python-qt4
21 2. Install digital_rf_hdf5 module (developed by Haystack Observatory)
4 2. Install digital_rf_hdf5 module (developed by Haystack Observatory)
22 if you want to use USRP data
5 if you want to use USRP data
23 3. untar schainpy-x.x.x.tar.gz
6 3. untar schainpy-x.x.x.tar.gz
24 4. cd schainpy-x.x.x
7 4. cd schainpy-x.x.x
25 5. execute:
8 5. execute:
26 [hostname]$ sudo pyhon setup.py install
9 [hostname]$ sudo pip install ./
27 6. testing gui:
10 6. testing gui:
28 [hostname]$ schainGUI (enter)
11 [hostname]$ schainGUI (enter)
29
12
30 If you want to use serialization and zerorpc you will need to install the next packages:
13 If you want to use serialization and zerorpc you will need to install the next packages:
31
14
32 1. zerorpc
15 1. zerorpc
33 [hostname]$ sudo port install zerorpc
16 [hostname]$ sudo port install zerorpc
34
17
35 2. cPickle, msgpack and msgpack_numpy
18 2. cPickle, msgpack and msgpack_numpy
36 [hostname]$ sudo port install cPickle msgpack mspack_numpy No newline at end of file
19 [hostname]$ sudo port install cPickle msgpack mspack_numpy
@@ -1,1294 +1,1294
1 '''
1 '''
2 Created on September , 2012
2 Created on September , 2012
3 @author:
3 @author:
4 '''
4 '''
5
5
6 import sys
6 import sys
7 import ast
7 import ast
8 import datetime
8 import datetime
9 import traceback
9 import traceback
10 import schainpy
10 import schainpy
11 import schainpy.admin
11 import schainpy.admin
12
12
13 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
13 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 from xml.dom import minidom
14 from xml.dom import minidom
15
15
16 from schainpy.model import *
16 from schainpy.model import *
17 from time import sleep
17 from time import sleep
18
18
19 def prettify(elem):
19 def prettify(elem):
20 """Return a pretty-printed XML string for the Element.
20 """Return a pretty-printed XML string for the Element.
21 """
21 """
22 rough_string = tostring(elem, 'utf-8')
22 rough_string = tostring(elem, 'utf-8')
23 reparsed = minidom.parseString(rough_string)
23 reparsed = minidom.parseString(rough_string)
24 return reparsed.toprettyxml(indent=" ")
24 return reparsed.toprettyxml(indent=" ")
25
25
26 class ParameterConf():
26 class ParameterConf():
27
27
28 id = None
28 id = None
29 name = None
29 name = None
30 value = None
30 value = None
31 format = None
31 format = None
32
32
33 __formated_value = None
33 __formated_value = None
34
34
35 ELEMENTNAME = 'Parameter'
35 ELEMENTNAME = 'Parameter'
36
36
37 def __init__(self):
37 def __init__(self):
38
38
39 self.format = 'str'
39 self.format = 'str'
40
40
41 def getElementName(self):
41 def getElementName(self):
42
42
43 return self.ELEMENTNAME
43 return self.ELEMENTNAME
44
44
45 def getValue(self):
45 def getValue(self):
46
46
47 value = self.value
47 value = self.value
48 format = self.format
48 format = self.format
49
49
50 if self.__formated_value != None:
50 if self.__formated_value != None:
51
51
52 return self.__formated_value
52 return self.__formated_value
53
53
54 if format == 'str':
54 if format == 'str':
55 self.__formated_value = str(value)
55 self.__formated_value = str(value)
56 return self.__formated_value
56 return self.__formated_value
57
57
58 if value == '':
58 if value == '':
59 raise ValueError, "%s: This parameter value is empty" %self.name
59 raise ValueError, "%s: This parameter value is empty" %self.name
60
60
61 if format == 'list':
61 if format == 'list':
62 strList = value.split(',')
62 strList = value.split(',')
63
63
64 self.__formated_value = strList
64 self.__formated_value = strList
65
65
66 return self.__formated_value
66 return self.__formated_value
67
67
68 if format == 'intlist':
68 if format == 'intlist':
69 """
69 """
70 Example:
70 Example:
71 value = (0,1,2)
71 value = (0,1,2)
72 """
72 """
73
73
74 new_value = ast.literal_eval(value)
74 new_value = ast.literal_eval(value)
75
75
76 if type(new_value) not in (tuple, list):
76 if type(new_value) not in (tuple, list):
77 new_value = [int(new_value)]
77 new_value = [int(new_value)]
78
78
79 self.__formated_value = new_value
79 self.__formated_value = new_value
80
80
81 return self.__formated_value
81 return self.__formated_value
82
82
83 if format == 'floatlist':
83 if format == 'floatlist':
84 """
84 """
85 Example:
85 Example:
86 value = (0.5, 1.4, 2.7)
86 value = (0.5, 1.4, 2.7)
87 """
87 """
88
88
89 new_value = ast.literal_eval(value)
89 new_value = ast.literal_eval(value)
90
90
91 if type(new_value) not in (tuple, list):
91 if type(new_value) not in (tuple, list):
92 new_value = [float(new_value)]
92 new_value = [float(new_value)]
93
93
94 self.__formated_value = new_value
94 self.__formated_value = new_value
95
95
96 return self.__formated_value
96 return self.__formated_value
97
97
98 if format == 'date':
98 if format == 'date':
99 strList = value.split('/')
99 strList = value.split('/')
100 intList = [int(x) for x in strList]
100 intList = [int(x) for x in strList]
101 date = datetime.date(intList[0], intList[1], intList[2])
101 date = datetime.date(intList[0], intList[1], intList[2])
102
102
103 self.__formated_value = date
103 self.__formated_value = date
104
104
105 return self.__formated_value
105 return self.__formated_value
106
106
107 if format == 'time':
107 if format == 'time':
108 strList = value.split(':')
108 strList = value.split(':')
109 intList = [int(x) for x in strList]
109 intList = [int(x) for x in strList]
110 time = datetime.time(intList[0], intList[1], intList[2])
110 time = datetime.time(intList[0], intList[1], intList[2])
111
111
112 self.__formated_value = time
112 self.__formated_value = time
113
113
114 return self.__formated_value
114 return self.__formated_value
115
115
116 if format == 'pairslist':
116 if format == 'pairslist':
117 """
117 """
118 Example:
118 Example:
119 value = (0,1),(1,2)
119 value = (0,1),(1,2)
120 """
120 """
121
121
122 new_value = ast.literal_eval(value)
122 new_value = ast.literal_eval(value)
123
123
124 if type(new_value) not in (tuple, list):
124 if type(new_value) not in (tuple, list):
125 raise ValueError, "%s has to be a tuple or list of pairs" %value
125 raise ValueError, "%s has to be a tuple or list of pairs" %value
126
126
127 if type(new_value[0]) not in (tuple, list):
127 if type(new_value[0]) not in (tuple, list):
128 if len(new_value) != 2:
128 if len(new_value) != 2:
129 raise ValueError, "%s has to be a tuple or list of pairs" %value
129 raise ValueError, "%s has to be a tuple or list of pairs" %value
130 new_value = [new_value]
130 new_value = [new_value]
131
131
132 for thisPair in new_value:
132 for thisPair in new_value:
133 if len(thisPair) != 2:
133 if len(thisPair) != 2:
134 raise ValueError, "%s has to be a tuple or list of pairs" %value
134 raise ValueError, "%s has to be a tuple or list of pairs" %value
135
135
136 self.__formated_value = new_value
136 self.__formated_value = new_value
137
137
138 return self.__formated_value
138 return self.__formated_value
139
139
140 if format == 'multilist':
140 if format == 'multilist':
141 """
141 """
142 Example:
142 Example:
143 value = (0,1,2),(3,4,5)
143 value = (0,1,2),(3,4,5)
144 """
144 """
145 multiList = ast.literal_eval(value)
145 multiList = ast.literal_eval(value)
146
146
147 if type(multiList[0]) == int:
147 if type(multiList[0]) == int:
148 multiList = ast.literal_eval("(" + value + ")")
148 multiList = ast.literal_eval("(" + value + ")")
149
149
150 self.__formated_value = multiList
150 self.__formated_value = multiList
151
151
152 return self.__formated_value
152 return self.__formated_value
153
153
154 if format == 'bool':
154 if format == 'bool':
155 value = int(value)
155 value = int(value)
156
156
157 if format == 'int':
157 if format == 'int':
158 value = float(value)
158 value = float(value)
159
159
160 format_func = eval(format)
160 format_func = eval(format)
161
161
162 self.__formated_value = format_func(value)
162 self.__formated_value = format_func(value)
163
163
164 return self.__formated_value
164 return self.__formated_value
165
165
166 def updateId(self, new_id):
166 def updateId(self, new_id):
167
167
168 self.id = str(new_id)
168 self.id = str(new_id)
169
169
170 def setup(self, id, name, value, format='str'):
170 def setup(self, id, name, value, format='str'):
171
171
172 self.id = str(id)
172 self.id = str(id)
173 self.name = name
173 self.name = name
174 self.value = str(value)
174 self.value = str(value)
175 self.format = str.lower(format)
175 self.format = str.lower(format)
176
176
177 self.getValue()
177 self.getValue()
178
178
179 return 1
179 return 1
180
180
181 def update(self, name, value, format='str'):
181 def update(self, name, value, format='str'):
182
182
183 self.name = name
183 self.name = name
184 self.value = str(value)
184 self.value = str(value)
185 self.format = format
185 self.format = format
186
186
187 def makeXml(self, opElement):
187 def makeXml(self, opElement):
188
188
189 parmElement = SubElement(opElement, self.ELEMENTNAME)
189 parmElement = SubElement(opElement, self.ELEMENTNAME)
190 parmElement.set('id', str(self.id))
190 parmElement.set('id', str(self.id))
191 parmElement.set('name', self.name)
191 parmElement.set('name', self.name)
192 parmElement.set('value', self.value)
192 parmElement.set('value', self.value)
193 parmElement.set('format', self.format)
193 parmElement.set('format', self.format)
194
194
195 def readXml(self, parmElement):
195 def readXml(self, parmElement):
196
196
197 self.id = parmElement.get('id')
197 self.id = parmElement.get('id')
198 self.name = parmElement.get('name')
198 self.name = parmElement.get('name')
199 self.value = parmElement.get('value')
199 self.value = parmElement.get('value')
200 self.format = str.lower(parmElement.get('format'))
200 self.format = str.lower(parmElement.get('format'))
201
201
202 #Compatible with old signal chain version
202 #Compatible with old signal chain version
203 if self.format == 'int' and self.name == 'idfigure':
203 if self.format == 'int' and self.name == 'idfigure':
204 self.name = 'id'
204 self.name = 'id'
205
205
206 def printattr(self):
206 def printattr(self):
207
207
208 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
208 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
209
209
210 class OperationConf():
210 class OperationConf():
211
211
212 id = None
212 id = None
213 name = None
213 name = None
214 priority = None
214 priority = None
215 type = None
215 type = None
216
216
217 parmConfObjList = []
217 parmConfObjList = []
218
218
219 ELEMENTNAME = 'Operation'
219 ELEMENTNAME = 'Operation'
220
220
221 def __init__(self):
221 def __init__(self):
222
222
223 self.id = '0'
223 self.id = '0'
224 self.name = None
224 self.name = None
225 self.priority = None
225 self.priority = None
226 self.type = 'self'
226 self.type = 'self'
227
227
228
228
229 def __getNewId(self):
229 def __getNewId(self):
230
230
231 return int(self.id)*10 + len(self.parmConfObjList) + 1
231 return int(self.id)*10 + len(self.parmConfObjList) + 1
232
232
233 def updateId(self, new_id):
233 def updateId(self, new_id):
234
234
235 self.id = str(new_id)
235 self.id = str(new_id)
236
236
237 n = 1
237 n = 1
238 for parmObj in self.parmConfObjList:
238 for parmObj in self.parmConfObjList:
239
239
240 idParm = str(int(new_id)*10 + n)
240 idParm = str(int(new_id)*10 + n)
241 parmObj.updateId(idParm)
241 parmObj.updateId(idParm)
242
242
243 n += 1
243 n += 1
244
244
245 def getElementName(self):
245 def getElementName(self):
246
246
247 return self.ELEMENTNAME
247 return self.ELEMENTNAME
248
248
249 def getParameterObjList(self):
249 def getParameterObjList(self):
250
250
251 return self.parmConfObjList
251 return self.parmConfObjList
252
252
253 def getParameterObj(self, parameterName):
253 def getParameterObj(self, parameterName):
254
254
255 for parmConfObj in self.parmConfObjList:
255 for parmConfObj in self.parmConfObjList:
256
256
257 if parmConfObj.name != parameterName:
257 if parmConfObj.name != parameterName:
258 continue
258 continue
259
259
260 return parmConfObj
260 return parmConfObj
261
261
262 return None
262 return None
263
263
264 def getParameterObjfromValue(self, parameterValue):
264 def getParameterObjfromValue(self, parameterValue):
265
265
266 for parmConfObj in self.parmConfObjList:
266 for parmConfObj in self.parmConfObjList:
267
267
268 if parmConfObj.getValue() != parameterValue:
268 if parmConfObj.getValue() != parameterValue:
269 continue
269 continue
270
270
271 return parmConfObj.getValue()
271 return parmConfObj.getValue()
272
272
273 return None
273 return None
274
274
275 def getParameterValue(self, parameterName):
275 def getParameterValue(self, parameterName):
276
276
277 parameterObj = self.getParameterObj(parameterName)
277 parameterObj = self.getParameterObj(parameterName)
278
278
279 # if not parameterObj:
279 # if not parameterObj:
280 # return None
280 # return None
281
281
282 value = parameterObj.getValue()
282 value = parameterObj.getValue()
283
283
284 return value
284 return value
285
285
286 def setup(self, id, name, priority, type):
286 def setup(self, id, name, priority, type):
287
287
288 self.id = str(id)
288 self.id = str(id)
289 self.name = name
289 self.name = name
290 self.type = type
290 self.type = type
291 self.priority = priority
291 self.priority = priority
292
292
293 self.parmConfObjList = []
293 self.parmConfObjList = []
294
294
295 def removeParameters(self):
295 def removeParameters(self):
296
296
297 for obj in self.parmConfObjList:
297 for obj in self.parmConfObjList:
298 del obj
298 del obj
299
299
300 self.parmConfObjList = []
300 self.parmConfObjList = []
301
301
302 def addParameter(self, name, value, format='str'):
302 def addParameter(self, name, value, format='str'):
303
303
304 id = self.__getNewId()
304 id = self.__getNewId()
305
305
306 parmConfObj = ParameterConf()
306 parmConfObj = ParameterConf()
307 if not parmConfObj.setup(id, name, value, format):
307 if not parmConfObj.setup(id, name, value, format):
308 return None
308 return None
309
309
310 self.parmConfObjList.append(parmConfObj)
310 self.parmConfObjList.append(parmConfObj)
311
311
312 return parmConfObj
312 return parmConfObj
313
313
314 def changeParameter(self, name, value, format='str'):
314 def changeParameter(self, name, value, format='str'):
315
315
316 parmConfObj = self.getParameterObj(name)
316 parmConfObj = self.getParameterObj(name)
317 parmConfObj.update(name, value, format)
317 parmConfObj.update(name, value, format)
318
318
319 return parmConfObj
319 return parmConfObj
320
320
321 def makeXml(self, procUnitElement):
321 def makeXml(self, procUnitElement):
322
322
323 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
323 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
324 opElement.set('id', str(self.id))
324 opElement.set('id', str(self.id))
325 opElement.set('name', self.name)
325 opElement.set('name', self.name)
326 opElement.set('type', self.type)
326 opElement.set('type', self.type)
327 opElement.set('priority', str(self.priority))
327 opElement.set('priority', str(self.priority))
328
328
329 for parmConfObj in self.parmConfObjList:
329 for parmConfObj in self.parmConfObjList:
330 parmConfObj.makeXml(opElement)
330 parmConfObj.makeXml(opElement)
331
331
332 def readXml(self, opElement):
332 def readXml(self, opElement):
333
333
334 self.id = opElement.get('id')
334 self.id = opElement.get('id')
335 self.name = opElement.get('name')
335 self.name = opElement.get('name')
336 self.type = opElement.get('type')
336 self.type = opElement.get('type')
337 self.priority = opElement.get('priority')
337 self.priority = opElement.get('priority')
338
338
339 #Compatible with old signal chain version
339 #Compatible with old signal chain version
340 #Use of 'run' method instead 'init'
340 #Use of 'run' method instead 'init'
341 if self.type == 'self' and self.name == 'init':
341 if self.type == 'self' and self.name == 'init':
342 self.name = 'run'
342 self.name = 'run'
343
343
344 self.parmConfObjList = []
344 self.parmConfObjList = []
345
345
346 parmElementList = opElement.getiterator(ParameterConf().getElementName())
346 parmElementList = opElement.iter(ParameterConf().getElementName())
347
347
348 for parmElement in parmElementList:
348 for parmElement in parmElementList:
349 parmConfObj = ParameterConf()
349 parmConfObj = ParameterConf()
350 parmConfObj.readXml(parmElement)
350 parmConfObj.readXml(parmElement)
351
351
352 #Compatible with old signal chain version
352 #Compatible with old signal chain version
353 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
353 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
354 if self.type != 'self' and self.name == 'Plot':
354 if self.type != 'self' and self.name == 'Plot':
355 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
355 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
356 self.name = parmConfObj.value
356 self.name = parmConfObj.value
357 continue
357 continue
358
358
359 self.parmConfObjList.append(parmConfObj)
359 self.parmConfObjList.append(parmConfObj)
360
360
361 def printattr(self):
361 def printattr(self):
362
362
363 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
363 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
364 self.id,
364 self.id,
365 self.name,
365 self.name,
366 self.type,
366 self.type,
367 self.priority)
367 self.priority)
368
368
369 for parmConfObj in self.parmConfObjList:
369 for parmConfObj in self.parmConfObjList:
370 parmConfObj.printattr()
370 parmConfObj.printattr()
371
371
372 def createObject(self, plotter_queue=None):
372 def createObject(self, plotter_queue=None):
373
373
374 if self.type == 'self':
374 if self.type == 'self':
375 raise ValueError, "This operation type cannot be created"
375 raise ValueError, "This operation type cannot be created"
376
376
377 if self.type == 'plotter':
377 if self.type == 'plotter':
378 #Plotter(plotter_name)
378 #Plotter(plotter_name)
379 if not plotter_queue:
379 if not plotter_queue:
380 raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)"
380 raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)"
381
381
382 opObj = Plotter(self.name, plotter_queue)
382 opObj = Plotter(self.name, plotter_queue)
383
383
384 if self.type == 'external' or self.type == 'other':
384 if self.type == 'external' or self.type == 'other':
385 className = eval(self.name)
385 className = eval(self.name)
386 opObj = className()
386 opObj = className()
387
387
388 return opObj
388 return opObj
389
389
390 class ProcUnitConf():
390 class ProcUnitConf():
391
391
392 id = None
392 id = None
393 name = None
393 name = None
394 datatype = None
394 datatype = None
395 inputId = None
395 inputId = None
396 parentId = None
396 parentId = None
397
397
398 opConfObjList = []
398 opConfObjList = []
399
399
400 procUnitObj = None
400 procUnitObj = None
401 opObjList = []
401 opObjList = []
402
402
403 ELEMENTNAME = 'ProcUnit'
403 ELEMENTNAME = 'ProcUnit'
404
404
405 def __init__(self):
405 def __init__(self):
406
406
407 self.id = None
407 self.id = None
408 self.datatype = None
408 self.datatype = None
409 self.name = None
409 self.name = None
410 self.inputId = None
410 self.inputId = None
411
411
412 self.opConfObjList = []
412 self.opConfObjList = []
413
413
414 self.procUnitObj = None
414 self.procUnitObj = None
415 self.opObjDict = {}
415 self.opObjDict = {}
416
416
417 def __getPriority(self):
417 def __getPriority(self):
418
418
419 return len(self.opConfObjList)+1
419 return len(self.opConfObjList)+1
420
420
421 def __getNewId(self):
421 def __getNewId(self):
422
422
423 return int(self.id)*10 + len(self.opConfObjList) + 1
423 return int(self.id)*10 + len(self.opConfObjList) + 1
424
424
425 def getElementName(self):
425 def getElementName(self):
426
426
427 return self.ELEMENTNAME
427 return self.ELEMENTNAME
428
428
429 def getId(self):
429 def getId(self):
430
430
431 return self.id
431 return self.id
432
432
433 def updateId(self, new_id, parentId=parentId):
433 def updateId(self, new_id, parentId=parentId):
434
434
435
435
436 new_id = int(parentId)*10 + (int(self.id) % 10)
436 new_id = int(parentId)*10 + (int(self.id) % 10)
437 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
437 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
438
438
439 #If this proc unit has not inputs
439 #If this proc unit has not inputs
440 if self.inputId == '0':
440 if self.inputId == '0':
441 new_inputId = 0
441 new_inputId = 0
442
442
443 n = 1
443 n = 1
444 for opConfObj in self.opConfObjList:
444 for opConfObj in self.opConfObjList:
445
445
446 idOp = str(int(new_id)*10 + n)
446 idOp = str(int(new_id)*10 + n)
447 opConfObj.updateId(idOp)
447 opConfObj.updateId(idOp)
448
448
449 n += 1
449 n += 1
450
450
451 self.parentId = str(parentId)
451 self.parentId = str(parentId)
452 self.id = str(new_id)
452 self.id = str(new_id)
453 self.inputId = str(new_inputId)
453 self.inputId = str(new_inputId)
454
454
455
455
456 def getInputId(self):
456 def getInputId(self):
457
457
458 return self.inputId
458 return self.inputId
459
459
460 def getOperationObjList(self):
460 def getOperationObjList(self):
461
461
462 return self.opConfObjList
462 return self.opConfObjList
463
463
464 def getOperationObj(self, name=None):
464 def getOperationObj(self, name=None):
465
465
466 for opConfObj in self.opConfObjList:
466 for opConfObj in self.opConfObjList:
467
467
468 if opConfObj.name != name:
468 if opConfObj.name != name:
469 continue
469 continue
470
470
471 return opConfObj
471 return opConfObj
472
472
473 return None
473 return None
474
474
475 def getOpObjfromParamValue(self, value=None):
475 def getOpObjfromParamValue(self, value=None):
476
476
477 for opConfObj in self.opConfObjList:
477 for opConfObj in self.opConfObjList:
478 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
478 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
479 continue
479 continue
480 return opConfObj
480 return opConfObj
481 return None
481 return None
482
482
483 def getProcUnitObj(self):
483 def getProcUnitObj(self):
484
484
485 return self.procUnitObj
485 return self.procUnitObj
486
486
487 def setup(self, id, name, datatype, inputId, parentId=None):
487 def setup(self, id, name, datatype, inputId, parentId=None):
488
488
489 #Compatible with old signal chain version
489 #Compatible with old signal chain version
490 if datatype==None and name==None:
490 if datatype==None and name==None:
491 raise ValueError, "datatype or name should be defined"
491 raise ValueError, "datatype or name should be defined"
492
492
493 if name==None:
493 if name==None:
494 if 'Proc' in datatype:
494 if 'Proc' in datatype:
495 name = datatype
495 name = datatype
496 else:
496 else:
497 name = '%sProc' %(datatype)
497 name = '%sProc' %(datatype)
498
498
499 if datatype==None:
499 if datatype==None:
500 datatype = name.replace('Proc','')
500 datatype = name.replace('Proc','')
501
501
502 self.id = str(id)
502 self.id = str(id)
503 self.name = name
503 self.name = name
504 self.datatype = datatype
504 self.datatype = datatype
505 self.inputId = inputId
505 self.inputId = inputId
506 self.parentId = parentId
506 self.parentId = parentId
507
507
508 self.opConfObjList = []
508 self.opConfObjList = []
509
509
510 self.addOperation(name='run', optype='self')
510 self.addOperation(name='run', optype='self')
511
511
512 def removeOperations(self):
512 def removeOperations(self):
513
513
514 for obj in self.opConfObjList:
514 for obj in self.opConfObjList:
515 del obj
515 del obj
516
516
517 self.opConfObjList = []
517 self.opConfObjList = []
518 self.addOperation(name='run')
518 self.addOperation(name='run')
519
519
520 def addParameter(self, **kwargs):
520 def addParameter(self, **kwargs):
521 '''
521 '''
522 Add parameters to "run" operation
522 Add parameters to "run" operation
523 '''
523 '''
524 opObj = self.opConfObjList[0]
524 opObj = self.opConfObjList[0]
525
525
526 opObj.addParameter(**kwargs)
526 opObj.addParameter(**kwargs)
527
527
528 return opObj
528 return opObj
529
529
530 def addOperation(self, name, optype='self'):
530 def addOperation(self, name, optype='self'):
531
531
532 id = self.__getNewId()
532 id = self.__getNewId()
533 priority = self.__getPriority()
533 priority = self.__getPriority()
534
534
535 opConfObj = OperationConf()
535 opConfObj = OperationConf()
536 opConfObj.setup(id, name=name, priority=priority, type=optype)
536 opConfObj.setup(id, name=name, priority=priority, type=optype)
537
537
538 self.opConfObjList.append(opConfObj)
538 self.opConfObjList.append(opConfObj)
539
539
540 return opConfObj
540 return opConfObj
541
541
542 def makeXml(self, projectElement):
542 def makeXml(self, projectElement):
543
543
544 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
544 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
545 procUnitElement.set('id', str(self.id))
545 procUnitElement.set('id', str(self.id))
546 procUnitElement.set('name', self.name)
546 procUnitElement.set('name', self.name)
547 procUnitElement.set('datatype', self.datatype)
547 procUnitElement.set('datatype', self.datatype)
548 procUnitElement.set('inputId', str(self.inputId))
548 procUnitElement.set('inputId', str(self.inputId))
549
549
550 for opConfObj in self.opConfObjList:
550 for opConfObj in self.opConfObjList:
551 opConfObj.makeXml(procUnitElement)
551 opConfObj.makeXml(procUnitElement)
552
552
553 def readXml(self, upElement):
553 def readXml(self, upElement):
554
554
555 self.id = upElement.get('id')
555 self.id = upElement.get('id')
556 self.name = upElement.get('name')
556 self.name = upElement.get('name')
557 self.datatype = upElement.get('datatype')
557 self.datatype = upElement.get('datatype')
558 self.inputId = upElement.get('inputId')
558 self.inputId = upElement.get('inputId')
559
559
560 if self.ELEMENTNAME == "ReadUnit":
560 if self.ELEMENTNAME == "ReadUnit":
561 self.datatype = self.datatype.replace("Reader", "")
561 self.datatype = self.datatype.replace("Reader", "")
562
562
563 if self.ELEMENTNAME == "ProcUnit":
563 if self.ELEMENTNAME == "ProcUnit":
564 self.datatype = self.datatype.replace("Proc", "")
564 self.datatype = self.datatype.replace("Proc", "")
565
565
566 if self.inputId == 'None':
566 if self.inputId == 'None':
567 self.inputId = '0'
567 self.inputId = '0'
568
568
569 self.opConfObjList = []
569 self.opConfObjList = []
570
570
571 opElementList = upElement.getiterator(OperationConf().getElementName())
571 opElementList = upElement.iter(OperationConf().getElementName())
572
572
573 for opElement in opElementList:
573 for opElement in opElementList:
574 opConfObj = OperationConf()
574 opConfObj = OperationConf()
575 opConfObj.readXml(opElement)
575 opConfObj.readXml(opElement)
576 self.opConfObjList.append(opConfObj)
576 self.opConfObjList.append(opConfObj)
577
577
578 def printattr(self):
578 def printattr(self):
579
579
580 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
580 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
581 self.id,
581 self.id,
582 self.name,
582 self.name,
583 self.datatype,
583 self.datatype,
584 self.inputId)
584 self.inputId)
585
585
586 for opConfObj in self.opConfObjList:
586 for opConfObj in self.opConfObjList:
587 opConfObj.printattr()
587 opConfObj.printattr()
588
588
589 def createObjects(self, plotter_queue=None):
589 def createObjects(self, plotter_queue=None):
590
590
591 className = eval(self.name)
591 className = eval(self.name)
592 procUnitObj = className()
592 procUnitObj = className()
593
593
594 for opConfObj in self.opConfObjList:
594 for opConfObj in self.opConfObjList:
595
595
596 if opConfObj.type == 'self':
596 if opConfObj.type == 'self':
597 continue
597 continue
598
598
599 opObj = opConfObj.createObject(plotter_queue)
599 opObj = opConfObj.createObject(plotter_queue)
600
600
601 self.opObjDict[opConfObj.id] = opObj
601 self.opObjDict[opConfObj.id] = opObj
602 procUnitObj.addOperation(opObj, opConfObj.id)
602 procUnitObj.addOperation(opObj, opConfObj.id)
603
603
604 self.procUnitObj = procUnitObj
604 self.procUnitObj = procUnitObj
605
605
606 return procUnitObj
606 return procUnitObj
607
607
608 def run(self):
608 def run(self):
609
609
610 is_ok = False
610 is_ok = False
611
611
612 for opConfObj in self.opConfObjList:
612 for opConfObj in self.opConfObjList:
613
613
614 kwargs = {}
614 kwargs = {}
615 for parmConfObj in opConfObj.getParameterObjList():
615 for parmConfObj in opConfObj.getParameterObjList():
616 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
616 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
617 continue
617 continue
618
618
619 kwargs[parmConfObj.name] = parmConfObj.getValue()
619 kwargs[parmConfObj.name] = parmConfObj.getValue()
620
620
621 ini = time.time()
621 ini = time.time()
622
622
623 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
623 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
624 sts = self.procUnitObj.call(opType = opConfObj.type,
624 sts = self.procUnitObj.call(opType = opConfObj.type,
625 opName = opConfObj.name,
625 opName = opConfObj.name,
626 opId = opConfObj.id,
626 opId = opConfObj.id,
627 **kwargs)
627 **kwargs)
628
628
629 # total_time = time.time() - ini
629 # total_time = time.time() - ini
630 #
630 #
631 # if total_time > 0.002:
631 # if total_time > 0.002:
632 # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time)
632 # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time)
633
633
634 is_ok = is_ok or sts
634 is_ok = is_ok or sts
635
635
636 return is_ok
636 return is_ok
637
637
638 def close(self):
638 def close(self):
639
639
640 for opConfObj in self.opConfObjList:
640 for opConfObj in self.opConfObjList:
641 if opConfObj.type == 'self':
641 if opConfObj.type == 'self':
642 continue
642 continue
643
643
644 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
644 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
645 opObj.close()
645 opObj.close()
646
646
647 self.procUnitObj.close()
647 self.procUnitObj.close()
648
648
649 return
649 return
650
650
651 class ReadUnitConf(ProcUnitConf):
651 class ReadUnitConf(ProcUnitConf):
652
652
653 path = None
653 path = None
654 startDate = None
654 startDate = None
655 endDate = None
655 endDate = None
656 startTime = None
656 startTime = None
657 endTime = None
657 endTime = None
658
658
659 ELEMENTNAME = 'ReadUnit'
659 ELEMENTNAME = 'ReadUnit'
660
660
661 def __init__(self):
661 def __init__(self):
662
662
663 self.id = None
663 self.id = None
664 self.datatype = None
664 self.datatype = None
665 self.name = None
665 self.name = None
666 self.inputId = None
666 self.inputId = None
667
667
668 self.parentId = None
668 self.parentId = None
669
669
670 self.opConfObjList = []
670 self.opConfObjList = []
671 self.opObjList = []
671 self.opObjList = []
672
672
673 def getElementName(self):
673 def getElementName(self):
674
674
675 return self.ELEMENTNAME
675 return self.ELEMENTNAME
676
676
677 def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs):
677 def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs):
678
678
679 #Compatible with old signal chain version
679 #Compatible with old signal chain version
680 if datatype==None and name==None:
680 if datatype==None and name==None:
681 raise ValueError, "datatype or name should be defined"
681 raise ValueError, "datatype or name should be defined"
682
682
683 if name==None:
683 if name==None:
684 if 'Reader' in datatype:
684 if 'Reader' in datatype:
685 name = datatype
685 name = datatype
686 else:
686 else:
687 name = '%sReader' %(datatype)
687 name = '%sReader' %(datatype)
688
688
689 if datatype==None:
689 if datatype==None:
690 datatype = name.replace('Reader','')
690 datatype = name.replace('Reader','')
691
691
692 self.id = id
692 self.id = id
693 self.name = name
693 self.name = name
694 self.datatype = datatype
694 self.datatype = datatype
695
695
696 self.path = os.path.abspath(path)
696 self.path = os.path.abspath(path)
697 self.startDate = startDate
697 self.startDate = startDate
698 self.endDate = endDate
698 self.endDate = endDate
699 self.startTime = startTime
699 self.startTime = startTime
700 self.endTime = endTime
700 self.endTime = endTime
701
701
702 self.inputId = '0'
702 self.inputId = '0'
703 self.parentId = parentId
703 self.parentId = parentId
704
704
705 self.addRunOperation(**kwargs)
705 self.addRunOperation(**kwargs)
706
706
707 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
707 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
708
708
709 #Compatible with old signal chain version
709 #Compatible with old signal chain version
710 if datatype==None and name==None:
710 if datatype==None and name==None:
711 raise ValueError, "datatype or name should be defined"
711 raise ValueError, "datatype or name should be defined"
712
712
713 if name==None:
713 if name==None:
714 if 'Reader' in datatype:
714 if 'Reader' in datatype:
715 name = datatype
715 name = datatype
716 else:
716 else:
717 name = '%sReader' %(datatype)
717 name = '%sReader' %(datatype)
718
718
719 if datatype==None:
719 if datatype==None:
720 datatype = name.replace('Reader','')
720 datatype = name.replace('Reader','')
721
721
722 self.datatype = datatype
722 self.datatype = datatype
723 self.name = name
723 self.name = name
724 self.path = path
724 self.path = path
725 self.startDate = startDate
725 self.startDate = startDate
726 self.endDate = endDate
726 self.endDate = endDate
727 self.startTime = startTime
727 self.startTime = startTime
728 self.endTime = endTime
728 self.endTime = endTime
729
729
730 self.inputId = '0'
730 self.inputId = '0'
731 self.parentId = parentId
731 self.parentId = parentId
732
732
733 self.updateRunOperation(**kwargs)
733 self.updateRunOperation(**kwargs)
734
734
735 def removeOperations(self):
735 def removeOperations(self):
736
736
737 for obj in self.opConfObjList:
737 for obj in self.opConfObjList:
738 del obj
738 del obj
739
739
740 self.opConfObjList = []
740 self.opConfObjList = []
741
741
742 def addRunOperation(self, **kwargs):
742 def addRunOperation(self, **kwargs):
743
743
744 opObj = self.addOperation(name = 'run', optype = 'self')
744 opObj = self.addOperation(name = 'run', optype = 'self')
745
745
746 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
746 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
747 opObj.addParameter(name='path' , value=self.path, format='str')
747 opObj.addParameter(name='path' , value=self.path, format='str')
748 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
748 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
749 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
749 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
750 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
750 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
751 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
751 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
752
752
753 for key, value in kwargs.items():
753 for key, value in kwargs.items():
754 opObj.addParameter(name=key, value=value, format=type(value).__name__)
754 opObj.addParameter(name=key, value=value, format=type(value).__name__)
755
755
756 return opObj
756 return opObj
757
757
758 def updateRunOperation(self, **kwargs):
758 def updateRunOperation(self, **kwargs):
759
759
760 opObj = self.getOperationObj(name = 'run')
760 opObj = self.getOperationObj(name = 'run')
761 opObj.removeParameters()
761 opObj.removeParameters()
762
762
763 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
763 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
764 opObj.addParameter(name='path' , value=self.path, format='str')
764 opObj.addParameter(name='path' , value=self.path, format='str')
765 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
765 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
766 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
766 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
767 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
767 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
768 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
768 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
769
769
770 for key, value in kwargs.items():
770 for key, value in kwargs.items():
771 opObj.addParameter(name=key, value=value, format=type(value).__name__)
771 opObj.addParameter(name=key, value=value, format=type(value).__name__)
772
772
773 return opObj
773 return opObj
774
774
775 # def makeXml(self, projectElement):
775 # def makeXml(self, projectElement):
776 #
776 #
777 # procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
777 # procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
778 # procUnitElement.set('id', str(self.id))
778 # procUnitElement.set('id', str(self.id))
779 # procUnitElement.set('name', self.name)
779 # procUnitElement.set('name', self.name)
780 # procUnitElement.set('datatype', self.datatype)
780 # procUnitElement.set('datatype', self.datatype)
781 # procUnitElement.set('inputId', str(self.inputId))
781 # procUnitElement.set('inputId', str(self.inputId))
782 #
782 #
783 # for opConfObj in self.opConfObjList:
783 # for opConfObj in self.opConfObjList:
784 # opConfObj.makeXml(procUnitElement)
784 # opConfObj.makeXml(procUnitElement)
785
785
786 def readXml(self, upElement):
786 def readXml(self, upElement):
787
787
788 self.id = upElement.get('id')
788 self.id = upElement.get('id')
789 self.name = upElement.get('name')
789 self.name = upElement.get('name')
790 self.datatype = upElement.get('datatype')
790 self.datatype = upElement.get('datatype')
791 self.inputId = upElement.get('inputId')
791 self.inputId = upElement.get('inputId')
792
792
793 if self.ELEMENTNAME == "ReadUnit":
793 if self.ELEMENTNAME == "ReadUnit":
794 self.datatype = self.datatype.replace("Reader", "")
794 self.datatype = self.datatype.replace("Reader", "")
795
795
796 if self.inputId == 'None':
796 if self.inputId == 'None':
797 self.inputId = '0'
797 self.inputId = '0'
798
798
799 self.opConfObjList = []
799 self.opConfObjList = []
800
800
801 opElementList = upElement.getiterator(OperationConf().getElementName())
801 opElementList = upElement.iter(OperationConf().getElementName())
802
802
803 for opElement in opElementList:
803 for opElement in opElementList:
804 opConfObj = OperationConf()
804 opConfObj = OperationConf()
805 opConfObj.readXml(opElement)
805 opConfObj.readXml(opElement)
806 self.opConfObjList.append(opConfObj)
806 self.opConfObjList.append(opConfObj)
807
807
808 if opConfObj.name == 'run':
808 if opConfObj.name == 'run':
809 self.path = opConfObj.getParameterValue('path')
809 self.path = opConfObj.getParameterValue('path')
810 self.startDate = opConfObj.getParameterValue('startDate')
810 self.startDate = opConfObj.getParameterValue('startDate')
811 self.endDate = opConfObj.getParameterValue('endDate')
811 self.endDate = opConfObj.getParameterValue('endDate')
812 self.startTime = opConfObj.getParameterValue('startTime')
812 self.startTime = opConfObj.getParameterValue('startTime')
813 self.endTime = opConfObj.getParameterValue('endTime')
813 self.endTime = opConfObj.getParameterValue('endTime')
814
814
815 class Project():
815 class Project():
816
816
817 id = None
817 id = None
818 name = None
818 name = None
819 description = None
819 description = None
820 filename = None
820 filename = None
821
821
822 procUnitConfObjDict = None
822 procUnitConfObjDict = None
823
823
824 ELEMENTNAME = 'Project'
824 ELEMENTNAME = 'Project'
825
825
826 plotterQueue = None
826 plotterQueue = None
827
827
828 def __init__(self, plotter_queue=None):
828 def __init__(self, plotter_queue=None):
829
829
830 self.id = None
830 self.id = None
831 self.name = None
831 self.name = None
832 self.description = None
832 self.description = None
833
833
834 self.plotterQueue = plotter_queue
834 self.plotterQueue = plotter_queue
835
835
836 self.procUnitConfObjDict = {}
836 self.procUnitConfObjDict = {}
837
837
838 def __getNewId(self):
838 def __getNewId(self):
839
839
840 idList = self.procUnitConfObjDict.keys()
840 idList = self.procUnitConfObjDict.keys()
841
841
842 id = int(self.id)*10
842 id = int(self.id)*10
843
843
844 while True:
844 while True:
845 id += 1
845 id += 1
846
846
847 if str(id) in idList:
847 if str(id) in idList:
848 continue
848 continue
849
849
850 break
850 break
851
851
852 return str(id)
852 return str(id)
853
853
854 def getElementName(self):
854 def getElementName(self):
855
855
856 return self.ELEMENTNAME
856 return self.ELEMENTNAME
857
857
858 def getId(self):
858 def getId(self):
859
859
860 return self.id
860 return self.id
861
861
862 def updateId(self, new_id):
862 def updateId(self, new_id):
863
863
864 self.id = str(new_id)
864 self.id = str(new_id)
865
865
866 keyList = self.procUnitConfObjDict.keys()
866 keyList = self.procUnitConfObjDict.keys()
867 keyList.sort()
867 keyList.sort()
868
868
869 n = 1
869 n = 1
870 newProcUnitConfObjDict = {}
870 newProcUnitConfObjDict = {}
871
871
872 for procKey in keyList:
872 for procKey in keyList:
873
873
874 procUnitConfObj = self.procUnitConfObjDict[procKey]
874 procUnitConfObj = self.procUnitConfObjDict[procKey]
875 idProcUnit = str(int(self.id)*10 + n)
875 idProcUnit = str(int(self.id)*10 + n)
876 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
876 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
877
877
878 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
878 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
879 n += 1
879 n += 1
880
880
881 self.procUnitConfObjDict = newProcUnitConfObjDict
881 self.procUnitConfObjDict = newProcUnitConfObjDict
882
882
883 def setup(self, id, name, description):
883 def setup(self, id, name, description):
884
884
885 self.id = str(id)
885 self.id = str(id)
886 self.name = name
886 self.name = name
887 self.description = description
887 self.description = description
888
888
889 def update(self, name, description):
889 def update(self, name, description):
890
890
891 self.name = name
891 self.name = name
892 self.description = description
892 self.description = description
893
893
894 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
894 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
895
895
896 if id is None:
896 if id is None:
897 idReadUnit = self.__getNewId()
897 idReadUnit = self.__getNewId()
898 else:
898 else:
899 idReadUnit = str(id)
899 idReadUnit = str(id)
900
900
901 readUnitConfObj = ReadUnitConf()
901 readUnitConfObj = ReadUnitConf()
902 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
902 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
903
903
904 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
904 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
905
905
906 return readUnitConfObj
906 return readUnitConfObj
907
907
908 def addProcUnit(self, inputId='0', datatype=None, name=None):
908 def addProcUnit(self, inputId='0', datatype=None, name=None):
909
909
910 idProcUnit = self.__getNewId()
910 idProcUnit = self.__getNewId()
911
911
912 procUnitConfObj = ProcUnitConf()
912 procUnitConfObj = ProcUnitConf()
913 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
913 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
914
914
915 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
915 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
916
916
917 return procUnitConfObj
917 return procUnitConfObj
918
918
919 def removeProcUnit(self, id):
919 def removeProcUnit(self, id):
920
920
921 if id in self.procUnitConfObjDict.keys():
921 if id in self.procUnitConfObjDict.keys():
922 self.procUnitConfObjDict.pop(id)
922 self.procUnitConfObjDict.pop(id)
923
923
924 def getReadUnitId(self):
924 def getReadUnitId(self):
925
925
926 readUnitConfObj = self.getReadUnitObj()
926 readUnitConfObj = self.getReadUnitObj()
927
927
928 return readUnitConfObj.id
928 return readUnitConfObj.id
929
929
930 def getReadUnitObj(self):
930 def getReadUnitObj(self):
931
931
932 for obj in self.procUnitConfObjDict.values():
932 for obj in self.procUnitConfObjDict.values():
933 if obj.getElementName() == "ReadUnit":
933 if obj.getElementName() == "ReadUnit":
934 return obj
934 return obj
935
935
936 return None
936 return None
937
937
938 def getProcUnitObj(self, id=None, name=None):
938 def getProcUnitObj(self, id=None, name=None):
939
939
940 if id != None:
940 if id != None:
941 return self.procUnitConfObjDict[id]
941 return self.procUnitConfObjDict[id]
942
942
943 if name != None:
943 if name != None:
944 return self.getProcUnitObjByName(name)
944 return self.getProcUnitObjByName(name)
945
945
946 return None
946 return None
947
947
948 def getProcUnitObjByName(self, name):
948 def getProcUnitObjByName(self, name):
949
949
950 for obj in self.procUnitConfObjDict.values():
950 for obj in self.procUnitConfObjDict.values():
951 if obj.name == name:
951 if obj.name == name:
952 return obj
952 return obj
953
953
954 return None
954 return None
955
955
956 def procUnitItems(self):
956 def procUnitItems(self):
957
957
958 return self.procUnitConfObjDict.items()
958 return self.procUnitConfObjDict.items()
959
959
960 def makeXml(self):
960 def makeXml(self):
961
961
962 projectElement = Element('Project')
962 projectElement = Element('Project')
963 projectElement.set('id', str(self.id))
963 projectElement.set('id', str(self.id))
964 projectElement.set('name', self.name)
964 projectElement.set('name', self.name)
965 projectElement.set('description', self.description)
965 projectElement.set('description', self.description)
966
966
967 for procUnitConfObj in self.procUnitConfObjDict.values():
967 for procUnitConfObj in self.procUnitConfObjDict.values():
968 procUnitConfObj.makeXml(projectElement)
968 procUnitConfObj.makeXml(projectElement)
969
969
970 self.projectElement = projectElement
970 self.projectElement = projectElement
971
971
972 def writeXml(self, filename=None):
972 def writeXml(self, filename=None):
973
973
974 if filename == None:
974 if filename == None:
975 if self.filename:
975 if self.filename:
976 filename = self.filename
976 filename = self.filename
977 else:
977 else:
978 filename = "schain.xml"
978 filename = "schain.xml"
979
979
980 if not filename:
980 if not filename:
981 print "filename has not been defined. Use setFilename(filename) for do it."
981 print "filename has not been defined. Use setFilename(filename) for do it."
982 return 0
982 return 0
983
983
984 abs_file = os.path.abspath(filename)
984 abs_file = os.path.abspath(filename)
985
985
986 if not os.access(os.path.dirname(abs_file), os.W_OK):
986 if not os.access(os.path.dirname(abs_file), os.W_OK):
987 print "No write permission on %s" %os.path.dirname(abs_file)
987 print "No write permission on %s" %os.path.dirname(abs_file)
988 return 0
988 return 0
989
989
990 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
990 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
991 print "File %s already exists and it could not be overwriten" %abs_file
991 print "File %s already exists and it could not be overwriten" %abs_file
992 return 0
992 return 0
993
993
994 self.makeXml()
994 self.makeXml()
995
995
996 ElementTree(self.projectElement).write(abs_file, method='xml')
996 ElementTree(self.projectElement).write(abs_file, method='xml')
997
997
998 self.filename = abs_file
998 self.filename = abs_file
999
999
1000 return 1
1000 return 1
1001
1001
1002 def readXml(self, filename = None):
1002 def readXml(self, filename = None):
1003
1003
1004 if not filename:
1004 if not filename:
1005 print "filename is not defined"
1005 print "filename is not defined"
1006 return 0
1006 return 0
1007
1007
1008 abs_file = os.path.abspath(filename)
1008 abs_file = os.path.abspath(filename)
1009
1009
1010 if not os.path.isfile(abs_file):
1010 if not os.path.isfile(abs_file):
1011 print "%s file does not exist" %abs_file
1011 print "%s file does not exist" %abs_file
1012 return 0
1012 return 0
1013
1013
1014 self.projectElement = None
1014 self.projectElement = None
1015 self.procUnitConfObjDict = {}
1015 self.procUnitConfObjDict = {}
1016
1016
1017 try:
1017 try:
1018 self.projectElement = ElementTree().parse(abs_file)
1018 self.projectElement = ElementTree().parse(abs_file)
1019 except:
1019 except:
1020 print "Error reading %s, verify file format" %filename
1020 print "Error reading %s, verify file format" %filename
1021 return 0
1021 return 0
1022
1022
1023 self.project = self.projectElement.tag
1023 self.project = self.projectElement.tag
1024
1024
1025 self.id = self.projectElement.get('id')
1025 self.id = self.projectElement.get('id')
1026 self.name = self.projectElement.get('name')
1026 self.name = self.projectElement.get('name')
1027 self.description = self.projectElement.get('description')
1027 self.description = self.projectElement.get('description')
1028
1028
1029 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
1029 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1030
1030
1031 for readUnitElement in readUnitElementList:
1031 for readUnitElement in readUnitElementList:
1032 readUnitConfObj = ReadUnitConf()
1032 readUnitConfObj = ReadUnitConf()
1033 readUnitConfObj.readXml(readUnitElement)
1033 readUnitConfObj.readXml(readUnitElement)
1034
1034
1035 if readUnitConfObj.parentId == None:
1035 if readUnitConfObj.parentId == None:
1036 readUnitConfObj.parentId = self.id
1036 readUnitConfObj.parentId = self.id
1037
1037
1038 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1038 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1039
1039
1040 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
1040 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1041
1041
1042 for procUnitElement in procUnitElementList:
1042 for procUnitElement in procUnitElementList:
1043 procUnitConfObj = ProcUnitConf()
1043 procUnitConfObj = ProcUnitConf()
1044 procUnitConfObj.readXml(procUnitElement)
1044 procUnitConfObj.readXml(procUnitElement)
1045
1045
1046 if procUnitConfObj.parentId == None:
1046 if procUnitConfObj.parentId == None:
1047 procUnitConfObj.parentId = self.id
1047 procUnitConfObj.parentId = self.id
1048
1048
1049 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1049 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1050
1050
1051 self.filename = abs_file
1051 self.filename = abs_file
1052
1052
1053 return 1
1053 return 1
1054
1054
1055 def printattr(self):
1055 def printattr(self):
1056
1056
1057 print "Project[%s]: name = %s, description = %s" %(self.id,
1057 print "Project[%s]: name = %s, description = %s" %(self.id,
1058 self.name,
1058 self.name,
1059 self.description)
1059 self.description)
1060
1060
1061 for procUnitConfObj in self.procUnitConfObjDict.values():
1061 for procUnitConfObj in self.procUnitConfObjDict.values():
1062 procUnitConfObj.printattr()
1062 procUnitConfObj.printattr()
1063
1063
1064 def createObjects(self):
1064 def createObjects(self):
1065
1065
1066 for procUnitConfObj in self.procUnitConfObjDict.values():
1066 for procUnitConfObj in self.procUnitConfObjDict.values():
1067 procUnitConfObj.createObjects(self.plotterQueue)
1067 procUnitConfObj.createObjects(self.plotterQueue)
1068
1068
1069 def __connect(self, objIN, thisObj):
1069 def __connect(self, objIN, thisObj):
1070
1070
1071 thisObj.setInput(objIN.getOutputObj())
1071 thisObj.setInput(objIN.getOutputObj())
1072
1072
1073 def connectObjects(self):
1073 def connectObjects(self):
1074
1074
1075 for thisPUConfObj in self.procUnitConfObjDict.values():
1075 for thisPUConfObj in self.procUnitConfObjDict.values():
1076
1076
1077 inputId = thisPUConfObj.getInputId()
1077 inputId = thisPUConfObj.getInputId()
1078
1078
1079 if int(inputId) == 0:
1079 if int(inputId) == 0:
1080 continue
1080 continue
1081
1081
1082 #Get input object
1082 #Get input object
1083 puConfINObj = self.procUnitConfObjDict[inputId]
1083 puConfINObj = self.procUnitConfObjDict[inputId]
1084 puObjIN = puConfINObj.getProcUnitObj()
1084 puObjIN = puConfINObj.getProcUnitObj()
1085
1085
1086 #Get current object
1086 #Get current object
1087 thisPUObj = thisPUConfObj.getProcUnitObj()
1087 thisPUObj = thisPUConfObj.getProcUnitObj()
1088
1088
1089 self.__connect(puObjIN, thisPUObj)
1089 self.__connect(puObjIN, thisPUObj)
1090
1090
1091 def __handleError(self, procUnitConfObj, send_email=True):
1091 def __handleError(self, procUnitConfObj, send_email=True):
1092
1092
1093 import socket
1093 import socket
1094
1094
1095 err = traceback.format_exception(sys.exc_info()[0],
1095 err = traceback.format_exception(sys.exc_info()[0],
1096 sys.exc_info()[1],
1096 sys.exc_info()[1],
1097 sys.exc_info()[2])
1097 sys.exc_info()[2])
1098
1098
1099 print "***** Error occurred in %s *****" %(procUnitConfObj.name)
1099 print "***** Error occurred in %s *****" %(procUnitConfObj.name)
1100 print "***** %s" %err[-1]
1100 print "***** %s" %err[-1]
1101
1101
1102 message = "".join(err)
1102 message = "".join(err)
1103
1103
1104 sys.stderr.write(message)
1104 sys.stderr.write(message)
1105
1105
1106 if not send_email:
1106 if not send_email:
1107 return
1107 return
1108
1108
1109 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name)
1109 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name)
1110
1110
1111 subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1111 subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1112 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
1112 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
1113 subtitle += "Working directory: %s\n" %os.path.abspath("./")
1113 subtitle += "Working directory: %s\n" %os.path.abspath("./")
1114 subtitle += "Configuration file: %s\n" %self.filename
1114 subtitle += "Configuration file: %s\n" %self.filename
1115 subtitle += "Time: %s\n" %str(datetime.datetime.now())
1115 subtitle += "Time: %s\n" %str(datetime.datetime.now())
1116
1116
1117 readUnitConfObj = self.getReadUnitObj()
1117 readUnitConfObj = self.getReadUnitObj()
1118 if readUnitConfObj:
1118 if readUnitConfObj:
1119 subtitle += "\nInput parameters:\n"
1119 subtitle += "\nInput parameters:\n"
1120 subtitle += "[Data path = %s]\n" %readUnitConfObj.path
1120 subtitle += "[Data path = %s]\n" %readUnitConfObj.path
1121 subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype
1121 subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype
1122 subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate
1122 subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate
1123 subtitle += "[End date = %s]\n" %readUnitConfObj.endDate
1123 subtitle += "[End date = %s]\n" %readUnitConfObj.endDate
1124 subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime
1124 subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime
1125 subtitle += "[End time = %s]\n" %readUnitConfObj.endTime
1125 subtitle += "[End time = %s]\n" %readUnitConfObj.endTime
1126
1126
1127 adminObj = schainpy.admin.SchainNotify()
1127 adminObj = schainpy.admin.SchainNotify()
1128 adminObj.sendAlert(message=message,
1128 adminObj.sendAlert(message=message,
1129 subject=subject,
1129 subject=subject,
1130 subtitle=subtitle,
1130 subtitle=subtitle,
1131 filename=self.filename)
1131 filename=self.filename)
1132
1132
1133 def isPaused(self):
1133 def isPaused(self):
1134 return 0
1134 return 0
1135
1135
1136 def isStopped(self):
1136 def isStopped(self):
1137 return 0
1137 return 0
1138
1138
1139 def runController(self):
1139 def runController(self):
1140 """
1140 """
1141 returns 0 when this process has been stopped, 1 otherwise
1141 returns 0 when this process has been stopped, 1 otherwise
1142 """
1142 """
1143
1143
1144 if self.isPaused():
1144 if self.isPaused():
1145 print "Process suspended"
1145 print "Process suspended"
1146
1146
1147 while True:
1147 while True:
1148 sleep(0.1)
1148 sleep(0.1)
1149
1149
1150 if not self.isPaused():
1150 if not self.isPaused():
1151 break
1151 break
1152
1152
1153 if self.isStopped():
1153 if self.isStopped():
1154 break
1154 break
1155
1155
1156 print "Process reinitialized"
1156 print "Process reinitialized"
1157
1157
1158 if self.isStopped():
1158 if self.isStopped():
1159 print "Process stopped"
1159 print "Process stopped"
1160 return 0
1160 return 0
1161
1161
1162 return 1
1162 return 1
1163
1163
1164 def setFilename(self, filename):
1164 def setFilename(self, filename):
1165
1165
1166 self.filename = filename
1166 self.filename = filename
1167
1167
1168 def setPlotterQueue(self, plotter_queue):
1168 def setPlotterQueue(self, plotter_queue):
1169
1169
1170 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1170 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1171
1171
1172 def getPlotterQueue(self):
1172 def getPlotterQueue(self):
1173
1173
1174 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1174 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1175
1175
1176 def useExternalPlotter(self):
1176 def useExternalPlotter(self):
1177
1177
1178 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1178 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1179
1179
1180 def run(self):
1180 def run(self):
1181
1181
1182 print
1182 print
1183 print "*"*60
1183 print "*"*60
1184 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__
1184 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__
1185 print "*"*60
1185 print "*"*60
1186 print
1186 print
1187
1187
1188 keyList = self.procUnitConfObjDict.keys()
1188 keyList = self.procUnitConfObjDict.keys()
1189 keyList.sort()
1189 keyList.sort()
1190
1190
1191 while(True):
1191 while(True):
1192
1192
1193 is_ok = False
1193 is_ok = False
1194
1194
1195 for procKey in keyList:
1195 for procKey in keyList:
1196 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1196 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1197
1197
1198 procUnitConfObj = self.procUnitConfObjDict[procKey]
1198 procUnitConfObj = self.procUnitConfObjDict[procKey]
1199
1199
1200 try:
1200 try:
1201 sts = procUnitConfObj.run()
1201 sts = procUnitConfObj.run()
1202 is_ok = is_ok or sts
1202 is_ok = is_ok or sts
1203 except KeyboardInterrupt:
1203 except KeyboardInterrupt:
1204 is_ok = False
1204 is_ok = False
1205 break
1205 break
1206 except ValueError, e:
1206 except ValueError, e:
1207 sleep(0.5)
1207 sleep(0.5)
1208 self.__handleError(procUnitConfObj, send_email=True)
1208 self.__handleError(procUnitConfObj, send_email=True)
1209 is_ok = False
1209 is_ok = False
1210 break
1210 break
1211 except:
1211 except:
1212 sleep(0.5)
1212 sleep(0.5)
1213 self.__handleError(procUnitConfObj)
1213 self.__handleError(procUnitConfObj)
1214 is_ok = False
1214 is_ok = False
1215 break
1215 break
1216
1216
1217 #If every process unit finished so end process
1217 #If every process unit finished so end process
1218 if not(is_ok):
1218 if not(is_ok):
1219 # print "Every process unit have finished"
1219 # print "Every process unit have finished"
1220 break
1220 break
1221
1221
1222 if not self.runController():
1222 if not self.runController():
1223 break
1223 break
1224
1224
1225 #Closing every process
1225 #Closing every process
1226 for procKey in keyList:
1226 for procKey in keyList:
1227 procUnitConfObj = self.procUnitConfObjDict[procKey]
1227 procUnitConfObj = self.procUnitConfObjDict[procKey]
1228 procUnitConfObj.close()
1228 procUnitConfObj.close()
1229
1229
1230 print "Process finished"
1230 print "Process finished"
1231
1231
1232 def start(self):
1232 def start(self):
1233
1233
1234 self.writeXml()
1234 self.writeXml()
1235
1235
1236 self.createObjects()
1236 self.createObjects()
1237 self.connectObjects()
1237 self.connectObjects()
1238 self.run()
1238 self.run()
1239
1239
1240 if __name__ == '__main__':
1240 if __name__ == '__main__':
1241
1241
1242 desc = "Segundo Test"
1242 desc = "Segundo Test"
1243 filename = "schain.xml"
1243 filename = "schain.xml"
1244
1244
1245 controllerObj = Project()
1245 controllerObj = Project()
1246
1246
1247 controllerObj.setup(id = '191', name='test01', description=desc)
1247 controllerObj.setup(id = '191', name='test01', description=desc)
1248
1248
1249 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
1249 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
1250 path='data/rawdata/',
1250 path='data/rawdata/',
1251 startDate='2011/01/01',
1251 startDate='2011/01/01',
1252 endDate='2012/12/31',
1252 endDate='2012/12/31',
1253 startTime='00:00:00',
1253 startTime='00:00:00',
1254 endTime='23:59:59',
1254 endTime='23:59:59',
1255 online=1,
1255 online=1,
1256 walk=1)
1256 walk=1)
1257
1257
1258 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
1258 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
1259
1259
1260 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
1260 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
1261 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
1261 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
1262
1262
1263 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
1263 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
1264 opObj10.addParameter(name='minHei', value='90', format='float')
1264 opObj10.addParameter(name='minHei', value='90', format='float')
1265 opObj10.addParameter(name='maxHei', value='180', format='float')
1265 opObj10.addParameter(name='maxHei', value='180', format='float')
1266
1266
1267 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
1267 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
1268 opObj12.addParameter(name='n', value='10', format='int')
1268 opObj12.addParameter(name='n', value='10', format='int')
1269
1269
1270 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
1270 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
1271 procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
1271 procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
1272 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
1272 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
1273
1273
1274
1274
1275 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
1275 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
1276 opObj11.addParameter(name='idfigure', value='1', format='int')
1276 opObj11.addParameter(name='idfigure', value='1', format='int')
1277 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
1277 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
1278 opObj11.addParameter(name='zmin', value='40', format='int')
1278 opObj11.addParameter(name='zmin', value='40', format='int')
1279 opObj11.addParameter(name='zmax', value='90', format='int')
1279 opObj11.addParameter(name='zmax', value='90', format='int')
1280 opObj11.addParameter(name='showprofile', value='1', format='int')
1280 opObj11.addParameter(name='showprofile', value='1', format='int')
1281
1281
1282 print "Escribiendo el archivo XML"
1282 print "Escribiendo el archivo XML"
1283
1283
1284 controllerObj.writeXml(filename)
1284 controllerObj.writeXml(filename)
1285
1285
1286 print "Leyendo el archivo XML"
1286 print "Leyendo el archivo XML"
1287 controllerObj.readXml(filename)
1287 controllerObj.readXml(filename)
1288 #controllerObj.printattr()
1288 #controllerObj.printattr()
1289
1289
1290 controllerObj.createObjects()
1290 controllerObj.createObjects()
1291 controllerObj.connectObjects()
1291 controllerObj.connectObjects()
1292 controllerObj.run()
1292 controllerObj.run()
1293
1293
1294 No newline at end of file
1294
@@ -1,661 +1,665
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6 from schainpy.model.proc.jroproc_base import Operation
6 from schainpy.model.proc.jroproc_base import Operation
7
7
8 def isTimeInHourRange(datatime, xmin, xmax):
8 def isTimeInHourRange(datatime, xmin, xmax):
9
9
10 if xmin == None or xmax == None:
10 if xmin == None or xmax == None:
11 return 1
11 return 1
12 hour = datatime.hour + datatime.minute/60.0
12 hour = datatime.hour + datatime.minute/60.0
13
13
14 if xmin < (xmax % 24):
14 if xmin < (xmax % 24):
15
15
16 if hour >= xmin and hour <= xmax:
16 if hour >= xmin and hour <= xmax:
17 return 1
17 return 1
18 else:
18 else:
19 return 0
19 return 0
20
20
21 else:
21 else:
22
22
23 if hour >= xmin or hour <= (xmax % 24):
23 if hour >= xmin or hour <= (xmax % 24):
24 return 1
24 return 1
25 else:
25 else:
26 return 0
26 return 0
27
27
28 return 0
28 return 0
29
29
30 def isRealtime(utcdatatime):
30 def isRealtime(utcdatatime):
31
31
32 utcnow = time.mktime(time.localtime())
32 utcnow = time.mktime(time.localtime())
33 delta = abs(utcnow - utcdatatime) # abs
33 delta = abs(utcnow - utcdatatime) # abs
34 if delta >= 30.:
34 if delta >= 30.:
35 return False
35 return False
36 return True
36 return True
37
37
38 class Figure(Operation):
38 class Figure(Operation):
39
39
40 __driver = mpldriver
40 __driver = mpldriver
41 fig = None
41 fig = None
42
42
43 id = None
43 id = None
44 wintitle = None
44 wintitle = None
45 width = None
45 width = None
46 height = None
46 height = None
47 nplots = None
47 nplots = None
48 timerange = None
48 timerange = None
49
49
50 axesObjList = []
50 axesObjList = []
51
51
52 WIDTH = 300
52 WIDTH = 300
53 HEIGHT = 200
53 HEIGHT = 200
54 PREFIX = 'fig'
54 PREFIX = 'fig'
55
55
56 xmin = None
56 xmin = None
57 xmax = None
57 xmax = None
58
58
59 counter_imagwr = 0
59 counter_imagwr = 0
60
60
61 figfile = None
61 figfile = None
62
62
63 created = False
63 created = False
64
64
65 def __init__(self):
65 def __init__(self):
66
66
67 raise NotImplementedError
67 raise NotImplementedError
68
68
69 def __del__(self):
69 def __del__(self):
70
70
71 self.__driver.closeFigure()
71 self.__driver.closeFigure()
72
72
73 def getFilename(self, name, ext='.png'):
73 def getFilename(self, name, ext='.png'):
74
74
75 path = '%s%03d' %(self.PREFIX, self.id)
75 path = '%s%03d' %(self.PREFIX, self.id)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
77 return os.path.join(path, filename)
77 return os.path.join(path, filename)
78
78
79 def getAxesObjList(self):
79 def getAxesObjList(self):
80
80
81 return self.axesObjList
81 return self.axesObjList
82
82
83 def getSubplots(self):
83 def getSubplots(self):
84
84
85 raise NotImplementedError
85 raise NotImplementedError
86
86
87 def getScreenDim(self, widthplot, heightplot):
87 def getScreenDim(self, widthplot, heightplot):
88
88
89 nrow, ncol = self.getSubplots()
89 nrow, ncol = self.getSubplots()
90
90
91 widthscreen = widthplot*ncol
91 widthscreen = widthplot*ncol
92 heightscreen = heightplot*nrow
92 heightscreen = heightplot*nrow
93
93
94 return widthscreen, heightscreen
94 return widthscreen, heightscreen
95
95
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
97
97
98 # if self.xmin != None and self.xmax != None:
98 # if self.xmin != None and self.xmax != None:
99 # if timerange == None:
99 # if timerange == None:
100 # timerange = self.xmax - self.xmin
100 # timerange = self.xmax - self.xmin
101 # xmin = self.xmin + timerange
101 # xmin = self.xmin + timerange
102 # xmax = self.xmax + timerange
102 # xmax = self.xmax + timerange
103 #
103 #
104 # return xmin, xmax
104 # return xmin, xmax
105
105
106 if timerange == None and (xmin==None or xmax==None):
106 if timerange == None and (xmin==None or xmax==None):
107 timerange = 14400 #seconds
107 timerange = 14400 #seconds
108
108
109 if timerange != None:
109 if timerange != None:
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
111 else:
111 else:
112 txmin = x[0] #- x[0] % 10*60
112 txmin = x[0] #- x[0] % 10*60
113
113
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116
116
117 if timerange != None:
117 if timerange != None:
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
119 xmax = xmin + timerange/(60*60.)
119 xmax = xmin + timerange/(60*60.)
120
120
121 d1970 = datetime.datetime(1970,1,1)
121 d1970 = datetime.datetime(1970,1,1)
122
122
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
125
125
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
128
128
129 return xmin_sec, xmax_sec
129 return xmin_sec, xmax_sec
130
130
131 def init(self, id, nplots, wintitle):
131 def init(self, id, nplots, wintitle):
132
132
133 raise NotImplementedError, "This method has been replaced by createFigure"
133 raise NotImplementedError, "This method has been replaced by createFigure"
134
134
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
136
136
137 """
137 """
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
141
141
142 Input:
142 Input:
143 id : Los parametros necesarios son
143 id : Los parametros necesarios son
144 wintitle :
144 wintitle :
145
145
146 """
146 """
147
147
148 if widthplot == None:
148 if widthplot == None:
149 widthplot = self.WIDTH
149 widthplot = self.WIDTH
150
150
151 if heightplot == None:
151 if heightplot == None:
152 heightplot = self.HEIGHT
152 heightplot = self.HEIGHT
153
153
154 self.id = id
154 self.id = id
155
155
156 self.wintitle = wintitle
156 self.wintitle = wintitle
157
157
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
159
159
160 # if self.created:
160 # if self.created:
161 # self.__driver.closeFigure(self.fig)
161 # self.__driver.closeFigure(self.fig)
162
162
163 if not self.created:
163 if not self.created:
164 self.fig = self.__driver.createFigure(id=self.id,
164 self.fig = self.__driver.createFigure(id=self.id,
165 wintitle=self.wintitle,
165 wintitle=self.wintitle,
166 width=self.widthscreen,
166 width=self.widthscreen,
167 height=self.heightscreen,
167 height=self.heightscreen,
168 show=show)
168 show=show)
169 else:
169 else:
170 self.__driver.clearFigure(self.fig)
170 self.__driver.clearFigure(self.fig)
171
171
172 self.axesObjList = []
172 self.axesObjList = []
173 self.counter_imagwr = 0
173 self.counter_imagwr = 0
174
174
175 self.created = True
175 self.created = True
176
176
177 def setDriver(self, driver=mpldriver):
177 def setDriver(self, driver=mpldriver):
178
178
179 self.__driver = driver
179 self.__driver = driver
180
180
181 def setTitle(self, title):
181 def setTitle(self, title):
182
182
183 self.__driver.setTitle(self.fig, title)
183 self.__driver.setTitle(self.fig, title)
184
184
185 def setWinTitle(self, title):
185 def setWinTitle(self, title):
186
186
187 self.__driver.setWinTitle(self.fig, title=title)
187 self.__driver.setWinTitle(self.fig, title=title)
188
188
189 def setTextFromAxes(self, text):
189 def setTextFromAxes(self, text):
190
190
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
192
192
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
194
194
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
196
196
197 def addAxes(self, *args):
197 def addAxes(self, *args):
198 """
198 """
199
199
200 Input:
200 Input:
201 *args : Los parametros necesarios son
201 *args : Los parametros necesarios son
202 nrow, ncol, xpos, ypos, colspan, rowspan
202 nrow, ncol, xpos, ypos, colspan, rowspan
203 """
203 """
204
204
205 axesObj = Axes(self.fig, *args)
205 axesObj = Axes(self.fig, *args)
206 self.axesObjList.append(axesObj)
206 self.axesObjList.append(axesObj)
207
207
208 def saveFigure(self, figpath, figfile, *args):
208 def saveFigure(self, figpath, figfile, *args):
209
209
210 filename = os.path.join(figpath, figfile)
210 filename = os.path.join(figpath, figfile)
211
211
212 fullpath = os.path.split(filename)[0]
212 fullpath = os.path.split(filename)[0]
213
213
214 if not os.path.exists(fullpath):
214 if not os.path.exists(fullpath):
215 subpath = os.path.split(fullpath)[0]
215 subpath = os.path.split(fullpath)[0]
216
216
217 if not os.path.exists(subpath):
217 if not os.path.exists(subpath):
218 os.mkdir(subpath)
218 os.mkdir(subpath)
219
219
220 os.mkdir(fullpath)
220 os.mkdir(fullpath)
221
221
222 self.__driver.saveFigure(self.fig, filename, *args)
222 self.__driver.saveFigure(self.fig, filename, *args)
223
223
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
225
225
226 self.counter_imagwr += 1
226 self.counter_imagwr += 1
227 if self.counter_imagwr < wr_period:
227 if self.counter_imagwr < wr_period:
228 return
228 return
229
229
230 self.counter_imagwr = 0
230 self.counter_imagwr = 0
231
231
232 if save:
232 if save:
233
233
234 if not figfile:
234 if not figfile:
235
235
236 if not thisDatetime:
236 if not thisDatetime:
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
238 return
238 return
239
239
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
241 figfile = self.getFilename(name = str_datetime)
241 figfile = self.getFilename(name = str_datetime)
242
242
243 if self.figfile == None:
243 if self.figfile == None:
244 self.figfile = figfile
244 self.figfile = figfile
245
245
246 if update_figfile:
246 if update_figfile:
247 self.figfile = figfile
247 self.figfile = figfile
248
248
249 # store png plot to local folder
249 # store png plot to local folder
250 self.saveFigure(figpath, self.figfile)
250 self.saveFigure(figpath, self.figfile)
251
251
252
252
253 if not ftp:
253 if not ftp:
254 return
254 return
255
255
256 if not thisDatetime:
256 if not thisDatetime:
257 return
257 return
258
258
259 # store png plot to FTP server according to RT-Web format
259 # store png plot to FTP server according to RT-Web format
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
261 # ftp_filename = os.path.join(figpath, name)
261 # ftp_filename = os.path.join(figpath, name)
262 self.saveFigure(figpath, ftp_filename)
262 self.saveFigure(figpath, ftp_filename)
263
263
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
267 FTP_WEI = '%2.2d'%FTP_WEI
267 FTP_WEI = '%2.2d'%FTP_WEI
268 EXP_CODE = '%3.3d'%EXP_CODE
268 EXP_CODE = '%3.3d'%EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
271 PLOT_POS = '%2.2d'%PLOT_POS
271 PLOT_POS = '%2.2d'%PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
273 return name
273 return name
274
274
275 def draw(self):
275 def draw(self):
276
276
277 self.__driver.draw(self.fig)
277 self.__driver.draw(self.fig)
278
278
279 def run(self):
279 def run(self):
280
280
281 raise NotImplementedError
281 raise NotImplementedError
282
282
283 def close(self, show=False):
283 def close(self, show=False):
284
284
285 self.__driver.closeFigure(show=show, fig=self.fig)
285 self.__driver.closeFigure(show=show, fig=self.fig)
286
286
287 axesList = property(getAxesObjList)
287 axesList = property(getAxesObjList)
288
288
289
289
290 class Axes:
290 class Axes:
291
291
292 __driver = mpldriver
292 __driver = mpldriver
293 fig = None
293 fig = None
294 ax = None
294 ax = None
295 plot = None
295 plot = None
296 __missing = 1E30
296 __missing = 1E30
297 __firsttime = None
297 __firsttime = None
298
298
299 __showprofile = False
299 __showprofile = False
300
300
301 xmin = None
301 xmin = None
302 xmax = None
302 xmax = None
303 ymin = None
303 ymin = None
304 ymax = None
304 ymax = None
305 zmin = None
305 zmin = None
306 zmax = None
306 zmax = None
307
307
308 x_buffer = None
308 x_buffer = None
309 z_buffer = None
309 z_buffer = None
310
310
311 decimationx = None
311 decimationx = None
312 decimationy = None
312 decimationy = None
313
313
314 __MAXNUMX = 200
314 __MAXNUMX = 200
315 __MAXNUMY = 400
315 __MAXNUMY = 100
316
316
317 __MAXNUMTIME = 500
317 __MAXNUMTIME = 500
318
318
319 def __init__(self, *args):
319 def __init__(self, *args):
320
320
321 """
321 """
322
322
323 Input:
323 Input:
324 *args : Los parametros necesarios son
324 *args : Los parametros necesarios son
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
326 """
326 """
327
327
328 ax = self.__driver.createAxes(*args)
328 ax = self.__driver.createAxes(*args)
329 self.fig = args[0]
329 self.fig = args[0]
330 self.ax = ax
330 self.ax = ax
331 self.plot = None
331 self.plot = None
332
332
333 self.__firsttime = True
333 self.__firsttime = True
334 self.idlineList = []
334 self.idlineList = []
335
335
336 self.x_buffer = numpy.array([])
336 self.x_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
338
338
339 def setText(self, text):
339 def setText(self, text):
340
340
341 self.__driver.setAxesText(self.ax, text)
341 self.__driver.setAxesText(self.ax, text)
342
342
343 def setXAxisAsTime(self):
343 def setXAxisAsTime(self):
344 pass
344 pass
345
345
346 def pline(self, x, y,
346 def pline(self, x, y,
347 xmin=None, xmax=None,
347 xmin=None, xmax=None,
348 ymin=None, ymax=None,
348 ymin=None, ymax=None,
349 xlabel='', ylabel='',
349 xlabel='', ylabel='',
350 title='',
350 title='',
351 **kwargs):
351 **kwargs):
352
352
353 """
353 """
354
354
355 Input:
355 Input:
356 x :
356 x :
357 y :
357 y :
358 xmin :
358 xmin :
359 xmax :
359 xmax :
360 ymin :
360 ymin :
361 ymax :
361 ymax :
362 xlabel :
362 xlabel :
363 ylabel :
363 ylabel :
364 title :
364 title :
365 **kwargs : Los parametros aceptados son
365 **kwargs : Los parametros aceptados son
366
366
367 ticksize
367 ticksize
368 ytick_visible
368 ytick_visible
369 """
369 """
370
370
371 if self.__firsttime:
371 if self.__firsttime:
372
372
373 if xmin == None: xmin = numpy.nanmin(x)
373 if xmin == None: xmin = numpy.nanmin(x)
374 if xmax == None: xmax = numpy.nanmax(x)
374 if xmax == None: xmax = numpy.nanmax(x)
375 if ymin == None: ymin = numpy.nanmin(y)
375 if ymin == None: ymin = numpy.nanmin(y)
376 if ymax == None: ymax = numpy.nanmax(y)
376 if ymax == None: ymax = numpy.nanmax(y)
377
377
378 self.plot = self.__driver.createPline(self.ax, x, y,
378 self.plot = self.__driver.createPline(self.ax, x, y,
379 xmin, xmax,
379 xmin, xmax,
380 ymin, ymax,
380 ymin, ymax,
381 xlabel=xlabel,
381 xlabel=xlabel,
382 ylabel=ylabel,
382 ylabel=ylabel,
383 title=title,
383 title=title,
384 **kwargs)
384 **kwargs)
385
385
386 self.idlineList.append(0)
386 self.idlineList.append(0)
387 self.__firsttime = False
387 self.__firsttime = False
388 return
388 return
389
389
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
391 ylabel=ylabel,
391 ylabel=ylabel,
392 title=title)
392 title=title)
393
393
394 # self.__driver.pause()
394 # self.__driver.pause()
395
395
396 def addpline(self, x, y, idline, **kwargs):
396 def addpline(self, x, y, idline, **kwargs):
397 lines = self.ax.lines
397 lines = self.ax.lines
398
398
399 if idline in self.idlineList:
399 if idline in self.idlineList:
400 self.__driver.set_linedata(self.ax, x, y, idline)
400 self.__driver.set_linedata(self.ax, x, y, idline)
401
401
402 if idline not in(self.idlineList):
402 if idline not in(self.idlineList):
403 self.__driver.addpline(self.ax, x, y, **kwargs)
403 self.__driver.addpline(self.ax, x, y, **kwargs)
404 self.idlineList.append(idline)
404 self.idlineList.append(idline)
405
405
406 return
406 return
407
407
408 def pmultiline(self, x, y,
408 def pmultiline(self, x, y,
409 xmin=None, xmax=None,
409 xmin=None, xmax=None,
410 ymin=None, ymax=None,
410 ymin=None, ymax=None,
411 xlabel='', ylabel='',
411 xlabel='', ylabel='',
412 title='',
412 title='',
413 **kwargs):
413 **kwargs):
414
414
415 if self.__firsttime:
415 if self.__firsttime:
416
416
417 if xmin == None: xmin = numpy.nanmin(x)
417 if xmin == None: xmin = numpy.nanmin(x)
418 if xmax == None: xmax = numpy.nanmax(x)
418 if xmax == None: xmax = numpy.nanmax(x)
419 if ymin == None: ymin = numpy.nanmin(y)
419 if ymin == None: ymin = numpy.nanmin(y)
420 if ymax == None: ymax = numpy.nanmax(y)
420 if ymax == None: ymax = numpy.nanmax(y)
421
421
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
423 xmin, xmax,
423 xmin, xmax,
424 ymin, ymax,
424 ymin, ymax,
425 xlabel=xlabel,
425 xlabel=xlabel,
426 ylabel=ylabel,
426 ylabel=ylabel,
427 title=title,
427 title=title,
428 **kwargs)
428 **kwargs)
429 self.__firsttime = False
429 self.__firsttime = False
430 return
430 return
431
431
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
433 ylabel=ylabel,
433 ylabel=ylabel,
434 title=title)
434 title=title)
435
435
436 # self.__driver.pause()
436 # self.__driver.pause()
437
437
438 def pmultilineyaxis(self, x, y,
438 def pmultilineyaxis(self, x, y,
439 xmin=None, xmax=None,
439 xmin=None, xmax=None,
440 ymin=None, ymax=None,
440 ymin=None, ymax=None,
441 xlabel='', ylabel='',
441 xlabel='', ylabel='',
442 title='',
442 title='',
443 **kwargs):
443 **kwargs):
444
444
445 if self.__firsttime:
445 if self.__firsttime:
446
446
447 if xmin == None: xmin = numpy.nanmin(x)
447 if xmin == None: xmin = numpy.nanmin(x)
448 if xmax == None: xmax = numpy.nanmax(x)
448 if xmax == None: xmax = numpy.nanmax(x)
449 if ymin == None: ymin = numpy.nanmin(y)
449 if ymin == None: ymin = numpy.nanmin(y)
450 if ymax == None: ymax = numpy.nanmax(y)
450 if ymax == None: ymax = numpy.nanmax(y)
451
451
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
453 xmin, xmax,
453 xmin, xmax,
454 ymin, ymax,
454 ymin, ymax,
455 xlabel=xlabel,
455 xlabel=xlabel,
456 ylabel=ylabel,
456 ylabel=ylabel,
457 title=title,
457 title=title,
458 **kwargs)
458 **kwargs)
459 if self.xmin == None: self.xmin = xmin
459 if self.xmin == None: self.xmin = xmin
460 if self.xmax == None: self.xmax = xmax
460 if self.xmax == None: self.xmax = xmax
461 if self.ymin == None: self.ymin = ymin
461 if self.ymin == None: self.ymin = ymin
462 if self.ymax == None: self.ymax = ymax
462 if self.ymax == None: self.ymax = ymax
463
463
464 self.__firsttime = False
464 self.__firsttime = False
465 return
465 return
466
466
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
468 ylabel=ylabel,
468 ylabel=ylabel,
469 title=title)
469 title=title)
470
470
471 # self.__driver.pause()
471 # self.__driver.pause()
472
472
473 def pcolor(self, x, y, z,
473 def pcolor(self, x, y, z,
474 xmin=None, xmax=None,
474 xmin=None, xmax=None,
475 ymin=None, ymax=None,
475 ymin=None, ymax=None,
476 zmin=None, zmax=None,
476 zmin=None, zmax=None,
477 xlabel='', ylabel='',
477 xlabel='', ylabel='',
478 title='', colormap='jet',
478 title='', colormap='jet',
479 **kwargs):
479 **kwargs):
480
480
481 """
481 """
482 Input:
482 Input:
483 x :
483 x :
484 y :
484 y :
485 x :
485 x :
486 xmin :
486 xmin :
487 xmax :
487 xmax :
488 ymin :
488 ymin :
489 ymax :
489 ymax :
490 zmin :
490 zmin :
491 zmax :
491 zmax :
492 xlabel :
492 xlabel :
493 ylabel :
493 ylabel :
494 title :
494 title :
495 **kwargs : Los parametros aceptados son
495 **kwargs : Los parametros aceptados son
496 ticksize=9,
496 ticksize=9,
497 cblabel=''
497 cblabel=''
498 """
498 """
499
499
500 #Decimating data
500 #Decimating data
501 xlen = len(x)
501 xlen = len(x)
502 ylen = len(y)
502 ylen = len(y)
503
503
504 decimationx = numpy.floor(xlen/self.__MAXNUMX) - 1 if numpy.floor(xlen/self.__MAXNUMX)>1 else 1
504 decimationx = int(xlen/self.__MAXNUMX)+1 \
505 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
505 if int(xlen/self.__MAXNUMX)>1 else 1
506 decimationy = int(ylen/self.__MAXNUMY) \
507 if int(ylen/self.__MAXNUMY)>1 else 1
506
508
509 x_buffer = x#[::decimationx]
510 y_buffer = y#[::decimationy]
511 z_buffer = z#[::decimationx, ::decimationy]
507
512
508 x_buffer = x[::decimationx]
509 y_buffer = y[::decimationy]
510 z_buffer = z[::decimationx, ::decimationy]
511 #===================================================
513 #===================================================
512
514
513 if self.__firsttime:
515 if self.__firsttime:
514
516
515 if xmin == None: xmin = numpy.nanmin(x)
517 if xmin == None: xmin = numpy.nanmin(x)
516 if xmax == None: xmax = numpy.nanmax(x)
518 if xmax == None: xmax = numpy.nanmax(x)
517 if ymin == None: ymin = numpy.nanmin(y)
519 if ymin == None: ymin = numpy.nanmin(y)
518 if ymax == None: ymax = numpy.nanmax(y)
520 if ymax == None: ymax = numpy.nanmax(y)
519 if zmin == None: zmin = numpy.nanmin(z)
521 if zmin == None: zmin = numpy.nanmin(z)
520 if zmax == None: zmax = numpy.nanmax(z)
522 if zmax == None: zmax = numpy.nanmax(z)
521
523
522
524
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
525 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
524 y_buffer,
526 y_buffer,
525 z_buffer,
527 z_buffer,
526 xmin, xmax,
528 xmin, xmax,
527 ymin, ymax,
529 ymin, ymax,
528 zmin, zmax,
530 zmin, zmax,
529 xlabel=xlabel,
531 xlabel=xlabel,
530 ylabel=ylabel,
532 ylabel=ylabel,
531 title=title,
533 title=title,
532 colormap=colormap,
534 colormap=colormap,
533 **kwargs)
535 **kwargs)
534
536
535 if self.xmin == None: self.xmin = xmin
537 if self.xmin == None: self.xmin = xmin
536 if self.xmax == None: self.xmax = xmax
538 if self.xmax == None: self.xmax = xmax
537 if self.ymin == None: self.ymin = ymin
539 if self.ymin == None: self.ymin = ymin
538 if self.ymax == None: self.ymax = ymax
540 if self.ymax == None: self.ymax = ymax
539 if self.zmin == None: self.zmin = zmin
541 if self.zmin == None: self.zmin = zmin
540 if self.zmax == None: self.zmax = zmax
542 if self.zmax == None: self.zmax = zmax
541
543
542 self.__firsttime = False
544 self.__firsttime = False
543 return
545 return
544
546
545 self.__driver.pcolor(self.plot,
547 self.__driver.pcolor(self.plot,
546 z_buffer,
548 z_buffer,
547 xlabel=xlabel,
549 xlabel=xlabel,
548 ylabel=ylabel,
550 ylabel=ylabel,
549 title=title)
551 title=title)
550
552
551 # self.__driver.pause()
553 # self.__driver.pause()
552
554
553 def pcolorbuffer(self, x, y, z,
555 def pcolorbuffer(self, x, y, z,
554 xmin=None, xmax=None,
556 xmin=None, xmax=None,
555 ymin=None, ymax=None,
557 ymin=None, ymax=None,
556 zmin=None, zmax=None,
558 zmin=None, zmax=None,
557 xlabel='', ylabel='',
559 xlabel='', ylabel='',
558 title='', rti = True, colormap='jet',
560 title='', rti = True, colormap='jet',
559 maxNumX = None, maxNumY = None,
561 maxNumX = None, maxNumY = None,
560 **kwargs):
562 **kwargs):
561
563
562 if maxNumX == None:
564 if maxNumX == None:
563 maxNumX = self.__MAXNUMTIME
565 maxNumX = self.__MAXNUMTIME
564
566
565 if maxNumY == None:
567 if maxNumY == None:
566 maxNumY = self.__MAXNUMY
568 maxNumY = self.__MAXNUMY
567
569
568 if self.__firsttime:
570 if self.__firsttime:
569 self.z_buffer = z
571 self.z_buffer = z
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
572 self.x_buffer = numpy.hstack((self.x_buffer, x))
571
573
572 if xmin == None: xmin = numpy.nanmin(x)
574 if xmin == None: xmin = numpy.nanmin(x)
573 if xmax == None: xmax = numpy.nanmax(x)
575 if xmax == None: xmax = numpy.nanmax(x)
574 if ymin == None: ymin = numpy.nanmin(y)
576 if ymin == None: ymin = numpy.nanmin(y)
575 if ymax == None: ymax = numpy.nanmax(y)
577 if ymax == None: ymax = numpy.nanmax(y)
576 if zmin == None: zmin = numpy.nanmin(z)
578 if zmin == None: zmin = numpy.nanmin(z)
577 if zmax == None: zmax = numpy.nanmax(z)
579 if zmax == None: zmax = numpy.nanmax(z)
578
580
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
581 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 xmin, xmax,
582 xmin, xmax,
581 ymin, ymax,
583 ymin, ymax,
582 zmin, zmax,
584 zmin, zmax,
583 xlabel=xlabel,
585 xlabel=xlabel,
584 ylabel=ylabel,
586 ylabel=ylabel,
585 title=title,
587 title=title,
586 colormap=colormap,
588 colormap=colormap,
587 **kwargs)
589 **kwargs)
588
590
589 if self.xmin == None: self.xmin = xmin
591 if self.xmin == None: self.xmin = xmin
590 if self.xmax == None: self.xmax = xmax
592 if self.xmax == None: self.xmax = xmax
591 if self.ymin == None: self.ymin = ymin
593 if self.ymin == None: self.ymin = ymin
592 if self.ymax == None: self.ymax = ymax
594 if self.ymax == None: self.ymax = ymax
593 if self.zmin == None: self.zmin = zmin
595 if self.zmin == None: self.zmin = zmin
594 if self.zmax == None: self.zmax = zmax
596 if self.zmax == None: self.zmax = zmax
595
597
596 self.__firsttime = False
598 self.__firsttime = False
597 return
599 return
598
600
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
601 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
602 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
603 z_buffer = self.z_buffer.reshape(-1,len(y))
602
604
603 #Decimating data
605 #Decimating data
604 xlen = len(self.x_buffer)
606 xlen = len(self.x_buffer)
605 ylen = len(y)
607 ylen = len(y)
606
608
607 decimationx = numpy.floor(xlen/maxNumX) + 1
609 decimationx = int(xlen/self.__MAXNUMX) \
608 decimationy = numpy.floor(ylen/maxNumY) + 1
610 if int(xlen/self.__MAXNUMX)>1 else 1
611 decimationy = int(ylen/self.__MAXNUMY) \
612 if int(ylen/self.__MAXNUMY)>1 else 1
609
613
610 x_buffer = self.x_buffer[::decimationx]
614 x_buffer = self.x_buffer#[::decimationx]
611 y_buffer = y[::decimationy]
615 y_buffer = y#[::decimationy]
612 z_buffer = z_buffer[::decimationx, ::decimationy]
616 z_buffer = z_buffer#[::decimationx, ::decimationy]
613 #===================================================
617 #===================================================
614
618
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
619 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
616
620
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
621 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
618 xlabel=xlabel,
622 xlabel=xlabel,
619 ylabel=ylabel,
623 ylabel=ylabel,
620 title=title,
624 title=title,
621 colormap=colormap)
625 colormap=colormap)
622
626
623 # self.__driver.pause()
627 # self.__driver.pause()
624
628
625 def polar(self, x, y,
629 def polar(self, x, y,
626 title='', xlabel='',ylabel='',**kwargs):
630 title='', xlabel='',ylabel='',**kwargs):
627
631
628 if self.__firsttime:
632 if self.__firsttime:
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
633 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
630 self.__firsttime = False
634 self.__firsttime = False
631 self.x_buffer = x
635 self.x_buffer = x
632 self.y_buffer = y
636 self.y_buffer = y
633 return
637 return
634
638
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
639 self.x_buffer = numpy.hstack((self.x_buffer,x))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
640 self.y_buffer = numpy.hstack((self.y_buffer,y))
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
641 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
638 ylabel=ylabel,
642 ylabel=ylabel,
639 title=title)
643 title=title)
640
644
641 # self.__driver.pause()
645 # self.__driver.pause()
642
646
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
647 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
644
648
645 if x_buffer.shape[0] < 2:
649 if x_buffer.shape[0] < 2:
646 return x_buffer, y_buffer, z_buffer
650 return x_buffer, y_buffer, z_buffer
647
651
648 deltas = x_buffer[1:] - x_buffer[0:-1]
652 deltas = x_buffer[1:] - x_buffer[0:-1]
649 x_median = numpy.median(deltas)
653 x_median = numpy.median(deltas)
650
654
651 index = numpy.where(deltas > 5*x_median)
655 index = numpy.where(deltas > 5*x_median)
652
656
653 if len(index[0]) != 0:
657 if len(index[0]) != 0:
654 z_buffer[index[0],::] = self.__missing
658 z_buffer[index[0],::] = self.__missing
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
659 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
656
660
657 return x_buffer, y_buffer, z_buffer
661 return x_buffer, y_buffer, z_buffer
658
662
659
663
660
664
661 No newline at end of file
665
@@ -1,1949 +1,1951
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8 import matplotlib.pyplot as plt
9
8 class MomentsPlot(Figure):
10 class MomentsPlot(Figure):
9
11
10 isConfig = None
12 isConfig = None
11 __nsubplots = None
13 __nsubplots = None
12
14
13 WIDTHPROF = None
15 WIDTHPROF = None
14 HEIGHTPROF = None
16 HEIGHTPROF = None
15 PREFIX = 'prm'
17 PREFIX = 'prm'
16
18
17 def __init__(self):
19 def __init__(self):
18
20
19 self.isConfig = False
21 self.isConfig = False
20 self.__nsubplots = 1
22 self.__nsubplots = 1
21
23
22 self.WIDTH = 280
24 self.WIDTH = 280
23 self.HEIGHT = 250
25 self.HEIGHT = 250
24 self.WIDTHPROF = 120
26 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
27 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
28 self.counter_imagwr = 0
27
29
28 self.PLOT_CODE = MOMENTS_CODE
30 self.PLOT_CODE = MOMENTS_CODE
29
31
30 self.FTP_WEI = None
32 self.FTP_WEI = None
31 self.EXP_CODE = None
33 self.EXP_CODE = None
32 self.SUB_EXP_CODE = None
34 self.SUB_EXP_CODE = None
33 self.PLOT_POS = None
35 self.PLOT_POS = None
34
36
35 def getSubplots(self):
37 def getSubplots(self):
36
38
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
39
41
40 return nrow, ncol
42 return nrow, ncol
41
43
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43
45
44 self.__showprofile = showprofile
46 self.__showprofile = showprofile
45 self.nplots = nplots
47 self.nplots = nplots
46
48
47 ncolspan = 1
49 ncolspan = 1
48 colspan = 1
50 colspan = 1
49 if showprofile:
51 if showprofile:
50 ncolspan = 3
52 ncolspan = 3
51 colspan = 2
53 colspan = 2
52 self.__nsubplots = 2
54 self.__nsubplots = 2
53
55
54 self.createFigure(id = id,
56 self.createFigure(id = id,
55 wintitle = wintitle,
57 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
58 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
60 show=show)
59
61
60 nrow, ncol = self.getSubplots()
62 nrow, ncol = self.getSubplots()
61
63
62 counter = 0
64 counter = 0
63 for y in range(nrow):
65 for y in range(nrow):
64 for x in range(ncol):
66 for x in range(ncol):
65
67
66 if counter >= self.nplots:
68 if counter >= self.nplots:
67 break
69 break
68
70
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
72
71 if showprofile:
73 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
75
74 counter += 1
76 counter += 1
75
77
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
80 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
81 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
83
82 """
84 """
83
85
84 Input:
86 Input:
85 dataOut :
87 dataOut :
86 id :
88 id :
87 wintitle :
89 wintitle :
88 channelList :
90 channelList :
89 showProfile :
91 showProfile :
90 xmin : None,
92 xmin : None,
91 xmax : None,
93 xmax : None,
92 ymin : None,
94 ymin : None,
93 ymax : None,
95 ymax : None,
94 zmin : None,
96 zmin : None,
95 zmax : None
97 zmax : None
96 """
98 """
97
99
98 if dataOut.flagNoData:
100 if dataOut.flagNoData:
99 return None
101 return None
100
102
101 if realtime:
103 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
105 print 'Skipping this plot function'
104 return
106 return
105
107
106 if channelList == None:
108 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
109 channelIndexList = dataOut.channelIndexList
108 else:
110 else:
109 channelIndexList = []
111 channelIndexList = []
110 for channel in channelList:
112 for channel in channelList:
111 if channel not in dataOut.channelList:
113 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
114 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
115 channelIndexList.append(dataOut.channelList.index(channel))
114
116
115 factor = dataOut.normFactor
117 factor = dataOut.normFactor
116 x = dataOut.abscissaList
118 x = dataOut.abscissaList
117 y = dataOut.heightList
119 y = dataOut.heightList
118
120
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
121 z = dataOut.data_pre[channelIndexList,:,:]/factor
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
121 avg = numpy.average(z, axis=1)
123 avg = numpy.average(z, axis=1)
122 noise = dataOut.noise/factor
124 noise = dataOut.noise/factor
123
125
124 zdB = 10*numpy.log10(z)
126 zdB = 10*numpy.log10(z)
125 avgdB = 10*numpy.log10(avg)
127 avgdB = 10*numpy.log10(avg)
126 noisedB = 10*numpy.log10(noise)
128 noisedB = 10*numpy.log10(noise)
127
129
128 #thisDatetime = dataOut.datatime
130 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Parameters"
132 title = wintitle + " Parameters"
131 xlabel = "Velocity (m/s)"
133 xlabel = "Velocity (m/s)"
132 ylabel = "Range (Km)"
134 ylabel = "Range (Km)"
133
135
134 update_figfile = False
136 update_figfile = False
135
137
136 if not self.isConfig:
138 if not self.isConfig:
137
139
138 nplots = len(channelIndexList)
140 nplots = len(channelIndexList)
139
141
140 self.setup(id=id,
142 self.setup(id=id,
141 nplots=nplots,
143 nplots=nplots,
142 wintitle=wintitle,
144 wintitle=wintitle,
143 showprofile=showprofile,
145 showprofile=showprofile,
144 show=show)
146 show=show)
145
147
146 if xmin == None: xmin = numpy.nanmin(x)
148 if xmin == None: xmin = numpy.nanmin(x)
147 if xmax == None: xmax = numpy.nanmax(x)
149 if xmax == None: xmax = numpy.nanmax(x)
148 if ymin == None: ymin = numpy.nanmin(y)
150 if ymin == None: ymin = numpy.nanmin(y)
149 if ymax == None: ymax = numpy.nanmax(y)
151 if ymax == None: ymax = numpy.nanmax(y)
150 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
151 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
152
154
153 self.FTP_WEI = ftp_wei
155 self.FTP_WEI = ftp_wei
154 self.EXP_CODE = exp_code
156 self.EXP_CODE = exp_code
155 self.SUB_EXP_CODE = sub_exp_code
157 self.SUB_EXP_CODE = sub_exp_code
156 self.PLOT_POS = plot_pos
158 self.PLOT_POS = plot_pos
157
159
158 self.isConfig = True
160 self.isConfig = True
159 update_figfile = True
161 update_figfile = True
160
162
161 self.setWinTitle(title)
163 self.setWinTitle(title)
162
164
163 for i in range(self.nplots):
165 for i in range(self.nplots):
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
166 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
167 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
166 axes = self.axesList[i*self.__nsubplots]
168 axes = self.axesList[i*self.__nsubplots]
167 axes.pcolor(x, y, zdB[i,:,:],
169 axes.pcolor(x, y, zdB[i,:,:],
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
170 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 xlabel=xlabel, ylabel=ylabel, title=title,
171 xlabel=xlabel, ylabel=ylabel, title=title,
170 ticksize=9, cblabel='')
172 ticksize=9, cblabel='')
171 #Mean Line
173 #Mean Line
172 mean = dataOut.data_param[i, 1, :]
174 mean = dataOut.data_param[i, 1, :]
173 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
175 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
174
176
175 if self.__showprofile:
177 if self.__showprofile:
176 axes = self.axesList[i*self.__nsubplots +1]
178 axes = self.axesList[i*self.__nsubplots +1]
177 axes.pline(avgdB[i], y,
179 axes.pline(avgdB[i], y,
178 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
180 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
179 xlabel='dB', ylabel='', title='',
181 xlabel='dB', ylabel='', title='',
180 ytick_visible=False,
182 ytick_visible=False,
181 grid='x')
183 grid='x')
182
184
183 noiseline = numpy.repeat(noisedB[i], len(y))
185 noiseline = numpy.repeat(noisedB[i], len(y))
184 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
186 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
185
187
186 self.draw()
188 self.draw()
187
189
188 self.save(figpath=figpath,
190 self.save(figpath=figpath,
189 figfile=figfile,
191 figfile=figfile,
190 save=save,
192 save=save,
191 ftp=ftp,
193 ftp=ftp,
192 wr_period=wr_period,
194 wr_period=wr_period,
193 thisDatetime=thisDatetime)
195 thisDatetime=thisDatetime)
194
196
195
197
196
198
197 class SkyMapPlot(Figure):
199 class SkyMapPlot(Figure):
198
200
199 __isConfig = None
201 __isConfig = None
200 __nsubplots = None
202 __nsubplots = None
201
203
202 WIDTHPROF = None
204 WIDTHPROF = None
203 HEIGHTPROF = None
205 HEIGHTPROF = None
204 PREFIX = 'mmap'
206 PREFIX = 'mmap'
205
207
206 def __init__(self):
208 def __init__(self):
207
209
208 self.isConfig = False
210 self.isConfig = False
209 self.__nsubplots = 1
211 self.__nsubplots = 1
210
212
211 # self.WIDTH = 280
213 # self.WIDTH = 280
212 # self.HEIGHT = 250
214 # self.HEIGHT = 250
213 self.WIDTH = 600
215 self.WIDTH = 600
214 self.HEIGHT = 600
216 self.HEIGHT = 600
215 self.WIDTHPROF = 120
217 self.WIDTHPROF = 120
216 self.HEIGHTPROF = 0
218 self.HEIGHTPROF = 0
217 self.counter_imagwr = 0
219 self.counter_imagwr = 0
218
220
219 self.PLOT_CODE = MSKYMAP_CODE
221 self.PLOT_CODE = MSKYMAP_CODE
220
222
221 self.FTP_WEI = None
223 self.FTP_WEI = None
222 self.EXP_CODE = None
224 self.EXP_CODE = None
223 self.SUB_EXP_CODE = None
225 self.SUB_EXP_CODE = None
224 self.PLOT_POS = None
226 self.PLOT_POS = None
225
227
226 def getSubplots(self):
228 def getSubplots(self):
227
229
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
230 ncol = int(numpy.sqrt(self.nplots)+0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
231 nrow = int(self.nplots*1./ncol + 0.9)
230
232
231 return nrow, ncol
233 return nrow, ncol
232
234
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
235 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
234
236
235 self.__showprofile = showprofile
237 self.__showprofile = showprofile
236 self.nplots = nplots
238 self.nplots = nplots
237
239
238 ncolspan = 1
240 ncolspan = 1
239 colspan = 1
241 colspan = 1
240
242
241 self.createFigure(id = id,
243 self.createFigure(id = id,
242 wintitle = wintitle,
244 wintitle = wintitle,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
245 widthplot = self.WIDTH, #+ self.WIDTHPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
246 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
245 show=show)
247 show=show)
246
248
247 nrow, ncol = 1,1
249 nrow, ncol = 1,1
248 counter = 0
250 counter = 0
249 x = 0
251 x = 0
250 y = 0
252 y = 0
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
253 self.addAxes(1, 1, 0, 0, 1, 1, True)
252
254
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
255 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
254 tmin=0, tmax=24, timerange=None,
256 tmin=0, tmax=24, timerange=None,
255 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
257 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
256 server=None, folder=None, username=None, password=None,
258 server=None, folder=None, username=None, password=None,
257 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
259 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
258
260
259 """
261 """
260
262
261 Input:
263 Input:
262 dataOut :
264 dataOut :
263 id :
265 id :
264 wintitle :
266 wintitle :
265 channelList :
267 channelList :
266 showProfile :
268 showProfile :
267 xmin : None,
269 xmin : None,
268 xmax : None,
270 xmax : None,
269 ymin : None,
271 ymin : None,
270 ymax : None,
272 ymax : None,
271 zmin : None,
273 zmin : None,
272 zmax : None
274 zmax : None
273 """
275 """
274
276
275 arrayParameters = dataOut.data_param
277 arrayParameters = dataOut.data_param
276 error = arrayParameters[:,-1]
278 error = arrayParameters[:,-1]
277 indValid = numpy.where(error == 0)[0]
279 indValid = numpy.where(error == 0)[0]
278 finalMeteor = arrayParameters[indValid,:]
280 finalMeteor = arrayParameters[indValid,:]
279 finalAzimuth = finalMeteor[:,3]
281 finalAzimuth = finalMeteor[:,3]
280 finalZenith = finalMeteor[:,4]
282 finalZenith = finalMeteor[:,4]
281
283
282 x = finalAzimuth*numpy.pi/180
284 x = finalAzimuth*numpy.pi/180
283 y = finalZenith
285 y = finalZenith
284 x1 = [dataOut.ltctime, dataOut.ltctime]
286 x1 = [dataOut.ltctime, dataOut.ltctime]
285
287
286 #thisDatetime = dataOut.datatime
288 #thisDatetime = dataOut.datatime
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
289 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
288 title = wintitle + " Parameters"
290 title = wintitle + " Parameters"
289 xlabel = "Zonal Zenith Angle (deg) "
291 xlabel = "Zonal Zenith Angle (deg) "
290 ylabel = "Meridional Zenith Angle (deg)"
292 ylabel = "Meridional Zenith Angle (deg)"
291 update_figfile = False
293 update_figfile = False
292
294
293 if not self.isConfig:
295 if not self.isConfig:
294
296
295 nplots = 1
297 nplots = 1
296
298
297 self.setup(id=id,
299 self.setup(id=id,
298 nplots=nplots,
300 nplots=nplots,
299 wintitle=wintitle,
301 wintitle=wintitle,
300 showprofile=showprofile,
302 showprofile=showprofile,
301 show=show)
303 show=show)
302
304
303 if self.xmin is None and self.xmax is None:
305 if self.xmin is None and self.xmax is None:
304 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
306 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
305
307
306 if timerange != None:
308 if timerange != None:
307 self.timerange = timerange
309 self.timerange = timerange
308 else:
310 else:
309 self.timerange = self.xmax - self.xmin
311 self.timerange = self.xmax - self.xmin
310
312
311 self.FTP_WEI = ftp_wei
313 self.FTP_WEI = ftp_wei
312 self.EXP_CODE = exp_code
314 self.EXP_CODE = exp_code
313 self.SUB_EXP_CODE = sub_exp_code
315 self.SUB_EXP_CODE = sub_exp_code
314 self.PLOT_POS = plot_pos
316 self.PLOT_POS = plot_pos
315 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
317 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
316 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
318 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
317 self.isConfig = True
319 self.isConfig = True
318 update_figfile = True
320 update_figfile = True
319
321
320 self.setWinTitle(title)
322 self.setWinTitle(title)
321
323
322 i = 0
324 i = 0
323 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
325 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
324
326
325 axes = self.axesList[i*self.__nsubplots]
327 axes = self.axesList[i*self.__nsubplots]
326 nevents = axes.x_buffer.shape[0] + x.shape[0]
328 nevents = axes.x_buffer.shape[0] + x.shape[0]
327 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
329 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
328 axes.polar(x, y,
330 axes.polar(x, y,
329 title=title, xlabel=xlabel, ylabel=ylabel,
331 title=title, xlabel=xlabel, ylabel=ylabel,
330 ticksize=9, cblabel='')
332 ticksize=9, cblabel='')
331
333
332 self.draw()
334 self.draw()
333
335
334 self.save(figpath=figpath,
336 self.save(figpath=figpath,
335 figfile=figfile,
337 figfile=figfile,
336 save=save,
338 save=save,
337 ftp=ftp,
339 ftp=ftp,
338 wr_period=wr_period,
340 wr_period=wr_period,
339 thisDatetime=thisDatetime,
341 thisDatetime=thisDatetime,
340 update_figfile=update_figfile)
342 update_figfile=update_figfile)
341
343
342 if dataOut.ltctime >= self.xmax:
344 if dataOut.ltctime >= self.xmax:
343 self.isConfigmagwr = wr_period
345 self.isConfigmagwr = wr_period
344 self.isConfig = False
346 self.isConfig = False
345 update_figfile = True
347 update_figfile = True
346 axes.__firsttime = True
348 axes.__firsttime = True
347 self.xmin += self.timerange
349 self.xmin += self.timerange
348 self.xmax += self.timerange
350 self.xmax += self.timerange
349
351
350
352
351
353
352
354
353 class WindProfilerPlot(Figure):
355 class WindProfilerPlot(Figure):
354
356
355 __isConfig = None
357 __isConfig = None
356 __nsubplots = None
358 __nsubplots = None
357
359
358 WIDTHPROF = None
360 WIDTHPROF = None
359 HEIGHTPROF = None
361 HEIGHTPROF = None
360 PREFIX = 'wind'
362 PREFIX = 'wind'
361
363
362 def __init__(self):
364 def __init__(self):
363
365
364 self.timerange = None
366 self.timerange = None
365 self.isConfig = False
367 self.isConfig = False
366 self.__nsubplots = 1
368 self.__nsubplots = 1
367
369
368 self.WIDTH = 800
370 self.WIDTH = 800
369 self.HEIGHT = 300
371 self.HEIGHT = 300
370 self.WIDTHPROF = 120
372 self.WIDTHPROF = 120
371 self.HEIGHTPROF = 0
373 self.HEIGHTPROF = 0
372 self.counter_imagwr = 0
374 self.counter_imagwr = 0
373
375
374 self.PLOT_CODE = WIND_CODE
376 self.PLOT_CODE = WIND_CODE
375
377
376 self.FTP_WEI = None
378 self.FTP_WEI = None
377 self.EXP_CODE = None
379 self.EXP_CODE = None
378 self.SUB_EXP_CODE = None
380 self.SUB_EXP_CODE = None
379 self.PLOT_POS = None
381 self.PLOT_POS = None
380 self.tmin = None
382 self.tmin = None
381 self.tmax = None
383 self.tmax = None
382
384
383 self.xmin = None
385 self.xmin = None
384 self.xmax = None
386 self.xmax = None
385
387
386 self.figfile = None
388 self.figfile = None
387
389
388 def getSubplots(self):
390 def getSubplots(self):
389
391
390 ncol = 1
392 ncol = 1
391 nrow = self.nplots
393 nrow = self.nplots
392
394
393 return nrow, ncol
395 return nrow, ncol
394
396
395 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
397 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
396
398
397 self.__showprofile = showprofile
399 self.__showprofile = showprofile
398 self.nplots = nplots
400 self.nplots = nplots
399
401
400 ncolspan = 1
402 ncolspan = 1
401 colspan = 1
403 colspan = 1
402
404
403 self.createFigure(id = id,
405 self.createFigure(id = id,
404 wintitle = wintitle,
406 wintitle = wintitle,
405 widthplot = self.WIDTH + self.WIDTHPROF,
407 widthplot = self.WIDTH + self.WIDTHPROF,
406 heightplot = self.HEIGHT + self.HEIGHTPROF,
408 heightplot = self.HEIGHT + self.HEIGHTPROF,
407 show=show)
409 show=show)
408
410
409 nrow, ncol = self.getSubplots()
411 nrow, ncol = self.getSubplots()
410
412
411 counter = 0
413 counter = 0
412 for y in range(nrow):
414 for y in range(nrow):
413 if counter >= self.nplots:
415 if counter >= self.nplots:
414 break
416 break
415
417
416 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
418 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
417 counter += 1
419 counter += 1
418
420
419 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
421 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
420 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
422 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
421 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
423 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
422 timerange=None, SNRthresh = None,
424 timerange=None, SNRthresh = None,
423 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
425 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
424 server=None, folder=None, username=None, password=None,
426 server=None, folder=None, username=None, password=None,
425 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
427 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
426 """
428 """
427
429
428 Input:
430 Input:
429 dataOut :
431 dataOut :
430 id :
432 id :
431 wintitle :
433 wintitle :
432 channelList :
434 channelList :
433 showProfile :
435 showProfile :
434 xmin : None,
436 xmin : None,
435 xmax : None,
437 xmax : None,
436 ymin : None,
438 ymin : None,
437 ymax : None,
439 ymax : None,
438 zmin : None,
440 zmin : None,
439 zmax : None
441 zmax : None
440 """
442 """
441
443
442 # if timerange is not None:
444 # if timerange is not None:
443 # self.timerange = timerange
445 # self.timerange = timerange
444 #
446 #
445 # tmin = None
447 # tmin = None
446 # tmax = None
448 # tmax = None
447
449
448 x = dataOut.getTimeRange1(dataOut.outputInterval)
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
449 # y = dataOut.heightList
450 y = dataOut.heightList
451 y = dataOut.heightList
451
452 z = dataOut.data_output.copy()
452 z = dataOut.data_output.copy()
453 nplots = z.shape[0] #Number of wind dimensions estimated
453 nplots = z.shape[0] #Number of wind dimensions estimated
454
454 nplotsw = nplots
455 nplotsw = nplots
455
456
456 #If there is a SNR function defined
457 #If there is a SNR function defined
457 if dataOut.data_SNR is not None:
458 if dataOut.data_SNR is not None:
458 nplots += 1
459 nplots += 1
459 SNR = dataOut.data_SNR
460 SNR = dataOut.data_SNR
460 SNRavg = numpy.average(SNR, axis=0)
461 SNRavg = numpy.average(SNR, axis=0)
461
462
462 SNRdB = 10*numpy.log10(SNR)
463 SNRdB = 10*numpy.log10(SNR)
463 SNRavgdB = 10*numpy.log10(SNRavg)
464 SNRavgdB = 10*numpy.log10(SNRavg)
464
465
465 if SNRthresh == None: SNRthresh = -5.0
466 if SNRthresh == None: SNRthresh = -5.0
466 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
467
468
468 for i in range(nplotsw):
469 for i in range(nplotsw):
469 z[i,ind] = numpy.nan
470 z[i,ind] = numpy.nan
470
471
471
472
472 # showprofile = False
473 # showprofile = False
473 # thisDatetime = dataOut.datatime
474 # thisDatetime = dataOut.datatime
474 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
475 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
476 thisDatetime = datetime.datetime.now()
475 title = wintitle + "Wind"
477 title = wintitle + "Wind"
476 xlabel = ""
478 xlabel = ""
477 ylabel = "Height (km)"
479 ylabel = "Height (km)"
478 update_figfile = False
480 update_figfile = False
479
481
480 if not self.isConfig:
482 if not self.isConfig:
481
483
482 self.setup(id=id,
484 self.setup(id=id,
483 nplots=nplots,
485 nplots=nplots,
484 wintitle=wintitle,
486 wintitle=wintitle,
485 showprofile=showprofile,
487 showprofile=showprofile,
486 show=show)
488 show=show)
487
489
488 if timerange is not None:
490 if timerange is not None:
489 self.timerange = timerange
491 self.timerange = timerange
490
492
491 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
492
494
493 if ymin == None: ymin = numpy.nanmin(y)
495 #if ymin == None: ymin = numpy.nanmin(y)
494 if ymax == None: ymax = numpy.nanmax(y)
496 #if ymax == None: ymax = numpy.nanmax(y)
495
497
496 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
497 #if numpy.isnan(zmax): zmax = 50
499 #if numpy.isnan(zmax): zmax = 50
498 if zmin == None: zmin = -zmax
500 if zmin == None: zmin = -zmax
499
501
500 if nplotsw == 3:
502 if nplotsw == 3:
501 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
502 if zmin_ver == None: zmin_ver = -zmax_ver
504 if zmin_ver == None: zmin_ver = -zmax_ver
503
505
504 if dataOut.data_SNR is not None:
506 # if dataOut.data_SNR is not None:
505 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
507 # if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
506 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
508 # if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
507
509
508
510
509 self.FTP_WEI = ftp_wei
511 self.FTP_WEI = ftp_wei
510 self.EXP_CODE = exp_code
512 self.EXP_CODE = exp_code
511 self.SUB_EXP_CODE = sub_exp_code
513 self.SUB_EXP_CODE = sub_exp_code
512 self.PLOT_POS = plot_pos
514 self.PLOT_POS = plot_pos
513
515
514 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
516 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
515 self.isConfig = True
517 self.isConfig = True
516 self.figfile = figfile
518 self.figfile = figfile
517 update_figfile = True
519 update_figfile = True
518
520
519 self.setWinTitle(title)
521 self.setWinTitle(title)
520
522
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
523 #if ((self.xmax - x[1]) < (x[1]-x[0])):
522 x[1] = self.xmax
524 # x[1] = self.xmax
523
525
524 strWind = ['Zonal', 'Meridional', 'Vertical']
526 strWind = ['Zonal', 'Meridional', 'Vertical']
525 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
527 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
526 zmaxVector = [zmax, zmax, zmax_ver]
528 zmaxVector = [zmax, zmax, zmax_ver]
527 zminVector = [zmin, zmin, zmin_ver]
529 zminVector = [zmin, zmin, zmin_ver]
528 windFactor = [1,1,100]
530 windFactor = [1,1,100]
529
531
530 for i in range(nplotsw):
532 for i in range(nplotsw):
531
533
532 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
534 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
533 axes = self.axesList[i*self.__nsubplots]
535 axes = self.axesList[i*self.__nsubplots]
534
536
535 z1 = z[i,:].reshape((1,-1))*windFactor[i]
537 z1 = z[i,:].reshape((1,-1))*windFactor[i]
536
538
537 axes.pcolorbuffer(x, y, z1,
539 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
540 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
541 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
542 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
541
543
542 if dataOut.data_SNR is not None:
544 if dataOut.data_SNR is not None:
543 i += 1
545 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
546 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
547 axes = self.axesList[i*self.__nsubplots]
546
548
547 SNRavgdB = SNRavgdB.reshape((1,-1))
549 SNRavgdB = SNRavgdB.reshape((1,-1))
548
550
549 axes.pcolorbuffer(x, y, SNRavgdB,
551 axes.pcolorbuffer(x, y, SNRavgdB,
550 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
552 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
551 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
553 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
552 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
554 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
553
555
554 self.draw()
556 self.draw()
555
557
556 self.save(figpath=figpath,
558 self.save(figpath=figpath,
557 figfile=figfile,
559 figfile=figfile,
558 save=save,
560 save=save,
559 ftp=ftp,
561 ftp=ftp,
560 wr_period=wr_period,
562 wr_period=wr_period,
561 thisDatetime=thisDatetime,
563 thisDatetime=thisDatetime,
562 update_figfile=update_figfile)
564 update_figfile=update_figfile)
563
565
564 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
566 if False and dataOut.ltctime + dataOut.outputInterval >= self.xmax:
565 self.counter_imagwr = wr_period
567 self.counter_imagwr = wr_period
566 self.isConfig = False
568 self.isConfig = False
567 update_figfile = True
569 update_figfile = True
568
570
569
571
570 class ParametersPlot(Figure):
572 class ParametersPlot(Figure):
571
573
572 __isConfig = None
574 __isConfig = None
573 __nsubplots = None
575 __nsubplots = None
574
576
575 WIDTHPROF = None
577 WIDTHPROF = None
576 HEIGHTPROF = None
578 HEIGHTPROF = None
577 PREFIX = 'param'
579 PREFIX = 'param'
578
580
579 nplots = None
581 nplots = None
580 nchan = None
582 nchan = None
581
583
582 def __init__(self):
584 def __init__(self):
583
585
584 self.timerange = None
586 self.timerange = None
585 self.isConfig = False
587 self.isConfig = False
586 self.__nsubplots = 1
588 self.__nsubplots = 1
587
589
588 self.WIDTH = 800
590 self.WIDTH = 800
589 self.HEIGHT = 180
591 self.HEIGHT = 180
590 self.WIDTHPROF = 120
592 self.WIDTHPROF = 120
591 self.HEIGHTPROF = 0
593 self.HEIGHTPROF = 0
592 self.counter_imagwr = 0
594 self.counter_imagwr = 0
593
595
594 self.PLOT_CODE = RTI_CODE
596 self.PLOT_CODE = RTI_CODE
595
597
596 self.FTP_WEI = None
598 self.FTP_WEI = None
597 self.EXP_CODE = None
599 self.EXP_CODE = None
598 self.SUB_EXP_CODE = None
600 self.SUB_EXP_CODE = None
599 self.PLOT_POS = None
601 self.PLOT_POS = None
600 self.tmin = None
602 self.tmin = None
601 self.tmax = None
603 self.tmax = None
602
604
603 self.xmin = None
605 self.xmin = None
604 self.xmax = None
606 self.xmax = None
605
607
606 self.figfile = None
608 self.figfile = None
607
609
608 def getSubplots(self):
610 def getSubplots(self):
609
611
610 ncol = 1
612 ncol = 1
611 nrow = self.nplots
613 nrow = self.nplots
612
614
613 return nrow, ncol
615 return nrow, ncol
614
616
615 def setup(self, id, nplots, wintitle, show=True):
617 def setup(self, id, nplots, wintitle, show=True):
616
618
617 self.nplots = nplots
619 self.nplots = nplots
618
620
619 ncolspan = 1
621 ncolspan = 1
620 colspan = 1
622 colspan = 1
621
623
622 self.createFigure(id = id,
624 self.createFigure(id = id,
623 wintitle = wintitle,
625 wintitle = wintitle,
624 widthplot = self.WIDTH + self.WIDTHPROF,
626 widthplot = self.WIDTH + self.WIDTHPROF,
625 heightplot = self.HEIGHT + self.HEIGHTPROF,
627 heightplot = self.HEIGHT + self.HEIGHTPROF,
626 show=show)
628 show=show)
627
629
628 nrow, ncol = self.getSubplots()
630 nrow, ncol = self.getSubplots()
629
631
630 counter = 0
632 counter = 0
631 for y in range(nrow):
633 for y in range(nrow):
632 for x in range(ncol):
634 for x in range(ncol):
633
635
634 if counter >= self.nplots:
636 if counter >= self.nplots:
635 break
637 break
636
638
637 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
639 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
638
640
639 counter += 1
641 counter += 1
640
642
641 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
643 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
642 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
644 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
643 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
645 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
644 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
646 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
645 server=None, folder=None, username=None, password=None,
647 server=None, folder=None, username=None, password=None,
646 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
648 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
647
649
648 """
650 """
649
651
650 Input:
652 Input:
651 dataOut :
653 dataOut :
652 id :
654 id :
653 wintitle :
655 wintitle :
654 channelList :
656 channelList :
655 showProfile :
657 showProfile :
656 xmin : None,
658 xmin : None,
657 xmax : None,
659 xmax : None,
658 ymin : None,
660 ymin : None,
659 ymax : None,
661 ymax : None,
660 zmin : None,
662 zmin : None,
661 zmax : None
663 zmax : None
662 """
664 """
663
665
664 if colormap:
666 if colormap:
665 colormap="jet"
667 colormap="jet"
666 else:
668 else:
667 colormap="RdBu_r"
669 colormap="RdBu_r"
668
670
669 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
671 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
670 return
672 return
671
673
672 if channelList == None:
674 if channelList == None:
673 channelIndexList = range(dataOut.data_param.shape[0])
675 channelIndexList = range(dataOut.data_param.shape[0])
674 else:
676 else:
675 channelIndexList = []
677 channelIndexList = []
676 for channel in channelList:
678 for channel in channelList:
677 if channel not in dataOut.channelList:
679 if channel not in dataOut.channelList:
678 raise ValueError, "Channel %d is not in dataOut.channelList"
680 raise ValueError, "Channel %d is not in dataOut.channelList"
679 channelIndexList.append(dataOut.channelList.index(channel))
681 channelIndexList.append(dataOut.channelList.index(channel))
680
682
681 x = dataOut.getTimeRange1(dataOut.paramInterval)
683 x = dataOut.getTimeRange1(dataOut.paramInterval)
682 y = dataOut.getHeiRange()
684 y = dataOut.getHeiRange()
683
685
684 if dataOut.data_param.ndim == 3:
686 if dataOut.data_param.ndim == 3:
685 z = dataOut.data_param[channelIndexList,paramIndex,:]
687 z = dataOut.data_param[channelIndexList,paramIndex,:]
686 else:
688 else:
687 z = dataOut.data_param[channelIndexList,:]
689 z = dataOut.data_param[channelIndexList,:]
688
690
689 if showSNR:
691 if showSNR:
690 #SNR data
692 #SNR data
691 SNRarray = dataOut.data_SNR[channelIndexList,:]
693 SNRarray = dataOut.data_SNR[channelIndexList,:]
692 SNRdB = 10*numpy.log10(SNRarray)
694 SNRdB = 10*numpy.log10(SNRarray)
693 ind = numpy.where(SNRdB < SNRthresh)
695 ind = numpy.where(SNRdB < SNRthresh)
694 z[ind] = numpy.nan
696 z[ind] = numpy.nan
695
697
696 thisDatetime = dataOut.datatime
698 thisDatetime = dataOut.datatime
697 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
699 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
698 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
700 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
699 xlabel = ""
701 xlabel = ""
700 ylabel = "Range (Km)"
702 ylabel = "Range (Km)"
701
703
702 update_figfile = False
704 update_figfile = False
703
705
704 if not self.isConfig:
706 if not self.isConfig:
705
707
706 nchan = len(channelIndexList)
708 nchan = len(channelIndexList)
707 self.nchan = nchan
709 self.nchan = nchan
708 self.plotFact = 1
710 self.plotFact = 1
709 nplots = nchan
711 nplots = nchan
710
712
711 if showSNR:
713 if showSNR:
712 nplots = nchan*2
714 nplots = nchan*2
713 self.plotFact = 2
715 self.plotFact = 2
714 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
716 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
715 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
717 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
716
718
717 self.setup(id=id,
719 self.setup(id=id,
718 nplots=nplots,
720 nplots=nplots,
719 wintitle=wintitle,
721 wintitle=wintitle,
720 show=show)
722 show=show)
721
723
722 if timerange != None:
724 if timerange != None:
723 self.timerange = timerange
725 self.timerange = timerange
724
726
725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
727 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
726
728
727 if ymin == None: ymin = numpy.nanmin(y)
729 if ymin == None: ymin = numpy.nanmin(y)
728 if ymax == None: ymax = numpy.nanmax(y)
730 if ymax == None: ymax = numpy.nanmax(y)
729 if zmin == None: zmin = numpy.nanmin(z)
731 if zmin == None: zmin = numpy.nanmin(z)
730 if zmax == None: zmax = numpy.nanmax(z)
732 if zmax == None: zmax = numpy.nanmax(z)
731
733
732 self.FTP_WEI = ftp_wei
734 self.FTP_WEI = ftp_wei
733 self.EXP_CODE = exp_code
735 self.EXP_CODE = exp_code
734 self.SUB_EXP_CODE = sub_exp_code
736 self.SUB_EXP_CODE = sub_exp_code
735 self.PLOT_POS = plot_pos
737 self.PLOT_POS = plot_pos
736
738
737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
739 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
738 self.isConfig = True
740 self.isConfig = True
739 self.figfile = figfile
741 self.figfile = figfile
740 update_figfile = True
742 update_figfile = True
741
743
742 self.setWinTitle(title)
744 self.setWinTitle(title)
743
745
744 for i in range(self.nchan):
746 for i in range(self.nchan):
745 index = channelIndexList[i]
747 index = channelIndexList[i]
746 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
748 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
747 axes = self.axesList[i*self.plotFact]
749 axes = self.axesList[i*self.plotFact]
748 z1 = z[i,:].reshape((1,-1))
750 z1 = z[i,:].reshape((1,-1))
749 axes.pcolorbuffer(x, y, z1,
751 axes.pcolorbuffer(x, y, z1,
750 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
752 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
751 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
753 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
752 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
754 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
753
755
754 if showSNR:
756 if showSNR:
755 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
757 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
756 axes = self.axesList[i*self.plotFact + 1]
758 axes = self.axesList[i*self.plotFact + 1]
757 SNRdB1 = SNRdB[i,:].reshape((1,-1))
759 SNRdB1 = SNRdB[i,:].reshape((1,-1))
758 axes.pcolorbuffer(x, y, SNRdB1,
760 axes.pcolorbuffer(x, y, SNRdB1,
759 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
761 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
760 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
762 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
761 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
763 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
762
764
763
765
764 self.draw()
766 self.draw()
765
767
766 if dataOut.ltctime >= self.xmax:
768 if dataOut.ltctime >= self.xmax:
767 self.counter_imagwr = wr_period
769 self.counter_imagwr = wr_period
768 self.isConfig = False
770 self.isConfig = False
769 update_figfile = True
771 update_figfile = True
770
772
771 self.save(figpath=figpath,
773 self.save(figpath=figpath,
772 figfile=figfile,
774 figfile=figfile,
773 save=save,
775 save=save,
774 ftp=ftp,
776 ftp=ftp,
775 wr_period=wr_period,
777 wr_period=wr_period,
776 thisDatetime=thisDatetime,
778 thisDatetime=thisDatetime,
777 update_figfile=update_figfile)
779 update_figfile=update_figfile)
778
780
779
781
780
782
781 class Parameters1Plot(Figure):
783 class ParametersPlot(Figure):
782
784
783 __isConfig = None
785 __isConfig = None
784 __nsubplots = None
786 __nsubplots = None
785
787
786 WIDTHPROF = None
788 WIDTHPROF = None
787 HEIGHTPROF = None
789 HEIGHTPROF = None
788 PREFIX = 'prm'
790 PREFIX = 'prm'
789
791
790 def __init__(self):
792 def __init__(self):
791
793
792 self.timerange = 2*60*60
794 self.timerange = 2*60*60
793 self.isConfig = False
795 self.isConfig = False
794 self.__nsubplots = 1
796 self.__nsubplots = 1
795
797
796 self.WIDTH = 800
798 self.WIDTH = 800
797 self.HEIGHT = 150
799 self.HEIGHT = 150
798 self.WIDTHPROF = 120
800 self.WIDTHPROF = 120
799 self.HEIGHTPROF = 0
801 self.HEIGHTPROF = 0
800 self.counter_imagwr = 0
802 self.counter_imagwr = 0
801
803
802 self.PLOT_CODE = PARMS_CODE
804 self.PLOT_CODE = PARMS_CODE
803
805
804 self.FTP_WEI = None
806 self.FTP_WEI = None
805 self.EXP_CODE = None
807 self.EXP_CODE = None
806 self.SUB_EXP_CODE = None
808 self.SUB_EXP_CODE = None
807 self.PLOT_POS = None
809 self.PLOT_POS = None
808 self.tmin = None
810 self.tmin = None
809 self.tmax = None
811 self.tmax = None
810
812
811 self.xmin = None
813 self.xmin = None
812 self.xmax = None
814 self.xmax = None
813
815
814 self.figfile = None
816 self.figfile = None
815
817
816 def getSubplots(self):
818 def getSubplots(self):
817
819
818 ncol = 1
820 ncol = 1
819 nrow = self.nplots
821 nrow = self.nplots
820
822
821 return nrow, ncol
823 return nrow, ncol
822
824
823 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
825 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
824
826
825 self.__showprofile = showprofile
827 self.__showprofile = showprofile
826 self.nplots = nplots
828 self.nplots = nplots
827
829
828 ncolspan = 1
830 ncolspan = 1
829 colspan = 1
831 colspan = 1
830
832
831 self.createFigure(id = id,
833 self.createFigure(id = id,
832 wintitle = wintitle,
834 wintitle = wintitle,
833 widthplot = self.WIDTH + self.WIDTHPROF,
835 widthplot = self.WIDTH + self.WIDTHPROF,
834 heightplot = self.HEIGHT + self.HEIGHTPROF,
836 heightplot = self.HEIGHT + self.HEIGHTPROF,
835 show=show)
837 show=show)
836
838
837 nrow, ncol = self.getSubplots()
839 nrow, ncol = self.getSubplots()
838
840
839 counter = 0
841 counter = 0
840 for y in range(nrow):
842 for y in range(nrow):
841 for x in range(ncol):
843 for x in range(ncol):
842
844
843 if counter >= self.nplots:
845 if counter >= self.nplots:
844 break
846 break
845
847
846 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
848 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
847
849
848 if showprofile:
850 if showprofile:
849 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
851 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
850
852
851 counter += 1
853 counter += 1
852
854
853 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
855 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
854 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
856 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
855 parameterIndex = None, onlyPositive = False,
857 parameterIndex = None, onlyPositive = False,
856 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
858 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
857 DOP = True,
859 DOP = True,
858 zlabel = "", parameterName = "", parameterObject = "data_param",
860 zlabel = "", parameterName = "", parameterObject = "data_param",
859 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
861 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
860 server=None, folder=None, username=None, password=None,
862 server=None, folder=None, username=None, password=None,
861 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
863 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
862
864
863 """
865 """
864
866
865 Input:
867 Input:
866 dataOut :
868 dataOut :
867 id :
869 id :
868 wintitle :
870 wintitle :
869 channelList :
871 channelList :
870 showProfile :
872 showProfile :
871 xmin : None,
873 xmin : None,
872 xmax : None,
874 xmax : None,
873 ymin : None,
875 ymin : None,
874 ymax : None,
876 ymax : None,
875 zmin : None,
877 zmin : None,
876 zmax : None
878 zmax : None
877 """
879 """
878
880
879 data_param = getattr(dataOut, parameterObject)
881 data_param = getattr(dataOut, parameterObject)
880
882
881 if channelList == None:
883 if channelList == None:
882 channelIndexList = numpy.arange(data_param.shape[0])
884 channelIndexList = numpy.arange(data_param.shape[0])
883 else:
885 else:
884 channelIndexList = numpy.array(channelList)
886 channelIndexList = numpy.array(channelList)
885
887
886 nchan = len(channelIndexList) #Number of channels being plotted
888 nchan = len(channelIndexList) #Number of channels being plotted
887
889
888 if nchan < 1:
890 if nchan < 1:
889 return
891 return
890
892
891 nGraphsByChannel = 0
893 nGraphsByChannel = 0
892
894
893 if SNR:
895 if SNR:
894 nGraphsByChannel += 1
896 nGraphsByChannel += 1
895 if DOP:
897 if DOP:
896 nGraphsByChannel += 1
898 nGraphsByChannel += 1
897
899
898 if nGraphsByChannel < 1:
900 if nGraphsByChannel < 1:
899 return
901 return
900
902
901 nplots = nGraphsByChannel*nchan
903 nplots = nGraphsByChannel*nchan
902
904
903 if timerange is not None:
905 if timerange is not None:
904 self.timerange = timerange
906 self.timerange = timerange
905
907
906 #tmin = None
908 #tmin = None
907 #tmax = None
909 #tmax = None
908 if parameterIndex == None:
910 if parameterIndex == None:
909 parameterIndex = 1
911 parameterIndex = 1
910
912
911 x = dataOut.getTimeRange1(dataOut.paramInterval)
913 x = dataOut.getTimeRange1(dataOut.paramInterval)
912 y = dataOut.heightList
914 y = dataOut.heightList
913 z = data_param[channelIndexList,parameterIndex,:].copy()
915 z = data_param[channelIndexList,parameterIndex,:].copy()
914
916
915 zRange = dataOut.abscissaList
917 zRange = dataOut.abscissaList
916 # nChannels = z.shape[0] #Number of wind dimensions estimated
918 # nChannels = z.shape[0] #Number of wind dimensions estimated
917 # thisDatetime = dataOut.datatime
919 # thisDatetime = dataOut.datatime
918
920
919 if dataOut.data_SNR is not None:
921 if dataOut.data_SNR is not None:
920 SNRarray = dataOut.data_SNR[channelIndexList,:]
922 SNRarray = dataOut.data_SNR[channelIndexList,:]
921 SNRdB = 10*numpy.log10(SNRarray)
923 SNRdB = 10*numpy.log10(SNRarray)
922 # SNRavgdB = 10*numpy.log10(SNRavg)
924 # SNRavgdB = 10*numpy.log10(SNRavg)
923 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
925 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
924 z[ind] = numpy.nan
926 z[ind] = numpy.nan
925
927
926 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
928 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
927 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
929 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
928 xlabel = ""
930 xlabel = ""
929 ylabel = "Range (Km)"
931 ylabel = "Range (Km)"
930
932
931 if (SNR and not onlySNR): nplots = 2*nplots
933 if (SNR and not onlySNR): nplots = 2*nplots
932
934
933 if onlyPositive:
935 if onlyPositive:
934 colormap = "jet"
936 colormap = "jet"
935 zmin = 0
937 zmin = 0
936 else: colormap = "RdBu_r"
938 else: colormap = "RdBu_r"
937
939
938 if not self.isConfig:
940 if not self.isConfig:
939
941
940 self.setup(id=id,
942 self.setup(id=id,
941 nplots=nplots,
943 nplots=nplots,
942 wintitle=wintitle,
944 wintitle=wintitle,
943 showprofile=showprofile,
945 showprofile=showprofile,
944 show=show)
946 show=show)
945
947
946 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
948 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
947
949
948 if ymin == None: ymin = numpy.nanmin(y)
950 if ymin == None: ymin = numpy.nanmin(y)
949 if ymax == None: ymax = numpy.nanmax(y)
951 if ymax == None: ymax = numpy.nanmax(y)
950 if zmin == None: zmin = numpy.nanmin(zRange)
952 if zmin == None: zmin = numpy.nanmin(zRange)
951 if zmax == None: zmax = numpy.nanmax(zRange)
953 if zmax == None: zmax = numpy.nanmax(zRange)
952
954
953 if SNR:
955 if SNR:
954 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
956 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
955 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
957 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
956
958
957 self.FTP_WEI = ftp_wei
959 self.FTP_WEI = ftp_wei
958 self.EXP_CODE = exp_code
960 self.EXP_CODE = exp_code
959 self.SUB_EXP_CODE = sub_exp_code
961 self.SUB_EXP_CODE = sub_exp_code
960 self.PLOT_POS = plot_pos
962 self.PLOT_POS = plot_pos
961
963
962 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
964 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
963 self.isConfig = True
965 self.isConfig = True
964 self.figfile = figfile
966 self.figfile = figfile
965
967
966 self.setWinTitle(title)
968 self.setWinTitle(title)
967
969
968 if ((self.xmax - x[1]) < (x[1]-x[0])):
970 if ((self.xmax - x[1]) < (x[1]-x[0])):
969 x[1] = self.xmax
971 x[1] = self.xmax
970
972
971 for i in range(nchan):
973 for i in range(nchan):
972
974
973 if (SNR and not onlySNR): j = 2*i
975 if (SNR and not onlySNR): j = 2*i
974 else: j = i
976 else: j = i
975
977
976 j = nGraphsByChannel*i
978 j = nGraphsByChannel*i
977
979
978 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
980 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
979 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
981 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
980
982
981 if not onlySNR:
983 if not onlySNR:
982 axes = self.axesList[j*self.__nsubplots]
984 axes = self.axesList[j*self.__nsubplots]
983 z1 = z[i,:].reshape((1,-1))
985 z1 = z[i,:].reshape((1,-1))
984 axes.pcolorbuffer(x, y, z1,
986 axes.pcolorbuffer(x, y, z1,
985 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
987 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
986 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
988 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
987 ticksize=9, cblabel=zlabel, cbsize="1%")
989 ticksize=9, cblabel=zlabel, cbsize="1%")
988
990
989 if DOP:
991 if DOP:
990 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
992 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
991
993
992 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
994 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
993 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
995 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
994 axes = self.axesList[j]
996 axes = self.axesList[j]
995 z1 = z[i,:].reshape((1,-1))
997 z1 = z[i,:].reshape((1,-1))
996 axes.pcolorbuffer(x, y, z1,
998 axes.pcolorbuffer(x, y, z1,
997 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
999 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
998 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1000 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
999 ticksize=9, cblabel=zlabel, cbsize="1%")
1001 ticksize=9, cblabel=zlabel, cbsize="1%")
1000
1002
1001 if SNR:
1003 if SNR:
1002 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1004 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1003 axes = self.axesList[(j)*self.__nsubplots]
1005 axes = self.axesList[(j)*self.__nsubplots]
1004 if not onlySNR:
1006 if not onlySNR:
1005 axes = self.axesList[(j + 1)*self.__nsubplots]
1007 axes = self.axesList[(j + 1)*self.__nsubplots]
1006
1008
1007 axes = self.axesList[(j + nGraphsByChannel-1)]
1009 axes = self.axesList[(j + nGraphsByChannel-1)]
1008
1010
1009 z1 = SNRdB[i,:].reshape((1,-1))
1011 z1 = SNRdB[i,:].reshape((1,-1))
1010 axes.pcolorbuffer(x, y, z1,
1012 axes.pcolorbuffer(x, y, z1,
1011 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1013 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1012 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1014 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1013 ticksize=9, cblabel=zlabel, cbsize="1%")
1015 ticksize=9, cblabel=zlabel, cbsize="1%")
1014
1016
1015
1017
1016
1018
1017 self.draw()
1019 self.draw()
1018
1020
1019 if x[1] >= self.axesList[0].xmax:
1021 if x[1] >= self.axesList[0].xmax:
1020 self.counter_imagwr = wr_period
1022 self.counter_imagwr = wr_period
1021 self.isConfig = False
1023 self.isConfig = False
1022 self.figfile = None
1024 self.figfile = None
1023
1025
1024 self.save(figpath=figpath,
1026 self.save(figpath=figpath,
1025 figfile=figfile,
1027 figfile=figfile,
1026 save=save,
1028 save=save,
1027 ftp=ftp,
1029 ftp=ftp,
1028 wr_period=wr_period,
1030 wr_period=wr_period,
1029 thisDatetime=thisDatetime,
1031 thisDatetime=thisDatetime,
1030 update_figfile=False)
1032 update_figfile=False)
1031
1033
1032 class SpectralFittingPlot(Figure):
1034 class SpectralFittingPlot(Figure):
1033
1035
1034 __isConfig = None
1036 __isConfig = None
1035 __nsubplots = None
1037 __nsubplots = None
1036
1038
1037 WIDTHPROF = None
1039 WIDTHPROF = None
1038 HEIGHTPROF = None
1040 HEIGHTPROF = None
1039 PREFIX = 'prm'
1041 PREFIX = 'prm'
1040
1042
1041
1043
1042 N = None
1044 N = None
1043 ippSeconds = None
1045 ippSeconds = None
1044
1046
1045 def __init__(self):
1047 def __init__(self):
1046 self.isConfig = False
1048 self.isConfig = False
1047 self.__nsubplots = 1
1049 self.__nsubplots = 1
1048
1050
1049 self.PLOT_CODE = SPECFIT_CODE
1051 self.PLOT_CODE = SPECFIT_CODE
1050
1052
1051 self.WIDTH = 450
1053 self.WIDTH = 450
1052 self.HEIGHT = 250
1054 self.HEIGHT = 250
1053 self.WIDTHPROF = 0
1055 self.WIDTHPROF = 0
1054 self.HEIGHTPROF = 0
1056 self.HEIGHTPROF = 0
1055
1057
1056 def getSubplots(self):
1058 def getSubplots(self):
1057
1059
1058 ncol = int(numpy.sqrt(self.nplots)+0.9)
1060 ncol = int(numpy.sqrt(self.nplots)+0.9)
1059 nrow = int(self.nplots*1./ncol + 0.9)
1061 nrow = int(self.nplots*1./ncol + 0.9)
1060
1062
1061 return nrow, ncol
1063 return nrow, ncol
1062
1064
1063 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1065 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1064
1066
1065 showprofile = False
1067 showprofile = False
1066 self.__showprofile = showprofile
1068 self.__showprofile = showprofile
1067 self.nplots = nplots
1069 self.nplots = nplots
1068
1070
1069 ncolspan = 5
1071 ncolspan = 5
1070 colspan = 4
1072 colspan = 4
1071 if showprofile:
1073 if showprofile:
1072 ncolspan = 5
1074 ncolspan = 5
1073 colspan = 4
1075 colspan = 4
1074 self.__nsubplots = 2
1076 self.__nsubplots = 2
1075
1077
1076 self.createFigure(id = id,
1078 self.createFigure(id = id,
1077 wintitle = wintitle,
1079 wintitle = wintitle,
1078 widthplot = self.WIDTH + self.WIDTHPROF,
1080 widthplot = self.WIDTH + self.WIDTHPROF,
1079 heightplot = self.HEIGHT + self.HEIGHTPROF,
1081 heightplot = self.HEIGHT + self.HEIGHTPROF,
1080 show=show)
1082 show=show)
1081
1083
1082 nrow, ncol = self.getSubplots()
1084 nrow, ncol = self.getSubplots()
1083
1085
1084 counter = 0
1086 counter = 0
1085 for y in range(nrow):
1087 for y in range(nrow):
1086 for x in range(ncol):
1088 for x in range(ncol):
1087
1089
1088 if counter >= self.nplots:
1090 if counter >= self.nplots:
1089 break
1091 break
1090
1092
1091 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1093 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1092
1094
1093 if showprofile:
1095 if showprofile:
1094 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1096 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1095
1097
1096 counter += 1
1098 counter += 1
1097
1099
1098 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1100 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1099 xmin=None, xmax=None, ymin=None, ymax=None,
1101 xmin=None, xmax=None, ymin=None, ymax=None,
1100 save=False, figpath='./', figfile=None, show=True):
1102 save=False, figpath='./', figfile=None, show=True):
1101
1103
1102 """
1104 """
1103
1105
1104 Input:
1106 Input:
1105 dataOut :
1107 dataOut :
1106 id :
1108 id :
1107 wintitle :
1109 wintitle :
1108 channelList :
1110 channelList :
1109 showProfile :
1111 showProfile :
1110 xmin : None,
1112 xmin : None,
1111 xmax : None,
1113 xmax : None,
1112 zmin : None,
1114 zmin : None,
1113 zmax : None
1115 zmax : None
1114 """
1116 """
1115
1117
1116 if cutHeight==None:
1118 if cutHeight==None:
1117 h=270
1119 h=270
1118 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1120 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1119 cutHeight = dataOut.heightList[heightindex]
1121 cutHeight = dataOut.heightList[heightindex]
1120
1122
1121 factor = dataOut.normFactor
1123 factor = dataOut.normFactor
1122 x = dataOut.abscissaList[:-1]
1124 x = dataOut.abscissaList[:-1]
1123 #y = dataOut.getHeiRange()
1125 #y = dataOut.getHeiRange()
1124
1126
1125 z = dataOut.data_pre[:,:,heightindex]/factor
1127 z = dataOut.data_pre[:,:,heightindex]/factor
1126 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1128 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1127 avg = numpy.average(z, axis=1)
1129 avg = numpy.average(z, axis=1)
1128 listChannels = z.shape[0]
1130 listChannels = z.shape[0]
1129
1131
1130 #Reconstruct Function
1132 #Reconstruct Function
1131 if fit==True:
1133 if fit==True:
1132 groupArray = dataOut.groupList
1134 groupArray = dataOut.groupList
1133 listChannels = groupArray.reshape((groupArray.size))
1135 listChannels = groupArray.reshape((groupArray.size))
1134 listChannels.sort()
1136 listChannels.sort()
1135 spcFitLine = numpy.zeros(z.shape)
1137 spcFitLine = numpy.zeros(z.shape)
1136 constants = dataOut.constants
1138 constants = dataOut.constants
1137
1139
1138 nGroups = groupArray.shape[0]
1140 nGroups = groupArray.shape[0]
1139 nChannels = groupArray.shape[1]
1141 nChannels = groupArray.shape[1]
1140 nProfiles = z.shape[1]
1142 nProfiles = z.shape[1]
1141
1143
1142 for f in range(nGroups):
1144 for f in range(nGroups):
1143 groupChann = groupArray[f,:]
1145 groupChann = groupArray[f,:]
1144 p = dataOut.data_param[f,:,heightindex]
1146 p = dataOut.data_param[f,:,heightindex]
1145 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1147 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1146 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1148 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1147 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1149 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1148 spcFitLine[groupChann,:] = fitLineAux
1150 spcFitLine[groupChann,:] = fitLineAux
1149 # spcFitLine = spcFitLine/factor
1151 # spcFitLine = spcFitLine/factor
1150
1152
1151 z = z[listChannels,:]
1153 z = z[listChannels,:]
1152 spcFitLine = spcFitLine[listChannels,:]
1154 spcFitLine = spcFitLine[listChannels,:]
1153 spcFitLinedB = 10*numpy.log10(spcFitLine)
1155 spcFitLinedB = 10*numpy.log10(spcFitLine)
1154
1156
1155 zdB = 10*numpy.log10(z)
1157 zdB = 10*numpy.log10(z)
1156 #thisDatetime = dataOut.datatime
1158 #thisDatetime = dataOut.datatime
1157 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1159 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1158 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1160 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1159 xlabel = "Velocity (m/s)"
1161 xlabel = "Velocity (m/s)"
1160 ylabel = "Spectrum"
1162 ylabel = "Spectrum"
1161
1163
1162 if not self.isConfig:
1164 if not self.isConfig:
1163
1165
1164 nplots = listChannels.size
1166 nplots = listChannels.size
1165
1167
1166 self.setup(id=id,
1168 self.setup(id=id,
1167 nplots=nplots,
1169 nplots=nplots,
1168 wintitle=wintitle,
1170 wintitle=wintitle,
1169 showprofile=showprofile,
1171 showprofile=showprofile,
1170 show=show)
1172 show=show)
1171
1173
1172 if xmin == None: xmin = numpy.nanmin(x)
1174 if xmin == None: xmin = numpy.nanmin(x)
1173 if xmax == None: xmax = numpy.nanmax(x)
1175 if xmax == None: xmax = numpy.nanmax(x)
1174 if ymin == None: ymin = numpy.nanmin(zdB)
1176 if ymin == None: ymin = numpy.nanmin(zdB)
1175 if ymax == None: ymax = numpy.nanmax(zdB)+2
1177 if ymax == None: ymax = numpy.nanmax(zdB)+2
1176
1178
1177 self.isConfig = True
1179 self.isConfig = True
1178
1180
1179 self.setWinTitle(title)
1181 self.setWinTitle(title)
1180 for i in range(self.nplots):
1182 for i in range(self.nplots):
1181 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1183 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1182 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1184 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1183 axes = self.axesList[i*self.__nsubplots]
1185 axes = self.axesList[i*self.__nsubplots]
1184 if fit == False:
1186 if fit == False:
1185 axes.pline(x, zdB[i,:],
1187 axes.pline(x, zdB[i,:],
1186 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1188 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1187 xlabel=xlabel, ylabel=ylabel, title=title
1189 xlabel=xlabel, ylabel=ylabel, title=title
1188 )
1190 )
1189 if fit == True:
1191 if fit == True:
1190 fitline=spcFitLinedB[i,:]
1192 fitline=spcFitLinedB[i,:]
1191 y=numpy.vstack([zdB[i,:],fitline] )
1193 y=numpy.vstack([zdB[i,:],fitline] )
1192 legendlabels=['Data','Fitting']
1194 legendlabels=['Data','Fitting']
1193 axes.pmultilineyaxis(x, y,
1195 axes.pmultilineyaxis(x, y,
1194 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1196 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1195 xlabel=xlabel, ylabel=ylabel, title=title,
1197 xlabel=xlabel, ylabel=ylabel, title=title,
1196 legendlabels=legendlabels, marker=None,
1198 legendlabels=legendlabels, marker=None,
1197 linestyle='solid', grid='both')
1199 linestyle='solid', grid='both')
1198
1200
1199 self.draw()
1201 self.draw()
1200
1202
1201 self.save(figpath=figpath,
1203 self.save(figpath=figpath,
1202 figfile=figfile,
1204 figfile=figfile,
1203 save=save,
1205 save=save,
1204 ftp=ftp,
1206 ftp=ftp,
1205 wr_period=wr_period,
1207 wr_period=wr_period,
1206 thisDatetime=thisDatetime)
1208 thisDatetime=thisDatetime)
1207
1209
1208
1210
1209 class EWDriftsPlot(Figure):
1211 class EWDriftsPlot(Figure):
1210
1212
1211 __isConfig = None
1213 __isConfig = None
1212 __nsubplots = None
1214 __nsubplots = None
1213
1215
1214 WIDTHPROF = None
1216 WIDTHPROF = None
1215 HEIGHTPROF = None
1217 HEIGHTPROF = None
1216 PREFIX = 'drift'
1218 PREFIX = 'drift'
1217
1219
1218 def __init__(self):
1220 def __init__(self):
1219
1221
1220 self.timerange = 2*60*60
1222 self.timerange = 2*60*60
1221 self.isConfig = False
1223 self.isConfig = False
1222 self.__nsubplots = 1
1224 self.__nsubplots = 1
1223
1225
1224 self.WIDTH = 800
1226 self.WIDTH = 800
1225 self.HEIGHT = 150
1227 self.HEIGHT = 150
1226 self.WIDTHPROF = 120
1228 self.WIDTHPROF = 120
1227 self.HEIGHTPROF = 0
1229 self.HEIGHTPROF = 0
1228 self.counter_imagwr = 0
1230 self.counter_imagwr = 0
1229
1231
1230 self.PLOT_CODE = EWDRIFT_CODE
1232 self.PLOT_CODE = EWDRIFT_CODE
1231
1233
1232 self.FTP_WEI = None
1234 self.FTP_WEI = None
1233 self.EXP_CODE = None
1235 self.EXP_CODE = None
1234 self.SUB_EXP_CODE = None
1236 self.SUB_EXP_CODE = None
1235 self.PLOT_POS = None
1237 self.PLOT_POS = None
1236 self.tmin = None
1238 self.tmin = None
1237 self.tmax = None
1239 self.tmax = None
1238
1240
1239 self.xmin = None
1241 self.xmin = None
1240 self.xmax = None
1242 self.xmax = None
1241
1243
1242 self.figfile = None
1244 self.figfile = None
1243
1245
1244 def getSubplots(self):
1246 def getSubplots(self):
1245
1247
1246 ncol = 1
1248 ncol = 1
1247 nrow = self.nplots
1249 nrow = self.nplots
1248
1250
1249 return nrow, ncol
1251 return nrow, ncol
1250
1252
1251 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1253 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1252
1254
1253 self.__showprofile = showprofile
1255 self.__showprofile = showprofile
1254 self.nplots = nplots
1256 self.nplots = nplots
1255
1257
1256 ncolspan = 1
1258 ncolspan = 1
1257 colspan = 1
1259 colspan = 1
1258
1260
1259 self.createFigure(id = id,
1261 self.createFigure(id = id,
1260 wintitle = wintitle,
1262 wintitle = wintitle,
1261 widthplot = self.WIDTH + self.WIDTHPROF,
1263 widthplot = self.WIDTH + self.WIDTHPROF,
1262 heightplot = self.HEIGHT + self.HEIGHTPROF,
1264 heightplot = self.HEIGHT + self.HEIGHTPROF,
1263 show=show)
1265 show=show)
1264
1266
1265 nrow, ncol = self.getSubplots()
1267 nrow, ncol = self.getSubplots()
1266
1268
1267 counter = 0
1269 counter = 0
1268 for y in range(nrow):
1270 for y in range(nrow):
1269 if counter >= self.nplots:
1271 if counter >= self.nplots:
1270 break
1272 break
1271
1273
1272 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1274 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1273 counter += 1
1275 counter += 1
1274
1276
1275 def run(self, dataOut, id, wintitle="", channelList=None,
1277 def run(self, dataOut, id, wintitle="", channelList=None,
1276 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1278 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1277 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1279 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1278 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1280 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1279 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1281 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1280 server=None, folder=None, username=None, password=None,
1282 server=None, folder=None, username=None, password=None,
1281 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1283 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1282 """
1284 """
1283
1285
1284 Input:
1286 Input:
1285 dataOut :
1287 dataOut :
1286 id :
1288 id :
1287 wintitle :
1289 wintitle :
1288 channelList :
1290 channelList :
1289 showProfile :
1291 showProfile :
1290 xmin : None,
1292 xmin : None,
1291 xmax : None,
1293 xmax : None,
1292 ymin : None,
1294 ymin : None,
1293 ymax : None,
1295 ymax : None,
1294 zmin : None,
1296 zmin : None,
1295 zmax : None
1297 zmax : None
1296 """
1298 """
1297
1299
1298 if timerange is not None:
1300 if timerange is not None:
1299 self.timerange = timerange
1301 self.timerange = timerange
1300
1302
1301 tmin = None
1303 tmin = None
1302 tmax = None
1304 tmax = None
1303
1305
1304 x = dataOut.getTimeRange1(dataOut.outputInterval)
1306 x = dataOut.getTimeRange1(dataOut.outputInterval)
1305 # y = dataOut.heightList
1307 # y = dataOut.heightList
1306 y = dataOut.heightList
1308 y = dataOut.heightList
1307
1309
1308 z = dataOut.data_output
1310 z = dataOut.data_output
1309 nplots = z.shape[0] #Number of wind dimensions estimated
1311 nplots = z.shape[0] #Number of wind dimensions estimated
1310 nplotsw = nplots
1312 nplotsw = nplots
1311
1313
1312 #If there is a SNR function defined
1314 #If there is a SNR function defined
1313 if dataOut.data_SNR is not None:
1315 if dataOut.data_SNR is not None:
1314 nplots += 1
1316 nplots += 1
1315 SNR = dataOut.data_SNR
1317 SNR = dataOut.data_SNR
1316
1318
1317 if SNR_1:
1319 if SNR_1:
1318 SNR += 1
1320 SNR += 1
1319
1321
1320 SNRavg = numpy.average(SNR, axis=0)
1322 SNRavg = numpy.average(SNR, axis=0)
1321
1323
1322 SNRdB = 10*numpy.log10(SNR)
1324 SNRdB = 10*numpy.log10(SNR)
1323 SNRavgdB = 10*numpy.log10(SNRavg)
1325 SNRavgdB = 10*numpy.log10(SNRavg)
1324
1326
1325 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1327 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1326
1328
1327 for i in range(nplotsw):
1329 for i in range(nplotsw):
1328 z[i,ind] = numpy.nan
1330 z[i,ind] = numpy.nan
1329
1331
1330
1332
1331 showprofile = False
1333 showprofile = False
1332 # thisDatetime = dataOut.datatime
1334 # thisDatetime = dataOut.datatime
1333 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1335 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1334 title = wintitle + " EW Drifts"
1336 title = wintitle + " EW Drifts"
1335 xlabel = ""
1337 xlabel = ""
1336 ylabel = "Height (Km)"
1338 ylabel = "Height (Km)"
1337
1339
1338 if not self.isConfig:
1340 if not self.isConfig:
1339
1341
1340 self.setup(id=id,
1342 self.setup(id=id,
1341 nplots=nplots,
1343 nplots=nplots,
1342 wintitle=wintitle,
1344 wintitle=wintitle,
1343 showprofile=showprofile,
1345 showprofile=showprofile,
1344 show=show)
1346 show=show)
1345
1347
1346 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1348 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1347
1349
1348 if ymin == None: ymin = numpy.nanmin(y)
1350 if ymin == None: ymin = numpy.nanmin(y)
1349 if ymax == None: ymax = numpy.nanmax(y)
1351 if ymax == None: ymax = numpy.nanmax(y)
1350
1352
1351 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1353 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1352 if zminZonal == None: zminZonal = -zmaxZonal
1354 if zminZonal == None: zminZonal = -zmaxZonal
1353 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1355 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1354 if zminVertical == None: zminVertical = -zmaxVertical
1356 if zminVertical == None: zminVertical = -zmaxVertical
1355
1357
1356 if dataOut.data_SNR is not None:
1358 if dataOut.data_SNR is not None:
1357 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1359 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1358 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1360 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1359
1361
1360 self.FTP_WEI = ftp_wei
1362 self.FTP_WEI = ftp_wei
1361 self.EXP_CODE = exp_code
1363 self.EXP_CODE = exp_code
1362 self.SUB_EXP_CODE = sub_exp_code
1364 self.SUB_EXP_CODE = sub_exp_code
1363 self.PLOT_POS = plot_pos
1365 self.PLOT_POS = plot_pos
1364
1366
1365 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1367 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1366 self.isConfig = True
1368 self.isConfig = True
1367
1369
1368
1370
1369 self.setWinTitle(title)
1371 self.setWinTitle(title)
1370
1372
1371 if ((self.xmax - x[1]) < (x[1]-x[0])):
1373 if ((self.xmax - x[1]) < (x[1]-x[0])):
1372 x[1] = self.xmax
1374 x[1] = self.xmax
1373
1375
1374 strWind = ['Zonal','Vertical']
1376 strWind = ['Zonal','Vertical']
1375 strCb = 'Velocity (m/s)'
1377 strCb = 'Velocity (m/s)'
1376 zmaxVector = [zmaxZonal, zmaxVertical]
1378 zmaxVector = [zmaxZonal, zmaxVertical]
1377 zminVector = [zminZonal, zminVertical]
1379 zminVector = [zminZonal, zminVertical]
1378
1380
1379 for i in range(nplotsw):
1381 for i in range(nplotsw):
1380
1382
1381 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1383 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1382 axes = self.axesList[i*self.__nsubplots]
1384 axes = self.axesList[i*self.__nsubplots]
1383
1385
1384 z1 = z[i,:].reshape((1,-1))
1386 z1 = z[i,:].reshape((1,-1))
1385
1387
1386 axes.pcolorbuffer(x, y, z1,
1388 axes.pcolorbuffer(x, y, z1,
1387 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1389 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1388 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1390 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1389 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1391 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1390
1392
1391 if dataOut.data_SNR is not None:
1393 if dataOut.data_SNR is not None:
1392 i += 1
1394 i += 1
1393 if SNR_1:
1395 if SNR_1:
1394 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1396 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1395 else:
1397 else:
1396 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1398 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1397 axes = self.axesList[i*self.__nsubplots]
1399 axes = self.axesList[i*self.__nsubplots]
1398 SNRavgdB = SNRavgdB.reshape((1,-1))
1400 SNRavgdB = SNRavgdB.reshape((1,-1))
1399
1401
1400 axes.pcolorbuffer(x, y, SNRavgdB,
1402 axes.pcolorbuffer(x, y, SNRavgdB,
1401 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1403 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1402 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1404 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1403 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1405 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1404
1406
1405 self.draw()
1407 self.draw()
1406
1408
1407 if x[1] >= self.axesList[0].xmax:
1409 if x[1] >= self.axesList[0].xmax:
1408 self.counter_imagwr = wr_period
1410 self.counter_imagwr = wr_period
1409 self.isConfig = False
1411 self.isConfig = False
1410 self.figfile = None
1412 self.figfile = None
1411
1413
1412
1414
1413
1415
1414
1416
1415 class PhasePlot(Figure):
1417 class PhasePlot(Figure):
1416
1418
1417 __isConfig = None
1419 __isConfig = None
1418 __nsubplots = None
1420 __nsubplots = None
1419
1421
1420 PREFIX = 'mphase'
1422 PREFIX = 'mphase'
1421
1423
1422 def __init__(self):
1424 def __init__(self):
1423
1425
1424 self.timerange = 24*60*60
1426 self.timerange = 24*60*60
1425 self.isConfig = False
1427 self.isConfig = False
1426 self.__nsubplots = 1
1428 self.__nsubplots = 1
1427 self.counter_imagwr = 0
1429 self.counter_imagwr = 0
1428 self.WIDTH = 600
1430 self.WIDTH = 600
1429 self.HEIGHT = 300
1431 self.HEIGHT = 300
1430 self.WIDTHPROF = 120
1432 self.WIDTHPROF = 120
1431 self.HEIGHTPROF = 0
1433 self.HEIGHTPROF = 0
1432 self.xdata = None
1434 self.xdata = None
1433 self.ydata = None
1435 self.ydata = None
1434
1436
1435 self.PLOT_CODE = MPHASE_CODE
1437 self.PLOT_CODE = MPHASE_CODE
1436
1438
1437 self.FTP_WEI = None
1439 self.FTP_WEI = None
1438 self.EXP_CODE = None
1440 self.EXP_CODE = None
1439 self.SUB_EXP_CODE = None
1441 self.SUB_EXP_CODE = None
1440 self.PLOT_POS = None
1442 self.PLOT_POS = None
1441
1443
1442
1444
1443 self.filename_phase = None
1445 self.filename_phase = None
1444
1446
1445 self.figfile = None
1447 self.figfile = None
1446
1448
1447 def getSubplots(self):
1449 def getSubplots(self):
1448
1450
1449 ncol = 1
1451 ncol = 1
1450 nrow = 1
1452 nrow = 1
1451
1453
1452 return nrow, ncol
1454 return nrow, ncol
1453
1455
1454 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1456 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1455
1457
1456 self.__showprofile = showprofile
1458 self.__showprofile = showprofile
1457 self.nplots = nplots
1459 self.nplots = nplots
1458
1460
1459 ncolspan = 7
1461 ncolspan = 7
1460 colspan = 6
1462 colspan = 6
1461 self.__nsubplots = 2
1463 self.__nsubplots = 2
1462
1464
1463 self.createFigure(id = id,
1465 self.createFigure(id = id,
1464 wintitle = wintitle,
1466 wintitle = wintitle,
1465 widthplot = self.WIDTH+self.WIDTHPROF,
1467 widthplot = self.WIDTH+self.WIDTHPROF,
1466 heightplot = self.HEIGHT+self.HEIGHTPROF,
1468 heightplot = self.HEIGHT+self.HEIGHTPROF,
1467 show=show)
1469 show=show)
1468
1470
1469 nrow, ncol = self.getSubplots()
1471 nrow, ncol = self.getSubplots()
1470
1472
1471 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1473 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1472
1474
1473
1475
1474 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1476 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1475 xmin=None, xmax=None, ymin=None, ymax=None,
1477 xmin=None, xmax=None, ymin=None, ymax=None,
1476 timerange=None,
1478 timerange=None,
1477 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1479 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1478 server=None, folder=None, username=None, password=None,
1480 server=None, folder=None, username=None, password=None,
1479 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1481 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1480
1482
1481
1483
1482 tmin = None
1484 tmin = None
1483 tmax = None
1485 tmax = None
1484 x = dataOut.getTimeRange1(dataOut.outputInterval)
1486 x = dataOut.getTimeRange1(dataOut.outputInterval)
1485 y = dataOut.getHeiRange()
1487 y = dataOut.getHeiRange()
1486
1488
1487
1489
1488 #thisDatetime = dataOut.datatime
1490 #thisDatetime = dataOut.datatime
1489 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1491 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1490 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1492 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1491 xlabel = "Local Time"
1493 xlabel = "Local Time"
1492 ylabel = "Phase"
1494 ylabel = "Phase"
1493
1495
1494
1496
1495 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1497 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1496 phase_beacon = dataOut.data_output
1498 phase_beacon = dataOut.data_output
1497 update_figfile = False
1499 update_figfile = False
1498
1500
1499 if not self.isConfig:
1501 if not self.isConfig:
1500
1502
1501 self.nplots = phase_beacon.size
1503 self.nplots = phase_beacon.size
1502
1504
1503 self.setup(id=id,
1505 self.setup(id=id,
1504 nplots=self.nplots,
1506 nplots=self.nplots,
1505 wintitle=wintitle,
1507 wintitle=wintitle,
1506 showprofile=showprofile,
1508 showprofile=showprofile,
1507 show=show)
1509 show=show)
1508
1510
1509 if timerange is not None:
1511 if timerange is not None:
1510 self.timerange = timerange
1512 self.timerange = timerange
1511
1513
1512 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1514 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1513
1515
1514 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1516 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1515 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1517 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1516
1518
1517 self.FTP_WEI = ftp_wei
1519 self.FTP_WEI = ftp_wei
1518 self.EXP_CODE = exp_code
1520 self.EXP_CODE = exp_code
1519 self.SUB_EXP_CODE = sub_exp_code
1521 self.SUB_EXP_CODE = sub_exp_code
1520 self.PLOT_POS = plot_pos
1522 self.PLOT_POS = plot_pos
1521
1523
1522 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1524 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1523 self.isConfig = True
1525 self.isConfig = True
1524 self.figfile = figfile
1526 self.figfile = figfile
1525 self.xdata = numpy.array([])
1527 self.xdata = numpy.array([])
1526 self.ydata = numpy.array([])
1528 self.ydata = numpy.array([])
1527
1529
1528 #open file beacon phase
1530 #open file beacon phase
1529 path = '%s%03d' %(self.PREFIX, self.id)
1531 path = '%s%03d' %(self.PREFIX, self.id)
1530 beacon_file = os.path.join(path,'%s.txt'%self.name)
1532 beacon_file = os.path.join(path,'%s.txt'%self.name)
1531 self.filename_phase = os.path.join(figpath,beacon_file)
1533 self.filename_phase = os.path.join(figpath,beacon_file)
1532 update_figfile = True
1534 update_figfile = True
1533
1535
1534
1536
1535 #store data beacon phase
1537 #store data beacon phase
1536 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1538 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1537
1539
1538 self.setWinTitle(title)
1540 self.setWinTitle(title)
1539
1541
1540
1542
1541 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1543 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1542
1544
1543 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1545 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1544
1546
1545 axes = self.axesList[0]
1547 axes = self.axesList[0]
1546
1548
1547 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1549 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1548
1550
1549 if len(self.ydata)==0:
1551 if len(self.ydata)==0:
1550 self.ydata = phase_beacon.reshape(-1,1)
1552 self.ydata = phase_beacon.reshape(-1,1)
1551 else:
1553 else:
1552 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1554 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1553
1555
1554
1556
1555 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1557 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1556 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1558 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1557 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1559 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1558 XAxisAsTime=True, grid='both'
1560 XAxisAsTime=True, grid='both'
1559 )
1561 )
1560
1562
1561 self.draw()
1563 self.draw()
1562
1564
1563 self.save(figpath=figpath,
1565 self.save(figpath=figpath,
1564 figfile=figfile,
1566 figfile=figfile,
1565 save=save,
1567 save=save,
1566 ftp=ftp,
1568 ftp=ftp,
1567 wr_period=wr_period,
1569 wr_period=wr_period,
1568 thisDatetime=thisDatetime,
1570 thisDatetime=thisDatetime,
1569 update_figfile=update_figfile)
1571 update_figfile=update_figfile)
1570
1572
1571 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1573 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1572 self.counter_imagwr = wr_period
1574 self.counter_imagwr = wr_period
1573 self.isConfig = False
1575 self.isConfig = False
1574 update_figfile = True
1576 update_figfile = True
1575
1577
1576
1578
1577
1579
1578 class NSMeteorDetection1Plot(Figure):
1580 class NSMeteorDetection1Plot(Figure):
1579
1581
1580 isConfig = None
1582 isConfig = None
1581 __nsubplots = None
1583 __nsubplots = None
1582
1584
1583 WIDTHPROF = None
1585 WIDTHPROF = None
1584 HEIGHTPROF = None
1586 HEIGHTPROF = None
1585 PREFIX = 'nsm'
1587 PREFIX = 'nsm'
1586
1588
1587 zminList = None
1589 zminList = None
1588 zmaxList = None
1590 zmaxList = None
1589 cmapList = None
1591 cmapList = None
1590 titleList = None
1592 titleList = None
1591 nPairs = None
1593 nPairs = None
1592 nChannels = None
1594 nChannels = None
1593 nParam = None
1595 nParam = None
1594
1596
1595 def __init__(self):
1597 def __init__(self):
1596
1598
1597 self.isConfig = False
1599 self.isConfig = False
1598 self.__nsubplots = 1
1600 self.__nsubplots = 1
1599
1601
1600 self.WIDTH = 750
1602 self.WIDTH = 750
1601 self.HEIGHT = 250
1603 self.HEIGHT = 250
1602 self.WIDTHPROF = 120
1604 self.WIDTHPROF = 120
1603 self.HEIGHTPROF = 0
1605 self.HEIGHTPROF = 0
1604 self.counter_imagwr = 0
1606 self.counter_imagwr = 0
1605
1607
1606 self.PLOT_CODE = SPEC_CODE
1608 self.PLOT_CODE = SPEC_CODE
1607
1609
1608 self.FTP_WEI = None
1610 self.FTP_WEI = None
1609 self.EXP_CODE = None
1611 self.EXP_CODE = None
1610 self.SUB_EXP_CODE = None
1612 self.SUB_EXP_CODE = None
1611 self.PLOT_POS = None
1613 self.PLOT_POS = None
1612
1614
1613 self.__xfilter_ena = False
1615 self.__xfilter_ena = False
1614 self.__yfilter_ena = False
1616 self.__yfilter_ena = False
1615
1617
1616 def getSubplots(self):
1618 def getSubplots(self):
1617
1619
1618 ncol = 3
1620 ncol = 3
1619 nrow = int(numpy.ceil(self.nplots/3.0))
1621 nrow = int(numpy.ceil(self.nplots/3.0))
1620
1622
1621 return nrow, ncol
1623 return nrow, ncol
1622
1624
1623 def setup(self, id, nplots, wintitle, show=True):
1625 def setup(self, id, nplots, wintitle, show=True):
1624
1626
1625 self.nplots = nplots
1627 self.nplots = nplots
1626
1628
1627 ncolspan = 1
1629 ncolspan = 1
1628 colspan = 1
1630 colspan = 1
1629
1631
1630 self.createFigure(id = id,
1632 self.createFigure(id = id,
1631 wintitle = wintitle,
1633 wintitle = wintitle,
1632 widthplot = self.WIDTH + self.WIDTHPROF,
1634 widthplot = self.WIDTH + self.WIDTHPROF,
1633 heightplot = self.HEIGHT + self.HEIGHTPROF,
1635 heightplot = self.HEIGHT + self.HEIGHTPROF,
1634 show=show)
1636 show=show)
1635
1637
1636 nrow, ncol = self.getSubplots()
1638 nrow, ncol = self.getSubplots()
1637
1639
1638 counter = 0
1640 counter = 0
1639 for y in range(nrow):
1641 for y in range(nrow):
1640 for x in range(ncol):
1642 for x in range(ncol):
1641
1643
1642 if counter >= self.nplots:
1644 if counter >= self.nplots:
1643 break
1645 break
1644
1646
1645 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1647 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1646
1648
1647 counter += 1
1649 counter += 1
1648
1650
1649 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1651 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1650 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1652 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1651 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1653 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1652 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1654 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1653 server=None, folder=None, username=None, password=None,
1655 server=None, folder=None, username=None, password=None,
1654 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1656 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1655 xaxis="frequency"):
1657 xaxis="frequency"):
1656
1658
1657 """
1659 """
1658
1660
1659 Input:
1661 Input:
1660 dataOut :
1662 dataOut :
1661 id :
1663 id :
1662 wintitle :
1664 wintitle :
1663 channelList :
1665 channelList :
1664 showProfile :
1666 showProfile :
1665 xmin : None,
1667 xmin : None,
1666 xmax : None,
1668 xmax : None,
1667 ymin : None,
1669 ymin : None,
1668 ymax : None,
1670 ymax : None,
1669 zmin : None,
1671 zmin : None,
1670 zmax : None
1672 zmax : None
1671 """
1673 """
1672 #SEPARAR EN DOS PLOTS
1674 #SEPARAR EN DOS PLOTS
1673 nParam = dataOut.data_param.shape[1] - 3
1675 nParam = dataOut.data_param.shape[1] - 3
1674
1676
1675 utctime = dataOut.data_param[0,0]
1677 utctime = dataOut.data_param[0,0]
1676 tmet = dataOut.data_param[:,1].astype(int)
1678 tmet = dataOut.data_param[:,1].astype(int)
1677 hmet = dataOut.data_param[:,2].astype(int)
1679 hmet = dataOut.data_param[:,2].astype(int)
1678
1680
1679 x = dataOut.abscissaList
1681 x = dataOut.abscissaList
1680 y = dataOut.heightList
1682 y = dataOut.heightList
1681
1683
1682 z = numpy.zeros((nParam, y.size, x.size - 1))
1684 z = numpy.zeros((nParam, y.size, x.size - 1))
1683 z[:,:] = numpy.nan
1685 z[:,:] = numpy.nan
1684 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1686 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1685 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1687 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1686
1688
1687 xlabel = "Time (s)"
1689 xlabel = "Time (s)"
1688 ylabel = "Range (km)"
1690 ylabel = "Range (km)"
1689
1691
1690 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1692 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1691
1693
1692 if not self.isConfig:
1694 if not self.isConfig:
1693
1695
1694 nplots = nParam
1696 nplots = nParam
1695
1697
1696 self.setup(id=id,
1698 self.setup(id=id,
1697 nplots=nplots,
1699 nplots=nplots,
1698 wintitle=wintitle,
1700 wintitle=wintitle,
1699 show=show)
1701 show=show)
1700
1702
1701 if xmin is None: xmin = numpy.nanmin(x)
1703 if xmin is None: xmin = numpy.nanmin(x)
1702 if xmax is None: xmax = numpy.nanmax(x)
1704 if xmax is None: xmax = numpy.nanmax(x)
1703 if ymin is None: ymin = numpy.nanmin(y)
1705 if ymin is None: ymin = numpy.nanmin(y)
1704 if ymax is None: ymax = numpy.nanmax(y)
1706 if ymax is None: ymax = numpy.nanmax(y)
1705 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1707 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1706 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1708 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1707 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1709 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1708 if vmin is None: vmin = -vmax
1710 if vmin is None: vmin = -vmax
1709 if wmin is None: wmin = 0
1711 if wmin is None: wmin = 0
1710 if wmax is None: wmax = 50
1712 if wmax is None: wmax = 50
1711
1713
1712 pairsList = dataOut.groupList
1714 pairsList = dataOut.groupList
1713 self.nPairs = len(dataOut.groupList)
1715 self.nPairs = len(dataOut.groupList)
1714
1716
1715 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1717 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1716 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1718 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1717 titleList = ["SNR","Radial Velocity","Coherence"]
1719 titleList = ["SNR","Radial Velocity","Coherence"]
1718 cmapList = ["jet","RdBu_r","jet"]
1720 cmapList = ["jet","RdBu_r","jet"]
1719
1721
1720 for i in range(self.nPairs):
1722 for i in range(self.nPairs):
1721 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1723 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1722 titleList = titleList + [strAux1]
1724 titleList = titleList + [strAux1]
1723 cmapList = cmapList + ["RdBu_r"]
1725 cmapList = cmapList + ["RdBu_r"]
1724
1726
1725 self.zminList = zminList
1727 self.zminList = zminList
1726 self.zmaxList = zmaxList
1728 self.zmaxList = zmaxList
1727 self.cmapList = cmapList
1729 self.cmapList = cmapList
1728 self.titleList = titleList
1730 self.titleList = titleList
1729
1731
1730 self.FTP_WEI = ftp_wei
1732 self.FTP_WEI = ftp_wei
1731 self.EXP_CODE = exp_code
1733 self.EXP_CODE = exp_code
1732 self.SUB_EXP_CODE = sub_exp_code
1734 self.SUB_EXP_CODE = sub_exp_code
1733 self.PLOT_POS = plot_pos
1735 self.PLOT_POS = plot_pos
1734
1736
1735 self.isConfig = True
1737 self.isConfig = True
1736
1738
1737 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1739 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1738
1740
1739 for i in range(nParam):
1741 for i in range(nParam):
1740 title = self.titleList[i] + ": " +str_datetime
1742 title = self.titleList[i] + ": " +str_datetime
1741 axes = self.axesList[i]
1743 axes = self.axesList[i]
1742 axes.pcolor(x, y, z[i,:].T,
1744 axes.pcolor(x, y, z[i,:].T,
1743 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1745 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1744 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1746 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1745 self.draw()
1747 self.draw()
1746
1748
1747 if figfile == None:
1749 if figfile == None:
1748 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1750 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1749 name = str_datetime
1751 name = str_datetime
1750 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1752 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1751 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1753 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1752 figfile = self.getFilename(name)
1754 figfile = self.getFilename(name)
1753
1755
1754 self.save(figpath=figpath,
1756 self.save(figpath=figpath,
1755 figfile=figfile,
1757 figfile=figfile,
1756 save=save,
1758 save=save,
1757 ftp=ftp,
1759 ftp=ftp,
1758 wr_period=wr_period,
1760 wr_period=wr_period,
1759 thisDatetime=thisDatetime)
1761 thisDatetime=thisDatetime)
1760
1762
1761
1763
1762 class NSMeteorDetection2Plot(Figure):
1764 class NSMeteorDetection2Plot(Figure):
1763
1765
1764 isConfig = None
1766 isConfig = None
1765 __nsubplots = None
1767 __nsubplots = None
1766
1768
1767 WIDTHPROF = None
1769 WIDTHPROF = None
1768 HEIGHTPROF = None
1770 HEIGHTPROF = None
1769 PREFIX = 'nsm'
1771 PREFIX = 'nsm'
1770
1772
1771 zminList = None
1773 zminList = None
1772 zmaxList = None
1774 zmaxList = None
1773 cmapList = None
1775 cmapList = None
1774 titleList = None
1776 titleList = None
1775 nPairs = None
1777 nPairs = None
1776 nChannels = None
1778 nChannels = None
1777 nParam = None
1779 nParam = None
1778
1780
1779 def __init__(self):
1781 def __init__(self):
1780
1782
1781 self.isConfig = False
1783 self.isConfig = False
1782 self.__nsubplots = 1
1784 self.__nsubplots = 1
1783
1785
1784 self.WIDTH = 750
1786 self.WIDTH = 750
1785 self.HEIGHT = 250
1787 self.HEIGHT = 250
1786 self.WIDTHPROF = 120
1788 self.WIDTHPROF = 120
1787 self.HEIGHTPROF = 0
1789 self.HEIGHTPROF = 0
1788 self.counter_imagwr = 0
1790 self.counter_imagwr = 0
1789
1791
1790 self.PLOT_CODE = SPEC_CODE
1792 self.PLOT_CODE = SPEC_CODE
1791
1793
1792 self.FTP_WEI = None
1794 self.FTP_WEI = None
1793 self.EXP_CODE = None
1795 self.EXP_CODE = None
1794 self.SUB_EXP_CODE = None
1796 self.SUB_EXP_CODE = None
1795 self.PLOT_POS = None
1797 self.PLOT_POS = None
1796
1798
1797 self.__xfilter_ena = False
1799 self.__xfilter_ena = False
1798 self.__yfilter_ena = False
1800 self.__yfilter_ena = False
1799
1801
1800 def getSubplots(self):
1802 def getSubplots(self):
1801
1803
1802 ncol = 3
1804 ncol = 3
1803 nrow = int(numpy.ceil(self.nplots/3.0))
1805 nrow = int(numpy.ceil(self.nplots/3.0))
1804
1806
1805 return nrow, ncol
1807 return nrow, ncol
1806
1808
1807 def setup(self, id, nplots, wintitle, show=True):
1809 def setup(self, id, nplots, wintitle, show=True):
1808
1810
1809 self.nplots = nplots
1811 self.nplots = nplots
1810
1812
1811 ncolspan = 1
1813 ncolspan = 1
1812 colspan = 1
1814 colspan = 1
1813
1815
1814 self.createFigure(id = id,
1816 self.createFigure(id = id,
1815 wintitle = wintitle,
1817 wintitle = wintitle,
1816 widthplot = self.WIDTH + self.WIDTHPROF,
1818 widthplot = self.WIDTH + self.WIDTHPROF,
1817 heightplot = self.HEIGHT + self.HEIGHTPROF,
1819 heightplot = self.HEIGHT + self.HEIGHTPROF,
1818 show=show)
1820 show=show)
1819
1821
1820 nrow, ncol = self.getSubplots()
1822 nrow, ncol = self.getSubplots()
1821
1823
1822 counter = 0
1824 counter = 0
1823 for y in range(nrow):
1825 for y in range(nrow):
1824 for x in range(ncol):
1826 for x in range(ncol):
1825
1827
1826 if counter >= self.nplots:
1828 if counter >= self.nplots:
1827 break
1829 break
1828
1830
1829 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1831 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1830
1832
1831 counter += 1
1833 counter += 1
1832
1834
1833 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1835 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1834 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1836 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1835 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1837 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1836 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1838 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1837 server=None, folder=None, username=None, password=None,
1839 server=None, folder=None, username=None, password=None,
1838 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1840 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1839 xaxis="frequency"):
1841 xaxis="frequency"):
1840
1842
1841 """
1843 """
1842
1844
1843 Input:
1845 Input:
1844 dataOut :
1846 dataOut :
1845 id :
1847 id :
1846 wintitle :
1848 wintitle :
1847 channelList :
1849 channelList :
1848 showProfile :
1850 showProfile :
1849 xmin : None,
1851 xmin : None,
1850 xmax : None,
1852 xmax : None,
1851 ymin : None,
1853 ymin : None,
1852 ymax : None,
1854 ymax : None,
1853 zmin : None,
1855 zmin : None,
1854 zmax : None
1856 zmax : None
1855 """
1857 """
1856 #Rebuild matrix
1858 #Rebuild matrix
1857 utctime = dataOut.data_param[0,0]
1859 utctime = dataOut.data_param[0,0]
1858 cmet = dataOut.data_param[:,1].astype(int)
1860 cmet = dataOut.data_param[:,1].astype(int)
1859 tmet = dataOut.data_param[:,2].astype(int)
1861 tmet = dataOut.data_param[:,2].astype(int)
1860 hmet = dataOut.data_param[:,3].astype(int)
1862 hmet = dataOut.data_param[:,3].astype(int)
1861
1863
1862 nParam = 3
1864 nParam = 3
1863 nChan = len(dataOut.groupList)
1865 nChan = len(dataOut.groupList)
1864 x = dataOut.abscissaList
1866 x = dataOut.abscissaList
1865 y = dataOut.heightList
1867 y = dataOut.heightList
1866
1868
1867 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1869 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1868 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1870 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1869 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1871 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1870 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1872 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1871
1873
1872 xlabel = "Time (s)"
1874 xlabel = "Time (s)"
1873 ylabel = "Range (km)"
1875 ylabel = "Range (km)"
1874
1876
1875 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1877 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1876
1878
1877 if not self.isConfig:
1879 if not self.isConfig:
1878
1880
1879 nplots = nParam*nChan
1881 nplots = nParam*nChan
1880
1882
1881 self.setup(id=id,
1883 self.setup(id=id,
1882 nplots=nplots,
1884 nplots=nplots,
1883 wintitle=wintitle,
1885 wintitle=wintitle,
1884 show=show)
1886 show=show)
1885
1887
1886 if xmin is None: xmin = numpy.nanmin(x)
1888 if xmin is None: xmin = numpy.nanmin(x)
1887 if xmax is None: xmax = numpy.nanmax(x)
1889 if xmax is None: xmax = numpy.nanmax(x)
1888 if ymin is None: ymin = numpy.nanmin(y)
1890 if ymin is None: ymin = numpy.nanmin(y)
1889 if ymax is None: ymax = numpy.nanmax(y)
1891 if ymax is None: ymax = numpy.nanmax(y)
1890 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1892 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1891 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1893 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1892 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1894 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1893 if vmin is None: vmin = -vmax
1895 if vmin is None: vmin = -vmax
1894 if wmin is None: wmin = 0
1896 if wmin is None: wmin = 0
1895 if wmax is None: wmax = 50
1897 if wmax is None: wmax = 50
1896
1898
1897 self.nChannels = nChan
1899 self.nChannels = nChan
1898
1900
1899 zminList = []
1901 zminList = []
1900 zmaxList = []
1902 zmaxList = []
1901 titleList = []
1903 titleList = []
1902 cmapList = []
1904 cmapList = []
1903 for i in range(self.nChannels):
1905 for i in range(self.nChannels):
1904 strAux1 = "SNR Channel "+ str(i)
1906 strAux1 = "SNR Channel "+ str(i)
1905 strAux2 = "Radial Velocity Channel "+ str(i)
1907 strAux2 = "Radial Velocity Channel "+ str(i)
1906 strAux3 = "Spectral Width Channel "+ str(i)
1908 strAux3 = "Spectral Width Channel "+ str(i)
1907
1909
1908 titleList = titleList + [strAux1,strAux2,strAux3]
1910 titleList = titleList + [strAux1,strAux2,strAux3]
1909 cmapList = cmapList + ["jet","RdBu_r","jet"]
1911 cmapList = cmapList + ["jet","RdBu_r","jet"]
1910 zminList = zminList + [SNRmin,vmin,wmin]
1912 zminList = zminList + [SNRmin,vmin,wmin]
1911 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1913 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1912
1914
1913 self.zminList = zminList
1915 self.zminList = zminList
1914 self.zmaxList = zmaxList
1916 self.zmaxList = zmaxList
1915 self.cmapList = cmapList
1917 self.cmapList = cmapList
1916 self.titleList = titleList
1918 self.titleList = titleList
1917
1919
1918 self.FTP_WEI = ftp_wei
1920 self.FTP_WEI = ftp_wei
1919 self.EXP_CODE = exp_code
1921 self.EXP_CODE = exp_code
1920 self.SUB_EXP_CODE = sub_exp_code
1922 self.SUB_EXP_CODE = sub_exp_code
1921 self.PLOT_POS = plot_pos
1923 self.PLOT_POS = plot_pos
1922
1924
1923 self.isConfig = True
1925 self.isConfig = True
1924
1926
1925 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1927 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1926
1928
1927 for i in range(self.nplots):
1929 for i in range(self.nplots):
1928 title = self.titleList[i] + ": " +str_datetime
1930 title = self.titleList[i] + ": " +str_datetime
1929 axes = self.axesList[i]
1931 axes = self.axesList[i]
1930 axes.pcolor(x, y, z[i,:].T,
1932 axes.pcolor(x, y, z[i,:].T,
1931 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1932 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1934 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1933 self.draw()
1935 self.draw()
1934
1936
1935 if figfile == None:
1937 if figfile == None:
1936 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1938 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1937 name = str_datetime
1939 name = str_datetime
1938 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1940 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1939 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1941 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1940 figfile = self.getFilename(name)
1942 figfile = self.getFilename(name)
1941
1943
1942 self.save(figpath=figpath,
1944 self.save(figpath=figpath,
1943 figfile=figfile,
1945 figfile=figfile,
1944 save=save,
1946 save=save,
1945 ftp=ftp,
1947 ftp=ftp,
1946 wr_period=wr_period,
1948 wr_period=wr_period,
1947 thisDatetime=thisDatetime)
1949 thisDatetime=thisDatetime)
1948
1950
1949
1951
@@ -1,1527 +1,1530
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime, isTimeInHourRange
10 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13 class SpectraPlot(Figure):
13 class SpectraPlot(Figure):
14
14
15 isConfig = None
15 isConfig = None
16 __nsubplots = None
16 __nsubplots = None
17
17
18 WIDTHPROF = None
18 WIDTHPROF = None
19 HEIGHTPROF = None
19 HEIGHTPROF = None
20 PREFIX = 'spc'
20 PREFIX = 'spc'
21
21
22 def __init__(self):
22 def __init__(self):
23
23
24 self.isConfig = False
24 self.isConfig = False
25 self.__nsubplots = 1
25 self.__nsubplots = 1
26
26
27 self.WIDTH = 250
27 self.WIDTH = 250
28 self.HEIGHT = 250
28 self.HEIGHT = 250
29 self.WIDTHPROF = 120
29 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
31 self.counter_imagwr = 0
32
32
33 self.PLOT_CODE = SPEC_CODE
33 self.PLOT_CODE = SPEC_CODE
34
34
35 self.FTP_WEI = None
35 self.FTP_WEI = None
36 self.EXP_CODE = None
36 self.EXP_CODE = None
37 self.SUB_EXP_CODE = None
37 self.SUB_EXP_CODE = None
38 self.PLOT_POS = None
38 self.PLOT_POS = None
39
39
40 self.__xfilter_ena = False
40 self.__xfilter_ena = False
41 self.__yfilter_ena = False
41 self.__yfilter_ena = False
42
42
43 def getSubplots(self):
43 def getSubplots(self):
44
44
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
47
47
48 return nrow, ncol
48 return nrow, ncol
49
49
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51
51
52 self.__showprofile = showprofile
52 self.__showprofile = showprofile
53 self.nplots = nplots
53 self.nplots = nplots
54
54
55 ncolspan = 1
55 ncolspan = 1
56 colspan = 1
56 colspan = 1
57 if showprofile:
57 if showprofile:
58 ncolspan = 3
58 ncolspan = 3
59 colspan = 2
59 colspan = 2
60 self.__nsubplots = 2
60 self.__nsubplots = 2
61
61
62 self.createFigure(id = id,
62 self.createFigure(id = id,
63 wintitle = wintitle,
63 wintitle = wintitle,
64 widthplot = self.WIDTH + self.WIDTHPROF,
64 widthplot = self.WIDTH + self.WIDTHPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 show=show)
66 show=show)
67
67
68 nrow, ncol = self.getSubplots()
68 nrow, ncol = self.getSubplots()
69
69
70 counter = 0
70 counter = 0
71 for y in range(nrow):
71 for y in range(nrow):
72 for x in range(ncol):
72 for x in range(ncol):
73
73
74 if counter >= self.nplots:
74 if counter >= self.nplots:
75 break
75 break
76
76
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78
78
79 if showprofile:
79 if showprofile:
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81
81
82 counter += 1
82 counter += 1
83
83
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 server=None, folder=None, username=None, password=None,
87 server=None, folder=None, username=None, password=None,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="frequency", colormap='jet'):
89 xaxis="velocity", **kwargs):
90
90
91 """
91 """
92
92
93 Input:
93 Input:
94 dataOut :
94 dataOut :
95 id :
95 id :
96 wintitle :
96 wintitle :
97 channelList :
97 channelList :
98 showProfile :
98 showProfile :
99 xmin : None,
99 xmin : None,
100 xmax : None,
100 xmax : None,
101 ymin : None,
101 ymin : None,
102 ymax : None,
102 ymax : None,
103 zmin : None,
103 zmin : None,
104 zmax : None
104 zmax : None
105 """
105 """
106
106
107 colormap = kwargs.get('colormap','jet')
108
107 if realtime:
109 if realtime:
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
110 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 print 'Skipping this plot function'
111 print 'Skipping this plot function'
110 return
112 return
111
113
112 if channelList == None:
114 if channelList == None:
113 channelIndexList = dataOut.channelIndexList
115 channelIndexList = dataOut.channelIndexList
114 else:
116 else:
115 channelIndexList = []
117 channelIndexList = []
116 for channel in channelList:
118 for channel in channelList:
117 if channel not in dataOut.channelList:
119 if channel not in dataOut.channelList:
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
120 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
119 channelIndexList.append(dataOut.channelList.index(channel))
121 channelIndexList.append(dataOut.channelList.index(channel))
120
122
121 factor = dataOut.normFactor
123 factor = dataOut.normFactor
122
124
123 if xaxis == "frequency":
125 if xaxis == "frequency":
124 x = dataOut.getFreqRange(1)/1000.
126 x = dataOut.getFreqRange(1)/1000.
125 xlabel = "Frequency (kHz)"
127 xlabel = "Frequency (kHz)"
126
128
127 elif xaxis == "time":
129 elif xaxis == "time":
128 x = dataOut.getAcfRange(1)
130 x = dataOut.getAcfRange(1)
129 xlabel = "Time (ms)"
131 xlabel = "Time (ms)"
130
132
131 else:
133 else:
132 x = dataOut.getVelRange(1)
134 x = dataOut.getVelRange(1)
133 xlabel = "Velocity (m/s)"
135 xlabel = "Velocity (m/s)"
134
136
135 ylabel = "Range (Km)"
137 ylabel = "Range (Km)"
136
138
137 y = dataOut.getHeiRange()
139 y = dataOut.getHeiRange()
138
140
139 z = dataOut.data_spc/factor
141 z = dataOut.data_spc/factor
140 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
141 zdB = 10*numpy.log10(z)
143 zdB = 10*numpy.log10(z)
142
144
143 avg = numpy.average(z, axis=1)
145 avg = numpy.average(z, axis=1)
144 avgdB = 10*numpy.log10(avg)
146 avgdB = 10*numpy.log10(avg)
145
147
146 noise = dataOut.getNoise()/factor
148 noise = dataOut.getNoise()/factor
147 noisedB = 10*numpy.log10(noise)
149 noisedB = 10*numpy.log10(noise)
148
150
149 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
150 title = wintitle + " Spectra"
152 title = wintitle + " Spectra"
151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
152 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
153
155
154 if not self.isConfig:
156 if not self.isConfig:
155
157
156 nplots = len(channelIndexList)
158 nplots = len(channelIndexList)
157
159
158 self.setup(id=id,
160 self.setup(id=id,
159 nplots=nplots,
161 nplots=nplots,
160 wintitle=wintitle,
162 wintitle=wintitle,
161 showprofile=showprofile,
163 showprofile=showprofile,
162 show=show)
164 show=show)
163
165
164 if xmin == None: xmin = numpy.nanmin(x)
166 if xmin == None: xmin = numpy.nanmin(x)
165 if xmax == None: xmax = numpy.nanmax(x)
167 if xmax == None: xmax = numpy.nanmax(x)
166 if ymin == None: ymin = numpy.nanmin(y)
168 if ymin == None: ymin = numpy.nanmin(y)
167 if ymax == None: ymax = numpy.nanmax(y)
169 if ymax == None: ymax = numpy.nanmax(y)
168 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
169 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
170
172
171 self.FTP_WEI = ftp_wei
173 self.FTP_WEI = ftp_wei
172 self.EXP_CODE = exp_code
174 self.EXP_CODE = exp_code
173 self.SUB_EXP_CODE = sub_exp_code
175 self.SUB_EXP_CODE = sub_exp_code
174 self.PLOT_POS = plot_pos
176 self.PLOT_POS = plot_pos
175
177
176 self.isConfig = True
178 self.isConfig = True
177
179
178 self.setWinTitle(title)
180 self.setWinTitle(title)
179
181
180 for i in range(self.nplots):
182 for i in range(self.nplots):
181 index = channelIndexList[i]
183 index = channelIndexList[i]
182 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
183 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
184 if len(dataOut.beam.codeList) != 0:
186 if len(dataOut.beam.codeList) != 0:
185 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
186
188
187 axes = self.axesList[i*self.__nsubplots]
189 axes = self.axesList[i*self.__nsubplots]
188 axes.pcolor(x, y, zdB[index,:,:],
190 axes.pcolor(x, y, zdB[index,:,:],
189 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
190 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
191 ticksize=9, cblabel='')
193 ticksize=9, cblabel='')
192
194
193 if self.__showprofile:
195 if self.__showprofile:
194 axes = self.axesList[i*self.__nsubplots +1]
196 axes = self.axesList[i*self.__nsubplots +1]
195 axes.pline(avgdB[index,:], y,
197 axes.pline(avgdB[index,:], y,
196 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
197 xlabel='dB', ylabel='', title='',
199 xlabel='dB', ylabel='', title='',
198 ytick_visible=False,
200 ytick_visible=False,
199 grid='x')
201 grid='x')
200
202
201 noiseline = numpy.repeat(noisedB[index], len(y))
203 noiseline = numpy.repeat(noisedB[index], len(y))
202 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
203
205
204 self.draw()
206 self.draw()
205
207
206 if figfile == None:
208 if figfile == None:
207 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
208 name = str_datetime
210 name = str_datetime
209 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
210 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
211 figfile = self.getFilename(name)
213 figfile = self.getFilename(name)
212
214
213 self.save(figpath=figpath,
215 self.save(figpath=figpath,
214 figfile=figfile,
216 figfile=figfile,
215 save=save,
217 save=save,
216 ftp=ftp,
218 ftp=ftp,
217 wr_period=wr_period,
219 wr_period=wr_period,
218 thisDatetime=thisDatetime)
220 thisDatetime=thisDatetime)
219
221
220 class CrossSpectraPlot(Figure):
222 class CrossSpectraPlot(Figure):
221
223
222 isConfig = None
224 isConfig = None
223 __nsubplots = None
225 __nsubplots = None
224
226
225 WIDTH = None
227 WIDTH = None
226 HEIGHT = None
228 HEIGHT = None
227 WIDTHPROF = None
229 WIDTHPROF = None
228 HEIGHTPROF = None
230 HEIGHTPROF = None
229 PREFIX = 'cspc'
231 PREFIX = 'cspc'
230
232
231 def __init__(self):
233 def __init__(self):
232
234
233 self.isConfig = False
235 self.isConfig = False
234 self.__nsubplots = 4
236 self.__nsubplots = 4
235 self.counter_imagwr = 0
237 self.counter_imagwr = 0
236 self.WIDTH = 250
238 self.WIDTH = 250
237 self.HEIGHT = 250
239 self.HEIGHT = 250
238 self.WIDTHPROF = 0
240 self.WIDTHPROF = 0
239 self.HEIGHTPROF = 0
241 self.HEIGHTPROF = 0
240
242
241 self.PLOT_CODE = CROSS_CODE
243 self.PLOT_CODE = CROSS_CODE
242 self.FTP_WEI = None
244 self.FTP_WEI = None
243 self.EXP_CODE = None
245 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
246 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
247 self.PLOT_POS = None
246
248
247 def getSubplots(self):
249 def getSubplots(self):
248
250
249 ncol = 4
251 ncol = 4
250 nrow = self.nplots
252 nrow = self.nplots
251
253
252 return nrow, ncol
254 return nrow, ncol
253
255
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
257
256 self.__showprofile = showprofile
258 self.__showprofile = showprofile
257 self.nplots = nplots
259 self.nplots = nplots
258
260
259 ncolspan = 1
261 ncolspan = 1
260 colspan = 1
262 colspan = 1
261
263
262 self.createFigure(id = id,
264 self.createFigure(id = id,
263 wintitle = wintitle,
265 wintitle = wintitle,
264 widthplot = self.WIDTH + self.WIDTHPROF,
266 widthplot = self.WIDTH + self.WIDTHPROF,
265 heightplot = self.HEIGHT + self.HEIGHTPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
266 show=True)
268 show=True)
267
269
268 nrow, ncol = self.getSubplots()
270 nrow, ncol = self.getSubplots()
269
271
270 counter = 0
272 counter = 0
271 for y in range(nrow):
273 for y in range(nrow):
272 for x in range(ncol):
274 for x in range(ncol):
273 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
274
276
275 counter += 1
277 counter += 1
276
278
277 def run(self, dataOut, id, wintitle="", pairsList=None,
279 def run(self, dataOut, id, wintitle="", pairsList=None,
278 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
279 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
280 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
281 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
282 server=None, folder=None, username=None, password=None,
284 server=None, folder=None, username=None, password=None,
283 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
284 xaxis='frequency'):
286 xaxis='frequency'):
285
287
286 """
288 """
287
289
288 Input:
290 Input:
289 dataOut :
291 dataOut :
290 id :
292 id :
291 wintitle :
293 wintitle :
292 channelList :
294 channelList :
293 showProfile :
295 showProfile :
294 xmin : None,
296 xmin : None,
295 xmax : None,
297 xmax : None,
296 ymin : None,
298 ymin : None,
297 ymax : None,
299 ymax : None,
298 zmin : None,
300 zmin : None,
299 zmax : None
301 zmax : None
300 """
302 """
301
303
302 if pairsList == None:
304 if pairsList == None:
303 pairsIndexList = dataOut.pairsIndexList
305 pairsIndexList = dataOut.pairsIndexList
304 else:
306 else:
305 pairsIndexList = []
307 pairsIndexList = []
306 for pair in pairsList:
308 for pair in pairsList:
307 if pair not in dataOut.pairsList:
309 if pair not in dataOut.pairsList:
308 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
309 pairsIndexList.append(dataOut.pairsList.index(pair))
311 pairsIndexList.append(dataOut.pairsList.index(pair))
310
312
311 if not pairsIndexList:
313 if not pairsIndexList:
312 return
314 return
313
315
314 if len(pairsIndexList) > 4:
316 if len(pairsIndexList) > 4:
315 pairsIndexList = pairsIndexList[0:4]
317 pairsIndexList = pairsIndexList[0:4]
316
318
317 factor = dataOut.normFactor
319 factor = dataOut.normFactor
318 x = dataOut.getVelRange(1)
320 x = dataOut.getVelRange(1)
319 y = dataOut.getHeiRange()
321 y = dataOut.getHeiRange()
320 z = dataOut.data_spc[:,:,:]/factor
322 z = dataOut.data_spc[:,:,:]/factor
321 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
323 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
322
324
323 noise = dataOut.noise/factor
325 noise = dataOut.noise/factor
324
326
325 zdB = 10*numpy.log10(z)
327 zdB = 10*numpy.log10(z)
326 noisedB = 10*numpy.log10(noise)
328 noisedB = 10*numpy.log10(noise)
327
329
328 if coh_min == None:
330 if coh_min == None:
329 coh_min = 0.0
331 coh_min = 0.0
330 if coh_max == None:
332 if coh_max == None:
331 coh_max = 1.0
333 coh_max = 1.0
332
334
333 if phase_min == None:
335 if phase_min == None:
334 phase_min = -180
336 phase_min = -180
335 if phase_max == None:
337 if phase_max == None:
336 phase_max = 180
338 phase_max = 180
337
339
338 #thisDatetime = dataOut.datatime
340 #thisDatetime = dataOut.datatime
339 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
340 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
342 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
341 # xlabel = "Velocity (m/s)"
343 # xlabel = "Velocity (m/s)"
342 ylabel = "Range (Km)"
344 ylabel = "Range (Km)"
343
345
344 if xaxis == "frequency":
346 if xaxis == "frequency":
345 x = dataOut.getFreqRange(1)/1000.
347 x = dataOut.getFreqRange(1)/1000.
346 xlabel = "Frequency (kHz)"
348 xlabel = "Frequency (kHz)"
347
349
348 elif xaxis == "time":
350 elif xaxis == "time":
349 x = dataOut.getAcfRange(1)
351 x = dataOut.getAcfRange(1)
350 xlabel = "Time (ms)"
352 xlabel = "Time (ms)"
351
353
352 else:
354 else:
353 x = dataOut.getVelRange(1)
355 x = dataOut.getVelRange(1)
354 xlabel = "Velocity (m/s)"
356 xlabel = "Velocity (m/s)"
355
357
356 if not self.isConfig:
358 if not self.isConfig:
357
359
358 nplots = len(pairsIndexList)
360 nplots = len(pairsIndexList)
359
361
360 self.setup(id=id,
362 self.setup(id=id,
361 nplots=nplots,
363 nplots=nplots,
362 wintitle=wintitle,
364 wintitle=wintitle,
363 showprofile=False,
365 showprofile=False,
364 show=show)
366 show=show)
365
367
366 avg = numpy.abs(numpy.average(z, axis=1))
368 avg = numpy.abs(numpy.average(z, axis=1))
367 avgdB = 10*numpy.log10(avg)
369 avgdB = 10*numpy.log10(avg)
368
370
369 if xmin == None: xmin = numpy.nanmin(x)
371 if xmin == None: xmin = numpy.nanmin(x)
370 if xmax == None: xmax = numpy.nanmax(x)
372 if xmax == None: xmax = numpy.nanmax(x)
371 if ymin == None: ymin = numpy.nanmin(y)
373 if ymin == None: ymin = numpy.nanmin(y)
372 if ymax == None: ymax = numpy.nanmax(y)
374 if ymax == None: ymax = numpy.nanmax(y)
373 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
375 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
374 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
376 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
375
377
376 self.FTP_WEI = ftp_wei
378 self.FTP_WEI = ftp_wei
377 self.EXP_CODE = exp_code
379 self.EXP_CODE = exp_code
378 self.SUB_EXP_CODE = sub_exp_code
380 self.SUB_EXP_CODE = sub_exp_code
379 self.PLOT_POS = plot_pos
381 self.PLOT_POS = plot_pos
380
382
381 self.isConfig = True
383 self.isConfig = True
382
384
383 self.setWinTitle(title)
385 self.setWinTitle(title)
384
386
385 for i in range(self.nplots):
387 for i in range(self.nplots):
386 pair = dataOut.pairsList[pairsIndexList[i]]
388 pair = dataOut.pairsList[pairsIndexList[i]]
387
389
388 chan_index0 = dataOut.channelList.index(pair[0])
390 chan_index0 = dataOut.channelList.index(pair[0])
389 chan_index1 = dataOut.channelList.index(pair[1])
391 chan_index1 = dataOut.channelList.index(pair[1])
390
392
391 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
393 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
392 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
394 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
393 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
395 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
394 axes0 = self.axesList[i*self.__nsubplots]
396 axes0 = self.axesList[i*self.__nsubplots]
395 axes0.pcolor(x, y, zdB,
397 axes0.pcolor(x, y, zdB,
396 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
398 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
397 xlabel=xlabel, ylabel=ylabel, title=title,
399 xlabel=xlabel, ylabel=ylabel, title=title,
398 ticksize=9, colormap=power_cmap, cblabel='')
400 ticksize=9, colormap=power_cmap, cblabel='')
399
401
400 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
402 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
401 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
403 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
402 axes0 = self.axesList[i*self.__nsubplots+1]
404 axes0 = self.axesList[i*self.__nsubplots+1]
403 axes0.pcolor(x, y, zdB,
405 axes0.pcolor(x, y, zdB,
404 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
406 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
405 xlabel=xlabel, ylabel=ylabel, title=title,
407 xlabel=xlabel, ylabel=ylabel, title=title,
406 ticksize=9, colormap=power_cmap, cblabel='')
408 ticksize=9, colormap=power_cmap, cblabel='')
407
409
408 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
410 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
409 coherence = numpy.abs(coherenceComplex)
411 coherence = numpy.abs(coherenceComplex)
410 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
412 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
411 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
413 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
412
414
413 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
415 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
414 axes0 = self.axesList[i*self.__nsubplots+2]
416 axes0 = self.axesList[i*self.__nsubplots+2]
415 axes0.pcolor(x, y, coherence,
417 axes0.pcolor(x, y, coherence,
416 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
418 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
417 xlabel=xlabel, ylabel=ylabel, title=title,
419 xlabel=xlabel, ylabel=ylabel, title=title,
418 ticksize=9, colormap=coherence_cmap, cblabel='')
420 ticksize=9, colormap=coherence_cmap, cblabel='')
419
421
420 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
422 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
421 axes0 = self.axesList[i*self.__nsubplots+3]
423 axes0 = self.axesList[i*self.__nsubplots+3]
422 axes0.pcolor(x, y, phase,
424 axes0.pcolor(x, y, phase,
423 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
425 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
424 xlabel=xlabel, ylabel=ylabel, title=title,
426 xlabel=xlabel, ylabel=ylabel, title=title,
425 ticksize=9, colormap=phase_cmap, cblabel='')
427 ticksize=9, colormap=phase_cmap, cblabel='')
426
428
427
429
428
430
429 self.draw()
431 self.draw()
430
432
431 self.save(figpath=figpath,
433 self.save(figpath=figpath,
432 figfile=figfile,
434 figfile=figfile,
433 save=save,
435 save=save,
434 ftp=ftp,
436 ftp=ftp,
435 wr_period=wr_period,
437 wr_period=wr_period,
436 thisDatetime=thisDatetime)
438 thisDatetime=thisDatetime)
437
439
438
440
439 class RTIPlot(Figure):
441 class RTIPlot(Figure):
440
442
441 __isConfig = None
443 __isConfig = None
442 __nsubplots = None
444 __nsubplots = None
443
445
444 WIDTHPROF = None
446 WIDTHPROF = None
445 HEIGHTPROF = None
447 HEIGHTPROF = None
446 PREFIX = 'rti'
448 PREFIX = 'rti'
447
449
448 def __init__(self):
450 def __init__(self):
449
451
450 self.timerange = None
452 self.timerange = None
451 self.isConfig = False
453 self.isConfig = False
452 self.__nsubplots = 1
454 self.__nsubplots = 1
453
455
454 self.WIDTH = 800
456 self.WIDTH = 800
455 self.HEIGHT = 180
457 self.HEIGHT = 180
456 self.WIDTHPROF = 120
458 self.WIDTHPROF = 120
457 self.HEIGHTPROF = 0
459 self.HEIGHTPROF = 0
458 self.counter_imagwr = 0
460 self.counter_imagwr = 0
459
461
460 self.PLOT_CODE = RTI_CODE
462 self.PLOT_CODE = RTI_CODE
461
463
462 self.FTP_WEI = None
464 self.FTP_WEI = None
463 self.EXP_CODE = None
465 self.EXP_CODE = None
464 self.SUB_EXP_CODE = None
466 self.SUB_EXP_CODE = None
465 self.PLOT_POS = None
467 self.PLOT_POS = None
466 self.tmin = None
468 self.tmin = None
467 self.tmax = None
469 self.tmax = None
468
470
469 self.xmin = None
471 self.xmin = None
470 self.xmax = None
472 self.xmax = None
471
473
472 self.figfile = None
474 self.figfile = None
473
475
474 def getSubplots(self):
476 def getSubplots(self):
475
477
476 ncol = 1
478 ncol = 1
477 nrow = self.nplots
479 nrow = self.nplots
478
480
479 return nrow, ncol
481 return nrow, ncol
480
482
481 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
483 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
482
484
483 self.__showprofile = showprofile
485 self.__showprofile = showprofile
484 self.nplots = nplots
486 self.nplots = nplots
485
487
486 ncolspan = 1
488 ncolspan = 1
487 colspan = 1
489 colspan = 1
488 if showprofile:
490 if showprofile:
489 ncolspan = 7
491 ncolspan = 7
490 colspan = 6
492 colspan = 6
491 self.__nsubplots = 2
493 self.__nsubplots = 2
492
494
493 self.createFigure(id = id,
495 self.createFigure(id = id,
494 wintitle = wintitle,
496 wintitle = wintitle,
495 widthplot = self.WIDTH + self.WIDTHPROF,
497 widthplot = self.WIDTH + self.WIDTHPROF,
496 heightplot = self.HEIGHT + self.HEIGHTPROF,
498 heightplot = self.HEIGHT + self.HEIGHTPROF,
497 show=show)
499 show=show)
498
500
499 nrow, ncol = self.getSubplots()
501 nrow, ncol = self.getSubplots()
500
502
501 counter = 0
503 counter = 0
502 for y in range(nrow):
504 for y in range(nrow):
503 for x in range(ncol):
505 for x in range(ncol):
504
506
505 if counter >= self.nplots:
507 if counter >= self.nplots:
506 break
508 break
507
509
508 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
510 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
509
511
510 if showprofile:
512 if showprofile:
511 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
513 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
512
514
513 counter += 1
515 counter += 1
514
516
515 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
517 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
516 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
518 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
517 timerange=None, colormap='jet',
519 timerange=None,
518 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
520 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
519 server=None, folder=None, username=None, password=None,
521 server=None, folder=None, username=None, password=None,
520 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
522 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
521
523
522 """
524 """
523
525
524 Input:
526 Input:
525 dataOut :
527 dataOut :
526 id :
528 id :
527 wintitle :
529 wintitle :
528 channelList :
530 channelList :
529 showProfile :
531 showProfile :
530 xmin : None,
532 xmin : None,
531 xmax : None,
533 xmax : None,
532 ymin : None,
534 ymin : None,
533 ymax : None,
535 ymax : None,
534 zmin : None,
536 zmin : None,
535 zmax : None
537 zmax : None
536 """
538 """
537
539
540 colormap = kwargs.get('colormap', 'jet')
538 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
541 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
539 return
542 return
540
543
541 if channelList == None:
544 if channelList == None:
542 channelIndexList = dataOut.channelIndexList
545 channelIndexList = dataOut.channelIndexList
543 else:
546 else:
544 channelIndexList = []
547 channelIndexList = []
545 for channel in channelList:
548 for channel in channelList:
546 if channel not in dataOut.channelList:
549 if channel not in dataOut.channelList:
547 raise ValueError, "Channel %d is not in dataOut.channelList"
550 raise ValueError, "Channel %d is not in dataOut.channelList"
548 channelIndexList.append(dataOut.channelList.index(channel))
551 channelIndexList.append(dataOut.channelList.index(channel))
549
552
550 if hasattr(dataOut, 'normFactor'):
553 if hasattr(dataOut, 'normFactor'):
551 factor = dataOut.normFactor
554 factor = dataOut.normFactor
552 else:
555 else:
553 factor = 1
556 factor = 1
554
557
555 # factor = dataOut.normFactor
558 # factor = dataOut.normFactor
556 x = dataOut.getTimeRange()
559 x = dataOut.getTimeRange()
557 y = dataOut.getHeiRange()
560 y = dataOut.getHeiRange()
558
561
559 # z = dataOut.data_spc/factor
562 # z = dataOut.data_spc/factor
560 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
563 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
561 # avg = numpy.average(z, axis=1)
564 # avg = numpy.average(z, axis=1)
562 # avgdB = 10.*numpy.log10(avg)
565 # avgdB = 10.*numpy.log10(avg)
563 avgdB = dataOut.getPower()
566 avgdB = dataOut.getPower()
564
567
565 thisDatetime = dataOut.datatime
568 thisDatetime = dataOut.datatime
566 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
569 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
567 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
570 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
568 xlabel = ""
571 xlabel = ""
569 ylabel = "Range (Km)"
572 ylabel = "Range (Km)"
570
573
571 update_figfile = False
574 update_figfile = False
572
575
573 if dataOut.ltctime >= self.xmax:
576 if dataOut.ltctime >= self.xmax:
574 self.counter_imagwr = wr_period
577 self.counter_imagwr = wr_period
575 self.isConfig = False
578 self.isConfig = False
576 update_figfile = True
579 update_figfile = True
577
580
578 if not self.isConfig:
581 if not self.isConfig:
579
582
580 nplots = len(channelIndexList)
583 nplots = len(channelIndexList)
581
584
582 self.setup(id=id,
585 self.setup(id=id,
583 nplots=nplots,
586 nplots=nplots,
584 wintitle=wintitle,
587 wintitle=wintitle,
585 showprofile=showprofile,
588 showprofile=showprofile,
586 show=show)
589 show=show)
587
590
588 if timerange != None:
591 if timerange != None:
589 self.timerange = timerange
592 self.timerange = timerange
590
593
591 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
594 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
592
595
593 noise = dataOut.noise/factor
596 noise = dataOut.noise/factor
594 noisedB = 10*numpy.log10(noise)
597 noisedB = 10*numpy.log10(noise)
595
598
596 if ymin == None: ymin = numpy.nanmin(y)
599 if ymin == None: ymin = numpy.nanmin(y)
597 if ymax == None: ymax = numpy.nanmax(y)
600 if ymax == None: ymax = numpy.nanmax(y)
598 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
601 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
599 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
602 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
600
603
601 self.FTP_WEI = ftp_wei
604 self.FTP_WEI = ftp_wei
602 self.EXP_CODE = exp_code
605 self.EXP_CODE = exp_code
603 self.SUB_EXP_CODE = sub_exp_code
606 self.SUB_EXP_CODE = sub_exp_code
604 self.PLOT_POS = plot_pos
607 self.PLOT_POS = plot_pos
605
608
606 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
609 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
607 self.isConfig = True
610 self.isConfig = True
608 self.figfile = figfile
611 self.figfile = figfile
609 update_figfile = True
612 update_figfile = True
610
613
611 self.setWinTitle(title)
614 self.setWinTitle(title)
612
615
613 for i in range(self.nplots):
616 for i in range(self.nplots):
614 index = channelIndexList[i]
617 index = channelIndexList[i]
615 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
618 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
616 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
619 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
617 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
620 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
618 axes = self.axesList[i*self.__nsubplots]
621 axes = self.axesList[i*self.__nsubplots]
619 zdB = avgdB[index].reshape((1,-1))
622 zdB = avgdB[index].reshape((1,-1))
620 axes.pcolorbuffer(x, y, zdB,
623 axes.pcolorbuffer(x, y, zdB,
621 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
624 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
622 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
625 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
623 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
626 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
624
627
625 if self.__showprofile:
628 if self.__showprofile:
626 axes = self.axesList[i*self.__nsubplots +1]
629 axes = self.axesList[i*self.__nsubplots +1]
627 axes.pline(avgdB[index], y,
630 axes.pline(avgdB[index], y,
628 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
631 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
629 xlabel='dB', ylabel='', title='',
632 xlabel='dB', ylabel='', title='',
630 ytick_visible=False,
633 ytick_visible=False,
631 grid='x')
634 grid='x')
632
635
633 self.draw()
636 self.draw()
634
637
635 self.save(figpath=figpath,
638 self.save(figpath=figpath,
636 figfile=figfile,
639 figfile=figfile,
637 save=save,
640 save=save,
638 ftp=ftp,
641 ftp=ftp,
639 wr_period=wr_period,
642 wr_period=wr_period,
640 thisDatetime=thisDatetime,
643 thisDatetime=thisDatetime,
641 update_figfile=update_figfile)
644 update_figfile=update_figfile)
642
645
643 class CoherenceMap(Figure):
646 class CoherenceMap(Figure):
644 isConfig = None
647 isConfig = None
645 __nsubplots = None
648 __nsubplots = None
646
649
647 WIDTHPROF = None
650 WIDTHPROF = None
648 HEIGHTPROF = None
651 HEIGHTPROF = None
649 PREFIX = 'cmap'
652 PREFIX = 'cmap'
650
653
651 def __init__(self):
654 def __init__(self):
652 self.timerange = 2*60*60
655 self.timerange = 2*60*60
653 self.isConfig = False
656 self.isConfig = False
654 self.__nsubplots = 1
657 self.__nsubplots = 1
655
658
656 self.WIDTH = 800
659 self.WIDTH = 800
657 self.HEIGHT = 180
660 self.HEIGHT = 180
658 self.WIDTHPROF = 120
661 self.WIDTHPROF = 120
659 self.HEIGHTPROF = 0
662 self.HEIGHTPROF = 0
660 self.counter_imagwr = 0
663 self.counter_imagwr = 0
661
664
662 self.PLOT_CODE = COH_CODE
665 self.PLOT_CODE = COH_CODE
663
666
664 self.FTP_WEI = None
667 self.FTP_WEI = None
665 self.EXP_CODE = None
668 self.EXP_CODE = None
666 self.SUB_EXP_CODE = None
669 self.SUB_EXP_CODE = None
667 self.PLOT_POS = None
670 self.PLOT_POS = None
668 self.counter_imagwr = 0
671 self.counter_imagwr = 0
669
672
670 self.xmin = None
673 self.xmin = None
671 self.xmax = None
674 self.xmax = None
672
675
673 def getSubplots(self):
676 def getSubplots(self):
674 ncol = 1
677 ncol = 1
675 nrow = self.nplots*2
678 nrow = self.nplots*2
676
679
677 return nrow, ncol
680 return nrow, ncol
678
681
679 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
682 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
680 self.__showprofile = showprofile
683 self.__showprofile = showprofile
681 self.nplots = nplots
684 self.nplots = nplots
682
685
683 ncolspan = 1
686 ncolspan = 1
684 colspan = 1
687 colspan = 1
685 if showprofile:
688 if showprofile:
686 ncolspan = 7
689 ncolspan = 7
687 colspan = 6
690 colspan = 6
688 self.__nsubplots = 2
691 self.__nsubplots = 2
689
692
690 self.createFigure(id = id,
693 self.createFigure(id = id,
691 wintitle = wintitle,
694 wintitle = wintitle,
692 widthplot = self.WIDTH + self.WIDTHPROF,
695 widthplot = self.WIDTH + self.WIDTHPROF,
693 heightplot = self.HEIGHT + self.HEIGHTPROF,
696 heightplot = self.HEIGHT + self.HEIGHTPROF,
694 show=True)
697 show=True)
695
698
696 nrow, ncol = self.getSubplots()
699 nrow, ncol = self.getSubplots()
697
700
698 for y in range(nrow):
701 for y in range(nrow):
699 for x in range(ncol):
702 for x in range(ncol):
700
703
701 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
704 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
702
705
703 if showprofile:
706 if showprofile:
704 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
707 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
705
708
706 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
709 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
707 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
710 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
708 timerange=None, phase_min=None, phase_max=None,
711 timerange=None, phase_min=None, phase_max=None,
709 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
712 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
710 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
713 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
711 server=None, folder=None, username=None, password=None,
714 server=None, folder=None, username=None, password=None,
712 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
715 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
713
716
714 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
717 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
715 return
718 return
716
719
717 if pairsList == None:
720 if pairsList == None:
718 pairsIndexList = dataOut.pairsIndexList
721 pairsIndexList = dataOut.pairsIndexList
719 else:
722 else:
720 pairsIndexList = []
723 pairsIndexList = []
721 for pair in pairsList:
724 for pair in pairsList:
722 if pair not in dataOut.pairsList:
725 if pair not in dataOut.pairsList:
723 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
726 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
724 pairsIndexList.append(dataOut.pairsList.index(pair))
727 pairsIndexList.append(dataOut.pairsList.index(pair))
725
728
726 if pairsIndexList == []:
729 if pairsIndexList == []:
727 return
730 return
728
731
729 if len(pairsIndexList) > 4:
732 if len(pairsIndexList) > 4:
730 pairsIndexList = pairsIndexList[0:4]
733 pairsIndexList = pairsIndexList[0:4]
731
734
732 if phase_min == None:
735 if phase_min == None:
733 phase_min = -180
736 phase_min = -180
734 if phase_max == None:
737 if phase_max == None:
735 phase_max = 180
738 phase_max = 180
736
739
737 x = dataOut.getTimeRange()
740 x = dataOut.getTimeRange()
738 y = dataOut.getHeiRange()
741 y = dataOut.getHeiRange()
739
742
740 thisDatetime = dataOut.datatime
743 thisDatetime = dataOut.datatime
741
744
742 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
745 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
743 xlabel = ""
746 xlabel = ""
744 ylabel = "Range (Km)"
747 ylabel = "Range (Km)"
745 update_figfile = False
748 update_figfile = False
746
749
747 if not self.isConfig:
750 if not self.isConfig:
748 nplots = len(pairsIndexList)
751 nplots = len(pairsIndexList)
749 self.setup(id=id,
752 self.setup(id=id,
750 nplots=nplots,
753 nplots=nplots,
751 wintitle=wintitle,
754 wintitle=wintitle,
752 showprofile=showprofile,
755 showprofile=showprofile,
753 show=show)
756 show=show)
754
757
755 if timerange != None:
758 if timerange != None:
756 self.timerange = timerange
759 self.timerange = timerange
757
760
758 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
761 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
759
762
760 if ymin == None: ymin = numpy.nanmin(y)
763 if ymin == None: ymin = numpy.nanmin(y)
761 if ymax == None: ymax = numpy.nanmax(y)
764 if ymax == None: ymax = numpy.nanmax(y)
762 if zmin == None: zmin = 0.
765 if zmin == None: zmin = 0.
763 if zmax == None: zmax = 1.
766 if zmax == None: zmax = 1.
764
767
765 self.FTP_WEI = ftp_wei
768 self.FTP_WEI = ftp_wei
766 self.EXP_CODE = exp_code
769 self.EXP_CODE = exp_code
767 self.SUB_EXP_CODE = sub_exp_code
770 self.SUB_EXP_CODE = sub_exp_code
768 self.PLOT_POS = plot_pos
771 self.PLOT_POS = plot_pos
769
772
770 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
773 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
771
774
772 self.isConfig = True
775 self.isConfig = True
773 update_figfile = True
776 update_figfile = True
774
777
775 self.setWinTitle(title)
778 self.setWinTitle(title)
776
779
777 for i in range(self.nplots):
780 for i in range(self.nplots):
778
781
779 pair = dataOut.pairsList[pairsIndexList[i]]
782 pair = dataOut.pairsList[pairsIndexList[i]]
780
783
781 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
784 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
782 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
785 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
783 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
786 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
784
787
785
788
786 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
789 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
787 coherence = numpy.abs(avgcoherenceComplex)
790 coherence = numpy.abs(avgcoherenceComplex)
788
791
789 z = coherence.reshape((1,-1))
792 z = coherence.reshape((1,-1))
790
793
791 counter = 0
794 counter = 0
792
795
793 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
796 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
794 axes = self.axesList[i*self.__nsubplots*2]
797 axes = self.axesList[i*self.__nsubplots*2]
795 axes.pcolorbuffer(x, y, z,
798 axes.pcolorbuffer(x, y, z,
796 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
799 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
797 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
800 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
798 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
801 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
799
802
800 if self.__showprofile:
803 if self.__showprofile:
801 counter += 1
804 counter += 1
802 axes = self.axesList[i*self.__nsubplots*2 + counter]
805 axes = self.axesList[i*self.__nsubplots*2 + counter]
803 axes.pline(coherence, y,
806 axes.pline(coherence, y,
804 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
807 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
805 xlabel='', ylabel='', title='', ticksize=7,
808 xlabel='', ylabel='', title='', ticksize=7,
806 ytick_visible=False, nxticks=5,
809 ytick_visible=False, nxticks=5,
807 grid='x')
810 grid='x')
808
811
809 counter += 1
812 counter += 1
810
813
811 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
814 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
812
815
813 z = phase.reshape((1,-1))
816 z = phase.reshape((1,-1))
814
817
815 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
818 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
816 axes = self.axesList[i*self.__nsubplots*2 + counter]
819 axes = self.axesList[i*self.__nsubplots*2 + counter]
817 axes.pcolorbuffer(x, y, z,
820 axes.pcolorbuffer(x, y, z,
818 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
821 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
819 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
822 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
820 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
823 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
821
824
822 if self.__showprofile:
825 if self.__showprofile:
823 counter += 1
826 counter += 1
824 axes = self.axesList[i*self.__nsubplots*2 + counter]
827 axes = self.axesList[i*self.__nsubplots*2 + counter]
825 axes.pline(phase, y,
828 axes.pline(phase, y,
826 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
829 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
827 xlabel='', ylabel='', title='', ticksize=7,
830 xlabel='', ylabel='', title='', ticksize=7,
828 ytick_visible=False, nxticks=4,
831 ytick_visible=False, nxticks=4,
829 grid='x')
832 grid='x')
830
833
831 self.draw()
834 self.draw()
832
835
833 if dataOut.ltctime >= self.xmax:
836 if dataOut.ltctime >= self.xmax:
834 self.counter_imagwr = wr_period
837 self.counter_imagwr = wr_period
835 self.isConfig = False
838 self.isConfig = False
836 update_figfile = True
839 update_figfile = True
837
840
838 self.save(figpath=figpath,
841 self.save(figpath=figpath,
839 figfile=figfile,
842 figfile=figfile,
840 save=save,
843 save=save,
841 ftp=ftp,
844 ftp=ftp,
842 wr_period=wr_period,
845 wr_period=wr_period,
843 thisDatetime=thisDatetime,
846 thisDatetime=thisDatetime,
844 update_figfile=update_figfile)
847 update_figfile=update_figfile)
845
848
846 class PowerProfilePlot(Figure):
849 class PowerProfilePlot(Figure):
847
850
848 isConfig = None
851 isConfig = None
849 __nsubplots = None
852 __nsubplots = None
850
853
851 WIDTHPROF = None
854 WIDTHPROF = None
852 HEIGHTPROF = None
855 HEIGHTPROF = None
853 PREFIX = 'spcprofile'
856 PREFIX = 'spcprofile'
854
857
855 def __init__(self):
858 def __init__(self):
856 self.isConfig = False
859 self.isConfig = False
857 self.__nsubplots = 1
860 self.__nsubplots = 1
858
861
859 self.PLOT_CODE = POWER_CODE
862 self.PLOT_CODE = POWER_CODE
860
863
861 self.WIDTH = 300
864 self.WIDTH = 300
862 self.HEIGHT = 500
865 self.HEIGHT = 500
863 self.counter_imagwr = 0
866 self.counter_imagwr = 0
864
867
865 def getSubplots(self):
868 def getSubplots(self):
866 ncol = 1
869 ncol = 1
867 nrow = 1
870 nrow = 1
868
871
869 return nrow, ncol
872 return nrow, ncol
870
873
871 def setup(self, id, nplots, wintitle, show):
874 def setup(self, id, nplots, wintitle, show):
872
875
873 self.nplots = nplots
876 self.nplots = nplots
874
877
875 ncolspan = 1
878 ncolspan = 1
876 colspan = 1
879 colspan = 1
877
880
878 self.createFigure(id = id,
881 self.createFigure(id = id,
879 wintitle = wintitle,
882 wintitle = wintitle,
880 widthplot = self.WIDTH,
883 widthplot = self.WIDTH,
881 heightplot = self.HEIGHT,
884 heightplot = self.HEIGHT,
882 show=show)
885 show=show)
883
886
884 nrow, ncol = self.getSubplots()
887 nrow, ncol = self.getSubplots()
885
888
886 counter = 0
889 counter = 0
887 for y in range(nrow):
890 for y in range(nrow):
888 for x in range(ncol):
891 for x in range(ncol):
889 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
892 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
890
893
891 def run(self, dataOut, id, wintitle="", channelList=None,
894 def run(self, dataOut, id, wintitle="", channelList=None,
892 xmin=None, xmax=None, ymin=None, ymax=None,
895 xmin=None, xmax=None, ymin=None, ymax=None,
893 save=False, figpath='./', figfile=None, show=True,
896 save=False, figpath='./', figfile=None, show=True,
894 ftp=False, wr_period=1, server=None,
897 ftp=False, wr_period=1, server=None,
895 folder=None, username=None, password=None):
898 folder=None, username=None, password=None):
896
899
897
900
898 if channelList == None:
901 if channelList == None:
899 channelIndexList = dataOut.channelIndexList
902 channelIndexList = dataOut.channelIndexList
900 channelList = dataOut.channelList
903 channelList = dataOut.channelList
901 else:
904 else:
902 channelIndexList = []
905 channelIndexList = []
903 for channel in channelList:
906 for channel in channelList:
904 if channel not in dataOut.channelList:
907 if channel not in dataOut.channelList:
905 raise ValueError, "Channel %d is not in dataOut.channelList"
908 raise ValueError, "Channel %d is not in dataOut.channelList"
906 channelIndexList.append(dataOut.channelList.index(channel))
909 channelIndexList.append(dataOut.channelList.index(channel))
907
910
908 factor = dataOut.normFactor
911 factor = dataOut.normFactor
909
912
910 y = dataOut.getHeiRange()
913 y = dataOut.getHeiRange()
911
914
912 #for voltage
915 #for voltage
913 if dataOut.type == 'Voltage':
916 if dataOut.type == 'Voltage':
914 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
917 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
915 x = x.real
918 x = x.real
916 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
919 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
917
920
918 #for spectra
921 #for spectra
919 if dataOut.type == 'Spectra':
922 if dataOut.type == 'Spectra':
920 x = dataOut.data_spc[channelIndexList,:,:]/factor
923 x = dataOut.data_spc[channelIndexList,:,:]/factor
921 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
924 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
922 x = numpy.average(x, axis=1)
925 x = numpy.average(x, axis=1)
923
926
924
927
925 xdB = 10*numpy.log10(x)
928 xdB = 10*numpy.log10(x)
926
929
927 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
930 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
928 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
931 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
929 xlabel = "dB"
932 xlabel = "dB"
930 ylabel = "Range (Km)"
933 ylabel = "Range (Km)"
931
934
932 if not self.isConfig:
935 if not self.isConfig:
933
936
934 nplots = 1
937 nplots = 1
935
938
936 self.setup(id=id,
939 self.setup(id=id,
937 nplots=nplots,
940 nplots=nplots,
938 wintitle=wintitle,
941 wintitle=wintitle,
939 show=show)
942 show=show)
940
943
941 if ymin == None: ymin = numpy.nanmin(y)
944 if ymin == None: ymin = numpy.nanmin(y)
942 if ymax == None: ymax = numpy.nanmax(y)
945 if ymax == None: ymax = numpy.nanmax(y)
943 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
946 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
944 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
947 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
945
948
946 self.isConfig = True
949 self.isConfig = True
947
950
948 self.setWinTitle(title)
951 self.setWinTitle(title)
949
952
950 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
953 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
951 axes = self.axesList[0]
954 axes = self.axesList[0]
952
955
953 legendlabels = ["channel %d"%x for x in channelList]
956 legendlabels = ["channel %d"%x for x in channelList]
954 axes.pmultiline(xdB, y,
957 axes.pmultiline(xdB, y,
955 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
958 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
956 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
959 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
957 ytick_visible=True, nxticks=5,
960 ytick_visible=True, nxticks=5,
958 grid='x')
961 grid='x')
959
962
960 self.draw()
963 self.draw()
961
964
962 self.save(figpath=figpath,
965 self.save(figpath=figpath,
963 figfile=figfile,
966 figfile=figfile,
964 save=save,
967 save=save,
965 ftp=ftp,
968 ftp=ftp,
966 wr_period=wr_period,
969 wr_period=wr_period,
967 thisDatetime=thisDatetime)
970 thisDatetime=thisDatetime)
968
971
969 class SpectraCutPlot(Figure):
972 class SpectraCutPlot(Figure):
970
973
971 isConfig = None
974 isConfig = None
972 __nsubplots = None
975 __nsubplots = None
973
976
974 WIDTHPROF = None
977 WIDTHPROF = None
975 HEIGHTPROF = None
978 HEIGHTPROF = None
976 PREFIX = 'spc_cut'
979 PREFIX = 'spc_cut'
977
980
978 def __init__(self):
981 def __init__(self):
979 self.isConfig = False
982 self.isConfig = False
980 self.__nsubplots = 1
983 self.__nsubplots = 1
981
984
982 self.PLOT_CODE = POWER_CODE
985 self.PLOT_CODE = POWER_CODE
983
986
984 self.WIDTH = 700
987 self.WIDTH = 700
985 self.HEIGHT = 500
988 self.HEIGHT = 500
986 self.counter_imagwr = 0
989 self.counter_imagwr = 0
987
990
988 def getSubplots(self):
991 def getSubplots(self):
989 ncol = 1
992 ncol = 1
990 nrow = 1
993 nrow = 1
991
994
992 return nrow, ncol
995 return nrow, ncol
993
996
994 def setup(self, id, nplots, wintitle, show):
997 def setup(self, id, nplots, wintitle, show):
995
998
996 self.nplots = nplots
999 self.nplots = nplots
997
1000
998 ncolspan = 1
1001 ncolspan = 1
999 colspan = 1
1002 colspan = 1
1000
1003
1001 self.createFigure(id = id,
1004 self.createFigure(id = id,
1002 wintitle = wintitle,
1005 wintitle = wintitle,
1003 widthplot = self.WIDTH,
1006 widthplot = self.WIDTH,
1004 heightplot = self.HEIGHT,
1007 heightplot = self.HEIGHT,
1005 show=show)
1008 show=show)
1006
1009
1007 nrow, ncol = self.getSubplots()
1010 nrow, ncol = self.getSubplots()
1008
1011
1009 counter = 0
1012 counter = 0
1010 for y in range(nrow):
1013 for y in range(nrow):
1011 for x in range(ncol):
1014 for x in range(ncol):
1012 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1015 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1013
1016
1014 def run(self, dataOut, id, wintitle="", channelList=None,
1017 def run(self, dataOut, id, wintitle="", channelList=None,
1015 xmin=None, xmax=None, ymin=None, ymax=None,
1018 xmin=None, xmax=None, ymin=None, ymax=None,
1016 save=False, figpath='./', figfile=None, show=True,
1019 save=False, figpath='./', figfile=None, show=True,
1017 ftp=False, wr_period=1, server=None,
1020 ftp=False, wr_period=1, server=None,
1018 folder=None, username=None, password=None,
1021 folder=None, username=None, password=None,
1019 xaxis="frequency"):
1022 xaxis="frequency"):
1020
1023
1021
1024
1022 if channelList == None:
1025 if channelList == None:
1023 channelIndexList = dataOut.channelIndexList
1026 channelIndexList = dataOut.channelIndexList
1024 channelList = dataOut.channelList
1027 channelList = dataOut.channelList
1025 else:
1028 else:
1026 channelIndexList = []
1029 channelIndexList = []
1027 for channel in channelList:
1030 for channel in channelList:
1028 if channel not in dataOut.channelList:
1031 if channel not in dataOut.channelList:
1029 raise ValueError, "Channel %d is not in dataOut.channelList"
1032 raise ValueError, "Channel %d is not in dataOut.channelList"
1030 channelIndexList.append(dataOut.channelList.index(channel))
1033 channelIndexList.append(dataOut.channelList.index(channel))
1031
1034
1032 factor = dataOut.normFactor
1035 factor = dataOut.normFactor
1033
1036
1034 y = dataOut.getHeiRange()
1037 y = dataOut.getHeiRange()
1035
1038
1036 z = dataOut.data_spc/factor
1039 z = dataOut.data_spc/factor
1037 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1040 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1038
1041
1039 hei_index = numpy.arange(25)*3 + 20
1042 hei_index = numpy.arange(25)*3 + 20
1040
1043
1041 if xaxis == "frequency":
1044 if xaxis == "frequency":
1042 x = dataOut.getFreqRange()/1000.
1045 x = dataOut.getFreqRange()/1000.
1043 zdB = 10*numpy.log10(z[0,:,hei_index])
1046 zdB = 10*numpy.log10(z[0,:,hei_index])
1044 xlabel = "Frequency (kHz)"
1047 xlabel = "Frequency (kHz)"
1045 ylabel = "Power (dB)"
1048 ylabel = "Power (dB)"
1046
1049
1047 elif xaxis == "time":
1050 elif xaxis == "time":
1048 x = dataOut.getAcfRange()
1051 x = dataOut.getAcfRange()
1049 zdB = z[0,:,hei_index]
1052 zdB = z[0,:,hei_index]
1050 xlabel = "Time (ms)"
1053 xlabel = "Time (ms)"
1051 ylabel = "ACF"
1054 ylabel = "ACF"
1052
1055
1053 else:
1056 else:
1054 x = dataOut.getVelRange()
1057 x = dataOut.getVelRange()
1055 zdB = 10*numpy.log10(z[0,:,hei_index])
1058 zdB = 10*numpy.log10(z[0,:,hei_index])
1056 xlabel = "Velocity (m/s)"
1059 xlabel = "Velocity (m/s)"
1057 ylabel = "Power (dB)"
1060 ylabel = "Power (dB)"
1058
1061
1059 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1062 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1060 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1063 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1061
1064
1062 if not self.isConfig:
1065 if not self.isConfig:
1063
1066
1064 nplots = 1
1067 nplots = 1
1065
1068
1066 self.setup(id=id,
1069 self.setup(id=id,
1067 nplots=nplots,
1070 nplots=nplots,
1068 wintitle=wintitle,
1071 wintitle=wintitle,
1069 show=show)
1072 show=show)
1070
1073
1071 if xmin == None: xmin = numpy.nanmin(x)*0.9
1074 if xmin == None: xmin = numpy.nanmin(x)*0.9
1072 if xmax == None: xmax = numpy.nanmax(x)*1.1
1075 if xmax == None: xmax = numpy.nanmax(x)*1.1
1073 if ymin == None: ymin = numpy.nanmin(zdB)
1076 if ymin == None: ymin = numpy.nanmin(zdB)
1074 if ymax == None: ymax = numpy.nanmax(zdB)
1077 if ymax == None: ymax = numpy.nanmax(zdB)
1075
1078
1076 self.isConfig = True
1079 self.isConfig = True
1077
1080
1078 self.setWinTitle(title)
1081 self.setWinTitle(title)
1079
1082
1080 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1083 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1081 axes = self.axesList[0]
1084 axes = self.axesList[0]
1082
1085
1083 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1086 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1084
1087
1085 axes.pmultilineyaxis( x, zdB,
1088 axes.pmultilineyaxis( x, zdB,
1086 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1089 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1087 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1090 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1088 ytick_visible=True, nxticks=5,
1091 ytick_visible=True, nxticks=5,
1089 grid='x')
1092 grid='x')
1090
1093
1091 self.draw()
1094 self.draw()
1092
1095
1093 self.save(figpath=figpath,
1096 self.save(figpath=figpath,
1094 figfile=figfile,
1097 figfile=figfile,
1095 save=save,
1098 save=save,
1096 ftp=ftp,
1099 ftp=ftp,
1097 wr_period=wr_period,
1100 wr_period=wr_period,
1098 thisDatetime=thisDatetime)
1101 thisDatetime=thisDatetime)
1099
1102
1100 class Noise(Figure):
1103 class Noise(Figure):
1101
1104
1102 isConfig = None
1105 isConfig = None
1103 __nsubplots = None
1106 __nsubplots = None
1104
1107
1105 PREFIX = 'noise'
1108 PREFIX = 'noise'
1106
1109
1107 def __init__(self):
1110 def __init__(self):
1108
1111
1109 self.timerange = 24*60*60
1112 self.timerange = 24*60*60
1110 self.isConfig = False
1113 self.isConfig = False
1111 self.__nsubplots = 1
1114 self.__nsubplots = 1
1112 self.counter_imagwr = 0
1115 self.counter_imagwr = 0
1113 self.WIDTH = 800
1116 self.WIDTH = 800
1114 self.HEIGHT = 400
1117 self.HEIGHT = 400
1115 self.WIDTHPROF = 120
1118 self.WIDTHPROF = 120
1116 self.HEIGHTPROF = 0
1119 self.HEIGHTPROF = 0
1117 self.xdata = None
1120 self.xdata = None
1118 self.ydata = None
1121 self.ydata = None
1119
1122
1120 self.PLOT_CODE = NOISE_CODE
1123 self.PLOT_CODE = NOISE_CODE
1121
1124
1122 self.FTP_WEI = None
1125 self.FTP_WEI = None
1123 self.EXP_CODE = None
1126 self.EXP_CODE = None
1124 self.SUB_EXP_CODE = None
1127 self.SUB_EXP_CODE = None
1125 self.PLOT_POS = None
1128 self.PLOT_POS = None
1126 self.figfile = None
1129 self.figfile = None
1127
1130
1128 self.xmin = None
1131 self.xmin = None
1129 self.xmax = None
1132 self.xmax = None
1130
1133
1131 def getSubplots(self):
1134 def getSubplots(self):
1132
1135
1133 ncol = 1
1136 ncol = 1
1134 nrow = 1
1137 nrow = 1
1135
1138
1136 return nrow, ncol
1139 return nrow, ncol
1137
1140
1138 def openfile(self, filename):
1141 def openfile(self, filename):
1139 dirname = os.path.dirname(filename)
1142 dirname = os.path.dirname(filename)
1140
1143
1141 if not os.path.exists(dirname):
1144 if not os.path.exists(dirname):
1142 os.mkdir(dirname)
1145 os.mkdir(dirname)
1143
1146
1144 f = open(filename,'w+')
1147 f = open(filename,'w+')
1145 f.write('\n\n')
1148 f.write('\n\n')
1146 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1149 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1147 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1150 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1148 f.close()
1151 f.close()
1149
1152
1150 def save_data(self, filename_phase, data, data_datetime):
1153 def save_data(self, filename_phase, data, data_datetime):
1151
1154
1152 f=open(filename_phase,'a')
1155 f=open(filename_phase,'a')
1153
1156
1154 timetuple_data = data_datetime.timetuple()
1157 timetuple_data = data_datetime.timetuple()
1155 day = str(timetuple_data.tm_mday)
1158 day = str(timetuple_data.tm_mday)
1156 month = str(timetuple_data.tm_mon)
1159 month = str(timetuple_data.tm_mon)
1157 year = str(timetuple_data.tm_year)
1160 year = str(timetuple_data.tm_year)
1158 hour = str(timetuple_data.tm_hour)
1161 hour = str(timetuple_data.tm_hour)
1159 minute = str(timetuple_data.tm_min)
1162 minute = str(timetuple_data.tm_min)
1160 second = str(timetuple_data.tm_sec)
1163 second = str(timetuple_data.tm_sec)
1161
1164
1162 data_msg = ''
1165 data_msg = ''
1163 for i in range(len(data)):
1166 for i in range(len(data)):
1164 data_msg += str(data[i]) + ' '
1167 data_msg += str(data[i]) + ' '
1165
1168
1166 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1169 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1167 f.close()
1170 f.close()
1168
1171
1169
1172
1170 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1173 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1171
1174
1172 self.__showprofile = showprofile
1175 self.__showprofile = showprofile
1173 self.nplots = nplots
1176 self.nplots = nplots
1174
1177
1175 ncolspan = 7
1178 ncolspan = 7
1176 colspan = 6
1179 colspan = 6
1177 self.__nsubplots = 2
1180 self.__nsubplots = 2
1178
1181
1179 self.createFigure(id = id,
1182 self.createFigure(id = id,
1180 wintitle = wintitle,
1183 wintitle = wintitle,
1181 widthplot = self.WIDTH+self.WIDTHPROF,
1184 widthplot = self.WIDTH+self.WIDTHPROF,
1182 heightplot = self.HEIGHT+self.HEIGHTPROF,
1185 heightplot = self.HEIGHT+self.HEIGHTPROF,
1183 show=show)
1186 show=show)
1184
1187
1185 nrow, ncol = self.getSubplots()
1188 nrow, ncol = self.getSubplots()
1186
1189
1187 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1190 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1188
1191
1189
1192
1190 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1193 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1191 xmin=None, xmax=None, ymin=None, ymax=None,
1194 xmin=None, xmax=None, ymin=None, ymax=None,
1192 timerange=None,
1195 timerange=None,
1193 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1196 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1194 server=None, folder=None, username=None, password=None,
1197 server=None, folder=None, username=None, password=None,
1195 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1198 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1196
1199
1197 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1200 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1198 return
1201 return
1199
1202
1200 if channelList == None:
1203 if channelList == None:
1201 channelIndexList = dataOut.channelIndexList
1204 channelIndexList = dataOut.channelIndexList
1202 channelList = dataOut.channelList
1205 channelList = dataOut.channelList
1203 else:
1206 else:
1204 channelIndexList = []
1207 channelIndexList = []
1205 for channel in channelList:
1208 for channel in channelList:
1206 if channel not in dataOut.channelList:
1209 if channel not in dataOut.channelList:
1207 raise ValueError, "Channel %d is not in dataOut.channelList"
1210 raise ValueError, "Channel %d is not in dataOut.channelList"
1208 channelIndexList.append(dataOut.channelList.index(channel))
1211 channelIndexList.append(dataOut.channelList.index(channel))
1209
1212
1210 x = dataOut.getTimeRange()
1213 x = dataOut.getTimeRange()
1211 #y = dataOut.getHeiRange()
1214 #y = dataOut.getHeiRange()
1212 factor = dataOut.normFactor
1215 factor = dataOut.normFactor
1213 noise = dataOut.noise[channelIndexList]/factor
1216 noise = dataOut.noise[channelIndexList]/factor
1214 noisedB = 10*numpy.log10(noise)
1217 noisedB = 10*numpy.log10(noise)
1215
1218
1216 thisDatetime = dataOut.datatime
1219 thisDatetime = dataOut.datatime
1217
1220
1218 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1221 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1219 xlabel = ""
1222 xlabel = ""
1220 ylabel = "Intensity (dB)"
1223 ylabel = "Intensity (dB)"
1221 update_figfile = False
1224 update_figfile = False
1222
1225
1223 if not self.isConfig:
1226 if not self.isConfig:
1224
1227
1225 nplots = 1
1228 nplots = 1
1226
1229
1227 self.setup(id=id,
1230 self.setup(id=id,
1228 nplots=nplots,
1231 nplots=nplots,
1229 wintitle=wintitle,
1232 wintitle=wintitle,
1230 showprofile=showprofile,
1233 showprofile=showprofile,
1231 show=show)
1234 show=show)
1232
1235
1233 if timerange != None:
1236 if timerange != None:
1234 self.timerange = timerange
1237 self.timerange = timerange
1235
1238
1236 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1239 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1237
1240
1238 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1241 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1239 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1242 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1240
1243
1241 self.FTP_WEI = ftp_wei
1244 self.FTP_WEI = ftp_wei
1242 self.EXP_CODE = exp_code
1245 self.EXP_CODE = exp_code
1243 self.SUB_EXP_CODE = sub_exp_code
1246 self.SUB_EXP_CODE = sub_exp_code
1244 self.PLOT_POS = plot_pos
1247 self.PLOT_POS = plot_pos
1245
1248
1246
1249
1247 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1250 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1248 self.isConfig = True
1251 self.isConfig = True
1249 self.figfile = figfile
1252 self.figfile = figfile
1250 self.xdata = numpy.array([])
1253 self.xdata = numpy.array([])
1251 self.ydata = numpy.array([])
1254 self.ydata = numpy.array([])
1252
1255
1253 update_figfile = True
1256 update_figfile = True
1254
1257
1255 #open file beacon phase
1258 #open file beacon phase
1256 path = '%s%03d' %(self.PREFIX, self.id)
1259 path = '%s%03d' %(self.PREFIX, self.id)
1257 noise_file = os.path.join(path,'%s.txt'%self.name)
1260 noise_file = os.path.join(path,'%s.txt'%self.name)
1258 self.filename_noise = os.path.join(figpath,noise_file)
1261 self.filename_noise = os.path.join(figpath,noise_file)
1259
1262
1260 self.setWinTitle(title)
1263 self.setWinTitle(title)
1261
1264
1262 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1265 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1263
1266
1264 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1267 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1265 axes = self.axesList[0]
1268 axes = self.axesList[0]
1266
1269
1267 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1270 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1268
1271
1269 if len(self.ydata)==0:
1272 if len(self.ydata)==0:
1270 self.ydata = noisedB.reshape(-1,1)
1273 self.ydata = noisedB.reshape(-1,1)
1271 else:
1274 else:
1272 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1275 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1273
1276
1274
1277
1275 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1278 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1276 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1279 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1277 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1280 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1278 XAxisAsTime=True, grid='both'
1281 XAxisAsTime=True, grid='both'
1279 )
1282 )
1280
1283
1281 self.draw()
1284 self.draw()
1282
1285
1283 if dataOut.ltctime >= self.xmax:
1286 if dataOut.ltctime >= self.xmax:
1284 self.counter_imagwr = wr_period
1287 self.counter_imagwr = wr_period
1285 self.isConfig = False
1288 self.isConfig = False
1286 update_figfile = True
1289 update_figfile = True
1287
1290
1288 self.save(figpath=figpath,
1291 self.save(figpath=figpath,
1289 figfile=figfile,
1292 figfile=figfile,
1290 save=save,
1293 save=save,
1291 ftp=ftp,
1294 ftp=ftp,
1292 wr_period=wr_period,
1295 wr_period=wr_period,
1293 thisDatetime=thisDatetime,
1296 thisDatetime=thisDatetime,
1294 update_figfile=update_figfile)
1297 update_figfile=update_figfile)
1295
1298
1296 #store data beacon phase
1299 #store data beacon phase
1297 if save:
1300 if save:
1298 self.save_data(self.filename_noise, noisedB, thisDatetime)
1301 self.save_data(self.filename_noise, noisedB, thisDatetime)
1299
1302
1300 class BeaconPhase(Figure):
1303 class BeaconPhase(Figure):
1301
1304
1302 __isConfig = None
1305 __isConfig = None
1303 __nsubplots = None
1306 __nsubplots = None
1304
1307
1305 PREFIX = 'beacon_phase'
1308 PREFIX = 'beacon_phase'
1306
1309
1307 def __init__(self):
1310 def __init__(self):
1308
1311
1309 self.timerange = 24*60*60
1312 self.timerange = 24*60*60
1310 self.isConfig = False
1313 self.isConfig = False
1311 self.__nsubplots = 1
1314 self.__nsubplots = 1
1312 self.counter_imagwr = 0
1315 self.counter_imagwr = 0
1313 self.WIDTH = 800
1316 self.WIDTH = 800
1314 self.HEIGHT = 400
1317 self.HEIGHT = 400
1315 self.WIDTHPROF = 120
1318 self.WIDTHPROF = 120
1316 self.HEIGHTPROF = 0
1319 self.HEIGHTPROF = 0
1317 self.xdata = None
1320 self.xdata = None
1318 self.ydata = None
1321 self.ydata = None
1319
1322
1320 self.PLOT_CODE = BEACON_CODE
1323 self.PLOT_CODE = BEACON_CODE
1321
1324
1322 self.FTP_WEI = None
1325 self.FTP_WEI = None
1323 self.EXP_CODE = None
1326 self.EXP_CODE = None
1324 self.SUB_EXP_CODE = None
1327 self.SUB_EXP_CODE = None
1325 self.PLOT_POS = None
1328 self.PLOT_POS = None
1326
1329
1327 self.filename_phase = None
1330 self.filename_phase = None
1328
1331
1329 self.figfile = None
1332 self.figfile = None
1330
1333
1331 self.xmin = None
1334 self.xmin = None
1332 self.xmax = None
1335 self.xmax = None
1333
1336
1334 def getSubplots(self):
1337 def getSubplots(self):
1335
1338
1336 ncol = 1
1339 ncol = 1
1337 nrow = 1
1340 nrow = 1
1338
1341
1339 return nrow, ncol
1342 return nrow, ncol
1340
1343
1341 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1344 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1342
1345
1343 self.__showprofile = showprofile
1346 self.__showprofile = showprofile
1344 self.nplots = nplots
1347 self.nplots = nplots
1345
1348
1346 ncolspan = 7
1349 ncolspan = 7
1347 colspan = 6
1350 colspan = 6
1348 self.__nsubplots = 2
1351 self.__nsubplots = 2
1349
1352
1350 self.createFigure(id = id,
1353 self.createFigure(id = id,
1351 wintitle = wintitle,
1354 wintitle = wintitle,
1352 widthplot = self.WIDTH+self.WIDTHPROF,
1355 widthplot = self.WIDTH+self.WIDTHPROF,
1353 heightplot = self.HEIGHT+self.HEIGHTPROF,
1356 heightplot = self.HEIGHT+self.HEIGHTPROF,
1354 show=show)
1357 show=show)
1355
1358
1356 nrow, ncol = self.getSubplots()
1359 nrow, ncol = self.getSubplots()
1357
1360
1358 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1361 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1359
1362
1360 def save_phase(self, filename_phase):
1363 def save_phase(self, filename_phase):
1361 f = open(filename_phase,'w+')
1364 f = open(filename_phase,'w+')
1362 f.write('\n\n')
1365 f.write('\n\n')
1363 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1366 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1364 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1367 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1365 f.close()
1368 f.close()
1366
1369
1367 def save_data(self, filename_phase, data, data_datetime):
1370 def save_data(self, filename_phase, data, data_datetime):
1368 f=open(filename_phase,'a')
1371 f=open(filename_phase,'a')
1369 timetuple_data = data_datetime.timetuple()
1372 timetuple_data = data_datetime.timetuple()
1370 day = str(timetuple_data.tm_mday)
1373 day = str(timetuple_data.tm_mday)
1371 month = str(timetuple_data.tm_mon)
1374 month = str(timetuple_data.tm_mon)
1372 year = str(timetuple_data.tm_year)
1375 year = str(timetuple_data.tm_year)
1373 hour = str(timetuple_data.tm_hour)
1376 hour = str(timetuple_data.tm_hour)
1374 minute = str(timetuple_data.tm_min)
1377 minute = str(timetuple_data.tm_min)
1375 second = str(timetuple_data.tm_sec)
1378 second = str(timetuple_data.tm_sec)
1376 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1379 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1377 f.close()
1380 f.close()
1378
1381
1379
1382
1380 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1383 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1381 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1384 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1382 timerange=None,
1385 timerange=None,
1383 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1386 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1384 server=None, folder=None, username=None, password=None,
1387 server=None, folder=None, username=None, password=None,
1385 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1388 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1386
1389
1387 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1390 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1388 return
1391 return
1389
1392
1390 if pairsList == None:
1393 if pairsList == None:
1391 pairsIndexList = dataOut.pairsIndexList[:10]
1394 pairsIndexList = dataOut.pairsIndexList[:10]
1392 else:
1395 else:
1393 pairsIndexList = []
1396 pairsIndexList = []
1394 for pair in pairsList:
1397 for pair in pairsList:
1395 if pair not in dataOut.pairsList:
1398 if pair not in dataOut.pairsList:
1396 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1399 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1397 pairsIndexList.append(dataOut.pairsList.index(pair))
1400 pairsIndexList.append(dataOut.pairsList.index(pair))
1398
1401
1399 if pairsIndexList == []:
1402 if pairsIndexList == []:
1400 return
1403 return
1401
1404
1402 # if len(pairsIndexList) > 4:
1405 # if len(pairsIndexList) > 4:
1403 # pairsIndexList = pairsIndexList[0:4]
1406 # pairsIndexList = pairsIndexList[0:4]
1404
1407
1405 hmin_index = None
1408 hmin_index = None
1406 hmax_index = None
1409 hmax_index = None
1407
1410
1408 if hmin != None and hmax != None:
1411 if hmin != None and hmax != None:
1409 indexes = numpy.arange(dataOut.nHeights)
1412 indexes = numpy.arange(dataOut.nHeights)
1410 hmin_list = indexes[dataOut.heightList >= hmin]
1413 hmin_list = indexes[dataOut.heightList >= hmin]
1411 hmax_list = indexes[dataOut.heightList <= hmax]
1414 hmax_list = indexes[dataOut.heightList <= hmax]
1412
1415
1413 if hmin_list.any():
1416 if hmin_list.any():
1414 hmin_index = hmin_list[0]
1417 hmin_index = hmin_list[0]
1415
1418
1416 if hmax_list.any():
1419 if hmax_list.any():
1417 hmax_index = hmax_list[-1]+1
1420 hmax_index = hmax_list[-1]+1
1418
1421
1419 x = dataOut.getTimeRange()
1422 x = dataOut.getTimeRange()
1420 #y = dataOut.getHeiRange()
1423 #y = dataOut.getHeiRange()
1421
1424
1422
1425
1423 thisDatetime = dataOut.datatime
1426 thisDatetime = dataOut.datatime
1424
1427
1425 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1428 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1426 xlabel = "Local Time"
1429 xlabel = "Local Time"
1427 ylabel = "Phase (degrees)"
1430 ylabel = "Phase (degrees)"
1428
1431
1429 update_figfile = False
1432 update_figfile = False
1430
1433
1431 nplots = len(pairsIndexList)
1434 nplots = len(pairsIndexList)
1432 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1435 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1433 phase_beacon = numpy.zeros(len(pairsIndexList))
1436 phase_beacon = numpy.zeros(len(pairsIndexList))
1434 for i in range(nplots):
1437 for i in range(nplots):
1435 pair = dataOut.pairsList[pairsIndexList[i]]
1438 pair = dataOut.pairsList[pairsIndexList[i]]
1436 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1439 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1437 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1440 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1438 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1441 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1439 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1442 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1440 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1443 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1441
1444
1442 #print "Phase %d%d" %(pair[0], pair[1])
1445 #print "Phase %d%d" %(pair[0], pair[1])
1443 #print phase[dataOut.beacon_heiIndexList]
1446 #print phase[dataOut.beacon_heiIndexList]
1444
1447
1445 if dataOut.beacon_heiIndexList:
1448 if dataOut.beacon_heiIndexList:
1446 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1449 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1447 else:
1450 else:
1448 phase_beacon[i] = numpy.average(phase)
1451 phase_beacon[i] = numpy.average(phase)
1449
1452
1450 if not self.isConfig:
1453 if not self.isConfig:
1451
1454
1452 nplots = len(pairsIndexList)
1455 nplots = len(pairsIndexList)
1453
1456
1454 self.setup(id=id,
1457 self.setup(id=id,
1455 nplots=nplots,
1458 nplots=nplots,
1456 wintitle=wintitle,
1459 wintitle=wintitle,
1457 showprofile=showprofile,
1460 showprofile=showprofile,
1458 show=show)
1461 show=show)
1459
1462
1460 if timerange != None:
1463 if timerange != None:
1461 self.timerange = timerange
1464 self.timerange = timerange
1462
1465
1463 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1466 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1464
1467
1465 if ymin == None: ymin = 0
1468 if ymin == None: ymin = 0
1466 if ymax == None: ymax = 360
1469 if ymax == None: ymax = 360
1467
1470
1468 self.FTP_WEI = ftp_wei
1471 self.FTP_WEI = ftp_wei
1469 self.EXP_CODE = exp_code
1472 self.EXP_CODE = exp_code
1470 self.SUB_EXP_CODE = sub_exp_code
1473 self.SUB_EXP_CODE = sub_exp_code
1471 self.PLOT_POS = plot_pos
1474 self.PLOT_POS = plot_pos
1472
1475
1473 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1476 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1474 self.isConfig = True
1477 self.isConfig = True
1475 self.figfile = figfile
1478 self.figfile = figfile
1476 self.xdata = numpy.array([])
1479 self.xdata = numpy.array([])
1477 self.ydata = numpy.array([])
1480 self.ydata = numpy.array([])
1478
1481
1479 update_figfile = True
1482 update_figfile = True
1480
1483
1481 #open file beacon phase
1484 #open file beacon phase
1482 path = '%s%03d' %(self.PREFIX, self.id)
1485 path = '%s%03d' %(self.PREFIX, self.id)
1483 beacon_file = os.path.join(path,'%s.txt'%self.name)
1486 beacon_file = os.path.join(path,'%s.txt'%self.name)
1484 self.filename_phase = os.path.join(figpath,beacon_file)
1487 self.filename_phase = os.path.join(figpath,beacon_file)
1485 #self.save_phase(self.filename_phase)
1488 #self.save_phase(self.filename_phase)
1486
1489
1487
1490
1488 #store data beacon phase
1491 #store data beacon phase
1489 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1492 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1490
1493
1491 self.setWinTitle(title)
1494 self.setWinTitle(title)
1492
1495
1493
1496
1494 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1497 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1495
1498
1496 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1499 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1497
1500
1498 axes = self.axesList[0]
1501 axes = self.axesList[0]
1499
1502
1500 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1503 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1501
1504
1502 if len(self.ydata)==0:
1505 if len(self.ydata)==0:
1503 self.ydata = phase_beacon.reshape(-1,1)
1506 self.ydata = phase_beacon.reshape(-1,1)
1504 else:
1507 else:
1505 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1508 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1506
1509
1507
1510
1508 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1511 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1509 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1512 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1510 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1513 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1511 XAxisAsTime=True, grid='both'
1514 XAxisAsTime=True, grid='both'
1512 )
1515 )
1513
1516
1514 self.draw()
1517 self.draw()
1515
1518
1516 if dataOut.ltctime >= self.xmax:
1519 if dataOut.ltctime >= self.xmax:
1517 self.counter_imagwr = wr_period
1520 self.counter_imagwr = wr_period
1518 self.isConfig = False
1521 self.isConfig = False
1519 update_figfile = True
1522 update_figfile = True
1520
1523
1521 self.save(figpath=figpath,
1524 self.save(figpath=figpath,
1522 figfile=figfile,
1525 figfile=figfile,
1523 save=save,
1526 save=save,
1524 ftp=ftp,
1527 ftp=ftp,
1525 wr_period=wr_period,
1528 wr_period=wr_period,
1526 thisDatetime=thisDatetime,
1529 thisDatetime=thisDatetime,
1527 update_figfile=update_figfile)
1530 update_figfile=update_figfile)
@@ -1,466 +1,468
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import sys
3 import sys
4 import matplotlib
4 import matplotlib
5
5
6 if 'linux' in sys.platform:
6 if 'linux' in sys.platform:
7 matplotlib.use("TKAgg")
7 matplotlib.use("TKAgg")
8
8
9 if 'darwin' in sys.platform:
9 if 'darwin' in sys.platform:
10 matplotlib.use('TKAgg')
10 matplotlib.use('TKAgg')
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 import matplotlib.pyplot
12 import matplotlib.pyplot
13
13
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 from matplotlib.ticker import FuncFormatter, LinearLocator
15 from matplotlib.ticker import FuncFormatter, LinearLocator
16
16
17 ###########################################
17 ###########################################
18 #Actualizacion de las funciones del driver
18 #Actualizacion de las funciones del driver
19 ###########################################
19 ###########################################
20
20
21 # create jro colormap
22
21 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
22 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
23 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
24 matplotlib.pyplot.register_cmap(cmap=ncmap)
26 matplotlib.pyplot.register_cmap(cmap=ncmap)
25
27
26 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
27
29
28 matplotlib.pyplot.ioff()
30 matplotlib.pyplot.ioff()
29
31
30 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
31 fig.canvas.manager.set_window_title(wintitle)
33 fig.canvas.manager.set_window_title(wintitle)
32 # fig.canvas.manager.resize(width, height)
34 # fig.canvas.manager.resize(width, height)
33 matplotlib.pyplot.ion()
35 matplotlib.pyplot.ion()
34
36
35 if show:
37 if show:
36 matplotlib.pyplot.show()
38 matplotlib.pyplot.show()
37
39
38 return fig
40 return fig
39
41
40 def closeFigure(show=False, fig=None):
42 def closeFigure(show=False, fig=None):
41
43
42 # matplotlib.pyplot.ioff()
44 # matplotlib.pyplot.ioff()
43 # matplotlib.pyplot.pause(0)
45 # matplotlib.pyplot.pause(0)
44
46
45 if show:
47 if show:
46 matplotlib.pyplot.show()
48 matplotlib.pyplot.show()
47
49
48 if fig != None:
50 if fig != None:
49 matplotlib.pyplot.close(fig)
51 matplotlib.pyplot.close(fig)
50 # matplotlib.pyplot.pause(0)
52 # matplotlib.pyplot.pause(0)
51 # matplotlib.pyplot.ion()
53 # matplotlib.pyplot.ion()
52
54
53 return
55 return
54
56
55 matplotlib.pyplot.close("all")
57 matplotlib.pyplot.close("all")
56 # matplotlib.pyplot.pause(0)
58 # matplotlib.pyplot.pause(0)
57 # matplotlib.pyplot.ion()
59 # matplotlib.pyplot.ion()
58
60
59 return
61 return
60
62
61 def saveFigure(fig, filename):
63 def saveFigure(fig, filename):
62
64
63 # matplotlib.pyplot.ioff()
65 # matplotlib.pyplot.ioff()
64 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
65 # matplotlib.pyplot.ion()
67 # matplotlib.pyplot.ion()
66
68
67 def clearFigure(fig):
69 def clearFigure(fig):
68
70
69 fig.clf()
71 fig.clf()
70
72
71 def setWinTitle(fig, title):
73 def setWinTitle(fig, title):
72
74
73 fig.canvas.manager.set_window_title(title)
75 fig.canvas.manager.set_window_title(title)
74
76
75 def setTitle(fig, title):
77 def setTitle(fig, title):
76
78
77 fig.suptitle(title)
79 fig.suptitle(title)
78
80
79 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
80
82
81 matplotlib.pyplot.ioff()
83 matplotlib.pyplot.ioff()
82 matplotlib.pyplot.figure(fig.number)
84 matplotlib.pyplot.figure(fig.number)
83 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
84 (xpos, ypos),
86 (xpos, ypos),
85 colspan=colspan,
87 colspan=colspan,
86 rowspan=rowspan,
88 rowspan=rowspan,
87 polar=polar)
89 polar=polar)
88
90
89 matplotlib.pyplot.ion()
91 matplotlib.pyplot.ion()
90 return axes
92 return axes
91
93
92 def setAxesText(ax, text):
94 def setAxesText(ax, text):
93
95
94 ax.annotate(text,
96 ax.annotate(text,
95 xy = (.1, .99),
97 xy = (.1, .99),
96 xycoords = 'figure fraction',
98 xycoords = 'figure fraction',
97 horizontalalignment = 'left',
99 horizontalalignment = 'left',
98 verticalalignment = 'top',
100 verticalalignment = 'top',
99 fontsize = 10)
101 fontsize = 10)
100
102
101 def printLabels(ax, xlabel, ylabel, title):
103 def printLabels(ax, xlabel, ylabel, title):
102
104
103 ax.set_xlabel(xlabel, size=11)
105 ax.set_xlabel(xlabel, size=11)
104 ax.set_ylabel(ylabel, size=11)
106 ax.set_ylabel(ylabel, size=11)
105 ax.set_title(title, size=8)
107 ax.set_title(title, size=8)
106
108
107 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
109 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
108 ticksize=9, xtick_visible=True, ytick_visible=True,
110 ticksize=9, xtick_visible=True, ytick_visible=True,
109 nxticks=4, nyticks=10,
111 nxticks=4, nyticks=10,
110 grid=None,color='blue'):
112 grid=None,color='blue'):
111
113
112 """
114 """
113
115
114 Input:
116 Input:
115 grid : None, 'both', 'x', 'y'
117 grid : None, 'both', 'x', 'y'
116 """
118 """
117
119
118 matplotlib.pyplot.ioff()
120 matplotlib.pyplot.ioff()
119
121
120 ax.set_xlim([xmin,xmax])
122 ax.set_xlim([xmin,xmax])
121 ax.set_ylim([ymin,ymax])
123 ax.set_ylim([ymin,ymax])
122
124
123 printLabels(ax, xlabel, ylabel, title)
125 printLabels(ax, xlabel, ylabel, title)
124
126
125 ######################################################
127 ######################################################
126 if (xmax-xmin)<=1:
128 if (xmax-xmin)<=1:
127 xtickspos = numpy.linspace(xmin,xmax,nxticks)
129 xtickspos = numpy.linspace(xmin,xmax,nxticks)
128 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
130 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
129 ax.set_xticks(xtickspos)
131 ax.set_xticks(xtickspos)
130 else:
132 else:
131 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
133 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
132 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
134 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
133 ax.set_xticks(xtickspos)
135 ax.set_xticks(xtickspos)
134
136
135 for tick in ax.get_xticklabels():
137 for tick in ax.get_xticklabels():
136 tick.set_visible(xtick_visible)
138 tick.set_visible(xtick_visible)
137
139
138 for tick in ax.xaxis.get_major_ticks():
140 for tick in ax.xaxis.get_major_ticks():
139 tick.label.set_fontsize(ticksize)
141 tick.label.set_fontsize(ticksize)
140
142
141 ######################################################
143 ######################################################
142 for tick in ax.get_yticklabels():
144 for tick in ax.get_yticklabels():
143 tick.set_visible(ytick_visible)
145 tick.set_visible(ytick_visible)
144
146
145 for tick in ax.yaxis.get_major_ticks():
147 for tick in ax.yaxis.get_major_ticks():
146 tick.label.set_fontsize(ticksize)
148 tick.label.set_fontsize(ticksize)
147
149
148 ax.plot(x, y, color=color)
150 ax.plot(x, y, color=color)
149 iplot = ax.lines[-1]
151 iplot = ax.lines[-1]
150
152
151 ######################################################
153 ######################################################
152 if '0.' in matplotlib.__version__[0:2]:
154 if '0.' in matplotlib.__version__[0:2]:
153 print "The matplotlib version has to be updated to 1.1 or newer"
155 print "The matplotlib version has to be updated to 1.1 or newer"
154 return iplot
156 return iplot
155
157
156 if '1.0.' in matplotlib.__version__[0:4]:
158 if '1.0.' in matplotlib.__version__[0:4]:
157 print "The matplotlib version has to be updated to 1.1 or newer"
159 print "The matplotlib version has to be updated to 1.1 or newer"
158 return iplot
160 return iplot
159
161
160 if grid != None:
162 if grid != None:
161 ax.grid(b=True, which='major', axis=grid)
163 ax.grid(b=True, which='major', axis=grid)
162
164
163 matplotlib.pyplot.tight_layout()
165 matplotlib.pyplot.tight_layout()
164
166
165 matplotlib.pyplot.ion()
167 matplotlib.pyplot.ion()
166
168
167 return iplot
169 return iplot
168
170
169 def set_linedata(ax, x, y, idline):
171 def set_linedata(ax, x, y, idline):
170
172
171 ax.lines[idline].set_data(x,y)
173 ax.lines[idline].set_data(x,y)
172
174
173 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
175 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
174
176
175 ax = iplot.get_axes()
177 ax = iplot.get_axes()
176
178
177 printLabels(ax, xlabel, ylabel, title)
179 printLabels(ax, xlabel, ylabel, title)
178
180
179 set_linedata(ax, x, y, idline=0)
181 set_linedata(ax, x, y, idline=0)
180
182
181 def addpline(ax, x, y, color, linestyle, lw):
183 def addpline(ax, x, y, color, linestyle, lw):
182
184
183 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
185 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
184
186
185
187
186 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
188 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
187 xlabel='', ylabel='', title='', ticksize = 9,
189 xlabel='', ylabel='', title='', ticksize = 9,
188 colormap='jet',cblabel='', cbsize="5%",
190 colormap='jet',cblabel='', cbsize="5%",
189 XAxisAsTime=False):
191 XAxisAsTime=False):
190
192
191 matplotlib.pyplot.ioff()
193 matplotlib.pyplot.ioff()
192
194
193 divider = make_axes_locatable(ax)
195 divider = make_axes_locatable(ax)
194 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
196 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
195 fig = ax.get_figure()
197 fig = ax.get_figure()
196 fig.add_axes(ax_cb)
198 fig.add_axes(ax_cb)
197
199
198 ax.set_xlim([xmin,xmax])
200 ax.set_xlim([xmin,xmax])
199 ax.set_ylim([ymin,ymax])
201 ax.set_ylim([ymin,ymax])
200
202
201 printLabels(ax, xlabel, ylabel, title)
203 printLabels(ax, xlabel, ylabel, title)
202
204
203 z = numpy.ma.masked_invalid(z)
205 z = numpy.ma.masked_invalid(z)
204 cmap=matplotlib.pyplot.get_cmap(colormap)
206 cmap=matplotlib.pyplot.get_cmap(colormap)
205 cmap.set_bad('white',1.)
207 cmap.set_bad('white', 1.)
206 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
207 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
208 cb.set_label(cblabel)
210 cb.set_label(cblabel)
209
211
210 # for tl in ax_cb.get_yticklabels():
212 # for tl in ax_cb.get_yticklabels():
211 # tl.set_visible(True)
213 # tl.set_visible(True)
212
214
213 for tick in ax.yaxis.get_major_ticks():
215 for tick in ax.yaxis.get_major_ticks():
214 tick.label.set_fontsize(ticksize)
216 tick.label.set_fontsize(ticksize)
215
217
216 for tick in ax.xaxis.get_major_ticks():
218 for tick in ax.xaxis.get_major_ticks():
217 tick.label.set_fontsize(ticksize)
219 tick.label.set_fontsize(ticksize)
218
220
219 for tick in cb.ax.get_yticklabels():
221 for tick in cb.ax.get_yticklabels():
220 tick.set_fontsize(ticksize)
222 tick.set_fontsize(ticksize)
221
223
222 ax_cb.yaxis.tick_right()
224 ax_cb.yaxis.tick_right()
223
225
224 if '0.' in matplotlib.__version__[0:2]:
226 if '0.' in matplotlib.__version__[0:2]:
225 print "The matplotlib version has to be updated to 1.1 or newer"
227 print "The matplotlib version has to be updated to 1.1 or newer"
226 return imesh
228 return imesh
227
229
228 if '1.0.' in matplotlib.__version__[0:4]:
230 if '1.0.' in matplotlib.__version__[0:4]:
229 print "The matplotlib version has to be updated to 1.1 or newer"
231 print "The matplotlib version has to be updated to 1.1 or newer"
230 return imesh
232 return imesh
231
233
232 matplotlib.pyplot.tight_layout()
234 matplotlib.pyplot.tight_layout()
233
235
234 if XAxisAsTime:
236 if XAxisAsTime:
235
237
236 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
238 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
237 ax.xaxis.set_major_formatter(FuncFormatter(func))
239 ax.xaxis.set_major_formatter(FuncFormatter(func))
238 ax.xaxis.set_major_locator(LinearLocator(7))
240 ax.xaxis.set_major_locator(LinearLocator(7))
239
241
240 matplotlib.pyplot.ion()
242 matplotlib.pyplot.ion()
241 return imesh
243 return imesh
242
244
243 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
245 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
244
246
245 z = z.T
247 z = z.T
246 ax = imesh.get_axes()
248 ax = imesh.get_axes()
247 printLabels(ax, xlabel, ylabel, title)
249 printLabels(ax, xlabel, ylabel, title)
248 imesh.set_array(z.ravel())
250 imesh.set_array(z.ravel())
249
251
250 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
252 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
251
253
252 printLabels(ax, xlabel, ylabel, title)
254 printLabels(ax, xlabel, ylabel, title)
253
255
254 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
256 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
255
257
256 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
258 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
257
259
258 printLabels(ax, xlabel, ylabel, title)
260 printLabels(ax, xlabel, ylabel, title)
259
261
260 ax.collections.remove(ax.collections[0])
262 ax.collections.remove(ax.collections[0])
261
263
262 z = numpy.ma.masked_invalid(z)
264 z = numpy.ma.masked_invalid(z)
263
265
264 cmap=matplotlib.pyplot.get_cmap(colormap)
266 cmap=matplotlib.pyplot.get_cmap(colormap)
265 cmap.set_bad('white',1.)
267 cmap.set_bad('white', 1.)
266
268
267
269
268 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
269
271
270 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
272 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
271 ticksize=9, xtick_visible=True, ytick_visible=True,
273 ticksize=9, xtick_visible=True, ytick_visible=True,
272 nxticks=4, nyticks=10,
274 nxticks=4, nyticks=10,
273 grid=None):
275 grid=None):
274
276
275 """
277 """
276
278
277 Input:
279 Input:
278 grid : None, 'both', 'x', 'y'
280 grid : None, 'both', 'x', 'y'
279 """
281 """
280
282
281 matplotlib.pyplot.ioff()
283 matplotlib.pyplot.ioff()
282
284
283 lines = ax.plot(x.T, y)
285 lines = ax.plot(x.T, y)
284 leg = ax.legend(lines, legendlabels, loc='upper right')
286 leg = ax.legend(lines, legendlabels, loc='upper right')
285 leg.get_frame().set_alpha(0.5)
287 leg.get_frame().set_alpha(0.5)
286 ax.set_xlim([xmin,xmax])
288 ax.set_xlim([xmin,xmax])
287 ax.set_ylim([ymin,ymax])
289 ax.set_ylim([ymin,ymax])
288 printLabels(ax, xlabel, ylabel, title)
290 printLabels(ax, xlabel, ylabel, title)
289
291
290 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
292 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
291 ax.set_xticks(xtickspos)
293 ax.set_xticks(xtickspos)
292
294
293 for tick in ax.get_xticklabels():
295 for tick in ax.get_xticklabels():
294 tick.set_visible(xtick_visible)
296 tick.set_visible(xtick_visible)
295
297
296 for tick in ax.xaxis.get_major_ticks():
298 for tick in ax.xaxis.get_major_ticks():
297 tick.label.set_fontsize(ticksize)
299 tick.label.set_fontsize(ticksize)
298
300
299 for tick in ax.get_yticklabels():
301 for tick in ax.get_yticklabels():
300 tick.set_visible(ytick_visible)
302 tick.set_visible(ytick_visible)
301
303
302 for tick in ax.yaxis.get_major_ticks():
304 for tick in ax.yaxis.get_major_ticks():
303 tick.label.set_fontsize(ticksize)
305 tick.label.set_fontsize(ticksize)
304
306
305 iplot = ax.lines[-1]
307 iplot = ax.lines[-1]
306
308
307 if '0.' in matplotlib.__version__[0:2]:
309 if '0.' in matplotlib.__version__[0:2]:
308 print "The matplotlib version has to be updated to 1.1 or newer"
310 print "The matplotlib version has to be updated to 1.1 or newer"
309 return iplot
311 return iplot
310
312
311 if '1.0.' in matplotlib.__version__[0:4]:
313 if '1.0.' in matplotlib.__version__[0:4]:
312 print "The matplotlib version has to be updated to 1.1 or newer"
314 print "The matplotlib version has to be updated to 1.1 or newer"
313 return iplot
315 return iplot
314
316
315 if grid != None:
317 if grid != None:
316 ax.grid(b=True, which='major', axis=grid)
318 ax.grid(b=True, which='major', axis=grid)
317
319
318 matplotlib.pyplot.tight_layout()
320 matplotlib.pyplot.tight_layout()
319
321
320 matplotlib.pyplot.ion()
322 matplotlib.pyplot.ion()
321
323
322 return iplot
324 return iplot
323
325
324
326
325 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
327 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
326
328
327 ax = iplot.get_axes()
329 ax = iplot.get_axes()
328
330
329 printLabels(ax, xlabel, ylabel, title)
331 printLabels(ax, xlabel, ylabel, title)
330
332
331 for i in range(len(ax.lines)):
333 for i in range(len(ax.lines)):
332 line = ax.lines[i]
334 line = ax.lines[i]
333 line.set_data(x[i,:],y)
335 line.set_data(x[i,:],y)
334
336
335 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
337 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
336 ticksize=9, xtick_visible=True, ytick_visible=True,
338 ticksize=9, xtick_visible=True, ytick_visible=True,
337 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
339 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
338 grid=None, XAxisAsTime=False):
340 grid=None, XAxisAsTime=False):
339
341
340 """
342 """
341
343
342 Input:
344 Input:
343 grid : None, 'both', 'x', 'y'
345 grid : None, 'both', 'x', 'y'
344 """
346 """
345
347
346 matplotlib.pyplot.ioff()
348 matplotlib.pyplot.ioff()
347
349
348 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
350 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
349 lines = ax.plot(x, y.T)
351 lines = ax.plot(x, y.T)
350 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
352 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
351 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
353 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
352
354
353 leg = ax.legend(lines, legendlabels,
355 leg = ax.legend(lines, legendlabels,
354 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
356 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
355
357
356 for label in leg.get_texts(): label.set_fontsize(9)
358 for label in leg.get_texts(): label.set_fontsize(9)
357
359
358 ax.set_xlim([xmin,xmax])
360 ax.set_xlim([xmin,xmax])
359 ax.set_ylim([ymin,ymax])
361 ax.set_ylim([ymin,ymax])
360 printLabels(ax, xlabel, ylabel, title)
362 printLabels(ax, xlabel, ylabel, title)
361
363
362 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
364 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
363 # ax.set_xticks(xtickspos)
365 # ax.set_xticks(xtickspos)
364
366
365 for tick in ax.get_xticklabels():
367 for tick in ax.get_xticklabels():
366 tick.set_visible(xtick_visible)
368 tick.set_visible(xtick_visible)
367
369
368 for tick in ax.xaxis.get_major_ticks():
370 for tick in ax.xaxis.get_major_ticks():
369 tick.label.set_fontsize(ticksize)
371 tick.label.set_fontsize(ticksize)
370
372
371 for tick in ax.get_yticklabels():
373 for tick in ax.get_yticklabels():
372 tick.set_visible(ytick_visible)
374 tick.set_visible(ytick_visible)
373
375
374 for tick in ax.yaxis.get_major_ticks():
376 for tick in ax.yaxis.get_major_ticks():
375 tick.label.set_fontsize(ticksize)
377 tick.label.set_fontsize(ticksize)
376
378
377 iplot = ax.lines[-1]
379 iplot = ax.lines[-1]
378
380
379 if '0.' in matplotlib.__version__[0:2]:
381 if '0.' in matplotlib.__version__[0:2]:
380 print "The matplotlib version has to be updated to 1.1 or newer"
382 print "The matplotlib version has to be updated to 1.1 or newer"
381 return iplot
383 return iplot
382
384
383 if '1.0.' in matplotlib.__version__[0:4]:
385 if '1.0.' in matplotlib.__version__[0:4]:
384 print "The matplotlib version has to be updated to 1.1 or newer"
386 print "The matplotlib version has to be updated to 1.1 or newer"
385 return iplot
387 return iplot
386
388
387 if grid != None:
389 if grid != None:
388 ax.grid(b=True, which='major', axis=grid)
390 ax.grid(b=True, which='major', axis=grid)
389
391
390 matplotlib.pyplot.tight_layout()
392 matplotlib.pyplot.tight_layout()
391
393
392 if XAxisAsTime:
394 if XAxisAsTime:
393
395
394 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
396 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
395 ax.xaxis.set_major_formatter(FuncFormatter(func))
397 ax.xaxis.set_major_formatter(FuncFormatter(func))
396 ax.xaxis.set_major_locator(LinearLocator(7))
398 ax.xaxis.set_major_locator(LinearLocator(7))
397
399
398 matplotlib.pyplot.ion()
400 matplotlib.pyplot.ion()
399
401
400 return iplot
402 return iplot
401
403
402 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
404 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
403
405
404 ax = iplot.get_axes()
406 ax = iplot.get_axes()
405
407
406 printLabels(ax, xlabel, ylabel, title)
408 printLabels(ax, xlabel, ylabel, title)
407
409
408 for i in range(len(ax.lines)):
410 for i in range(len(ax.lines)):
409 line = ax.lines[i]
411 line = ax.lines[i]
410 line.set_data(x,y[i,:])
412 line.set_data(x,y[i,:])
411
413
412 def createPolar(ax, x, y,
414 def createPolar(ax, x, y,
413 xlabel='', ylabel='', title='', ticksize = 9,
415 xlabel='', ylabel='', title='', ticksize = 9,
414 colormap='jet',cblabel='', cbsize="5%",
416 colormap='jet',cblabel='', cbsize="5%",
415 XAxisAsTime=False):
417 XAxisAsTime=False):
416
418
417 matplotlib.pyplot.ioff()
419 matplotlib.pyplot.ioff()
418
420
419 ax.plot(x,y,'bo', markersize=5)
421 ax.plot(x,y,'bo', markersize=5)
420 # ax.set_rmax(90)
422 # ax.set_rmax(90)
421 ax.set_ylim(0,90)
423 ax.set_ylim(0,90)
422 ax.set_yticks(numpy.arange(0,90,20))
424 ax.set_yticks(numpy.arange(0,90,20))
423 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
424 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
426 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
425 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
427 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
426 ax.yaxis.labelpad = 230
428 ax.yaxis.labelpad = 230
427 printLabels(ax, xlabel, ylabel, title)
429 printLabels(ax, xlabel, ylabel, title)
428 iplot = ax.lines[-1]
430 iplot = ax.lines[-1]
429
431
430 if '0.' in matplotlib.__version__[0:2]:
432 if '0.' in matplotlib.__version__[0:2]:
431 print "The matplotlib version has to be updated to 1.1 or newer"
433 print "The matplotlib version has to be updated to 1.1 or newer"
432 return iplot
434 return iplot
433
435
434 if '1.0.' in matplotlib.__version__[0:4]:
436 if '1.0.' in matplotlib.__version__[0:4]:
435 print "The matplotlib version has to be updated to 1.1 or newer"
437 print "The matplotlib version has to be updated to 1.1 or newer"
436 return iplot
438 return iplot
437
439
438 # if grid != None:
440 # if grid != None:
439 # ax.grid(b=True, which='major', axis=grid)
441 # ax.grid(b=True, which='major', axis=grid)
440
442
441 matplotlib.pyplot.tight_layout()
443 matplotlib.pyplot.tight_layout()
442
444
443 matplotlib.pyplot.ion()
445 matplotlib.pyplot.ion()
444
446
445
447
446 return iplot
448 return iplot
447
449
448 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
450 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
449
451
450 ax = iplot.get_axes()
452 ax = iplot.get_axes()
451
453
452 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
454 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
453 printLabels(ax, xlabel, ylabel, title)
455 printLabels(ax, xlabel, ylabel, title)
454
456
455 set_linedata(ax, x, y, idline=0)
457 set_linedata(ax, x, y, idline=0)
456
458
457 def draw(fig):
459 def draw(fig):
458
460
459 if type(fig) == 'int':
461 if type(fig) == 'int':
460 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
462 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
461
463
462 fig.canvas.draw()
464 fig.canvas.draw()
463
465
464 def pause(interval=0.000001):
466 def pause(interval=0.000001):
465
467
466 matplotlib.pyplot.pause(interval)
468 matplotlib.pyplot.pause(interval)
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -1,1092 +1,1029
1 import numpy
1 import numpy
2 import time
2 import time
3 import os
3 import os
4 import h5py
4 import h5py
5 import re
5 import re
6 import datetime
6 import datetime
7
7
8 from schainpy.model.data.jrodata import *
8 from schainpy.model.data.jrodata import *
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 # from jroIO_base import *
10 # from jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
12 import schainpy
12 import schainpy
13
13
14
14
15 class ParamReader(ProcessingUnit):
15 class ParamReader(ProcessingUnit):
16 '''
16 '''
17 Reads HDF5 format files
17 Reads HDF5 format files
18
18
19 path
19 path
20
20
21 startDate
21 startDate
22
22
23 endDate
23 endDate
24
24
25 startTime
25 startTime
26
26
27 endTime
27 endTime
28 '''
28 '''
29
29
30 ext = ".hdf5"
30 ext = ".hdf5"
31
31
32 optchar = "D"
32 optchar = "D"
33
33
34 timezone = None
34 timezone = None
35
35
36 startTime = None
36 startTime = None
37
37
38 endTime = None
38 endTime = None
39
39
40 fileIndex = None
40 fileIndex = None
41
41
42 utcList = None #To select data in the utctime list
42 utcList = None #To select data in the utctime list
43
43
44 blockList = None #List to blocks to be read from the file
44 blockList = None #List to blocks to be read from the file
45
45
46 blocksPerFile = None #Number of blocks to be read
46 blocksPerFile = None #Number of blocks to be read
47
47
48 blockIndex = None
48 blockIndex = None
49
49
50 path = None
50 path = None
51
51
52 #List of Files
52 #List of Files
53
53
54 filenameList = None
54 filenameList = None
55
55
56 datetimeList = None
56 datetimeList = None
57
57
58 #Hdf5 File
58 #Hdf5 File
59
59
60 listMetaname = None
60 listMetaname = None
61
61
62 listMeta = None
62 listMeta = None
63
63
64 listDataname = None
64 listDataname = None
65
65
66 listData = None
66 listData = None
67
67
68 listShapes = None
68 listShapes = None
69
69
70 fp = None
70 fp = None
71
71
72 #dataOut reconstruction
72 #dataOut reconstruction
73
73
74 dataOut = None
74 dataOut = None
75
75
76
76
77 def __init__(self):
77 def __init__(self):
78 self.dataOut = Parameters()
78 self.dataOut = Parameters()
79 return
79 return
80
80
81 def setup(self, **kwargs):
81 def setup(self, **kwargs):
82
82
83 path = kwargs['path']
83 path = kwargs['path']
84 startDate = kwargs['startDate']
84 startDate = kwargs['startDate']
85 endDate = kwargs['endDate']
85 endDate = kwargs['endDate']
86 startTime = kwargs['startTime']
86 startTime = kwargs['startTime']
87 endTime = kwargs['endTime']
87 endTime = kwargs['endTime']
88 walk = kwargs['walk']
88 walk = kwargs['walk']
89 if kwargs.has_key('ext'):
89 if kwargs.has_key('ext'):
90 ext = kwargs['ext']
90 ext = kwargs['ext']
91 else:
91 else:
92 ext = '.hdf5'
92 ext = '.hdf5'
93 if kwargs.has_key('timezone'):
93 if kwargs.has_key('timezone'):
94 self.timezone = kwargs['timezone']
94 self.timezone = kwargs['timezone']
95 else:
95 else:
96 self.timezone = 'lt'
96 self.timezone = 'lt'
97
97
98 print "[Reading] Searching files in offline mode ..."
98 print "[Reading] Searching files in offline mode ..."
99 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
99 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
100 startTime=startTime, endTime=endTime,
100 startTime=startTime, endTime=endTime,
101 ext=ext, walk=walk)
101 ext=ext, walk=walk)
102
102
103 if not(filenameList):
103 if not(filenameList):
104 print "There is no files into the folder: %s"%(path)
104 print "There is no files into the folder: %s"%(path)
105 sys.exit(-1)
105 sys.exit(-1)
106
106
107 self.fileIndex = -1
107 self.fileIndex = -1
108 self.startTime = startTime
108 self.startTime = startTime
109 self.endTime = endTime
109 self.endTime = endTime
110
110
111 self.__readMetadata()
111 self.__readMetadata()
112
112
113 self.__setNextFileOffline()
113 self.__setNextFileOffline()
114
114
115 return
115 return
116
116
117 def __searchFilesOffLine(self,
117 def __searchFilesOffLine(self,
118 path,
118 path,
119 startDate=None,
119 startDate=None,
120 endDate=None,
120 endDate=None,
121 startTime=datetime.time(0,0,0),
121 startTime=datetime.time(0,0,0),
122 endTime=datetime.time(23,59,59),
122 endTime=datetime.time(23,59,59),
123 ext='.hdf5',
123 ext='.hdf5',
124 walk=True):
124 walk=True):
125
125
126 expLabel = ''
126 expLabel = ''
127 self.filenameList = []
127 self.filenameList = []
128 self.datetimeList = []
128 self.datetimeList = []
129
129
130 pathList = []
130 pathList = []
131
131
132 JRODataObj = JRODataReader()
132 JRODataObj = JRODataReader()
133 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
133 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
134
134
135 if dateList == []:
135 if dateList == []:
136 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
136 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
137 datetime.datetime.combine(startDate,startTime).ctime(),
137 datetime.datetime.combine(startDate,startTime).ctime(),
138 datetime.datetime.combine(endDate,endTime).ctime())
138 datetime.datetime.combine(endDate,endTime).ctime())
139
139
140 return None, None
140 return None, None
141
141
142 if len(dateList) > 1:
142 if len(dateList) > 1:
143 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
143 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
144 else:
144 else:
145 print "[Reading] data was found for the date %s" %(dateList[0])
145 print "[Reading] data was found for the date %s" %(dateList[0])
146
146
147 filenameList = []
147 filenameList = []
148 datetimeList = []
148 datetimeList = []
149
149
150 #----------------------------------------------------------------------------------
150 #----------------------------------------------------------------------------------
151
151
152 for thisPath in pathList:
152 for thisPath in pathList:
153 # thisPath = pathList[pathDict[file]]
153 # thisPath = pathList[pathDict[file]]
154
154
155 fileList = glob.glob1(thisPath, "*%s" %ext)
155 fileList = glob.glob1(thisPath, "*%s" %ext)
156 fileList.sort()
156 fileList.sort()
157
157
158 for file in fileList:
158 for file in fileList:
159
159
160 filename = os.path.join(thisPath,file)
160 filename = os.path.join(thisPath,file)
161
161
162 if not isFileInDateRange(filename, startDate, endDate):
162 if not isFileInDateRange(filename, startDate, endDate):
163 continue
163 continue
164
164
165 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
165 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
166
166
167 if not(thisDatetime):
167 if not(thisDatetime):
168 continue
168 continue
169
169
170 filenameList.append(filename)
170 filenameList.append(filename)
171 datetimeList.append(thisDatetime)
171 datetimeList.append(thisDatetime)
172
172
173 if not(filenameList):
173 if not(filenameList):
174 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
174 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
175 return None, None
175 return None, None
176
176
177 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
177 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
178 print
178 print
179
179
180 for i in range(len(filenameList)):
180 for i in range(len(filenameList)):
181 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
181 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
182
182
183 self.filenameList = filenameList
183 self.filenameList = filenameList
184 self.datetimeList = datetimeList
184 self.datetimeList = datetimeList
185
185
186 return pathList, filenameList
186 return pathList, filenameList
187
187
188 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
188 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
189
189
190 """
190 """
191 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
191 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
192
192
193 Inputs:
193 Inputs:
194 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
194 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
195
195
196 startDate : fecha inicial del rango seleccionado en formato datetime.date
196 startDate : fecha inicial del rango seleccionado en formato datetime.date
197
197
198 endDate : fecha final del rango seleccionado en formato datetime.date
198 endDate : fecha final del rango seleccionado en formato datetime.date
199
199
200 startTime : tiempo inicial del rango seleccionado en formato datetime.time
200 startTime : tiempo inicial del rango seleccionado en formato datetime.time
201
201
202 endTime : tiempo final del rango seleccionado en formato datetime.time
202 endTime : tiempo final del rango seleccionado en formato datetime.time
203
203
204 Return:
204 Return:
205 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
205 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
206 fecha especificado, de lo contrario retorna False.
206 fecha especificado, de lo contrario retorna False.
207
207
208 Excepciones:
208 Excepciones:
209 Si el archivo no existe o no puede ser abierto
209 Si el archivo no existe o no puede ser abierto
210 Si la cabecera no puede ser leida.
210 Si la cabecera no puede ser leida.
211
211
212 """
212 """
213
213
214 try:
214 try:
215 fp = h5py.File(filename,'r')
215 fp = h5py.File(filename,'r')
216 grp1 = fp['Data']
216 grp1 = fp['Data']
217
217
218 except IOError:
218 except IOError:
219 traceback.print_exc()
219 traceback.print_exc()
220 raise IOError, "The file %s can't be opened" %(filename)
220 raise IOError, "The file %s can't be opened" %(filename)
221 #chino rata
221 #chino rata
222 #In case has utctime attribute
222 #In case has utctime attribute
223 grp2 = grp1['utctime']
223 grp2 = grp1['utctime']
224 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
224 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
225 thisUtcTime = grp2.value[0]
225 thisUtcTime = grp2.value[0]
226
226
227 fp.close()
227 fp.close()
228
228
229 if self.timezone == 'lt':
229 if self.timezone == 'lt':
230 thisUtcTime -= 5*3600
230 thisUtcTime -= 5*3600
231
231
232 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
232 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
233 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
233 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
234 thisDate = thisDatetime.date()
234 thisDate = thisDatetime.date()
235 thisTime = thisDatetime.time()
235 thisTime = thisDatetime.time()
236
236
237 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
237 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
238 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
238 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239
239
240 #General case
240 #General case
241 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
241 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
242 #-----------o----------------------------o-----------
242 #-----------o----------------------------o-----------
243 # startTime endTime
243 # startTime endTime
244
244
245 if endTime >= startTime:
245 if endTime >= startTime:
246 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
246 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
247 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
247 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
248 return thisDatetime
248 return thisDatetime
249 return None
249 return None
250
250
251 #If endTime < startTime then endTime belongs to the next day
251 #If endTime < startTime then endTime belongs to the next day
252 #<<<<<<<<<<<o o>>>>>>>>>>>
252 #<<<<<<<<<<<o o>>>>>>>>>>>
253 #-----------o----------------------------o-----------
253 #-----------o----------------------------o-----------
254 # endTime startTime
254 # endTime startTime
255
255
256 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
256 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
257 return None
257 return None
258
258
259 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
259 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
260 return None
260 return None
261
261
262 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
262 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
263 return None
263 return None
264
264
265 return thisDatetime
265 return thisDatetime
266
266
267 def __setNextFileOffline(self):
267 def __setNextFileOffline(self):
268
268
269 self.fileIndex += 1
269 self.fileIndex += 1
270 idFile = self.fileIndex
270 idFile = self.fileIndex
271
271
272 if not(idFile < len(self.filenameList)):
272 if not(idFile < len(self.filenameList)):
273 print "No more Files"
273 print "No more Files"
274 return 0
274 return 0
275
275
276 filename = self.filenameList[idFile]
276 filename = self.filenameList[idFile]
277
277
278 filePointer = h5py.File(filename,'r')
278 filePointer = h5py.File(filename,'r')
279
279
280 self.filename = filename
280 self.filename = filename
281
281
282 self.fp = filePointer
282 self.fp = filePointer
283
283
284 print "Setting the file: %s"%self.filename
284 print "Setting the file: %s"%self.filename
285
285
286 # self.__readMetadata()
286 # self.__readMetadata()
287 self.__setBlockList()
287 self.__setBlockList()
288 self.__readData()
288 self.__readData()
289 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
289 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
290 # self.nRecords = self.fp['Data'].attrs['nRecords']
290 # self.nRecords = self.fp['Data'].attrs['nRecords']
291 self.blockIndex = 0
291 self.blockIndex = 0
292 return 1
292 return 1
293
293
294 def __setBlockList(self):
294 def __setBlockList(self):
295 '''
295 '''
296 Selects the data within the times defined
296 Selects the data within the times defined
297
297
298 self.fp
298 self.fp
299 self.startTime
299 self.startTime
300 self.endTime
300 self.endTime
301
301
302 self.blockList
302 self.blockList
303 self.blocksPerFile
303 self.blocksPerFile
304
304
305 '''
305 '''
306 fp = self.fp
306 fp = self.fp
307 startTime = self.startTime
307 startTime = self.startTime
308 endTime = self.endTime
308 endTime = self.endTime
309
309
310 grp = fp['Data']
310 grp = fp['Data']
311 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
311 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
312
312
313 #ERROOOOR
313 #ERROOOOR
314 if self.timezone == 'lt':
314 if self.timezone == 'lt':
315 thisUtcTime -= 5*3600
315 thisUtcTime -= 5*3600
316
316
317 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
317 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
318
318
319 thisDate = thisDatetime.date()
319 thisDate = thisDatetime.date()
320 thisTime = thisDatetime.time()
320 thisTime = thisDatetime.time()
321
321
322 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
322 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
323 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
323 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324
324
325 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
325 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
326
326
327 self.blockList = ind
327 self.blockList = ind
328 self.blocksPerFile = len(ind)
328 self.blocksPerFile = len(ind)
329
329
330 return
330 return
331
331
332 def __readMetadata(self):
332 def __readMetadata(self):
333 '''
333 '''
334 Reads Metadata
334 Reads Metadata
335
335
336 self.pathMeta
336 self.pathMeta
337
337
338 self.listShapes
338 self.listShapes
339 self.listMetaname
339 self.listMetaname
340 self.listMeta
340 self.listMeta
341
341
342 '''
342 '''
343
343
344 # grp = self.fp['Data']
344 # grp = self.fp['Data']
345 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
345 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
346 #
346 #
347 # if pathMeta == self.pathMeta:
347 # if pathMeta == self.pathMeta:
348 # return
348 # return
349 # else:
349 # else:
350 # self.pathMeta = pathMeta
350 # self.pathMeta = pathMeta
351 #
351 #
352 # filePointer = h5py.File(self.pathMeta,'r')
352 # filePointer = h5py.File(self.pathMeta,'r')
353 # groupPointer = filePointer['Metadata']
353 # groupPointer = filePointer['Metadata']
354
354
355 filename = self.filenameList[0]
355 filename = self.filenameList[0]
356
356
357 fp = h5py.File(filename,'r')
357 fp = h5py.File(filename,'r')
358
358
359 gp = fp['Metadata']
359 gp = fp['Metadata']
360
360
361 listMetaname = []
361 listMetaname = []
362 listMetadata = []
362 listMetadata = []
363 for item in gp.items():
363 for item in gp.items():
364 name = item[0]
364 name = item[0]
365
365
366 if name=='array dimensions':
366 if name=='array dimensions':
367 table = gp[name][:]
367 table = gp[name][:]
368 listShapes = {}
368 listShapes = {}
369 for shapes in table:
369 for shapes in table:
370 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
370 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
371 else:
371 else:
372 data = gp[name].value
372 data = gp[name].value
373 listMetaname.append(name)
373 listMetaname.append(name)
374 listMetadata.append(data)
374 listMetadata.append(data)
375
375
376 # if name=='type':
376 # if name=='type':
377 # self.__initDataOut(data)
377 # self.__initDataOut(data)
378
378
379 self.listShapes = listShapes
379 self.listShapes = listShapes
380 self.listMetaname = listMetaname
380 self.listMetaname = listMetaname
381 self.listMeta = listMetadata
381 self.listMeta = listMetadata
382
382
383 fp.close()
383 fp.close()
384 return
384 return
385
385
386 def __readData(self):
386 def __readData(self):
387 grp = self.fp['Data']
387 grp = self.fp['Data']
388 listdataname = []
388 listdataname = []
389 listdata = []
389 listdata = []
390
390
391 for item in grp.items():
391 for item in grp.items():
392 name = item[0]
392 name = item[0]
393 listdataname.append(name)
393 listdataname.append(name)
394
394
395 array = self.__setDataArray(grp[name],self.listShapes[name])
395 array = self.__setDataArray(grp[name],self.listShapes[name])
396 listdata.append(array)
396 listdata.append(array)
397
397
398 self.listDataname = listdataname
398 self.listDataname = listdataname
399 self.listData = listdata
399 self.listData = listdata
400 return
400 return
401
401
402 def __setDataArray(self, dataset, shapes):
403
402
404 nDims = shapes[0]
405
406 nDim2 = shapes[1] #Dimension 0
407
408 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
409
410 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
411
412 mode = shapes[4] #Mode of storing
413
414 blockList = self.blockList
415
416 blocksPerFile = self.blocksPerFile
417
418 #Depending on what mode the data was stored
419 if mode == 0: #Divided in channels
420 arrayData = dataset.value.astype(numpy.float)[0][blockList]
421 if mode == 1: #Divided in parameter
422 strds = 'table'
423 nDatas = nDim1
424 newShapes = (blocksPerFile,nDim2,nDim0)
425 elif mode==2: #Concatenated in a table
426 strds = 'table0'
427 arrayData = dataset[strds].value
428 #Selecting part of the dataset
429 utctime = arrayData[:,0]
430 u, indices = numpy.unique(utctime, return_index=True)
431
432 if blockList.size != indices.size:
433 indMin = indices[blockList[0]]
434 if blockList[-1] + 1 >= indices.size:
435 arrayData = arrayData[indMin:,:]
436 else:
437 indMax = indices[blockList[-1] + 1]
438 arrayData = arrayData[indMin:indMax,:]
439 return arrayData
440
441 #------- One dimension ---------------
442 if nDims == 0:
443 arrayData = dataset.value.astype(numpy.float)[0][blockList]
444
445 #------- Two dimensions -----------
446 elif nDims == 2:
447 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
448 newShapes = (blocksPerFile,nDim0)
449 nDatas = nDim1
450
451 for i in range(nDatas):
452 data = dataset[strds + str(i)].value
453 arrayData[:,i,:] = data[blockList,:]
454
455 #------- Three dimensions ---------
456 else:
457 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
458 for i in range(nDatas):
459
460 data = dataset[strds + str(i)].value
461
462 for b in range(blockList.size):
463 arrayData[b,:,i,:] = data[:,:,blockList[b]]
464
465 return arrayData
466
403
467 def __setDataOut(self):
404 def __setDataOut(self):
468 listMeta = self.listMeta
405 listMeta = self.listMeta
469 listMetaname = self.listMetaname
406 listMetaname = self.listMetaname
470 listDataname = self.listDataname
407 listDataname = self.listDataname
471 listData = self.listData
408 listData = self.listData
472 listShapes = self.listShapes
409 listShapes = self.listShapes
473
410
474 blockIndex = self.blockIndex
411 blockIndex = self.blockIndex
475 # blockList = self.blockList
412 # blockList = self.blockList
476
413
477 for i in range(len(listMeta)):
414 for i in range(len(listMeta)):
478 setattr(self.dataOut,listMetaname[i],listMeta[i])
415 setattr(self.dataOut,listMetaname[i],listMeta[i])
479
416
480 for j in range(len(listData)):
417 for j in range(len(listData)):
481 nShapes = listShapes[listDataname[j]][0]
418 nShapes = listShapes[listDataname[j]][0]
482 mode = listShapes[listDataname[j]][4]
419 mode = listShapes[listDataname[j]][4]
483 if nShapes == 1:
420 if nShapes == 1:
484 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
421 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
485 elif nShapes > 1:
422 elif nShapes > 1:
486 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
423 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
487 elif mode==0:
424 elif mode==0:
488 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
425 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
489 #Mode Meteors
426 #Mode Meteors
490 elif mode ==2:
427 elif mode ==2:
491 selectedData = self.__selectDataMode2(listData[j], blockIndex)
428 selectedData = self.__selectDataMode2(listData[j], blockIndex)
492 setattr(self.dataOut, listDataname[j], selectedData)
429 setattr(self.dataOut, listDataname[j], selectedData)
493 return
430 return
494
431
495 def __selectDataMode2(self, data, blockIndex):
432 def __selectDataMode2(self, data, blockIndex):
496 utctime = data[:,0]
433 utctime = data[:,0]
497 aux, indices = numpy.unique(utctime, return_inverse=True)
434 aux, indices = numpy.unique(utctime, return_inverse=True)
498 selInd = numpy.where(indices == blockIndex)[0]
435 selInd = numpy.where(indices == blockIndex)[0]
499 selData = data[selInd,:]
436 selData = data[selInd,:]
500
437
501 return selData
438 return selData
502
439
503 def getData(self):
440 def getData(self):
504
441
505 # if self.flagNoMoreFiles:
442 # if self.flagNoMoreFiles:
506 # self.dataOut.flagNoData = True
443 # self.dataOut.flagNoData = True
507 # print 'Process finished'
444 # print 'Process finished'
508 # return 0
445 # return 0
509 #
446 #
510 if self.blockIndex==self.blocksPerFile:
447 if self.blockIndex==self.blocksPerFile:
511 if not( self.__setNextFileOffline() ):
448 if not( self.__setNextFileOffline() ):
512 self.dataOut.flagNoData = True
449 self.dataOut.flagNoData = True
513 return 0
450 return 0
514
451
515 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
452 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
516 # self.dataOut.flagNoData = True
453 # self.dataOut.flagNoData = True
517 # return 0
454 # return 0
518 # self.__readData()
455 # self.__readData()
519 self.__setDataOut()
456 self.__setDataOut()
520 self.dataOut.flagNoData = False
457 self.dataOut.flagNoData = False
521
458
522 self.blockIndex += 1
459 self.blockIndex += 1
523
460
524 return
461 return
525
462
526 def run(self, **kwargs):
463 def run(self, **kwargs):
527
464
528 if not(self.isConfig):
465 if not(self.isConfig):
529 self.setup(**kwargs)
466 self.setup(**kwargs)
530 # self.setObjProperties()
467 # self.setObjProperties()
531 self.isConfig = True
468 self.isConfig = True
532
469
533 self.getData()
470 self.getData()
534
471
535 return
472 return
536
473
537 class ParamWriter(Operation):
474 class ParamWriter(Operation):
538 '''
475 '''
539 HDF5 Writer, stores parameters data in HDF5 format files
476 HDF5 Writer, stores parameters data in HDF5 format files
540
477
541 path: path where the files will be stored
478 path: path where the files will be stored
542
479
543 blocksPerFile: number of blocks that will be saved in per HDF5 format file
480 blocksPerFile: number of blocks that will be saved in per HDF5 format file
544
481
545 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
482 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
546
483
547 metadataList: list of attributes that will be stored as metadata
484 metadataList: list of attributes that will be stored as metadata
548
485
549 dataList: list of attributes that will be stores as data
486 dataList: list of attributes that will be stores as data
550
487
551 '''
488 '''
552
489
553
490
554 ext = ".hdf5"
491 ext = ".hdf5"
555
492
556 optchar = "D"
493 optchar = "D"
557
494
558 metaoptchar = "M"
495 metaoptchar = "M"
559
496
560 metaFile = None
497 metaFile = None
561
498
562 filename = None
499 filename = None
563
500
564 path = None
501 path = None
565
502
566 setFile = None
503 setFile = None
567
504
568 fp = None
505 fp = None
569
506
570 grp = None
507 grp = None
571
508
572 ds = None
509 ds = None
573
510
574 firsttime = True
511 firsttime = True
575
512
576 #Configurations
513 #Configurations
577
514
578 blocksPerFile = None
515 blocksPerFile = None
579
516
580 blockIndex = None
517 blockIndex = None
581
518
582 dataOut = None
519 dataOut = None
583
520
584 #Data Arrays
521 #Data Arrays
585
522
586 dataList = None
523 dataList = None
587
524
588 metadataList = None
525 metadataList = None
589
526
590 # arrayDim = None
527 # arrayDim = None
591
528
592 dsList = None #List of dictionaries with dataset properties
529 dsList = None #List of dictionaries with dataset properties
593
530
594 tableDim = None
531 tableDim = None
595
532
596 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
533 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
597
534
598 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
535 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
599
536
600 currentDay = None
537 currentDay = None
601
538
602 lastTime = None
539 lastTime = None
603
540
604 def __init__(self):
541 def __init__(self):
605
542
606 Operation.__init__(self)
543 Operation.__init__(self)
607 self.isConfig = False
544 self.isConfig = False
608 return
545 return
609
546
610 def setup(self, dataOut, **kwargs):
547 def setup(self, dataOut, **kwargs):
611
548
612 self.path = kwargs['path']
549 self.path = kwargs['path']
613
550
614 if kwargs.has_key('blocksPerFile'):
551 if kwargs.has_key('blocksPerFile'):
615 self.blocksPerFile = kwargs['blocksPerFile']
552 self.blocksPerFile = kwargs['blocksPerFile']
616 else:
553 else:
617 self.blocksPerFile = 10
554 self.blocksPerFile = 10
618
555
619 self.metadataList = kwargs['metadataList']
556 self.metadataList = kwargs['metadataList']
620 self.dataList = kwargs['dataList']
557 self.dataList = kwargs['dataList']
621 self.dataOut = dataOut
558 self.dataOut = dataOut
622
559
623 if kwargs.has_key('mode'):
560 if kwargs.has_key('mode'):
624 mode = kwargs['mode']
561 mode = kwargs['mode']
625
562
626 if type(mode) == int:
563 if type(mode) == int:
627 mode = numpy.zeros(len(self.dataList)) + mode
564 mode = numpy.zeros(len(self.dataList)) + mode
628 else:
565 else:
629 mode = numpy.ones(len(self.dataList))
566 mode = numpy.ones(len(self.dataList))
630
567
631 self.mode = mode
568 self.mode = mode
632
569
633 arrayDim = numpy.zeros((len(self.dataList),5))
570 arrayDim = numpy.zeros((len(self.dataList),5))
634
571
635 #Table dimensions
572 #Table dimensions
636 dtype0 = self.dtype
573 dtype0 = self.dtype
637 tableList = []
574 tableList = []
638
575
639 #Dictionary and list of tables
576 #Dictionary and list of tables
640 dsList = []
577 dsList = []
641
578
642 for i in range(len(self.dataList)):
579 for i in range(len(self.dataList)):
643 dsDict = {}
580 dsDict = {}
644 dataAux = getattr(self.dataOut, self.dataList[i])
581 dataAux = getattr(self.dataOut, self.dataList[i])
645 dsDict['variable'] = self.dataList[i]
582 dsDict['variable'] = self.dataList[i]
646 #--------------------- Conditionals ------------------------
583 #--------------------- Conditionals ------------------------
647 #There is no data
584 #There is no data
648 if dataAux == None:
585 if dataAux == None:
649 return 0
586 return 0
650
587
651 #Not array, just a number
588 #Not array, just a number
652 #Mode 0
589 #Mode 0
653 if type(dataAux)==float or type(dataAux)==int:
590 if type(dataAux)==float or type(dataAux)==int:
654 dsDict['mode'] = 0
591 dsDict['mode'] = 0
655 dsDict['nDim'] = 0
592 dsDict['nDim'] = 0
656 arrayDim[i,0] = 0
593 arrayDim[i,0] = 0
657 dsList.append(dsDict)
594 dsList.append(dsDict)
658
595
659 #Mode 2: meteors
596 #Mode 2: meteors
660 elif mode[i] == 2:
597 elif mode[i] == 2:
661 # dsDict['nDim'] = 0
598 # dsDict['nDim'] = 0
662 dsDict['dsName'] = 'table0'
599 dsDict['dsName'] = 'table0'
663 dsDict['mode'] = 2 # Mode meteors
600 dsDict['mode'] = 2 # Mode meteors
664 dsDict['shape'] = dataAux.shape[-1]
601 dsDict['shape'] = dataAux.shape[-1]
665 dsDict['nDim'] = 0
602 dsDict['nDim'] = 0
666 dsDict['dsNumber'] = 1
603 dsDict['dsNumber'] = 1
667
604
668 arrayDim[i,3] = dataAux.shape[-1]
605 arrayDim[i,3] = dataAux.shape[-1]
669 arrayDim[i,4] = mode[i] #Mode the data was stored
606 arrayDim[i,4] = mode[i] #Mode the data was stored
670
607
671 dsList.append(dsDict)
608 dsList.append(dsDict)
672
609
673 #Mode 1
610 #Mode 1
674 else:
611 else:
675 arrayDim0 = dataAux.shape #Data dimensions
612 arrayDim0 = dataAux.shape #Data dimensions
676 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
613 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
677 arrayDim[i,4] = mode[i] #Mode the data was stored
614 arrayDim[i,4] = mode[i] #Mode the data was stored
678
615
679 strtable = 'table'
616 strtable = 'table'
680 dsDict['mode'] = 1 # Mode parameters
617 dsDict['mode'] = 1 # Mode parameters
681
618
682 # Three-dimension arrays
619 # Three-dimension arrays
683 if len(arrayDim0) == 3:
620 if len(arrayDim0) == 3:
684 arrayDim[i,1:-1] = numpy.array(arrayDim0)
621 arrayDim[i,1:-1] = numpy.array(arrayDim0)
685 nTables = int(arrayDim[i,2])
622 nTables = int(arrayDim[i,2])
686 dsDict['dsNumber'] = nTables
623 dsDict['dsNumber'] = nTables
687 dsDict['shape'] = arrayDim[i,2:4]
624 dsDict['shape'] = arrayDim[i,2:4]
688 dsDict['nDim'] = 3
625 dsDict['nDim'] = 3
689
626
690 for j in range(nTables):
627 for j in range(nTables):
691 dsDict = dsDict.copy()
628 dsDict = dsDict.copy()
692 dsDict['dsName'] = strtable + str(j)
629 dsDict['dsName'] = strtable + str(j)
693 dsList.append(dsDict)
630 dsList.append(dsDict)
694
631
695 # Two-dimension arrays
632 # Two-dimension arrays
696 elif len(arrayDim0) == 2:
633 elif len(arrayDim0) == 2:
697 arrayDim[i,2:-1] = numpy.array(arrayDim0)
634 arrayDim[i,2:-1] = numpy.array(arrayDim0)
698 nTables = int(arrayDim[i,2])
635 nTables = int(arrayDim[i,2])
699 dsDict['dsNumber'] = nTables
636 dsDict['dsNumber'] = nTables
700 dsDict['shape'] = arrayDim[i,3]
637 dsDict['shape'] = arrayDim[i,3]
701 dsDict['nDim'] = 2
638 dsDict['nDim'] = 2
702
639
703 for j in range(nTables):
640 for j in range(nTables):
704 dsDict = dsDict.copy()
641 dsDict = dsDict.copy()
705 dsDict['dsName'] = strtable + str(j)
642 dsDict['dsName'] = strtable + str(j)
706 dsList.append(dsDict)
643 dsList.append(dsDict)
707
644
708 # One-dimension arrays
645 # One-dimension arrays
709 elif len(arrayDim0) == 1:
646 elif len(arrayDim0) == 1:
710 arrayDim[i,3] = arrayDim0[0]
647 arrayDim[i,3] = arrayDim0[0]
711 dsDict['shape'] = arrayDim0[0]
648 dsDict['shape'] = arrayDim0[0]
712 dsDict['dsNumber'] = 1
649 dsDict['dsNumber'] = 1
713 dsDict['dsName'] = strtable + str(0)
650 dsDict['dsName'] = strtable + str(0)
714 dsDict['nDim'] = 1
651 dsDict['nDim'] = 1
715 dsList.append(dsDict)
652 dsList.append(dsDict)
716
653
717 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
654 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
718 tableList.append(table)
655 tableList.append(table)
719
656
720 # self.arrayDim = arrayDim
657 # self.arrayDim = arrayDim
721 self.dsList = dsList
658 self.dsList = dsList
722 self.tableDim = numpy.array(tableList, dtype = dtype0)
659 self.tableDim = numpy.array(tableList, dtype = dtype0)
723 self.blockIndex = 0
660 self.blockIndex = 0
724
661
725 timeTuple = time.localtime(dataOut.utctime)
662 timeTuple = time.localtime(dataOut.utctime)
726 self.currentDay = timeTuple.tm_yday
663 self.currentDay = timeTuple.tm_yday
727 return 1
664 return 1
728
665
729 def putMetadata(self):
666 def putMetadata(self):
730
667
731 fp = self.createMetadataFile()
668 fp = self.createMetadataFile()
732 self.writeMetadata(fp)
669 self.writeMetadata(fp)
733 fp.close()
670 fp.close()
734 return
671 return
735
672
736 def createMetadataFile(self):
673 def createMetadataFile(self):
737 ext = self.ext
674 ext = self.ext
738 path = self.path
675 path = self.path
739 setFile = self.setFile
676 setFile = self.setFile
740
677
741 timeTuple = time.localtime(self.dataOut.utctime)
678 timeTuple = time.localtime(self.dataOut.utctime)
742
679
743 subfolder = ''
680 subfolder = ''
744 fullpath = os.path.join( path, subfolder )
681 fullpath = os.path.join( path, subfolder )
745
682
746 if not( os.path.exists(fullpath) ):
683 if not( os.path.exists(fullpath) ):
747 os.mkdir(fullpath)
684 os.mkdir(fullpath)
748 setFile = -1 #inicializo mi contador de seteo
685 setFile = -1 #inicializo mi contador de seteo
749
686
750 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
687 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
751 fullpath = os.path.join( path, subfolder )
688 fullpath = os.path.join( path, subfolder )
752
689
753 if not( os.path.exists(fullpath) ):
690 if not( os.path.exists(fullpath) ):
754 os.mkdir(fullpath)
691 os.mkdir(fullpath)
755 setFile = -1 #inicializo mi contador de seteo
692 setFile = -1 #inicializo mi contador de seteo
756
693
757 else:
694 else:
758 filesList = os.listdir( fullpath )
695 filesList = os.listdir( fullpath )
759 filesList = sorted( filesList, key=str.lower )
696 filesList = sorted( filesList, key=str.lower )
760 if len( filesList ) > 0:
697 if len( filesList ) > 0:
761 filesList = [k for k in filesList if 'M' in k]
698 filesList = [k for k in filesList if 'M' in k]
762 filen = filesList[-1]
699 filen = filesList[-1]
763 # el filename debera tener el siguiente formato
700 # el filename debera tener el siguiente formato
764 # 0 1234 567 89A BCDE (hex)
701 # 0 1234 567 89A BCDE (hex)
765 # x YYYY DDD SSS .ext
702 # x YYYY DDD SSS .ext
766 if isNumber( filen[8:11] ):
703 if isNumber( filen[8:11] ):
767 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
704 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
768 else:
705 else:
769 setFile = -1
706 setFile = -1
770 else:
707 else:
771 setFile = -1 #inicializo mi contador de seteo
708 setFile = -1 #inicializo mi contador de seteo
772
709
773 setFile += 1
710 setFile += 1
774
711
775 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
712 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
776 timeTuple.tm_year,
713 timeTuple.tm_year,
777 timeTuple.tm_yday,
714 timeTuple.tm_yday,
778 setFile,
715 setFile,
779 ext )
716 ext )
780
717
781 filename = os.path.join( path, subfolder, file )
718 filename = os.path.join( path, subfolder, file )
782 self.metaFile = file
719 self.metaFile = file
783 #Setting HDF5 File
720 #Setting HDF5 File
784 fp = h5py.File(filename,'w')
721 fp = h5py.File(filename,'w')
785
722
786 return fp
723 return fp
787
724
788 def writeMetadata(self, fp):
725 def writeMetadata(self, fp):
789
726
790 grp = fp.create_group("Metadata")
727 grp = fp.create_group("Metadata")
791 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
728 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
792
729
793 for i in range(len(self.metadataList)):
730 for i in range(len(self.metadataList)):
794 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
731 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
795 return
732 return
796
733
797 def timeFlag(self):
734 def timeFlag(self):
798 currentTime = self.dataOut.utctime
735 currentTime = self.dataOut.utctime
799
736
800 if self.lastTime is None:
737 if self.lastTime is None:
801 self.lastTime = currentTime
738 self.lastTime = currentTime
802
739
803 #Day
740 #Day
804 timeTuple = time.localtime(currentTime)
741 timeTuple = time.localtime(currentTime)
805 dataDay = timeTuple.tm_yday
742 dataDay = timeTuple.tm_yday
806
743
807 #Time
744 #Time
808 timeDiff = currentTime - self.lastTime
745 timeDiff = currentTime - self.lastTime
809
746
810 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
747 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
811 if dataDay != self.currentDay:
748 if dataDay != self.currentDay:
812 self.currentDay = dataDay
749 self.currentDay = dataDay
813 return True
750 return True
814 elif timeDiff > 3*60*60:
751 elif timeDiff > 3*60*60:
815 self.lastTime = currentTime
752 self.lastTime = currentTime
816 return True
753 return True
817 else:
754 else:
818 self.lastTime = currentTime
755 self.lastTime = currentTime
819 return False
756 return False
820
757
821 def setNextFile(self):
758 def setNextFile(self):
822
759
823 ext = self.ext
760 ext = self.ext
824 path = self.path
761 path = self.path
825 setFile = self.setFile
762 setFile = self.setFile
826 mode = self.mode
763 mode = self.mode
827
764
828 timeTuple = time.localtime(self.dataOut.utctime)
765 timeTuple = time.localtime(self.dataOut.utctime)
829 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
766 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
830
767
831 fullpath = os.path.join( path, subfolder )
768 fullpath = os.path.join( path, subfolder )
832
769
833 if os.path.exists(fullpath):
770 if os.path.exists(fullpath):
834 filesList = os.listdir( fullpath )
771 filesList = os.listdir( fullpath )
835 filesList = [k for k in filesList if 'D' in k]
772 filesList = [k for k in filesList if 'D' in k]
836 if len( filesList ) > 0:
773 if len( filesList ) > 0:
837 filesList = sorted( filesList, key=str.lower )
774 filesList = sorted( filesList, key=str.lower )
838 filen = filesList[-1]
775 filen = filesList[-1]
839 # el filename debera tener el siguiente formato
776 # el filename debera tener el siguiente formato
840 # 0 1234 567 89A BCDE (hex)
777 # 0 1234 567 89A BCDE (hex)
841 # x YYYY DDD SSS .ext
778 # x YYYY DDD SSS .ext
842 if isNumber( filen[8:11] ):
779 if isNumber( filen[8:11] ):
843 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
780 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
844 else:
781 else:
845 setFile = -1
782 setFile = -1
846 else:
783 else:
847 setFile = -1 #inicializo mi contador de seteo
784 setFile = -1 #inicializo mi contador de seteo
848 else:
785 else:
849 os.mkdir(fullpath)
786 os.mkdir(fullpath)
850 setFile = -1 #inicializo mi contador de seteo
787 setFile = -1 #inicializo mi contador de seteo
851
788
852 setFile += 1
789 setFile += 1
853
790
854 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
791 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
855 timeTuple.tm_year,
792 timeTuple.tm_year,
856 timeTuple.tm_yday,
793 timeTuple.tm_yday,
857 setFile,
794 setFile,
858 ext )
795 ext )
859
796
860 filename = os.path.join( path, subfolder, file )
797 filename = os.path.join( path, subfolder, file )
861
798
862 #Setting HDF5 File
799 #Setting HDF5 File
863 fp = h5py.File(filename,'w')
800 fp = h5py.File(filename,'w')
864 #write metadata
801 #write metadata
865 self.writeMetadata(fp)
802 self.writeMetadata(fp)
866 #Write data
803 #Write data
867 grp = fp.create_group("Data")
804 grp = fp.create_group("Data")
868 # grp.attrs['metadata'] = self.metaFile
805 # grp.attrs['metadata'] = self.metaFile
869
806
870 # grp.attrs['blocksPerFile'] = 0
807 # grp.attrs['blocksPerFile'] = 0
871 ds = []
808 ds = []
872 data = []
809 data = []
873 dsList = self.dsList
810 dsList = self.dsList
874 i = 0
811 i = 0
875 while i < len(dsList):
812 while i < len(dsList):
876 dsInfo = dsList[i]
813 dsInfo = dsList[i]
877 #One-dimension data
814 #One-dimension data
878 if dsInfo['mode'] == 0:
815 if dsInfo['mode'] == 0:
879 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
816 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
880 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
817 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
881 ds.append(ds0)
818 ds.append(ds0)
882 data.append([])
819 data.append([])
883 i += 1
820 i += 1
884 continue
821 continue
885 # nDimsForDs.append(nDims[i])
822 # nDimsForDs.append(nDims[i])
886
823
887 elif dsInfo['mode'] == 2:
824 elif dsInfo['mode'] == 2:
888 grp0 = grp.create_group(dsInfo['variable'])
825 grp0 = grp.create_group(dsInfo['variable'])
889 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
826 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
890 ds.append(ds0)
827 ds.append(ds0)
891 data.append([])
828 data.append([])
892 i += 1
829 i += 1
893 continue
830 continue
894
831
895 elif dsInfo['mode'] == 1:
832 elif dsInfo['mode'] == 1:
896 grp0 = grp.create_group(dsInfo['variable'])
833 grp0 = grp.create_group(dsInfo['variable'])
897
834
898 for j in range(dsInfo['dsNumber']):
835 for j in range(dsInfo['dsNumber']):
899 dsInfo = dsList[i]
836 dsInfo = dsList[i]
900 tableName = dsInfo['dsName']
837 tableName = dsInfo['dsName']
901 shape = dsInfo['shape']
838 shape = dsInfo['shape']
902
839
903 if dsInfo['nDim'] == 3:
840 if dsInfo['nDim'] == 3:
904 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
841 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
905 else:
842 else:
906 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
843 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
907
844
908 ds.append(ds0)
845 ds.append(ds0)
909 data.append([])
846 data.append([])
910 i += 1
847 i += 1
911 # nDimsForDs.append(nDims[i])
848 # nDimsForDs.append(nDims[i])
912
849
913 fp.flush()
850 fp.flush()
914 fp.close()
851 fp.close()
915
852
916 # self.nDatas = nDatas
853 # self.nDatas = nDatas
917 # self.nDims = nDims
854 # self.nDims = nDims
918 # self.nDimsForDs = nDimsForDs
855 # self.nDimsForDs = nDimsForDs
919 #Saving variables
856 #Saving variables
920 print 'Writing the file: %s'%filename
857 print 'Writing the file: %s'%filename
921 self.filename = filename
858 self.filename = filename
922 # self.fp = fp
859 # self.fp = fp
923 # self.grp = grp
860 # self.grp = grp
924 # self.grp.attrs.modify('nRecords', 1)
861 # self.grp.attrs.modify('nRecords', 1)
925 self.ds = ds
862 self.ds = ds
926 self.data = data
863 self.data = data
927 # self.setFile = setFile
864 # self.setFile = setFile
928 self.firsttime = True
865 self.firsttime = True
929 self.blockIndex = 0
866 self.blockIndex = 0
930 return
867 return
931
868
932 def putData(self):
869 def putData(self):
933
870
934 if self.blockIndex == self.blocksPerFile or self.timeFlag():
871 if self.blockIndex == self.blocksPerFile or self.timeFlag():
935 self.setNextFile()
872 self.setNextFile()
936
873
937 # if not self.firsttime:
874 # if not self.firsttime:
938 self.readBlock()
875 self.readBlock()
939 self.setBlock() #Prepare data to be written
876 self.setBlock() #Prepare data to be written
940 self.writeBlock() #Write data
877 self.writeBlock() #Write data
941
878
942 return
879 return
943
880
944 def readBlock(self):
881 def readBlock(self):
945
882
946 '''
883 '''
947 data Array configured
884 data Array configured
948
885
949
886
950 self.data
887 self.data
951 '''
888 '''
952 dsList = self.dsList
889 dsList = self.dsList
953 ds = self.ds
890 ds = self.ds
954 #Setting HDF5 File
891 #Setting HDF5 File
955 fp = h5py.File(self.filename,'r+')
892 fp = h5py.File(self.filename,'r+')
956 grp = fp["Data"]
893 grp = fp["Data"]
957 ind = 0
894 ind = 0
958
895
959 # grp.attrs['blocksPerFile'] = 0
896 # grp.attrs['blocksPerFile'] = 0
960 while ind < len(dsList):
897 while ind < len(dsList):
961 dsInfo = dsList[ind]
898 dsInfo = dsList[ind]
962
899
963 if dsInfo['mode'] == 0:
900 if dsInfo['mode'] == 0:
964 ds0 = grp[dsInfo['variable']]
901 ds0 = grp[dsInfo['variable']]
965 ds[ind] = ds0
902 ds[ind] = ds0
966 ind += 1
903 ind += 1
967 else:
904 else:
968
905
969 grp0 = grp[dsInfo['variable']]
906 grp0 = grp[dsInfo['variable']]
970
907
971 for j in range(dsInfo['dsNumber']):
908 for j in range(dsInfo['dsNumber']):
972 dsInfo = dsList[ind]
909 dsInfo = dsList[ind]
973 ds0 = grp0[dsInfo['dsName']]
910 ds0 = grp0[dsInfo['dsName']]
974 ds[ind] = ds0
911 ds[ind] = ds0
975 ind += 1
912 ind += 1
976
913
977 self.fp = fp
914 self.fp = fp
978 self.grp = grp
915 self.grp = grp
979 self.ds = ds
916 self.ds = ds
980
917
981 return
918 return
982
919
983 def setBlock(self):
920 def setBlock(self):
984 '''
921 '''
985 data Array configured
922 data Array configured
986
923
987
924
988 self.data
925 self.data
989 '''
926 '''
990 #Creating Arrays
927 #Creating Arrays
991 dsList = self.dsList
928 dsList = self.dsList
992 data = self.data
929 data = self.data
993 ind = 0
930 ind = 0
994
931
995 while ind < len(dsList):
932 while ind < len(dsList):
996 dsInfo = dsList[ind]
933 dsInfo = dsList[ind]
997 dataAux = getattr(self.dataOut, dsInfo['variable'])
934 dataAux = getattr(self.dataOut, dsInfo['variable'])
998
935
999 mode = dsInfo['mode']
936 mode = dsInfo['mode']
1000 nDim = dsInfo['nDim']
937 nDim = dsInfo['nDim']
1001
938
1002 if mode == 0 or mode == 2 or nDim == 1:
939 if mode == 0 or mode == 2 or nDim == 1:
1003 data[ind] = dataAux
940 data[ind] = dataAux
1004 ind += 1
941 ind += 1
1005 # elif nDim == 1:
942 # elif nDim == 1:
1006 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
943 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1007 # ind += 1
944 # ind += 1
1008 elif nDim == 2:
945 elif nDim == 2:
1009 for j in range(dsInfo['dsNumber']):
946 for j in range(dsInfo['dsNumber']):
1010 data[ind] = dataAux[j,:]
947 data[ind] = dataAux[j,:]
1011 ind += 1
948 ind += 1
1012 elif nDim == 3:
949 elif nDim == 3:
1013 for j in range(dsInfo['dsNumber']):
950 for j in range(dsInfo['dsNumber']):
1014 data[ind] = dataAux[:,j,:]
951 data[ind] = dataAux[:,j,:]
1015 ind += 1
952 ind += 1
1016
953
1017 self.data = data
954 self.data = data
1018 return
955 return
1019
956
1020 def writeBlock(self):
957 def writeBlock(self):
1021 '''
958 '''
1022 Saves the block in the HDF5 file
959 Saves the block in the HDF5 file
1023 '''
960 '''
1024 dsList = self.dsList
961 dsList = self.dsList
1025
962
1026 for i in range(len(self.ds)):
963 for i in range(len(self.ds)):
1027 dsInfo = dsList[i]
964 dsInfo = dsList[i]
1028 nDim = dsInfo['nDim']
965 nDim = dsInfo['nDim']
1029 mode = dsInfo['mode']
966 mode = dsInfo['mode']
1030
967
1031 # First time
968 # First time
1032 if self.firsttime:
969 if self.firsttime:
1033 # self.ds[i].resize(self.data[i].shape)
970 # self.ds[i].resize(self.data[i].shape)
1034 # self.ds[i][self.blockIndex,:] = self.data[i]
971 # self.ds[i][self.blockIndex,:] = self.data[i]
1035 if type(self.data[i]) == numpy.ndarray:
972 if type(self.data[i]) == numpy.ndarray:
1036
973
1037 if nDim == 3:
974 if nDim == 3:
1038 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
975 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1039 self.ds[i].resize(self.data[i].shape)
976 self.ds[i].resize(self.data[i].shape)
1040 if mode == 2:
977 if mode == 2:
1041 self.ds[i].resize(self.data[i].shape)
978 self.ds[i].resize(self.data[i].shape)
1042 self.ds[i][:] = self.data[i]
979 self.ds[i][:] = self.data[i]
1043 else:
980 else:
1044
981
1045 # From second time
982 # From second time
1046 # Meteors!
983 # Meteors!
1047 if mode == 2:
984 if mode == 2:
1048 dataShape = self.data[i].shape
985 dataShape = self.data[i].shape
1049 dsShape = self.ds[i].shape
986 dsShape = self.ds[i].shape
1050 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
987 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1051 self.ds[i][dsShape[0]:,:] = self.data[i]
988 self.ds[i][dsShape[0]:,:] = self.data[i]
1052 # No dimension
989 # No dimension
1053 elif mode == 0:
990 elif mode == 0:
1054 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
991 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1055 self.ds[i][0,-1] = self.data[i]
992 self.ds[i][0,-1] = self.data[i]
1056 # One dimension
993 # One dimension
1057 elif nDim == 1:
994 elif nDim == 1:
1058 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
995 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1059 self.ds[i][-1,:] = self.data[i]
996 self.ds[i][-1,:] = self.data[i]
1060 # Two dimension
997 # Two dimension
1061 elif nDim == 2:
998 elif nDim == 2:
1062 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
999 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1063 self.ds[i][self.blockIndex,:] = self.data[i]
1000 self.ds[i][self.blockIndex,:] = self.data[i]
1064 # Three dimensions
1001 # Three dimensions
1065 elif nDim == 3:
1002 elif nDim == 3:
1066 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1003 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1067 self.ds[i][:,:,-1] = self.data[i]
1004 self.ds[i][:,:,-1] = self.data[i]
1068
1005
1069 self.firsttime = False
1006 self.firsttime = False
1070 self.blockIndex += 1
1007 self.blockIndex += 1
1071
1008
1072 #Close to save changes
1009 #Close to save changes
1073 self.fp.flush()
1010 self.fp.flush()
1074 self.fp.close()
1011 self.fp.close()
1075 return
1012 return
1076
1013
1077 def run(self, dataOut, **kwargs):
1014 def run(self, dataOut, **kwargs):
1078
1015
1079 if not(self.isConfig):
1016 if not(self.isConfig):
1080 flagdata = self.setup(dataOut, **kwargs)
1017 flagdata = self.setup(dataOut, **kwargs)
1081
1018
1082 if not(flagdata):
1019 if not(flagdata):
1083 return
1020 return
1084
1021
1085 self.isConfig = True
1022 self.isConfig = True
1086 # self.putMetadata()
1023 # self.putMetadata()
1087 self.setNextFile()
1024 self.setNextFile()
1088
1025
1089 self.putData()
1026 self.putData()
1090 return
1027 return
1091
1028
1092
1029
@@ -1,677 +1,679
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import numpy
6 import numpy
7
7
8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 from schainpy.model.data.jrodata import Spectra
11 from schainpy.model.data.jrodata import Spectra
12
12
13 class SpectraReader(JRODataReader, ProcessingUnit):
13 class SpectraReader(JRODataReader, ProcessingUnit):
14 """
14 """
15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
17 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
17 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
18
18
19 paresCanalesIguales * alturas * perfiles (Self Spectra)
19 paresCanalesIguales * alturas * perfiles (Self Spectra)
20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
21 canales * alturas (DC Channels)
21 canales * alturas (DC Channels)
22
22
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
27
27
28 Example:
28 Example:
29 dpath = "/home/myuser/data"
29 dpath = "/home/myuser/data"
30
30
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
32
32
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
34
34
35 readerObj = SpectraReader()
35 readerObj = SpectraReader()
36
36
37 readerObj.setup(dpath, startTime, endTime)
37 readerObj.setup(dpath, startTime, endTime)
38
38
39 while(True):
39 while(True):
40
40
41 readerObj.getData()
41 readerObj.getData()
42
42
43 print readerObj.data_spc
43 print readerObj.data_spc
44
44
45 print readerObj.data_cspc
45 print readerObj.data_cspc
46
46
47 print readerObj.data_dc
47 print readerObj.data_dc
48
48
49 if readerObj.flagNoMoreFiles:
49 if readerObj.flagNoMoreFiles:
50 break
50 break
51
51
52 """
52 """
53
53
54 pts2read_SelfSpectra = 0
54 pts2read_SelfSpectra = 0
55
55
56 pts2read_CrossSpectra = 0
56 pts2read_CrossSpectra = 0
57
57
58 pts2read_DCchannels = 0
58 pts2read_DCchannels = 0
59
59
60 ext = ".pdata"
60 ext = ".pdata"
61
61
62 optchar = "P"
62 optchar = "P"
63
63
64 dataOut = None
64 dataOut = None
65
65
66 nRdChannels = None
66 nRdChannels = None
67
67
68 nRdPairs = None
68 nRdPairs = None
69
69
70 rdPairList = []
70 rdPairList = []
71
71
72 def __init__(self):
72 def __init__(self):
73 """
73 """
74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
75
75
76 Inputs:
76 Inputs:
77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
78 almacenar un perfil de datos cada vez que se haga un requerimiento
78 almacenar un perfil de datos cada vez que se haga un requerimiento
79 (getData). El perfil sera obtenido a partir del buffer de datos,
79 (getData). El perfil sera obtenido a partir del buffer de datos,
80 si el buffer esta vacio se hara un nuevo proceso de lectura de un
80 si el buffer esta vacio se hara un nuevo proceso de lectura de un
81 bloque de datos.
81 bloque de datos.
82 Si este parametro no es pasado se creara uno internamente.
82 Si este parametro no es pasado se creara uno internamente.
83
83
84 Affected:
84 Affected:
85 self.dataOut
85 self.dataOut
86
86
87 Return : None
87 Return : None
88 """
88 """
89
89
90 #Eliminar de la base la herencia
90 #Eliminar de la base la herencia
91 ProcessingUnit.__init__(self)
91 ProcessingUnit.__init__(self)
92
92
93 # self.isConfig = False
93 # self.isConfig = False
94
94
95 self.pts2read_SelfSpectra = 0
95 self.pts2read_SelfSpectra = 0
96
96
97 self.pts2read_CrossSpectra = 0
97 self.pts2read_CrossSpectra = 0
98
98
99 self.pts2read_DCchannels = 0
99 self.pts2read_DCchannels = 0
100
100
101 self.datablock = None
101 self.datablock = None
102
102
103 self.utc = None
103 self.utc = None
104
104
105 self.ext = ".pdata"
105 self.ext = ".pdata"
106
106
107 self.optchar = "P"
107 self.optchar = "P"
108
108
109 self.basicHeaderObj = BasicHeader(LOCALTIME)
109 self.basicHeaderObj = BasicHeader(LOCALTIME)
110
110
111 self.systemHeaderObj = SystemHeader()
111 self.systemHeaderObj = SystemHeader()
112
112
113 self.radarControllerHeaderObj = RadarControllerHeader()
113 self.radarControllerHeaderObj = RadarControllerHeader()
114
114
115 self.processingHeaderObj = ProcessingHeader()
115 self.processingHeaderObj = ProcessingHeader()
116
116
117 self.online = 0
117 self.online = 0
118
118
119 self.fp = None
119 self.fp = None
120
120
121 self.idFile = None
121 self.idFile = None
122
122
123 self.dtype = None
123 self.dtype = None
124
124
125 self.fileSizeByHeader = None
125 self.fileSizeByHeader = None
126
126
127 self.filenameList = []
127 self.filenameList = []
128
128
129 self.filename = None
129 self.filename = None
130
130
131 self.fileSize = None
131 self.fileSize = None
132
132
133 self.firstHeaderSize = 0
133 self.firstHeaderSize = 0
134
134
135 self.basicHeaderSize = 24
135 self.basicHeaderSize = 24
136
136
137 self.pathList = []
137 self.pathList = []
138
138
139 self.lastUTTime = 0
139 self.lastUTTime = 0
140
140
141 self.maxTimeStep = 30
141 self.maxTimeStep = 30
142
142
143 self.flagNoMoreFiles = 0
143 self.flagNoMoreFiles = 0
144
144
145 self.set = 0
145 self.set = 0
146
146
147 self.path = None
147 self.path = None
148
148
149 self.delay = 60 #seconds
149 self.delay = 60 #seconds
150
150
151 self.nTries = 3 #quantity tries
151 self.nTries = 3 #quantity tries
152
152
153 self.nFiles = 3 #number of files for searching
153 self.nFiles = 3 #number of files for searching
154
154
155 self.nReadBlocks = 0
155 self.nReadBlocks = 0
156
156
157 self.flagIsNewFile = 1
157 self.flagIsNewFile = 1
158
158
159 self.__isFirstTimeOnline = 1
159 self.__isFirstTimeOnline = 1
160
160
161 # self.ippSeconds = 0
161 # self.ippSeconds = 0
162
162
163 self.flagDiscontinuousBlock = 0
163 self.flagDiscontinuousBlock = 0
164
164
165 self.flagIsNewBlock = 0
165 self.flagIsNewBlock = 0
166
166
167 self.nTotalBlocks = 0
167 self.nTotalBlocks = 0
168
168
169 self.blocksize = 0
169 self.blocksize = 0
170
170
171 self.dataOut = self.createObjByDefault()
171 self.dataOut = self.createObjByDefault()
172
172
173 self.profileIndex = 1 #Always
173 self.profileIndex = 1 #Always
174
174
175
175
176 def createObjByDefault(self):
176 def createObjByDefault(self):
177
177
178 dataObj = Spectra()
178 dataObj = Spectra()
179
179
180 return dataObj
180 return dataObj
181
181
182 def __hasNotDataInBuffer(self):
182 def __hasNotDataInBuffer(self):
183 return 1
183 return 1
184
184
185
185
186 def getBlockDimension(self):
186 def getBlockDimension(self):
187 """
187 """
188 Obtiene la cantidad de puntos a leer por cada bloque de datos
188 Obtiene la cantidad de puntos a leer por cada bloque de datos
189
189
190 Affected:
190 Affected:
191 self.nRdChannels
191 self.nRdChannels
192 self.nRdPairs
192 self.nRdPairs
193 self.pts2read_SelfSpectra
193 self.pts2read_SelfSpectra
194 self.pts2read_CrossSpectra
194 self.pts2read_CrossSpectra
195 self.pts2read_DCchannels
195 self.pts2read_DCchannels
196 self.blocksize
196 self.blocksize
197 self.dataOut.nChannels
197 self.dataOut.nChannels
198 self.dataOut.nPairs
198 self.dataOut.nPairs
199
199
200 Return:
200 Return:
201 None
201 None
202 """
202 """
203 self.nRdChannels = 0
203 self.nRdChannels = 0
204 self.nRdPairs = 0
204 self.nRdPairs = 0
205 self.rdPairList = []
205 self.rdPairList = []
206
206
207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
210 else:
210 else:
211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
213
213
214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
215
215
216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
217 self.blocksize = self.pts2read_SelfSpectra
217 self.blocksize = self.pts2read_SelfSpectra
218
218
219 if self.processingHeaderObj.flag_cspc:
219 if self.processingHeaderObj.flag_cspc:
220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
221 self.blocksize += self.pts2read_CrossSpectra
221 self.blocksize += self.pts2read_CrossSpectra
222
222
223 if self.processingHeaderObj.flag_dc:
223 if self.processingHeaderObj.flag_dc:
224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
225 self.blocksize += self.pts2read_DCchannels
225 self.blocksize += self.pts2read_DCchannels
226
226
227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
228
228
229
229
230 def readBlock(self):
230 def readBlock(self):
231 """
231 """
232 Lee el bloque de datos desde la posicion actual del puntero del archivo
232 Lee el bloque de datos desde la posicion actual del puntero del archivo
233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
235 es seteado a 0
235 es seteado a 0
236
236
237 Return: None
237 Return: None
238
238
239 Variables afectadas:
239 Variables afectadas:
240
240
241 self.flagIsNewFile
241 self.flagIsNewFile
242 self.flagIsNewBlock
242 self.flagIsNewBlock
243 self.nTotalBlocks
243 self.nTotalBlocks
244 self.data_spc
244 self.data_spc
245 self.data_cspc
245 self.data_cspc
246 self.data_dc
246 self.data_dc
247
247
248 Exceptions:
248 Exceptions:
249 Si un bloque leido no es un bloque valido
249 Si un bloque leido no es un bloque valido
250 """
250 """
251 blockOk_flag = False
251 blockOk_flag = False
252 fpointer = self.fp.tell()
252 fpointer = self.fp.tell()
253
253
254 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
254 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
255 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
255 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
256
256
257 if self.processingHeaderObj.flag_cspc:
257 if self.processingHeaderObj.flag_cspc:
258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
260
260
261 if self.processingHeaderObj.flag_dc:
261 if self.processingHeaderObj.flag_dc:
262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
264
264
265
265
266 if not(self.processingHeaderObj.shif_fft):
266 if not(self.processingHeaderObj.shif_fft):
267 #desplaza a la derecha en el eje 2 determinadas posiciones
267 #desplaza a la derecha en el eje 2 determinadas posiciones
268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
269 spc = numpy.roll( spc, shift , axis=2 )
269 spc = numpy.roll( spc, shift , axis=2 )
270
270
271 if self.processingHeaderObj.flag_cspc:
271 if self.processingHeaderObj.flag_cspc:
272 #desplaza a la derecha en el eje 2 determinadas posiciones
272 #desplaza a la derecha en el eje 2 determinadas posiciones
273 cspc = numpy.roll( cspc, shift, axis=2 )
273 cspc = numpy.roll( cspc, shift, axis=2 )
274
274
275 #Dimensions : nChannels, nProfiles, nSamples
275 #Dimensions : nChannels, nProfiles, nSamples
276 spc = numpy.transpose( spc, (0,2,1) )
276 spc = numpy.transpose( spc, (0,2,1) )
277 self.data_spc = spc
277 self.data_spc = spc
278
278
279 if self.processingHeaderObj.flag_cspc:
279 if self.processingHeaderObj.flag_cspc:
280 cspc = numpy.transpose( cspc, (0,2,1) )
280 cspc = numpy.transpose( cspc, (0,2,1) )
281 self.data_cspc = cspc['real'] + cspc['imag']*1j
281 self.data_cspc = cspc['real'] + cspc['imag']*1j
282 else:
282 else:
283 self.data_cspc = None
283 self.data_cspc = None
284
284
285 if self.processingHeaderObj.flag_dc:
285 if self.processingHeaderObj.flag_dc:
286 self.data_dc = dc['real'] + dc['imag']*1j
286 self.data_dc = dc['real'] + dc['imag']*1j
287 else:
287 else:
288 self.data_dc = None
288 self.data_dc = None
289
289
290 self.flagIsNewFile = 0
290 self.flagIsNewFile = 0
291 self.flagIsNewBlock = 1
291 self.flagIsNewBlock = 1
292
292
293 self.nTotalBlocks += 1
293 self.nTotalBlocks += 1
294 self.nReadBlocks += 1
294 self.nReadBlocks += 1
295
295
296 return 1
296 return 1
297
297
298 def getFirstHeader(self):
298 def getFirstHeader(self):
299
299
300 self.getBasicHeader()
300 self.getBasicHeader()
301
301
302 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
302 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
303
303
304 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
304 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
305
305
306 # self.dataOut.ippSeconds = self.ippSeconds
306 # self.dataOut.ippSeconds = self.ippSeconds
307
307
308 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
308 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
309
309
310 self.dataOut.dtype = self.dtype
310 self.dataOut.dtype = self.dtype
311
311
312 # self.dataOut.nPairs = self.nPairs
312 # self.dataOut.nPairs = self.nPairs
313
313
314 self.dataOut.pairsList = self.rdPairList
314 self.dataOut.pairsList = self.rdPairList
315
315
316 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
316 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
317
317
318 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
318 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
319
319
320 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
320 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
321
321
322 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
322 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
323
323
324 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
324 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
325
325
326 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
326 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
327
327
328 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
328 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
329
329
330 self.dataOut.flagShiftFFT = True #Data is always shifted
330 self.dataOut.flagShiftFFT = True #Data is always shifted
331
331
332 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
332 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
333
333
334 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
334 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
335
335
336 def getData(self):
336 def getData(self):
337 """
337 """
338 First method to execute before "RUN" is called.
338 First method to execute before "RUN" is called.
339
339
340 Copia el buffer de lectura a la clase "Spectra",
340 Copia el buffer de lectura a la clase "Spectra",
341 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
341 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
342 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
342 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
343
343
344 Return:
344 Return:
345 0 : Si no hay mas archivos disponibles
345 0 : Si no hay mas archivos disponibles
346 1 : Si hizo una buena copia del buffer
346 1 : Si hizo una buena copia del buffer
347
347
348 Affected:
348 Affected:
349 self.dataOut
349 self.dataOut
350
350
351 self.flagDiscontinuousBlock
351 self.flagDiscontinuousBlock
352 self.flagIsNewBlock
352 self.flagIsNewBlock
353 """
353 """
354
354
355 if self.flagNoMoreFiles:
355 if self.flagNoMoreFiles:
356 self.dataOut.flagNoData = True
356 self.dataOut.flagNoData = True
357 print 'Process finished'
357 print 'Process finished'
358 return 0
358 return 0
359
359
360 self.flagDiscontinuousBlock = 0
360 self.flagDiscontinuousBlock = 0
361 self.flagIsNewBlock = 0
361 self.flagIsNewBlock = 0
362
362
363 if self.__hasNotDataInBuffer():
363 if self.__hasNotDataInBuffer():
364
364
365 if not( self.readNextBlock() ):
365 if not( self.readNextBlock() ):
366 self.dataOut.flagNoData = True
366 self.dataOut.flagNoData = True
367 return 0
367 return 0
368
368
369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
370
370
371 if self.data_spc is None:
371 if self.data_spc is None:
372 self.dataOut.flagNoData = True
372 self.dataOut.flagNoData = True
373 return 0
373 return 0
374
374
375 self.getBasicHeader()
375 self.getBasicHeader()
376
376
377 self.getFirstHeader()
377 self.getFirstHeader()
378
378
379 self.dataOut.data_spc = self.data_spc
379 self.dataOut.data_spc = self.data_spc
380
380
381 self.dataOut.data_cspc = self.data_cspc
381 self.dataOut.data_cspc = self.data_cspc
382
382
383 self.dataOut.data_dc = self.data_dc
383 self.dataOut.data_dc = self.data_dc
384
384
385 self.dataOut.flagNoData = False
385 self.dataOut.flagNoData = False
386
386
387 self.dataOut.realtime = self.online
387 self.dataOut.realtime = self.online
388
388
389 return self.dataOut.data_spc
389 return self.dataOut.data_spc
390
390
391 class SpectraWriter(JRODataWriter, Operation):
391 class SpectraWriter(JRODataWriter, Operation):
392
392
393 """
393 """
394 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
394 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
395 de los datos siempre se realiza por bloques.
395 de los datos siempre se realiza por bloques.
396 """
396 """
397
397
398 ext = ".pdata"
398 ext = ".pdata"
399
399
400 optchar = "P"
400 optchar = "P"
401
401
402 shape_spc_Buffer = None
402 shape_spc_Buffer = None
403
403
404 shape_cspc_Buffer = None
404 shape_cspc_Buffer = None
405
405
406 shape_dc_Buffer = None
406 shape_dc_Buffer = None
407
407
408 data_spc = None
408 data_spc = None
409
409
410 data_cspc = None
410 data_cspc = None
411
411
412 data_dc = None
412 data_dc = None
413
413
414 # dataOut = None
414 # dataOut = None
415
415
416 def __init__(self):
416 def __init__(self):
417 """
417 """
418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
419
419
420 Affected:
420 Affected:
421 self.dataOut
421 self.dataOut
422 self.basicHeaderObj
422 self.basicHeaderObj
423 self.systemHeaderObj
423 self.systemHeaderObj
424 self.radarControllerHeaderObj
424 self.radarControllerHeaderObj
425 self.processingHeaderObj
425 self.processingHeaderObj
426
426
427 Return: None
427 Return: None
428 """
428 """
429
429
430 Operation.__init__(self)
430 Operation.__init__(self)
431
431
432 self.isConfig = False
432 self.isConfig = False
433
433
434 self.nTotalBlocks = 0
434 self.nTotalBlocks = 0
435
435
436 self.data_spc = None
436 self.data_spc = None
437
437
438 self.data_cspc = None
438 self.data_cspc = None
439
439
440 self.data_dc = None
440 self.data_dc = None
441
441
442 self.fp = None
442 self.fp = None
443
443
444 self.flagIsNewFile = 1
444 self.flagIsNewFile = 1
445
445
446 self.nTotalBlocks = 0
446 self.nTotalBlocks = 0
447
447
448 self.flagIsNewBlock = 0
448 self.flagIsNewBlock = 0
449
449
450 self.setFile = None
450 self.setFile = None
451
451
452 self.dtype = None
452 self.dtype = None
453
453
454 self.path = None
454 self.path = None
455
455
456 self.noMoreFiles = 0
456 self.noMoreFiles = 0
457
457
458 self.filename = None
458 self.filename = None
459
459
460 self.basicHeaderObj = BasicHeader(LOCALTIME)
460 self.basicHeaderObj = BasicHeader(LOCALTIME)
461
461
462 self.systemHeaderObj = SystemHeader()
462 self.systemHeaderObj = SystemHeader()
463
463
464 self.radarControllerHeaderObj = RadarControllerHeader()
464 self.radarControllerHeaderObj = RadarControllerHeader()
465
465
466 self.processingHeaderObj = ProcessingHeader()
466 self.processingHeaderObj = ProcessingHeader()
467
467
468
468
469 def hasAllDataInBuffer(self):
469 def hasAllDataInBuffer(self):
470 return 1
470 return 1
471
471
472
472
473 def setBlockDimension(self):
473 def setBlockDimension(self):
474 """
474 """
475 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
475 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
476
476
477 Affected:
477 Affected:
478 self.shape_spc_Buffer
478 self.shape_spc_Buffer
479 self.shape_cspc_Buffer
479 self.shape_cspc_Buffer
480 self.shape_dc_Buffer
480 self.shape_dc_Buffer
481
481
482 Return: None
482 Return: None
483 """
483 """
484 self.shape_spc_Buffer = (self.dataOut.nChannels,
484 self.shape_spc_Buffer = (self.dataOut.nChannels,
485 self.processingHeaderObj.nHeights,
485 self.processingHeaderObj.nHeights,
486 self.processingHeaderObj.profilesPerBlock)
486 self.processingHeaderObj.profilesPerBlock)
487
487
488 self.shape_cspc_Buffer = (self.dataOut.nPairs,
488 self.shape_cspc_Buffer = (self.dataOut.nPairs,
489 self.processingHeaderObj.nHeights,
489 self.processingHeaderObj.nHeights,
490 self.processingHeaderObj.profilesPerBlock)
490 self.processingHeaderObj.profilesPerBlock)
491
491
492 self.shape_dc_Buffer = (self.dataOut.nChannels,
492 self.shape_dc_Buffer = (self.dataOut.nChannels,
493 self.processingHeaderObj.nHeights)
493 self.processingHeaderObj.nHeights)
494
494
495
495
496 def writeBlock(self):
496 def writeBlock(self):
497 """
497 """
498 Escribe el buffer en el file designado
498 Escribe el buffer en el file designado
499
499
500 Affected:
500 Affected:
501 self.data_spc
501 self.data_spc
502 self.data_cspc
502 self.data_cspc
503 self.data_dc
503 self.data_dc
504 self.flagIsNewFile
504 self.flagIsNewFile
505 self.flagIsNewBlock
505 self.flagIsNewBlock
506 self.nTotalBlocks
506 self.nTotalBlocks
507 self.nWriteBlocks
507 self.nWriteBlocks
508
508
509 Return: None
509 Return: None
510 """
510 """
511
511
512 spc = numpy.transpose( self.data_spc, (0,2,1) )
512 spc = numpy.transpose( self.data_spc, (0,2,1) )
513 if not( self.processingHeaderObj.shif_fft ):
513 if not( self.processingHeaderObj.shif_fft ):
514 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
514 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
515 data = spc.reshape((-1))
515 data = spc.reshape((-1))
516 data = data.astype(self.dtype[0])
516 data = data.astype(self.dtype[0])
517 data.tofile(self.fp)
517 data.tofile(self.fp)
518
518
519 if self.data_cspc is not None:
519 if self.data_cspc is not None:
520 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
520 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
521 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
521 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
522 if not( self.processingHeaderObj.shif_fft ):
522 if not( self.processingHeaderObj.shif_fft ):
523 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
523 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
524 data['real'] = cspc.real
524 data['real'] = cspc.real
525 data['imag'] = cspc.imag
525 data['imag'] = cspc.imag
526 data = data.reshape((-1))
526 data = data.reshape((-1))
527 data.tofile(self.fp)
527 data.tofile(self.fp)
528
528
529 if self.data_dc is not None:
529 if self.data_dc is not None:
530 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
530 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
531 dc = self.data_dc
531 dc = self.data_dc
532 data['real'] = dc.real
532 data['real'] = dc.real
533 data['imag'] = dc.imag
533 data['imag'] = dc.imag
534 data = data.reshape((-1))
534 data = data.reshape((-1))
535 data.tofile(self.fp)
535 data.tofile(self.fp)
536
536
537 # self.data_spc.fill(0)
537 # self.data_spc.fill(0)
538 #
538 #
539 # if self.data_dc is not None:
539 # if self.data_dc is not None:
540 # self.data_dc.fill(0)
540 # self.data_dc.fill(0)
541 #
541 #
542 # if self.data_cspc is not None:
542 # if self.data_cspc is not None:
543 # self.data_cspc.fill(0)
543 # self.data_cspc.fill(0)
544
544
545 self.flagIsNewFile = 0
545 self.flagIsNewFile = 0
546 self.flagIsNewBlock = 1
546 self.flagIsNewBlock = 1
547 self.nTotalBlocks += 1
547 self.nTotalBlocks += 1
548 self.nWriteBlocks += 1
548 self.nWriteBlocks += 1
549 self.blockIndex += 1
549 self.blockIndex += 1
550
550
551 # print "[Writing] Block = %d04" %self.blockIndex
551 # print "[Writing] Block = %d04" %self.blockIndex
552
552
553 def putData(self):
553 def putData(self):
554 """
554 """
555 Setea un bloque de datos y luego los escribe en un file
555 Setea un bloque de datos y luego los escribe en un file
556
556
557 Affected:
557 Affected:
558 self.data_spc
558 self.data_spc
559 self.data_cspc
559 self.data_cspc
560 self.data_dc
560 self.data_dc
561
561
562 Return:
562 Return:
563 0 : Si no hay data o no hay mas files que puedan escribirse
563 0 : Si no hay data o no hay mas files que puedan escribirse
564 1 : Si se escribio la data de un bloque en un file
564 1 : Si se escribio la data de un bloque en un file
565 """
565 """
566
566
567 if self.dataOut.flagNoData:
567 if self.dataOut.flagNoData:
568 return 0
568 return 0
569
569
570 self.flagIsNewBlock = 0
570 self.flagIsNewBlock = 0
571
571
572 if self.dataOut.flagDiscontinuousBlock:
572 if self.dataOut.flagDiscontinuousBlock:
573 self.data_spc.fill(0)
573 self.data_spc.fill(0)
574 if self.dataOut.data_cspc is not None:
574 self.data_cspc.fill(0)
575 self.data_cspc.fill(0)
576 if self.dataOut.data_dc is not None:
575 self.data_dc.fill(0)
577 self.data_dc.fill(0)
576 self.setNextFile()
578 self.setNextFile()
577
579
578 if self.flagIsNewFile == 0:
580 if self.flagIsNewFile == 0:
579 self.setBasicHeader()
581 self.setBasicHeader()
580
582
581 self.data_spc = self.dataOut.data_spc.copy()
583 self.data_spc = self.dataOut.data_spc.copy()
582
584
583 if self.dataOut.data_cspc is not None:
585 if self.dataOut.data_cspc is not None:
584 self.data_cspc = self.dataOut.data_cspc.copy()
586 self.data_cspc = self.dataOut.data_cspc.copy()
585
587
586 if self.dataOut.data_dc is not None:
588 if self.dataOut.data_dc is not None:
587 self.data_dc = self.dataOut.data_dc.copy()
589 self.data_dc = self.dataOut.data_dc.copy()
588
590
589 # #self.processingHeaderObj.dataBlocksPerFile)
591 # #self.processingHeaderObj.dataBlocksPerFile)
590 if self.hasAllDataInBuffer():
592 if self.hasAllDataInBuffer():
591 # self.setFirstHeader()
593 # self.setFirstHeader()
592 self.writeNextBlock()
594 self.writeNextBlock()
593
595
594 return 1
596 return 1
595
597
596 def __getBlockSize(self):
598 def __getBlockSize(self):
597 '''
599 '''
598 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
600 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
599 '''
601 '''
600
602
601 dtype_width = self.getDtypeWidth()
603 dtype_width = self.getDtypeWidth()
602
604
603 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
605 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
604
606
605 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
607 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
606 blocksize = (pts2write_SelfSpectra*dtype_width)
608 blocksize = (pts2write_SelfSpectra*dtype_width)
607
609
608 if self.dataOut.data_cspc is not None:
610 if self.dataOut.data_cspc is not None:
609 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
611 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
610 blocksize += (pts2write_CrossSpectra*dtype_width*2)
612 blocksize += (pts2write_CrossSpectra*dtype_width*2)
611
613
612 if self.dataOut.data_dc is not None:
614 if self.dataOut.data_dc is not None:
613 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
615 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
614 blocksize += (pts2write_DCchannels*dtype_width*2)
616 blocksize += (pts2write_DCchannels*dtype_width*2)
615
617
616 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
618 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
617
619
618 return blocksize
620 return blocksize
619
621
620 def setFirstHeader(self):
622 def setFirstHeader(self):
621
623
622 """
624 """
623 Obtiene una copia del First Header
625 Obtiene una copia del First Header
624
626
625 Affected:
627 Affected:
626 self.systemHeaderObj
628 self.systemHeaderObj
627 self.radarControllerHeaderObj
629 self.radarControllerHeaderObj
628 self.dtype
630 self.dtype
629
631
630 Return:
632 Return:
631 None
633 None
632 """
634 """
633
635
634 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
636 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
635 self.systemHeaderObj.nChannels = self.dataOut.nChannels
637 self.systemHeaderObj.nChannels = self.dataOut.nChannels
636 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
638 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
637
639
638 self.processingHeaderObj.dtype = 1 # Spectra
640 self.processingHeaderObj.dtype = 1 # Spectra
639 self.processingHeaderObj.blockSize = self.__getBlockSize()
641 self.processingHeaderObj.blockSize = self.__getBlockSize()
640 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
642 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
641 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
643 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
642 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
644 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
643 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
645 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
644 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
646 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
645 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
647 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
646 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
648 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
647
649
648 if self.processingHeaderObj.totalSpectra > 0:
650 if self.processingHeaderObj.totalSpectra > 0:
649 channelList = []
651 channelList = []
650 for channel in range(self.dataOut.nChannels):
652 for channel in range(self.dataOut.nChannels):
651 channelList.append(channel)
653 channelList.append(channel)
652 channelList.append(channel)
654 channelList.append(channel)
653
655
654 pairsList = []
656 pairsList = []
655 if self.dataOut.nPairs > 0:
657 if self.dataOut.nPairs > 0:
656 for pair in self.dataOut.pairsList:
658 for pair in self.dataOut.pairsList:
657 pairsList.append(pair[0])
659 pairsList.append(pair[0])
658 pairsList.append(pair[1])
660 pairsList.append(pair[1])
659
661
660 spectraComb = channelList + pairsList
662 spectraComb = channelList + pairsList
661 spectraComb = numpy.array(spectraComb, dtype="u1")
663 spectraComb = numpy.array(spectraComb, dtype="u1")
662 self.processingHeaderObj.spectraComb = spectraComb
664 self.processingHeaderObj.spectraComb = spectraComb
663
665
664 if self.dataOut.code is not None:
666 if self.dataOut.code is not None:
665 self.processingHeaderObj.code = self.dataOut.code
667 self.processingHeaderObj.code = self.dataOut.code
666 self.processingHeaderObj.nCode = self.dataOut.nCode
668 self.processingHeaderObj.nCode = self.dataOut.nCode
667 self.processingHeaderObj.nBaud = self.dataOut.nBaud
669 self.processingHeaderObj.nBaud = self.dataOut.nBaud
668
670
669 if self.processingHeaderObj.nWindows != 0:
671 if self.processingHeaderObj.nWindows != 0:
670 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
672 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
671 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
673 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
672 self.processingHeaderObj.nHeights = self.dataOut.nHeights
674 self.processingHeaderObj.nHeights = self.dataOut.nHeights
673 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
675 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
674
676
675 self.processingHeaderObj.processFlags = self.getProcessFlags()
677 self.processingHeaderObj.processFlags = self.getProcessFlags()
676
678
677 self.setBasicHeader()
679 self.setBasicHeader()
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -1,343 +1,345
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import SpectraHeis
4 from schainpy.model.data.jrodata import SpectraHeis
5
5
6 class SpectraHeisProc(ProcessingUnit):
6 class SpectraHeisProc(ProcessingUnit):
7
7
8 def __init__(self):
8 def __init__(self):
9
9
10 ProcessingUnit.__init__(self)
10 ProcessingUnit.__init__(self)
11
11
12 # self.buffer = None
12 # self.buffer = None
13 # self.firstdatatime = None
13 # self.firstdatatime = None
14 # self.profIndex = 0
14 # self.profIndex = 0
15 self.dataOut = SpectraHeis()
15 self.dataOut = SpectraHeis()
16
16
17 def __updateObjFromVoltage(self):
17 def __updateObjFromVoltage(self):
18
18
19 self.dataOut.timeZone = self.dataIn.timeZone
19 self.dataOut.timeZone = self.dataIn.timeZone
20 self.dataOut.dstFlag = self.dataIn.dstFlag
20 self.dataOut.dstFlag = self.dataIn.dstFlag
21 self.dataOut.errorCount = self.dataIn.errorCount
21 self.dataOut.errorCount = self.dataIn.errorCount
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
23
23
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
26 self.dataOut.channelList = self.dataIn.channelList
26 self.dataOut.channelList = self.dataIn.channelList
27 self.dataOut.heightList = self.dataIn.heightList
27 self.dataOut.heightList = self.dataIn.heightList
28 # self.dataOut.dtype = self.dataIn.dtype
28 # self.dataOut.dtype = self.dataIn.dtype
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
30 # self.dataOut.nHeights = self.dataIn.nHeights
30 # self.dataOut.nHeights = self.dataIn.nHeights
31 # self.dataOut.nChannels = self.dataIn.nChannels
31 # self.dataOut.nChannels = self.dataIn.nChannels
32 self.dataOut.nBaud = self.dataIn.nBaud
32 self.dataOut.nBaud = self.dataIn.nBaud
33 self.dataOut.nCode = self.dataIn.nCode
33 self.dataOut.nCode = self.dataIn.nCode
34 self.dataOut.code = self.dataIn.code
34 self.dataOut.code = self.dataIn.code
35 # self.dataOut.nProfiles = 1
35 # self.dataOut.nProfiles = 1
36 self.dataOut.ippFactor = 1
37 self.dataOut.noise_estimation = None
36 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
37 self.dataOut.nFFTPoints = self.dataIn.nHeights
39 self.dataOut.nFFTPoints = self.dataIn.nHeights
38 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
39 # self.dataOut.flagNoData = self.dataIn.flagNoData
41 # self.dataOut.flagNoData = self.dataIn.flagNoData
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 self.dataOut.utctime = self.dataIn.utctime
43 self.dataOut.utctime = self.dataIn.utctime
42 # self.dataOut.utctime = self.firstdatatime
44 # self.dataOut.utctime = self.firstdatatime
43 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
45 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
44 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
46 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
45 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
47 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
46 self.dataOut.nCohInt = self.dataIn.nCohInt
48 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.nIncohInt = 1
49 self.dataOut.nIncohInt = 1
48 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
50 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50
52
51 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
53 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
52 # self.dataOut.set=self.dataIn.set
54 # self.dataOut.set=self.dataIn.set
53 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
55 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
54
56
55
57
56 def __updateObjFromFits(self):
58 def __updateObjFromFits(self):
57
59
58 self.dataOut.utctime = self.dataIn.utctime
60 self.dataOut.utctime = self.dataIn.utctime
59 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
61 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
60
62
61 self.dataOut.channelList = self.dataIn.channelList
63 self.dataOut.channelList = self.dataIn.channelList
62 self.dataOut.heightList = self.dataIn.heightList
64 self.dataOut.heightList = self.dataIn.heightList
63 self.dataOut.data_spc = self.dataIn.data
65 self.dataOut.data_spc = self.dataIn.data
64 self.dataOut.ippSeconds = self.dataIn.ippSeconds
66 self.dataOut.ippSeconds = self.dataIn.ippSeconds
65 self.dataOut.nCohInt = self.dataIn.nCohInt
67 self.dataOut.nCohInt = self.dataIn.nCohInt
66 self.dataOut.nIncohInt = self.dataIn.nIncohInt
68 self.dataOut.nIncohInt = self.dataIn.nIncohInt
67 # self.dataOut.timeInterval = self.dataIn.timeInterval
69 # self.dataOut.timeInterval = self.dataIn.timeInterval
68 self.dataOut.timeZone = self.dataIn.timeZone
70 self.dataOut.timeZone = self.dataIn.timeZone
69 self.dataOut.useLocalTime = True
71 self.dataOut.useLocalTime = True
70 # self.dataOut.
72 # self.dataOut.
71 # self.dataOut.
73 # self.dataOut.
72
74
73 def __getFft(self):
75 def __getFft(self):
74
76
75 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
77 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
76 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
78 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
77 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
79 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
78 self.dataOut.data_spc = spc
80 self.dataOut.data_spc = spc
79
81
80 def run(self):
82 def run(self):
81
83
82 self.dataOut.flagNoData = True
84 self.dataOut.flagNoData = True
83
85
84 if self.dataIn.type == "Fits":
86 if self.dataIn.type == "Fits":
85 self.__updateObjFromFits()
87 self.__updateObjFromFits()
86 self.dataOut.flagNoData = False
88 self.dataOut.flagNoData = False
87 return
89 return
88
90
89 if self.dataIn.type == "SpectraHeis":
91 if self.dataIn.type == "SpectraHeis":
90 self.dataOut.copy(self.dataIn)
92 self.dataOut.copy(self.dataIn)
91 return
93 return
92
94
93 if self.dataIn.type == "Voltage":
95 if self.dataIn.type == "Voltage":
94 self.__updateObjFromVoltage()
96 self.__updateObjFromVoltage()
95 self.__getFft()
97 self.__getFft()
96 self.dataOut.flagNoData = False
98 self.dataOut.flagNoData = False
97
99
98 return
100 return
99
101
100 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
102 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
101
103
102
104
103 def selectChannels(self, channelList):
105 def selectChannels(self, channelList):
104
106
105 channelIndexList = []
107 channelIndexList = []
106
108
107 for channel in channelList:
109 for channel in channelList:
108 index = self.dataOut.channelList.index(channel)
110 index = self.dataOut.channelList.index(channel)
109 channelIndexList.append(index)
111 channelIndexList.append(index)
110
112
111 self.selectChannelsByIndex(channelIndexList)
113 self.selectChannelsByIndex(channelIndexList)
112
114
113 def selectChannelsByIndex(self, channelIndexList):
115 def selectChannelsByIndex(self, channelIndexList):
114 """
116 """
115 Selecciona un bloque de datos en base a canales segun el channelIndexList
117 Selecciona un bloque de datos en base a canales segun el channelIndexList
116
118
117 Input:
119 Input:
118 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
120 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
119
121
120 Affected:
122 Affected:
121 self.dataOut.data
123 self.dataOut.data
122 self.dataOut.channelIndexList
124 self.dataOut.channelIndexList
123 self.dataOut.nChannels
125 self.dataOut.nChannels
124 self.dataOut.m_ProcessingHeader.totalSpectra
126 self.dataOut.m_ProcessingHeader.totalSpectra
125 self.dataOut.systemHeaderObj.numChannels
127 self.dataOut.systemHeaderObj.numChannels
126 self.dataOut.m_ProcessingHeader.blockSize
128 self.dataOut.m_ProcessingHeader.blockSize
127
129
128 Return:
130 Return:
129 None
131 None
130 """
132 """
131
133
132 for channelIndex in channelIndexList:
134 for channelIndex in channelIndexList:
133 if channelIndex not in self.dataOut.channelIndexList:
135 if channelIndex not in self.dataOut.channelIndexList:
134 print channelIndexList
136 print channelIndexList
135 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
137 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
136
138
137 # nChannels = len(channelIndexList)
139 # nChannels = len(channelIndexList)
138
140
139 data_spc = self.dataOut.data_spc[channelIndexList,:]
141 data_spc = self.dataOut.data_spc[channelIndexList,:]
140
142
141 self.dataOut.data_spc = data_spc
143 self.dataOut.data_spc = data_spc
142 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
144 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
143
145
144 return 1
146 return 1
145
147
146 class IncohInt4SpectraHeis(Operation):
148 class IncohInt4SpectraHeis(Operation):
147
149
148 isConfig = False
150 isConfig = False
149
151
150 __profIndex = 0
152 __profIndex = 0
151 __withOverapping = False
153 __withOverapping = False
152
154
153 __byTime = False
155 __byTime = False
154 __initime = None
156 __initime = None
155 __lastdatatime = None
157 __lastdatatime = None
156 __integrationtime = None
158 __integrationtime = None
157
159
158 __buffer = None
160 __buffer = None
159
161
160 __dataReady = False
162 __dataReady = False
161
163
162 n = None
164 n = None
163
165
164
166
165 def __init__(self):
167 def __init__(self):
166
168
167 Operation.__init__(self)
169 Operation.__init__(self)
168 # self.isConfig = False
170 # self.isConfig = False
169
171
170 def setup(self, n=None, timeInterval=None, overlapping=False):
172 def setup(self, n=None, timeInterval=None, overlapping=False):
171 """
173 """
172 Set the parameters of the integration class.
174 Set the parameters of the integration class.
173
175
174 Inputs:
176 Inputs:
175
177
176 n : Number of coherent integrations
178 n : Number of coherent integrations
177 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
179 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
178 overlapping :
180 overlapping :
179
181
180 """
182 """
181
183
182 self.__initime = None
184 self.__initime = None
183 self.__lastdatatime = 0
185 self.__lastdatatime = 0
184 self.__buffer = None
186 self.__buffer = None
185 self.__dataReady = False
187 self.__dataReady = False
186
188
187
189
188 if n == None and timeInterval == None:
190 if n == None and timeInterval == None:
189 raise ValueError, "n or timeInterval should be specified ..."
191 raise ValueError, "n or timeInterval should be specified ..."
190
192
191 if n != None:
193 if n != None:
192 self.n = n
194 self.n = n
193 self.__byTime = False
195 self.__byTime = False
194 else:
196 else:
195 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
197 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
196 self.n = 9999
198 self.n = 9999
197 self.__byTime = True
199 self.__byTime = True
198
200
199 if overlapping:
201 if overlapping:
200 self.__withOverapping = True
202 self.__withOverapping = True
201 self.__buffer = None
203 self.__buffer = None
202 else:
204 else:
203 self.__withOverapping = False
205 self.__withOverapping = False
204 self.__buffer = 0
206 self.__buffer = 0
205
207
206 self.__profIndex = 0
208 self.__profIndex = 0
207
209
208 def putData(self, data):
210 def putData(self, data):
209
211
210 """
212 """
211 Add a profile to the __buffer and increase in one the __profileIndex
213 Add a profile to the __buffer and increase in one the __profileIndex
212
214
213 """
215 """
214
216
215 if not self.__withOverapping:
217 if not self.__withOverapping:
216 self.__buffer += data.copy()
218 self.__buffer += data.copy()
217 self.__profIndex += 1
219 self.__profIndex += 1
218 return
220 return
219
221
220 #Overlapping data
222 #Overlapping data
221 nChannels, nHeis = data.shape
223 nChannels, nHeis = data.shape
222 data = numpy.reshape(data, (1, nChannels, nHeis))
224 data = numpy.reshape(data, (1, nChannels, nHeis))
223
225
224 #If the buffer is empty then it takes the data value
226 #If the buffer is empty then it takes the data value
225 if self.__buffer is None:
227 if self.__buffer is None:
226 self.__buffer = data
228 self.__buffer = data
227 self.__profIndex += 1
229 self.__profIndex += 1
228 return
230 return
229
231
230 #If the buffer length is lower than n then stakcing the data value
232 #If the buffer length is lower than n then stakcing the data value
231 if self.__profIndex < self.n:
233 if self.__profIndex < self.n:
232 self.__buffer = numpy.vstack((self.__buffer, data))
234 self.__buffer = numpy.vstack((self.__buffer, data))
233 self.__profIndex += 1
235 self.__profIndex += 1
234 return
236 return
235
237
236 #If the buffer length is equal to n then replacing the last buffer value with the data value
238 #If the buffer length is equal to n then replacing the last buffer value with the data value
237 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
239 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
238 self.__buffer[self.n-1] = data
240 self.__buffer[self.n-1] = data
239 self.__profIndex = self.n
241 self.__profIndex = self.n
240 return
242 return
241
243
242
244
243 def pushData(self):
245 def pushData(self):
244 """
246 """
245 Return the sum of the last profiles and the profiles used in the sum.
247 Return the sum of the last profiles and the profiles used in the sum.
246
248
247 Affected:
249 Affected:
248
250
249 self.__profileIndex
251 self.__profileIndex
250
252
251 """
253 """
252
254
253 if not self.__withOverapping:
255 if not self.__withOverapping:
254 data = self.__buffer
256 data = self.__buffer
255 n = self.__profIndex
257 n = self.__profIndex
256
258
257 self.__buffer = 0
259 self.__buffer = 0
258 self.__profIndex = 0
260 self.__profIndex = 0
259
261
260 return data, n
262 return data, n
261
263
262 #Integration with Overlapping
264 #Integration with Overlapping
263 data = numpy.sum(self.__buffer, axis=0)
265 data = numpy.sum(self.__buffer, axis=0)
264 n = self.__profIndex
266 n = self.__profIndex
265
267
266 return data, n
268 return data, n
267
269
268 def byProfiles(self, data):
270 def byProfiles(self, data):
269
271
270 self.__dataReady = False
272 self.__dataReady = False
271 avgdata = None
273 avgdata = None
272 # n = None
274 # n = None
273
275
274 self.putData(data)
276 self.putData(data)
275
277
276 if self.__profIndex == self.n:
278 if self.__profIndex == self.n:
277
279
278 avgdata, n = self.pushData()
280 avgdata, n = self.pushData()
279 self.__dataReady = True
281 self.__dataReady = True
280
282
281 return avgdata
283 return avgdata
282
284
283 def byTime(self, data, datatime):
285 def byTime(self, data, datatime):
284
286
285 self.__dataReady = False
287 self.__dataReady = False
286 avgdata = None
288 avgdata = None
287 n = None
289 n = None
288
290
289 self.putData(data)
291 self.putData(data)
290
292
291 if (datatime - self.__initime) >= self.__integrationtime:
293 if (datatime - self.__initime) >= self.__integrationtime:
292 avgdata, n = self.pushData()
294 avgdata, n = self.pushData()
293 self.n = n
295 self.n = n
294 self.__dataReady = True
296 self.__dataReady = True
295
297
296 return avgdata
298 return avgdata
297
299
298 def integrate(self, data, datatime=None):
300 def integrate(self, data, datatime=None):
299
301
300 if self.__initime == None:
302 if self.__initime == None:
301 self.__initime = datatime
303 self.__initime = datatime
302
304
303 if self.__byTime:
305 if self.__byTime:
304 avgdata = self.byTime(data, datatime)
306 avgdata = self.byTime(data, datatime)
305 else:
307 else:
306 avgdata = self.byProfiles(data)
308 avgdata = self.byProfiles(data)
307
309
308
310
309 self.__lastdatatime = datatime
311 self.__lastdatatime = datatime
310
312
311 if avgdata is None:
313 if avgdata is None:
312 return None, None
314 return None, None
313
315
314 avgdatatime = self.__initime
316 avgdatatime = self.__initime
315
317
316 deltatime = datatime -self.__lastdatatime
318 deltatime = datatime -self.__lastdatatime
317
319
318 if not self.__withOverapping:
320 if not self.__withOverapping:
319 self.__initime = datatime
321 self.__initime = datatime
320 else:
322 else:
321 self.__initime += deltatime
323 self.__initime += deltatime
322
324
323 return avgdata, avgdatatime
325 return avgdata, avgdatatime
324
326
325 def run(self, dataOut, **kwargs):
327 def run(self, dataOut, **kwargs):
326
328
327 if not self.isConfig:
329 if not self.isConfig:
328 self.setup(**kwargs)
330 self.setup(**kwargs)
329 self.isConfig = True
331 self.isConfig = True
330
332
331 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
333 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
332
334
333 # dataOut.timeInterval *= n
335 # dataOut.timeInterval *= n
334 dataOut.flagNoData = True
336 dataOut.flagNoData = True
335
337
336 if self.__dataReady:
338 if self.__dataReady:
337 dataOut.data_spc = avgdata
339 dataOut.data_spc = avgdata
338 dataOut.nIncohInt *= self.n
340 dataOut.nIncohInt *= self.n
339 # dataOut.nCohInt *= self.n
341 # dataOut.nCohInt *= self.n
340 dataOut.utctime = avgdatatime
342 dataOut.utctime = avgdatatime
341 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
343 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
342 # dataOut.timeInterval = self.__timeInterval*self.n
344 # dataOut.timeInterval = self.__timeInterval*self.n
343 dataOut.flagNoData = False No newline at end of file
345 dataOut.flagNoData = False
@@ -1,8 +1,8
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z murco $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z murco $
5 '''
5 '''
6
6
7 from jroutils_ftp import *
7 from jroutils_ftp import *
8 from jroutils_publish import PublishData No newline at end of file
8 from jroutils_publish import *
@@ -1,102 +1,152
1 '''
1 '''
2 @author: Juan C. Espinoza
2 @author: Juan C. Espinoza
3 '''
3 '''
4
4
5 import time
5 import time
6 import json
6 import json
7 import numpy
7 import numpy
8 import paho.mqtt.client as mqtt
8 import paho.mqtt.client as mqtt
9
9
10 from schainpy.model.proc.jroproc_base import Operation
10 from schainpy.model.proc.jroproc_base import Operation
11
11
12
13 class PrettyFloat(float):
12 class PrettyFloat(float):
14 def __repr__(self):
13 def __repr__(self):
15 return '%.2f' % self
14 return '%.2f' % self
16
15
16
17 def pretty_floats(obj):
17 def pretty_floats(obj):
18 if isinstance(obj, float):
18 if isinstance(obj, float):
19 return PrettyFloat(obj)
19 return PrettyFloat(obj)
20 elif isinstance(obj, dict):
20 elif isinstance(obj, dict):
21 return dict((k, pretty_floats(v)) for k, v in obj.items())
21 return dict((k, pretty_floats(v)) for k, v in obj.items())
22 elif isinstance(obj, (list, tuple)):
22 elif isinstance(obj, (list, tuple)):
23 return map(pretty_floats, obj)
23 return map(pretty_floats, obj)
24 return obj
24 return obj
25
25
26
26 class PublishData(Operation):
27 class PublishData(Operation):
28 """Clase publish."""
27
29
28 __MAXNUMX = 80
30 __MAXNUMX = 80
29 __MAXNUMY = 80
31 __MAXNUMY = 80
30
32
31 def __init__(self):
33 def __init__(self):
32
34 """Inicio."""
33 Operation.__init__(self)
35 Operation.__init__(self)
34
35 self.isConfig = False
36 self.isConfig = False
36 self.client = None
37 self.client = None
37
38
38 @staticmethod
39 def on_disconnect(self, client, userdata, rc):
39 def on_disconnect(client, userdata, rc):
40 if rc != 0:
40 if rc != 0:
41 print("Unexpected disconnection.")
41 print("Unexpected disconnection.")
42 self.connect()
42
43
43 def setup(self, host, port=1883, username=None, password=None, **kwargs):
44 def connect(self):
44
45 print 'trying to connect'
45 self.client = mqtt.Client()
46 try:
46 try:
47 self.client.connect(host=host, port=port, keepalive=60*10, bind_address='')
47 self.client.connect(
48 host=self.host,
49 port=self.port,
50 keepalive=60*10,
51 bind_address='')
52 print "connected"
53 self.client.loop_start()
54 # self.client.publish(
55 # self.topic + 'SETUP',
56 # json.dumps(setup),
57 # retain=True
58 # )
48 except:
59 except:
60 print "MQTT Conection error."
49 self.client = False
61 self.client = False
62
63 def setup(self, host, port=1883, username=None, password=None, **kwargs):
64
50 self.topic = kwargs.get('topic', 'schain')
65 self.topic = kwargs.get('topic', 'schain')
51 self.delay = kwargs.get('delay', 0)
66 self.delay = kwargs.get('delay', 0)
67 self.plottype = kwargs.get('plottype', 'spectra')
52 self.host = host
68 self.host = host
53 self.port = port
69 self.port = port
54 self.cnt = 0
70 self.cnt = 0
55
71 setup = []
56 def run(self, dataOut, host, datatype='data_spc', **kwargs):
72 for plot in self.plottype:
57
73 setup.append({
58 if not self.isConfig:
74 'plot': plot,
59 self.setup(host, **kwargs)
75 'topic': self.topic + plot,
60 self.isConfig = True
76 'title': getattr(self, plot + '_' + 'title', False),
61
77 'xlabel': getattr(self, plot + '_' + 'xlabel', False),
62 data = getattr(dataOut, datatype)
78 'ylabel': getattr(self, plot + '_' + 'ylabel', False),
63
79 'xrange': getattr(self, plot + '_' + 'xrange', False),
64 z = data/dataOut.normFactor
80 'yrange': getattr(self, plot + '_' + 'yrange', False),
81 'zrange': getattr(self, plot + '_' + 'zrange', False),
82 })
83 self.client = mqtt.Client(
84 client_id='jc'+self.topic + 'SCHAIN',
85 clean_session=True)
86 self.client.on_disconnect = self.on_disconnect
87 self.connect()
88
89 def publish_data(self, plottype):
90 data = getattr(self.dataOut, 'data_spc')
91 if plottype == 'spectra':
92 z = data/self.dataOut.normFactor
65 zdB = 10*numpy.log10(z)
93 zdB = 10*numpy.log10(z)
66 avg = numpy.average(z, axis=1)
67 avgdB = 10*numpy.log10(avg)
68
69 xlen ,ylen = zdB[0].shape
94 xlen, ylen = zdB[0].shape
70
71
72 dx = numpy.floor(xlen/self.__MAXNUMX) + 1
95 dx = numpy.floor(xlen/self.__MAXNUMX) + 1
73 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
96 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
74
97 Z = [0 for i in self.dataOut.channelList]
75 Z = [0 for i in dataOut.channelList]
98 for i in self.dataOut.channelList:
76 AVG = [0 for i in dataOut.channelList]
77
78 for i in dataOut.channelList:
79 Z[i] = zdB[i][::dx, ::dy].tolist()
99 Z[i] = zdB[i][::dx, ::dy].tolist()
80 AVG[i] = avgdB[i][::dy].tolist()
100 payload = {
81
101 'timestamp': self.dataOut.utctime,
82 payload = {'timestamp':dataOut.utctime,
83 'data':pretty_floats(Z),
102 'data': pretty_floats(Z),
84 'data_profile':pretty_floats(AVG),
103 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
85 'channels': ['Ch %s' % ch for ch in dataOut.channelList],
104 'interval': self.dataOut.getTimeInterval(),
86 'interval': dataOut.getTimeInterval(),
105 'xRange': [0, 80]
87 }
106 }
88
107
108 elif plottype in ('rti', 'power'):
109 z = data/self.dataOut.normFactor
110 avg = numpy.average(z, axis=1)
111 avgdB = 10*numpy.log10(avg)
112 xlen, ylen = z[0].shape
113 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
114 AVG = [0 for i in self.dataOut.channelList]
115 for i in self.dataOut.channelList:
116 AVG[i] = avgdB[i][::dy].tolist()
117 payload = {
118 'timestamp': self.dataOut.utctime,
119 'data': pretty_floats(AVG),
120 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
121 'interval': self.dataOut.getTimeInterval(),
122 'xRange': [0, 80]
123 }
124 elif plottype == 'noise':
125 noise = self.dataOut.getNoise()/self.dataOut.normFactor
126 noisedB = 10*numpy.log10(noise)
127 payload = {
128 'timestamp': self.dataOut.utctime,
129 'data': pretty_floats(noisedB.reshape(-1, 1).tolist()),
130 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
131 'interval': self.dataOut.getTimeInterval(),
132 'xRange': [0, 80]
133 }
89
134
90 #if self.cnt==self.interval and self.client:
91 print 'Publishing data to {}'.format(self.host)
135 print 'Publishing data to {}'.format(self.host)
92 self.client.publish(self.topic, json.dumps(payload), qos=0)
136 print '*************************'
93 time.sleep(self.delay)
137 self.client.publish(self.topic + plottype, json.dumps(payload), qos=0)
94 #self.cnt = 0
95 #else:
96 # self.cnt += 1
97
138
98
139
99 def close(self):
140 def run(self, dataOut, host, **kwargs):
141 self.dataOut = dataOut
142 if not self.isConfig:
143 self.setup(host, **kwargs)
144 self.isConfig = True
100
145
146 map(self.publish_data, self.plottype)
147 time.sleep(self.delay)
148
149 def close(self):
101 if self.client:
150 if self.client:
151 self.client.loop_stop()
102 self.client.disconnect()
152 self.client.disconnect()
@@ -1,40 +1,44
1 '''
1 '''
2 Created on Jul 16, 2014
2 Created on Jul 16, 2014
3
3
4 @author: @author: Miguel Urco
4 @author: @author: Miguel Urco
5 '''
5 '''
6
6
7 from schainpy import __version__
7 from schainpy import __version__
8 from setuptools import setup, Extension
8 from setuptools import setup, Extension
9
9
10 setup(name="schainpy",
10 setup(name="schainpy",
11 version=__version__,
11 version=__version__,
12 description="Python tools to read, write and process Jicamarca data",
12 description="Python tools to read, write and process Jicamarca data",
13 author="Miguel Urco",
13 author="Miguel Urco",
14 author_email="miguel.urco@jro.igp.gob.pe",
14 author_email="miguel.urco@jro.igp.gob.pe",
15 url="http://jro.igp.gob.pe",
15 url="http://jro.igp.gob.pe",
16 packages = {'schainpy',
16 packages = {'schainpy',
17 'schainpy.model',
17 'schainpy.model',
18 'schainpy.model.data',
18 'schainpy.model.data',
19 'schainpy.model.graphics',
19 'schainpy.model.graphics',
20 'schainpy.model.io',
20 'schainpy.model.io',
21 'schainpy.model.proc',
21 'schainpy.model.proc',
22 'schainpy.model.serializer',
22 'schainpy.model.serializer',
23 'schainpy.model.utils',
23 'schainpy.model.utils',
24 'schainpy.gui',
24 'schainpy.gui',
25 'schainpy.gui.figures',
25 'schainpy.gui.figures',
26 'schainpy.gui.viewcontroller',
26 'schainpy.gui.viewcontroller',
27 'schainpy.gui.viewer',
27 'schainpy.gui.viewer',
28 'schainpy.gui.viewer.windows'},
28 'schainpy.gui.viewer.windows'},
29 py_modules=[''],
29 py_modules=[''],
30 package_data={'': ['schain.conf.template'],
30 package_data={'': ['schain.conf.template'],
31 'schainpy.gui.figures': ['*.png','*.jpg'],
31 'schainpy.gui.figures': ['*.png','*.jpg'],
32 },
32 },
33 include_package_data=False,
33 include_package_data=False,
34 scripts =['schainpy/gui/schainGUI',
34 scripts =['schainpy/gui/schainGUI',
35 'schainpy/scripts/schain'],
35 'schainpy/scripts/schain'],
36 install_requires=["numpy >= 1.6.0",
36 install_requires=[
37 "scipy >= 0.9.0",
37 "scipy >= 0.9.0",
38 "h5py >= 2.0.1",
38 "matplotlib >= 1.0.0",
39 "matplotlib >= 1.0.0",
40 "pyfits >= 2.0.0",
41 "numpy >= 1.6.0",
42 "paramiko",
39 ],
43 ],
40 ) No newline at end of file
44 )
General Comments 0
You need to be logged in to leave comments. Login now